mirror of
				https://github.com/PlaceholderAPI/PlaceholderAPI
				synced 2025-10-31 06:12:28 +01:00 
			
		
		
		
	Reformatted project to conform to google style guide.
This commit is contained in:
		
							
								
								
									
										12
									
								
								placeholderapi.iml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								placeholderapi.iml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <module version="4"> | ||||||
|  |   <component name="FacetManager"> | ||||||
|  |     <facet type="minecraft" name="Minecraft"> | ||||||
|  |       <configuration> | ||||||
|  |         <autoDetectTypes> | ||||||
|  |           <platformType>SPIGOT</platformType> | ||||||
|  |         </autoDetectTypes> | ||||||
|  |       </configuration> | ||||||
|  |     </facet> | ||||||
|  |   </component> | ||||||
|  | </module> | ||||||
							
								
								
									
										203
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										203
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -1,108 +1,109 @@ | |||||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | <project 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"> |   xmlns="http://maven.apache.org/POM/4.0.0" | ||||||
|     <modelVersion>4.0.0</modelVersion> |   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
|     <groupId>me.clip</groupId> |   <modelVersion>4.0.0</modelVersion> | ||||||
|     <artifactId>placeholderapi</artifactId> |   <groupId>me.clip</groupId> | ||||||
|  |   <artifactId>placeholderapi</artifactId> | ||||||
|  |  | ||||||
|     <version>2.9.1-DEV-${BUILD_NUMBER}</version> |   <version>2.9.1-DEV-${BUILD_NUMBER}</version> | ||||||
|     <name>PlaceholderAPI</name> |   <name>PlaceholderAPI</name> | ||||||
|     <description>An awesome placeholder provider!</description> |   <description>An awesome placeholder provider!</description> | ||||||
|     <url>http://extendedclip.com</url> |   <url>http://extendedclip.com</url> | ||||||
|  |  | ||||||
|     <properties> |   <properties> | ||||||
|         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||||
|     </properties> |   </properties> | ||||||
|  |  | ||||||
|     <repositories> |   <repositories> | ||||||
|         <repository> |     <repository> | ||||||
|             <id>spigot-repo</id> |       <id>spigot-repo</id> | ||||||
|             <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> |       <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||||||
|         </repository> |     </repository> | ||||||
|         <repository> |     <repository> | ||||||
|             <id>bstats-repo</id> |       <id>bstats-repo</id> | ||||||
|             <url>http://repo.bstats.org/content/repositories/releases/</url> |       <url>http://repo.bstats.org/content/repositories/releases/</url> | ||||||
|         </repository> |     </repository> | ||||||
|         <repository> |     <repository> | ||||||
|             <id>rayzr-repo</id> |       <id>rayzr-repo</id> | ||||||
|             <url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url> |       <url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url> | ||||||
|         </repository> |     </repository> | ||||||
|     </repositories> |   </repositories> | ||||||
|  |  | ||||||
|     <dependencies> |   <dependencies> | ||||||
|         <dependency> |     <dependency> | ||||||
|             <groupId>org.spigotmc</groupId> |       <groupId>org.spigotmc</groupId> | ||||||
|             <artifactId>spigot-api</artifactId> |       <artifactId>spigot-api</artifactId> | ||||||
|             <version>1.12.2-R0.1-SNAPSHOT</version> |       <version>1.12.2-R0.1-SNAPSHOT</version> | ||||||
|             <scope>provided</scope> |       <scope>provided</scope> | ||||||
|         </dependency> |     </dependency> | ||||||
|         <dependency> |     <dependency> | ||||||
|             <groupId>org.bstats</groupId> |       <groupId>org.bstats</groupId> | ||||||
|             <artifactId>bstats-bukkit</artifactId> |       <artifactId>bstats-bukkit</artifactId> | ||||||
|             <version>1.2</version> |       <version>1.2</version> | ||||||
|             <scope>compile</scope> |       <scope>compile</scope> | ||||||
|         </dependency> |     </dependency> | ||||||
|         <dependency> |     <dependency> | ||||||
|             <groupId>me.rayzr522</groupId> |       <groupId>me.rayzr522</groupId> | ||||||
|             <artifactId>jsonmessage</artifactId> |       <artifactId>jsonmessage</artifactId> | ||||||
|             <version>1.0.0</version> |       <version>1.0.0</version> | ||||||
|             <scope>compile</scope> |       <scope>compile</scope> | ||||||
|         </dependency> |     </dependency> | ||||||
|     </dependencies> |   </dependencies> | ||||||
|  |  | ||||||
|     <build> |   <build> | ||||||
|         <defaultGoal>clean package</defaultGoal> |     <defaultGoal>clean package</defaultGoal> | ||||||
|  |  | ||||||
|         <plugins> |     <plugins> | ||||||
|             <plugin> |       <plugin> | ||||||
|                 <groupId>org.apache.maven.plugins</groupId> |         <groupId>org.apache.maven.plugins</groupId> | ||||||
|                 <artifactId>maven-jar-plugin</artifactId> |         <artifactId>maven-jar-plugin</artifactId> | ||||||
|                 <version>2.3.2</version> |         <version>2.3.2</version> | ||||||
|                 <configuration> |         <configuration> | ||||||
|                     <finalName>${project.name}-${project.version}</finalName> |           <finalName>${project.name}-${project.version}</finalName> | ||||||
|                 </configuration> |         </configuration> | ||||||
|             </plugin> |       </plugin> | ||||||
|             <plugin> |       <plugin> | ||||||
|                 <groupId>org.apache.maven.plugins</groupId> |         <groupId>org.apache.maven.plugins</groupId> | ||||||
|                 <artifactId>maven-compiler-plugin</artifactId> |         <artifactId>maven-compiler-plugin</artifactId> | ||||||
|                 <version>3.7.0</version> |         <version>3.7.0</version> | ||||||
|                 <configuration> |         <configuration> | ||||||
|                     <source>1.8</source> |           <source>1.8</source> | ||||||
|                     <target>1.8</target> |           <target>1.8</target> | ||||||
|                 </configuration> |         </configuration> | ||||||
|             </plugin> |       </plugin> | ||||||
|             <plugin> |       <plugin> | ||||||
|                 <groupId>org.apache.maven.plugins</groupId> |         <groupId>org.apache.maven.plugins</groupId> | ||||||
|                 <artifactId>maven-shade-plugin</artifactId> |         <artifactId>maven-shade-plugin</artifactId> | ||||||
|                 <version>3.1.0</version> |         <version>3.1.0</version> | ||||||
|                 <executions> |         <executions> | ||||||
|                     <execution> |           <execution> | ||||||
|                         <phase>package</phase> |             <phase>package</phase> | ||||||
|                         <goals> |             <goals> | ||||||
|                             <goal>shade</goal> |               <goal>shade</goal> | ||||||
|                         </goals> |             </goals> | ||||||
|                         <configuration> |             <configuration> | ||||||
|                             <minimizeJar>false</minimizeJar> |               <minimizeJar>false</minimizeJar> | ||||||
|                             <createDependencyReducedPom>false</createDependencyReducedPom> |               <createDependencyReducedPom>false</createDependencyReducedPom> | ||||||
|                             <relocations> |               <relocations> | ||||||
|                                 <relocation> |                 <relocation> | ||||||
|                                     <pattern>org.bstats</pattern> |                   <pattern>org.bstats</pattern> | ||||||
|                                     <shadedPattern>me.clip.placeholderapi.metrics</shadedPattern> |                   <shadedPattern>me.clip.placeholderapi.metrics</shadedPattern> | ||||||
|                                 </relocation> |                 </relocation> | ||||||
|                                 <relocation> |                 <relocation> | ||||||
|                                     <pattern>me.rayzr522</pattern> |                   <pattern>me.rayzr522</pattern> | ||||||
|                                     <shadedPattern>me.clip.placeholderapi.util</shadedPattern> |                   <shadedPattern>me.clip.placeholderapi.util</shadedPattern> | ||||||
|                                 </relocation> |                 </relocation> | ||||||
|                             </relocations> |               </relocations> | ||||||
|                         </configuration> |             </configuration> | ||||||
|                     </execution> |           </execution> | ||||||
|                 </executions> |         </executions> | ||||||
|             </plugin> |       </plugin> | ||||||
|         </plugins> |     </plugins> | ||||||
|         <resources> |     <resources> | ||||||
|             <resource> |       <resource> | ||||||
|                 <directory>src/main/resources</directory> |         <directory>src/main/resources</directory> | ||||||
|                 <filtering>true</filtering> |         <filtering>true</filtering> | ||||||
|             </resource> |       </resource> | ||||||
|         </resources> |     </resources> | ||||||
|     </build> |   </build> | ||||||
| </project> | </project> | ||||||
|   | |||||||
| @@ -46,8 +46,10 @@ public class PlaceholderAPI { | |||||||
|  |  | ||||||
|   private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]"); |   private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]"); | ||||||
|   private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]"); |   private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]"); | ||||||
|   private static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern.compile("[%](rel_)([^%]+)[%]"); |   private static final Pattern RELATIONAL_PLACEHOLDER_PATTERN = Pattern | ||||||
|  |       .compile("[%](rel_)([^%]+)[%]"); | ||||||
|   private static final Map<String, PlaceholderHook> placeholders = new HashMap<>(); |   private static final Map<String, PlaceholderHook> placeholders = new HashMap<>(); | ||||||
|  |  | ||||||
|   private PlaceholderAPI() { |   private PlaceholderAPI() { | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -374,21 +376,21 @@ public class PlaceholderAPI { | |||||||
|  |  | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public static String setPlaceholders(Player p, String text) { |   public static String setPlaceholders(Player p, String text) { | ||||||
|     return setPlaceholders((OfflinePlayer)p, text, PLACEHOLDER_PATTERN); |     return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public static List<String> setPlaceholders(Player p, List<String> text) { |   public static List<String> setPlaceholders(Player p, List<String> text) { | ||||||
|     return setPlaceholders((OfflinePlayer)p, text, PLACEHOLDER_PATTERN); |     return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public static String setBracketPlaceholders(Player p, String text) { |   public static String setBracketPlaceholders(Player p, String text) { | ||||||
|     return setPlaceholders((OfflinePlayer)p, text, BRACKET_PLACEHOLDER_PATTERN); |     return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public static List<String> setBracketPlaceholders(Player p, List<String> text) { |   public static List<String> setBracketPlaceholders(Player p, List<String> text) { | ||||||
|     return setPlaceholders((OfflinePlayer)p, text, BRACKET_PLACEHOLDER_PATTERN); |     return setPlaceholders((OfflinePlayer) p, text, BRACKET_PLACEHOLDER_PATTERN); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,6 +20,10 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi; | package me.clip.placeholderapi; | ||||||
|  |  | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.concurrent.TimeUnit; | ||||||
| import me.clip.placeholderapi.commands.PlaceholderAPICommands; | import me.clip.placeholderapi.commands.PlaceholderAPICommands; | ||||||
| import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; | import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; | ||||||
| import me.clip.placeholderapi.expansion.ExpansionManager; | import me.clip.placeholderapi.expansion.ExpansionManager; | ||||||
| @@ -34,235 +38,223 @@ import org.bukkit.ChatColor; | |||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
| import java.text.SimpleDateFormat; |  | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.concurrent.TimeUnit; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Yes I have a shit load of work to do... |  * Yes I have a shit load of work to do... | ||||||
|  *  |  | ||||||
|  * @author Ryan McCarthy |  | ||||||
|  * |  * | ||||||
|  |  * @author Ryan McCarthy | ||||||
|  */ |  */ | ||||||
| public class PlaceholderAPIPlugin extends JavaPlugin { | public class PlaceholderAPIPlugin extends JavaPlugin { | ||||||
|  |  | ||||||
| 	private static PlaceholderAPIPlugin instance; |   private static PlaceholderAPIPlugin instance; | ||||||
|  |   private static SimpleDateFormat dateFormat; | ||||||
|  |   private static String booleanTrue; | ||||||
|  |   private static String booleanFalse; | ||||||
|  |   private static Version serverVersion; | ||||||
|  |   private PlaceholderAPIConfig config; | ||||||
|  |   private ExpansionManager expansionManager; | ||||||
|  |   private ExpansionCloudManager expansionCloud; | ||||||
|  |   private long startTime; | ||||||
|  |  | ||||||
| 	private PlaceholderAPIConfig config; |   private static Version getVersion() { | ||||||
|  |     String v = "unknown"; | ||||||
|  |     boolean spigot = false; | ||||||
|  |     try { | ||||||
|  |       v = Bukkit.getServer().getClass().getPackage().getName() | ||||||
|  |           .split("\\.")[3]; | ||||||
|  |     } catch (ArrayIndexOutOfBoundsException ex) { | ||||||
|  |     } | ||||||
|  |     try { | ||||||
|  |       Class.forName("org.spigotmc.SpigotConfig"); | ||||||
|  |       Class.forName("net.md_5.bungee.api.chat.BaseComponent"); | ||||||
|  |       spigot = true; | ||||||
|  |     } catch (ExceptionInInitializerError | ClassNotFoundException exception) { | ||||||
|  |     } | ||||||
|  |     return new Version(v, spigot); | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private ExpansionManager expansionManager; |   /** | ||||||
|  |    * Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API | ||||||
|  |    * class, this is the main class that extends JavaPlugin. For most API methods, use static methods | ||||||
|  |    * available from the class: {@link PlaceholderAPI} | ||||||
|  |    * | ||||||
|  |    * @return PlaceholderAPIPlugin instance | ||||||
|  |    */ | ||||||
|  |   public static PlaceholderAPIPlugin getInstance() { | ||||||
|  |     return instance; | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private ExpansionCloudManager expansionCloud; |   /** | ||||||
|  |    * Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for | ||||||
|  |    * generic time based placeholders | ||||||
|  |    * | ||||||
|  |    * @return date format | ||||||
|  |    */ | ||||||
|  |   public static SimpleDateFormat getDateFormat() { | ||||||
|  |     return dateFormat != null ? dateFormat : new SimpleDateFormat( | ||||||
|  |         "MM/dd/yy HH:mm:ss"); | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private static SimpleDateFormat dateFormat; |   /** | ||||||
|  |    * Get the configurable {@linkplain String} value that should be returned when a boolean is true | ||||||
|  |    * | ||||||
|  |    * @return string value of true | ||||||
|  |    */ | ||||||
|  |   public static String booleanTrue() { | ||||||
|  |     return booleanTrue != null ? booleanTrue : "true"; | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private static String booleanTrue; |   /** | ||||||
|  |    * Get the configurable {@linkplain String} value that should be returned when a boolean is false | ||||||
|  |    * | ||||||
|  |    * @return string value of false | ||||||
|  |    */ | ||||||
|  |   public static String booleanFalse() { | ||||||
|  |     return booleanFalse != null ? booleanFalse : "false"; | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private static String booleanFalse; |   public static Version getServerVersion() { | ||||||
|  |     return serverVersion != null ? serverVersion : getVersion(); | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private static Version serverVersion; |   @Override | ||||||
|  |   public void onLoad() { | ||||||
|  |     startTime = System.currentTimeMillis(); | ||||||
|  |     instance = this; | ||||||
|  |     serverVersion = getVersion(); | ||||||
|  |     config = new PlaceholderAPIConfig(this); | ||||||
|  |     expansionManager = new ExpansionManager(this); | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private long startTime; |   @Override | ||||||
|  |   public void onEnable() { | ||||||
|  |     config.loadDefConfig(); | ||||||
|  |     setupOptions(); | ||||||
|  |     getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this)); | ||||||
|  |     new PlaceholderListener(this); | ||||||
|  |     getLogger().info("Placeholder expansion registration initializing..."); | ||||||
|  |     expansionManager.registerAllExpansions(); | ||||||
|  |     if (config.checkUpdates()) { | ||||||
|  |       new UpdateChecker(this).fetch(); | ||||||
|  |     } | ||||||
|  |     if (config.isCloudEnabled()) { | ||||||
|  |       enableCloud(); | ||||||
|  |     } | ||||||
|  |     setupMetrics(); | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	@Override |   @Override | ||||||
| 	public void onLoad() { |   public void onDisable() { | ||||||
| 		startTime = System.currentTimeMillis(); |     disableCloud(); | ||||||
| 		instance = this; |     PlaceholderAPI.unregisterAll(); | ||||||
| 		serverVersion = getVersion(); |     expansionManager.clean(); | ||||||
| 		config = new PlaceholderAPIConfig(this); |     expansionManager = null; | ||||||
| 		expansionManager = new ExpansionManager(this); |     Bukkit.getScheduler().cancelTasks(this); | ||||||
| 	} |     serverVersion = null; | ||||||
|  |     instance = null; | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	@Override |   public void reloadConf(CommandSender s) { | ||||||
| 	public void onEnable() { |     boolean cloudEnabled = this.expansionCloud != null; | ||||||
| 		config.loadDefConfig(); |     expansionManager.clean(); | ||||||
| 		setupOptions(); |     PlaceholderAPI.unregisterAllProvidedExpansions(); | ||||||
| 		getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this)); |     reloadConfig(); | ||||||
| 		new PlaceholderListener(this); |     setupOptions(); | ||||||
| 		getLogger().info("Placeholder expansion registration initializing..."); |     expansionManager.registerAllExpansions(); | ||||||
| 		expansionManager.registerAllExpansions(); |     if (!config.isCloudEnabled()) { | ||||||
| 		if (config.checkUpdates()) { |       disableCloud(); | ||||||
| 			new UpdateChecker(this).fetch(); |     } else if (!cloudEnabled) { | ||||||
| 		} |       enableCloud(); | ||||||
| 		if (config.isCloudEnabled()) { |     } | ||||||
| 			enableCloud(); |     s.sendMessage(ChatColor.translateAlternateColorCodes('&', | ||||||
| 		} |         PlaceholderAPI.getRegisteredIdentifiers().size() | ||||||
| 		setupMetrics(); |             + " &aplaceholder hooks successfully registered!")); | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	@Override |   private void setupOptions() { | ||||||
| 	public void onDisable() { |     booleanTrue = config.booleanTrue(); | ||||||
| 		disableCloud(); |     if (booleanTrue == null) { | ||||||
| 		PlaceholderAPI.unregisterAll(); |       booleanTrue = "true"; | ||||||
| 		expansionManager.clean(); |     } | ||||||
| 		expansionManager = null; |     booleanFalse = config.booleanFalse(); | ||||||
| 		Bukkit.getScheduler().cancelTasks(this); |     if (booleanFalse == null) { | ||||||
| 		serverVersion = null; |       booleanFalse = "false"; | ||||||
| 		instance = null; |     } | ||||||
| 	} |     try { | ||||||
|  |       dateFormat = new SimpleDateFormat(config.dateFormat()); | ||||||
|  |     } catch (Exception e) { | ||||||
|  |       dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	public void reloadConf(CommandSender s) { |   private void setupMetrics() { | ||||||
| 		boolean cloudEnabled = this.expansionCloud != null; |     Metrics m = new Metrics(this); | ||||||
| 		expansionManager.clean(); |     m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", | ||||||
| 		PlaceholderAPI.unregisterAllProvidedExpansions(); |         () -> getExpansionCloud() != null ? "yes" : "no")); | ||||||
| 		reloadConfig(); |  | ||||||
| 		setupOptions(); |  | ||||||
| 		expansionManager.registerAllExpansions(); |  | ||||||
| 		if (!config.isCloudEnabled()) { |  | ||||||
| 			disableCloud(); |  | ||||||
| 		} else if (!cloudEnabled) { |  | ||||||
| 			enableCloud(); |  | ||||||
| 		} |  | ||||||
| 		s.sendMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!")); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	private void setupOptions() { |     m.addCustomChart( | ||||||
| 		booleanTrue = config.booleanTrue(); |         new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); | ||||||
| 		if (booleanTrue == null) { |  | ||||||
| 			booleanTrue = "true"; |  | ||||||
| 		} |  | ||||||
| 		booleanFalse = config.booleanFalse(); |  | ||||||
| 		if (booleanFalse == null) { |  | ||||||
| 			booleanFalse = "false"; |  | ||||||
| 		} |  | ||||||
| 		try { |  | ||||||
| 			dateFormat = new SimpleDateFormat(config.dateFormat()); |  | ||||||
| 		} catch (Exception e) { |  | ||||||
| 			dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss"); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	private void setupMetrics() { |     m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> { | ||||||
| 		Metrics m = new Metrics(this); |       Map<String, Integer> map = new HashMap<>(); | ||||||
| 	    m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getExpansionCloud() != null ? "yes" : "no")); |       Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders(); | ||||||
| 		 |  | ||||||
| 	    m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); |  | ||||||
|  |  | ||||||
| 	    m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> { |       if (!p.isEmpty()) { | ||||||
|             Map<String, Integer> map = new HashMap<>(); |  | ||||||
|             Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders(); |  | ||||||
|  |  | ||||||
|             if (!p.isEmpty()) { |         for (PlaceholderHook hook : p.values()) { | ||||||
|  |           if (hook instanceof PlaceholderExpansion) { | ||||||
|  |             PlaceholderExpansion ex = (PlaceholderExpansion) hook; | ||||||
|  |             map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier() | ||||||
|  |                 : ex.getRequiredPlugin(), 1); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       return map; | ||||||
|  |  | ||||||
|                 for (PlaceholderHook hook : p.values()) { |     })); | ||||||
|                     if (hook instanceof PlaceholderExpansion) { |  | ||||||
|                         PlaceholderExpansion ex = (PlaceholderExpansion) hook; |  | ||||||
|                         map.put(ex.getRequiredPlugin() == null ? ex.getIdentifier() |  | ||||||
|                                 : ex.getRequiredPlugin(), 1); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             return map; |  | ||||||
|  |  | ||||||
|         })); |   } | ||||||
|  |  | ||||||
| 	} |   public void enableCloud() { | ||||||
|  |     if (expansionCloud == null) { | ||||||
|  |       expansionCloud = new ExpansionCloudManager(this); | ||||||
|  |       expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); | ||||||
|  |     } else { | ||||||
|  |       expansionCloud.clean(); | ||||||
|  |       expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
| 	private static Version getVersion() { |   public void disableCloud() { | ||||||
| 		String v = "unknown"; |     if (expansionCloud != null) { | ||||||
| 		boolean spigot = false; |       expansionCloud.clean(); | ||||||
| 		try { |       expansionCloud = null; | ||||||
| 			v = Bukkit.getServer().getClass().getPackage().getName() |     } | ||||||
| 					.split("\\.")[3]; |   } | ||||||
| 		} catch (ArrayIndexOutOfBoundsException ex) { |  | ||||||
| 		} |  | ||||||
| 		try { |  | ||||||
| 			Class.forName("org.spigotmc.SpigotConfig"); |  | ||||||
| 			Class.forName("net.md_5.bungee.api.chat.BaseComponent"); |  | ||||||
| 			spigot = true; |  | ||||||
| 		} catch (ExceptionInInitializerError | ClassNotFoundException exception) { |  | ||||||
| 		} |  | ||||||
| 		return new Version(v, spigot); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public void enableCloud() { |   /** | ||||||
| 		if (expansionCloud == null) { |    * Obtain the configuration class for PlaceholderAPI. | ||||||
| 			expansionCloud = new ExpansionCloudManager(this); |    * | ||||||
| 			expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); |    * @return PlaceholderAPIConfig instance | ||||||
| 		} else { |    */ | ||||||
| 			expansionCloud.clean(); |   public PlaceholderAPIConfig getPlaceholderAPIConfig() { | ||||||
| 			expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); |     return config; | ||||||
| 		} |   } | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public void disableCloud() { |   public ExpansionManager getExpansionManager() { | ||||||
| 		if (expansionCloud != null) { |     return expansionManager; | ||||||
| 			expansionCloud.clean(); |   } | ||||||
| 			expansionCloud = null; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |   public ExpansionCloudManager getExpansionCloud() { | ||||||
| 	 * Gets the static instance of the main class for PlaceholderAPI. This class |     return expansionCloud; | ||||||
| 	 * is not the actual API class, this is the main class that extends |   } | ||||||
| 	 * JavaPlugin. For most API methods, use static methods available from the |  | ||||||
| 	 * class: {@link PlaceholderAPI} |  | ||||||
| 	 *  |  | ||||||
| 	 * @return PlaceholderAPIPlugin instance |  | ||||||
| 	 */ |  | ||||||
| 	public static PlaceholderAPIPlugin getInstance() { |  | ||||||
| 		return instance; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |   public String getUptime() { | ||||||
| 	 * Get the configurable {@linkplain SimpleDateFormat} object that is used to |     return TimeUtil | ||||||
| 	 * parse time for generic time based placeholders |         .getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)); | ||||||
| 	 *  |   } | ||||||
| 	 * @return date format |  | ||||||
| 	 */ |  | ||||||
| 	public static SimpleDateFormat getDateFormat() { |  | ||||||
| 		return dateFormat != null ? dateFormat : new SimpleDateFormat( |  | ||||||
| 				"MM/dd/yy HH:mm:ss"); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |   public long getUptimeMillis() { | ||||||
| 	 * Get the configurable {@linkplain String} value that should be returned |     return (System.currentTimeMillis() - startTime); | ||||||
| 	 * when a boolean is true |   } | ||||||
| 	 *  |  | ||||||
| 	 * @return string value of true |  | ||||||
| 	 */ |  | ||||||
| 	public static String booleanTrue() { |  | ||||||
| 		return booleanTrue != null ? booleanTrue : "true"; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |  | ||||||
| 	 * Get the configurable {@linkplain String} value that should be returned |  | ||||||
| 	 * when a boolean is false |  | ||||||
| 	 *  |  | ||||||
| 	 * @return string value of false |  | ||||||
| 	 */ |  | ||||||
| 	public static String booleanFalse() { |  | ||||||
| 		return booleanFalse != null ? booleanFalse : "false"; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public static Version getServerVersion() { |  | ||||||
| 		return serverVersion != null ? serverVersion : getVersion(); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |  | ||||||
| 	 * Obtain the configuration class for PlaceholderAPI. |  | ||||||
| 	 *  |  | ||||||
| 	 * @return PlaceholderAPIConfig instance |  | ||||||
| 	 */ |  | ||||||
| 	public PlaceholderAPIConfig getPlaceholderAPIConfig() { |  | ||||||
| 		return config; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public ExpansionManager getExpansionManager() { |  | ||||||
| 		return expansionManager; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public ExpansionCloudManager getExpansionCloud() { |  | ||||||
| 		return expansionCloud; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public String getUptime() { |  | ||||||
| 		return TimeUtil.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public long getUptimeMillis() { |  | ||||||
| 		return (System.currentTimeMillis() - startTime); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,24 +27,27 @@ public abstract class PlaceholderHook { | |||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * called when a placeholder value is requested from this hook |    * called when a placeholder value is requested from this hook | ||||||
|    * @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a player |    * | ||||||
|  |    * @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a | ||||||
|  |    * player | ||||||
|    * @param params String passed to the hook to determine what value to return |    * @param params String passed to the hook to determine what value to return | ||||||
|    * @return value for the requested player and params |    * @return value for the requested player and params | ||||||
|    */ |    */ | ||||||
| 	public String onRequest(OfflinePlayer p, String params) { |   public String onRequest(OfflinePlayer p, String params) { | ||||||
| 		if (p != null && p.isOnline()) { |     if (p != null && p.isOnline()) { | ||||||
| 			return onPlaceholderRequest((Player) p, params); |       return onPlaceholderRequest((Player) p, params); | ||||||
| 		} |     } | ||||||
| 		return onPlaceholderRequest(null, params); |     return onPlaceholderRequest(null, params); | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * called when a placeholder is requested from this hook |    * called when a placeholder is requested from this hook | ||||||
| 	 * @param p {@link Player} to request the placeholder value for, null if not needed for a player |    * | ||||||
| 	 * @param params String passed to the hook to determine what value to return |    * @param p {@link Player} to request the placeholder value for, null if not needed for a player | ||||||
| 	 * @return value for the requested player and params |    * @param params String passed to the hook to determine what value to return | ||||||
| 	 */ |    * @return value for the requested player and params | ||||||
| 	public String onPlaceholderRequest(Player p, String params) { |    */ | ||||||
| 		return null; |   public String onPlaceholderRequest(Player p, String params) { | ||||||
| 	} |     return null; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,9 +20,15 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi; | package me.clip.placeholderapi; | ||||||
|  |  | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Map.Entry; | ||||||
|  | import java.util.Set; | ||||||
| import me.clip.placeholderapi.events.ExpansionUnregisterEvent; | import me.clip.placeholderapi.events.ExpansionUnregisterEvent; | ||||||
| import me.clip.placeholderapi.events.PlaceholderHookUnloadEvent; | import me.clip.placeholderapi.expansion.Cacheable; | ||||||
| import me.clip.placeholderapi.expansion.*; | import me.clip.placeholderapi.expansion.Cleanable; | ||||||
|  | import me.clip.placeholderapi.expansion.ExpansionManager; | ||||||
|  | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
|  | import me.clip.placeholderapi.expansion.Taskable; | ||||||
| import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | ||||||
| import me.clip.placeholderapi.external.EZPlaceholderHook; | import me.clip.placeholderapi.external.EZPlaceholderHook; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| @@ -34,120 +40,118 @@ import org.bukkit.event.player.PlayerQuitEvent; | |||||||
| import org.bukkit.event.server.PluginDisableEvent; | import org.bukkit.event.server.PluginDisableEvent; | ||||||
| import org.bukkit.event.server.PluginEnableEvent; | import org.bukkit.event.server.PluginEnableEvent; | ||||||
|  |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.Map.Entry; |  | ||||||
| import java.util.Set; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| public class PlaceholderListener implements Listener { | public class PlaceholderListener implements Listener { | ||||||
| 	 |  | ||||||
| 	private PlaceholderAPIPlugin plugin; |  | ||||||
| 	 |  | ||||||
| 	public PlaceholderListener(PlaceholderAPIPlugin instance) { |  | ||||||
| 		plugin = instance; |  | ||||||
| 		Bukkit.getPluginManager().registerEvents(this, instance); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	@EventHandler |  | ||||||
| 	public void onExpansionUnregister(ExpansionUnregisterEvent event) { |  | ||||||
| 		 |  | ||||||
| 		if (event.getExpansion() instanceof Listener) { |  | ||||||
| 			HandlerList.unregisterAll((Listener)event.getExpansion()); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (event.getExpansion() instanceof Taskable) { |  | ||||||
| 			((Taskable) event.getExpansion()).stop(); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (event.getExpansion() instanceof Cacheable) { |  | ||||||
| 			((Cacheable) event.getExpansion()).clear(); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (plugin.getExpansionCloud() != null) { |  | ||||||
| 			 |  | ||||||
| 			CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName()); |  | ||||||
| 			 |  | ||||||
| 			if (ex != null) { |  | ||||||
| 				ex.setHasExpansion(false); |  | ||||||
| 				ex.setShouldUpdate(false); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	@EventHandler |  | ||||||
| 	public void onEnable(PluginEnableEvent event) { |  | ||||||
| 		ExpansionManager m = plugin.getExpansionManager(); |  | ||||||
| 		PlaceholderExpansion e = m.getCachedExpansion(event.getPlugin().getName().toLowerCase()); |  | ||||||
| 		if (e != null && e.canRegister()) { |  | ||||||
| 			if (e.isRegistered() || m.registerExpansion(e)) { |  | ||||||
| 				m.removeCachedExpansion(e.getRequiredPlugin()); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	@EventHandler(priority = EventPriority.HIGH) |  | ||||||
| 	public void onPluginUnload(PluginDisableEvent e) { |  | ||||||
| 		 |  | ||||||
| 		String n = e.getPlugin().getName(); |  | ||||||
| 		 |  | ||||||
| 		if (n == null) { |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (n.equals(plugin.getName())) { |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 			 |  | ||||||
| 		Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders(); |  | ||||||
| 			 |  | ||||||
| 		for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) { |  | ||||||
| 				 |  | ||||||
| 			PlaceholderHook i = hook.getValue(); |  | ||||||
| 				 |  | ||||||
| 			if (i instanceof EZPlaceholderHook) { |  | ||||||
| 					 |  | ||||||
| 				EZPlaceholderHook h = (EZPlaceholderHook) i; |  | ||||||
| 				 |  | ||||||
| 				if (h.getPluginName() == null) { |  | ||||||
| 					continue; |  | ||||||
| 				} |  | ||||||
| 					 |  | ||||||
| 				if (h.getPluginName().equalsIgnoreCase(n)) { |  | ||||||
| 					if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) { |  | ||||||
| 						plugin.getLogger().info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName()); |  | ||||||
| 						break; |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 			} else if (i instanceof PlaceholderExpansion) { |  | ||||||
| 				 |  | ||||||
| 				PlaceholderExpansion ex = (PlaceholderExpansion) i; |  | ||||||
| 				 |  | ||||||
| 				if (ex.getRequiredPlugin() == null) { |  | ||||||
| 					continue; |  | ||||||
| 				} |  | ||||||
| 				 |  | ||||||
| 				if (ex.getRequiredPlugin().equalsIgnoreCase(n)) { |  | ||||||
| 					if (PlaceholderAPI.unregisterExpansion(ex)) { |  | ||||||
| 						plugin.getLogger().info("Unregistered placeholder expansion: " + ex.getIdentifier()); |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	@EventHandler |  | ||||||
| 	public void onQuit(PlayerQuitEvent e) { |  | ||||||
|  |  | ||||||
| 	    Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions(); |   private PlaceholderAPIPlugin plugin; | ||||||
|  |  | ||||||
| 		if (expansions.isEmpty()) { |   public PlaceholderListener(PlaceholderAPIPlugin instance) { | ||||||
| 			return; |     plugin = instance; | ||||||
| 		} |     Bukkit.getPluginManager().registerEvents(this, instance); | ||||||
| 		 |   } | ||||||
| 		for (PlaceholderExpansion ex : expansions) { |  | ||||||
| 			if (ex instanceof Cleanable) { |   @EventHandler | ||||||
| 				((Cleanable) ex).cleanup(e.getPlayer()); |   public void onExpansionUnregister(ExpansionUnregisterEvent event) { | ||||||
| 			} |  | ||||||
| 		} |     if (event.getExpansion() instanceof Listener) { | ||||||
| 	} |       HandlerList.unregisterAll((Listener) event.getExpansion()); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (event.getExpansion() instanceof Taskable) { | ||||||
|  |       ((Taskable) event.getExpansion()).stop(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (event.getExpansion() instanceof Cacheable) { | ||||||
|  |       ((Cacheable) event.getExpansion()).clear(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (plugin.getExpansionCloud() != null) { | ||||||
|  |  | ||||||
|  |       CloudExpansion ex = plugin.getExpansionCloud() | ||||||
|  |           .getCloudExpansion(event.getExpansion().getName()); | ||||||
|  |  | ||||||
|  |       if (ex != null) { | ||||||
|  |         ex.setHasExpansion(false); | ||||||
|  |         ex.setShouldUpdate(false); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @EventHandler | ||||||
|  |   public void onEnable(PluginEnableEvent event) { | ||||||
|  |     ExpansionManager m = plugin.getExpansionManager(); | ||||||
|  |     PlaceholderExpansion e = m.getCachedExpansion(event.getPlugin().getName().toLowerCase()); | ||||||
|  |     if (e != null && e.canRegister()) { | ||||||
|  |       if (e.isRegistered() || m.registerExpansion(e)) { | ||||||
|  |         m.removeCachedExpansion(e.getRequiredPlugin()); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @EventHandler(priority = EventPriority.HIGH) | ||||||
|  |   public void onPluginUnload(PluginDisableEvent e) { | ||||||
|  |  | ||||||
|  |     String n = e.getPlugin().getName(); | ||||||
|  |  | ||||||
|  |     if (n == null) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (n.equals(plugin.getName())) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders(); | ||||||
|  |  | ||||||
|  |     for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) { | ||||||
|  |  | ||||||
|  |       PlaceholderHook i = hook.getValue(); | ||||||
|  |  | ||||||
|  |       if (i instanceof EZPlaceholderHook) { | ||||||
|  |  | ||||||
|  |         EZPlaceholderHook h = (EZPlaceholderHook) i; | ||||||
|  |  | ||||||
|  |         if (h.getPluginName() == null) { | ||||||
|  |           continue; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (h.getPluginName().equalsIgnoreCase(n)) { | ||||||
|  |           if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) { | ||||||
|  |             plugin.getLogger() | ||||||
|  |                 .info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName()); | ||||||
|  |             break; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } else if (i instanceof PlaceholderExpansion) { | ||||||
|  |  | ||||||
|  |         PlaceholderExpansion ex = (PlaceholderExpansion) i; | ||||||
|  |  | ||||||
|  |         if (ex.getRequiredPlugin() == null) { | ||||||
|  |           continue; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (ex.getRequiredPlugin().equalsIgnoreCase(n)) { | ||||||
|  |           if (PlaceholderAPI.unregisterExpansion(ex)) { | ||||||
|  |             plugin.getLogger().info("Unregistered placeholder expansion: " + ex.getIdentifier()); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @EventHandler | ||||||
|  |   public void onQuit(PlayerQuitEvent e) { | ||||||
|  |  | ||||||
|  |     Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions(); | ||||||
|  |  | ||||||
|  |     if (expansions.isEmpty()) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     for (PlaceholderExpansion ex : expansions) { | ||||||
|  |       if (ex instanceof Cleanable) { | ||||||
|  |         ((Cleanable) ex).cleanup(e.getPlayer()); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,6 +20,12 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi.commands; | package me.clip.placeholderapi.commands; | ||||||
|  |  | ||||||
|  | import static me.clip.placeholderapi.util.Msg.color; | ||||||
|  | import static me.clip.placeholderapi.util.Msg.msg; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Map.Entry; | ||||||
| import me.clip.placeholderapi.PlaceholderAPI; | import me.clip.placeholderapi.PlaceholderAPI; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| @@ -30,367 +36,384 @@ import org.bukkit.command.CommandExecutor; | |||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
| import java.util.Map; |  | ||||||
| import java.util.Map.Entry; |  | ||||||
|  |  | ||||||
| import static me.clip.placeholderapi.util.Msg.color; |  | ||||||
| import static me.clip.placeholderapi.util.Msg.msg; |  | ||||||
|  |  | ||||||
| public class ExpansionCloudCommands implements CommandExecutor { | public class ExpansionCloudCommands implements CommandExecutor { | ||||||
|  |  | ||||||
| 	private PlaceholderAPIPlugin plugin; |   private PlaceholderAPIPlugin plugin; | ||||||
| 	 |  | ||||||
| 	public ExpansionCloudCommands(PlaceholderAPIPlugin instance) { |  | ||||||
| 		plugin = instance; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	@Override |   public ExpansionCloudCommands(PlaceholderAPIPlugin instance) { | ||||||
| 	public boolean onCommand(CommandSender s, Command c, String label, String[] args) { |     plugin = instance; | ||||||
| 		 |   } | ||||||
| 		if (args.length == 1) { |  | ||||||
| 			msg(s, "&bExpansion cloud commands", |  | ||||||
| 			" ", |  | ||||||
| 			"&b/papi ecloud status", |  | ||||||
| 			"&fView status of the ecloud", |  | ||||||
| 			"&b/papi ecloud list <all/author> (page)", |  | ||||||
| 			"&fList all/author specific available expansions", |  | ||||||
| 			"&b/papi ecloud info <expansion name>", |  | ||||||
| 			"&fView information about a specific expansion available on the cloud", |  | ||||||
|             "&b/papi ecloud versioninfo <expansion name> <version>", |  | ||||||
|             "&fView information about a specific version of an expansion", |  | ||||||
|             "&b/papi ecloud placeholders <expansion name>", |  | ||||||
|             "&fView placeholders for an expansion", |  | ||||||
| 			"&b/papi ecloud download <expansion name> (version)", |  | ||||||
| 			"&fDownload an expansion from the ecloud", |  | ||||||
| 			"&b/papi ecloud refresh", |  | ||||||
| 			"&fFetch the most up to date list of expansions available.", |  | ||||||
| 			"&b/papi ecloud clear", |  | ||||||
| 			"&fClear the expansion cloud cache."); |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1].equalsIgnoreCase("fetch")) { |   @Override | ||||||
| 			msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!"); |   public boolean onCommand(CommandSender s, Command c, String label, String[] args) { | ||||||
| 			plugin.getExpansionCloud().clean(); |  | ||||||
| 			plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) { |     if (args.length == 1) { | ||||||
| 			msg(s, "&7No cloud expansions are available at this time."); |       msg(s, "&bExpansion cloud commands", | ||||||
| 			return true; |           " ", | ||||||
| 		} |           "&b/papi ecloud status", | ||||||
|  |           "&fView status of the ecloud", | ||||||
|  |           "&b/papi ecloud list <all/author> (page)", | ||||||
|  |           "&fList all/author specific available expansions", | ||||||
|  |           "&b/papi ecloud info <expansion name>", | ||||||
|  |           "&fView information about a specific expansion available on the cloud", | ||||||
|  |           "&b/papi ecloud versioninfo <expansion name> <version>", | ||||||
|  |           "&fView information about a specific version of an expansion", | ||||||
|  |           "&b/papi ecloud placeholders <expansion name>", | ||||||
|  |           "&fView placeholders for an expansion", | ||||||
|  |           "&b/papi ecloud download <expansion name> (version)", | ||||||
|  |           "&fDownload an expansion from the ecloud", | ||||||
|  |           "&b/papi ecloud refresh", | ||||||
|  |           "&fFetch the most up to date list of expansions available.", | ||||||
|  |           "&b/papi ecloud clear", | ||||||
|  |           "&fClear the expansion cloud cache."); | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
| 		if (args[1].equalsIgnoreCase("clear")) { |     if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1] | ||||||
| 			plugin.getExpansionCloud().clean(); |         .equalsIgnoreCase("fetch")) { | ||||||
| 			msg(s, "&aThe cache has been cleared!!"); |       msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!"); | ||||||
| 			return true; |       plugin.getExpansionCloud().clean(); | ||||||
| 		} |       plugin.getExpansionCloud() | ||||||
|  |           .fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
| 		if (args[1].equalsIgnoreCase("status")) { |     if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) { | ||||||
| 			 |       msg(s, "&7No cloud expansions are available at this time."); | ||||||
| 			msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() + " &bexpansions available on the cloud.", |       return true; | ||||||
| 			"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount() + " &7authors have contributed to the expansion cloud."); |     } | ||||||
| 			if (plugin.getExpansionCloud().getToUpdateCount() > 0) { |  | ||||||
| 				msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount() |  | ||||||
| 						+ " &eexpansions installed that have updates available."); |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (args[1].equalsIgnoreCase("info")) { |     if (args[1].equalsIgnoreCase("clear")) { | ||||||
| 			 |       plugin.getExpansionCloud().clean(); | ||||||
| 			if (args.length < 3) { |       msg(s, "&aThe cache has been cleared!!"); | ||||||
| 				msg(s, "&cAn expansion name must be specified!"); |       return true; | ||||||
| 				return true; |     } | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); |  | ||||||
| 			 |  | ||||||
| 			if (expansion == null) { |  | ||||||
| 				msg(s, "&cNo expansion found by the name: &f" + args[2]); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			if (!(s instanceof Player)) { |  | ||||||
| 				msg(s, (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion.getVersion().getUrl()); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			Player p = (Player) s; |  | ||||||
| 			 |  | ||||||
| 			msg(s, "&bExpansion&7: &f" + expansion.getName(), |  | ||||||
| 					"&bAuthor: &f" + expansion.getAuthor(), |  | ||||||
| 					"&bVerified: &f" + expansion.isVerified() |  | ||||||
| 			); |  | ||||||
|  |  | ||||||
| 			// latest version |     if (args[1].equalsIgnoreCase("status")) { | ||||||
|             JSONMessage latestVersion = JSONMessage.create(color("&bLatest version: &f" + expansion.getLatestVersion())); |  | ||||||
|             latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate() |  | ||||||
|                     + "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes() |  | ||||||
|             )); |  | ||||||
|             latestVersion.send(p); |  | ||||||
|  |  | ||||||
| 			// versions |       msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() | ||||||
|             JSONMessage versions = JSONMessage.create(color("&bVersions available: &f" + expansion.getVersions().size())); |               + " &bexpansions available on the cloud.", | ||||||
|             versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions()))); |           "&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount() | ||||||
|             versions.suggestCommand("/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion()); |               + " &7authors have contributed to the expansion cloud."); | ||||||
|             versions.send(p); |       if (plugin.getExpansionCloud().getToUpdateCount() > 0) { | ||||||
|  |         msg(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount() | ||||||
|  |             + " &eexpansions installed that have updates available."); | ||||||
|  |       } | ||||||
|  |  | ||||||
|             // placeholders |       return true; | ||||||
|             if (expansion.getPlaceholders() != null) { |     } | ||||||
|                 JSONMessage placeholders = JSONMessage.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size())); |  | ||||||
|                 placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders()))); |     if (args[1].equalsIgnoreCase("info")) { | ||||||
|                 placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName()); |  | ||||||
|                 placeholders.send(p); |       if (args.length < 3) { | ||||||
|  |         msg(s, "&cAn expansion name must be specified!"); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); | ||||||
|  |  | ||||||
|  |       if (expansion == null) { | ||||||
|  |         msg(s, "&cNo expansion found by the name: &f" + args[2]); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (!(s instanceof Player)) { | ||||||
|  |         msg(s, | ||||||
|  |             (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion | ||||||
|  |                 .getVersion().getUrl()); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       Player p = (Player) s; | ||||||
|  |  | ||||||
|  |       msg(s, "&bExpansion&7: &f" + expansion.getName(), | ||||||
|  |           "&bAuthor: &f" + expansion.getAuthor(), | ||||||
|  |           "&bVerified: &f" + expansion.isVerified() | ||||||
|  |       ); | ||||||
|  |  | ||||||
|  |       // latest version | ||||||
|  |       JSONMessage latestVersion = JSONMessage | ||||||
|  |           .create(color("&bLatest version: &f" + expansion.getLatestVersion())); | ||||||
|  |       latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate() | ||||||
|  |           + "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes() | ||||||
|  |       )); | ||||||
|  |       latestVersion.send(p); | ||||||
|  |  | ||||||
|  |       // versions | ||||||
|  |       JSONMessage versions = JSONMessage | ||||||
|  |           .create(color("&bVersions available: &f" + expansion.getVersions().size())); | ||||||
|  |       versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions()))); | ||||||
|  |       versions.suggestCommand( | ||||||
|  |           "/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion()); | ||||||
|  |       versions.send(p); | ||||||
|  |  | ||||||
|  |       // placeholders | ||||||
|  |       if (expansion.getPlaceholders() != null) { | ||||||
|  |         JSONMessage placeholders = JSONMessage | ||||||
|  |             .create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size())); | ||||||
|  |         placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders()))); | ||||||
|  |         placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName()); | ||||||
|  |         placeholders.send(p); | ||||||
|  |       } | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (args[1].equalsIgnoreCase("versioninfo")) { | ||||||
|  |  | ||||||
|  |       if (args.length < 4) { | ||||||
|  |         msg(s, "&cAn expansion name and version must be specified!"); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); | ||||||
|  |  | ||||||
|  |       if (expansion == null) { | ||||||
|  |         msg(s, "&cNo expansion found by the name: &f" + args[2]); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       CloudExpansion.Version version = expansion.getVersion(args[3]); | ||||||
|  |  | ||||||
|  |       if (version == null) { | ||||||
|  |         msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName()); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       msg(s, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(), | ||||||
|  |           "&bVersion: &f" + version.getVersion(), | ||||||
|  |           "&bVersion info: &f" + version.getReleaseNotes()); | ||||||
|  |  | ||||||
|  |       if (!(s instanceof Player)) { | ||||||
|  |         msg(s, "&bDownload url: " + version.getUrl()); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       Player p = (Player) s; | ||||||
|  |  | ||||||
|  |       JSONMessage download = JSONMessage.create(color("&7Click to download this version")); | ||||||
|  |       download.suggestCommand( | ||||||
|  |           "/papi ecloud download " + expansion.getName() + " " + version.getVersion()); | ||||||
|  |       download.send(p); | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (args[1].equalsIgnoreCase("placeholders")) { | ||||||
|  |  | ||||||
|  |       if (args.length < 3) { | ||||||
|  |         msg(s, "&cAn expansion name must be specified!"); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); | ||||||
|  |  | ||||||
|  |       if (expansion == null) { | ||||||
|  |         msg(s, "&cNo expansion found by the name: &f" + args[2]); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       List<String> placeholders = expansion.getPlaceholders(); | ||||||
|  |  | ||||||
|  |       if (placeholders == null) { | ||||||
|  |         msg(s, "&cThe expansion: &f" + expansion.getName() | ||||||
|  |                 + " &cdoes not have any placeholders listed.", | ||||||
|  |             "&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added."); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (!(s instanceof Player) | ||||||
|  |           || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) { | ||||||
|  |         msg(s, "&bPlaceholders: &f" + placeholders.size(), | ||||||
|  |             String.join("&a, &f", placeholders)); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       Player p = (Player) s; | ||||||
|  |       JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size())); | ||||||
|  |       message.then("\n"); | ||||||
|  |  | ||||||
|  |       for (int i = 0; i < placeholders.size(); i++) { | ||||||
|  |         if (i == placeholders.size() - 1) { | ||||||
|  |           message.then(placeholders.get(i)); | ||||||
|  |         } else { | ||||||
|  |           message.then(color(placeholders.get(i) + "&b, &f")); | ||||||
|  |         } | ||||||
|  |         message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i))); | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       message.send(p); | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (args[1].equalsIgnoreCase("list")) { | ||||||
|  |  | ||||||
|  |       int page = 1; | ||||||
|  |  | ||||||
|  |       String author; | ||||||
|  |       boolean installed = false; | ||||||
|  |  | ||||||
|  |       if (args.length < 3) { | ||||||
|  |         msg(s, "&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)"); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       author = args[2]; | ||||||
|  |  | ||||||
|  |       if (author.equalsIgnoreCase("all")) { | ||||||
|  |         author = null; | ||||||
|  |       } else if (author.equalsIgnoreCase("installed")) { | ||||||
|  |         author = null; | ||||||
|  |         installed = true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (args.length >= 4) { | ||||||
|  |         try { | ||||||
|  |           page = Integer.parseInt(args[3]); | ||||||
|  |         } catch (NumberFormatException ex) { | ||||||
|  |           msg(s, "&cPage number must be an integer!"); | ||||||
|  |           return true; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (page < 1) { | ||||||
|  |         msg(s, "&cPage must be greater than or equal to 1!"); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       int avail; | ||||||
|  |  | ||||||
|  |       Map<Integer, CloudExpansion> ex; | ||||||
|  |  | ||||||
|  |       if (installed) { | ||||||
|  |         ex = plugin.getExpansionCloud().getAllInstalled(); | ||||||
|  |       } else if (author == null) { | ||||||
|  |         ex = plugin.getExpansionCloud().getCloudExpansions(); | ||||||
|  |       } else { | ||||||
|  |         ex = plugin.getExpansionCloud().getAllByAuthor(author); | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (ex == null || ex.isEmpty()) { | ||||||
|  |         msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : "")); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10); | ||||||
|  |  | ||||||
|  |       if (page > avail) { | ||||||
|  |         msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!" | ||||||
|  |             : "are only &f" + avail + " &cpages available!")); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       msg(s, "&bShowing expansions for&7: &f" + (author != null ? author | ||||||
|  |           : (installed ? "all installed" : "all available")) + " &8&m--&r &bamount&7: &f" + ex | ||||||
|  |           .size() + " &bpage&7: &f" + page + "&7/&f" + avail); | ||||||
|  |  | ||||||
|  |       ex = plugin.getExpansionCloud().getPage(ex, page, 10); | ||||||
|  |  | ||||||
|  |       if (ex == null) { | ||||||
|  |         msg(s, "&cThere was a problem getting the requested page..."); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       msg(s, "&aGreen = Expansions you have"); | ||||||
|  |       msg(s, "&6Gold = Expansions which need updated"); | ||||||
|  |  | ||||||
|  |       if (!(s instanceof Player)) { | ||||||
|  |  | ||||||
|  |         for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) { | ||||||
|  |             if (expansion == null || expansion.getValue() == null) { | ||||||
|  |                 continue; | ||||||
|             } |             } | ||||||
| 			return true; |           msg(s, | ||||||
| 		} |               "&b" + (expansion.getKey() + 1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" | ||||||
|  |                   : (expansion.getValue().hasExpansion() ? "&a" : "&7")) + expansion.getValue() | ||||||
|         if (args[1].equalsIgnoreCase("versioninfo")) { |                   .getName() + " &8&m-- &r" + expansion.getValue().getVersion().getUrl()); | ||||||
|  |  | ||||||
|             if (args.length < 4) { |  | ||||||
|                 msg(s, "&cAn expansion name and version must be specified!"); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); |  | ||||||
|  |  | ||||||
|             if (expansion == null) { |  | ||||||
|                 msg(s, "&cNo expansion found by the name: &f" + args[2]); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             CloudExpansion.Version version = expansion.getVersion(args[3]); |  | ||||||
|  |  | ||||||
|             if (version == null) { |  | ||||||
|                 msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName()); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             msg(s, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(), |  | ||||||
|                     "&bVersion: &f" + version.getVersion(), |  | ||||||
|                     "&bVersion info: &f" + version.getReleaseNotes()); |  | ||||||
|  |  | ||||||
|             if (!(s instanceof Player)) { |  | ||||||
|                 msg(s, "&bDownload url: " + version.getUrl()); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             Player p = (Player) s; |  | ||||||
|  |  | ||||||
|             JSONMessage download = JSONMessage.create(color("&7Click to download this version")); |  | ||||||
|             download.suggestCommand("/papi ecloud download " + expansion.getName() + " " + version.getVersion()); |  | ||||||
|             download.send(p); |  | ||||||
|             return true; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (args[1].equalsIgnoreCase("placeholders")) { |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|             if (args.length < 3) { |       Player p = (Player) s; | ||||||
|                 msg(s, "&cAn expansion name must be specified!"); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); |       for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) { | ||||||
|  |  | ||||||
|             if (expansion == null) { |         if (expansion == null || expansion.getValue() == null) { | ||||||
|                 msg(s, "&cNo expansion found by the name: &f" + args[2]); |           continue; | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             List<String> placeholders = expansion.getPlaceholders(); |  | ||||||
|  |  | ||||||
|             if (placeholders == null) { |  | ||||||
|                 msg(s, "&cThe expansion: &f" + expansion.getName() + " &cdoes not have any placeholders listed.", |  | ||||||
|                         "&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added."); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (!(s instanceof Player) || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) { |  | ||||||
|                 msg(s, "&bPlaceholders: &f" + placeholders.size(), |  | ||||||
|                         String.join("&a, &f", placeholders)); |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             Player p = (Player) s; |  | ||||||
|             JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size())); |  | ||||||
|             message.then("\n"); |  | ||||||
|  |  | ||||||
|             for (int i = 0 ; i < placeholders.size() ; i++) { |  | ||||||
|                 if (i == placeholders.size()-1) { |  | ||||||
|                     message.then(placeholders.get(i)); |  | ||||||
|                 } else { |  | ||||||
|                     message.then(color(placeholders.get(i) + "&b, &f")); |  | ||||||
|                 } |  | ||||||
|                 message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i))); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             message.send(p); |  | ||||||
|             return true; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (args[1].equalsIgnoreCase("list")) { |         StringBuilder sb = new StringBuilder(); | ||||||
| 			 |         if (expansion.getValue().shouldUpdate()) { | ||||||
| 			int page = 1; |           sb.append("&6Click to update to the latest version of this expansion\n\n"); | ||||||
| 			 |         } else if (!expansion.getValue().hasExpansion()) { | ||||||
| 			String author; |           sb.append("&bClick to download this expansion\n\n"); | ||||||
| 			boolean installed = false; |         } else { | ||||||
| 			 |           sb.append("&aYou have the latest version of this expansion\n\n"); | ||||||
| 			if (args.length < 3) { |         } | ||||||
| 				msg(s, "&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)"); |         sb.append("&bAuthor&7: &f" + expansion.getValue().getAuthor() + "\n"); | ||||||
| 				return true; |         sb.append("&bVerified&7: &f" + expansion.getValue().isVerified() + "\n"); | ||||||
| 			} |         sb.append("&bLatest version&7: &f" + expansion.getValue().getVersion().getVersion() + "\n"); | ||||||
| 			 |         sb.append( | ||||||
| 			author = args[2]; |             "&bLast updated&7: &f" + expansion.getValue().getTimeSinceLastUpdate() + " ago\n"); | ||||||
| 			 |         sb.append("\n" + expansion.getValue().getDescription()); | ||||||
| 			if (author.equalsIgnoreCase("all")) { |  | ||||||
| 				author = null; |  | ||||||
| 			} else if (author.equalsIgnoreCase("installed")) { |  | ||||||
| 				author = null; |  | ||||||
| 				installed = true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			if (args.length >= 4) { |  | ||||||
| 				try { |  | ||||||
| 					page = Integer.parseInt(args[3]); |  | ||||||
| 				} catch (NumberFormatException ex) { |  | ||||||
| 					msg(s, "&cPage number must be an integer!"); |  | ||||||
| 					return true; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			if (page < 1) { |  | ||||||
| 				msg(s, "&cPage must be greater than or equal to 1!"); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			int avail; |  | ||||||
| 			 |  | ||||||
| 			Map<Integer, CloudExpansion> ex; |  | ||||||
| 			 |  | ||||||
| 			if (installed) { |  | ||||||
| 				ex = plugin.getExpansionCloud().getAllInstalled(); |  | ||||||
| 			} else if (author == null) { |  | ||||||
| 				ex = plugin.getExpansionCloud().getCloudExpansions(); |  | ||||||
| 			} else { |  | ||||||
| 				ex = plugin.getExpansionCloud().getAllByAuthor(author); |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			if (ex == null || ex.isEmpty()) { |  | ||||||
| 				msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : "")); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10); |  | ||||||
| 			 |  | ||||||
| 			if (page > avail) { |  | ||||||
| 				msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!" : "are only &f" + avail + " &cpages available!")); |  | ||||||
| 				return true; |  | ||||||
| 			}			 |  | ||||||
| 			 |  | ||||||
| 			msg(s, "&bShowing expansions for&7: &f" + (author != null ? author : (installed ? "all installed" : "all available"))+ " &8&m--&r &bamount&7: &f" + ex.size() + " &bpage&7: &f" + page + "&7/&f" + avail); |  | ||||||
| 			 |  | ||||||
| 			ex = plugin.getExpansionCloud().getPage(ex, page, 10); |  | ||||||
| 			 |  | ||||||
| 			if (ex == null) { |  | ||||||
| 				msg(s, "&cThere was a problem getting the requested page..."); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			msg(s, "&aGreen = Expansions you have"); |  | ||||||
| 			msg(s, "&6Gold = Expansions which need updated"); |  | ||||||
| 			 |  | ||||||
| 			if (!(s instanceof Player)) { |  | ||||||
| 				 |  | ||||||
| 				for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) { |  | ||||||
| 					if (expansion == null || expansion.getValue() == null) continue; |  | ||||||
| 					msg(s, "&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "&7")) + expansion.getValue().getName() + " &8&m-- &r" + expansion.getValue().getVersion().getUrl()); |  | ||||||
| 				} |  | ||||||
| 				 |  | ||||||
| 				return true; |  | ||||||
| 			}   |  | ||||||
| 			 |  | ||||||
| 			Player p = (Player) s; |  | ||||||
| 			 |  | ||||||
| 			for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) { |  | ||||||
| 				 |  | ||||||
| 				if (expansion == null || expansion.getValue() == null) { |  | ||||||
| 					continue; |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
|                 StringBuilder sb = new StringBuilder(); |         String msg = color( | ||||||
|                 if (expansion.getValue().shouldUpdate()) { |             "&b" + (expansion.getKey() + 1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" | ||||||
|                     sb.append("&6Click to update to the latest version of this expansion\n\n"); |                 : (expansion.getValue().hasExpansion() ? "&a" : "")) + expansion.getValue() | ||||||
|                 } else if (!expansion.getValue().hasExpansion()) { |                 .getName()); | ||||||
|                     sb.append("&bClick to download this expansion\n\n"); |  | ||||||
|                 } else { |  | ||||||
|                     sb.append("&aYou have the latest version of this expansion\n\n"); |  | ||||||
|                 } |  | ||||||
|                 sb.append("&bAuthor&7: &f" + expansion.getValue().getAuthor() + "\n"); |  | ||||||
|                 sb.append("&bVerified&7: &f" + expansion.getValue().isVerified() + "\n"); |  | ||||||
|                 sb.append("&bLatest version&7: &f" + expansion.getValue().getVersion().getVersion() + "\n"); |  | ||||||
|                 sb.append("&bLast updated&7: &f" + expansion.getValue().getTimeSinceLastUpdate() + " ago\n"); |  | ||||||
|                 sb.append("\n" + expansion.getValue().getDescription()); |  | ||||||
|  |  | ||||||
|                 String msg = color("&b" + (expansion.getKey()+1) + "&7: " + (expansion.getValue().shouldUpdate() ? "&6" : (expansion.getValue().hasExpansion() ? "&a" : "")) + expansion.getValue().getName()); |         String hover = color(sb.toString()); | ||||||
|  |  | ||||||
|                 String hover = color(sb.toString()); |         JSONMessage line = JSONMessage.create(msg); | ||||||
|  |         line.tooltip(hover); | ||||||
|  |         line.suggestCommand("/papi ecloud info " + expansion.getValue().getName()); | ||||||
|  |         line.send(p); | ||||||
|  |       } | ||||||
|  |  | ||||||
|                 JSONMessage line = JSONMessage.create(msg); |       return true; | ||||||
|                 line.tooltip(hover); |     } | ||||||
|                 line.suggestCommand("/papi ecloud info " + expansion.getValue().getName()); |  | ||||||
|                 line.send(p); |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		 |  | ||||||
| 		if (args[1].equalsIgnoreCase("download")) { |  | ||||||
| 			 |  | ||||||
| 			if (args.length < 3) { |  | ||||||
| 				msg(s, "&cAn expansion name must be specified!"); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); |  | ||||||
| 			 |  | ||||||
| 			if (expansion == null) { |  | ||||||
| 				msg(s, "&cNo expansion found with the name: &f" + args[2]); |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 			PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]); |  | ||||||
| 			 |  | ||||||
| 			if (loaded != null && loaded.isRegistered()) { |  | ||||||
| 				PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier()); |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			String version = expansion.getLatestVersion(); |     if (args[1].equalsIgnoreCase("download")) { | ||||||
|  |  | ||||||
| 			if (args.length == 4) { |       if (args.length < 3) { | ||||||
| 				version = args[3]; |         msg(s, "&cAn expansion name must be specified!"); | ||||||
| 				if (expansion.getVersion(version) == null) { |         return true; | ||||||
| 					msg(s, "&cThe version you specified does not exist for &f" + expansion.getName()); |       } | ||||||
| 					msg(s, "&7Available versions: &f" + expansion.getVersions().size()); |  | ||||||
| 					msg(s, String.join("&a, &f", expansion.getAvailableVersions())); |       CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); | ||||||
| 					return true; |  | ||||||
| 				} |       if (expansion == null) { | ||||||
| 			} |         msg(s, "&cNo expansion found with the name: &f" + args[2]); | ||||||
|  |         return true; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]); | ||||||
|  |  | ||||||
|  |       if (loaded != null && loaded.isRegistered()) { | ||||||
|  |         PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier()); | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       String version = expansion.getLatestVersion(); | ||||||
|  |  | ||||||
|  |       if (args.length == 4) { | ||||||
|  |         version = args[3]; | ||||||
|  |         if (expansion.getVersion(version) == null) { | ||||||
|  |           msg(s, "&cThe version you specified does not exist for &f" + expansion.getName()); | ||||||
|  |           msg(s, "&7Available versions: &f" + expansion.getVersions().size()); | ||||||
|  |           msg(s, String.join("&a, &f", expansion.getAvailableVersions())); | ||||||
|  |           return true; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" | ||||||
|  |           + version); | ||||||
|  |       String player = ((s instanceof Player) ? s.getName() : null); | ||||||
|  |       plugin.getExpansionCloud().downloadExpansion(player, expansion, version); | ||||||
|  |       return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     msg(s, "&cIncorrect usage! &b/papi ecloud"); | ||||||
|  |     return true; | ||||||
|  |   } | ||||||
|  |  | ||||||
| 			msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version); |  | ||||||
| 			String player = ((s instanceof Player) ? s.getName() : null); |  | ||||||
| 			plugin.getExpansionCloud().downloadExpansion(player, expansion, version); |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		msg(s, "&cIncorrect usage! &b/papi ecloud"); |  | ||||||
| 		return true; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
|  |  | ||||||
| 	 |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -24,43 +24,43 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin; | |||||||
|  |  | ||||||
| public class PlaceholderAPIConfig { | public class PlaceholderAPIConfig { | ||||||
|  |  | ||||||
| 	private PlaceholderAPIPlugin plugin; |   private PlaceholderAPIPlugin plugin; | ||||||
| 	 |  | ||||||
| 	public PlaceholderAPIConfig(PlaceholderAPIPlugin i) { |  | ||||||
| 		plugin = i; |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public void loadDefConfig() { |  | ||||||
| 		plugin.saveDefaultConfig(); |  | ||||||
| 		plugin.reloadConfig(); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	public boolean checkUpdates() { |  | ||||||
| 		return plugin.getConfig().getBoolean("check_updates"); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public boolean cloudAllowUnverifiedExpansions() { |   public PlaceholderAPIConfig(PlaceholderAPIPlugin i) { | ||||||
| 		return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions"); |     plugin = i; | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public boolean isCloudEnabled() { |   public void loadDefConfig() { | ||||||
| 		return plugin.getConfig().getBoolean("cloud_enabled"); |     plugin.saveDefaultConfig(); | ||||||
| 	} |     plugin.reloadConfig(); | ||||||
| 	 |   } | ||||||
| 	public void setCloudEnabled(boolean b) { |  | ||||||
| 		plugin.getConfig().set("cloud_enabled", b); |   public boolean checkUpdates() { | ||||||
| 		plugin.reloadConfig(); |     return plugin.getConfig().getBoolean("check_updates"); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String booleanTrue() { |   public boolean cloudAllowUnverifiedExpansions() { | ||||||
| 		return plugin.getConfig().getString("boolean.true"); |     return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions"); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String booleanFalse() { |   public boolean isCloudEnabled() { | ||||||
| 		return plugin.getConfig().getString("boolean.false"); |     return plugin.getConfig().getBoolean("cloud_enabled"); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String dateFormat() { |   public void setCloudEnabled(boolean b) { | ||||||
| 		return plugin.getConfig().getString("date_format"); |     plugin.getConfig().set("cloud_enabled", b); | ||||||
| 	}	 |     plugin.reloadConfig(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String booleanTrue() { | ||||||
|  |     return plugin.getConfig().getString("boolean.true"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String booleanFalse() { | ||||||
|  |     return plugin.getConfig().getString("boolean.false"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String dateFormat() { | ||||||
|  |     return plugin.getConfig().getString("date_format"); | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -26,23 +26,23 @@ import org.bukkit.event.HandlerList; | |||||||
|  |  | ||||||
| public class ExpansionRegisterEvent extends Event { | public class ExpansionRegisterEvent extends Event { | ||||||
|  |  | ||||||
| 	private static final HandlerList HANDLERS = new HandlerList(); |   private static final HandlerList HANDLERS = new HandlerList(); | ||||||
| 	private PlaceholderExpansion expansion; |   private PlaceholderExpansion expansion; | ||||||
|  |  | ||||||
| 	public ExpansionRegisterEvent(PlaceholderExpansion expansion) { |   public ExpansionRegisterEvent(PlaceholderExpansion expansion) { | ||||||
| 		this.expansion = expansion; |     this.expansion = expansion; | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	@Override |   public static HandlerList getHandlerList() { | ||||||
| 	public HandlerList getHandlers() { |     return HANDLERS; | ||||||
| 		return HANDLERS; |   } | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public static HandlerList getHandlerList() { |   @Override | ||||||
| 		return HANDLERS; |   public HandlerList getHandlers() { | ||||||
| 	} |     return HANDLERS; | ||||||
| 	 |   } | ||||||
| 	public PlaceholderExpansion getExpansion() { |  | ||||||
| 		return expansion; |   public PlaceholderExpansion getExpansion() { | ||||||
| 	} |     return expansion; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,30 +20,29 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi.events; | package me.clip.placeholderapi.events; | ||||||
|  |  | ||||||
| import me.clip.placeholderapi.PlaceholderHook; |  | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| import org.bukkit.event.Event; | import org.bukkit.event.Event; | ||||||
| import org.bukkit.event.HandlerList; | import org.bukkit.event.HandlerList; | ||||||
|  |  | ||||||
| public class ExpansionUnregisterEvent extends Event { | public class ExpansionUnregisterEvent extends Event { | ||||||
|  |  | ||||||
| 	private static final HandlerList HANDLERS = new HandlerList(); |   private static final HandlerList HANDLERS = new HandlerList(); | ||||||
| 	private PlaceholderExpansion expansion; |   private PlaceholderExpansion expansion; | ||||||
|  |  | ||||||
| 	public ExpansionUnregisterEvent(PlaceholderExpansion expansion) { |   public ExpansionUnregisterEvent(PlaceholderExpansion expansion) { | ||||||
| 		this.expansion = expansion; |     this.expansion = expansion; | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	@Override |   public static HandlerList getHandlerList() { | ||||||
| 	public HandlerList getHandlers() { |     return HANDLERS; | ||||||
| 		return HANDLERS; |   } | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public static HandlerList getHandlerList() { |   @Override | ||||||
| 		return HANDLERS; |   public HandlerList getHandlers() { | ||||||
| 	} |     return HANDLERS; | ||||||
| 	 |   } | ||||||
| 	public PlaceholderExpansion getExpansion() { |  | ||||||
| 		return expansion; |   public PlaceholderExpansion getExpansion() { | ||||||
| 	} |     return expansion; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,29 +27,29 @@ import org.bukkit.event.HandlerList; | |||||||
| @Deprecated | @Deprecated | ||||||
| public class PlaceholderHookUnloadEvent extends Event { | public class PlaceholderHookUnloadEvent extends Event { | ||||||
|  |  | ||||||
| 	private static final HandlerList HANDLERS = new HandlerList(); |   private static final HandlerList HANDLERS = new HandlerList(); | ||||||
| 	private String plugin; |   private String plugin; | ||||||
| 	private PlaceholderHook hook; |   private PlaceholderHook hook; | ||||||
|  |  | ||||||
| 	public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) { |   public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) { | ||||||
| 		this.plugin = plugin; |     this.plugin = plugin; | ||||||
| 		this.hook = placeholderHook; |     this.hook = placeholderHook; | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	@Override |   public static HandlerList getHandlerList() { | ||||||
| 	public HandlerList getHandlers() { |     return HANDLERS; | ||||||
| 		return HANDLERS; |   } | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	public static HandlerList getHandlerList() { |   @Override | ||||||
| 		return HANDLERS; |   public HandlerList getHandlers() { | ||||||
| 	} |     return HANDLERS; | ||||||
| 	 |   } | ||||||
| 	public String getHookName() { |  | ||||||
| 		return plugin; |   public String getHookName() { | ||||||
| 	} |     return plugin; | ||||||
| 	 |   } | ||||||
| 	public PlaceholderHook getHook() { |  | ||||||
| 		return hook; |   public PlaceholderHook getHook() { | ||||||
| 	} |     return hook; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,17 +21,16 @@ | |||||||
| package me.clip.placeholderapi.expansion; | package me.clip.placeholderapi.expansion; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} |  * This interface allows a class which extends a {@link PlaceholderExpansion} to have the clear | ||||||
|  * to have the clear method called when the implementing expansion is unregistered |  * method called when the implementing expansion is unregistered from PlaceholderAPI. This is useful | ||||||
|  * from PlaceholderAPI. |  * if we want to do things when the implementing hook is unregistered | ||||||
|  * This is useful if we want to do things when the implementing hook is unregistered |  | ||||||
|  * @author Ryan McCarthy |  | ||||||
|  * |  * | ||||||
|  |  * @author Ryan McCarthy | ||||||
|  */ |  */ | ||||||
| public interface Cacheable { | public interface Cacheable { | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * Called when the implementing class is unregistered from PlaceholderAPI |    * Called when the implementing class is unregistered from PlaceholderAPI | ||||||
| 	 */ |    */ | ||||||
| 	void clear(); |   void clear(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -23,17 +23,18 @@ package me.clip.placeholderapi.expansion; | |||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} |  * This interface allows a class which extends a {@link PlaceholderExpansion} to have the cleanup | ||||||
|  * to have the cleanup method called every time a player leaves the server. |  * method called every time a player leaves the server. This is useful if we want to clean up after | ||||||
|  * This is useful if we want to clean up after the player |  * the player | ||||||
|  * @author Ryan McCarthy |  | ||||||
|  * |  * | ||||||
|  |  * @author Ryan McCarthy | ||||||
|  */ |  */ | ||||||
| public interface Cleanable { | public interface Cleanable { | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * Called when a player leaves the server |    * Called when a player leaves the server | ||||||
| 	 * @param p (@link Player} who left the server |    * | ||||||
| 	 */ |    * @param p (@link Player} who left the server | ||||||
| 	void cleanup(Player p); |    */ | ||||||
|  |   void cleanup(Player p); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -23,19 +23,21 @@ package me.clip.placeholderapi.expansion; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Any {@link PlaceholderExpansion} class which implements configurable will |  * Any {@link PlaceholderExpansion} class which implements configurable will have any options listed | ||||||
|  * have any options listed in the getDefaults map automatically added to the PlaceholderAPI config.yml file |  * in the getDefaults map automatically added to the PlaceholderAPI config.yml file | ||||||
|  * @author Ryan McCarthy |  | ||||||
|  * |  * | ||||||
|  |  * @author Ryan McCarthy | ||||||
|  */ |  */ | ||||||
| public interface Configurable { | public interface Configurable { | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * This method will be called before the implementing class is registered |    * This method will be called before the implementing class is registered to obtain a map of | ||||||
| 	 * to obtain a map of configuration options that the implementing class needs |    * configuration options that the implementing class needs These paths and values will be added to | ||||||
| 	 * These paths and values will be added to the PlaceholderAPI config.yml in the configuration section |    * the PlaceholderAPI config.yml in the configuration section expansions.(placeholder | ||||||
| 	 * expansions.(placeholder identifier).(your key): (your value) |    * identifier).(your key): (your value) | ||||||
| 	 * @return Map of config path / values which need to be added / removed from the PlaceholderAPI config.yml file |    * | ||||||
| 	 */ |    * @return Map of config path / values which need to be added / removed from the PlaceholderAPI | ||||||
| 	Map<String, Object> getDefaults(); |    * config.yml file | ||||||
|  |    */ | ||||||
|  |   Map<String, Object> getDefaults(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -22,36 +22,37 @@ package me.clip.placeholderapi.expansion; | |||||||
|  |  | ||||||
| public enum NMSVersion { | public enum NMSVersion { | ||||||
|  |  | ||||||
| 	UNKNOWN("unknown"), |   UNKNOWN("unknown"), | ||||||
| 	SPIGOT_1_7_R1("v1_7_R1"), |   SPIGOT_1_7_R1("v1_7_R1"), | ||||||
| 	SPIGOT_1_7_R2("v1_7_R2"), |   SPIGOT_1_7_R2("v1_7_R2"), | ||||||
| 	SPIGOT_1_7_R3("v1_7_R3"), |   SPIGOT_1_7_R3("v1_7_R3"), | ||||||
| 	SPIGOT_1_7_R4("v1_7_R4"), |   SPIGOT_1_7_R4("v1_7_R4"), | ||||||
| 	SPIGOT_1_8_R1("v1_8_R1"), |   SPIGOT_1_8_R1("v1_8_R1"), | ||||||
| 	SPIGOT_1_8_R2("v1_8_R2"), |   SPIGOT_1_8_R2("v1_8_R2"), | ||||||
| 	SPIGOT_1_8_R3("v1_8_R3"), |   SPIGOT_1_8_R3("v1_8_R3"), | ||||||
| 	SPIGOT_1_9_R1("v1_9_R1"), |   SPIGOT_1_9_R1("v1_9_R1"), | ||||||
| 	SPIGOT_1_9_R2("v1_9_R2"), |   SPIGOT_1_9_R2("v1_9_R2"), | ||||||
| 	SPIGOT_1_10_R1("v1_10_R1"), |   SPIGOT_1_10_R1("v1_10_R1"), | ||||||
| 	SPIGOT_1_11_R1("v1_11_R1"), |   SPIGOT_1_11_R1("v1_11_R1"), | ||||||
| 	SPIGOT_1_12_R1("v1_12_R1"); |   SPIGOT_1_12_R1("v1_12_R1"); | ||||||
| 	 |  | ||||||
| 	private String version; |   private String version; | ||||||
| 	 |  | ||||||
| 	NMSVersion(String version) { |   NMSVersion(String version) { | ||||||
| 		this.version = version; |     this.version = version; | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String getVersion() { |   public static NMSVersion getVersion(String version) { | ||||||
| 		return version; |     for (NMSVersion v : values()) { | ||||||
| 	} |       if (v.getVersion().equalsIgnoreCase(version)) { | ||||||
| 	 |         return v; | ||||||
| 	public static NMSVersion getVersion(String version) { |       } | ||||||
| 		for (NMSVersion v : values()) { |     } | ||||||
| 			if (v.getVersion().equalsIgnoreCase(version)) { |     return NMSVersion.UNKNOWN; | ||||||
| 				return v; |   } | ||||||
| 			} |  | ||||||
| 		} |   public String getVersion() { | ||||||
| 		return NMSVersion.UNKNOWN; |     return version; | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi.expansion; | package me.clip.placeholderapi.expansion; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
| import me.clip.placeholderapi.PlaceholderAPI; | import me.clip.placeholderapi.PlaceholderAPI; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.PlaceholderHook; | import me.clip.placeholderapi.PlaceholderHook; | ||||||
| @@ -27,39 +28,42 @@ import org.apache.commons.lang.Validate; | |||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.configuration.ConfigurationSection; | import org.bukkit.configuration.ConfigurationSection; | ||||||
|  |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| public abstract class PlaceholderExpansion extends PlaceholderHook { | public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * The name of this expansion |  | ||||||
| 	 * @return {@link #getIdentifier()} by default, name of this expansion if specified |  | ||||||
| 	 */ |  | ||||||
| 	public String getName() { |  | ||||||
| 		return getIdentifier(); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** |  | ||||||
| 	 * The placeholder identifier of this expanion |  | ||||||
| 	 * @return placeholder identifier that is associated with this expansion |  | ||||||
| 	 */ |  | ||||||
| 	public abstract String getIdentifier(); |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * The author of this expansion |  | ||||||
| 	 * @return name of the author for this expansion |  | ||||||
| 	 */ |  | ||||||
| 	public abstract String getAuthor(); |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * The version of this expansion |  | ||||||
| 	 * @return current version of this expansion |  | ||||||
| 	 */ |  | ||||||
| 	public abstract String getVersion(); |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * The name of the plugin that this expansion hooks into. |    * The name of this expansion | ||||||
|    * by default will return the deprecated {@link #getPlugin()} method |    * | ||||||
|  |    * @return {@link #getIdentifier()} by default, name of this expansion if specified | ||||||
|  |    */ | ||||||
|  |   public String getName() { | ||||||
|  |     return getIdentifier(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * The placeholder identifier of this expanion | ||||||
|  |    * | ||||||
|  |    * @return placeholder identifier that is associated with this expansion | ||||||
|  |    */ | ||||||
|  |   public abstract String getIdentifier(); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * The author of this expansion | ||||||
|  |    * | ||||||
|  |    * @return name of the author for this expansion | ||||||
|  |    */ | ||||||
|  |   public abstract String getAuthor(); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * The version of this expansion | ||||||
|  |    * | ||||||
|  |    * @return current version of this expansion | ||||||
|  |    */ | ||||||
|  |   public abstract String getVersion(); | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * The name of the plugin that this expansion hooks into. by default will return the deprecated | ||||||
|  |    * {@link #getPlugin()} method | ||||||
|  |    * | ||||||
|    * @return plugin name that this expansion requires to function |    * @return plugin name that this expansion requires to function | ||||||
|    */ |    */ | ||||||
|   public String getRequiredPlugin() { |   public String getRequiredPlugin() { | ||||||
| @@ -68,95 +72,109 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | |||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * The placeholders associated with this expansion |    * The placeholders associated with this expansion | ||||||
|  |    * | ||||||
|    * @return placeholder list that this expansion provides |    * @return placeholder list that this expansion provides | ||||||
|    */ |    */ | ||||||
|   public List<String> getPlaceholders() { |   public List<String> getPlaceholders() { | ||||||
|     return null; |     return null; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * Expansions that do not use the ecloud and instead register from the dependency should set this to true |    * Expansions that do not use the ecloud and instead register from the dependency should set this | ||||||
| 	 * to ensure that your placeholder expansion is not unregistered when the papi reload command is used |    * to true to ensure that your placeholder expansion is not unregistered when the papi reload | ||||||
| 	 * @return if this expansion should persist through placeholder reloads |    * command is used | ||||||
| 	 */ |    * | ||||||
| 	public boolean persist() { |    * @return if this expansion should persist through placeholder reloads | ||||||
| 		return false; |    */ | ||||||
| 	} |   public boolean persist() { | ||||||
| 	 |     return false; | ||||||
| 	/** |   } | ||||||
| 	 * Check if this placeholder identfier has already been registered |  | ||||||
| 	 * @return true if the identifier for this expansion is already registered |   /** | ||||||
| 	 */ |    * Check if this placeholder identfier has already been registered | ||||||
| 	public boolean isRegistered() { |    * | ||||||
| 		Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); |    * @return true if the identifier for this expansion is already registered | ||||||
| 		return PlaceholderAPI.getRegisteredIdentifiers().contains(getIdentifier()); |    */ | ||||||
| 	} |   public boolean isRegistered() { | ||||||
| 	 |     Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); | ||||||
| 	/** |     return PlaceholderAPI.getRegisteredIdentifiers().contains(getIdentifier()); | ||||||
| 	 * If any requirements need to be checked before this expansion should register, |   } | ||||||
|    * you can check them here |  | ||||||
| 	 * @return true if this hook meets all the requirements to register |   /** | ||||||
| 	 */ |    * If any requirements need to be checked before this expansion should register, you can check | ||||||
| 	public boolean canRegister() { |    * them here | ||||||
| 		return getRequiredPlugin() == null || Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null; |    * | ||||||
| 	} |    * @return true if this hook meets all the requirements to register | ||||||
| 	 |    */ | ||||||
| 	/** |   public boolean canRegister() { | ||||||
| 	 * Attempt to register this PlaceholderExpansion |     return getRequiredPlugin() == null | ||||||
| 	 * @return true if this expansion is now registered with PlaceholderAPI |         || Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null; | ||||||
| 	 */ |   } | ||||||
| 	public boolean register() { |  | ||||||
| 		Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); |   /** | ||||||
| 		return PlaceholderAPI.registerExpansion(this); |    * Attempt to register this PlaceholderExpansion | ||||||
| 	} |    * | ||||||
| 	 |    * @return true if this expansion is now registered with PlaceholderAPI | ||||||
| 	/** |    */ | ||||||
| 	 * Quick getter for the {@link PlaceholderAPIPlugin} instance |   public boolean register() { | ||||||
| 	 * @return {@link PlaceholderAPIPlugin} instance |     Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); | ||||||
| 	 */ |     return PlaceholderAPI.registerExpansion(this); | ||||||
| 	public PlaceholderAPIPlugin getPlaceholderAPI() { |   } | ||||||
| 		return PlaceholderAPIPlugin.getInstance(); |  | ||||||
| 	} |   /** | ||||||
| 	 |    * Quick getter for the {@link PlaceholderAPIPlugin} instance | ||||||
| 	public String getString(String path, String def) { |    * | ||||||
| 		return getPlaceholderAPI().getConfig().getString("expansions." + getIdentifier() + "." + path, def); |    * @return {@link PlaceholderAPIPlugin} instance | ||||||
| 	} |    */ | ||||||
| 	 |   public PlaceholderAPIPlugin getPlaceholderAPI() { | ||||||
| 	public int getInt(String path, int def) { |     return PlaceholderAPIPlugin.getInstance(); | ||||||
| 		return getPlaceholderAPI().getConfig().getInt("expansions." + getIdentifier() + "." + path, def); |   } | ||||||
| 	} |  | ||||||
| 	 |   public String getString(String path, String def) { | ||||||
| 	public long getLong(String path, long def) { |     return getPlaceholderAPI().getConfig() | ||||||
| 		return getPlaceholderAPI().getConfig().getLong("expansions." + getIdentifier() + "." + path, def); |         .getString("expansions." + getIdentifier() + "." + path, def); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public double getDouble(String path, double def) { |   public int getInt(String path, int def) { | ||||||
| 		return getPlaceholderAPI().getConfig().getDouble("expansions." + getIdentifier() + "." + path, def); |     return getPlaceholderAPI().getConfig() | ||||||
| 	}	 |         .getInt("expansions." + getIdentifier() + "." + path, def); | ||||||
| 	 |   } | ||||||
| 	public List<String> getStringList(String path) { |  | ||||||
| 		return getPlaceholderAPI().getConfig().getStringList("expansions." + getIdentifier() + "." + path); |   public long getLong(String path, long def) { | ||||||
| 	} |     return getPlaceholderAPI().getConfig() | ||||||
| 	 |         .getLong("expansions." + getIdentifier() + "." + path, def); | ||||||
| 	public Object get(String path, Object def) { |   } | ||||||
| 		return getPlaceholderAPI().getConfig().get("expansions." + getIdentifier() + "." + path, def); |  | ||||||
| 	} |   public double getDouble(String path, double def) { | ||||||
| 	 |     return getPlaceholderAPI().getConfig() | ||||||
| 	public ConfigurationSection getConfigSection(String path) { |         .getDouble("expansions." + getIdentifier() + "." + path, def); | ||||||
| 		return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier() + "." + path);  |   } | ||||||
| 	} |  | ||||||
| 	 |   public List<String> getStringList(String path) { | ||||||
| 	public ConfigurationSection getConfigSection() { |     return getPlaceholderAPI().getConfig() | ||||||
| 		return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier());  |         .getStringList("expansions." + getIdentifier() + "." + path); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public boolean configurationContains(String path) { |   public Object get(String path, Object def) { | ||||||
| 		return getPlaceholderAPI().getConfig().contains("expansions." + getIdentifier() + "." + path);  |     return getPlaceholderAPI().getConfig().get("expansions." + getIdentifier() + "." + path, def); | ||||||
| 	} |   } | ||||||
|  |  | ||||||
|  |   public ConfigurationSection getConfigSection(String path) { | ||||||
|  |     return getPlaceholderAPI().getConfig() | ||||||
|  |         .getConfigurationSection("expansions." + getIdentifier() + "." + path); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public ConfigurationSection getConfigSection() { | ||||||
|  |     return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier()); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean configurationContains(String path) { | ||||||
|  |     return getPlaceholderAPI().getConfig().contains("expansions." + getIdentifier() + "." + path); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @deprecated  As of versions greater than 2.8.7, use {@link #getRequiredPlugin()} |    * @deprecated As of versions greater than 2.8.7, use {@link #getRequiredPlugin()} | ||||||
|    */ |    */ | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public String getPlugin() { |   public String getPlugin() { | ||||||
| @@ -164,14 +182,18 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @deprecated  As of versions greater than 2.8.7, use the expansion cloud to show a description |    * @deprecated As of versions greater than 2.8.7, use the expansion cloud to show a description | ||||||
|    */ |    */ | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public String getDescription() { return null; } |   public String getDescription() { | ||||||
|  |     return null; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @deprecated  As of versions greater than 2.8.7, use the expansion cloud to display a link |    * @deprecated As of versions greater than 2.8.7, use the expansion cloud to display a link | ||||||
|    */ |    */ | ||||||
|   @Deprecated |   @Deprecated | ||||||
|   public String getLink() { return null; } |   public String getLink() { | ||||||
|  |     return null; | ||||||
|  |   } | ||||||
| } | } | ||||||
| @@ -23,5 +23,6 @@ package me.clip.placeholderapi.expansion; | |||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| public interface Relational { | public interface Relational { | ||||||
| 	String onPlaceholderRequest(Player one, Player two, String identifier); |  | ||||||
|  |   String onPlaceholderRequest(Player one, Player two, String identifier); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -22,16 +22,16 @@ package me.clip.placeholderapi.expansion; | |||||||
|  |  | ||||||
|  |  | ||||||
| public interface Taskable { | public interface Taskable { | ||||||
| 	 |  | ||||||
| 	/** |   /** | ||||||
| 	 * Called when the implementing class has successfully been registered to the placeholder map |    * Called when the implementing class has successfully been registered to the placeholder map | ||||||
| 	 * Tasks that need to be performed when this expansion is registered should go here |    * Tasks that need to be performed when this expansion is registered should go here | ||||||
| 	 */ |    */ | ||||||
| 	void start(); |   void start(); | ||||||
| 	 |  | ||||||
| 	/** |   /** | ||||||
| 	 * Called when the implementing class has been unregistered from PlaceholderAPI |    * Called when the implementing class has been unregistered from PlaceholderAPI Tasks that need to | ||||||
| 	 * Tasks that need to be performed when this expansion has unregistered should go here |    * be performed when this expansion has unregistered should go here | ||||||
| 	 */ |    */ | ||||||
| 	void stop(); |   void stop(); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,19 +21,20 @@ | |||||||
| package me.clip.placeholderapi.expansion; | package me.clip.placeholderapi.expansion; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Placeholder expansions which use NMS code should be version specific. |  * Placeholder expansions which use NMS code should be version specific. Implementing this class | ||||||
|  * Implementing this class allows you to perform checks based on the version the server is running.  |  * allows you to perform checks based on the version the server is running. The isCompatibleWith | ||||||
|  * The isCompatibleWith method will be passed the server version and allow you to return if your expansion is compatible with that version. |  * method will be passed the server version and allow you to return if your expansion is compatible | ||||||
|  * @author Ryan McCarthy |  * with that version. | ||||||
|  * |  * | ||||||
|  |  * @author Ryan McCarthy | ||||||
|  */ |  */ | ||||||
| public interface VersionSpecific { | public interface VersionSpecific { | ||||||
|  |  | ||||||
| 	/** |   /** | ||||||
| 	 * This method is called before the expansion is attempted to be registered |    * This method is called before the expansion is attempted to be registered The server version | ||||||
| 	 * The server version will be passed to this method so you know what version the server is currently running. |    * will be passed to this method so you know what version the server is currently running. | ||||||
| 	 *  |    * | ||||||
| 	 * @return true if your expansion is compatible with the version the server is running. |    * @return true if your expansion is compatible with the version the server is running. | ||||||
| 	 */ |    */ | ||||||
| 	boolean isCompatibleWith(Version v); |   boolean isCompatibleWith(Version v); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,183 +20,183 @@ | |||||||
|  */ |  */ | ||||||
| package me.clip.placeholderapi.expansion.cloud; | package me.clip.placeholderapi.expansion.cloud; | ||||||
|  |  | ||||||
| import me.clip.placeholderapi.util.TimeUtil; |  | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  | import me.clip.placeholderapi.util.TimeUtil; | ||||||
|  |  | ||||||
|  |  | ||||||
| public class CloudExpansion { | public class CloudExpansion { | ||||||
|  |  | ||||||
| 	private String name, |   private String name, | ||||||
|             author, |       author, | ||||||
|             latest_version, |       latest_version, | ||||||
|             description, |       description, | ||||||
|             source_url, |       source_url, | ||||||
|             dependency_url; |       dependency_url; | ||||||
|  |  | ||||||
| 	private boolean hasExpansion, |   private boolean hasExpansion, | ||||||
|             shouldUpdate, |       shouldUpdate, | ||||||
|             verified; |       verified; | ||||||
|  |  | ||||||
| 	private long last_update, |   private long last_update, | ||||||
|             ratings_count; |       ratings_count; | ||||||
|  |  | ||||||
| 	private double average_rating; |   private double average_rating; | ||||||
|  |  | ||||||
| 	private List<String> placeholders; |   private List<String> placeholders; | ||||||
|  |  | ||||||
| 	private List<Version> versions; |   private List<Version> versions; | ||||||
|  |  | ||||||
| 	public CloudExpansion() { |   public CloudExpansion() { | ||||||
| 	} |   } | ||||||
|  |  | ||||||
| 	public String getTimeSinceLastUpdate() { |   public String getTimeSinceLastUpdate() { | ||||||
| 		int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate()); |     int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate()); | ||||||
| 		return TimeUtil.getTime(time); |     return TimeUtil.getTime(time); | ||||||
| 	} |   } | ||||||
|  |  | ||||||
|     public String getName() { |   public String getName() { | ||||||
|         return name; |     return name; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setName(String name) { | ||||||
|  |     this.name = name; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getAuthor() { | ||||||
|  |     return author; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setAuthor(String author) { | ||||||
|  |     this.author = author; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public Version getVersion() { | ||||||
|  |     return getLatestVersion() == null ? null : getVersion(getLatestVersion()); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public Version getVersion(String version) { | ||||||
|  |     return versions == null ? null : versions.stream() | ||||||
|  |         .filter(v -> v.getVersion().equals(version)) | ||||||
|  |         .findFirst() | ||||||
|  |         .orElse(null); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public List<String> getAvailableVersions() { | ||||||
|  |     return versions.stream().map(Version::getVersion).collect(Collectors.toList()); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getLatestVersion() { | ||||||
|  |     return latest_version; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setLatestVersion(String latest_version) { | ||||||
|  |     this.latest_version = latest_version; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getDescription() { | ||||||
|  |     return description; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setDescription(String description) { | ||||||
|  |     this.description = description; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getSourceUrl() { | ||||||
|  |     return source_url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setSourceUrl(String source_url) { | ||||||
|  |     this.source_url = source_url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getDependencyUrl() { | ||||||
|  |     return dependency_url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setDependencyUrl(String dependency_url) { | ||||||
|  |     this.dependency_url = dependency_url; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean hasExpansion() { | ||||||
|  |     return hasExpansion; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setHasExpansion(boolean hasExpansion) { | ||||||
|  |     this.hasExpansion = hasExpansion; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean shouldUpdate() { | ||||||
|  |     return shouldUpdate; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setShouldUpdate(boolean shouldUpdate) { | ||||||
|  |     this.shouldUpdate = shouldUpdate; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean isVerified() { | ||||||
|  |     return verified; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public long getLastUpdate() { | ||||||
|  |     return last_update; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setLastUpdate(long last_update) { | ||||||
|  |     this.last_update = last_update; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public long getRatingsCount() { | ||||||
|  |     return ratings_count; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public double getAverage_rating() { | ||||||
|  |     return average_rating; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public List<String> getPlaceholders() { | ||||||
|  |     return placeholders; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setPlaceholders(List<String> placeholders) { | ||||||
|  |     this.placeholders = placeholders; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public List<Version> getVersions() { | ||||||
|  |     return versions; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void setVersions(List<Version> versions) { | ||||||
|  |     this.versions = versions; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public class Version { | ||||||
|  |  | ||||||
|  |     private String url, version, release_notes; | ||||||
|  |  | ||||||
|  |     public String getUrl() { | ||||||
|  |       return url; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setName(String name) { |     public void setUrl(String url) { | ||||||
|         this.name = name; |       this.url = url; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String getAuthor() { |     public String getVersion() { | ||||||
|         return author; |       return version; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setAuthor(String author) { |     public void setVersion(String version) { | ||||||
|         this.author = author; |       this.version = version; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Version getVersion() { |     public String getReleaseNotes() { | ||||||
| 	    return getLatestVersion() == null ? null : getVersion(getLatestVersion()); |       return release_notes; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Version getVersion(String version) { |     public void setReleaseNotes(String release_notes) { | ||||||
|         return versions == null ? null : versions.stream() |       this.release_notes = release_notes; | ||||||
|                 .filter(v -> v.getVersion().equals(version)) |  | ||||||
|                 .findFirst() |  | ||||||
|                 .orElse(null); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public List<String> getAvailableVersions() { |  | ||||||
|         return versions.stream().map(Version::getVersion).collect(Collectors.toList()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getLatestVersion() { |  | ||||||
|         return latest_version; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setLatestVersion(String latest_version) { |  | ||||||
|         this.latest_version = latest_version; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getDescription() { |  | ||||||
|         return description; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setDescription(String description) { |  | ||||||
|         this.description = description; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getSourceUrl() { |  | ||||||
|         return source_url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setSourceUrl(String source_url) { |  | ||||||
|         this.source_url = source_url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String getDependencyUrl() { |  | ||||||
|         return dependency_url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setDependencyUrl(String dependency_url) { |  | ||||||
|         this.dependency_url = dependency_url; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean hasExpansion() { |  | ||||||
|         return hasExpansion; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setHasExpansion(boolean hasExpansion) { |  | ||||||
|         this.hasExpansion = hasExpansion; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean shouldUpdate() { |  | ||||||
|         return shouldUpdate; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setShouldUpdate(boolean shouldUpdate) { |  | ||||||
|         this.shouldUpdate = shouldUpdate; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public boolean isVerified() { |  | ||||||
|         return verified; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public long getLastUpdate() { |  | ||||||
|         return last_update; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setLastUpdate(long last_update) { |  | ||||||
|         this.last_update = last_update; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public long getRatingsCount() { |  | ||||||
|         return ratings_count; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public double getAverage_rating() { |  | ||||||
|         return average_rating; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public List<String> getPlaceholders() { |  | ||||||
|         return placeholders; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setPlaceholders(List<String> placeholders) { |  | ||||||
|         this.placeholders = placeholders; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public List<Version> getVersions() { |  | ||||||
|         return versions; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setVersions(List<Version> versions) { |  | ||||||
|         this.versions = versions; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public class Version { |  | ||||||
| 	    private String url, version, release_notes; |  | ||||||
|  |  | ||||||
|         public String getUrl() { |  | ||||||
|             return url; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public void setUrl(String url) { |  | ||||||
|             this.url = url; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public String getVersion() { |  | ||||||
|             return version; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public void setVersion(String version) { |  | ||||||
|             this.version = version; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public String getReleaseNotes() { |  | ||||||
|             return release_notes; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public void setReleaseNotes(String release_notes) { |  | ||||||
|             this.release_notes = release_notes; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,6 +21,22 @@ | |||||||
| package me.clip.placeholderapi.expansion.cloud; | package me.clip.placeholderapi.expansion.cloud; | ||||||
|  |  | ||||||
| import com.google.gson.Gson; | import com.google.gson.Gson; | ||||||
|  | import java.io.BufferedReader; | ||||||
|  | import java.io.File; | ||||||
|  | import java.io.FileOutputStream; | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.InputStreamReader; | ||||||
|  | import java.net.HttpURLConnection; | ||||||
|  | import java.net.URL; | ||||||
|  | import java.net.URLConnection; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Comparator; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.TreeMap; | ||||||
|  | import java.util.stream.Collectors; | ||||||
|  | import java.util.stream.IntStream; | ||||||
| import me.clip.placeholderapi.PlaceholderAPI; | import me.clip.placeholderapi.PlaceholderAPI; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| @@ -32,342 +48,346 @@ import org.json.simple.JSONObject; | |||||||
| import org.json.simple.parser.JSONParser; | import org.json.simple.parser.JSONParser; | ||||||
| import org.json.simple.parser.ParseException; | import org.json.simple.parser.ParseException; | ||||||
|  |  | ||||||
| import java.io.*; |  | ||||||
| import java.net.HttpURLConnection; |  | ||||||
| import java.net.URL; |  | ||||||
| import java.net.URLConnection; |  | ||||||
| import java.util.*; |  | ||||||
| import java.util.stream.Collectors; |  | ||||||
| import java.util.stream.IntStream; |  | ||||||
|  |  | ||||||
| public class ExpansionCloudManager { | public class ExpansionCloudManager { | ||||||
|  |  | ||||||
|     private PlaceholderAPIPlugin plugin; |   private final String API = "http://api.extendedclip.com/v2/"; | ||||||
|     private final String API = "http://api.extendedclip.com/v2/"; |   private final File dir; | ||||||
|     private final File dir; |   private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>(); | ||||||
|     private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>(); |   private final List<String> downloading = new ArrayList<>(); | ||||||
|     private final List<String> downloading = new ArrayList<>(); |   private PlaceholderAPIPlugin plugin; | ||||||
|     private Gson gson; |   private Gson gson; | ||||||
|  |  | ||||||
|     public ExpansionCloudManager(PlaceholderAPIPlugin instance) { |   public ExpansionCloudManager(PlaceholderAPIPlugin instance) { | ||||||
|         plugin = instance; |     plugin = instance; | ||||||
|         gson = new Gson(); |     gson = new Gson(); | ||||||
|         dir = new File(instance.getDataFolder() + File.separator + "expansions"); |     dir = new File(instance.getDataFolder() + File.separator + "expansions"); | ||||||
|         if (!dir.exists()) { |     if (!dir.exists()) { | ||||||
|             try { |       try { | ||||||
|                 dir.mkdirs(); |         dir.mkdirs(); | ||||||
|             } catch (Exception ex) { |       } catch (Exception ex) { | ||||||
|                 ex.printStackTrace(); |         ex.printStackTrace(); | ||||||
|             } |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void clean() { | ||||||
|  |     remote.clear(); | ||||||
|  |     downloading.clear(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean isDownloading(String expansion) { | ||||||
|  |     return downloading.contains(expansion); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public Map<Integer, CloudExpansion> getCloudExpansions() { | ||||||
|  |     return remote; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public CloudExpansion getCloudExpansion(String name) { | ||||||
|  |     return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst() | ||||||
|  |         .orElse(null); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public int getCloudAuthorCount() { | ||||||
|  |     return remote.values().stream() | ||||||
|  |         .collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())).size(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public long getToUpdateCount() { | ||||||
|  |     return PlaceholderAPI.getExpansions().stream().filter( | ||||||
|  |         ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()) | ||||||
|  |             .shouldUpdate()).count(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public Map<Integer, CloudExpansion> getAllByAuthor(String author) { | ||||||
|  |     if (remote.isEmpty()) { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |     TreeMap<Integer, CloudExpansion> byAuthor = new TreeMap<>(); | ||||||
|  |     boolean first = true; | ||||||
|  |     for (CloudExpansion ex : remote.values()) { | ||||||
|  |       if (ex.getAuthor().equalsIgnoreCase(author)) { | ||||||
|  |         if (first) { | ||||||
|  |           first = false; | ||||||
|  |           byAuthor.put(0, ex); | ||||||
|  |         } else { | ||||||
|  |           byAuthor.put(byAuthor.lastKey() + 1, ex); | ||||||
|         } |         } | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void clean() { |     if (byAuthor.isEmpty()) { | ||||||
|         remote.clear(); |       return null; | ||||||
|         downloading.clear(); |  | ||||||
|     } |     } | ||||||
|  |     return byAuthor; | ||||||
|  |   } | ||||||
|  |  | ||||||
|     public boolean isDownloading(String expansion) { |   public Map<Integer, CloudExpansion> getAllInstalled() { | ||||||
|         return downloading.contains(expansion); |     if (remote.isEmpty()) { | ||||||
|  |       return null; | ||||||
|     } |     } | ||||||
|  |     TreeMap<Integer, CloudExpansion> has = new TreeMap<>(); | ||||||
|     public Map<Integer, CloudExpansion> getCloudExpansions() { |     boolean first = true; | ||||||
|         return remote; |     for (CloudExpansion ex : remote.values()) { | ||||||
|     } |       if (ex.hasExpansion()) { | ||||||
|  |         if (first) { | ||||||
|     public CloudExpansion getCloudExpansion(String name) { |           first = false; | ||||||
|         return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst().orElse(null); |           has.put(1, ex); | ||||||
|     } |         } else { | ||||||
|  |           has.put(has.lastKey() + 1, ex); | ||||||
|     public int getCloudAuthorCount() { |  | ||||||
|         return remote.values().stream().collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())).size(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public long getToUpdateCount() { |  | ||||||
|         return PlaceholderAPI.getExpansions().stream().filter(ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()).shouldUpdate()).count(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Map<Integer, CloudExpansion> getAllByAuthor(String author) { |  | ||||||
|         if (remote.isEmpty()) { |  | ||||||
|             return null; |  | ||||||
|         } |         } | ||||||
|         TreeMap<Integer, CloudExpansion> byAuthor = new TreeMap<>(); |       } | ||||||
|         boolean first = true; |  | ||||||
|         for (CloudExpansion ex : remote.values()) { |  | ||||||
|             if (ex.getAuthor().equalsIgnoreCase(author)) { |  | ||||||
|                 if (first) { |  | ||||||
|                     first = false; |  | ||||||
|                     byAuthor.put(0, ex); |  | ||||||
|                 } else { |  | ||||||
|                     byAuthor.put(byAuthor.lastKey() + 1, ex); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (byAuthor.isEmpty()) { |  | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|         return byAuthor; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public Map<Integer, CloudExpansion> getAllInstalled() { |     if (has.isEmpty()) { | ||||||
|         if (remote.isEmpty()) { |       return null; | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|         TreeMap<Integer, CloudExpansion> has = new TreeMap<>(); |  | ||||||
|         boolean first = true; |  | ||||||
|         for (CloudExpansion ex : remote.values()) { |  | ||||||
|             if (ex.hasExpansion()) { |  | ||||||
|                 if (first) { |  | ||||||
|                     first = false; |  | ||||||
|                     has.put(1, ex); |  | ||||||
|                 } else { |  | ||||||
|                     has.put(has.lastKey() + 1, ex); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (has.isEmpty()) { |  | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|         return has; |  | ||||||
|     } |     } | ||||||
|  |     return has; | ||||||
|  |   } | ||||||
|  |  | ||||||
|     public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) { |   public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) { | ||||||
|         if (map == null) { |     if (map == null) { | ||||||
|             return 0; |       return 0; | ||||||
|         } |  | ||||||
|         int pages = map.size() > 0 ? 1 : 0; |  | ||||||
|         if (pages == 0) { |  | ||||||
|             return pages; |  | ||||||
|         } |  | ||||||
|         if (map.size() > amount) { |  | ||||||
|             pages = map.size() / amount; |  | ||||||
|             if (map.size() % amount > 0) { |  | ||||||
|                 pages++; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return pages; |  | ||||||
|     } |     } | ||||||
|  |     int pages = map.size() > 0 ? 1 : 0; | ||||||
|     public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, int size) { |     if (pages == 0) { | ||||||
|         if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) { |       return pages; | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|         int end = size * page; |  | ||||||
|         int start = end - size; |  | ||||||
|         TreeMap<Integer, CloudExpansion> ex = new TreeMap<>(); |  | ||||||
|         IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n))); |  | ||||||
|         return ex; |  | ||||||
|     } |     } | ||||||
|  |     if (map.size() > amount) { | ||||||
|     public void fetch(boolean allowUnverified) { |       pages = map.size() / amount; | ||||||
|  |       if (map.size() % amount > 0) { | ||||||
|         plugin.getLogger().info("Fetching available expansion information..."); |         pages++; | ||||||
|  |       } | ||||||
|         new BukkitRunnable() { |  | ||||||
|  |  | ||||||
|             @Override |  | ||||||
|             public void run() { |  | ||||||
|  |  | ||||||
|                 StringBuilder sb; |  | ||||||
|  |  | ||||||
|                 try { |  | ||||||
|  |  | ||||||
|                     URL site = new URL(API); |  | ||||||
|  |  | ||||||
|                     HttpURLConnection connection = (HttpURLConnection) site.openConnection(); |  | ||||||
|  |  | ||||||
|                     connection.setRequestMethod("GET"); |  | ||||||
|  |  | ||||||
|                     connection.connect(); |  | ||||||
|  |  | ||||||
|                     BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); |  | ||||||
|  |  | ||||||
|                     sb = new StringBuilder(); |  | ||||||
|  |  | ||||||
|                     String line; |  | ||||||
|  |  | ||||||
|                     while ((line = br.readLine()) != null) { |  | ||||||
|                         sb.append(line); |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     br.close(); |  | ||||||
|                     connection.disconnect(); |  | ||||||
|  |  | ||||||
|                 } catch (Exception e) { |  | ||||||
|                     return; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 String json = sb.toString(); |  | ||||||
|                 JSONParser parser = new JSONParser(); |  | ||||||
|                 Object obj = null; |  | ||||||
|  |  | ||||||
|                 try { |  | ||||||
|                     obj = parser.parse(json); |  | ||||||
|                 } catch (ParseException e) { |  | ||||||
|                     e.printStackTrace(); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 if (obj == null) { |  | ||||||
|                     return; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 List<CloudExpansion> unsorted = new ArrayList<>(); |  | ||||||
|  |  | ||||||
|                 if (obj instanceof JSONObject) { |  | ||||||
|  |  | ||||||
|                     JSONObject jo = (JSONObject) obj; |  | ||||||
|  |  | ||||||
|                     for (Object o : jo.keySet()) { |  | ||||||
|  |  | ||||||
|                         JSONObject sub = (JSONObject) jo.get(o); |  | ||||||
|  |  | ||||||
|                         CloudExpansion ce = gson.fromJson(sub.toJSONString(), CloudExpansion.class); |  | ||||||
|  |  | ||||||
|                         if (!allowUnverified && !ce.isVerified()) { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         if (ce.getLatestVersion() == null || ce.getVersion(ce.getLatestVersion()) == null) { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         ce.setName(o.toString()); |  | ||||||
|  |  | ||||||
|                         PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(ce.getName()); |  | ||||||
|  |  | ||||||
|                         if (ex != null && ex.isRegistered()) { |  | ||||||
|                             ce.setHasExpansion(true); |  | ||||||
|                             if (!ex.getVersion().equals(ce.getLatestVersion())) { |  | ||||||
|                                 ce.setShouldUpdate(true); |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         unsorted.add(ce); |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     int count = 0; |  | ||||||
|  |  | ||||||
|                     unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed()); |  | ||||||
|  |  | ||||||
|                     for (CloudExpansion e : unsorted) { |  | ||||||
|                         remote.put(count, e); |  | ||||||
|                         count++; |  | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     plugin.getLogger().info(count + " placeholder expansions are available on the cloud."); |  | ||||||
|  |  | ||||||
|                     long updates = getToUpdateCount(); |  | ||||||
|  |  | ||||||
|                     if (updates > 0) { |  | ||||||
|                         plugin.getLogger().info(updates + " installed expansions have updates available."); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         }.runTaskAsynchronously(plugin); |  | ||||||
|     } |     } | ||||||
|  |     return pages; | ||||||
|  |   } | ||||||
|  |  | ||||||
|     private void download(URL url, String name) throws IOException { |   public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, | ||||||
|  |       int size) { | ||||||
|  |     if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |     int end = size * page; | ||||||
|  |     int start = end - size; | ||||||
|  |     TreeMap<Integer, CloudExpansion> ex = new TreeMap<>(); | ||||||
|  |     IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n))); | ||||||
|  |     return ex; | ||||||
|  |   } | ||||||
|  |  | ||||||
|         InputStream is = null; |   public void fetch(boolean allowUnverified) { | ||||||
|  |  | ||||||
|         FileOutputStream fos = null; |     plugin.getLogger().info("Fetching available expansion information..."); | ||||||
|  |  | ||||||
|  |     new BukkitRunnable() { | ||||||
|  |  | ||||||
|  |       @Override | ||||||
|  |       public void run() { | ||||||
|  |  | ||||||
|  |         StringBuilder sb; | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|  |  | ||||||
|             URLConnection urlConn = url.openConnection(); |           URL site = new URL(API); | ||||||
|  |  | ||||||
|             is = urlConn.getInputStream(); |           HttpURLConnection connection = (HttpURLConnection) site.openConnection(); | ||||||
|  |  | ||||||
|             fos = new FileOutputStream(dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar"); |           connection.setRequestMethod("GET"); | ||||||
|  |  | ||||||
|             byte[] buffer = new byte[is.available()]; |           connection.connect(); | ||||||
|  |  | ||||||
|             int l; |           BufferedReader br = new BufferedReader( | ||||||
|  |               new InputStreamReader(connection.getInputStream())); | ||||||
|  |  | ||||||
|             while ((l = is.read(buffer)) > 0) { |           sb = new StringBuilder(); | ||||||
|                 fos.write(buffer, 0, l); |  | ||||||
|             } |           String line; | ||||||
|         } finally { |  | ||||||
|             try { |           while ((line = br.readLine()) != null) { | ||||||
|                 if (is != null) { |             sb.append(line); | ||||||
|                     is.close(); |           } | ||||||
|                 } |  | ||||||
|             } finally { |           br.close(); | ||||||
|                 if (fos != null) { |           connection.disconnect(); | ||||||
|                     fos.close(); |  | ||||||
|                 } |         } catch (Exception e) { | ||||||
|             } |           return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         String json = sb.toString(); | ||||||
|  |         JSONParser parser = new JSONParser(); | ||||||
|  |         Object obj = null; | ||||||
|  |  | ||||||
|  |         try { | ||||||
|  |           obj = parser.parse(json); | ||||||
|  |         } catch (ParseException e) { | ||||||
|  |           e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (obj == null) { | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         List<CloudExpansion> unsorted = new ArrayList<>(); | ||||||
|  |  | ||||||
|  |         if (obj instanceof JSONObject) { | ||||||
|  |  | ||||||
|  |           JSONObject jo = (JSONObject) obj; | ||||||
|  |  | ||||||
|  |           for (Object o : jo.keySet()) { | ||||||
|  |  | ||||||
|  |             JSONObject sub = (JSONObject) jo.get(o); | ||||||
|  |  | ||||||
|  |             CloudExpansion ce = gson.fromJson(sub.toJSONString(), CloudExpansion.class); | ||||||
|  |  | ||||||
|  |             if (!allowUnverified && !ce.isVerified()) { | ||||||
|  |               continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (ce.getLatestVersion() == null || ce.getVersion(ce.getLatestVersion()) == null) { | ||||||
|  |               continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             ce.setName(o.toString()); | ||||||
|  |  | ||||||
|  |             PlaceholderExpansion ex = plugin.getExpansionManager() | ||||||
|  |                 .getRegisteredExpansion(ce.getName()); | ||||||
|  |  | ||||||
|  |             if (ex != null && ex.isRegistered()) { | ||||||
|  |               ce.setHasExpansion(true); | ||||||
|  |               if (!ex.getVersion().equals(ce.getLatestVersion())) { | ||||||
|  |                 ce.setShouldUpdate(true); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             unsorted.add(ce); | ||||||
|  |           } | ||||||
|  |  | ||||||
|  |           int count = 0; | ||||||
|  |  | ||||||
|  |           unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed()); | ||||||
|  |  | ||||||
|  |           for (CloudExpansion e : unsorted) { | ||||||
|  |             remote.put(count, e); | ||||||
|  |             count++; | ||||||
|  |           } | ||||||
|  |  | ||||||
|  |           plugin.getLogger().info(count + " placeholder expansions are available on the cloud."); | ||||||
|  |  | ||||||
|  |           long updates = getToUpdateCount(); | ||||||
|  |  | ||||||
|  |           if (updates > 0) { | ||||||
|  |             plugin.getLogger().info(updates + " installed expansions have updates available."); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }.runTaskAsynchronously(plugin); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   private void download(URL url, String name) throws IOException { | ||||||
|  |  | ||||||
|  |     InputStream is = null; | ||||||
|  |  | ||||||
|  |     FileOutputStream fos = null; | ||||||
|  |  | ||||||
|  |     try { | ||||||
|  |  | ||||||
|  |       URLConnection urlConn = url.openConnection(); | ||||||
|  |  | ||||||
|  |       is = urlConn.getInputStream(); | ||||||
|  |  | ||||||
|  |       fos = new FileOutputStream( | ||||||
|  |           dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar"); | ||||||
|  |  | ||||||
|  |       byte[] buffer = new byte[is.available()]; | ||||||
|  |  | ||||||
|  |       int l; | ||||||
|  |  | ||||||
|  |       while ((l = is.read(buffer)) > 0) { | ||||||
|  |         fos.write(buffer, 0, l); | ||||||
|  |       } | ||||||
|  |     } finally { | ||||||
|  |       try { | ||||||
|  |         if (is != null) { | ||||||
|  |           is.close(); | ||||||
|  |         } | ||||||
|  |       } finally { | ||||||
|  |         if (fos != null) { | ||||||
|  |           fos.close(); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void downloadExpansion(final String player, final CloudExpansion ex) { | ||||||
|  |     downloadExpansion(player, ex, ex.getLatestVersion()); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void downloadExpansion(final String player, final CloudExpansion ex, | ||||||
|  |       final String version) { | ||||||
|  |  | ||||||
|  |     if (downloading.contains(ex.getName())) { | ||||||
|  |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void downloadExpansion(final String player, final CloudExpansion ex) { |     final CloudExpansion.Version ver = ex.getVersions() | ||||||
|         downloadExpansion(player, ex, ex.getLatestVersion()); |         .stream() | ||||||
|  |         .filter(v -> v.getVersion().equals(version)) | ||||||
|  |         .findFirst() | ||||||
|  |         .orElse(null); | ||||||
|  |  | ||||||
|  |     if (ver == null) { | ||||||
|  |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void downloadExpansion(final String player, final CloudExpansion ex, final String version) { |     downloading.add(ex.getName()); | ||||||
|  |  | ||||||
|         if (downloading.contains(ex.getName())) { |     plugin.getLogger().info( | ||||||
|             return; |         "Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " | ||||||
|         } |             + player : "") + " from url: " + ver.getUrl()); | ||||||
|  |  | ||||||
|         final CloudExpansion.Version ver = ex.getVersions() |     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||||||
|                 .stream() |  | ||||||
|                 .filter(v -> v.getVersion().equals(version)) |  | ||||||
|                 .findFirst() |  | ||||||
|                 .orElse(null); |  | ||||||
|  |  | ||||||
|         if (ver == null) { |       try { | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         downloading.add(ex.getName()); |         download(new URL(ver.getUrl()), ex.getName()); | ||||||
|  |  | ||||||
|         plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl()); |         plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!"); | ||||||
|  |  | ||||||
|         Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { |       } catch (Exception e) { | ||||||
|  |  | ||||||
|             try { |         plugin.getLogger() | ||||||
|  |             .warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl()); | ||||||
|  |  | ||||||
|                 download(new URL(ver.getUrl()), ex.getName()); |         Bukkit.getScheduler().runTask(plugin, () -> { | ||||||
|  |  | ||||||
|                 plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!"); |           downloading.remove(ex.getName()); | ||||||
|  |  | ||||||
|             } catch (Exception e) { |           if (player != null) { | ||||||
|  |             Player p = Bukkit.getPlayer(player); | ||||||
|  |  | ||||||
|                 plugin.getLogger().warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl()); |             if (p != null) { | ||||||
|  |               Msg.msg(p, "&cThere was a problem downloading expansion: &f" + ex.getName()); | ||||||
|                 Bukkit.getScheduler().runTask(plugin, () -> { |  | ||||||
|  |  | ||||||
|                     downloading.remove(ex.getName()); |  | ||||||
|  |  | ||||||
|                     if (player != null) { |  | ||||||
|                         Player p = Bukkit.getPlayer(player); |  | ||||||
|  |  | ||||||
|                         if (p != null) { |  | ||||||
|                             Msg.msg(p, "&cThere was a problem downloading expansion: &f" + ex.getName()); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 }); |  | ||||||
|  |  | ||||||
|                 return; |  | ||||||
|             } |             } | ||||||
|  |           } | ||||||
|             Bukkit.getScheduler().runTask(plugin, () -> { |  | ||||||
|  |  | ||||||
|                 downloading.remove(ex.getName()); |  | ||||||
|  |  | ||||||
|                 if (player != null) { |  | ||||||
|  |  | ||||||
|                     Player p = Bukkit.getPlayer(player); |  | ||||||
|  |  | ||||||
|                     if (p != null) { |  | ||||||
|                         Msg.msg(p, "&aExpansion &f" + ex.getName() + " &adownload complete!"); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|         }); |         }); | ||||||
|     } |  | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       Bukkit.getScheduler().runTask(plugin, () -> { | ||||||
|  |  | ||||||
|  |         downloading.remove(ex.getName()); | ||||||
|  |  | ||||||
|  |         if (player != null) { | ||||||
|  |  | ||||||
|  |           Player p = Bukkit.getPlayer(player); | ||||||
|  |  | ||||||
|  |           if (p != null) { | ||||||
|  |             Msg.msg(p, "&aExpansion &f" + ex.getName() + " &adownload complete!"); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |  | ||||||
|  |     }); | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -28,30 +28,30 @@ import org.bukkit.plugin.Plugin; | |||||||
| @Deprecated | @Deprecated | ||||||
| public abstract class EZPlaceholderHook extends PlaceholderHook { | public abstract class EZPlaceholderHook extends PlaceholderHook { | ||||||
|  |  | ||||||
| 	private String identifier; |   private String identifier; | ||||||
| 	 |  | ||||||
| 	private String plugin; |   private String plugin; | ||||||
| 	 |  | ||||||
| 	public EZPlaceholderHook(Plugin plugin, String identifier) { |   public EZPlaceholderHook(Plugin plugin, String identifier) { | ||||||
| 		Validate.notNull(plugin, "Plugin can not be null!"); |     Validate.notNull(plugin, "Plugin can not be null!"); | ||||||
| 		Validate.notNull(identifier, "Placeholder name can not be null!"); |     Validate.notNull(identifier, "Placeholder name can not be null!"); | ||||||
| 		this.identifier = identifier; |     this.identifier = identifier; | ||||||
| 		this.plugin = plugin.getName(); |     this.plugin = plugin.getName(); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public boolean isHooked() { |   public boolean isHooked() { | ||||||
| 		return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier); |     return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public boolean hook() { |   public boolean hook() { | ||||||
| 		return PlaceholderAPI.registerPlaceholderHook(identifier, this); |     return PlaceholderAPI.registerPlaceholderHook(identifier, this); | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String getPlaceholderName() { |   public String getPlaceholderName() { | ||||||
| 		return identifier; |     return identifier; | ||||||
| 	} |   } | ||||||
| 	 |  | ||||||
| 	public String getPluginName() { |   public String getPluginName() { | ||||||
| 		return plugin; |     return plugin; | ||||||
| 	} |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,5 +1,9 @@ | |||||||
| package me.clip.placeholderapi.updatechecker; | package me.clip.placeholderapi.updatechecker; | ||||||
|  |  | ||||||
|  | import java.io.BufferedReader; | ||||||
|  | import java.io.InputStreamReader; | ||||||
|  | import java.net.URL; | ||||||
|  | import javax.net.ssl.HttpsURLConnection; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.util.Msg; | import me.clip.placeholderapi.util.Msg; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| @@ -8,77 +12,82 @@ import org.bukkit.event.EventPriority; | |||||||
| import org.bukkit.event.Listener; | import org.bukkit.event.Listener; | ||||||
| import org.bukkit.event.player.PlayerJoinEvent; | import org.bukkit.event.player.PlayerJoinEvent; | ||||||
|  |  | ||||||
| import javax.net.ssl.HttpsURLConnection; |  | ||||||
| import java.io.BufferedReader; |  | ||||||
| import java.io.InputStreamReader; |  | ||||||
| import java.net.URL; |  | ||||||
|  |  | ||||||
| public class UpdateChecker implements Listener { | public class UpdateChecker implements Listener { | ||||||
|  |  | ||||||
| 	private PlaceholderAPIPlugin plugin; |   private final int RESOURCE_ID = 6245; | ||||||
|     private final int RESOURCE_ID = 6245; |   private PlaceholderAPIPlugin plugin; | ||||||
|     private String spigotVersion, pluginVersion; |   private String spigotVersion, pluginVersion; | ||||||
|     private boolean updateAvailable; |   private boolean updateAvailable; | ||||||
|  |  | ||||||
|     public UpdateChecker(PlaceholderAPIPlugin i) { |   public UpdateChecker(PlaceholderAPIPlugin i) { | ||||||
|     	plugin = i; |     plugin = i; | ||||||
|         pluginVersion = i.getDescription().getVersion(); |     pluginVersion = i.getDescription().getVersion(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public boolean hasUpdateAvailable() { | ||||||
|  |     return updateAvailable; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public String getSpigotVersion() { | ||||||
|  |     return spigotVersion; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public void fetch() { | ||||||
|  |     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||||||
|  |       try { | ||||||
|  |         HttpsURLConnection con = (HttpsURLConnection) new URL( | ||||||
|  |             "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); | ||||||
|  |         con.setRequestMethod("GET"); | ||||||
|  |         spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); | ||||||
|  |       } catch (Exception ex) { | ||||||
|  |         plugin.getLogger().info("Failed to check for updates on spigot."); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (spigotVersion == null || spigotVersion.isEmpty()) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       updateAvailable = spigotIsNewer(); | ||||||
|  |  | ||||||
|  |       if (!updateAvailable) { | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       Bukkit.getScheduler().runTask(plugin, () -> { | ||||||
|  |         plugin.getLogger() | ||||||
|  |             .info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:"); | ||||||
|  |         plugin.getLogger() | ||||||
|  |             .info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/"); | ||||||
|  |         Bukkit.getPluginManager().registerEvents(this, plugin); | ||||||
|  |       }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   private boolean spigotIsNewer() { | ||||||
|  |       if (spigotVersion == null || spigotVersion.isEmpty()) { | ||||||
|  |           return false; | ||||||
|  |       } | ||||||
|  |     String plV = toReadable(pluginVersion); | ||||||
|  |     String spV = toReadable(spigotVersion); | ||||||
|  |     return plV.compareTo(spV) < 0; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   private String toReadable(String version) { | ||||||
|  |     if (version.contains("-DEV-")) { | ||||||
|  |       version = version.split("-DEV-")[0]; | ||||||
|     } |     } | ||||||
|  |     return version.replaceAll("\\.", ""); | ||||||
|  |   } | ||||||
|  |  | ||||||
|     public boolean hasUpdateAvailable() { return updateAvailable; } |   @EventHandler(priority = EventPriority.MONITOR) | ||||||
|  |   public void onJoin(PlayerJoinEvent e) { | ||||||
|     public String getSpigotVersion() { |     if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) { | ||||||
|         return spigotVersion; |       Msg.msg(e.getPlayer(), | ||||||
|     } |           "&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion() | ||||||
|  |               + "&e)" | ||||||
|     public void fetch() { |           , "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID | ||||||
|         Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { |               + "/"); | ||||||
|             try { |  | ||||||
|                 HttpsURLConnection con = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); |  | ||||||
|                 con.setRequestMethod("GET"); |  | ||||||
|                 spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); |  | ||||||
|             } catch (Exception ex) { |  | ||||||
|                 plugin.getLogger().info("Failed to check for updates on spigot."); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (spigotVersion == null || spigotVersion.isEmpty()) { |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             updateAvailable = spigotIsNewer(); |  | ||||||
|  |  | ||||||
|             if (!updateAvailable) { |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             Bukkit.getScheduler().runTask(plugin, () -> { |  | ||||||
|                     plugin.getLogger().info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:"); |  | ||||||
|                     plugin.getLogger().info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/"); |  | ||||||
|                     Bukkit.getPluginManager().registerEvents(this, plugin); |  | ||||||
|             }); |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private boolean spigotIsNewer() { |  | ||||||
|         if (spigotVersion == null || spigotVersion.isEmpty()) return false; |  | ||||||
|         String plV = toReadable(pluginVersion); |  | ||||||
|         String spV = toReadable(spigotVersion); |  | ||||||
|         return plV.compareTo(spV) < 0; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private String toReadable(String version) { |  | ||||||
|         if (version.contains("-DEV-")) { |  | ||||||
|             version = version.split("-DEV-")[0]; |  | ||||||
|         } |  | ||||||
|         return version.replaceAll("\\.",""); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @EventHandler(priority = EventPriority.MONITOR) |  | ||||||
|     public void onJoin(PlayerJoinEvent e) { |  | ||||||
|         if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) { |  | ||||||
|             Msg.msg(e.getPlayer(), "&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion() + "&e)" |  | ||||||
|             , "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/"); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -22,8 +22,8 @@ package me.clip.placeholderapi.util; | |||||||
|  |  | ||||||
| public enum TimeFormat { | public enum TimeFormat { | ||||||
|  |  | ||||||
| 	DAYS,  |   DAYS, | ||||||
| 	HOURS,  |   HOURS, | ||||||
| 	MINUTES,  |   MINUTES, | ||||||
| 	SECONDS |   SECONDS | ||||||
| } | } | ||||||
|   | |||||||
| @@ -22,141 +22,141 @@ package me.clip.placeholderapi.util; | |||||||
|  |  | ||||||
| public class TimeUtil { | public class TimeUtil { | ||||||
|  |  | ||||||
| 	public static String getRemaining(int seconds, TimeFormat type) { |   public static String getRemaining(int seconds, TimeFormat type) { | ||||||
| 		 |  | ||||||
| 		if (seconds < 60) { |  | ||||||
| 			switch(type) { |  | ||||||
| 			case DAYS: |  | ||||||
| 				return "0"; |  | ||||||
| 			case HOURS: |  | ||||||
| 				return "0"; |  | ||||||
| 			case MINUTES: |  | ||||||
| 				return "0"; |  | ||||||
| 			case SECONDS: |  | ||||||
| 				return String.valueOf(seconds); |  | ||||||
| 			} |  | ||||||
| 			return String.valueOf(seconds); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		int minutes = seconds / 60; |  | ||||||
| 		int s = 60 * minutes; |  | ||||||
| 		int secondsLeft = seconds - s; |  | ||||||
| 		if (minutes < 60) { |  | ||||||
| 			switch(type) { |  | ||||||
| 			case DAYS: |  | ||||||
| 				return "0"; |  | ||||||
| 			case HOURS: |  | ||||||
| 				return "0"; |  | ||||||
| 			case MINUTES: |  | ||||||
| 				return String.valueOf(minutes); |  | ||||||
| 			case SECONDS: |  | ||||||
| 				return String.valueOf(secondsLeft); |  | ||||||
| 			} |  | ||||||
| 			return String.valueOf(seconds); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		if (minutes < 1440) { |  | ||||||
| 			int hours = minutes / 60; |  | ||||||
| 			int inMins = 60 * hours; |  | ||||||
| 			int leftOver = minutes - inMins; |  | ||||||
| 			switch(type) { |  | ||||||
| 			case DAYS: |  | ||||||
| 				return "0"; |  | ||||||
| 			case HOURS: |  | ||||||
| 				return String.valueOf(hours); |  | ||||||
| 			case MINUTES: |  | ||||||
| 				return String.valueOf(leftOver); |  | ||||||
| 			case SECONDS: |  | ||||||
| 				return String.valueOf(secondsLeft); |  | ||||||
| 			} |  | ||||||
| 			return String.valueOf(seconds); |  | ||||||
| 		} |  | ||||||
| 		 |  | ||||||
| 		int days = minutes / 1440; |  | ||||||
| 		int inMins = 1440 * days; |  | ||||||
| 		int leftOver = minutes - inMins; |  | ||||||
| 			 |  | ||||||
| 		if (leftOver < 60) { |  | ||||||
| 			switch (type) { |  | ||||||
| 			case DAYS: |  | ||||||
| 				return String.valueOf(days); |  | ||||||
| 			case HOURS: |  | ||||||
| 				return String.valueOf(0); |  | ||||||
| 			case MINUTES: |  | ||||||
| 				return String.valueOf(leftOver); |  | ||||||
| 			case SECONDS: |  | ||||||
| 				return String.valueOf(secondsLeft); |  | ||||||
| 			} |  | ||||||
| 			return String.valueOf(seconds); |  | ||||||
|  |  | ||||||
| 		} else { |     if (seconds < 60) { | ||||||
| 			int hours = leftOver / 60; |       switch (type) { | ||||||
| 			int hoursInMins = 60 * hours; |         case DAYS: | ||||||
| 			int minsLeft = leftOver - hoursInMins; |           return "0"; | ||||||
| 			switch (type) { |         case HOURS: | ||||||
| 			case DAYS: |           return "0"; | ||||||
| 				return String.valueOf(days); |         case MINUTES: | ||||||
| 			case HOURS: |           return "0"; | ||||||
| 				return String.valueOf(hours); |         case SECONDS: | ||||||
| 			case MINUTES: |           return String.valueOf(seconds); | ||||||
| 				return String.valueOf(minsLeft); |       } | ||||||
| 			case SECONDS: |       return String.valueOf(seconds); | ||||||
| 				return String.valueOf(secondsLeft); |     } | ||||||
| 			} |  | ||||||
| 			return String.valueOf(seconds); |     int minutes = seconds / 60; | ||||||
| 		}	 |     int s = 60 * minutes; | ||||||
| 	} |     int secondsLeft = seconds - s; | ||||||
| 	 |     if (minutes < 60) { | ||||||
| 	public static String getTime(int seconds) { |       switch (type) { | ||||||
| 		 |         case DAYS: | ||||||
| 		if (seconds < 60) { |           return "0"; | ||||||
| 			return seconds+"s"; |         case HOURS: | ||||||
| 		} |           return "0"; | ||||||
| 		 |         case MINUTES: | ||||||
| 		int minutes = seconds / 60; |           return String.valueOf(minutes); | ||||||
| 		int s = 60 * minutes; |         case SECONDS: | ||||||
| 		int secondsLeft = seconds - s; |           return String.valueOf(secondsLeft); | ||||||
| 		if (minutes < 60) { |       } | ||||||
| 			if (secondsLeft > 0) { |       return String.valueOf(seconds); | ||||||
| 				return String.valueOf(minutes+"m "+secondsLeft+"s"); |     } | ||||||
| 			} else { |  | ||||||
| 				return String.valueOf(minutes+"m"); |     if (minutes < 1440) { | ||||||
| 			} |       int hours = minutes / 60; | ||||||
| 		} |       int inMins = 60 * hours; | ||||||
| 		if (minutes < 1440) { |       int leftOver = minutes - inMins; | ||||||
| 			String time; |       switch (type) { | ||||||
| 			int hours = minutes / 60; |         case DAYS: | ||||||
| 			time = hours+"h"; |           return "0"; | ||||||
| 			int inMins = 60 * hours; |         case HOURS: | ||||||
| 			int leftOver = minutes - inMins; |           return String.valueOf(hours); | ||||||
| 			if (leftOver >= 1) { |         case MINUTES: | ||||||
| 				time = time+" "+leftOver+"m"; |           return String.valueOf(leftOver); | ||||||
| 			} |         case SECONDS: | ||||||
| 			if (secondsLeft > 0) { |           return String.valueOf(secondsLeft); | ||||||
| 				time = time+" "+secondsLeft+"s"; |       } | ||||||
| 			} |       return String.valueOf(seconds); | ||||||
| 			return time; |     } | ||||||
| 		} |  | ||||||
| 		 |     int days = minutes / 1440; | ||||||
| 		String time; |     int inMins = 1440 * days; | ||||||
| 		int days = minutes / 1440; |     int leftOver = minutes - inMins; | ||||||
| 		time = days+"d"; |  | ||||||
| 		int inMins = 1440 * days; |     if (leftOver < 60) { | ||||||
| 		int leftOver = minutes - inMins; |       switch (type) { | ||||||
| 		if (leftOver >= 1) { |         case DAYS: | ||||||
| 			if (leftOver < 60) { |           return String.valueOf(days); | ||||||
| 				time = time+" "+leftOver+"m"; |         case HOURS: | ||||||
| 			} else { |           return String.valueOf(0); | ||||||
| 				int hours = leftOver / 60; |         case MINUTES: | ||||||
| 				time = time+" "+hours+"h"; |           return String.valueOf(leftOver); | ||||||
| 				int hoursInMins = 60 * hours; |         case SECONDS: | ||||||
| 				int minsLeft = leftOver - hoursInMins; |           return String.valueOf(secondsLeft); | ||||||
| 				time = time+" "+minsLeft+"m"; |       } | ||||||
| 			} |       return String.valueOf(seconds); | ||||||
| 		} |  | ||||||
| 		if (secondsLeft > 0) { |     } else { | ||||||
| 			time = time+" "+secondsLeft+"s"; |       int hours = leftOver / 60; | ||||||
| 		} |       int hoursInMins = 60 * hours; | ||||||
| 		return time; |       int minsLeft = leftOver - hoursInMins; | ||||||
| 	} |       switch (type) { | ||||||
|  |         case DAYS: | ||||||
|  |           return String.valueOf(days); | ||||||
|  |         case HOURS: | ||||||
|  |           return String.valueOf(hours); | ||||||
|  |         case MINUTES: | ||||||
|  |           return String.valueOf(minsLeft); | ||||||
|  |         case SECONDS: | ||||||
|  |           return String.valueOf(secondsLeft); | ||||||
|  |       } | ||||||
|  |       return String.valueOf(seconds); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public static String getTime(int seconds) { | ||||||
|  |  | ||||||
|  |     if (seconds < 60) { | ||||||
|  |       return seconds + "s"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     int minutes = seconds / 60; | ||||||
|  |     int s = 60 * minutes; | ||||||
|  |     int secondsLeft = seconds - s; | ||||||
|  |     if (minutes < 60) { | ||||||
|  |       if (secondsLeft > 0) { | ||||||
|  |         return String.valueOf(minutes + "m " + secondsLeft + "s"); | ||||||
|  |       } else { | ||||||
|  |         return String.valueOf(minutes + "m"); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     if (minutes < 1440) { | ||||||
|  |       String time; | ||||||
|  |       int hours = minutes / 60; | ||||||
|  |       time = hours + "h"; | ||||||
|  |       int inMins = 60 * hours; | ||||||
|  |       int leftOver = minutes - inMins; | ||||||
|  |       if (leftOver >= 1) { | ||||||
|  |         time = time + " " + leftOver + "m"; | ||||||
|  |       } | ||||||
|  |       if (secondsLeft > 0) { | ||||||
|  |         time = time + " " + secondsLeft + "s"; | ||||||
|  |       } | ||||||
|  |       return time; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     String time; | ||||||
|  |     int days = minutes / 1440; | ||||||
|  |     time = days + "d"; | ||||||
|  |     int inMins = 1440 * days; | ||||||
|  |     int leftOver = minutes - inMins; | ||||||
|  |     if (leftOver >= 1) { | ||||||
|  |       if (leftOver < 60) { | ||||||
|  |         time = time + " " + leftOver + "m"; | ||||||
|  |       } else { | ||||||
|  |         int hours = leftOver / 60; | ||||||
|  |         time = time + " " + hours + "h"; | ||||||
|  |         int hoursInMins = 60 * hours; | ||||||
|  |         int minsLeft = leftOver - hoursInMins; | ||||||
|  |         time = time + " " + minsLeft + "m"; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     if (secondsLeft > 0) { | ||||||
|  |       time = time + " " + secondsLeft + "s"; | ||||||
|  |     } | ||||||
|  |     return time; | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user