expansions = PlaceholderAPI.getExpansions();
+
+ if (expansions.isEmpty()) {
+ return;
+ }
+
+ for (PlaceholderExpansion ex : expansions) {
+ if (ex instanceof Cleanable) {
+ ((Cleanable) ex).cleanup(e.getPlayer());
}
}
}
diff --git a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java
index e08da2b..b1f38f7 100644
--- a/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java
+++ b/src/main/java/me/clip/placeholderapi/listeners/ServerLoadEventListener.java
@@ -31,6 +31,7 @@ import org.bukkit.event.server.ServerLoadEvent;
import java.util.Map;
public class ServerLoadEventListener implements Listener {
+
private final PlaceholderAPIPlugin plugin;
public ServerLoadEventListener(PlaceholderAPIPlugin instance) {
@@ -39,19 +40,19 @@ public class ServerLoadEventListener implements Listener {
}
/**
- * This method will be called when the server is first loaded.
+ * This method will be called when the server is first loaded
*
* The goal of the method is to register all the expansions as soon as possible
- * especially before players can join.
+ * especially before players can join
*
* This will ensure no issues with expanions and hooks.
*
- * @param event the server load event.
+ * @param e the server load event
*/
@EventHandler
- public void onServerLoad(ServerLoadEvent event) {
+ public void onServerLoad(ServerLoadEvent e) {
plugin.getLogger().info("Placeholder expansion registration initializing...");
- Map alreadyRegistered = PlaceholderAPI.getPlaceholders();
+ final Map alreadyRegistered = PlaceholderAPI.getPlaceholders();
plugin.getExpansionManager().registerAllExpansions();
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
diff --git a/src/main/java/me/clip/placeholderapi/util/UpdateChecker.java b/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java
similarity index 66%
rename from src/main/java/me/clip/placeholderapi/util/UpdateChecker.java
rename to src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java
index 03d88e2..afafb0d 100644
--- a/src/main/java/me/clip/placeholderapi/util/UpdateChecker.java
+++ b/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java
@@ -18,13 +18,13 @@
*
*
*/
-package me.clip.placeholderapi.util;
+package me.clip.placeholderapi.updatechecker;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
-import org.apache.commons.lang.StringUtils;
+import me.clip.placeholderapi.util.Msg;
import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -32,11 +32,10 @@ import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
-import java.nio.charset.StandardCharsets;
public class UpdateChecker implements Listener {
- private static final int RESOURCE_ID = 6245;
- private static final String SPIGOT_API = "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID;
+
+ private final int RESOURCE_ID = 6245;
private final PlaceholderAPIPlugin plugin;
private final String pluginVersion;
private String spigotVersion;
@@ -58,35 +57,39 @@ public class UpdateChecker implements Listener {
public void fetch() {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
- HttpsURLConnection con = (HttpsURLConnection) new URL(SPIGOT_API).openConnection();
-
- // Prevents the server from freezing with bad internet connection.
+ HttpsURLConnection con = (HttpsURLConnection) new URL(
+ "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
con.setRequestMethod("GET");
- con.setConnectTimeout(2000);
- con.setReadTimeout(2000);
-
- spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)).readLine();
+ spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
} catch (Exception ex) {
- plugin.getLogger().warning("Failed to check for updates on spigot.");
+ plugin.getLogger().info("Failed to check for updates on spigot.");
+ return;
+ }
+
+ if (spigotVersion == null || spigotVersion.isEmpty()) {
return;
}
- if (spigotVersion == null || spigotVersion.isEmpty()) return;
updateAvailable = spigotIsNewer();
- if (!updateAvailable) return;
+
+ if (!updateAvailable) {
+ return;
+ }
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.getLogger()
- .info("An update for PlaceholderAPI (v" + spigotVersion + ") is available at:");
+ .info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
plugin.getLogger()
- .info("https://www.spigotmc.org/resources/" + RESOURCE_ID + '/');
+ .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);
@@ -94,17 +97,21 @@ public class UpdateChecker implements Listener {
}
private String toReadable(String version) {
- if (version.contains("-DEV-")) version = StringUtils.split(version, "-DEV-")[0];
- return StringUtils.remove(version, '.');
+ if (version.contains("-DEV-")) {
+ version = version.split("-DEV-")[0];
+ }
+
+ return version.replaceAll("\\.", "");
}
- @EventHandler
- public void onJoin(PlayerJoinEvent event) {
- Player player = event.getPlayer();
- if (player.hasPermission("placeholderapi.updatenotify")) {
- Msg.msg(player,
- "&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
+ + "/");
}
}
}
diff --git a/src/main/java/me/clip/placeholderapi/util/Constants.java b/src/main/java/me/clip/placeholderapi/util/Constants.java
new file mode 100644
index 0000000..d911793
--- /dev/null
+++ b/src/main/java/me/clip/placeholderapi/util/Constants.java
@@ -0,0 +1,9 @@
+package me.clip.placeholderapi.util;
+
+public class Constants {
+ public static final String ADMIN_PERMISSION = "placeholderapi.admin";
+ public static final String ECLOUD_PERMISSION = "placeholderapi.ecloud";
+ public static final String INFO_PERMISSION = "placeholderapi.info";
+ public static final String LIST_PERMISSION = "placeholderapi.list";
+ public static final String RELOAD_PERMISSION = "placeholderapi.reload";
+}
diff --git a/src/main/java/me/clip/placeholderapi/util/FileUtil.java b/src/main/java/me/clip/placeholderapi/util/FileUtil.java
index 9466e5b..84eb613 100644
--- a/src/main/java/me/clip/placeholderapi/util/FileUtil.java
+++ b/src/main/java/me/clip/placeholderapi/util/FileUtil.java
@@ -42,50 +42,65 @@ public class FileUtil {
try {
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
- if (!f.exists()) return list;
+ if (!f.exists()) {
+ return list;
+ }
FilenameFilter fileNameFilter = (dir, name) -> {
- boolean isJar = name.endsWith(".jar");
if (fileName != null) {
- return isJar && name.substring(0, name.length() - 4)
- .equalsIgnoreCase(fileName.substring(0, fileName.length() - 4));
+ return name.endsWith(".jar") && name.replace(".jar", "")
+ .equalsIgnoreCase(fileName.replace(".jar", ""));
}
- return isJar;
+ return name.endsWith(".jar");
};
File[] jars = f.listFiles(fileNameFilter);
- if (jars == null) return list;
+ if (jars == null) {
+ return list;
+ }
for (File file : jars) {
list = gather(file.toURI().toURL(), list, type);
}
return list;
- } catch (Throwable ignored) {
+ } catch (Throwable t) {
}
return null;
}
private static List> gather(URL jar, List> list, Class> clazz) {
- // list cannot be null.
+ if (list == null) {
+ list = new ArrayList<>();
+ }
+
try (URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader());
JarInputStream jis = new JarInputStream(jar.openStream())) {
- JarEntry entry;
- while ((entry = jis.getNextJarEntry()) != null) {
- String name = entry.getName();
- if (name == null || name.isEmpty()) continue;
+ while (true) {
+ JarEntry j = jis.getNextJarEntry();
+ if (j == null) {
+ break;
+ }
+
+ String name = j.getName();
+ if (name == null || name.isEmpty()) {
+ continue;
+ }
if (name.endsWith(".class")) {
- name = name.substring(0, name.length() - 6).replace('/', '.');
+ name = name.replace("/", ".");
+ String cname = name.substring(0, name.lastIndexOf(".class"));
- Class> loaded = cl.loadClass(name);
- if (clazz.isAssignableFrom(loaded)) list.add(loaded);
+ Class> c = cl.loadClass(cname);
+ if (clazz.isAssignableFrom(c)) {
+ list.add(c);
+ }
}
}
- } catch (Throwable ignored) {
+ } catch (Throwable t) {
}
return list;
diff --git a/src/main/java/me/clip/placeholderapi/util/Msg.java b/src/main/java/me/clip/placeholderapi/util/Msg.java
index e1cdd25..3d526e4 100644
--- a/src/main/java/me/clip/placeholderapi/util/Msg.java
+++ b/src/main/java/me/clip/placeholderapi/util/Msg.java
@@ -24,20 +24,17 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
-public class Msg {
- public static void msg(CommandSender sender, String... messages) {
- for (String message : messages) {
- String msg = color(message);
- sender.sendMessage(msg);
- }
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public final class Msg {
+ public static void msg(CommandSender s, String... msg) {
+ s.sendMessage(Arrays.stream(msg).filter(Objects::nonNull).map(Msg::color).collect(Collectors.joining("\n")));
}
- public static void broadcast(String... messages) {
- CommandSender sender = Bukkit.getConsoleSender();
- for (String message : messages) {
- String msg = color(message);
- sender.sendMessage(msg);
- }
+ public static void broadcast(String... msg) {
+ Arrays.stream(msg).filter(Objects::nonNull).map(Msg::color).forEach(Bukkit::broadcastMessage);
}
public static String color(String text) {
diff --git a/src/main/java/me/clip/placeholderapi/util/TimeFormat.java b/src/main/java/me/clip/placeholderapi/util/TimeFormat.java
new file mode 100644
index 0000000..a9c3190
--- /dev/null
+++ b/src/main/java/me/clip/placeholderapi/util/TimeFormat.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * PlaceholderAPI
+ * Copyright (C) 2019 Ryan McCarthy
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ *
+ */
+package me.clip.placeholderapi.util;
+
+public enum TimeFormat {
+ DAYS,
+ HOURS,
+ MINUTES,
+ SECONDS
+}
diff --git a/src/main/java/me/clip/placeholderapi/util/TimeUtil.java b/src/main/java/me/clip/placeholderapi/util/TimeUtil.java
index 8c834ff..b320ecf 100644
--- a/src/main/java/me/clip/placeholderapi/util/TimeUtil.java
+++ b/src/main/java/me/clip/placeholderapi/util/TimeUtil.java
@@ -22,10 +22,10 @@ package me.clip.placeholderapi.util;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
-import java.util.concurrent.TimeUnit;
public class TimeUtil {
- public static String getRemaining(int seconds, TimeUnit type) {
+
+ public static String getRemaining(int seconds, TimeFormat type) {
if (seconds < 60) {
switch (type) {
case DAYS:
@@ -124,8 +124,8 @@ public class TimeUtil {
* @param duration {@link Duration} (eg, Duration.of(20, {@link ChronoUnit#SECONDS}) for 20 seconds)
* @return formatted time
*/
- public static String getTime(Duration duration) {
- StringBuilder builder = new StringBuilder();
+ public static String getTime(final Duration duration) {
+ final StringBuilder builder = new StringBuilder();
long seconds = duration.getSeconds();
long minutes = seconds / 60;
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 8b3e5aa..d4031ef 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -4,51 +4,39 @@ version: ${project.version}
api-version: '1.13'
authors: [extended_clip, Glare]
description: ${project.description}
-
-commands:
- placeholderapi:
- description: PlaceholderAPI command
- aliases: [papi]
-
permissions:
- placeholderapi.*:
- description: ability to use all commands
- children:
- placeholderapi.admin: true
- placeholderapi.admin:
- description: ability to use all commands
- children:
- placeholderapi.list: true
- placeholderapi.reload: true
- placeholderapi.ecloud: true
- placeholderapi.parse: true
- placeholderapi.register: true
- placeholderapi.updatenotify: true
- placeholderapi.list:
- description: ability to use the list command
- default: op
- placeholderapi.reload:
- description: ability to use the reload command
- default: op
- placeholderapi.parse:
- description: ability to use parse command
- default: op
- placeholderapi.register:
- description: ability to register or unregister placeholder expansions
- default: op
- placeholderapi.ecloud:
- description: allows the usage of ecloud commands
- default: op
- children:
- placeholderapi.ecloud.enable: true
- placeholderapi.ecloud.disable: true
- placeholderapi.ecloud.list: true
- placeholderapi.ecloud.info: true
- placeholderapi.ecloud.clear: true
- placeholderapi.ecloud.status: true
- placeholderapi.ecloud.refresh: true
- placeholderapi.ecloud.download: true
- placeholderapi.ecloud.versioninfo: true
- placeholderapi.updatenotify:
- description: notifies you when there is a PAPI update
- default: op
\ No newline at end of file
+ placeholderapi.*:
+ description: ability to use all commands
+ children:
+ placeholderapi.admin: true
+ placeholderapi.admin:
+ description: ability to use all commands
+ children:
+ placeholderapi.list: true
+ placeholderapi.reload: true
+ placeholderapi.ecloud: true
+ placeholderapi.parse: true
+ placeholderapi.register: true
+ placeholderapi.updatenotify: true
+ placeholderapi.list:
+ description: ability to use the list command
+ default: op
+ placeholderapi.reload:
+ description: ability to use the reload command
+ default: op
+ placeholderapi.parse:
+ description: ability to use parse command
+ default: op
+ placeholderapi.register:
+ description: ability to register or unregister placeholder expansions
+ default: op
+ placeholderapi.ecloud:
+ description: allows the usage of ecloud commands
+ default: op
+ placeholderapi.updatenotify:
+ description: notifies you when there is a PAPI update
+ default: op
+commands:
+ placeholderapi:
+ description: PlaceholderAPI command
+ aliases: [papi]