Browse Source

added Placeholder API for ATM balance (#54)

MasterCake 4 years ago
parent
commit
e232ba8ab1

+ 148 - 142
Plugin/pom.xml

@@ -1,149 +1,155 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
 
-    <parent>
-        <groupId>de.Linus122.TimeIsMoney</groupId>
-        <artifactId>parent</artifactId>
-        <version>1.9.6.11</version>
-        <relativePath>../pom.xml</relativePath>
-    </parent>
+	<parent>
+		<groupId>de.Linus122.TimeIsMoney</groupId>
+		<artifactId>parent</artifactId>
+		<version>1.9.6.11</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
 
-    <name>TimeIsMoney Plugin</name>
-    <packaging>jar</packaging>
-    <artifactId>Plugin</artifactId>
+	<name>TimeIsMoney Plugin</name>
+	<packaging>jar</packaging>
+	<artifactId>Plugin</artifactId>
 
-    <build>
-        <directory>../target</directory>
-        <finalName>TimeIsMoney</finalName>
-        <resources>
-            <resource>
-                <targetPath>.</targetPath>
-                <filtering>true</filtering>
-                <directory>src/main/resources</directory>
-                <includes>
-                    <include>plugin.yml</include>
-                    <include>config.yml</include>
-                </includes>
-            </resource>
-        </resources>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-shade-plugin</artifactId>
-                <version>2.4.3</version>
-                <executions>
-                    <execution>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>shade</goal>
-                        </goals>
-                        <configuration>
-                            <artifactSet>
-                                <includes>
-                                    <include>de.Linus122.TimeIsMoney:*</include>
-                                </includes>
-                            </artifactSet>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
-                <configuration>
-                    <archive>
-                        <addMavenDescriptor>false</addMavenDescriptor>
-                    </archive>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+	<build>
+		<directory>../target</directory>
+		<finalName>TimeIsMoney</finalName>
+		<resources>
+			<resource>
+				<targetPath>.</targetPath>
+				<filtering>true</filtering>
+				<directory>src/main/resources</directory>
+				<includes>
+					<include>plugin.yml</include>
+					<include>config.yml</include>
+				</includes>
+			</resource>
+		</resources>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-shade-plugin</artifactId>
+				<version>2.4.3</version>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>shade</goal>
+						</goals>
+						<configuration>
+							<artifactSet>
+								<includes>
+									<include>de.Linus122.TimeIsMoney:*</include>
+								</includes>
+							</artifactSet>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<configuration>
+					<archive>
+						<addMavenDescriptor>false</addMavenDescriptor>
+					</archive>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.spigotmc</groupId>
-            <artifactId>spigot-api</artifactId>
-            <version>1.14.1-R0.1-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>net.milkbowl.vault</groupId>
-            <artifactId>VaultAPI</artifactId>
-            <version>1.6</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>net.ess3</groupId>
-            <artifactId>Essentials</artifactId>
-            <version>2.13-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>Tools</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_8_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_8_R2</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_8_R3</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_9_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_9_R2</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_10_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_11_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_12_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_13_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_13_R2</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_14_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-        <dependency>
-            <groupId>de.Linus122.TimeIsMoney</groupId>
-            <artifactId>v1_15_R1</artifactId>
-            <version>1.9.6.11</version>
-        </dependency>
-    </dependencies>
+	<dependencies>
+		<dependency>
+			<groupId>org.spigotmc</groupId>
+			<artifactId>spigot-api</artifactId>
+			<version>1.14.1-R0.1-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>net.milkbowl.vault</groupId>
+			<artifactId>VaultAPI</artifactId>
+			<version>1.6</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>net.ess3</groupId>
+			<artifactId>Essentials</artifactId>
+			<version>2.13-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>me.clip</groupId>
+			<artifactId>placeholderapi</artifactId>
+			<version>2.10.6</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>Tools</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_8_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_8_R2</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_8_R3</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_9_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_9_R2</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_10_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_11_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_12_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_13_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_13_R2</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_14_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+		<dependency>
+			<groupId>de.Linus122.TimeIsMoney</groupId>
+			<artifactId>v1_15_R1</artifactId>
+			<version>1.9.6.11</version>
+		</dependency>
+	</dependencies>
 </project>

+ 2 - 2
Plugin/src/main/java/de/Linus122/TimeIsMoney/ATM.java

@@ -123,7 +123,7 @@ public class ATM implements Listener, CommandExecutor {
 	 * @param p The offline player to get the balance of.
 	 * @return The offline player's balance in the bank.
 	 */
-	private static double getBankBalance(OfflinePlayer p) {
+	public static double getBankBalance(OfflinePlayer p) {
 		String bankString = p.getName() + "_TimBANK";
 		if (!bankAccountsConfig.contains(bankString)) bankAccountsConfig.set(bankString, 0.0);
 		return bankAccountsConfig.getDouble(bankString);
@@ -135,7 +135,7 @@ public class ATM implements Listener, CommandExecutor {
 	 * @param p The player to get the balance of.
 	 * @return The player's balance in the bank.
 	 */
-	private static double getBankBalance(Player p) {
+	public static double getBankBalance(Player p) {
 		String bankString = getBankString(p);
 		if (!bankAccountsConfig.contains(bankString)) bankAccountsConfig.set(bankString, 0.0);
 		return bankAccountsConfig.getDouble(bankString);

+ 8 - 0
Plugin/src/main/java/de/Linus122/TimeIsMoney/Main.java

@@ -2,6 +2,7 @@ package de.Linus122.TimeIsMoney;
 
 import com.earth2me.essentials.Essentials;
 import de.Linus122.TimeIsMoney.tools.ActionBarUtils;
+
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
 import org.bukkit.Server;
@@ -171,6 +172,13 @@ public class Main extends JavaPlugin {
 			} catch (NullPointerException ignored) {
 			}
 		}, 20L, 20L);
+		
+		// Placeholder API
+
+        if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
+        	new NamePlaceholder(this).register();
+        }
+		
 		Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
 			if (currentDay != new Date().getDay()) { //Next day, clear payouts!
 				log("Cleared all payouts");

+ 49 - 0
Plugin/src/main/java/de/Linus122/TimeIsMoney/NamePlaceholder.java

@@ -0,0 +1,49 @@
+package de.Linus122.TimeIsMoney;
+
+import org.bukkit.OfflinePlayer;
+
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+
+
+public class NamePlaceholder extends PlaceholderExpansion {
+
+	Main timeIsMoney;
+
+	public NamePlaceholder(Main plugin) {
+		this.timeIsMoney = plugin;
+	}
+
+	// This tells PlaceholderAPI to not unregister your expansion on reloads since it is provided by the dependency
+	// Introduced in PlaceholderAPI 2.8.5
+	@Override
+	public boolean persist() {
+		return true;
+	}
+
+	// Our placeholders will be %tim <params>%
+	@Override
+	public String getIdentifier() {
+		return "tim";
+	}
+
+	// the author
+	@Override
+	public String getAuthor() {
+		return "Linus122";
+	}
+
+	// This is the version
+	@Override
+	public String getVersion() {
+		return timeIsMoney.getDescription().getVersion();
+	}
+
+	@Override
+	public String onRequest(OfflinePlayer player, String label) {
+		switch(label) {
+			case "atm":
+				return Main.economy.format(ATM.getBankBalance(player));
+		}
+		return null;
+	}
+}

+ 1 - 1
Plugin/src/main/resources/plugin.yml

@@ -8,7 +8,7 @@ api-version: 1.13
 
 
 depend: [Vault]
-softdepend: [Essentials]
+softdepend: [Essentials, PlaceholderAPI]
 
 commands:
   timeismoney:

+ 4 - 0
pom.xml

@@ -45,6 +45,10 @@
             <id>ess-repo</id>
             <url>http://repo.ess3.net/content/groups/essentials</url>
         </repository>
+        <repository>
+            <id>placeholderapi</id>
+            <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
+        </repository>
     </repositories>
 
     <build>