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> | ||||
							
								
								
									
										3
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|   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> | ||||
|   | ||||
| @@ -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() { | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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,38 +38,85 @@ 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 | ||||
|  * | ||||
|  */ | ||||
| public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|  | ||||
|   private static PlaceholderAPIPlugin instance; | ||||
|  | ||||
| 	private PlaceholderAPIConfig config; | ||||
|  | ||||
| 	private ExpansionManager expansionManager; | ||||
|  | ||||
| 	private ExpansionCloudManager expansionCloud; | ||||
|  | ||||
|   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 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); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 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; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 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"); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 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(); | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public void onLoad() { | ||||
|     startTime = System.currentTimeMillis(); | ||||
| @@ -115,7 +166,9 @@ public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|     } else if (!cloudEnabled) { | ||||
|       enableCloud(); | ||||
|     } | ||||
| 		s.sendMessage(ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!")); | ||||
|     s.sendMessage(ChatColor.translateAlternateColorCodes('&', | ||||
|         PlaceholderAPI.getRegisteredIdentifiers().size() | ||||
|             + " &aplaceholder hooks successfully registered!")); | ||||
|   } | ||||
|  | ||||
|   private void setupOptions() { | ||||
| @@ -136,9 +189,11 @@ public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|  | ||||
|   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_expansion_cloud", | ||||
|         () -> getExpansionCloud() != null ? "yes" : "no")); | ||||
|  | ||||
| 	    m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "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<>(); | ||||
| @@ -160,23 +215,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|  | ||||
|   } | ||||
|  | ||||
| 	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 enableCloud() { | ||||
|     if (expansionCloud == null) { | ||||
|       expansionCloud = new ExpansionCloudManager(this); | ||||
| @@ -194,53 +232,6 @@ public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|     } | ||||
|   } | ||||
|  | ||||
| 	/** | ||||
| 	 * 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; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * 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"); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * 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. | ||||
|    * | ||||
| @@ -259,7 +250,8 @@ public class PlaceholderAPIPlugin extends JavaPlugin { | ||||
|   } | ||||
|  | ||||
|   public String getUptime() { | ||||
| 		return TimeUtil.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)); | ||||
|     return TimeUtil | ||||
|         .getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime)); | ||||
|   } | ||||
|  | ||||
|   public long getUptimeMillis() { | ||||
|   | ||||
| @@ -27,7 +27,9 @@ 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 | ||||
|    */ | ||||
| @@ -40,6 +42,7 @@ public abstract class PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * 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 | ||||
|   | ||||
| @@ -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,10 +40,6 @@ 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 { | ||||
|  | ||||
| @@ -65,7 +67,8 @@ public class PlaceholderListener implements Listener { | ||||
|  | ||||
|     if (plugin.getExpansionCloud() != null) { | ||||
|  | ||||
| 			CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName()); | ||||
|       CloudExpansion ex = plugin.getExpansionCloud() | ||||
|           .getCloudExpansion(event.getExpansion().getName()); | ||||
|  | ||||
|       if (ex != null) { | ||||
|         ex.setHasExpansion(false); | ||||
| @@ -114,7 +117,8 @@ public class PlaceholderListener implements Listener { | ||||
|  | ||||
|         if (h.getPluginName().equalsIgnoreCase(n)) { | ||||
|           if (PlaceholderAPI.unregisterPlaceholderHook(hook.getKey())) { | ||||
| 						plugin.getLogger().info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName()); | ||||
|             plugin.getLogger() | ||||
|                 .info("Unregistered placeholder hook for placeholder: " + h.getPlaceholderName()); | ||||
|             break; | ||||
|           } | ||||
|         } | ||||
|   | ||||
| @@ -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,13 +36,6 @@ 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; | ||||
| @@ -70,10 +69,12 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 		if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1].equalsIgnoreCase("fetch")) { | ||||
|     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()); | ||||
|       plugin.getExpansionCloud() | ||||
|           .fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| @@ -90,8 +91,10 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|  | ||||
|     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."); | ||||
|       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."); | ||||
| @@ -115,7 +118,9 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       } | ||||
|  | ||||
|       if (!(s instanceof Player)) { | ||||
| 				msg(s, (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion.getVersion().getUrl()); | ||||
|         msg(s, | ||||
|             (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion | ||||
|                 .getVersion().getUrl()); | ||||
|         return true; | ||||
|       } | ||||
|  | ||||
| @@ -127,21 +132,25 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       ); | ||||
|  | ||||
|       // latest version | ||||
|             JSONMessage latestVersion = JSONMessage.create(color("&bLatest version: &f" + expansion.getLatestVersion())); | ||||
|       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())); | ||||
|       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.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())); | ||||
|         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); | ||||
| @@ -182,7 +191,8 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       Player p = (Player) s; | ||||
|  | ||||
|       JSONMessage download = JSONMessage.create(color("&7Click to download this version")); | ||||
|             download.suggestCommand("/papi ecloud download " + expansion.getName() + " " + version.getVersion()); | ||||
|       download.suggestCommand( | ||||
|           "/papi ecloud download " + expansion.getName() + " " + version.getVersion()); | ||||
|       download.send(p); | ||||
|       return true; | ||||
|     } | ||||
| @@ -204,12 +214,14 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       List<String> placeholders = expansion.getPlaceholders(); | ||||
|  | ||||
|       if (placeholders == null) { | ||||
|                 msg(s, "&cThe expansion: &f" + expansion.getName() + " &cdoes not have any placeholders listed.", | ||||
|         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) { | ||||
|       if (!(s instanceof Player) | ||||
|           || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) { | ||||
|         msg(s, "&bPlaceholders: &f" + placeholders.size(), | ||||
|             String.join("&a, &f", placeholders)); | ||||
|         return true; | ||||
| @@ -287,11 +299,14 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       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!")); | ||||
|         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); | ||||
|       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); | ||||
|  | ||||
| @@ -306,8 +321,13 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       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()); | ||||
|             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; | ||||
| @@ -332,10 +352,14 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|         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( | ||||
|             "&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()); | ||||
|  | ||||
| @@ -348,7 +372,6 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|       return true; | ||||
|     } | ||||
|  | ||||
| 		 | ||||
|     if (args[1].equalsIgnoreCase("download")) { | ||||
|  | ||||
|       if (args.length < 3) { | ||||
| @@ -381,7 +404,8 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|         } | ||||
|       } | ||||
|  | ||||
| 			msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version); | ||||
|       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; | ||||
| @@ -392,5 +416,4 @@ public class ExpansionCloudCommands implements CommandExecutor { | ||||
|   } | ||||
|  | ||||
|  | ||||
| 	 | ||||
| } | ||||
|   | ||||
| @@ -33,12 +33,12 @@ public class ExpansionRegisterEvent extends Event { | ||||
|     this.expansion = expansion; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -20,7 +20,6 @@ | ||||
|  */ | ||||
| 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; | ||||
| @@ -34,12 +33,12 @@ public class ExpansionUnregisterEvent extends Event { | ||||
|     this.expansion = expansion; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -36,12 +36,12 @@ public class PlaceholderHookUnloadEvent extends Event { | ||||
|     this.hook = placeholderHook; | ||||
|   } | ||||
|  | ||||
| 	@Override | ||||
| 	public HandlerList getHandlers() { | ||||
|   public static HandlerList getHandlerList() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
| 	public static HandlerList getHandlerList() { | ||||
|   @Override | ||||
|   public HandlerList getHandlers() { | ||||
|     return HANDLERS; | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -21,12 +21,11 @@ | ||||
| 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 { | ||||
|  | ||||
|   | ||||
| @@ -23,16 +23,17 @@ 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); | ||||
|   | ||||
| @@ -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 | ||||
|    * 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(); | ||||
| } | ||||
|   | ||||
| @@ -42,10 +42,6 @@ public enum NMSVersion { | ||||
|     this.version = version; | ||||
|   } | ||||
|  | ||||
| 	public String getVersion() { | ||||
| 		return version; | ||||
| 	} | ||||
| 	 | ||||
|   public static NMSVersion getVersion(String version) { | ||||
|     for (NMSVersion v : values()) { | ||||
|       if (v.getVersion().equalsIgnoreCase(version)) { | ||||
| @@ -54,4 +50,9 @@ public enum NMSVersion { | ||||
|     } | ||||
|     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,12 +28,11 @@ 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() { | ||||
| @@ -41,25 +41,29 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * 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 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,6 +72,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * The placeholders associated with this expansion | ||||
|    * | ||||
|    * @return placeholder list that this expansion provides | ||||
|    */ | ||||
|   public List<String> getPlaceholders() { | ||||
| @@ -75,8 +80,10 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| 	 * 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 | ||||
|    * 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() { | ||||
| @@ -85,6 +92,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * Check if this placeholder identfier has already been registered | ||||
|    * | ||||
|    * @return true if the identifier for this expansion is already registered | ||||
|    */ | ||||
|   public boolean isRegistered() { | ||||
| @@ -93,16 +101,19 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|   } | ||||
|  | ||||
|   /** | ||||
| 	 * If any requirements need to be checked before this expansion should register, | ||||
|    * you can check them here | ||||
|    * 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; | ||||
|     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() { | ||||
| @@ -112,6 +123,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|  | ||||
|   /** | ||||
|    * Quick getter for the {@link PlaceholderAPIPlugin} instance | ||||
|    * | ||||
|    * @return {@link PlaceholderAPIPlugin} instance | ||||
|    */ | ||||
|   public PlaceholderAPIPlugin getPlaceholderAPI() { | ||||
| @@ -119,23 +131,28 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|   } | ||||
|  | ||||
|   public String getString(String path, String def) { | ||||
| 		return getPlaceholderAPI().getConfig().getString("expansions." + getIdentifier() + "." + path, def); | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getString("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public int getInt(String path, int def) { | ||||
| 		return getPlaceholderAPI().getConfig().getInt("expansions." + getIdentifier() + "." + path, def); | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getInt("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public long getLong(String path, long def) { | ||||
| 		return getPlaceholderAPI().getConfig().getLong("expansions." + getIdentifier() + "." + path, def); | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getLong("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public double getDouble(String path, double def) { | ||||
| 		return getPlaceholderAPI().getConfig().getDouble("expansions." + getIdentifier() + "." + path, def); | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getDouble("expansions." + getIdentifier() + "." + path, def); | ||||
|   } | ||||
|  | ||||
|   public List<String> getStringList(String path) { | ||||
| 		return getPlaceholderAPI().getConfig().getStringList("expansions." + getIdentifier() + "." + path); | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getStringList("expansions." + getIdentifier() + "." + path); | ||||
|   } | ||||
|  | ||||
|   public Object get(String path, Object def) { | ||||
| @@ -143,7 +160,8 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|   } | ||||
|  | ||||
|   public ConfigurationSection getConfigSection(String path) { | ||||
| 		return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier() + "." + path);  | ||||
|     return getPlaceholderAPI().getConfig() | ||||
|         .getConfigurationSection("expansions." + getIdentifier() + "." + path); | ||||
|   } | ||||
|  | ||||
|   public ConfigurationSection getConfigSection() { | ||||
| @@ -167,11 +185,15 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { | ||||
|    * @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 | ||||
|   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); | ||||
| } | ||||
|   | ||||
| @@ -30,8 +30,8 @@ public interface Taskable { | ||||
|   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 | ||||
|    * 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,17 +21,18 @@ | ||||
| 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. | ||||
|    * 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. | ||||
|    */ | ||||
|   | ||||
| @@ -20,11 +20,10 @@ | ||||
|  */ | ||||
| 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 { | ||||
| @@ -173,6 +172,7 @@ public class CloudExpansion { | ||||
|   } | ||||
|  | ||||
|   public class Version { | ||||
|  | ||||
|     private String url, version, release_notes; | ||||
|  | ||||
|     public String getUrl() { | ||||
|   | ||||
| @@ -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,21 +48,13 @@ 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 PlaceholderAPIPlugin plugin; | ||||
|   private Gson gson; | ||||
|  | ||||
|   public ExpansionCloudManager(PlaceholderAPIPlugin instance) { | ||||
| @@ -76,15 +84,19 @@ public class ExpansionCloudManager { | ||||
|   } | ||||
|  | ||||
|   public CloudExpansion getCloudExpansion(String name) { | ||||
|         return remote.values().stream().filter(ex -> ex.getName().equalsIgnoreCase(name)).findFirst().orElse(null); | ||||
|     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(); | ||||
|     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(); | ||||
|     return PlaceholderAPI.getExpansions().stream().filter( | ||||
|         ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()) | ||||
|             .shouldUpdate()).count(); | ||||
|   } | ||||
|  | ||||
|   public Map<Integer, CloudExpansion> getAllByAuthor(String author) { | ||||
| @@ -150,7 +162,8 @@ public class ExpansionCloudManager { | ||||
|     return pages; | ||||
|   } | ||||
|  | ||||
|     public Map<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> map, int page, int size) { | ||||
|   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; | ||||
|     } | ||||
| @@ -182,7 +195,8 @@ public class ExpansionCloudManager { | ||||
|  | ||||
|           connection.connect(); | ||||
|  | ||||
|                     BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||||
|           BufferedReader br = new BufferedReader( | ||||
|               new InputStreamReader(connection.getInputStream())); | ||||
|  | ||||
|           sb = new StringBuilder(); | ||||
|  | ||||
| @@ -235,7 +249,8 @@ public class ExpansionCloudManager { | ||||
|  | ||||
|             ce.setName(o.toString()); | ||||
|  | ||||
|                         PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(ce.getName()); | ||||
|             PlaceholderExpansion ex = plugin.getExpansionManager() | ||||
|                 .getRegisteredExpansion(ce.getName()); | ||||
|  | ||||
|             if (ex != null && ex.isRegistered()) { | ||||
|               ce.setHasExpansion(true); | ||||
| @@ -280,7 +295,8 @@ public class ExpansionCloudManager { | ||||
|  | ||||
|       is = urlConn.getInputStream(); | ||||
|  | ||||
|             fos = new FileOutputStream(dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar"); | ||||
|       fos = new FileOutputStream( | ||||
|           dir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar"); | ||||
|  | ||||
|       byte[] buffer = new byte[is.available()]; | ||||
|  | ||||
| @@ -306,7 +322,8 @@ public class ExpansionCloudManager { | ||||
|     downloadExpansion(player, ex, ex.getLatestVersion()); | ||||
|   } | ||||
|  | ||||
|     public void downloadExpansion(final String player, final CloudExpansion ex, final String version) { | ||||
|   public void downloadExpansion(final String player, final CloudExpansion ex, | ||||
|       final String version) { | ||||
|  | ||||
|     if (downloading.contains(ex.getName())) { | ||||
|       return; | ||||
| @@ -324,7 +341,9 @@ public class ExpansionCloudManager { | ||||
|  | ||||
|     downloading.add(ex.getName()); | ||||
|  | ||||
|         plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl()); | ||||
|     plugin.getLogger().info( | ||||
|         "Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " | ||||
|             + player : "") + " from url: " + ver.getUrl()); | ||||
|  | ||||
|     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||||
|  | ||||
| @@ -336,7 +355,8 @@ public class ExpansionCloudManager { | ||||
|  | ||||
|       } catch (Exception e) { | ||||
|  | ||||
|                 plugin.getLogger().warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl()); | ||||
|         plugin.getLogger() | ||||
|             .warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl()); | ||||
|  | ||||
|         Bukkit.getScheduler().runTask(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,15 +12,10 @@ 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 PlaceholderAPIPlugin plugin; | ||||
|   private String spigotVersion, pluginVersion; | ||||
|   private boolean updateAvailable; | ||||
|  | ||||
| @@ -25,7 +24,9 @@ public class UpdateChecker implements Listener { | ||||
|     pluginVersion = i.getDescription().getVersion(); | ||||
|   } | ||||
|  | ||||
|     public boolean hasUpdateAvailable() { return updateAvailable; } | ||||
|   public boolean hasUpdateAvailable() { | ||||
|     return updateAvailable; | ||||
|   } | ||||
|  | ||||
|   public String getSpigotVersion() { | ||||
|     return spigotVersion; | ||||
| @@ -34,7 +35,8 @@ public class UpdateChecker implements Listener { | ||||
|   public void fetch() { | ||||
|     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||||
|       try { | ||||
|                 HttpsURLConnection con = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); | ||||
|         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) { | ||||
| @@ -53,15 +55,19 @@ public class UpdateChecker implements Listener { | ||||
|       } | ||||
|  | ||||
|       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 + "/"); | ||||
|         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; | ||||
|       if (spigotVersion == null || spigotVersion.isEmpty()) { | ||||
|           return false; | ||||
|       } | ||||
|     String plV = toReadable(pluginVersion); | ||||
|     String spV = toReadable(spigotVersion); | ||||
|     return plV.compareTo(spV) < 0; | ||||
| @@ -77,8 +83,11 @@ public class UpdateChecker implements Listener { | ||||
|   @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 + "/"); | ||||
|       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 | ||||
|               + "/"); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user