mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
Cleanup formatting / spacing
This commit is contained in:
parent
c9abc4ae00
commit
dfbf1b95f6
@ -72,14 +72,16 @@ public class PlaceholderAPI {
|
|||||||
* @return true if the hook was successfully registered, false if there is already a hook
|
* @return true if the hook was successfully registered, false if there is already a hook
|
||||||
* registered for the specified identifier
|
* registered for the specified identifier
|
||||||
*/
|
*/
|
||||||
public static boolean registerPlaceholderHook(String identifier,
|
public static boolean registerPlaceholderHook(String identifier, PlaceholderHook placeholderHook) {
|
||||||
PlaceholderHook placeholderHook) {
|
|
||||||
Validate.notNull(identifier, "Identifier can not be null");
|
Validate.notNull(identifier, "Identifier can not be null");
|
||||||
Validate.notNull(placeholderHook, "Placeholderhook can not be null");
|
Validate.notNull(placeholderHook, "Placeholderhook can not be null");
|
||||||
|
|
||||||
if (isRegistered(identifier)) {
|
if (isRegistered(identifier)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
placeholders.put(identifier.toLowerCase(), placeholderHook);
|
placeholders.put(identifier.toLowerCase(), placeholderHook);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +119,7 @@ public class PlaceholderAPI {
|
|||||||
Set<PlaceholderExpansion> set = getPlaceholders().values().stream()
|
Set<PlaceholderExpansion> set = getPlaceholders().values().stream()
|
||||||
.filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast)
|
.filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast)
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
return ImmutableSet.copyOf(set);
|
return ImmutableSet.copyOf(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,6 +180,7 @@ public class PlaceholderAPI {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return text.stream().map(line -> setPlaceholders(p, line, pattern))
|
return text.stream().map(line -> setPlaceholders(p, line, pattern))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@ -215,24 +219,29 @@ public class PlaceholderAPI {
|
|||||||
* underscore separating the identifier from the params
|
* underscore separating the identifier from the params
|
||||||
* @return text with all placeholders set to the corresponding values
|
* @return text with all placeholders set to the corresponding values
|
||||||
*/
|
*/
|
||||||
public static String setPlaceholders(OfflinePlayer player, String text,
|
public static String setPlaceholders(OfflinePlayer player, String text, Pattern placeholderPattern) {
|
||||||
Pattern placeholderPattern) {
|
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (placeholders.isEmpty()) {
|
if (placeholders.isEmpty()) {
|
||||||
return color(text);
|
return color(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher m = placeholderPattern.matcher(text);
|
Matcher m = placeholderPattern.matcher(text);
|
||||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||||
|
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String format = m.group(1);
|
String format = m.group(1);
|
||||||
int index = format.indexOf("_");
|
int index = format.indexOf("_");
|
||||||
|
|
||||||
if (index <= 0 || index >= format.length()) {
|
if (index <= 0 || index >= format.length()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String identifier = format.substring(0, index).toLowerCase();
|
String identifier = format.substring(0, index).toLowerCase();
|
||||||
String params = format.substring(index + 1);
|
String params = format.substring(index + 1);
|
||||||
|
|
||||||
if (hooks.containsKey(identifier)) {
|
if (hooks.containsKey(identifier)) {
|
||||||
String value = hooks.get(identifier).onRequest(player, params);
|
String value = hooks.get(identifier).onRequest(player, params);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@ -240,6 +249,7 @@ public class PlaceholderAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return color(text);
|
return color(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +266,7 @@ public class PlaceholderAPI {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
|
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@ -273,30 +284,39 @@ public class PlaceholderAPI {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (placeholders.isEmpty()) {
|
if (placeholders.isEmpty()) {
|
||||||
return color(text);
|
return color(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||||
|
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
String format = m.group(2);
|
String format = m.group(2);
|
||||||
int index = format.indexOf("_");
|
int index = format.indexOf("_");
|
||||||
|
|
||||||
if (index <= 0 || index >= format.length()) {
|
if (index <= 0 || index >= format.length()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String identifier = format.substring(0, index).toLowerCase();
|
String identifier = format.substring(0, index).toLowerCase();
|
||||||
String params = format.substring(index + 1);
|
String params = format.substring(index + 1);
|
||||||
|
|
||||||
if (hooks.containsKey(identifier)) {
|
if (hooks.containsKey(identifier)) {
|
||||||
if (!(hooks.get(identifier) instanceof Relational)) {
|
if (!(hooks.get(identifier) instanceof Relational)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Relational rel = (Relational) hooks.get(identifier);
|
Relational rel = (Relational) hooks.get(identifier);
|
||||||
String value = rel.onPlaceholderRequest(one, two, params);
|
String value = rel.onPlaceholderRequest(one, two, params);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return color(text);
|
return color(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,9 +335,11 @@ public class PlaceholderAPI {
|
|||||||
if (placeholders.isEmpty()) {
|
if (placeholders.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlaceholders().forEach((key, value) -> {
|
getPlaceholders().forEach((key, value) -> {
|
||||||
if (value instanceof PlaceholderExpansion) {
|
if (value instanceof PlaceholderExpansion) {
|
||||||
PlaceholderExpansion ex = (PlaceholderExpansion) value;
|
PlaceholderExpansion ex = (PlaceholderExpansion) value;
|
||||||
|
|
||||||
if (!ex.persist()) {
|
if (!ex.persist()) {
|
||||||
unregisterExpansion(ex);
|
unregisterExpansion(ex);
|
||||||
}
|
}
|
||||||
@ -330,6 +352,7 @@ public class PlaceholderAPI {
|
|||||||
Bukkit.getPluginManager().callEvent(new ExpansionRegisterEvent(ex));
|
Bukkit.getPluginManager().callEvent(new ExpansionRegisterEvent(ex));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,6 +361,7 @@ public class PlaceholderAPI {
|
|||||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
|
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,17 +60,20 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
private static Version getVersion() {
|
private static Version getVersion() {
|
||||||
String v = "unknown";
|
String v = "unknown";
|
||||||
boolean spigot = false;
|
boolean spigot = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
v = Bukkit.getServer().getClass().getPackage().getName()
|
v = Bukkit.getServer().getClass().getPackage().getName()
|
||||||
.split("\\.")[3];
|
.split("\\.")[3];
|
||||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName("org.spigotmc.SpigotConfig");
|
Class.forName("org.spigotmc.SpigotConfig");
|
||||||
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
|
||||||
spigot = true;
|
spigot = true;
|
||||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Version(v, spigot);
|
return new Version(v, spigot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,28 +134,35 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
config.loadDefConfig();
|
config.loadDefConfig();
|
||||||
setupOptions();
|
setupOptions();
|
||||||
|
|
||||||
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
getCommand("placeholderapi").setExecutor(new PlaceholderAPICommands(this));
|
||||||
new PlaceholderListener(this);
|
new PlaceholderListener(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
Class.forName("org.bukkit.event.server.ServerLoadEvent");
|
||||||
new ServerLoadEventListener(this);
|
new ServerLoadEventListener(this);
|
||||||
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
|
||||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||||
getLogger().info("Placeholder expansion registration initializing...");
|
getLogger().info("Placeholder expansion registration initializing...");
|
||||||
|
|
||||||
//fetch any hooks that may have registered externally onEnable first otherwise they will be lost
|
//fetch any hooks that may have registered externally onEnable first otherwise they will be lost
|
||||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||||
getExpansionManager().registerAllExpansions();
|
getExpansionManager().registerAllExpansions();
|
||||||
|
|
||||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||||
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
|
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.checkUpdates()) {
|
if (config.checkUpdates()) {
|
||||||
new UpdateChecker(this).fetch();
|
new UpdateChecker(this).fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.isCloudEnabled()) {
|
if (config.isCloudEnabled()) {
|
||||||
enableCloud();
|
enableCloud();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupMetrics();
|
setupMetrics();
|
||||||
getServer().getScheduler().runTaskLater(this, this::checkHook, 40);
|
getServer().getScheduler().runTaskLater(this, this::checkHook, 40);
|
||||||
}
|
}
|
||||||
@ -173,11 +183,13 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
reloadConfig();
|
reloadConfig();
|
||||||
setupOptions();
|
setupOptions();
|
||||||
expansionManager.registerAllExpansions();
|
expansionManager.registerAllExpansions();
|
||||||
|
|
||||||
if (!config.isCloudEnabled()) {
|
if (!config.isCloudEnabled()) {
|
||||||
disableCloud();
|
disableCloud();
|
||||||
} else if (!cloudEnabled) {
|
} else if (!cloudEnabled) {
|
||||||
enableCloud();
|
enableCloud();
|
||||||
}
|
}
|
||||||
|
|
||||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
PlaceholderAPI.getRegisteredIdentifiers().size()
|
PlaceholderAPI.getRegisteredIdentifiers().size()
|
||||||
+ " &aplaceholder hooks successfully registered!"));
|
+ " &aplaceholder hooks successfully registered!"));
|
||||||
@ -185,31 +197,40 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private void checkHook() {
|
private void checkHook() {
|
||||||
Map<String, PlaceholderHook> loaded = PlaceholderAPI.getPlaceholders();
|
Map<String, PlaceholderHook> loaded = PlaceholderAPI.getPlaceholders();
|
||||||
|
|
||||||
loaded.values().forEach(h -> {
|
loaded.values().forEach(h -> {
|
||||||
if (h instanceof EZPlaceholderHook) {
|
if (h instanceof EZPlaceholderHook) {
|
||||||
String author;
|
String author;
|
||||||
try {
|
|
||||||
author = Bukkit.getPluginManager().getPlugin(((EZPlaceholderHook) h).getPluginName()).getDescription().getAuthors().toString();
|
try {
|
||||||
} catch (Exception ex) {
|
author = Bukkit.getPluginManager().getPlugin(((EZPlaceholderHook) h).getPluginName()).getDescription().getAuthors().toString();
|
||||||
author = "the author of the hook's plugin";
|
} catch (Exception ex) {
|
||||||
|
author = "the author of the hook's plugin";
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogger().severe(((EZPlaceholderHook) h).getPluginName() +
|
||||||
|
" is currently using a deprecated method to hook into PlaceholderAPI. Placeholders for that plugin no longer work. " +
|
||||||
|
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
|
||||||
|
|
||||||
|
// disable the hook on startup
|
||||||
|
PlaceholderAPI.unregisterPlaceholderHook(((EZPlaceholderHook) h).getPlaceholderName());
|
||||||
}
|
}
|
||||||
getLogger().severe(((EZPlaceholderHook) h).getPluginName() + " is currently using a deprecated method to hook into PlaceholderAPI. Placeholders for that plugin no longer work. " +
|
|
||||||
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
|
|
||||||
// disable the hook on startup
|
|
||||||
PlaceholderAPI.unregisterPlaceholderHook(((EZPlaceholderHook) h).getPlaceholderName());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupOptions() {
|
private void setupOptions() {
|
||||||
booleanTrue = config.booleanTrue();
|
booleanTrue = config.booleanTrue();
|
||||||
|
|
||||||
if (booleanTrue == null) {
|
if (booleanTrue == null) {
|
||||||
booleanTrue = "true";
|
booleanTrue = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
booleanFalse = config.booleanFalse();
|
booleanFalse = config.booleanFalse();
|
||||||
|
|
||||||
if (booleanFalse == null) {
|
if (booleanFalse == null) {
|
||||||
booleanFalse = "false";
|
booleanFalse = "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dateFormat = new SimpleDateFormat(config.dateFormat());
|
dateFormat = new SimpleDateFormat(config.dateFormat());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -37,6 +37,7 @@ public abstract class PlaceholderHook {
|
|||||||
if (p != null && p.isOnline()) {
|
if (p != null && p.isOnline()) {
|
||||||
return onPlaceholderRequest((Player) p, params);
|
return onPlaceholderRequest((Player) p, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
return onPlaceholderRequest(null, params);
|
return onPlaceholderRequest(null, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ public class PlaceholderListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
public void onExpansionUnregister(ExpansionUnregisterEvent event) {
|
||||||
|
|
||||||
if (event.getExpansion() instanceof Listener) {
|
if (event.getExpansion() instanceof Listener) {
|
||||||
HandlerList.unregisterAll((Listener) event.getExpansion());
|
HandlerList.unregisterAll((Listener) event.getExpansion());
|
||||||
}
|
}
|
||||||
@ -76,7 +75,6 @@ public class PlaceholderListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPluginUnload(PluginDisableEvent e) {
|
public void onPluginUnload(PluginDisableEvent e) {
|
||||||
|
|
||||||
String n = e.getPlugin().getName();
|
String n = e.getPlugin().getName();
|
||||||
|
|
||||||
if (n == null) {
|
if (n == null) {
|
||||||
@ -90,11 +88,9 @@ public class PlaceholderListener implements Listener {
|
|||||||
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
|
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
|
||||||
|
|
||||||
for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) {
|
for (Entry<String, PlaceholderHook> hook : hooks.entrySet()) {
|
||||||
|
|
||||||
PlaceholderHook i = hook.getValue();
|
PlaceholderHook i = hook.getValue();
|
||||||
|
|
||||||
if (i instanceof PlaceholderExpansion) {
|
if (i instanceof PlaceholderExpansion) {
|
||||||
|
|
||||||
PlaceholderExpansion ex = (PlaceholderExpansion) i;
|
PlaceholderExpansion ex = (PlaceholderExpansion) i;
|
||||||
|
|
||||||
if (ex.getRequiredPlugin() == null) {
|
if (ex.getRequiredPlugin() == null) {
|
||||||
@ -112,7 +108,6 @@ public class PlaceholderListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerQuitEvent e) {
|
public void onQuit(PlayerQuitEvent e) {
|
||||||
|
|
||||||
Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions();
|
Set<PlaceholderExpansion> expansions = PlaceholderAPI.getExpansions();
|
||||||
|
|
||||||
if (expansions.isEmpty()) {
|
if (expansions.isEmpty()) {
|
||||||
|
@ -30,6 +30,7 @@ public class ServerLoadEventListener implements Listener {
|
|||||||
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
plugin.getLogger().info("Placeholder expansion registration initializing...");
|
||||||
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
|
||||||
plugin.getExpansionManager().registerAllExpansions();
|
plugin.getExpansionManager().registerAllExpansions();
|
||||||
|
|
||||||
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
|
||||||
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
|
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
|
||||||
}
|
}
|
||||||
|
@ -76,22 +76,24 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||||
plugin.getExpansionCloud().clean();
|
plugin.getExpansionCloud().clean();
|
||||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) {
|
if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) {
|
||||||
msg(s, "&7No cloud expansions are available at this time.");
|
msg(s, "&7No cloud expansions are available at this time.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("clear")) {
|
if (args[1].equalsIgnoreCase("clear")) {
|
||||||
plugin.getExpansionCloud().clean();
|
|
||||||
msg(s, "&aThe cache has been cleared!!");
|
msg(s, "&aThe cache has been cleared!!");
|
||||||
|
plugin.getExpansionCloud().clean();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("status")) {
|
if (args[1].equalsIgnoreCase("status")) {
|
||||||
|
|
||||||
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size()
|
msg(s, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size()
|
||||||
+ " &bexpansions available on the cloud.",
|
+ " &bexpansions available on the cloud.",
|
||||||
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount()
|
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount()
|
||||||
@ -105,9 +107,9 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("info")) {
|
if (args[1].equalsIgnoreCase("info")) {
|
||||||
|
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
msg(s, "&cAn expansion name must be specified!");
|
msg(s, "&cAn expansion name must be specified!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +117,7 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (expansion == null) {
|
if (expansion == null) {
|
||||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +125,7 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
msg(s,
|
msg(s,
|
||||||
(expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion
|
(expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion
|
||||||
.getVersion().getUrl());
|
.getVersion().getUrl());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,21 +164,18 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("versioninfo")) {
|
if (args[1].equalsIgnoreCase("versioninfo")) {
|
||||||
|
|
||||||
if (args.length < 4) {
|
if (args.length < 4) {
|
||||||
msg(s, "&cAn expansion name and version must be specified!");
|
msg(s, "&cAn expansion name and version must be specified!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||||
|
|
||||||
if (expansion == null) {
|
if (expansion == null) {
|
||||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion.Version version = expansion.getVersion(args[3]);
|
CloudExpansion.Version version = expansion.getVersion(args[3]);
|
||||||
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
||||||
return true;
|
return true;
|
||||||
@ -195,29 +196,30 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
download.suggestCommand(
|
download.suggestCommand(
|
||||||
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||||
download.send(p);
|
download.send(p);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("placeholders")) {
|
if (args[1].equalsIgnoreCase("placeholders")) {
|
||||||
|
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
msg(s, "&cAn expansion name must be specified!");
|
msg(s, "&cAn expansion name must be specified!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||||
|
|
||||||
if (expansion == null) {
|
if (expansion == null) {
|
||||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> placeholders = expansion.getPlaceholders();
|
List<String> placeholders = expansion.getPlaceholders();
|
||||||
|
|
||||||
if (placeholders == null) {
|
if (placeholders == null) {
|
||||||
msg(s, "&cThe expansion: &f" + expansion.getName()
|
msg(s, "&cThe expansion: &f" + expansion.getName()
|
||||||
+ " &cdoes not have any placeholders listed.",
|
+ " &cdoes not have any placeholders listed.",
|
||||||
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
"&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +227,7 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|| plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
|| plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
||||||
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
||||||
String.join("&a, &f", placeholders));
|
String.join("&a, &f", placeholders));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,11 +245,11 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message.send(p);
|
message.send(p);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("list")) {
|
if (args[1].equalsIgnoreCase("list")) {
|
||||||
|
|
||||||
int page = 1;
|
int page = 1;
|
||||||
|
|
||||||
String author;
|
String author;
|
||||||
@ -271,17 +274,18 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
page = Integer.parseInt(args[3]);
|
page = Integer.parseInt(args[3]);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
msg(s, "&cPage number must be an integer!");
|
msg(s, "&cPage number must be an integer!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page < 1) {
|
if (page < 1) {
|
||||||
msg(s, "&cPage must be greater than or equal to 1!");
|
msg(s, "&cPage must be greater than or equal to 1!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int avail;
|
int avail;
|
||||||
|
|
||||||
Map<Integer, CloudExpansion> ex;
|
Map<Integer, CloudExpansion> ex;
|
||||||
|
|
||||||
if (installed) {
|
if (installed) {
|
||||||
@ -294,14 +298,15 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (ex == null || ex.isEmpty()) {
|
if (ex == null || ex.isEmpty()) {
|
||||||
msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : ""));
|
msg(s, "&cNo expansions available" + (author != null ? " for author &f" + author : ""));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
||||||
|
|
||||||
if (page > avail) {
|
if (page > avail) {
|
||||||
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!"
|
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!"
|
||||||
: "are only &f" + avail + " &cpages available!"));
|
: "are only &f" + avail + " &cpages available!"));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,6 +318,7 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
msg(s, "&cThere was a problem getting the requested page...");
|
msg(s, "&cThere was a problem getting the requested page...");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,19 +327,25 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (!(s instanceof Player)) {
|
if (!(s instanceof Player)) {
|
||||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||||
|
|
||||||
for (CloudExpansion exp : ex.values()) {
|
for (CloudExpansion exp : ex.values()) {
|
||||||
if (exp == null || exp.getName() == null) {
|
if (exp == null || exp.getName() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
expansions.put(exp.getName(), exp);
|
expansions.put(exp.getName(), exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||||
int i = (int) ex.keySet().toArray()[0]+1;
|
int i = (int) ex.keySet().toArray()[0]+1;
|
||||||
|
|
||||||
for (String name : ce) {
|
for (String name : ce) {
|
||||||
if (expansions.get(name) == null) {
|
if (expansions.get(name) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion expansion = expansions.get(name);
|
CloudExpansion expansion = expansions.get(name);
|
||||||
|
|
||||||
msg(s,
|
msg(s,
|
||||||
"&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6"
|
"&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||||
: (expansion.hasExpansion() ? "&a" : "&7")) + expansion
|
: (expansion.hasExpansion() ? "&a" : "&7")) + expansion
|
||||||
@ -347,20 +359,26 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
Player p = (Player) s;
|
Player p = (Player) s;
|
||||||
|
|
||||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||||
|
|
||||||
for (CloudExpansion exp : ex.values()) {
|
for (CloudExpansion exp : ex.values()) {
|
||||||
if (exp == null || exp.getName() == null) {
|
if (exp == null || exp.getName() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
expansions.put(exp.getName(), exp);
|
expansions.put(exp.getName(), exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
for (String name : ce) {
|
for (String name : ce) {
|
||||||
if (expansions.get(name) == null) {
|
if (expansions.get(name) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion expansion = expansions.get(name);
|
CloudExpansion expansion = expansions.get(name);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if (expansion.shouldUpdate()) {
|
if (expansion.shouldUpdate()) {
|
||||||
sb.append("&6Click to update to the latest version of this expansion\n\n");
|
sb.append("&6Click to update to the latest version of this expansion\n\n");
|
||||||
} else if (!expansion.hasExpansion()) {
|
} else if (!expansion.hasExpansion()) {
|
||||||
@ -368,11 +386,11 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
} else {
|
} else {
|
||||||
sb.append("&aYou have the latest version of this expansion\n\n");
|
sb.append("&aYou have the latest version of this expansion\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append("&bAuthor&7: &f" + expansion.getAuthor() + "\n");
|
sb.append("&bAuthor&7: &f" + expansion.getAuthor() + "\n");
|
||||||
sb.append("&bVerified&7: &f" + expansion.isVerified() + "\n");
|
sb.append("&bVerified&7: &f" + expansion.isVerified() + "\n");
|
||||||
sb.append("&bLatest version&7: &f" + expansion.getVersion().getVersion() + "\n");
|
sb.append("&bLatest version&7: &f" + expansion.getVersion().getVersion() + "\n");
|
||||||
sb.append(
|
sb.append("&bLast updated&7: &f" + expansion.getTimeSinceLastUpdate() + " ago\n");
|
||||||
"&bLast updated&7: &f" + expansion.getTimeSinceLastUpdate() + " ago\n");
|
|
||||||
sb.append("\n" + expansion.getDescription());
|
sb.append("\n" + expansion.getDescription());
|
||||||
|
|
||||||
String msg = color(
|
String msg = color(
|
||||||
@ -383,34 +401,33 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
|
|
||||||
JSONMessage line = JSONMessage.create(msg);
|
JSONMessage line = JSONMessage.create(msg);
|
||||||
line.tooltip(hover);
|
line.tooltip(hover);
|
||||||
|
|
||||||
if (expansion.shouldUpdate()) {
|
if (expansion.shouldUpdate()) {
|
||||||
line.suggestCommand("/papi ecloud download " + expansion.getName());
|
line.suggestCommand("/papi ecloud download " + expansion.getName());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
line.suggestCommand("/papi ecloud info " + expansion.getName());
|
line.suggestCommand("/papi ecloud info " + expansion.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
line.send(p);
|
line.send(p);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("download")) {
|
if (args[1].equalsIgnoreCase("download")) {
|
||||||
|
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
msg(s, "&cAn expansion name must be specified!");
|
msg(s, "&cAn expansion name must be specified!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||||
|
|
||||||
if (expansion == null) {
|
if (expansion == null) {
|
||||||
msg(s, "&cNo expansion found with the name: &f" + args[2]);
|
msg(s, "&cNo expansion found with the name: &f" + args[2]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]);
|
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]);
|
||||||
|
|
||||||
if (loaded != null && loaded.isRegistered()) {
|
if (loaded != null && loaded.isRegistered()) {
|
||||||
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
||||||
}
|
}
|
||||||
@ -423,20 +440,22 @@ public class ExpansionCloudCommands implements CommandExecutor {
|
|||||||
msg(s, "&cThe version you specified does not exist for &f" + expansion.getName());
|
msg(s, "&cThe version you specified does not exist for &f" + expansion.getName());
|
||||||
msg(s, "&7Available versions: &f" + expansion.getVersions().size());
|
msg(s, "&7Available versions: &f" + expansion.getVersions().size());
|
||||||
msg(s, String.join("&a, &f", expansion.getAvailableVersions()));
|
msg(s, String.join("&a, &f", expansion.getAvailableVersions()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f"
|
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version);
|
||||||
+ version);
|
|
||||||
String player = ((s instanceof Player) ? s.getName() : null);
|
String player = ((s instanceof Player) ? s.getName() : null);
|
||||||
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
||||||
plugin.getExpansionCloud().clean();
|
plugin.getExpansionCloud().clean();
|
||||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg(s, "&cIncorrect usage! &b/papi ecloud");
|
msg(s, "&cIncorrect usage! &b/papi ecloud");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
"&fCreated by&7: &b" + plugin.getDescription().getAuthors(),
|
"&fCreated by&7: &b" + plugin.getDescription().getAuthors(),
|
||||||
"&fPapi commands: &b/papi help",
|
"&fPapi commands: &b/papi help",
|
||||||
"&fEcloud commands: &b/papi ecloud");
|
"&fEcloud commands: &b/papi ecloud");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("help")) {
|
if (args[0].equalsIgnoreCase("help")) {
|
||||||
|
|
||||||
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
|
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
|
||||||
@ -76,6 +76,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
"&fUnregister an expansion by name",
|
"&fUnregister an expansion by name",
|
||||||
"&b/papi reload",
|
"&b/papi reload",
|
||||||
"&fReload the config settings");
|
"&fReload the config settings");
|
||||||
|
|
||||||
if (s.hasPermission("placeholderapi.ecloud")) {
|
if (s.hasPermission("placeholderapi.ecloud")) {
|
||||||
if (plugin.getExpansionCloud() == null) {
|
if (plugin.getExpansionCloud() == null) {
|
||||||
Msg.msg(s, "&b/papi enablecloud",
|
Msg.msg(s, "&b/papi enablecloud",
|
||||||
@ -87,88 +88,113 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
"&fView ecloud command usage");
|
"&fView ecloud command usage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("ecloud")) {
|
} else if (args[0].equalsIgnoreCase("ecloud")) {
|
||||||
|
|
||||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getExpansionCloud() == null) {
|
if (plugin.getExpansionCloud() == null) {
|
||||||
Msg.msg(s, "&7The expansion cloud is not enabled!");
|
Msg.msg(s, "&7The expansion cloud is not enabled!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return eCloud.onCommand(s, c, label, args);
|
return eCloud.onCommand(s, c, label, args);
|
||||||
} else if (args[0].equalsIgnoreCase("enablecloud")) {
|
} else if (args[0].equalsIgnoreCase("enablecloud")) {
|
||||||
|
|
||||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getExpansionCloud() != null) {
|
if (plugin.getExpansionCloud() != null) {
|
||||||
Msg.msg(s, "&7The cloud is already enabled!");
|
Msg.msg(s, "&7The cloud is already enabled!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.enableCloud();
|
plugin.enableCloud();
|
||||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
|
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
|
||||||
Msg.msg(s, "&aThe cloud has been enabled!");
|
Msg.msg(s, "&aThe cloud has been enabled!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("disablecloud")) {
|
} else if (args[0].equalsIgnoreCase("disablecloud")) {
|
||||||
|
|
||||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getExpansionCloud() == null) {
|
if (plugin.getExpansionCloud() == null) {
|
||||||
Msg.msg(s, "&7The cloud is already disabled!");
|
Msg.msg(s, "&7The cloud is already disabled!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.disableCloud();
|
plugin.disableCloud();
|
||||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
||||||
Msg.msg(s, "&aThe cloud has been disabled!");
|
Msg.msg(s, "&aThe cloud has been disabled!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
|
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
|
||||||
|
|
||||||
if (!s.hasPermission("placeholderapi.info")) {
|
if (!s.hasPermission("placeholderapi.info")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
|
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
|
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
|
||||||
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
|
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
|
||||||
|
|
||||||
if (ex.getAuthor() != null) {
|
if (ex.getAuthor() != null) {
|
||||||
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
|
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ex.getVersion() != null) {
|
if (ex.getVersion() != null) {
|
||||||
Msg.msg(s, "&7Version: &f" + ex.getVersion());
|
Msg.msg(s, "&7Version: &f" + ex.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ex.getRequiredPlugin() != null) {
|
if (ex.getRequiredPlugin() != null) {
|
||||||
Msg.msg(s, "&7Requires plugin: &f" + ex.getRequiredPlugin());
|
Msg.msg(s, "&7Requires plugin: &f" + ex.getRequiredPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ex.getPlaceholders() != null) {
|
if (ex.getPlaceholders() != null) {
|
||||||
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
|
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
|
||||||
|
|
||||||
for (String placeholder : ex.getPlaceholders()) {
|
for (String placeholder : ex.getPlaceholders()) {
|
||||||
Msg.msg(s, placeholder);
|
Msg.msg(s, placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")
|
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")
|
||||||
|| args.length > 2 && args[0].equalsIgnoreCase("bcparse")) {
|
|| args.length > 2 && args[0].equalsIgnoreCase("bcparse")) {
|
||||||
|
|
||||||
if (!s.hasPermission("placeholderapi.parse")) {
|
if (!s.hasPermission("placeholderapi.parse")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
OfflinePlayer pl = null;
|
|
||||||
|
OfflinePlayer pl;
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("me")) {
|
if (args[1].equalsIgnoreCase("me")) {
|
||||||
if (s instanceof Player) {
|
if (s instanceof Player) {
|
||||||
pl = (Player) s;
|
pl = (Player) s;
|
||||||
} else {
|
} else {
|
||||||
Msg.msg(s, "&cThis command must target a player when used by console");
|
Msg.msg(s, "&cThis command must target a player when used by console");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -178,56 +204,67 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
pl = Bukkit.getOfflinePlayer(args[1]);
|
pl = Bukkit.getOfflinePlayer(args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pl == null || !pl.hasPlayedBefore()) {
|
if (pl == null || !pl.hasPlayedBefore()) {
|
||||||
Msg.msg(s, "&cFailed to find player: &f" + args[1]);
|
Msg.msg(s, "&cFailed to find player: &f" + args[1]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String parse = StringUtils.join(args, " ", 2, args.length);
|
String parse = StringUtils.join(args, " ", 2, args.length);
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("bcparse")) {
|
if (args[0].equalsIgnoreCase("bcparse")) {
|
||||||
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||||
} else {
|
} else {
|
||||||
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
|
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
|
||||||
|
|
||||||
if (!(s instanceof Player)) {
|
if (!(s instanceof Player)) {
|
||||||
Msg.msg(s, "&cThis command can only be used in game!");
|
Msg.msg(s, "&cThis command can only be used in game!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (!s.hasPermission("placeholderapi.parse")) {
|
if (!s.hasPermission("placeholderapi.parse")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Player one = Bukkit.getPlayer(args[1]);
|
Player one = Bukkit.getPlayer(args[1]);
|
||||||
if (one == null) {
|
if (one == null) {
|
||||||
Msg.msg(s, args[1] + " &cis not online!");
|
Msg.msg(s, args[1] + " &cis not online!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player two = Bukkit.getPlayer(args[2]);
|
Player two = Bukkit.getPlayer(args[2]);
|
||||||
if (two == null) {
|
if (two == null) {
|
||||||
Msg.msg(s, args[2] + " &cis not online!");
|
Msg.msg(s, args[2] + " &cis not online!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String parse = StringUtils.join(args, " ", 3, args.length);
|
String parse = StringUtils.join(args, " ", 3, args.length);
|
||||||
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||||
|
|
||||||
if (s instanceof Player) {
|
if (s instanceof Player) {
|
||||||
if (!s.hasPermission("placeholderapi.reload")) {
|
if (!s.hasPermission("placeholderapi.reload")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
|
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
|
||||||
plugin.reloadConf(s);
|
plugin.reloadConf(s);
|
||||||
} else if (args[0].equalsIgnoreCase("list")) {
|
} else if (args[0].equalsIgnoreCase("list")) {
|
||||||
|
|
||||||
if (s instanceof Player) {
|
if (s instanceof Player) {
|
||||||
if (!s.hasPermission("placeholderapi.list")) {
|
if (!s.hasPermission("placeholderapi.list")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,15 +272,17 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||||
if (registered.isEmpty()) {
|
if (registered.isEmpty()) {
|
||||||
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
|
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg.msg(s, registered.size() + " &7Placeholder hooks registered:");
|
Msg.msg(s, registered.size() + " &7Placeholder hooks registered:");
|
||||||
Msg.msg(s, registered.stream().sorted().collect(Collectors.joining(", ")));
|
Msg.msg(s, registered.stream().sorted().collect(Collectors.joining(", ")));
|
||||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("register")) {
|
} else if (args.length > 1 && args[0].equalsIgnoreCase("register")) {
|
||||||
|
|
||||||
if (s instanceof Player) {
|
if (s instanceof Player) {
|
||||||
if (!s.hasPermission("placeholderapi.register")) {
|
if (!s.hasPermission("placeholderapi.register")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,6 +292,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
|
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
Msg.msg(s, "&cFailed to register expansion from " + fileName);
|
Msg.msg(s, "&cFailed to register expansion from " + fileName);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,14 +302,15 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
if (s instanceof Player) {
|
if (s instanceof Player) {
|
||||||
if (!s.hasPermission("placeholderapi.register")) {
|
if (!s.hasPermission("placeholderapi.register")) {
|
||||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||||
|
|
||||||
if (ex == null) {
|
if (ex == null) {
|
||||||
Msg.msg(s, "&cFailed to find expansion: &f" + args[1]);
|
Msg.msg(s, "&cFailed to find expansion: &f" + args[1]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,6 +324,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
|
|||||||
Msg.msg(s, "&cIncorrect usage! &7/papi help");
|
Msg.msg(s, "&cIncorrect usage! &7/papi help");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public final class ExpansionManager {
|
|||||||
|
|
||||||
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
|
|
||||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
|
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
f.mkdirs();
|
f.mkdirs();
|
||||||
@ -54,6 +55,7 @@ public final class ExpansionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,16 +63,19 @@ public final class ExpansionManager {
|
|||||||
if (expansion == null || expansion.getIdentifier() == null) {
|
if (expansion == null || expansion.getIdentifier() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expansion instanceof Configurable) {
|
if (expansion instanceof Configurable) {
|
||||||
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
||||||
String pre = "expansions." + expansion.getIdentifier() + ".";
|
String pre = "expansions." + expansion.getIdentifier() + ".";
|
||||||
FileConfiguration cfg = plugin.getConfig();
|
FileConfiguration cfg = plugin.getConfig();
|
||||||
boolean save = false;
|
boolean save = false;
|
||||||
|
|
||||||
if (defaults != null) {
|
if (defaults != null) {
|
||||||
for (Entry<String, Object> entries : defaults.entrySet()) {
|
for (Entry<String, Object> entries : defaults.entrySet()) {
|
||||||
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries.getValue() == null) {
|
if (entries.getValue() == null) {
|
||||||
if (cfg.contains(pre + entries.getKey())) {
|
if (cfg.contains(pre + entries.getKey())) {
|
||||||
save = true;
|
save = true;
|
||||||
@ -84,11 +89,13 @@ public final class ExpansionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save) {
|
if (save) {
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expansion instanceof VersionSpecific) {
|
if (expansion instanceof VersionSpecific) {
|
||||||
VersionSpecific nms = (VersionSpecific) expansion;
|
VersionSpecific nms = (VersionSpecific) expansion;
|
||||||
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
|
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
|
||||||
@ -99,22 +106,29 @@ public final class ExpansionManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expansion.canRegister()) {
|
if (!expansion.canRegister()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expansion.register()) {
|
if (!expansion.register()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expansion instanceof Listener) {
|
if (expansion instanceof Listener) {
|
||||||
Listener l = (Listener) expansion;
|
Listener l = (Listener) expansion;
|
||||||
Bukkit.getPluginManager().registerEvents(l, plugin);
|
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
|
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
|
||||||
|
|
||||||
if (expansion instanceof Taskable) {
|
if (expansion instanceof Taskable) {
|
||||||
((Taskable) expansion).start();
|
((Taskable) expansion).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getExpansionCloud() != null) {
|
if (plugin.getExpansionCloud() != null) {
|
||||||
CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier());
|
CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier());
|
||||||
|
|
||||||
if (ce != null) {
|
if (ce != null) {
|
||||||
ce.setHasExpansion(true);
|
ce.setHasExpansion(true);
|
||||||
if (!ce.getLatestVersion().equals(expansion.getVersion())) {
|
if (!ce.getLatestVersion().equals(expansion.getVersion())) {
|
||||||
@ -122,6 +136,7 @@ public final class ExpansionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,12 +146,14 @@ public final class ExpansionManager {
|
|||||||
if (subs == null || subs.isEmpty()) {
|
if (subs == null || subs.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only register the first instance found as an expansion jar should only have 1 class
|
// only register the first instance found as an expansion jar should only have 1 class
|
||||||
// extending PlaceholderExpansion
|
// extending PlaceholderExpansion
|
||||||
PlaceholderExpansion ex = createInstance(subs.get(0));
|
PlaceholderExpansion ex = createInstance(subs.get(0));
|
||||||
if (registerExpansion(ex)) {
|
if (registerExpansion(ex)) {
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,10 +161,12 @@ public final class ExpansionManager {
|
|||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Class<?>> subs = FileUtil.getClasses("expansions", null, PlaceholderExpansion.class);
|
List<Class<?>> subs = FileUtil.getClasses("expansions", null, PlaceholderExpansion.class);
|
||||||
if (subs == null || subs.isEmpty()) {
|
if (subs == null || subs.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Class<?> klass : subs) {
|
for (Class<?> klass : subs) {
|
||||||
PlaceholderExpansion ex = createInstance(klass);
|
PlaceholderExpansion ex = createInstance(klass);
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
@ -160,10 +179,12 @@ public final class ExpansionManager {
|
|||||||
if (klass == null) {
|
if (klass == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceholderExpansion ex = null;
|
PlaceholderExpansion ex = null;
|
||||||
if (!PlaceholderExpansion.class.isAssignableFrom(klass)) {
|
if (!PlaceholderExpansion.class.isAssignableFrom(klass)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Constructor<?>[] c = klass.getConstructors();
|
Constructor<?>[] c = klass.getConstructors();
|
||||||
if (c.length == 0) {
|
if (c.length == 0) {
|
||||||
@ -181,6 +202,7 @@ public final class ExpansionManager {
|
|||||||
.severe("Failed to init placeholder expansion from class: " + klass.getName());
|
.severe("Failed to init placeholder expansion from class: " + klass.getName());
|
||||||
plugin.getLogger().severe(t.getMessage());
|
plugin.getLogger().severe(t.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public enum NMSVersion {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NMSVersion.UNKNOWN;
|
return NMSVersion.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,6 @@ public class CloudExpansion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Version {
|
public class Version {
|
||||||
|
|
||||||
private String url, version, release_notes;
|
private String url, version, release_notes;
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
|
@ -135,16 +135,19 @@ public class ExpansionCloudManager {
|
|||||||
if (map == null) {
|
if (map == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pages = map.size() > 0 ? 1 : 0;
|
int pages = map.size() > 0 ? 1 : 0;
|
||||||
if (pages == 0) {
|
if (pages == 0) {
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.size() > amount) {
|
if (map.size() > amount) {
|
||||||
pages = map.size() / amount;
|
pages = map.size() / amount;
|
||||||
if (map.size() % amount > 0) {
|
if (map.size() % amount > 0) {
|
||||||
pages++;
|
pages++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +167,6 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
|
|
||||||
public void fetch(boolean allowUnverified) {
|
public void fetch(boolean allowUnverified) {
|
||||||
|
|
||||||
plugin.getLogger().info("Fetching available expansion information...");
|
plugin.getLogger().info("Fetching available expansion information...");
|
||||||
|
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
@ -176,7 +178,6 @@ public class ExpansionCloudManager {
|
|||||||
final List<CloudExpansion> unsorted = new ArrayList<>();
|
final List<CloudExpansion> unsorted = new ArrayList<>();
|
||||||
|
|
||||||
data.forEach((name, cexp) -> {
|
data.forEach((name, cexp) -> {
|
||||||
|
|
||||||
if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) {
|
if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) {
|
||||||
cexp.setName(name);
|
cexp.setName(name);
|
||||||
|
|
||||||
@ -207,7 +208,6 @@ public class ExpansionCloudManager {
|
|||||||
if (updates > 0) {
|
if (updates > 0) {
|
||||||
plugin.getLogger().info(updates + " installed expansions have updates available.");
|
plugin.getLogger().info(updates + " installed expansions have updates available.");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,13 +217,11 @@ public class ExpansionCloudManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void download(URL url, String name) throws IOException {
|
private void download(URL url, String name) throws IOException {
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URLConnection urlConn = url.openConnection();
|
URLConnection urlConn = url.openConnection();
|
||||||
|
|
||||||
is = urlConn.getInputStream();
|
is = urlConn.getInputStream();
|
||||||
@ -257,7 +255,6 @@ public class ExpansionCloudManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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())) {
|
if (downloading.contains(ex.getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -279,13 +276,11 @@ public class ExpansionCloudManager {
|
|||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
download(new URL(ver.getUrl()), ex.getName());
|
download(new URL(ver.getUrl()), ex.getName());
|
||||||
|
|
||||||
plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!");
|
plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
plugin.getLogger()
|
plugin.getLogger()
|
||||||
.warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
.warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
||||||
|
|
||||||
@ -306,11 +301,9 @@ public class ExpansionCloudManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
|
|
||||||
downloading.remove(ex.getName());
|
downloading.remove(ex.getName());
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
|
||||||
Player p = Bukkit.getPlayer(player);
|
Player p = Bukkit.getPlayer(player);
|
||||||
|
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
@ -324,16 +317,15 @@ public class ExpansionCloudManager {
|
|||||||
|
|
||||||
|
|
||||||
private static class URLReader {
|
private static class URLReader {
|
||||||
|
|
||||||
static String read(String url) {
|
static String read(String url) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
|
||||||
|
|
||||||
String inputLine;
|
String inputLine;
|
||||||
while ((inputLine = reader.readLine()) != null) {
|
while ((inputLine = reader.readLine()) != null) {
|
||||||
builder.append(inputLine);
|
builder.append(inputLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
builder.setLength(0);
|
builder.setLength(0);
|
||||||
}
|
}
|
||||||
|
@ -65,9 +65,10 @@ public class UpdateChecker implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean spigotIsNewer() {
|
private boolean spigotIsNewer() {
|
||||||
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String plV = toReadable(pluginVersion);
|
String plV = toReadable(pluginVersion);
|
||||||
String spV = toReadable(spigotVersion);
|
String spV = toReadable(spigotVersion);
|
||||||
return plV.compareTo(spV) < 0;
|
return plV.compareTo(spV) < 0;
|
||||||
@ -77,6 +78,7 @@ public class UpdateChecker implements Listener {
|
|||||||
if (version.contains("-DEV-")) {
|
if (version.contains("-DEV-")) {
|
||||||
version = version.split("-DEV-")[0];
|
version = version.split("-DEV-")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return version.replaceAll("\\.", "");
|
return version.replaceAll("\\.", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,28 +38,35 @@ public class FileUtil {
|
|||||||
|
|
||||||
public static List<Class<?>> getClasses(String folder, String fileName, Class<?> type) {
|
public static List<Class<?>> getClasses(String folder, String fileName, Class<?> type) {
|
||||||
List<Class<?>> list = new ArrayList<>();
|
List<Class<?>> list = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), folder);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilenameFilter fileNameFilter = (dir, name) -> {
|
FilenameFilter fileNameFilter = (dir, name) -> {
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
return name.endsWith(".jar") && name.replace(".jar", "")
|
return name.endsWith(".jar") && name.replace(".jar", "")
|
||||||
.equalsIgnoreCase(fileName.replace(".jar", ""));
|
.equalsIgnoreCase(fileName.replace(".jar", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
return name.endsWith(".jar");
|
return name.endsWith(".jar");
|
||||||
};
|
};
|
||||||
|
|
||||||
File[] jars = f.listFiles(fileNameFilter);
|
File[] jars = f.listFiles(fileNameFilter);
|
||||||
if (jars == null) {
|
if (jars == null) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File file : jars) {
|
for (File file : jars) {
|
||||||
list = gather(file.toURI().toURL(), list, type);
|
list = gather(file.toURI().toURL(), list, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,19 +74,23 @@ public class FileUtil {
|
|||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
try (URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()); JarInputStream jis = new JarInputStream(jar.openStream())) {
|
try (URLClassLoader cl = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()); JarInputStream jis = new JarInputStream(jar.openStream())) {
|
||||||
while (true) {
|
while (true) {
|
||||||
JarEntry j = jis.getNextJarEntry();
|
JarEntry j = jis.getNextJarEntry();
|
||||||
if (j == null) {
|
if (j == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = j.getName();
|
String name = j.getName();
|
||||||
if (name == null || name.isEmpty()) {
|
if (name == null || name.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.endsWith(".class")) {
|
if (name.endsWith(".class")) {
|
||||||
name = name.replace("/", ".");
|
name = name.replace("/", ".");
|
||||||
String cname = name.substring(0, name.lastIndexOf(".class"));
|
String cname = name.substring(0, name.lastIndexOf(".class"));
|
||||||
|
|
||||||
Class<?> c = cl.loadClass(cname);
|
Class<?> c = cl.loadClass(cname);
|
||||||
if (clazz.isAssignableFrom(c)) {
|
if (clazz.isAssignableFrom(c)) {
|
||||||
list.add(c);
|
list.add(c);
|
||||||
@ -88,6 +99,7 @@ public class FileUtil {
|
|||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
package me.clip.placeholderapi.util;
|
package me.clip.placeholderapi.util;
|
||||||
|
|
||||||
public enum TimeFormat {
|
public enum TimeFormat {
|
||||||
|
|
||||||
DAYS,
|
DAYS,
|
||||||
HOURS,
|
HOURS,
|
||||||
MINUTES,
|
MINUTES,
|
||||||
|
@ -23,7 +23,6 @@ package me.clip.placeholderapi.util;
|
|||||||
public class TimeUtil {
|
public class TimeUtil {
|
||||||
|
|
||||||
public static String getRemaining(int seconds, TimeFormat type) {
|
public static String getRemaining(int seconds, TimeFormat type) {
|
||||||
|
|
||||||
if (seconds < 60) {
|
if (seconds < 60) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
@ -33,12 +32,14 @@ public class TimeUtil {
|
|||||||
case SECONDS:
|
case SECONDS:
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
int s = 60 * minutes;
|
int s = 60 * minutes;
|
||||||
int secondsLeft = seconds - s;
|
int secondsLeft = seconds - s;
|
||||||
|
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
@ -49,6 +50,7 @@ public class TimeUtil {
|
|||||||
case SECONDS:
|
case SECONDS:
|
||||||
return String.valueOf(secondsLeft);
|
return String.valueOf(secondsLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ public class TimeUtil {
|
|||||||
int hours = minutes / 60;
|
int hours = minutes / 60;
|
||||||
int inMins = 60 * hours;
|
int inMins = 60 * hours;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
return "0";
|
return "0";
|
||||||
@ -66,6 +69,7 @@ public class TimeUtil {
|
|||||||
case SECONDS:
|
case SECONDS:
|
||||||
return String.valueOf(secondsLeft);
|
return String.valueOf(secondsLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +88,14 @@ public class TimeUtil {
|
|||||||
case SECONDS:
|
case SECONDS:
|
||||||
return String.valueOf(secondsLeft);
|
return String.valueOf(secondsLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int hours = leftOver / 60;
|
int hours = leftOver / 60;
|
||||||
int hoursInMins = 60 * hours;
|
int hoursInMins = 60 * hours;
|
||||||
int minsLeft = leftOver - hoursInMins;
|
int minsLeft = leftOver - hoursInMins;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DAYS:
|
case DAYS:
|
||||||
return String.valueOf(days);
|
return String.valueOf(days);
|
||||||
@ -100,6 +106,7 @@ public class TimeUtil {
|
|||||||
case SECONDS:
|
case SECONDS:
|
||||||
return String.valueOf(secondsLeft);
|
return String.valueOf(secondsLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.valueOf(seconds);
|
return String.valueOf(seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,6 +120,7 @@ public class TimeUtil {
|
|||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
int s = 60 * minutes;
|
int s = 60 * minutes;
|
||||||
int secondsLeft = seconds - s;
|
int secondsLeft = seconds - s;
|
||||||
|
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
return minutes + "m " + secondsLeft + "s";
|
return minutes + "m " + secondsLeft + "s";
|
||||||
@ -120,18 +128,22 @@ public class TimeUtil {
|
|||||||
return minutes + "m";
|
return minutes + "m";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minutes < 1440) {
|
if (minutes < 1440) {
|
||||||
String time;
|
String time;
|
||||||
int hours = minutes / 60;
|
int hours = minutes / 60;
|
||||||
time = hours + "h";
|
time = hours + "h";
|
||||||
int inMins = 60 * hours;
|
int inMins = 60 * hours;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
|
|
||||||
if (leftOver >= 1) {
|
if (leftOver >= 1) {
|
||||||
time = time + " " + leftOver + "m";
|
time = time + " " + leftOver + "m";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
time = time + " " + secondsLeft + "s";
|
time = time + " " + secondsLeft + "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,20 +152,24 @@ public class TimeUtil {
|
|||||||
time = days + "d";
|
time = days + "d";
|
||||||
int inMins = 1440 * days;
|
int inMins = 1440 * days;
|
||||||
int leftOver = minutes - inMins;
|
int leftOver = minutes - inMins;
|
||||||
|
|
||||||
if (leftOver >= 1) {
|
if (leftOver >= 1) {
|
||||||
if (leftOver < 60) {
|
if (leftOver < 60) {
|
||||||
time = time + " " + leftOver + "m";
|
time = time + " " + leftOver + "m";
|
||||||
} else {
|
} else {
|
||||||
int hours = leftOver / 60;
|
int hours = leftOver / 60;
|
||||||
time = time + " " + hours + "h";
|
time = time + " " + hours + "h";
|
||||||
|
|
||||||
int hoursInMins = 60 * hours;
|
int hoursInMins = 60 * hours;
|
||||||
int minsLeft = leftOver - hoursInMins;
|
int minsLeft = leftOver - hoursInMins;
|
||||||
time = time + " " + minsLeft + "m";
|
time = time + " " + minsLeft + "m";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondsLeft > 0) {
|
if (secondsLeft > 0) {
|
||||||
time = time + " " + secondsLeft + "s";
|
time = time + " " + secondsLeft + "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user