This commit is contained in:
cyberpwn
2022-01-12 01:47:38 -05:00
parent 8c00499e76
commit 2dde426df6
463 changed files with 11845 additions and 10159 deletions

View File

@@ -25,14 +25,14 @@ import org.bukkit.entity.Player;
public class Chunks {
public static boolean isSafe(World w, int x, int z) {
return w.isChunkLoaded(x, z)
&& w.isChunkLoaded(x + 1, z)
&& w.isChunkLoaded(x, z + 1)
&& w.isChunkLoaded(x - 1, z)
&& w.isChunkLoaded(x, z - 1)
&& w.isChunkLoaded(x - 1, z - 1)
&& w.isChunkLoaded(x + 1, z + 1)
&& w.isChunkLoaded(x + 1, z - 1)
&& w.isChunkLoaded(x - 1, z + 1);
&& w.isChunkLoaded(x + 1, z)
&& w.isChunkLoaded(x, z + 1)
&& w.isChunkLoaded(x - 1, z)
&& w.isChunkLoaded(x, z - 1)
&& w.isChunkLoaded(x - 1, z - 1)
&& w.isChunkLoaded(x + 1, z + 1)
&& w.isChunkLoaded(x + 1, z - 1)
&& w.isChunkLoaded(x - 1, z + 1);
}
public static boolean isSafe(Location l) {
@@ -42,7 +42,7 @@ public class Chunks {
public static boolean hasPlayersNearby(Location at) {
try {
return !at.getWorld().getNearbyEntities(at, 32, 32, 32, (i) -> i instanceof Player).isEmpty();
} catch (Throwable ignored) {
} catch(Throwable ignored) {
return false;
}
}

View File

@@ -52,7 +52,8 @@ public interface ICommand {
/**
* Add a node to this command
*
* @param node the node
* @param node
* the node
*/
void addNode(String node);
@@ -60,8 +61,10 @@ public interface ICommand {
* Handle a command. If this is a subcommand, parameters after the subcommand
* will be adapted in args for you
*
* @param sender the volume sender (pre-tagged)
* @param args the arguments after this command node
* @param sender
* the volume sender (pre-tagged)
* @param args
* the arguments after this command node
* @return return true to mark it as handled
*/
boolean handle(VolmitSender sender, String[] args);

View File

@@ -75,13 +75,13 @@ public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
if(System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
final String defaultPackage = new String(
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong package names
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
if(Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
@@ -101,12 +101,14 @@ public class Metrics {
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
* @param plugin
* The plugin which stats should be submitted.
* @param pluginId
* The id of the plugin.
* It can be found at <a href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
if(plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
@@ -118,7 +120,7 @@ public class Metrics {
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
if(!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
@@ -133,15 +135,15 @@ public class Metrics {
// Inform the server owners about bStats
config.options().header(
"""
bStats collects some data for plugin authors like how many servers are using their plugins.
To honor their work, you should not disable it.
This has nearly no effect on the server performance!
Check out https://bStats.org/ to learn more :)"""
"""
bStats collects some data for plugin authors like how many servers are using their plugins.
To honor their work, you should not disable it.
This has nearly no effect on the server performance!
Check out https://bStats.org/ to learn more :)"""
).copyDefaults(true);
try {
config.save(configFile);
} catch (IOException e) {
} catch(IOException e) {
Iris.reportError(e);
}
}
@@ -153,21 +155,21 @@ public class Metrics {
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
if(enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
for(Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException e) {
} catch(NoSuchFieldException e) {
Iris.reportError(e);
}
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
if(!found) {
// We are the first!
startSubmitting();
}
@@ -177,18 +179,21 @@ public class Metrics {
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
* @param plugin
* Any plugin. It's just used to get a logger instance.
* @param data
* The data to send.
* @throws Exception
* If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
if(data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
if(Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
if(logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
@@ -207,19 +212,19 @@ public class Metrics {
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
try(DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
while((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
if(logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
@@ -227,16 +232,18 @@ public class Metrics {
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @param str
* The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
* @throws IOException
* If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
if(str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
try(GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
@@ -254,10 +261,11 @@ public class Metrics {
/**
* Adds a custom chart.
*
* @param chart The chart to add.
* @param chart
* The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
if(chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
@@ -271,7 +279,7 @@ public class Metrics {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
if(!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
@@ -301,10 +309,10 @@ public class Metrics {
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
for(CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
if(chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
@@ -327,9 +335,9 @@ public class Metrics {
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch(Exception e) {
Iris.reportError(e);
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
@@ -370,39 +378,39 @@ public class Metrics {
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
for(Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
for(RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
if(plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
if(plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
} catch(ClassNotFoundException e) {
Iris.reportError(e);
// minecraft version 1.14+
if (logFailedRequests) {
if(logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
} catch(NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
Iris.reportError(ignored);
}
}
} catch (NoSuchFieldException e) {
} catch(NoSuchFieldException e) {
Iris.reportError(e);
}
}
@@ -414,10 +422,10 @@ public class Metrics {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
} catch(Exception e) {
Iris.reportError(e);
// Something went wrong! :(
if (logFailedRequests) {
if(logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
@@ -435,10 +443,11 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param chartId
* The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
if(chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
@@ -449,14 +458,14 @@ public class Metrics {
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
if(data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
} catch(Throwable t) {
Iris.reportError(t);
if (logFailedRequests) {
if(logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
@@ -478,8 +487,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
@@ -490,7 +501,7 @@ public class Metrics {
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
if(value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
@@ -509,8 +520,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
@@ -522,19 +535,19 @@ public class Metrics {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
if(map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
for(Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
if(allSkipped) {
// Null = skip the chart
return null;
}
@@ -553,8 +566,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
@@ -566,24 +581,24 @@ public class Metrics {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
if(map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
for(Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
for(Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
if(!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
if(reallyAllSkipped) {
// Null = skip the chart
return null;
}
@@ -602,8 +617,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
@@ -614,7 +631,7 @@ public class Metrics {
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
if(value == 0) {
// Null = skip the chart
return null;
}
@@ -634,8 +651,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
@@ -647,19 +666,19 @@ public class Metrics {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
if(map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
for(Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
if(allSkipped) {
// Null = skip the chart
return null;
}
@@ -679,8 +698,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
@@ -692,11 +713,11 @@ public class Metrics {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
if(map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
for(Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
@@ -717,8 +738,10 @@ public class Metrics {
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
* @param chartId
* The id of the chart.
* @param callable
* The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
@@ -730,23 +753,23 @@ public class Metrics {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
if(map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
for(Map.Entry<String, int[]> entry : map.entrySet()) {
if(entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
for(int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
if(allSkipped) {
// Null = skip the chart
return null;
}

View File

@@ -69,14 +69,14 @@ public class MetricsLite {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
if(System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this
// little "trick" ... :D
final String defaultPackage = new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
final String defaultPackage = new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
final String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
// We want to make sure nobody just copy & pastes the example and use the wrong
// package names
if (MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) {
if(MetricsLite.class.getPackage().getName().equals(defaultPackage) || MetricsLite.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
@@ -93,13 +93,15 @@ public class MetricsLite {
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin. It can be found at
* <a href="https://bstats.org/what-is-my-plugin-id">What is my
* plugin id?</a>
* @param plugin
* The plugin which stats should be submitted.
* @param pluginId
* The id of the plugin. It can be found at
* <a href="https://bstats.org/what-is-my-plugin-id">What is my
* plugin id?</a>
*/
public MetricsLite(Plugin plugin, int pluginId) {
if (plugin == null) {
if(plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
@@ -111,7 +113,7 @@ public class MetricsLite {
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
if(!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
@@ -126,13 +128,13 @@ public class MetricsLite {
// Inform the server owners about bStats
config.options().header("""
bStats collects some data for plugin authors like how many servers are using their plugins.
To honor their work, you should not disable it.
This has nearly no effect on the server performance!
Check out https://bStats.org/ to learn more :)""").copyDefaults(true);
bStats collects some data for plugin authors like how many servers are using their plugins.
To honor their work, you should not disable it.
This has nearly no effect on the server performance!
Check out https://bStats.org/ to learn more :)""").copyDefaults(true);
try {
config.save(configFile);
} catch (IOException e) {
} catch(IOException e) {
Iris.reportError(e);
}
}
@@ -143,21 +145,21 @@ public class MetricsLite {
enabled = config.getBoolean("enabled", true);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
if(enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
for(Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException e) {
} catch(NoSuchFieldException e) {
Iris.reportError(e);
}
}
// Register our service
Bukkit.getServicesManager().register(MetricsLite.class, this, plugin, ServicePriority.Normal);
if (!found) {
if(!found) {
// We are the first!
startSubmitting();
}
@@ -167,18 +169,21 @@ public class MetricsLite {
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
* @param plugin
* Any plugin. It's just used to get a logger instance.
* @param data
* The data to send.
* @throws Exception
* If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
if(data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
if(Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
if(logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
@@ -197,19 +202,19 @@ public class MetricsLite {
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
try(DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
while((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
if(logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
@@ -217,16 +222,18 @@ public class MetricsLite {
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @param str
* The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
* @throws IOException
* If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
if(str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
try(GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
@@ -249,7 +256,7 @@ public class MetricsLite {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
if(!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
@@ -300,7 +307,7 @@ public class MetricsLite {
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size() : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
} catch(Exception e) {
Iris.reportError(e);
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
@@ -341,38 +348,38 @@ public class MetricsLite {
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
for(Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
for(RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
if(plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
if(plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
} catch(ClassNotFoundException e) {
Iris.reportError(e);
// minecraft version 1.14+
if (logFailedRequests) {
if(logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception ", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
} catch(NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
Iris.reportError(ignored);
}
}
} catch (NoSuchFieldException e) {
} catch(NoSuchFieldException e) {
Iris.reportError(e);
}
}
@@ -385,10 +392,10 @@ public class MetricsLite {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
} catch(Exception e) {
Iris.reportError(e);
// Something went wrong! :(
if (logFailedRequests) {
if(logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}

View File

@@ -45,8 +45,10 @@ public abstract class MortarCommand implements ICommand {
* Override this with a super constructor as most commands shouldn't change
* these parameters
*
* @param node the node (primary node) i.e. volume
* @param nodes the aliases. i.e. v, vol, bile
* @param node
* the node (primary node) i.e. volume
* @param nodes
* the aliases. i.e. v, vol, bile
*/
public MortarCommand(String node, String... nodes) {
category = "";
@@ -60,19 +62,19 @@ public abstract class MortarCommand implements ICommand {
@Override
public KList<String> handleTab(VolmitSender sender, String[] args) {
KList<String> v = new KList<>();
if (args.length == 0) {
for (MortarCommand i : getChildren()) {
if(args.length == 0) {
for(MortarCommand i : getChildren()) {
v.add(i.getNode());
}
}
addTabOptions(sender, args, v);
if (v.isEmpty()) {
if(v.isEmpty()) {
return null;
}
if (sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
if(sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 0.25f, 1.7f);
}
@@ -84,9 +86,9 @@ public abstract class MortarCommand implements ICommand {
public void printHelp(VolmitSender sender) {
boolean b = false;
for (MortarCommand i : getChildren()) {
for (String j : i.getRequiredPermissions()) {
if (!sender.hasPermission(j)) {
for(MortarCommand i : getChildren()) {
for(String j : i.getRequiredPermissions()) {
if(!sender.hasPermission(j)) {
}
}
@@ -95,11 +97,11 @@ public abstract class MortarCommand implements ICommand {
sender.sendMessage("" + C.GREEN + i.getNode() + " " + "<font:minecraft:uniform>" + (getArgsUsage().trim().isEmpty() ? "" : (C.WHITE + i.getArgsUsage())) + C.GRAY + " - " + i.getDescription());
}
if (!b) {
if(!b) {
sender.sendMessage("There are either no sub-commands or you do not have permission to use them.");
}
if (sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
if(sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
sender.playSound(Sound.ITEM_BOOK_PAGE_TURN, 0.28f, 1.4f);
sender.playSound(Sound.ITEM_AXE_STRIP, 0.35f, 1.7f);
}
@@ -116,7 +118,7 @@ public abstract class MortarCommand implements ICommand {
}
protected void requiresPermission(MortarPermission node) {
if (node == null) {
if(node == null) {
return;
}
@@ -124,7 +126,7 @@ public abstract class MortarCommand implements ICommand {
}
protected void requiresPermission(String node) {
if (node == null) {
if(node == null) {
return;
}
@@ -132,19 +134,19 @@ public abstract class MortarCommand implements ICommand {
}
public void rejectAny(int past, VolmitSender sender, String[] a) {
if (a.length > past) {
if(a.length > past) {
int p = past;
StringBuilder m = new StringBuilder();
for (String i : a) {
for(String i : a) {
p--;
if (p < 0) {
if(p < 0) {
m.append(i).append(", ");
}
}
if (!m.toString().trim().isEmpty()) {
if(!m.toString().trim().isEmpty()) {
sender.sendMessage("Parameters Ignored: " + m);
}
}
@@ -177,21 +179,21 @@ public abstract class MortarCommand implements ICommand {
private KList<MortarCommand> buildChildren() {
KList<MortarCommand> p = new KList<>();
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Command.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Command.class)) {
try {
i.setAccessible(true);
MortarCommand pc = (MortarCommand) i.getType().getConstructor().newInstance();
Command c = i.getAnnotation(Command.class);
if (!c.value().trim().isEmpty()) {
if(!c.value().trim().isEmpty()) {
pc.setCategory(c.value().trim());
} else {
pc.setCategory(getCategory());
}
p.add(pc);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
Iris.reportError(e);
e.printStackTrace();
}

View File

@@ -30,13 +30,13 @@ public abstract class MortarPermission {
private MortarPermission parent;
public MortarPermission() {
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Permission.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Permission.class)) {
try {
MortarPermission px = (MortarPermission) i.getType().getConstructor().newInstance();
px.setParent(this);
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, px);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
Iris.reportError(e);
}
@@ -47,11 +47,11 @@ public abstract class MortarPermission {
public KList<MortarPermission> getChildren() {
KList<MortarPermission> p = new KList<>();
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Permission.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Permission.class)) {
try {
p.add((MortarPermission) i.get(Modifier.isStatic(i.getModifiers()) ? null : this));
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | SecurityException e) {
e.printStackTrace();
Iris.reportError(e);
}
@@ -62,7 +62,7 @@ public abstract class MortarPermission {
}
public String getFullNode() {
if (hasParent()) {
if(hasParent()) {
return getParent().getFullNode() + "." + getNode();
}

View File

@@ -38,7 +38,7 @@ public class PluginRegistry<T> {
}
public T get(String s) {
if (!registry.containsKey(s)) {
if(!registry.containsKey(s)) {
return null;
}
@@ -54,7 +54,7 @@ public class PluginRegistry<T> {
}
public T resolve(String id) {
if (registry.isEmpty()) {
if(registry.isEmpty()) {
return null;
}

View File

@@ -25,12 +25,12 @@ public class PluginRegistryGroup<T> {
private final KMap<String, PluginRegistry<T>> registries = new KMap<>();
public T resolve(String namespace, String id) {
if (registries.isEmpty()) {
if(registries.isEmpty()) {
return null;
}
PluginRegistry<T> r = registries.get(namespace);
if (r == null) {
if(r == null) {
return null;
}
@@ -52,8 +52,8 @@ public class PluginRegistryGroup<T> {
public KList<String> compile() {
KList<String> l = new KList<>();
registries.values().forEach((i)
-> i.getRegistries().forEach((j)
-> l.add(i.getNamespace() + ":" + j)));
-> i.getRegistries().forEach((j)
-> l.add(i.getNamespace() + ":" + j)));
return l;
}
}

View File

@@ -34,8 +34,10 @@ public class RouterCommand extends org.bukkit.command.Command {
/**
* The router command routes commands to bukkit executors
*
* @param realCommand the real command
* @param ex the executor
* @param realCommand
* the real command
* @param ex
* the executor
*/
public RouterCommand(ICommand realCommand, CommandExecutor ex) {
super(realCommand.getNode().toLowerCase());

View File

@@ -51,14 +51,14 @@ public class VirtualCommand {
children = new KMap<>();
this.tag = tag;
for (Field i : command.getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Command.class)) {
for(Field i : command.getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Command.class)) {
try {
Command cc = i.getAnnotation(Command.class);
ICommand cmd = (ICommand) i.getType().getConstructor().newInstance();
new V(command, true, true).set(i.getName(), cmd);
children.put(cmd.getAllNodes(), new VirtualCommand(cmd, cc.value().trim().isEmpty() ? tag : cc.value().trim()));
} catch (Exception e) {
} catch(Exception e) {
Iris.reportError(e);
e.printStackTrace();
}
@@ -86,12 +86,12 @@ public class VirtualCommand {
VolmitSender vs = new VolmitSender(sender);
vs.setTag(tag);
if (label != null) {
if(label != null) {
vs.setCommand(label);
}
if (chain.isEmpty()) {
if (!checkPermissions(sender, command)) {
if(chain.isEmpty()) {
if(!checkPermissions(sender, command)) {
return true;
}
@@ -100,15 +100,15 @@ public class VirtualCommand {
String nl = chain.get(0);
for (KList<String> i : children.k()) {
for (String j : i) {
if (j.equalsIgnoreCase(nl)) {
for(KList<String> i : children.k()) {
for(String j : i) {
if(j.equalsIgnoreCase(nl)) {
vs.setCommand(chain.get(0));
VirtualCommand cmd = children.get(i);
KList<String> c = chain.copy();
c.remove(0);
if (cmd.hit(sender, c, vs.getCommand())) {
if (vs.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
if(cmd.hit(sender, c, vs.getCommand())) {
if(vs.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) {
vs.player().getWorld().playSound(vs.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.8f);
}
@@ -118,7 +118,7 @@ public class VirtualCommand {
}
}
if (!checkPermissions(sender, command)) {
if(!checkPermissions(sender, command)) {
return true;
}
@@ -129,11 +129,11 @@ public class VirtualCommand {
VolmitSender vs = new VolmitSender(sender);
vs.setTag(tag);
if (label != null)
if(label != null)
vs.setCommand(label);
if (chain.isEmpty()) {
if (!checkPermissions(sender, command)) {
if(chain.isEmpty()) {
if(!checkPermissions(sender, command)) {
return null;
}
@@ -142,22 +142,22 @@ public class VirtualCommand {
String nl = chain.get(0);
for (KList<String> i : children.k()) {
for (String j : i) {
if (j.equalsIgnoreCase(nl)) {
for(KList<String> i : children.k()) {
for(String j : i) {
if(j.equalsIgnoreCase(nl)) {
vs.setCommand(chain.get(0));
VirtualCommand cmd = children.get(i);
KList<String> c = chain.copy();
c.remove(0);
KList<String> v = cmd.hitTab(sender, c, vs.getCommand());
if (v != null) {
if(v != null) {
return v;
}
}
}
}
if (!checkPermissions(sender, command)) {
if(!checkPermissions(sender, command)) {
return null;
}
@@ -168,14 +168,14 @@ public class VirtualCommand {
private boolean checkPermissions(CommandSender sender, ICommand command2) {
boolean failed = false;
for (String i : command.getRequiredPermissions()) {
if (!sender.hasPermission(i)) {
for(String i : command.getRequiredPermissions()) {
if(!sender.hasPermission(i)) {
failed = true;
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> sender.sendMessage("- " + C.WHITE + i), 0);
}
}
if (failed) {
if(failed) {
sender.sendMessage("Insufficient Permissions");
return false;
}

View File

@@ -97,7 +97,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
outputPluginInfo();
outputCommandInfo();
outputPermissionInfo();
} catch (Throwable e) {
} catch(Throwable e) {
Iris.reportError(e);
}
@@ -106,7 +106,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private void outputPermissionInfo() throws IOException {
FileConfiguration fc = new YamlConfiguration();
for (MortarPermission i : permissionCache) {
for(MortarPermission i : permissionCache) {
chain(i, fc);
}
@@ -116,7 +116,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private void chain(MortarPermission i, FileConfiguration fc) {
KList<String> ff = new KList<>();
for (MortarPermission j : i.getChildren()) {
for(MortarPermission j : i.getChildren()) {
ff.add(j.getFullNode());
}
@@ -124,7 +124,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
fc.set(i.getFullNode().replaceAll("\\Q.\\E", ",") + "." + "default", i.isDefault());
fc.set(i.getFullNode().replaceAll("\\Q.\\E", ",") + "." + "children", ff);
for (MortarPermission j : i.getChildren()) {
for(MortarPermission j : i.getChildren()) {
chain(j, fc);
}
}
@@ -132,7 +132,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private void outputCommandInfo() throws IOException {
FileConfiguration fc = new YamlConfiguration();
for (MortarCommand i : commandCache) {
for(MortarCommand i : commandCache) {
chain(i, "/", fc);
}
@@ -145,7 +145,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
fc.set(n + "." + "required-permissions", i.getRequiredPermissions());
fc.set(n + "." + "aliases", i.getAllNodes());
for (MortarCommand j : i.getChildren()) {
for(MortarCommand j : i.getChildren()) {
chain(j, n, fc);
}
}
@@ -160,8 +160,8 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private void registerPermissions() {
permissionCache = new KList<>();
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Permission.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Permission.class)) {
try {
i.setAccessible(true);
MortarPermission pc = (MortarPermission) i.getType().getConstructor().newInstance();
@@ -169,7 +169,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
registerPermission(pc);
permissionCache.add(pc);
v("Registered Permissions " + pc.getFullNode() + " (" + i.getName() + ")");
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
Iris.reportError(e);
w("Failed to register permission (field " + i.getName() + ")");
e.printStackTrace();
@@ -177,10 +177,10 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
}
for (org.bukkit.permissions.Permission i : computePermissions()) {
for(org.bukkit.permissions.Permission i : computePermissions()) {
try {
Bukkit.getPluginManager().addPermission(i);
} catch (Throwable e) {
} catch(Throwable e) {
Iris.reportError(e);
}
@@ -189,13 +189,13 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private KList<org.bukkit.permissions.Permission> computePermissions() {
KList<org.bukkit.permissions.Permission> g = new KList<>();
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Permission.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Permission.class)) {
try {
MortarPermission x = (MortarPermission) i.get(Modifier.isStatic(i.getModifiers()) ? null : this);
g.add(toPermission(x));
g.addAll(computePermissions(x));
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | SecurityException e) {
Iris.reportError(e);
e.printStackTrace();
}
@@ -208,12 +208,12 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
private KList<org.bukkit.permissions.Permission> computePermissions(MortarPermission p) {
KList<org.bukkit.permissions.Permission> g = new KList<>();
if (p == null) {
if(p == null) {
return g;
}
for (MortarPermission i : p.getChildren()) {
if (i == null) {
for(MortarPermission i : p.getChildren()) {
if(i == null) {
continue;
}
@@ -225,7 +225,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private org.bukkit.permissions.Permission toPermission(MortarPermission p) {
if (p == null) {
if(p == null) {
return null;
}
@@ -233,7 +233,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
perm.setDescription(p.getDescription() == null ? "" : p.getDescription());
perm.setDefault(p.isDefault() ? PermissionDefault.TRUE : PermissionDefault.OP);
for (MortarPermission i : p.getChildren()) {
for(MortarPermission i : p.getChildren()) {
perm.getChildren().put(i.getFullNode(), true);
}
@@ -253,19 +253,19 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private void tickController(IController i) {
if (bad) {
if(bad) {
return;
}
if (i.getTickInterval() < 0) {
if(i.getTickInterval() < 0) {
return;
}
M.tick++;
if (M.interval(i.getTickInterval())) {
if(M.interval(i.getTickInterval())) {
try {
i.tick();
} catch (Throwable e) {
} catch(Throwable e) {
w("Failed to tick controller " + i.getName());
e.printStackTrace();
Iris.reportError(e);
@@ -274,16 +274,16 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private void registerInstance() {
if (bad) {
if(bad) {
return;
}
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Instance.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Instance.class)) {
try {
i.setAccessible(true);
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, this);
v("Registered Instance " + i.getName());
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | SecurityException e) {
w("Failed to register instance (field " + i.getName() + ")");
e.printStackTrace();
Iris.reportError(e);
@@ -293,16 +293,16 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private void unregisterInstance() {
if (bad) {
if(bad) {
return;
}
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(Instance.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(Instance.class)) {
try {
i.setAccessible(true);
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, null);
v("Unregistered Instance " + i.getName());
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | SecurityException e) {
w("Failed to unregister instance (field " + i.getName() + ")");
e.printStackTrace();
Iris.reportError(e);
@@ -312,14 +312,14 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private void registerCommands() {
if (bad) {
if(bad) {
return;
}
commands = new KMap<>();
commandCache = new KList<>();
for (Field i : getClass().getDeclaredFields()) {
if (i.isAnnotationPresent(com.volmit.iris.util.plugin.Command.class)) {
for(Field i : getClass().getDeclaredFields()) {
if(i.isAnnotationPresent(com.volmit.iris.util.plugin.Command.class)) {
try {
i.setAccessible(true);
MortarCommand pc = (MortarCommand) i.getType().getConstructor().newInstance();
@@ -327,7 +327,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
registerCommand(pc, c.value());
commandCache.add(pc);
v("Registered Commands /" + pc.getNode() + " (" + i.getName() + ")");
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
w("Failed to register command (field " + i.getName() + ")");
e.printStackTrace();
Iris.reportError(e);
@@ -342,21 +342,21 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
String alias, String[] args) {
KList<String> chain = new KList<>();
for (String i : args) {
if (i.trim().isEmpty()) {
for(String i : args) {
if(i.trim().isEmpty()) {
continue;
}
chain.add(i.trim());
}
for (KList<String> i : commands.k()) {
for (String j : i) {
if (j.equalsIgnoreCase(alias)) {
for(KList<String> i : commands.k()) {
for(String j : i) {
if(j.equalsIgnoreCase(alias)) {
VirtualCommand cmd = commands.get(i);
List<String> v = cmd.hitTab(sender, chain.copy(), alias);
if (v != null) {
if(v != null) {
return v;
}
}
@@ -368,19 +368,19 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
if (bad) {
if(bad) {
return false;
}
KList<String> chain = new KList<>();
chain.add(args);
for (KList<String> i : commands.k()) {
for (String j : i) {
if (j.equalsIgnoreCase(label)) {
for(KList<String> i : commands.k()) {
for(String j : i) {
if(j.equalsIgnoreCase(label)) {
VirtualCommand cmd = commands.get(i);
if (cmd.hit(sender, chain.copy(), label)) {
if(cmd.hit(sender, chain.copy(), label)) {
return true;
}
}
@@ -395,14 +395,14 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
public void registerCommand(ICommand cmd, String subTag) {
if (bad) {
if(bad) {
return;
}
commands.put(cmd.getAllNodes(), new VirtualCommand(cmd, subTag.trim().isEmpty() ? getTag() : getTag(subTag.trim())));
PluginCommand cc = getCommand(cmd.getNode().toLowerCase());
if (cc != null) {
if(cc != null) {
cc.setExecutor(this);
cc.setUsage(getName() + ":" + getClass().toString() + ":" + cmd.getNode());
} else {
@@ -413,7 +413,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
public void unregisterCommand(ICommand cmd) {
if (bad) {
if(bad) {
return;
}
try {
@@ -421,14 +421,14 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
Map<String, Command> k = new V(m).get("knownCommands");
for (Iterator<Map.Entry<String, Command>> it = k.entrySet().iterator(); it.hasNext(); ) {
for(Iterator<Map.Entry<String, Command>> it = k.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Command> entry = it.next();
if (entry.getValue() instanceof Command) {
if(entry.getValue() instanceof Command) {
org.bukkit.command.Command c = entry.getValue();
String u = c.getUsage();
if (u != null && u.equals(getName() + ":" + getClass().toString() + ":" + cmd.getNode())) {
if (c.unregister(m)) {
if(u != null && u.equals(getName() + ":" + getClass().toString() + ":" + cmd.getNode())) {
if(c.unregister(m)) {
it.remove();
v("Unregistered Command /" + cmd.getNode());
} else {
@@ -437,14 +437,14 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
}
}
} catch (Throwable e) {
} catch(Throwable e) {
e.printStackTrace();
Iris.reportError(e);
}
}
public String getTag() {
if (bad) {
if(bad) {
return "";
}
return getTag("");
@@ -461,20 +461,20 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
public void unregisterListeners() {
if (bad) {
if(bad) {
return;
}
HandlerList.unregisterAll((Listener) this);
}
public void unregisterCommands() {
if (bad) {
if(bad) {
return;
}
for (VirtualCommand i : commands.v()) {
for(VirtualCommand i : commands.v()) {
try {
unregisterCommand(i.getCommand());
} catch (Throwable e) {
} catch(Throwable e) {
Iris.reportError(e);
}
@@ -482,10 +482,10 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
private void unregisterPermissions() {
if (bad) {
if(bad) {
return;
}
for (org.bukkit.permissions.Permission i : computePermissions()) {
for(org.bukkit.permissions.Permission i : computePermissions()) {
Bukkit.getPluginManager().removePermission(i);
v("Unregistered Permission " + i.getName());
}
@@ -506,7 +506,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
public File getDataFolder(String... strings) {
if (strings.length == 0) {
if(strings.length == 0) {
return super.getDataFolder();
}
@@ -517,7 +517,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
}
public File getDataFolderNoCreate(String... strings) {
if (strings.length == 0) {
if(strings.length == 0) {
return super.getDataFolder();
}
@@ -529,7 +529,7 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
public File getDataFolderList(String pre, String[] strings) {
KList<String> v = new KList<>(strings);
v.add(0, pre);
if (v.size() == 0) {
if(v.size() == 0) {
return super.getDataFolder();
}
File f = new File(getDataFolder(), v.toString(File.separator));

View File

@@ -69,7 +69,8 @@ public class VolmitSender implements CommandSender {
/**
* Wrap a command sender
*
* @param s the command sender
* @param s
* the command sender
*/
public VolmitSender(CommandSender s) {
tag = "";
@@ -103,7 +104,7 @@ public class VolmitSender implements CommandSender {
hasNext.set(page < totalPages - 1);
KList<T> d = new KList<>();
for (int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) {
for(int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) {
d.add(all.get(i));
}
@@ -122,7 +123,8 @@ public class VolmitSender implements CommandSender {
/**
* Set a command tag (prefix for sendMessage)
*
* @param tag the tag
* @param tag
* the tag
*/
public void setTag(String tag) {
this.tag = tag;
@@ -226,13 +228,13 @@ public class VolmitSender implements CommandSender {
public void sendTitle(String title, String subtitle, int i, int s, int o) {
Iris.audiences.player(player()).showTitle(Title.title(
createComponent(title),
createComponent(subtitle),
Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o))));
createComponent(title),
createComponent(subtitle),
Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o))));
}
public void sendProgress(double percent, String thing) {
if (percent < 0) {
if(percent < 0) {
int l = 44;
int g = (int) (1D * l);
sendTitle(C.IRIS + thing + " ", 0, 500, 250);
@@ -255,13 +257,13 @@ public class VolmitSender implements CommandSender {
public void sendTitle(String subtitle, int i, int s, int o) {
Iris.audiences.player(player()).showTitle(Title.title(
createNoPrefixComponent(" "),
createNoPrefixComponent(subtitle),
Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o))));
createNoPrefixComponent(" "),
createNoPrefixComponent(subtitle),
Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o))));
}
private Component createNoPrefixComponent(String message) {
if (!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
if(!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
String t = C.translateAlternateColorCodes('&', MiniMessage.get().stripTokens(message));
return MiniMessage.get().parse(t);
}
@@ -276,7 +278,7 @@ public class VolmitSender implements CommandSender {
}
private Component createComponent(String message) {
if (!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
if(!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
String t = C.translateAlternateColorCodes('&', MiniMessage.get().stripTokens(getTag() + message));
return MiniMessage.get().parse(t);
}
@@ -287,7 +289,7 @@ public class VolmitSender implements CommandSender {
}
private Component createComponentRaw(String message) {
if (!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
if(!IrisSettings.get().getGeneral().canUseCustomColors(this)) {
String t = C.translateAlternateColorCodes('&', MiniMessage.get().stripTokens(getTag() + message));
return MiniMessage.get().parse(t);
}
@@ -300,7 +302,7 @@ public class VolmitSender implements CommandSender {
AtomicInteger v = new AtomicInteger();
AtomicReference<T> g = new AtomicReference<>();
v.set(J.ar(() -> {
if (f.isDone() && g.get() != null) {
if(f.isDone() && g.get() != null) {
J.car(v.get());
sendAction(" ");
return;
@@ -311,9 +313,9 @@ public class VolmitSender implements CommandSender {
J.a(() -> {
try {
g.set(f.get());
} catch (InterruptedException e) {
} catch(InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
} catch(ExecutionException e) {
e.printStackTrace();
}
});
@@ -322,23 +324,23 @@ public class VolmitSender implements CommandSender {
@Override
public void sendMessage(String message) {
if (s instanceof CommandDummy) {
if(s instanceof CommandDummy) {
return;
}
if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message));
return;
}
if (message.contains("<NOMINI>")) {
if(message.contains("<NOMINI>")) {
s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message.replaceAll("\\Q<NOMINI>\\E", "")));
return;
}
try {
Iris.audiences.sender(s).sendMessage(createComponent(message));
} catch (Throwable e) {
} catch(Throwable e) {
String t = C.translateAlternateColorCodes('&', getTag() + message);
String a = C.aura(t, IrisSettings.get().getGeneral().getSpinh(), IrisSettings.get().getGeneral().getSpins(), IrisSettings.get().getGeneral().getSpinb());
@@ -352,23 +354,23 @@ public class VolmitSender implements CommandSender {
}
public void sendMessageRaw(String message) {
if (s instanceof CommandDummy) {
if(s instanceof CommandDummy) {
return;
}
if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
s.sendMessage(C.translateAlternateColorCodes('&', message));
return;
}
if (message.contains("<NOMINI>")) {
if(message.contains("<NOMINI>")) {
s.sendMessage(message.replaceAll("\\Q<NOMINI>\\E", ""));
return;
}
try {
Iris.audiences.sender(s).sendMessage(createComponentRaw(message));
} catch (Throwable e) {
} catch(Throwable e) {
String t = C.translateAlternateColorCodes('&', getTag() + message);
String a = C.aura(t, IrisSettings.get().getGeneral().getSpinh(), IrisSettings.get().getGeneral().getSpins(), IrisSettings.get().getGeneral().getSpinb());
@@ -379,7 +381,7 @@ public class VolmitSender implements CommandSender {
@Override
public void sendMessage(String[] messages) {
for (String str : messages)
for(String str : messages)
sendMessage(str);
}
@@ -410,21 +412,21 @@ public class VolmitSender implements CommandSender {
private String pickRandoms(int max, VirtualDecreeCommand i) {
KList<String> m = new KList<>();
for (int ix = 0; ix < max; ix++) {
for(int ix = 0; ix < max; ix++) {
m.add((i.isNode()
? (i.getNode().getParameters().isNotEmpty())
? "<#aebef2>✦ <#5ef288>"
+ i.getParentPath()
+ " <#42ecf5>"
+ i.getName() + " "
+ i.getNode().getParameters().shuffleCopy(RNG.r).convert((f)
-> (f.isRequired() || RNG.r.b(0.5)
? "<#f2e15e>" + f.getNames().getRandom() + "="
+ "<#d665f0>" + f.example()
: ""))
.toString(" ")
: ""
: ""));
? (i.getNode().getParameters().isNotEmpty())
? "<#aebef2>✦ <#5ef288>"
+ i.getParentPath()
+ " <#42ecf5>"
+ i.getName() + " "
+ i.getNode().getParameters().shuffleCopy(RNG.r).convert((f)
-> (f.isRequired() || RNG.r.b(0.5)
? "<#f2e15e>" + f.getNames().getRandom() + "="
+ "<#d665f0>" + f.example()
: ""))
.toString(" ")
: ""
: ""));
}
return m.removeDuplicates().convert((iff) -> iff.replaceAll("\\Q \\E", " ")).toString("\n");
@@ -439,7 +441,7 @@ public class VolmitSender implements CommandSender {
String sf = "[";
String se = "]";
if (name.trim().isEmpty()) {
if(name.trim().isEmpty()) {
sendMessageRaw("<font:minecraft:uniform><strikethrough><gradient:#34eb6b:#32bfad>" + sf + s + "<reset><font:minecraft:uniform><strikethrough><gradient:#32bfad:#34eb6b>" + s + se);
} else {
sendMessageRaw("<font:minecraft:uniform><strikethrough><gradient:#34eb6b:#32bfad>" + sf + s + si + "<reset> <gradient:#3299bf:#323bbf>" + name + "<reset> <font:minecraft:uniform><strikethrough><gradient:#32bfad:#34eb6b>" + so + s + se);
@@ -455,8 +457,8 @@ public class VolmitSender implements CommandSender {
}
public void sendDecreeHelp(VirtualDecreeCommand v, int page) {
if (!isPlayer()) {
for (VirtualDecreeCommand i : v.getNodes()) {
if(!isPlayer()) {
for(VirtualDecreeCommand i : v.getNodes()) {
sendDecreeHelpNode(i);
}
@@ -467,27 +469,27 @@ public class VolmitSender implements CommandSender {
sendMessageRaw("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
if (v.getNodes().isNotEmpty()) {
if(v.getNodes().isNotEmpty()) {
sendHeader(v.getPath() + (page > 0 ? (" {" + (page + 1) + "}") : ""));
if (isPlayer() && v.getParent() != null) {
if(isPlayer() && v.getParent() != null) {
sendMessageRaw("<hover:show_text:'" + "<#b54b38>Click to go back to <#3299bf>" + Form.capitalize(v.getParent().getName()) + " Help" + "'><click:run_command:" + v.getParent().getPath() + "><font:minecraft:uniform><#f58571>〈 Back</click></hover>");
}
AtomicBoolean next = new AtomicBoolean(false);
for (VirtualDecreeCommand i : paginate(v.getNodes(), 17, page, next)) {
for(VirtualDecreeCommand i : paginate(v.getNodes(), 17, page, next)) {
sendDecreeHelpNode(i);
}
String s = "";
int l = 75 - (page > 0 ? 10 : 0) - (next.get() ? 10 : 0);
if (page > 0) {
if(page > 0) {
s += "<hover:show_text:'<green>Click to go back to page " + page + "'><click:run_command:" + v.getPath() + " help=" + page + "><gradient:#27b84d:#2770b8>〈 Page " + page + "</click></hover><reset> ";
}
s += "<reset><font:minecraft:uniform><strikethrough><gradient:#32bfad:#34eb6b>" + Form.repeat(" ", l) + "<reset>";
if (next.get()) {
if(next.get()) {
s += " <hover:show_text:'<green>Click to go to back to page " + (page + 2) + "'><click:run_command:" + v.getPath() + " help=" + (page + 2) + "><gradient:#2770b8:#27b84d>Page " + (page + 2) + " ❭</click></hover>";
}
@@ -498,7 +500,7 @@ public class VolmitSender implements CommandSender {
}
public void sendDecreeHelpNode(VirtualDecreeCommand i) {
if (isPlayer() || s instanceof CommandDummy) {
if(isPlayer() || s instanceof CommandDummy) {
sendMessageRaw(helpCache.computeIfAbsent(i.getPath(), (k) -> {
String newline = "<reset>\n";
@@ -509,8 +511,8 @@ public class VolmitSender implements CommandSender {
String description = "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription();
String usage = "<#bbe03f>✒ <#a8e0a2><font:minecraft:uniform>";
String onClick;
if (i.isNode()) {
if (i.getNode().getParameters().isEmpty()) {
if(i.isNode()) {
if(i.getNode().getParameters().isEmpty()) {
usage += "There are no parameters. Click to type command.";
onClick = "suggest_command";
} else {
@@ -524,16 +526,16 @@ public class VolmitSender implements CommandSender {
String suggestion = "";
String suggestions = "";
if (i.isNode() && i.getNode().getParameters().isNotEmpty()) {
if(i.isNode() && i.getNode().getParameters().isNotEmpty()) {
suggestion += newline + "<#aebef2>✦ <#5ef288><font:minecraft:uniform>" + i.getParentPath() + " <#42ecf5>" + i.getName() + " "
+ i.getNode().getParameters().convert((f) -> "<#d665f0>" + f.example()).toString(" ");
+ i.getNode().getParameters().convert((f) -> "<#d665f0>" + f.example()).toString(" ");
suggestions += newline + "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i);
}
/// Params
StringBuilder nodes = new StringBuilder();
if (i.isNode()) {
for (DecreeParameter p : i.getNode().getParameters()) {
if(i.isNode()) {
for(DecreeParameter p : i.getNode().getParameters()) {
String nTitle = "<gradient:#d665f0:#a37feb>" + p.getName();
String nHoverTitle = p.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ");
@@ -541,13 +543,13 @@ public class VolmitSender implements CommandSender {
String nUsage;
String fullTitle;
Iris.debug("Contextual: " + p.isContextual() + " / player: " + isPlayer());
if (p.isContextual() && (isPlayer() || s instanceof CommandDummy)) {
if(p.isContextual() && (isPlayer() || s instanceof CommandDummy)) {
fullTitle = "<#ffcc00>[" + nTitle + "<#ffcc00>] ";
nUsage = "<#ff9900>➱ <#ffcc00><font:minecraft:uniform>The value may be derived from environment context.";
} else if (p.isRequired()) {
} else if(p.isRequired()) {
fullTitle = "<red>[" + nTitle + "<red>] ";
nUsage = "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required.";
} else if (p.hasDefault()) {
} else if(p.hasDefault()) {
fullTitle = "<#4f4f4f>⊰" + nTitle + "<#4f4f4f>⊱";
nUsage = "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \"" + p.getParam().defaultValue() + "\" if undefined.";
} else {
@@ -557,14 +559,14 @@ public class VolmitSender implements CommandSender {
String type = "<#cc00ff>✢ <#ff33cc><font:minecraft:uniform>This parameter is of type " + p.getType().getSimpleName() + ".";
nodes
.append("<hover:show_text:'")
.append(nHoverTitle).append(newline)
.append(nDescription).append(newline)
.append(nUsage).append(newline)
.append(type)
.append("'>")
.append(fullTitle)
.append("</hover>");
.append("<hover:show_text:'")
.append(nHoverTitle).append(newline)
.append(nDescription).append(newline)
.append(nUsage).append(newline)
.append(type)
.append("'>")
.append(fullTitle)
.append("</hover>");
}
} else {
nodes = new StringBuilder("<gradient:#afe3d3:#a2dae0> - Category of Commands");
@@ -572,21 +574,21 @@ public class VolmitSender implements CommandSender {
/// Wrapper
String wrapper =
"<hover:show_text:'" +
hoverTitle + newline +
description + newline +
usage +
suggestion + //Newlines for suggestions are added when they're built, to prevent blanklines.
suggestions + // ^
"'>" +
"<click:" +
onClick +
":" +
realText +
"</click>" +
"</hover>" +
" " +
nodes;
"<hover:show_text:'" +
hoverTitle + newline +
description + newline +
usage +
suggestion + //Newlines for suggestions are added when they're built, to prevent blanklines.
suggestions + // ^
"'>" +
"<click:" +
onClick +
":" +
realText +
"</click>" +
"</hover>" +
" " +
nodes;
return wrapper;
}));
@@ -596,7 +598,7 @@ public class VolmitSender implements CommandSender {
}
public void playSound(Sound sound, float volume, float pitch) {
if (isPlayer()) {
if(isPlayer()) {
player().playSound(player().getLocation(), sound, volume, pitch);
}
}