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" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|     <modelVersion>4.0.0</modelVersion> | ||||
|     <groupId>me.clip</groupId> | ||||
|     <artifactId>placeholderapi</artifactId> | ||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|   xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|   <modelVersion>4.0.0</modelVersion> | ||||
|   <groupId>me.clip</groupId> | ||||
|   <artifactId>placeholderapi</artifactId> | ||||
|  | ||||
|     <version>2.9.1-DEV-${BUILD_NUMBER}</version> | ||||
|     <name>PlaceholderAPI</name> | ||||
|     <description>An awesome placeholder provider!</description> | ||||
|     <url>http://extendedclip.com</url> | ||||
|   <version>2.9.1-DEV-${BUILD_NUMBER}</version> | ||||
|   <name>PlaceholderAPI</name> | ||||
|   <description>An awesome placeholder provider!</description> | ||||
|   <url>http://extendedclip.com</url> | ||||
|  | ||||
|     <properties> | ||||
|         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||
|     </properties> | ||||
|   <properties> | ||||
|     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||
|   </properties> | ||||
|  | ||||
|     <repositories> | ||||
|         <repository> | ||||
|             <id>spigot-repo</id> | ||||
|             <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||||
|         </repository> | ||||
|         <repository> | ||||
|             <id>bstats-repo</id> | ||||
|             <url>http://repo.bstats.org/content/repositories/releases/</url> | ||||
|         </repository> | ||||
|         <repository> | ||||
|             <id>rayzr-repo</id> | ||||
|             <url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url> | ||||
|         </repository> | ||||
|     </repositories> | ||||
|   <repositories> | ||||
|     <repository> | ||||
|       <id>spigot-repo</id> | ||||
|       <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||||
|     </repository> | ||||
|     <repository> | ||||
|       <id>bstats-repo</id> | ||||
|       <url>http://repo.bstats.org/content/repositories/releases/</url> | ||||
|     </repository> | ||||
|     <repository> | ||||
|       <id>rayzr-repo</id> | ||||
|       <url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url> | ||||
|     </repository> | ||||
|   </repositories> | ||||
|  | ||||
|     <dependencies> | ||||
|         <dependency> | ||||
|             <groupId>org.spigotmc</groupId> | ||||
|             <artifactId>spigot-api</artifactId> | ||||
|             <version>1.12.2-R0.1-SNAPSHOT</version> | ||||
|             <scope>provided</scope> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.bstats</groupId> | ||||
|             <artifactId>bstats-bukkit</artifactId> | ||||
|             <version>1.2</version> | ||||
|             <scope>compile</scope> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>me.rayzr522</groupId> | ||||
|             <artifactId>jsonmessage</artifactId> | ||||
|             <version>1.0.0</version> | ||||
|             <scope>compile</scope> | ||||
|         </dependency> | ||||
|     </dependencies> | ||||
|   <dependencies> | ||||
|     <dependency> | ||||
|       <groupId>org.spigotmc</groupId> | ||||
|       <artifactId>spigot-api</artifactId> | ||||
|       <version>1.12.2-R0.1-SNAPSHOT</version> | ||||
|       <scope>provided</scope> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>org.bstats</groupId> | ||||
|       <artifactId>bstats-bukkit</artifactId> | ||||
|       <version>1.2</version> | ||||
|       <scope>compile</scope> | ||||
|     </dependency> | ||||
|     <dependency> | ||||
|       <groupId>me.rayzr522</groupId> | ||||
|       <artifactId>jsonmessage</artifactId> | ||||
|       <version>1.0.0</version> | ||||
|       <scope>compile</scope> | ||||
|     </dependency> | ||||
|   </dependencies> | ||||
|  | ||||
|     <build> | ||||
|         <defaultGoal>clean package</defaultGoal> | ||||
|   <build> | ||||
|     <defaultGoal>clean package</defaultGoal> | ||||
|  | ||||
|         <plugins> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-jar-plugin</artifactId> | ||||
|                 <version>2.3.2</version> | ||||
|                 <configuration> | ||||
|                     <finalName>${project.name}-${project.version}</finalName> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <version>3.7.0</version> | ||||
|                 <configuration> | ||||
|                     <source>1.8</source> | ||||
|                     <target>1.8</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|             <plugin> | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-shade-plugin</artifactId> | ||||
|                 <version>3.1.0</version> | ||||
|                 <executions> | ||||
|                     <execution> | ||||
|                         <phase>package</phase> | ||||
|                         <goals> | ||||
|                             <goal>shade</goal> | ||||
|                         </goals> | ||||
|                         <configuration> | ||||
|                             <minimizeJar>false</minimizeJar> | ||||
|                             <createDependencyReducedPom>false</createDependencyReducedPom> | ||||
|                             <relocations> | ||||
|                                 <relocation> | ||||
|                                     <pattern>org.bstats</pattern> | ||||
|                                     <shadedPattern>me.clip.placeholderapi.metrics</shadedPattern> | ||||
|                                 </relocation> | ||||
|                                 <relocation> | ||||
|                                     <pattern>me.rayzr522</pattern> | ||||
|                                     <shadedPattern>me.clip.placeholderapi.util</shadedPattern> | ||||
|                                 </relocation> | ||||
|                             </relocations> | ||||
|                         </configuration> | ||||
|                     </execution> | ||||
|                 </executions> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|         <resources> | ||||
|             <resource> | ||||
|                 <directory>src/main/resources</directory> | ||||
|                 <filtering>true</filtering> | ||||
|             </resource> | ||||
|         </resources> | ||||
|     </build> | ||||
|     <plugins> | ||||
|       <plugin> | ||||
|         <groupId>org.apache.maven.plugins</groupId> | ||||
|         <artifactId>maven-jar-plugin</artifactId> | ||||
|         <version>2.3.2</version> | ||||
|         <configuration> | ||||
|           <finalName>${project.name}-${project.version}</finalName> | ||||
|         </configuration> | ||||
|       </plugin> | ||||
|       <plugin> | ||||
|         <groupId>org.apache.maven.plugins</groupId> | ||||
|         <artifactId>maven-compiler-plugin</artifactId> | ||||
|         <version>3.7.0</version> | ||||
|         <configuration> | ||||
|           <source>1.8</source> | ||||
|           <target>1.8</target> | ||||
|         </configuration> | ||||
|       </plugin> | ||||
|       <plugin> | ||||
|         <groupId>org.apache.maven.plugins</groupId> | ||||
|         <artifactId>maven-shade-plugin</artifactId> | ||||
|         <version>3.1.0</version> | ||||
|         <executions> | ||||
|           <execution> | ||||
|             <phase>package</phase> | ||||
|             <goals> | ||||
|               <goal>shade</goal> | ||||
|             </goals> | ||||
|             <configuration> | ||||
|               <minimizeJar>false</minimizeJar> | ||||
|               <createDependencyReducedPom>false</createDependencyReducedPom> | ||||
|               <relocations> | ||||
|                 <relocation> | ||||
|                   <pattern>org.bstats</pattern> | ||||
|                   <shadedPattern>me.clip.placeholderapi.metrics</shadedPattern> | ||||
|                 </relocation> | ||||
|                 <relocation> | ||||
|                   <pattern>me.rayzr522</pattern> | ||||
|                   <shadedPattern>me.clip.placeholderapi.util</shadedPattern> | ||||
|                 </relocation> | ||||
|               </relocations> | ||||
|             </configuration> | ||||
|           </execution> | ||||
|         </executions> | ||||
|       </plugin> | ||||
|     </plugins> | ||||
|     <resources> | ||||
|       <resource> | ||||
|         <directory>src/main/resources</directory> | ||||
|         <filtering>true</filtering> | ||||
|       </resource> | ||||
|     </resources> | ||||
|   </build> | ||||
| </project> | ||||
|   | ||||
| @@ -46,8 +46,10 @@ public class PlaceholderAPI { | ||||
|  | ||||
|   private static final Pattern 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 PlaceholderAPI() { | ||||
|   } | ||||
|  | ||||
| @@ -374,21 +376,21 @@ public class PlaceholderAPI { | ||||
|  | ||||
|   @Deprecated | ||||
|   public static String setPlaceholders(Player p, String text) { | ||||
|     return setPlaceholders((OfflinePlayer)p, text, PLACEHOLDER_PATTERN); | ||||
|     return setPlaceholders((OfflinePlayer) p, text, PLACEHOLDER_PATTERN); | ||||
|   } | ||||
|  | ||||
|   @Deprecated | ||||
|   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 | ||||
|   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 | ||||
|   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; | ||||
|  | ||||
| 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.configuration.PlaceholderAPIConfig; | ||||
| import me.clip.placeholderapi.expansion.ExpansionManager; | ||||
| @@ -34,235 +38,223 @@ import org.bukkit.ChatColor; | ||||
| import org.bukkit.command.CommandSender; | ||||
| 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... | ||||
|  *  | ||||
|  * @author Ryan McCarthy | ||||
|  * | ||||
|  * @author Ryan McCarthy | ||||
|  */ | ||||
| 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 | ||||
| 	public void onLoad() { | ||||
| 		startTime = System.currentTimeMillis(); | ||||
| 		instance = this; | ||||
| 		serverVersion = getVersion(); | ||||
| 		config = new PlaceholderAPIConfig(this); | ||||
| 		expansionManager = new ExpansionManager(this); | ||||
| 	} | ||||
|   @Override | ||||
|   public void onDisable() { | ||||
|     disableCloud(); | ||||
|     PlaceholderAPI.unregisterAll(); | ||||
|     expansionManager.clean(); | ||||
|     expansionManager = null; | ||||
|     Bukkit.getScheduler().cancelTasks(this); | ||||
|     serverVersion = null; | ||||
|     instance = null; | ||||
|   } | ||||
|  | ||||
| 	@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(); | ||||
| 	} | ||||
|   public void reloadConf(CommandSender s) { | ||||
|     boolean cloudEnabled = this.expansionCloud != null; | ||||
|     expansionManager.clean(); | ||||
|     PlaceholderAPI.unregisterAllProvidedExpansions(); | ||||
|     reloadConfig(); | ||||
|     setupOptions(); | ||||
|     expansionManager.registerAllExpansions(); | ||||
|     if (!config.isCloudEnabled()) { | ||||
|       disableCloud(); | ||||
|     } else if (!cloudEnabled) { | ||||
|       enableCloud(); | ||||
|     } | ||||
|     s.sendMessage(ChatColor.translateAlternateColorCodes('&', | ||||
|         PlaceholderAPI.getRegisteredIdentifiers().size() | ||||
|             + " &aplaceholder hooks successfully registered!")); | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public void onDisable() { | ||||
| 		disableCloud(); | ||||
| 		PlaceholderAPI.unregisterAll(); | ||||
| 		expansionManager.clean(); | ||||
| 		expansionManager = null; | ||||
| 		Bukkit.getScheduler().cancelTasks(this); | ||||
| 		serverVersion = null; | ||||
| 		instance = null; | ||||
| 	} | ||||
|   private void setupOptions() { | ||||
|     booleanTrue = config.booleanTrue(); | ||||
|     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"); | ||||
|     } | ||||
|   } | ||||
|  | ||||
| 	public void reloadConf(CommandSender s) { | ||||
| 		boolean cloudEnabled = this.expansionCloud != null; | ||||
| 		expansionManager.clean(); | ||||
| 		PlaceholderAPI.unregisterAllProvidedExpansions(); | ||||
| 		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 setupMetrics() { | ||||
|     Metrics m = new Metrics(this); | ||||
|     m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", | ||||
|         () -> getExpansionCloud() != null ? "yes" : "no")); | ||||
|  | ||||
| 	private void setupOptions() { | ||||
| 		booleanTrue = config.booleanTrue(); | ||||
| 		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"); | ||||
| 		} | ||||
| 	} | ||||
|     m.addCustomChart( | ||||
|         new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); | ||||
|  | ||||
| 	private void setupMetrics() { | ||||
| 		Metrics m = new Metrics(this); | ||||
| 	    m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getExpansionCloud() != null ? "yes" : "no")); | ||||
| 		 | ||||
| 	    m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no")); | ||||
|     m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> { | ||||
|       Map<String, Integer> map = new HashMap<>(); | ||||
|       Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders(); | ||||
|  | ||||
| 	    m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> { | ||||
|             Map<String, Integer> map = new HashMap<>(); | ||||
|             Map<String, PlaceholderHook> p = PlaceholderAPI.getPlaceholders(); | ||||
|       if (!p.isEmpty()) { | ||||
|  | ||||
|             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() { | ||||
| 		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); | ||||
| 	} | ||||
|   public void disableCloud() { | ||||
|     if (expansionCloud != null) { | ||||
|       expansionCloud.clean(); | ||||
|       expansionCloud = null; | ||||
|     } | ||||
|   } | ||||
|  | ||||
| 	public void enableCloud() { | ||||
| 		if (expansionCloud == null) { | ||||
| 			expansionCloud = new ExpansionCloudManager(this); | ||||
| 			expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); | ||||
| 		} else { | ||||
| 			expansionCloud.clean(); | ||||
| 			expansionCloud.fetch(config.cloudAllowUnverifiedExpansions()); | ||||
| 		} | ||||
| 	} | ||||
|   /** | ||||
|    * Obtain the configuration class for PlaceholderAPI. | ||||
|    * | ||||
|    * @return PlaceholderAPIConfig instance | ||||
|    */ | ||||
|   public PlaceholderAPIConfig getPlaceholderAPIConfig() { | ||||
|     return config; | ||||
|   } | ||||
|  | ||||
| 	public void disableCloud() { | ||||
| 		if (expansionCloud != null) { | ||||
| 			expansionCloud.clean(); | ||||
| 			expansionCloud = null; | ||||
| 		} | ||||
| 	} | ||||
|   public ExpansionManager getExpansionManager() { | ||||
|     return 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; | ||||
| 	} | ||||
|   public ExpansionCloudManager getExpansionCloud() { | ||||
|     return 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"); | ||||
| 	} | ||||
|   public String getUptime() { | ||||
|     return TimeUtil | ||||
|         .getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)); | ||||
|   } | ||||
|  | ||||
| 	/** | ||||
| 	 * 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"; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * 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); | ||||
| 	} | ||||
|   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 | ||||
|    * @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 | ||||
|    * @return value for the requested player and params | ||||
|    */ | ||||
| 	public String onRequest(OfflinePlayer p, String params) { | ||||
| 		if (p != null && p.isOnline()) { | ||||
| 			return onPlaceholderRequest((Player) p, params); | ||||
| 		} | ||||
| 		return onPlaceholderRequest(null, params); | ||||
| 	} | ||||
|   public String onRequest(OfflinePlayer p, String params) { | ||||
|     if (p != null && p.isOnline()) { | ||||
|       return onPlaceholderRequest((Player) p, params); | ||||
|     } | ||||
|     return onPlaceholderRequest(null, params); | ||||
|   } | ||||
|  | ||||
| 	/** | ||||
| 	 * 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 | ||||
| 	 * @return value for the requested player and params | ||||
| 	 */ | ||||
| 	public String onPlaceholderRequest(Player p, String params) { | ||||
| 		return null; | ||||
| 	} | ||||
|   /** | ||||
|    * 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 | ||||
|    * @return value for the requested player and params | ||||
|    */ | ||||
|   public String onPlaceholderRequest(Player p, String params) { | ||||
|     return null; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -20,9 +20,15 @@ | ||||
|  */ | ||||
| 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.PlaceholderHookUnloadEvent; | ||||
| import me.clip.placeholderapi.expansion.*; | ||||
| import me.clip.placeholderapi.expansion.Cacheable; | ||||
| 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.external.EZPlaceholderHook; | ||||
| 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.PluginEnableEvent; | ||||
|  | ||||
| import java.util.Map; | ||||
| import java.util.Map.Entry; | ||||
| import java.util.Set; | ||||
|  | ||||
|  | ||||
| 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()) { | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		for (PlaceholderExpansion ex : expansions) { | ||||
| 			if (ex instanceof Cleanable) { | ||||
| 				((Cleanable) ex).cleanup(e.getPlayer()); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   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(); | ||||
|  | ||||
|     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; | ||||
|  | ||||
| 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.PlaceholderAPIPlugin; | ||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||
| @@ -30,367 +36,384 @@ import org.bukkit.command.CommandExecutor; | ||||
| import org.bukkit.command.CommandSender; | ||||
| 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 { | ||||
|  | ||||
| 	private PlaceholderAPIPlugin plugin; | ||||
| 	 | ||||
| 	public ExpansionCloudCommands(PlaceholderAPIPlugin instance) { | ||||
| 		plugin = instance; | ||||
| 	} | ||||
|   private PlaceholderAPIPlugin plugin; | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean onCommand(CommandSender s, Command c, String label, String[] args) { | ||||
| 		 | ||||
| 		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; | ||||
| 		} | ||||
|   public ExpansionCloudCommands(PlaceholderAPIPlugin instance) { | ||||
|     plugin = instance; | ||||
|   } | ||||
|  | ||||
| 		if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1].equalsIgnoreCase("fetch")) { | ||||
| 			msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!"); | ||||
| 			plugin.getExpansionCloud().clean(); | ||||
| 			plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); | ||||
| 			return true; | ||||
| 		} | ||||
|   @Override | ||||
|   public boolean onCommand(CommandSender s, Command c, String label, String[] args) { | ||||
|  | ||||
| 		if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) { | ||||
| 			msg(s, "&7No cloud expansions are available at this time."); | ||||
| 			return true; | ||||
| 		} | ||||
|     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("clear")) { | ||||
| 			plugin.getExpansionCloud().clean(); | ||||
| 			msg(s, "&aThe cache has been cleared!!"); | ||||
| 			return true; | ||||
| 		} | ||||
|     if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1] | ||||
|         .equalsIgnoreCase("fetch")) { | ||||
|       msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!"); | ||||
|       plugin.getExpansionCloud().clean(); | ||||
|       plugin.getExpansionCloud() | ||||
|           .fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 		if (args[1].equalsIgnoreCase("status")) { | ||||
| 			 | ||||
| 			msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() + " &bexpansions available on the cloud.", | ||||
| 			"&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 (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) { | ||||
|       msg(s, "&7No cloud expansions are available at this time."); | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 		if (args[1].equalsIgnoreCase("info")) { | ||||
| 			 | ||||
| 			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() | ||||
| 			); | ||||
|     if (args[1].equalsIgnoreCase("clear")) { | ||||
|       plugin.getExpansionCloud().clean(); | ||||
|       msg(s, "&aThe cache has been cleared!!"); | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 			// 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); | ||||
|     if (args[1].equalsIgnoreCase("status")) { | ||||
|  | ||||
| 			// 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); | ||||
|       msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size() | ||||
|               + " &bexpansions available on the cloud.", | ||||
|           "&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."); | ||||
|       } | ||||
|  | ||||
|             // 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("info")) { | ||||
|  | ||||
|       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; | ||||
| 		} | ||||
|  | ||||
|         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; | ||||
|           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()); | ||||
|         } | ||||
|  | ||||
|         if (args[1].equalsIgnoreCase("placeholders")) { | ||||
|         return true; | ||||
|       } | ||||
|  | ||||
|             if (args.length < 3) { | ||||
|                 msg(s, "&cAn expansion name must be specified!"); | ||||
|                 return true; | ||||
|             } | ||||
|       Player p = (Player) s; | ||||
|  | ||||
|             CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]); | ||||
|       for (Entry<Integer, CloudExpansion> expansion : ex.entrySet()) { | ||||
|  | ||||
|             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 (expansion == null || expansion.getValue() == null) { | ||||
|           continue; | ||||
|         } | ||||
|  | ||||
|         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; | ||||
| 					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(); | ||||
|         if (expansion.getValue().shouldUpdate()) { | ||||
|           sb.append("&6Click to update to the latest version of this expansion\n\n"); | ||||
|         } else if (!expansion.getValue().hasExpansion()) { | ||||
|           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()); | ||||
|  | ||||
|                 StringBuilder sb = new StringBuilder(); | ||||
|                 if (expansion.getValue().shouldUpdate()) { | ||||
|                     sb.append("&6Click to update to the latest version of this expansion\n\n"); | ||||
|                 } else if (!expansion.getValue().hasExpansion()) { | ||||
|                     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 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); | ||||
|                 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()); | ||||
| 			} | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 			String version = expansion.getLatestVersion(); | ||||
|     if (args[1].equalsIgnoreCase("download")) { | ||||
|  | ||||
| 			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; | ||||
| 				} | ||||
| 			} | ||||
|       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.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 { | ||||
|  | ||||
| 	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"); | ||||
| 	} | ||||
|   private PlaceholderAPIPlugin plugin; | ||||
|  | ||||
| 	public boolean cloudAllowUnverifiedExpansions() { | ||||
| 		return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions"); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean isCloudEnabled() { | ||||
| 		return plugin.getConfig().getBoolean("cloud_enabled"); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setCloudEnabled(boolean b) { | ||||
| 		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"); | ||||
| 	}	 | ||||
|   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() { | ||||
|     return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions"); | ||||
|   } | ||||
|  | ||||
|   public boolean isCloudEnabled() { | ||||
|     return plugin.getConfig().getBoolean("cloud_enabled"); | ||||
|   } | ||||
|  | ||||
|   public void setCloudEnabled(boolean b) { | ||||
|     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 { | ||||
|  | ||||
| 	private static final HandlerList HANDLERS = new HandlerList(); | ||||
| 	private PlaceholderExpansion expansion; | ||||
|   private static final HandlerList HANDLERS = new HandlerList(); | ||||
|   private PlaceholderExpansion expansion; | ||||
|  | ||||
| 	public ExpansionRegisterEvent(PlaceholderExpansion expansion) { | ||||
| 		this.expansion = expansion; | ||||
| 	} | ||||
|   public ExpansionRegisterEvent(PlaceholderExpansion expansion) { | ||||
|     this.expansion = expansion; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
| 	 | ||||
| 	public PlaceholderExpansion getExpansion() { | ||||
| 		return expansion; | ||||
| 	} | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   public PlaceholderExpansion getExpansion() { | ||||
|     return expansion; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -20,30 +20,29 @@ | ||||
|  */ | ||||
| package me.clip.placeholderapi.events; | ||||
|  | ||||
| import me.clip.placeholderapi.PlaceholderHook; | ||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||
| import org.bukkit.event.Event; | ||||
| import org.bukkit.event.HandlerList; | ||||
|  | ||||
| public class ExpansionUnregisterEvent extends Event { | ||||
|  | ||||
| 	private static final HandlerList HANDLERS = new HandlerList(); | ||||
| 	private PlaceholderExpansion expansion; | ||||
|   private static final HandlerList HANDLERS = new HandlerList(); | ||||
|   private PlaceholderExpansion expansion; | ||||
|  | ||||
| 	public ExpansionUnregisterEvent(PlaceholderExpansion expansion) { | ||||
| 		this.expansion = expansion; | ||||
| 	} | ||||
|   public ExpansionUnregisterEvent(PlaceholderExpansion expansion) { | ||||
|     this.expansion = expansion; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
| 	 | ||||
| 	public PlaceholderExpansion getExpansion() { | ||||
| 		return expansion; | ||||
| 	} | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   public PlaceholderExpansion getExpansion() { | ||||
|     return expansion; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -27,29 +27,29 @@ import org.bukkit.event.HandlerList; | ||||
| @Deprecated | ||||
| public class PlaceholderHookUnloadEvent extends Event { | ||||
|  | ||||
| 	private static final HandlerList HANDLERS = new HandlerList(); | ||||
| 	private String plugin; | ||||
| 	private PlaceholderHook hook; | ||||
|   private static final HandlerList HANDLERS = new HandlerList(); | ||||
|   private String plugin; | ||||
|   private PlaceholderHook hook; | ||||
|  | ||||
| 	public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) { | ||||
| 		this.plugin = plugin; | ||||
| 		this.hook = placeholderHook; | ||||
| 	} | ||||
|   public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) { | ||||
|     this.plugin = plugin; | ||||
|     this.hook = placeholderHook; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
| 		return HANDLERS; | ||||
| 	} | ||||
| 	 | ||||
| 	public String getHookName() { | ||||
| 		return plugin; | ||||
| 	} | ||||
| 	 | ||||
| 	public PlaceholderHook getHook() { | ||||
| 		return hook; | ||||
| 	} | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   public String getHookName() { | ||||
|     return plugin; | ||||
|   } | ||||
|  | ||||
|   public PlaceholderHook getHook() { | ||||
|     return hook; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -21,17 +21,16 @@ | ||||
| package me.clip.placeholderapi.expansion; | ||||
|  | ||||
| /** | ||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} | ||||
|  * to have the clear method called when the implementing expansion is unregistered | ||||
|  * from PlaceholderAPI. | ||||
|  * This is useful if we want to do things when the implementing hook is unregistered | ||||
|  * @author Ryan McCarthy | ||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} to have the clear | ||||
|  * method called when the implementing expansion is unregistered from PlaceholderAPI. This is useful | ||||
|  * if we want to do things when the implementing hook is unregistered | ||||
|  * | ||||
|  * @author Ryan McCarthy | ||||
|  */ | ||||
| public interface Cacheable { | ||||
|  | ||||
| 	/** | ||||
| 	 * Called when the implementing class is unregistered from PlaceholderAPI | ||||
| 	 */ | ||||
| 	void clear(); | ||||
|   /** | ||||
|    * Called when the implementing class is unregistered from PlaceholderAPI | ||||
|    */ | ||||
|   void clear(); | ||||
| } | ||||
|   | ||||
| @@ -23,17 +23,18 @@ package me.clip.placeholderapi.expansion; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| /** | ||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} | ||||
|  * to have the cleanup method called every time a player leaves the server. | ||||
|  * This is useful if we want to clean up after the player | ||||
|  * @author Ryan McCarthy | ||||
|  * This interface allows a class which extends a {@link PlaceholderExpansion} to have the cleanup | ||||
|  * method called every time a player leaves the server. This is useful if we want to clean up after | ||||
|  * the player | ||||
|  * | ||||
|  * @author Ryan McCarthy | ||||
|  */ | ||||
| public interface Cleanable { | ||||
|  | ||||
| 	/** | ||||
| 	 * Called when a player leaves the server | ||||
| 	 * @param p (@link Player} who left the server | ||||
| 	 */ | ||||
| 	void cleanup(Player p); | ||||
|   /** | ||||
|    * Called when a player leaves the server | ||||
|    * | ||||
|    * @param p (@link Player} who left the server | ||||
|    */ | ||||
|   void cleanup(Player p); | ||||
| } | ||||
|   | ||||
| @@ -23,19 +23,21 @@ package me.clip.placeholderapi.expansion; | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * Any {@link PlaceholderExpansion} class which implements configurable will | ||||
|  * have any options listed in the getDefaults map automatically added to the PlaceholderAPI config.yml file | ||||
|  * @author Ryan McCarthy | ||||
|  * Any {@link PlaceholderExpansion} class which implements configurable will have any options listed | ||||
|  * in the getDefaults map automatically added to the PlaceholderAPI config.yml file | ||||
|  * | ||||
|  * @author Ryan McCarthy | ||||
|  */ | ||||
| public interface Configurable { | ||||
|  | ||||
| 	/** | ||||
| 	 * This method will be called before the implementing class is registered | ||||
| 	 * to obtain a map of configuration options that the implementing class needs | ||||
| 	 * These paths and values will be added to the PlaceholderAPI config.yml in the configuration section | ||||
| 	 * expansions.(placeholder identifier).(your key): (your value) | ||||
| 	 * @return Map of config path / values which need to be added / removed from the PlaceholderAPI config.yml file | ||||
| 	 */ | ||||
| 	Map<String, Object> getDefaults(); | ||||
|   /** | ||||
|    * This method will be called before the implementing class is registered to obtain a map of | ||||
|    * configuration options that the implementing class needs These paths and values will be added to | ||||
|    * the PlaceholderAPI config.yml in the configuration section expansions.(placeholder | ||||
|    * identifier).(your key): (your value) | ||||
|    * | ||||
|    * @return Map of config path / values which need to be added / removed from the PlaceholderAPI | ||||
|    * config.yml file | ||||
|    */ | ||||
|   Map<String, Object> getDefaults(); | ||||
| } | ||||
|   | ||||
| @@ -22,36 +22,37 @@ package me.clip.placeholderapi.expansion; | ||||
|  | ||||
| public enum NMSVersion { | ||||
|  | ||||
| 	UNKNOWN("unknown"), | ||||
| 	SPIGOT_1_7_R1("v1_7_R1"), | ||||
| 	SPIGOT_1_7_R2("v1_7_R2"), | ||||
| 	SPIGOT_1_7_R3("v1_7_R3"), | ||||
| 	SPIGOT_1_7_R4("v1_7_R4"), | ||||
| 	SPIGOT_1_8_R1("v1_8_R1"), | ||||
| 	SPIGOT_1_8_R2("v1_8_R2"), | ||||
| 	SPIGOT_1_8_R3("v1_8_R3"), | ||||
| 	SPIGOT_1_9_R1("v1_9_R1"), | ||||
| 	SPIGOT_1_9_R2("v1_9_R2"), | ||||
| 	SPIGOT_1_10_R1("v1_10_R1"), | ||||
| 	SPIGOT_1_11_R1("v1_11_R1"), | ||||
| 	SPIGOT_1_12_R1("v1_12_R1"); | ||||
| 	 | ||||
| 	private String version; | ||||
| 	 | ||||
| 	NMSVersion(String version) { | ||||
| 		this.version = version; | ||||
| 	} | ||||
| 	 | ||||
| 	public String getVersion() { | ||||
| 		return version; | ||||
| 	} | ||||
| 	 | ||||
| 	public static NMSVersion getVersion(String version) { | ||||
| 		for (NMSVersion v : values()) { | ||||
| 			if (v.getVersion().equalsIgnoreCase(version)) { | ||||
| 				return v; | ||||
| 			} | ||||
| 		} | ||||
| 		return NMSVersion.UNKNOWN; | ||||
| 	} | ||||
|   UNKNOWN("unknown"), | ||||
|   SPIGOT_1_7_R1("v1_7_R1"), | ||||
|   SPIGOT_1_7_R2("v1_7_R2"), | ||||
|   SPIGOT_1_7_R3("v1_7_R3"), | ||||
|   SPIGOT_1_7_R4("v1_7_R4"), | ||||
|   SPIGOT_1_8_R1("v1_8_R1"), | ||||
|   SPIGOT_1_8_R2("v1_8_R2"), | ||||
|   SPIGOT_1_8_R3("v1_8_R3"), | ||||
|   SPIGOT_1_9_R1("v1_9_R1"), | ||||
|   SPIGOT_1_9_R2("v1_9_R2"), | ||||
|   SPIGOT_1_10_R1("v1_10_R1"), | ||||
|   SPIGOT_1_11_R1("v1_11_R1"), | ||||
|   SPIGOT_1_12_R1("v1_12_R1"); | ||||
|  | ||||
|   private String version; | ||||
|  | ||||
|   NMSVersion(String version) { | ||||
|     this.version = version; | ||||
|   } | ||||
|  | ||||
|   public static NMSVersion getVersion(String version) { | ||||
|     for (NMSVersion v : values()) { | ||||
|       if (v.getVersion().equalsIgnoreCase(version)) { | ||||
|         return v; | ||||
|       } | ||||
|     } | ||||
|     return NMSVersion.UNKNOWN; | ||||
|   } | ||||
|  | ||||
|   public String getVersion() { | ||||
|     return version; | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -20,6 +20,7 @@ | ||||
|  */ | ||||
| package me.clip.placeholderapi.expansion; | ||||
|  | ||||
| import java.util.List; | ||||
| import me.clip.placeholderapi.PlaceholderAPI; | ||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||
| import me.clip.placeholderapi.PlaceholderHook; | ||||
| @@ -27,39 +28,42 @@ import org.apache.commons.lang.Validate; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.configuration.ConfigurationSection; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| 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. | ||||
|    * by default will return the deprecated {@link #getPlugin()} method | ||||
|    * 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. by default will return the deprecated | ||||
|    * {@link #getPlugin()} method | ||||
|    * | ||||
|    * @return plugin name that this expansion requires to function | ||||
|    */ | ||||
|   public String getRequiredPlugin() { | ||||
| @@ -68,95 +72,109 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * The placeholders associated with this expansion | ||||
|    * | ||||
|    * @return placeholder list that this expansion provides | ||||
|    */ | ||||
|   public List<String> getPlaceholders() { | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
| 	/** | ||||
| 	 * Expansions that do not use the ecloud and instead register from the dependency should set this to true | ||||
| 	 * to ensure that your placeholder expansion is not unregistered when the papi reload command is used | ||||
| 	 * @return if this expansion should persist through placeholder reloads | ||||
| 	 */ | ||||
| 	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 | ||||
| 	 */ | ||||
| 	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 | ||||
| 	 */ | ||||
| 	public boolean canRegister() { | ||||
| 		return getRequiredPlugin() == null || Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null; | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Attempt to register this PlaceholderExpansion | ||||
| 	 * @return true if this expansion is now registered with PlaceholderAPI | ||||
| 	 */ | ||||
| 	public boolean register() { | ||||
| 		Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); | ||||
| 		return PlaceholderAPI.registerExpansion(this); | ||||
| 	} | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Quick getter for the {@link PlaceholderAPIPlugin} instance | ||||
| 	 * @return {@link PlaceholderAPIPlugin} instance | ||||
| 	 */ | ||||
| 	public PlaceholderAPIPlugin getPlaceholderAPI() { | ||||
| 		return PlaceholderAPIPlugin.getInstance(); | ||||
| 	} | ||||
| 	 | ||||
| 	public String getString(String path, String def) { | ||||
| 		return getPlaceholderAPI().getConfig().getString("expansions." + getIdentifier() + "." + path, def); | ||||
| 	} | ||||
| 	 | ||||
| 	public int getInt(String path, int def) { | ||||
| 		return getPlaceholderAPI().getConfig().getInt("expansions." + getIdentifier() + "." + path, def); | ||||
| 	} | ||||
| 	 | ||||
| 	public long getLong(String path, long def) { | ||||
| 		return getPlaceholderAPI().getConfig().getLong("expansions." + getIdentifier() + "." + path, def); | ||||
| 	} | ||||
| 	 | ||||
| 	public double getDouble(String path, double def) { | ||||
| 		return getPlaceholderAPI().getConfig().getDouble("expansions." + getIdentifier() + "." + path, def); | ||||
| 	}	 | ||||
| 	 | ||||
| 	public List<String> getStringList(String path) { | ||||
| 		return getPlaceholderAPI().getConfig().getStringList("expansions." + getIdentifier() + "." + path); | ||||
| 	} | ||||
| 	 | ||||
| 	public Object get(String path, Object def) { | ||||
| 		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);  | ||||
| 	} | ||||
|   /** | ||||
|    * Expansions that do not use the ecloud and instead register from the dependency should set this | ||||
|    * to true to ensure that your placeholder expansion is not unregistered when the papi reload | ||||
|    * command is used | ||||
|    * | ||||
|    * @return if this expansion should persist through placeholder reloads | ||||
|    */ | ||||
|   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 | ||||
|    */ | ||||
|   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 | ||||
|    */ | ||||
|   public boolean canRegister() { | ||||
|     return getRequiredPlugin() == null | ||||
|         || Bukkit.getPluginManager().getPlugin(getRequiredPlugin()) != null; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Attempt to register this PlaceholderExpansion | ||||
|    * | ||||
|    * @return true if this expansion is now registered with PlaceholderAPI | ||||
|    */ | ||||
|   public boolean register() { | ||||
|     Validate.notNull(getIdentifier(), "Placeholder identifier can not be null!"); | ||||
|     return PlaceholderAPI.registerExpansion(this); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * Quick getter for the {@link PlaceholderAPIPlugin} instance | ||||
|    * | ||||
|    * @return {@link PlaceholderAPIPlugin} instance | ||||
|    */ | ||||
|   public PlaceholderAPIPlugin getPlaceholderAPI() { | ||||
|     return PlaceholderAPIPlugin.getInstance(); | ||||
|   } | ||||
|  | ||||
|   public String getString(String path, String def) { | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getString("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public int getInt(String path, int def) { | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getInt("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public long getLong(String path, long def) { | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getLong("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public double getDouble(String path, double def) { | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getDouble("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public List<String> getStringList(String path) { | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getStringList("expansions." + getIdentifier() + "." + path); | ||||
|   } | ||||
|  | ||||
|   public Object get(String path, Object def) { | ||||
|     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 | ||||
|   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 | ||||
|   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 | ||||
|   public String getLink() { return null; } | ||||
|   public String getLink() { | ||||
|     return null; | ||||
|   } | ||||
| } | ||||
| @@ -23,5 +23,6 @@ package me.clip.placeholderapi.expansion; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| 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 { | ||||
| 	 | ||||
| 	/** | ||||
| 	 * 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 | ||||
| 	 */ | ||||
| 	void start(); | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Called when the implementing class has been unregistered from PlaceholderAPI | ||||
| 	 * Tasks that need to be performed when this expansion has unregistered should go here | ||||
| 	 */ | ||||
| 	void stop(); | ||||
|  | ||||
|   /** | ||||
|    * 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 | ||||
|    */ | ||||
|   void start(); | ||||
|  | ||||
|   /** | ||||
|    * Called when the implementing class has been unregistered from PlaceholderAPI Tasks that need to | ||||
|    * be performed when this expansion has unregistered should go here | ||||
|    */ | ||||
|   void stop(); | ||||
| } | ||||
|   | ||||
| @@ -21,19 +21,20 @@ | ||||
| package me.clip.placeholderapi.expansion; | ||||
|  | ||||
| /** | ||||
|  * Placeholder expansions which use NMS code should be version specific. | ||||
|  * Implementing this class allows you to perform checks based on the version the server is running.  | ||||
|  * The isCompatibleWith method will be passed the server version and allow you to return if your expansion is compatible with that version. | ||||
|  * @author Ryan McCarthy | ||||
|  * Placeholder expansions which use NMS code should be version specific. Implementing this class | ||||
|  * allows you to perform checks based on the version the server is running. The isCompatibleWith | ||||
|  * method will be passed the server version and allow you to return if your expansion is compatible | ||||
|  * with that version. | ||||
|  * | ||||
|  * @author Ryan McCarthy | ||||
|  */ | ||||
| public interface VersionSpecific { | ||||
|  | ||||
| 	/** | ||||
| 	 * This method is called before the expansion is attempted to be registered | ||||
| 	 * The server version 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. | ||||
| 	 */ | ||||
| 	boolean isCompatibleWith(Version v); | ||||
|   /** | ||||
|    * This method is called before the expansion is attempted to be registered The server version | ||||
|    * 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. | ||||
|    */ | ||||
|   boolean isCompatibleWith(Version v); | ||||
| } | ||||
|   | ||||
| @@ -20,183 +20,183 @@ | ||||
|  */ | ||||
| package me.clip.placeholderapi.expansion.cloud; | ||||
|  | ||||
| import me.clip.placeholderapi.util.TimeUtil; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import java.util.stream.Collectors; | ||||
| import me.clip.placeholderapi.util.TimeUtil; | ||||
|  | ||||
|  | ||||
| public class CloudExpansion { | ||||
|  | ||||
| 	private String name, | ||||
|             author, | ||||
|             latest_version, | ||||
|             description, | ||||
|             source_url, | ||||
|             dependency_url; | ||||
|   private String name, | ||||
|       author, | ||||
|       latest_version, | ||||
|       description, | ||||
|       source_url, | ||||
|       dependency_url; | ||||
|  | ||||
| 	private boolean hasExpansion, | ||||
|             shouldUpdate, | ||||
|             verified; | ||||
|   private boolean hasExpansion, | ||||
|       shouldUpdate, | ||||
|       verified; | ||||
|  | ||||
| 	private long last_update, | ||||
|             ratings_count; | ||||
|   private long last_update, | ||||
|       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() { | ||||
| 		int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate()); | ||||
| 		return TimeUtil.getTime(time); | ||||
| 	} | ||||
|   public String getTimeSinceLastUpdate() { | ||||
|     int time = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getLastUpdate()); | ||||
|     return TimeUtil.getTime(time); | ||||
|   } | ||||
|  | ||||
|     public String getName() { | ||||
|         return name; | ||||
|   public String getName() { | ||||
|     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) { | ||||
|         this.name = name; | ||||
|     public void setUrl(String url) { | ||||
|       this.url = url; | ||||
|     } | ||||
|  | ||||
|     public String getAuthor() { | ||||
|         return author; | ||||
|     public String getVersion() { | ||||
|       return version; | ||||
|     } | ||||
|  | ||||
|     public void setAuthor(String author) { | ||||
|         this.author = author; | ||||
|     public void setVersion(String version) { | ||||
|       this.version = version; | ||||
|     } | ||||
|  | ||||
|     public Version getVersion() { | ||||
| 	    return getLatestVersion() == null ? null : getVersion(getLatestVersion()); | ||||
|     public String getReleaseNotes() { | ||||
|       return release_notes; | ||||
|     } | ||||
|  | ||||
|     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 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; | ||||
|         } | ||||
|     public void setReleaseNotes(String release_notes) { | ||||
|       this.release_notes = release_notes; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -21,6 +21,22 @@ | ||||
| package me.clip.placeholderapi.expansion.cloud; | ||||
|  | ||||
| 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.PlaceholderAPIPlugin; | ||||
| 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.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 { | ||||
|  | ||||
|     private PlaceholderAPIPlugin plugin; | ||||
|     private final String API = "http://api.extendedclip.com/v2/"; | ||||
|     private final File dir; | ||||
|     private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>(); | ||||
|     private final List<String> downloading = new ArrayList<>(); | ||||
|     private Gson gson; | ||||
|   private final String API = "http://api.extendedclip.com/v2/"; | ||||
|   private final File dir; | ||||
|   private final TreeMap<Integer, CloudExpansion> remote = new TreeMap<>(); | ||||
|   private final List<String> downloading = new ArrayList<>(); | ||||
|   private PlaceholderAPIPlugin plugin; | ||||
|   private Gson gson; | ||||
|  | ||||
|     public ExpansionCloudManager(PlaceholderAPIPlugin instance) { | ||||
|         plugin = instance; | ||||
|         gson = new Gson(); | ||||
|         dir = new File(instance.getDataFolder() + File.separator + "expansions"); | ||||
|         if (!dir.exists()) { | ||||
|             try { | ||||
|                 dir.mkdirs(); | ||||
|             } catch (Exception ex) { | ||||
|                 ex.printStackTrace(); | ||||
|             } | ||||
|   public ExpansionCloudManager(PlaceholderAPIPlugin instance) { | ||||
|     plugin = instance; | ||||
|     gson = new Gson(); | ||||
|     dir = new File(instance.getDataFolder() + File.separator + "expansions"); | ||||
|     if (!dir.exists()) { | ||||
|       try { | ||||
|         dir.mkdirs(); | ||||
|       } catch (Exception ex) { | ||||
|         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() { | ||||
|         remote.clear(); | ||||
|         downloading.clear(); | ||||
|     if (byAuthor.isEmpty()) { | ||||
|       return null; | ||||
|     } | ||||
|     return byAuthor; | ||||
|   } | ||||
|  | ||||
|     public boolean isDownloading(String expansion) { | ||||
|         return downloading.contains(expansion); | ||||
|   public Map<Integer, CloudExpansion> getAllInstalled() { | ||||
|     if (remote.isEmpty()) { | ||||
|       return null; | ||||
|     } | ||||
|  | ||||
|     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> 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); | ||||
|         } | ||||
|         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 (remote.isEmpty()) { | ||||
|             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; | ||||
|     if (has.isEmpty()) { | ||||
|       return null; | ||||
|     } | ||||
|     return has; | ||||
|   } | ||||
|  | ||||
|     public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) { | ||||
|         if (map == null) { | ||||
|             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; | ||||
|   public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) { | ||||
|     if (map == null) { | ||||
|       return 0; | ||||
|     } | ||||
|  | ||||
|     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; | ||||
|     int pages = map.size() > 0 ? 1 : 0; | ||||
|     if (pages == 0) { | ||||
|       return pages; | ||||
|     } | ||||
|  | ||||
|     public void fetch(boolean allowUnverified) { | ||||
|  | ||||
|         plugin.getLogger().info("Fetching available expansion information..."); | ||||
|  | ||||
|         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); | ||||
|     if (map.size() > amount) { | ||||
|       pages = map.size() / amount; | ||||
|       if (map.size() % amount > 0) { | ||||
|         pages++; | ||||
|       } | ||||
|     } | ||||
|     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 { | ||||
|  | ||||
|             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) { | ||||
|                 fos.write(buffer, 0, l); | ||||
|             } | ||||
|         } finally { | ||||
|             try { | ||||
|                 if (is != null) { | ||||
|                     is.close(); | ||||
|                 } | ||||
|             } finally { | ||||
|                 if (fos != null) { | ||||
|                     fos.close(); | ||||
|                 } | ||||
|             } | ||||
|           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); | ||||
|   } | ||||
|  | ||||
|   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) { | ||||
|         downloadExpansion(player, ex, ex.getLatestVersion()); | ||||
|     final CloudExpansion.Version ver = ex.getVersions() | ||||
|         .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())) { | ||||
|             return; | ||||
|         } | ||||
|     plugin.getLogger().info( | ||||
|         "Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " | ||||
|             + player : "") + " from url: " + ver.getUrl()); | ||||
|  | ||||
|         final CloudExpansion.Version ver = ex.getVersions() | ||||
|                 .stream() | ||||
|                 .filter(v -> v.getVersion().equals(version)) | ||||
|                 .findFirst() | ||||
|                 .orElse(null); | ||||
|     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||||
|  | ||||
|         if (ver == null) { | ||||
|             return; | ||||
|         } | ||||
|       try { | ||||
|  | ||||
|         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()); | ||||
|  | ||||
|                 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; | ||||
|             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, "&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 | ||||
| public abstract class EZPlaceholderHook extends PlaceholderHook { | ||||
|  | ||||
| 	private String identifier; | ||||
| 	 | ||||
| 	private String plugin; | ||||
| 	 | ||||
| 	public EZPlaceholderHook(Plugin plugin, String identifier) { | ||||
| 		Validate.notNull(plugin, "Plugin can not be null!"); | ||||
| 		Validate.notNull(identifier, "Placeholder name can not be null!"); | ||||
| 		this.identifier = identifier; | ||||
| 		this.plugin = plugin.getName(); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean isHooked() { | ||||
| 		return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean hook() { | ||||
| 		return PlaceholderAPI.registerPlaceholderHook(identifier, this); | ||||
| 	} | ||||
| 	 | ||||
| 	public String getPlaceholderName() { | ||||
| 		return identifier; | ||||
| 	} | ||||
| 	 | ||||
| 	public String getPluginName() { | ||||
| 		return plugin; | ||||
| 	} | ||||
|   private String identifier; | ||||
|  | ||||
|   private String plugin; | ||||
|  | ||||
|   public EZPlaceholderHook(Plugin plugin, String identifier) { | ||||
|     Validate.notNull(plugin, "Plugin can not be null!"); | ||||
|     Validate.notNull(identifier, "Placeholder name can not be null!"); | ||||
|     this.identifier = identifier; | ||||
|     this.plugin = plugin.getName(); | ||||
|   } | ||||
|  | ||||
|   public boolean isHooked() { | ||||
|     return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier); | ||||
|   } | ||||
|  | ||||
|   public boolean hook() { | ||||
|     return PlaceholderAPI.registerPlaceholderHook(identifier, this); | ||||
|   } | ||||
|  | ||||
|   public String getPlaceholderName() { | ||||
|     return identifier; | ||||
|   } | ||||
|  | ||||
|   public String getPluginName() { | ||||
|     return plugin; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,9 @@ | ||||
| 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.util.Msg; | ||||
| import org.bukkit.Bukkit; | ||||
| @@ -8,77 +12,82 @@ import org.bukkit.event.EventPriority; | ||||
| import org.bukkit.event.Listener; | ||||
| 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 { | ||||
|  | ||||
| 	private PlaceholderAPIPlugin plugin; | ||||
|     private final int RESOURCE_ID = 6245; | ||||
|     private String spigotVersion, pluginVersion; | ||||
|     private boolean updateAvailable; | ||||
|   private final int RESOURCE_ID = 6245; | ||||
|   private PlaceholderAPIPlugin plugin; | ||||
|   private String spigotVersion, pluginVersion; | ||||
|   private boolean updateAvailable; | ||||
|  | ||||
|     public UpdateChecker(PlaceholderAPIPlugin i) { | ||||
|     	plugin = i; | ||||
|         pluginVersion = i.getDescription().getVersion(); | ||||
|   public UpdateChecker(PlaceholderAPIPlugin i) { | ||||
|     plugin = i; | ||||
|     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; } | ||||
|  | ||||
|     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("\\.",""); | ||||
|     } | ||||
|  | ||||
|     @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 + "/"); | ||||
|         } | ||||
|   @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 { | ||||
|  | ||||
| 	DAYS,  | ||||
| 	HOURS,  | ||||
| 	MINUTES,  | ||||
| 	SECONDS | ||||
|   DAYS, | ||||
|   HOURS, | ||||
|   MINUTES, | ||||
|   SECONDS | ||||
| } | ||||
|   | ||||
| @@ -22,141 +22,141 @@ package me.clip.placeholderapi.util; | ||||
|  | ||||
| public class TimeUtil { | ||||
|  | ||||
| 	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); | ||||
|   public static String getRemaining(int seconds, TimeFormat type) { | ||||
|  | ||||
| 		} else { | ||||
| 			int hours = leftOver / 60; | ||||
| 			int hoursInMins = 60 * hours; | ||||
| 			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; | ||||
| 	} | ||||
|     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 { | ||||
|       int hours = leftOver / 60; | ||||
|       int hoursInMins = 60 * hours; | ||||
|       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