From 4b997d42dfb8c4b40935296d47f7d2beb92e28fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 26 Jun 2020 11:03:42 +0200 Subject: [PATCH 01/35] Some slf4j progress --- Bukkit/build.gradle | 2 + Core/build.gradle | 1 + .../com/plotsquared/core/PlotSquared.java | 8 +- .../core/configuration/Config.java | 22 +++--- .../core/listener/ProcessedWEExtent.java | 13 ++-- .../plotsquared/core/player/PlotPlayer.java | 9 ++- .../java/com/plotsquared/core/plot/Plot.java | 35 +++++---- .../com/plotsquared/core/plot/PlotArea.java | 16 ++-- .../core/plot/expiration/PlotAnalysis.java | 78 +++++++++---------- .../core/plot/flag/FlagContainer.java | 13 ++-- .../plot/flag/types/BlockTypeWrapper.java | 7 +- .../core/plot/message/PlotMessage.java | 8 +- ...LocationOffsetDelegateLocalBlockQueue.java | 12 +-- .../com/plotsquared/core/util/Expression.java | 7 +- .../plotsquared/core/util/logger/ILogger.java | 4 +- 15 files changed, 129 insertions(+), 106 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 6995d9034..d28377f6a 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -37,6 +37,7 @@ dependencies { implementation("net.alpenblock:BungeePerms:4.0-dev-106") compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } + compile("org.slf4j:slf4j-jdk14:2.0.0-alpha1") } sourceCompatibility = 1.8 @@ -95,6 +96,7 @@ shadowJar { include(dependency("org.bstats:bstats-bukkit:1.7")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) + include(dependency("org.slf4j:slf4j-jdk14:2.0.0-alpha1")) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") diff --git a/Core/build.gradle b/Core/build.gradle index 51f56e187..206568547 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -18,6 +18,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains:annotations:19.0.0") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") + implementation("org.slf4j:slf4j-api:2.0.0-alpha1") } sourceCompatibility = 1.8 diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 3f7f35229..0487c59da 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -165,7 +165,7 @@ public class PlotSquared { public HashMap> plots_tmp; private YamlConfiguration config; // Implementation logger - @Setter @Getter private ILogger logger; + @Deprecated @Setter @Getter private ILogger logger; // Platform / Version / Update URL private PlotVersion version; // Files and configuration @@ -398,8 +398,9 @@ public class PlotSquared { * * @param message Message to log * @see IPlotMain#log(String) + * @deprecated Use slf4j */ - public static void log(Object message) { + @Deprecated public static void log(Object message) { if (message == null || (message instanceof Caption ? ((Caption) message).getTranslated().isEmpty() : message.toString().isEmpty())) { @@ -417,8 +418,9 @@ public class PlotSquared { * * @param message Message to log * @see IPlotMain#log(String) + * @deprecated Use sl4j */ - public static void debug(@Nullable Object message) { + @Deprecated public static void debug(@Nullable Object message) { if (Settings.DEBUG) { if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { System.out.printf("[P2][Debug] %s\n", StringMan.getString(message)); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Config.java b/Core/src/main/java/com/plotsquared/core/configuration/Config.java index 701cca773..402ee7cd9 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Config.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Config.java @@ -25,10 +25,11 @@ */ package com.plotsquared.core.configuration; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings.Enabled_Components; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.util.StringMan; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.PrintWriter; @@ -46,6 +47,8 @@ import java.util.Map; public class Config { + private static final Logger logger = LoggerFactory.getLogger(Config.class); + /** * Get the value for a node
* Probably throws some error if you try to get a non existent key @@ -68,7 +71,7 @@ public class Config { } } } - PlotSquared.debug("Failed to get config option: " + key); + logger.debug("Failed to get config option: {}", key); return null; } @@ -95,15 +98,13 @@ public class Config { } field.set(instance, value); return; - } catch (Throwable e) { - PlotSquared.debug( - "Invalid configuration value: " + key + ": " + value + " in " + root - .getSimpleName()); - e.printStackTrace(); + } catch (final Throwable e) { + logger.atDebug().addArgument(key).addArgument(value).addArgument(root.getSimpleName()) + .setCause(e).log("Invalid configuration value '{}: {}' in {}"); } } } - PlotSquared.debug("Failed to set config option: " + key + ": " + value + " | " + instance); + logger.debug("Failed to set config option '{}: {}' | {}", key, value, instance); } public static boolean load(File file, Class root) { @@ -289,9 +290,8 @@ public class Config { setAccessible(field); return field; } catch (Throwable e) { - PlotSquared.debug( - "Invalid config field: " + StringMan.join(split, ".") + " for " + toNodeName( - instance.getClass().getSimpleName())); + logger.atDebug().addArgument(StringMan.join(split, ".")).setCause(e) + .addArgument(toNodeName(instance.getClass().getSimpleName())).log("Invalid config field: {} for {}"); return null; } } diff --git a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java index 0df6c3a3c..191309c99 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java @@ -25,8 +25,6 @@ */ package com.plotsquared.core.listener; -import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.util.WEManager; import com.plotsquared.core.util.WorldUtil; @@ -44,6 +42,8 @@ import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.util.HashMap; @@ -52,6 +52,8 @@ import java.util.Set; public class ProcessedWEExtent extends AbstractDelegateExtent { + private static final Logger logger = LoggerFactory.getLogger(ProcessedWEExtent.class); + private final Set mask; private final String world; private final int max; @@ -101,8 +103,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return false; } else { tileEntityCount[0]++; - PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + "," - + location.getZ()); + logger.debug("Detected unsafe WorldEdit: {},{},{}", location.getX(), location.getY(), location.getZ()); } } if (WEManager.maskContains(this.mask, location.getX(), location.getY(), location.getZ())) { @@ -133,9 +134,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { this.Ecount++; if (this.Ecount > Settings.Chunk_Processor.MAX_ENTITIES) { this.Eblocked = true; - PlotSquared.debug( - Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getBlockX() + "," - + location.getBlockZ()); + logger.debug("Detected unsafe WorldEdit: {},{},{}", location.getX(), location.getY(), location.getZ()); } if (WEManager.maskContains(this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) { diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index a9af02b65..56a32e328 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -54,6 +54,8 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.item.ItemType; import lombok.NonNull; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.nio.ByteBuffer; import java.util.Collection; @@ -73,6 +75,8 @@ import java.util.stream.Collectors; */ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer { + private static final Logger logger = LoggerFactory.getLogger(PlotPlayer.class); + public static final String META_LAST_PLOT = "lastplot"; public static final String META_LOCATION = "location"; @@ -580,9 +584,8 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer if (Settings.Enabled_Components.BAN_DELETER && isBanned()) { for (Plot owned : getPlots()) { owned.deletePlot(null); - PlotSquared.debug(String - .format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", - plot.getId(), getName())); + logger.debug("Plot {} was deleted + cleared due to {} getting banned", + owned.getId(), getName()); } } if (ExpireManager.IMP != null) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 0d756ac6c..bccf03232 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -73,6 +73,8 @@ import com.sk89q.worldedit.world.block.BlockTypes; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.awt.geom.Area; import java.awt.geom.PathIterator; @@ -117,6 +119,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; */ public class Plot { + private static final Logger logger = LoggerFactory.getLogger(Plot.class); + public static final int MAX_HEIGHT = 256; private static Set connected_cache; @@ -1731,9 +1735,8 @@ public class Plot { public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { - PlotSquared.debug(Captions.PREFIX.getTranslated() + String - .format("Player %s attempted to claim plot %s, but was not allowed", - player.getName(), this.getId().toCommaSeparatedString())); + logger.atDebug().addArgument(player.getName()).addArgument(this.getId().toCommaSeparatedString()) + .log("Player {} attempted to claim plot {}, but was not allowed"); return false; } return claim(player, teleport, schematic, true); @@ -1744,9 +1747,8 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { - PlotSquared.debug(Captions.PREFIX.getTranslated() + String.format( - "Player %s attempted to claim plot %s, but the database failed to update", - player.getName(), this.getId().toCommaSeparatedString())); + logger.debug("Player {} attempted to claim plot {}, but the database failed to update", + player.getName(), this.getId().toCommaSeparatedString()); return false; } } else { @@ -1833,9 +1835,8 @@ public class Plot { }); return true; } - PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String - .format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(), - this.area.toString())); + logger.atInfo().addArgument(this.getId().toCommaSeparatedString()) + .addArgument(this.area.toString()).log("Failed to add plot {} to plot area {}"); return false; } @@ -1933,12 +1934,12 @@ public class Plot { */ public boolean moveData(Plot plot, Runnable whenDone) { if (!this.hasOwner()) { - PlotSquared.debug(plot + " is unowned (single)"); + logger.atDebug().addArgument(plot).log("{} is unowned (single)"); TaskManager.runTask(whenDone); return false; } if (plot.hasOwner()) { - PlotSquared.debug(plot + " is unowned (multi)"); + logger.atDebug().addArgument(plot).log("{} is unowned (multi)"); TaskManager.runTask(whenDone); return false; } @@ -2646,7 +2647,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge - PlotSquared.debug("Fixing invalid merge: " + this); + logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2663,7 +2664,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.WEST)) { // invalid merge - PlotSquared.debug("Fixing invalid merge: " + this); + logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2680,7 +2681,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.NORTH)) { // invalid merge - PlotSquared.debug("Fixing invalid merge: " + this); + logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2696,7 +2697,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); if (!tmp.getMerged(Direction.EAST)) { // invalid merge - PlotSquared.debug("Fixing invalid merge: " + this); + logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2713,8 +2714,8 @@ public class Plot { if (!current.hasOwner() || current.settings == null) { // Invalid plot // merged onto unclaimed plot - PlotSquared.debug( - "Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs()); + logger.atDebug().addArgument(current).addArgument(current.getOwnerAbs()) + .log("Ignoring invalid merged plot: {} | {}"); continue; } tmpSet.add(current); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index fc2c12453..64fc305b6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -66,6 +66,8 @@ import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; @@ -85,6 +87,8 @@ import java.util.function.Consumer; */ public abstract class PlotArea { + private static final Logger logger = LoggerFactory.getLogger(PlotArea.class); + protected final ConcurrentHashMap plots = new ConcurrentHashMap<>(); @Getter @NotNull private final String worldName; @Getter private final String id; @@ -366,7 +370,6 @@ public abstract class PlotArea { } } - PlotSquared.log(Captions.PREFIX + "&3 - default flags: &7" + flagBuilder.toString()); this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); this.spawnBreeding = config.getBoolean("event.spawn.breeding"); @@ -1060,10 +1063,13 @@ public abstract class PlotArea { try { flags.add(flagInstance.parse(split[1])); } catch (final FlagParseException e) { - PlotSquared.log(Captions.PREFIX.getTranslated() + String.format( - "§cFailed to parse default flag with key §6'%s'§c and value: §6'%s'§c." - + " Reason: %s. This flag will not be added as a default flag.", - e.getFlag().getName(), e.getValue(), e.getErrorMessage())); + logger.atWarn() + .addArgument(e.getFlag().getName()) + .addArgument(e.getValue()) + .addArgument(e.getErrorMessage()) + .setCause(e) + .log("Failed to parse default flag with key '{}' and value '{}'. " + + "Reason: {}. This flag will not be added as a default flag."); } } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java index f7d326411..ed4b1453f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java @@ -33,6 +33,8 @@ import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.Array; import java.util.ArrayDeque; @@ -43,6 +45,9 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class PlotAnalysis { + + private static final Logger logger = LoggerFactory.getLogger(PlotAnalysis.class); + public static boolean running = false; public int changes; public int faces; @@ -91,22 +96,20 @@ public class PlotAnalysis { */ public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) { if (running) { - PlotSquared.debug("Calibration task already in progress!"); + logger.debug("Calibration task already in progress!"); return; } if (threshold <= 0 || threshold >= 1) { - PlotSquared.debug( - "Invalid threshold provided! (Cannot be 0 or 100 as then there's no point calibrating)"); + logger.debug("Invalid threshold provided! (Cannot be 0 or 100 as then there's no point in calibrating)"); return; } running = true; - PlotSquared.debug(" - Fetching all plots"); + logger.debug("- Fetching all plots"); final ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots()); TaskManager.runTaskAsync(new Runnable() { @Override public void run() { Iterator iterator = plots.iterator(); - PlotSquared.debug( - " - $1Reducing " + plots.size() + " plots to those with sufficient data"); + logger.debug("- Reducing {} plots to those with sufficient data", plots.size()); while (iterator.hasNext()) { Plot plot = iterator.next(); if (plot.getSettings().getRatings() == null || plot.getSettings().getRatings() @@ -116,11 +119,10 @@ public class PlotAnalysis { plot.addRunning(); } } - PlotSquared.debug(" - | Reduced to " + plots.size() + " plots"); + logger.debug("- | Reduced to {} plots", plots.size()); if (plots.size() < 3) { - PlotSquared.debug( - "Calibration cancelled due to insufficient comparison data, please try again later"); + logger.debug("Calibration cancelled due to insufficient comparison data, please try again later"); running = false; for (Plot plot : plots) { plot.removeRunning(); @@ -128,7 +130,7 @@ public class PlotAnalysis { return; } - PlotSquared.debug(" - $1Analyzing plot contents (this may take a while)"); + logger.debug("- Analyzing plot contents (this may take a while)"); int[] changes = new int[plots.size()]; int[] faces = new int[plots.size()]; @@ -154,7 +156,7 @@ public class PlotAnalysis { ratings[i] = (int) ( (plot.getAverageRating() + plot.getSettings().getRatings().size()) * 100); - PlotSquared.debug(" | " + plot + " (rating) " + ratings[i]); + logger.debug(" | {} (rating) {}", plot, ratings[i]); } } }); @@ -166,7 +168,7 @@ public class PlotAnalysis { if (queuePlot == null) { break; } - PlotSquared.debug(" | " + queuePlot); + logger.debug(" | {}", queuePlot); final Object lock = new Object(); TaskManager.runTask(new Runnable() { @Override public void run() { @@ -196,20 +198,18 @@ public class PlotAnalysis { } } - PlotSquared.debug( - " - $1Waiting on plot rating thread: " + mi.intValue() * 100 / plots.size() - + "%"); + logger.debug(" - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size()); + try { ratingAnalysis.join(); } catch (InterruptedException e) { e.printStackTrace(); } - PlotSquared - .debug(" - $1Processing and grouping single plot analysis for bulk processing"); + logger.debug(" - Processing and grouping single plot analysis for bulk processing"); for (int i = 0; i < plots.size(); i++) { Plot plot = plots.get(i); - PlotSquared.debug(" | " + plot); + logger.debug(" | {}", plot); PlotAnalysis analysis = plot.getComplexity(null); changes[i] = analysis.changes; @@ -225,18 +225,16 @@ public class PlotAnalysis { variety_sd[i] = analysis.variety_sd; } - PlotSquared.debug(" - $1Calculating rankings"); + logger.debug(" - Calculating rankings"); int[] rankRatings = rank(ratings); int n = rankRatings.length; int optimalIndex = (int) Math.round((1 - threshold) * (n - 1)); - PlotSquared.debug(" - $1Calculating rank correlation: "); - PlotSquared.debug( - " - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking"); - PlotSquared.debug( - " - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing"); + logger.debug(" - Calculating rank correlation: "); + logger.debug(" - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking"); + logger.debug(" - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing"); Settings.Auto_Clear settings = new Settings.Auto_Clear(); @@ -248,7 +246,7 @@ public class PlotAnalysis { settings.CALIBRATION.CHANGES = factorChanges == 1 ? 0 : (int) (factorChanges * 1000 / MathMan.getMean(changes)); - PlotSquared.debug(" - | changes " + factorChanges); + logger.debug(" - | changes {}", factorChanges); int[] rankFaces = rank(faces); int[] sdFaces = getSD(rankFaces, rankRatings); @@ -257,7 +255,7 @@ public class PlotAnalysis { double factorFaces = getCC(n, sumFaces); settings.CALIBRATION.FACES = factorFaces == 1 ? 0 : (int) (factorFaces * 1000 / MathMan.getMean(faces)); - PlotSquared.debug(" - | faces " + factorFaces); + logger.debug(" - | faces {}", factorFaces); int[] rankData = rank(data); int[] sdData = getSD(rankData, rankRatings); @@ -266,7 +264,7 @@ public class PlotAnalysis { double factor_data = getCC(n, sum_data); settings.CALIBRATION.DATA = factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data)); - PlotSquared.debug(" - | data " + factor_data); + logger.debug(" - | data {}", factor_data); int[] rank_air = rank(air); int[] sd_air = getSD(rank_air, rankRatings); @@ -275,7 +273,7 @@ public class PlotAnalysis { double factor_air = getCC(n, sum_air); settings.CALIBRATION.AIR = factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air)); - PlotSquared.debug(" - | air " + factor_air); + logger.debug("- | air {}", factor_air); int[] rank_variety = rank(variety); int[] sd_variety = getSD(rank_variety, rankRatings); @@ -285,7 +283,7 @@ public class PlotAnalysis { settings.CALIBRATION.VARIETY = factor_variety == 1 ? 0 : (int) (factor_variety * 1000 / MathMan.getMean(variety)); - PlotSquared.debug(" - | variety " + factor_variety); + logger.debug("- | variety {}", factor_variety); int[] rank_changes_sd = rank(changes_sd); int[] sd_changes_sd = getSD(rank_changes_sd, rankRatings); @@ -295,7 +293,7 @@ public class PlotAnalysis { settings.CALIBRATION.CHANGES_SD = factor_changes_sd == 1 ? 0 : (int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd)); - PlotSquared.debug(" - | changes_sd " + factor_changes_sd); + logger.debug(" - | changed_sd {}", factor_changes_sd); int[] rank_faces_sd = rank(faces_sd); int[] sd_faces_sd = getSD(rank_faces_sd, rankRatings); @@ -305,7 +303,7 @@ public class PlotAnalysis { settings.CALIBRATION.FACES_SD = factor_faces_sd == 1 ? 0 : (int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd)); - PlotSquared.debug(" - | faces_sd " + factor_faces_sd); + logger.debug(" - | faced_sd {}", factor_faces_sd); int[] rank_data_sd = rank(data_sd); int[] sd_data_sd = getSD(rank_data_sd, rankRatings); @@ -315,7 +313,7 @@ public class PlotAnalysis { settings.CALIBRATION.DATA_SD = factor_data_sd == 1 ? 0 : (int) (factor_data_sd * 1000 / MathMan.getMean(data_sd)); - PlotSquared.debug(" - | data_sd " + factor_data_sd); + logger.debug(" - | data_sd {}", factor_data_sd); int[] rank_air_sd = rank(air_sd); int[] sd_air_sd = getSD(rank_air_sd, rankRatings); @@ -324,7 +322,7 @@ public class PlotAnalysis { double factor_air_sd = getCC(n, sum_air_sd); settings.CALIBRATION.AIR_SD = factor_air_sd == 1 ? 0 : (int) (factor_air_sd * 1000 / MathMan.getMean(air_sd)); - PlotSquared.debug(" - | air_sd " + factor_air_sd); + logger.debug(" - | air_sd {}", factor_air_sd); int[] rank_variety_sd = rank(variety_sd); int[] sd_variety_sd = getSD(rank_variety_sd, rankRatings); @@ -334,11 +332,11 @@ public class PlotAnalysis { settings.CALIBRATION.VARIETY_SD = factor_variety_sd == 1 ? 0 : (int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd)); - PlotSquared.debug(" - | variety_sd " + factor_variety_sd); + logger.debug(" - | variety_sd {}", factor_variety_sd); int[] complexity = new int[n]; - PlotSquared.debug(" $1Calculating threshold"); + logger.debug(" Calculating threshold"); int max = 0; int min = 0; for (int i = 0; i < n; i++) { @@ -367,9 +365,7 @@ public class PlotAnalysis { logln("Correlation: "); logln(getCC(n, sum(square(getSD(rankComplexity, rankRatings))))); if (optimalComplexity == Integer.MAX_VALUE) { - PlotSquared.debug( - "Insufficient data to determine correlation! " + optimalIndex + " | " - + n); + logger.debug("Insufficient data to determine correlation! {} | {}", optimalIndex, n); running = false; for (Plot plot : plots) { plot.removeRunning(); @@ -387,10 +383,10 @@ public class PlotAnalysis { } // Save calibration - PlotSquared.debug(" $1Saving calibration"); + logger.debug(" Saving calibration"); Settings.AUTO_CLEAR.put("auto-calibrated", settings); Settings.save(PlotSquared.get().worldsFile); - PlotSquared.debug("$1Done!"); + logger.debug("Done!"); running = false; for (Plot plot : plots) { plot.removeRunning(); @@ -401,7 +397,7 @@ public class PlotAnalysis { } public static void logln(Object obj) { - PlotSquared.debug(log(obj)); + logger.debug(log(obj)); } public static String log(Object obj) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java index e0bb40fb8..b55c6a96d 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java @@ -27,11 +27,12 @@ package com.plotsquared.core.plot.flag; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; -import com.plotsquared.core.PlotSquared; import lombok.EqualsAndHashCode; import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; @@ -44,6 +45,8 @@ import java.util.Map; */ @EqualsAndHashCode(of = "flagMap") public class FlagContainer { + private static final Logger logger = LoggerFactory.getLogger(FlagContainer.class); + private final Map unknownFlags = new HashMap<>(); private final Map, PlotFlag> flagMap = new HashMap<>(); private final PlotFlagUpdateHandler plotFlagUpdateHandler; @@ -145,11 +148,9 @@ import java.util.Map; this.updateSubscribers .forEach(subscriber -> subscriber.handle(flag, plotFlagUpdateType)); } catch (IllegalStateException e) { - PlotSquared.log(String.format( - "Flag '%s' (class: '%s') could not be added to the container" - + " because the flag name exceeded the allowed limit of 64 characters." - + " Please tell the developer of that flag to fix this.", flag.getName(), - flag.getClass().getName())); + logger.info("Flag {} (class '{}') could not be added to the container because the " + + "flag name exceeded the allowed limit of 64 characters. Please tell the developer " + + "of the flag to fix this.", flag.getName(), flag.getClass().getName()); e.printStackTrace(); } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java index 9af840d4c..6197327a6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/BlockTypeWrapper.java @@ -27,13 +27,14 @@ package com.plotsquared.core.plot.flag.types; import com.google.common.base.Objects; import com.google.common.base.Preconditions; -import com.plotsquared.core.PlotSquared; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; @@ -44,6 +45,8 @@ import java.util.Map; */ public class BlockTypeWrapper { + private static final Logger logger = LoggerFactory.getLogger(BlockTypeWrapper.class); + private static final Map blockTypes = new HashMap<>(); private static final Map blockCategories = new HashMap<>(); @Nullable @Getter private final BlockType blockType; @@ -129,7 +132,7 @@ public class BlockTypeWrapper { && this.blockCategoryId != null) { // only if name is available this.blockCategory = BlockCategory.REGISTRY.get(this.blockCategoryId); if (this.blockCategory == null && !BlockCategory.REGISTRY.values().isEmpty()) { - PlotSquared.debug("- Block category #" + this.blockCategoryId + " does not exist"); + logger.debug("- Block category #{} does not exist", this.blockCategoryId); this.blockCategory = new NullBlockCategory(this.blockCategoryId); } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java b/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java index 95ae8e953..7e192dbe8 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java +++ b/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java @@ -29,18 +29,20 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.ChatManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PlotMessage { + private static final Logger logger = LoggerFactory.getLogger(PlotMessage.class); + private Object builder; public PlotMessage() { try { reset(ChatManager.manager); } catch (Throwable e) { - PlotSquared.debug( - PlotSquared.imp().getPluginName() + " doesn't support fancy chat for " + PlotSquared - .get().IMP.getServerVersion()); + logger.error("{} doesn't support fancy chat for {}", PlotSquared.imp().getPluginName(), PlotSquared.get().IMP.getServerVersion()); ChatManager.manager = new PlainChatManager(); reset(ChatManager.manager); } diff --git a/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java index cea58a95d..d3ad4e36e 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java @@ -25,17 +25,20 @@ */ package com.plotsquared.core.queue; -import com.plotsquared.core.PlotSquared; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nullable; public class LocationOffsetDelegateLocalBlockQueue extends DelegateLocalBlockQueue { + private static final Logger logger = LoggerFactory.getLogger(LocationOffsetDelegateLocalBlockQueue.class); + private final boolean[][] canPlace; private final int blockX; private final int blockZ; @@ -61,10 +64,9 @@ public class LocationOffsetDelegateLocalBlockQueue extends DelegateLocalBlockQue return super.setBlock(x, y, z, id); } } catch (final Exception e) { - PlotSquared.debug(String.format( - "Failed to set block at: %d;%d;%d (to = %s) with offset %d;%d." - + " Translated to: %d;%d", x, y, z, id, blockX, blockZ, x - blockX, - z - blockZ)); + logger.debug("Failed set block at {},{},{} (to = {}) with offset {};{}. Translated to: {}, {}", + x, y, z, id, blockX, blockZ, x - blockX, + z - blockZ); throw e; } return false; diff --git a/Core/src/main/java/com/plotsquared/core/util/Expression.java b/Core/src/main/java/com/plotsquared/core/util/Expression.java index 86bdeea2d..da25e4ed1 100644 --- a/Core/src/main/java/com/plotsquared/core/util/Expression.java +++ b/Core/src/main/java/com/plotsquared/core/util/Expression.java @@ -28,10 +28,15 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.DebugExec; import com.plotsquared.core.command.MainCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.script.ScriptException; public abstract class Expression { + + private static final Logger logger = LoggerFactory.getLogger(Expression.class); + public static Expression constant(final U value) { return new Expression() { @Override public U evaluate(U arg) { @@ -66,7 +71,7 @@ public abstract class Expression { try { return (Double) exec.getEngine().eval(expression.replace("{arg}", "" + arg)); } catch (ScriptException e) { - PlotSquared.debug("Invalid Expression: " + expression); + logger.debug("Invalid expression: {}", expression); e.printStackTrace(); } return 0d; diff --git a/Core/src/main/java/com/plotsquared/core/util/logger/ILogger.java b/Core/src/main/java/com/plotsquared/core/util/logger/ILogger.java index 3f9b3d598..c5e145812 100644 --- a/Core/src/main/java/com/plotsquared/core/util/logger/ILogger.java +++ b/Core/src/main/java/com/plotsquared/core/util/logger/ILogger.java @@ -25,6 +25,6 @@ */ package com.plotsquared.core.util.logger; -public interface ILogger { - void log(String message); +@Deprecated public interface ILogger { + @Deprecated void log(String message); } From 1c254984c189588a91bafeffe4d5d416fbd0661f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 5 Jul 2020 13:56:54 +0200 Subject: [PATCH 02/35] Replace logging references in Bukkitmain --- .../com/plotsquared/bukkit/BukkitMain.java | 86 +++++++------------ 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1a40c51d5..780c36326 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -133,6 +133,8 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.lang.reflect.Method; @@ -159,6 +161,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { + private static final Logger logger = LoggerFactory.getLogger(BukkitMain.class); + private static final int BSTATS_ID = 1404; @Getter private static WorldEdit worldEdit; @@ -191,9 +195,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } catch (NumberFormatException e) { e.printStackTrace(); - PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion())); - PlotSquared.debug( - StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\."))); + logger.debug(StringMan.getString(Bukkit.getBukkitVersion())); + logger.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\."))); return new int[] {1, 13, 0}; } } @@ -225,14 +228,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } if (PremiumVerification.isPremium()) { - PlotSquared.log( - Captions.PREFIX + "&6PlotSquared version licensed to Spigot user " + getUserID()); - PlotSquared - .log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/" + getResourceID()); - PlotSquared.log(Captions.PREFIX + "&6Download ID: " + getDownloadID()); - PlotSquared.log(Captions.PREFIX + "&6Thanks for supporting us :)"); + logger.info("PlotSquared version licensed to Spigot user {}", getUserID()); + logger.info("https://www.spigotmc.org/resources/{}", getResourceID()); + logger.info("Download ID: {}", getDownloadID()); + logger.info("Thanks for supporting us :)"); } else { - PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :("); + logger.info("Couldn't verify purchase :("); } final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline(); @@ -252,7 +253,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService(); impromptuPipeline.registerService(offlineModeUUIDService); backgroundPipeline.registerService(offlineModeUUIDService); - PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service"); + logger.info("(UUID) Using the offline mode UUID service"); } final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService(); @@ -272,8 +273,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final LuckPermsUUIDService luckPermsUUIDService; if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { luckPermsUUIDService = new LuckPermsUUIDService(); - PlotSquared - .log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service"); + logger.info("(UUID) Using LuckPerms as a complementary UUID service"); } else { luckPermsUUIDService = null; } @@ -281,8 +281,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final BungeePermsUUIDService bungeePermsUUIDService; if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) { bungeePermsUUIDService = new BungeePermsUUIDService(); - PlotSquared - .log(Captions.PREFIX + "(UUID) Using BungeePerms as a complementary UUID service"); + logger.info("(UUID) Using BungeePerms as a complementary UUID service"); } else { bungeePermsUUIDService = null; } @@ -290,8 +289,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final EssentialsUUIDService essentialsUUIDService; if (Bukkit.getPluginManager().getPlugin("Essentials") != null) { essentialsUUIDService = new EssentialsUUIDService(); - PlotSquared - .log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service"); + logger.info("(UUID) Using Essentials as a complementary UUID service"); } else { essentialsUUIDService = null; } @@ -302,8 +300,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final PaperUUIDService paperUUIDService = new PaperUUIDService(); impromptuPipeline.registerService(paperUUIDService); backgroundPipeline.registerService(paperUUIDService); - PlotSquared - .log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service"); + logger.info("(UUID) Using Paper as a complementary UUID service"); } impromptuPipeline.registerService(sqLiteUUIDService); @@ -356,10 +353,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { ChatFormatter.formatters.add(new PlaceholderFormatter()); } - PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI"); + logger.info("PlotSquared hooked into PlaceholderAPI"); } else { - PlotSquared - .debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated."); + logger.info("PlaceholderAPI is not in use. Hook deactivated"); } this.startMetrics(); @@ -375,9 +371,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< try { this.backupManager = new SimpleBackupManager(); } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX + "&6Failed to initialize backup manager"); - e.printStackTrace(); - PlotSquared.log(Captions.PREFIX + "&6Backup features will be disabled"); + logger.error("Failed to initialize backup manager", e); + logger.error("Backup features will be disabled"); this.backupManager = new NullBackupManager(); } @@ -389,9 +384,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< this.worldManager = new BukkitWorldManager(); } - PlotSquared.log( - Captions.PREFIX.getTranslated() + "Using platform world manager: " + this.worldManager - .getName()); + logger.info("Using platform world manager: {}", this.worldManager.getName()); // Clean up potential memory leak Bukkit.getScheduler().runTaskTimer(this, () -> { @@ -452,7 +445,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final Chunk[] chunks = world.getLoadedChunks(); if (chunks.length == 0) { if (!Bukkit.unloadWorld(world, true)) { - PlotSquared.debug("Failed to unload " + world.getName()); + logger.debug("Failed to unload {}", world.getName()); } return; } else { @@ -502,8 +495,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } }); - PlotSquared.log(Captions.PREFIX.getTranslated() + "(UUID) " + uuidQueue.size() - + " UUIDs will be cached."); + + logger.info("(UUID) {} UUIDs will be cached", uuidQueue.size()); Executors.newSingleThreadScheduledExecutor().schedule(() -> { // Begin by reading all the SQLite cache at once @@ -511,9 +504,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< // Now fetch names for all known UUIDs final int totalSize = uuidQueue.size(); int read = 0; - PlotSquared.log(Captions.PREFIX.getTranslated() - + "(UUID) PlotSquared will fetch UUIDs in groups of " - + Settings.UUID.BACKGROUND_LIMIT); + logger.info("(UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT); final List uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT); // Used to indicate that the second retrieval has been attempted @@ -521,7 +512,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) { if (!uuidList.isEmpty() && secondRun) { - PlotSquared.log("Giving up on last batch. Fetching new batch instead."); + logger.warn("(UUID) Giving up on last batch. Fetching new batch instead"); uuidList.clear(); } if (uuidList.isEmpty()) { @@ -545,15 +536,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< uuidList.clear(); // Print progress final double percentage = ((double) read / (double) totalSize) * 100.0D; - PlotSquared.log(Captions.PREFIX.getTranslated() + String - .format("(UUID) PlotSquared has cached %.1f%% of UUIDs", percentage)); + logger.info("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); } catch (final InterruptedException | ExecutionException e) { - PlotSquared.log("Failed to retrieve that batch. Will try again."); + logger.error("(UUID) Failed to retrieve last batch. Will try again", e); e.printStackTrace(); } } - PlotSquared - .log(Captions.PREFIX.getTranslated() + "(UUID) PlotSquared has cached all UUIDs"); + logger.info("(UUID) PlotSquared has cached all UUIDs"); }, 10, TimeUnit.SECONDS); } @@ -615,7 +604,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } @Override @SuppressWarnings("deprecation") public void runEntityTask() { - PlotSquared.log(Captions.PREFIX + "KillAllEntities started."); + logger.info("KillAllEntities started"); TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> { final World world = Bukkit.getWorld(plotArea.getWorldName()); try { @@ -908,21 +897,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return econ; } } catch (Throwable ignored) { - PlotSquared.debug("No economy detected!"); + logger.debug("No economy handler detected"); } return null; } @Override public QueueProvider initBlockQueue() { - //TODO Figure out why this code is still here yet isn't being called anywhere. - // try { - // new SendChunk(); - // MainUtil.canSendChunk = true; - // } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { - // PlotSquared.debug( - // SendChunk.class + " does not support " + StringMan.getString(getServerVersion())); - // MainUtil.canSendChunk = false; - // } return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class); } @@ -1034,8 +1014,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< if (!PlotSquared.get().hasPlotArea(worldName)) { SetGenCB.setGenerator(BukkitUtil.getWorld(worldName)); } - } catch (Exception e) { - PlotSquared.log("Failed to reload world: " + world + " | " + e.getMessage()); + } catch (final Exception e) { + logger.error("Failed to reload world: {} | {}", world, e.getMessage()); Bukkit.getServer().unloadWorld(world, false); return; } From 298e65a394dd245bca22ca3421ef35e4275370bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 6 Jul 2020 17:17:46 +0200 Subject: [PATCH 03/35] Replace remaining references to PlotSquared#log --- .../plotsquared/bukkit/util/BukkitUtil.java | 8 +- .../bukkit/util/UpdateUtility.java | 21 +- .../com/plotsquared/core/PlotSquared.java | 201 +++++------- .../com/plotsquared/core/command/Debug.java | 11 + .../plotsquared/core/command/DebugExec.java | 11 +- .../com/plotsquared/core/command/Purge.java | 19 +- .../com/plotsquared/core/command/Trim.java | 10 +- .../components/ComponentPresetManager.java | 12 +- .../plotsquared/core/database/SQLManager.java | 297 +++++++----------- .../core/generator/HybridPlotWorld.java | 14 +- .../core/generator/HybridUtils.java | 31 +- .../core/player/ConsolePlayer.java | 5 +- .../core/util/LegacyConverter.java | 8 +- .../com/plotsquared/core/util/MainUtil.java | 11 +- .../plotsquared/core/util/RegionManager.java | 6 +- .../plotsquared/core/uuid/UUIDPipeline.java | 12 +- 16 files changed, 298 insertions(+), 379 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 5acdde298..a9dcd4a66 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -95,6 +95,8 @@ import org.bukkit.entity.Vehicle; import org.bukkit.entity.WaterMob; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; @@ -110,6 +112,8 @@ import java.util.stream.Stream; @SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil { + private static final Logger logger = LoggerFactory.getLogger(BukkitUtil.class); + private static String lastString = null; private static World lastWorld = null; @@ -505,7 +509,7 @@ public class BukkitUtil extends WorldUtil { @NonNull final BiomeType biomeType) { final World world = getWorld(worldName); if (world == null) { - PlotSquared.log("An error occurred setting the biome because the world was null."); + logger.warn("An error occured while setting the biome because the world was null", new RuntimeException()); return; } final Biome biome = BukkitAdapter.adapt(biomeType); @@ -619,7 +623,7 @@ public class BukkitUtil extends WorldUtil { } break; default: { - PlotSquared.log(Captions.PREFIX + "Unknown entity category requested: " + category); + logger.error("Unknown entity category requested: {}", category); } break; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java index 458e3ca58..d3ed81cb8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -30,12 +30,13 @@ import com.google.gson.JsonParser; import com.google.gson.stream.JsonReader; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotVersion; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.net.ssl.HttpsURLConnection; import java.io.IOException; @@ -44,6 +45,8 @@ import java.net.URL; public class UpdateUtility implements Listener { + private static final Logger logger = LoggerFactory.getLogger(UpdateUtility.class); + public static PlotVersion internalVersion; public static String spigotVersion; public static boolean hasUpdate; @@ -68,26 +71,22 @@ public class UpdateUtility implements Listener { .getAsJsonObject(); spigotVersion = result.get("current_version").getAsString(); } catch (IOException e) { - PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e); + logger.error("Unable to check for updates. Error: {}", e.getMessage()); return; } if (internalVersion.isLaterVersion(spigotVersion)) { - PlotSquared - .log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!"); - PlotSquared.log( - Captions.PREFIX + "&6You are running version " + internalVersion.versionString() - + ", &6latest version is " + spigotVersion); - PlotSquared - .log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/77506/updates"); + logger.info("There appears to be a PlotSquared update available!"); + logger.info("You are running version {}, the latest version is {}", + internalVersion.versionString(), spigotVersion); + logger.info("https://www.spigotmc.org/resources/77506/updates"); hasUpdate = true; if (Settings.UpdateChecker.NOTIFY_ONCE) { cancelTask(); } } else if (notify) { notify = false; - PlotSquared.log(Captions.PREFIX - + "Congratulations! You are running the latest PlotSquared version."); + logger.info("Congratulations! You are running the latest PlotSquared version"); } }, 0L, Settings.UpdateChecker.POLL_RATE * 60 * 20); } diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 0487c59da..d6ccfd81d 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -28,7 +28,6 @@ package com.plotsquared.core; import com.plotsquared.core.command.WE_Anywhere; import com.plotsquared.core.components.ComponentPresetManager; import com.plotsquared.core.configuration.Caption; -import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; @@ -48,7 +47,6 @@ import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.listener.WESubscriber; import com.plotsquared.core.location.Location; -import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.Plot; @@ -81,7 +79,6 @@ import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.WorldUtil; -import com.plotsquared.core.util.logger.ILogger; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDPipeline; @@ -90,9 +87,10 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import lombok.Getter; import lombok.NonNull; -import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.File; @@ -138,6 +136,8 @@ import java.util.zip.ZipInputStream; */ @SuppressWarnings({"unused", "WeakerAccess"}) public class PlotSquared { + + private static final Logger logger = LoggerFactory.getLogger(PlotSquared.class); private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); private static PlotSquared instance; // Implementation @@ -164,8 +164,6 @@ public class PlotSquared { public HashMap> clusters_tmp; public HashMap> plots_tmp; private YamlConfiguration config; - // Implementation logger - @Deprecated @Setter @Getter private ILogger logger; // Platform / Version / Update URL private PlotVersion version; // Files and configuration @@ -188,7 +186,6 @@ public class PlotSquared { this.thread = Thread.currentThread(); this.IMP = iPlotMain; - this.logger = iPlotMain; Settings.PLATFORM = platform; // @@ -240,7 +237,7 @@ public class PlotSquared { if (!getConfigurationVersion().equalsIgnoreCase("v5")) { // Perform upgrade if (DBFunc.dbManager.convertFlags()) { - log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!"); + logger.info("Flags were converted successfully"); // Update the config version setConfigurationVersion("v5"); } @@ -288,8 +285,7 @@ public class PlotSquared { if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { if (this.IMP.initWorldEdit()) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName() - + " hooked into WorldEdit."); + logger.info("{} hooked into WorldEdit", imp().getPluginName()); this.worldedit = WorldEdit.getInstance(); WorldEdit.getInstance().getEventBus().register(new WESubscriber()); if (Settings.Enabled_Components.COMMANDS) { @@ -298,8 +294,8 @@ public class PlotSquared { } } catch (Throwable e) { - PlotSquared.debug( - "Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); + logger.error("Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); + } } // Economy @@ -312,8 +308,7 @@ public class PlotSquared { try { new ComponentPresetManager(); } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX + "Failed to initialize the preset system"); - e.printStackTrace(); + logger.error("Failed to initialize the preset system", e); } } @@ -334,14 +329,11 @@ public class PlotSquared { continue; } if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { - debug("`" + world + "` was not properly loaded - " + IMP.getPluginName() - + " will now try to load it properly: "); - debug( - " - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); - debug( - " - Your world management plugin may be faulty (or non existent)"); - debug( - " This message may also be a false positive and could be ignored."); + logger.debug("`{}` was not properly loaded - {} will now try to load it properly", + world, imp().getPluginName()); + logger.debug(" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); + logger.debug(" - Your world management plugin may be faulty (or non existent)"); + logger.debug(" This message may also be a false positive and could be ignored."); PlotSquared.this.IMP.setGenerator(world); } } @@ -372,9 +364,7 @@ public class PlotSquared { e.printStackTrace(); } - PlotSquared.log(Captions.PREFIX + CaptionUtility - .format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(), - IMP.getPluginName())); + logger.debug("{} is now enabled!", imp().getPluginName()); } /** @@ -406,11 +396,7 @@ public class PlotSquared { message.toString().isEmpty())) { return; } - if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { - System.out.printf("[P2][Info] %s\n", StringMan.getString(message)); - } else { - PlotSquared.get().getLogger().log(StringMan.getString(message)); - } + logger.info(StringMan.getString(message)); } /** @@ -422,11 +408,7 @@ public class PlotSquared { */ @Deprecated public static void debug(@Nullable Object message) { if (Settings.DEBUG) { - if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) { - System.out.printf("[P2][Debug] %s\n", StringMan.getString(message)); - } else { - PlotSquared.get().getLogger().log(StringMan.getString(message)); - } + logger.debug(StringMan.getString(message)); } } @@ -557,21 +539,16 @@ public class PlotSquared { regionInts.forEach(l -> regions.add(BlockVector2.at(l[0], l[1]))); chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1]))); int height = (int) list.get(2); - PlotSquared.log( - Captions.PREFIX + "Incomplete road regeneration found. Restarting in world " - + plotArea.getWorldName() + " with height " + height + "."); + logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height); PlotSquared.debug(" Regions: " + regions.size()); PlotSquared.debug(" Chunks: " + chunks.size()); HybridUtils.UPDATE = true; HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks); } catch (IOException | ClassNotFoundException e) { - PlotSquared.log(Captions.PREFIX + "Error restarting road regeneration."); - e.printStackTrace(); + logger.error("Error restarting road regeneration", e); } finally { if (!file.delete()) { - PlotSquared.log( - Captions.PREFIX + "Error deleting persistent_regen_data_" + plotArea.getId() - + ". Please manually delete this file."); + logger.error("Error deleting persistent_regen_data_{}. Please delete this file manually", plotArea.getId()); } } }); @@ -1159,12 +1136,10 @@ public class PlotSquared { // Conventional plot generator PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null); PlotManager plotManager = plotArea.getPlotManager(); - PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'"); - PlotSquared - .log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator); - PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName()); - PlotSquared.log( - Captions.PREFIX + "&3 - plotAreaManager: &7" + plotManager.getClass().getName()); + logger.info("Detected world load for '{}'", world); + logger.info(" - generator: {}>{}", baseGenerator, plotGenerator); + logger.info(" - plot world: {}", plotArea.getClass().getCanonicalName()); + logger.info("- plot area manager: {}", plotManager.getClass().getCanonicalName()); if (!this.worlds.contains(path)) { this.worlds.createSection(path); worldSection = this.worlds.getConfigurationSection(path); @@ -1186,10 +1161,10 @@ public class PlotSquared { ConfigurationSection areasSection = worldSection.getConfigurationSection("areas"); if (areasSection == null) { if (plotAreaManager.getPlotAreas(world, null).length != 0) { - debug("World possibly already loaded: " + world); + logger.debug("World possibly already loaded: {}", world); return; } - PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'"); + logger.info("Detected world load for '{}'", world); String gen_string = worldSection.getString("generator.plugin", IMP.getPluginName()); if (type == PlotAreaType.PARTIAL) { Set clusters = @@ -1205,8 +1180,7 @@ public class PlotSquared { String fullId = name + "-" + pos1 + "-" + pos2; worldSection.createSection("areas." + fullId); DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE - - PlotSquared.log(Captions.PREFIX + "&3 - " + name + "-" + pos1 + "-" + pos2); + logger.info(" - {}-{}-{}", name, pos1, pos2); GeneratorWrapper areaGen = this.IMP.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); @@ -1220,14 +1194,10 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - PlotSquared.log( - Captions.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" - + areaGen); - PlotSquared.log(Captions.PREFIX + "&c | &9plotworld: &7" + pa); - PlotSquared.log(Captions.PREFIX + "&c | &9manager: &7" + pa); - PlotSquared.log( - Captions.PREFIX + "&cNote: &7Area created for cluster:" + name - + " (invalid or old configuration?)"); + logger.info(" | generator: {}>{}", baseGenerator, areaGen); + logger.info(" | plot world: {}", pa); + logger.info(" | manager: {}", pa); + logger.info("Note: Area created for cluster '{}' (invalid or old configuration?)", name); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); toLoad.add(pa); @@ -1249,10 +1219,9 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - PlotSquared - .log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + areaGen); - PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + pa); - PlotSquared.log(Captions.PREFIX + "&3 - plotAreaManager: &7" + pa.getPlotManager()); + logger.info(" - generator: {}>{}", baseGenerator, areaGen); + logger.info(" - plot world: {}", pa); + logger.info(" - plot area manager: {}", pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1264,7 +1233,7 @@ public class PlotSquared { + PlotAreaType.AUGMENTED + "`"); } for (String areaId : areasSection.getKeys(false)) { - PlotSquared.log(Captions.PREFIX + " - " + areaId); + logger.info(" - {}", areaId); String[] split = areaId.split("(?<=[^;-])-"); if (split.length != 3) { throw new IllegalArgumentException("Invalid Area identifier: " + areaId @@ -1326,11 +1295,10 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - PlotSquared.log(Captions.PREFIX + "&aDetected area load for '" + world + "'"); - PlotSquared - .log(Captions.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); - PlotSquared.log(Captions.PREFIX + "&c | &9plotworld: &7" + pa); - PlotSquared.log(Captions.PREFIX + "&c | &9manager: &7" + pa.getPlotManager()); + logger.info("Detected area load for '{}'", world); + logger.info(" | generator: {}>{}", baseGenerator, areaGen); + logger.info(" | plot world: {}", pa); + logger.info(" | manager: {}", pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1399,7 +1367,7 @@ public class PlotSquared { for (String element : split) { String[] pair = element.split("="); if (pair.length != 2) { - PlotSquared.log("&cNo value provided for: &7" + element); + logger.error("No value provided for '{}'", element); return false; } String key = pair[0].toLowerCase(); @@ -1447,12 +1415,12 @@ public class PlotSquared { ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); break; default: - PlotSquared.log("&cKey not found: &7" + element); + logger.error("Key not found: {}", element); return false; } } catch (Exception e) { + logger.error("Invalid value '{}' for arg '{}'", value, element); e.printStackTrace(); - PlotSquared.log("&cInvalid value: &7" + value + " in arg " + element); return false; } } @@ -1530,8 +1498,8 @@ public class PlotSquared { } } } catch (IOException e) { + logger.error("Could not save {}", file); e.printStackTrace(); - PlotSquared.log("&cCould not save " + file); } } @@ -1566,8 +1534,8 @@ public class PlotSquared { // Close the connection DBFunc.close(); } catch (NullPointerException throwable) { + logger.error("Could not close database connection", throwable); throwable.printStackTrace(); - PlotSquared.log("&cCould not close database connection!"); } } @@ -1579,10 +1547,9 @@ public class PlotSquared { HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) { return; } - PlotSquared.log( - Captions.PREFIX + "Road regeneration incomplete. Saving incomplete regions to disk."); - PlotSquared.debug(" Regions: " + HybridUtils.regions.size()); - PlotSquared.debug(" Chunks: " + HybridUtils.chunks.size()); + logger.info("Road regeneration incomplete. Saving incomplete regions to disk"); + logger.info(" - regions: {}", HybridUtils.regions.size()); + logger.info(" - chunks: {}", HybridUtils.chunks.size()); ArrayList regions = new ArrayList<>(); ArrayList chunks = new ArrayList<>(); for (BlockVector2 r : HybridUtils.regions) { @@ -1599,16 +1566,14 @@ public class PlotSquared { this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area .getId() + "_" + HybridUtils.area.getWorldName()); if (file.exists() && !file.delete()) { - PlotSquared.log(Captions.PREFIX - + "persistent_regen_data file already exists and could not be deleted."); + logger.error("persistent_regene_data file already exists and could not be deleted"); return; } try (ObjectOutputStream oos = new ObjectOutputStream( Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) { oos.writeObject(list); } catch (IOException e) { - PlotSquared.log(Captions.PREFIX + "Error create persistent_regen_data file."); - e.printStackTrace(); + logger.error("Error creating persistent_region_data file", e); } } @@ -1628,7 +1593,7 @@ public class PlotSquared { File file = MainUtil.getFile(IMP.getDirectory(), Storage.SQLite.DB + ".db"); database = new SQLite(file); } else { - PlotSquared.log(Captions.PREFIX + "&cNo storage type is set!"); + logger.error("No storage type is set. Disabling PlotSquared"); this.IMP.shutdown(); //shutdown used instead of disable because no database is set return; } @@ -1646,19 +1611,12 @@ public class PlotSquared { } this.clusters_tmp = DBFunc.getClusters(); } catch (ClassNotFoundException | SQLException e) { - PlotSquared.log(Captions.PREFIX - + "&cFailed to open DATABASE connection. The plugin will disable itself."); - if (Storage.MySQL.USE) { - PlotSquared.log("$4MYSQL"); - } else if (Storage.SQLite.USE) { - PlotSquared.log("$4SQLITE"); - } - PlotSquared.log( - "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); + logger.error("Failed to open database connection ({}). Disabling PlotSquared", Storage.MySQL.USE ? "MySQL" : "SQLite"); + logger.error("==== Here is an ugly stacktrace, if you are interested in those things ==="); e.printStackTrace(); - PlotSquared.log("&d==== End of stacktrace ===="); - PlotSquared.log("&6Please go to the " + IMP.getPluginName() - + " 'storage.yml' and configure the database correctly."); + logger.error("&d==== End of stacktrace ===="); + logger.error("&6Please go to the {} 'storage.yml' and configure the database correctly", + imp().getPluginName()); this.IMP.shutdown(); //shutdown used instead of disable because of database error } } @@ -1683,7 +1641,7 @@ public class PlotSquared { try { worlds.save(worldsFile); } catch (IOException e) { - PlotSquared.debug("Failed to save " + IMP.getPluginName() + " worlds.yml"); + logger.error("Failed to save worlds.yml", e); e.printStackTrace(); } } @@ -1716,14 +1674,12 @@ public class PlotSquared { public boolean setupConfigs() { File folder = new File(this.IMP.getDirectory(), "config"); if (!folder.exists() && !folder.mkdirs()) { - PlotSquared.log(Captions.PREFIX - + "&cFailed to create the /plugins/config folder. Please create it manually."); + logger.error("Failed to create the /plugins/config folder. Please create it manually"); } try { this.worldsFile = new File(folder, "worlds.yml"); if (!this.worldsFile.exists() && !this.worldsFile.createNewFile()) { - PlotSquared.log( - "Could not create the worlds file, please create \"worlds.yml\" manually."); + logger.error("Could not create the worlds file. Please create 'worlds.yml' manually"); } this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile); @@ -1733,21 +1689,20 @@ public class PlotSquared { .equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worlds .getString("configuration_version").equalsIgnoreCase("v5"))) { // Conversion needed - log(Captions.LEGACY_CONFIG_FOUND.getTranslated()); + logger.info(Captions.LEGACY_CONFIG_FOUND.getTranslated()); try { com.google.common.io.Files .copy(this.worldsFile, new File(folder, "worlds.yml.old")); - log(Captions.LEGACY_CONFIG_BACKUP.getTranslated()); + logger.info(Captions.LEGACY_CONFIG_BACKUP.getTranslated()); final ConfigurationSection worlds = this.worlds.getConfigurationSection("worlds"); final LegacyConverter converter = new LegacyConverter(worlds); converter.convert(); this.worlds.set("worlds", worlds); this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION); - log(Captions.LEGACY_CONFIG_DONE.getTranslated()); + logger.info(Captions.LEGACY_CONFIG_DONE.getTranslated()); } catch (final Exception e) { - log(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated()); - e.printStackTrace(); + logger.error(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated(), e); } // Disable plugin this.IMP.shutdown(); @@ -1757,18 +1712,17 @@ public class PlotSquared { this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION); } } catch (IOException ignored) { - PlotSquared.log("Failed to save settings.yml"); + logger.error("Failed to save worlds.yml"); } try { this.configFile = new File(folder, "settings.yml"); if (!this.configFile.exists() && !this.configFile.createNewFile()) { - PlotSquared.log( - "Could not create the settings file, please create \"settings.yml\" manually."); + logger.error("Could not create the settings file. Please create 'settings.yml' manually"); } this.config = YamlConfiguration.loadConfiguration(this.configFile); setupConfig(); } catch (IOException ignored) { - PlotSquared.log("Failed to save settings.yml"); + logger.error("Failed to save settings.yml"); } try { this.styleFile = MainUtil.getFile(IMP.getDirectory(), @@ -1778,43 +1732,38 @@ public class PlotSquared { this.styleFile.getParentFile().mkdirs(); } if (!this.styleFile.createNewFile()) { - PlotSquared.log( - "Could not create the style file, please create \"translations/style.yml\" manually"); + logger.error("Failed to create the style file. Please create 'translations/style.yml' manually"); } } this.style = YamlConfiguration.loadConfiguration(this.styleFile); setupStyle(); - } catch (IOException err) { - err.printStackTrace(); - PlotSquared.log("Failed to save style.yml"); + } catch (IOException ignored) { + logger.error("Failed to save style.yml"); } try { this.storageFile = new File(folder, "storage.yml"); if (!this.storageFile.exists() && !this.storageFile.createNewFile()) { - PlotSquared.log( - "Could not the storage settings file, please create \"storage.yml\" manually."); + logger.error("Could not create the storage settings file. Please create 'storage.yml' manually"); } this.storage = YamlConfiguration.loadConfiguration(this.storageFile); setupStorage(); } catch (IOException ignored) { - PlotSquared.log("Failed to save storage.yml"); + logger.error("Failed to save storage.yml"); } try { this.commandsFile = new File(folder, "commands.yml"); if (!this.commandsFile.exists() && !this.commandsFile.createNewFile()) { - PlotSquared.log( - "Could not the storage settings file, please create \"commands.yml\" manually."); + logger.error("Could not create the commands file. Please create 'commands.yml' manually"); } this.commands = YamlConfiguration.loadConfiguration(this.commandsFile); } catch (IOException ignored) { - PlotSquared.log("Failed to save commands.yml"); + logger.error("Failed to save commands.yml"); } try { this.style.save(this.styleFile); this.commands.save(this.commandsFile); } catch (IOException e) { - PlotSquared.log("Configuration file saving failed"); - e.printStackTrace(); + logger.error("Configuration file saving failed", e); } return true; } @@ -1845,9 +1794,7 @@ public class PlotSquared { if (Settings.DEBUG) { Map components = Settings.getFields(Settings.Enabled_Components.class); for (Entry component : components.entrySet()) { - PlotSquared.log(Captions.PREFIX + String - .format("&cKey: &6%s&c, Value: &6%s", component.getKey(), - component.getValue())); + logger.debug("Key: {} | Value: {}", component.getKey(), component.getValue()); } } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index 91997a4ec..677003483 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -36,6 +36,8 @@ import com.plotsquared.core.util.entity.EntityCategory; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDMapping; import com.sk89q.worldedit.world.entity.EntityType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.Comparator; @@ -48,6 +50,8 @@ import java.util.Map; permission = "plots.admin") public class Debug extends SubCommand { + private static final Logger logger = LoggerFactory.getLogger(Debug.class); + @Override public boolean onCommand(PlotPlayer player, String[] args) { if (args.length > 0) { if ("player".equalsIgnoreCase(args[0])) { @@ -79,6 +83,13 @@ public class Debug extends SubCommand { } return true; } + if (args.length > 0 && "logging".equalsIgnoreCase(args[0])) { + logger.info("Info!"); + logger.warn("Warning!"); + logger.error("Error!", new RuntimeException()); + logger.debug("Debug!"); + return true; + } if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) { EntityCategories.init(); player.sendMessage(Captions.PREFIX.getTranslated() + "§cEntity Categories: "); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 381582c57..53d6b00a5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -59,6 +59,8 @@ import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.world.block.BlockState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.script.Bindings; import javax.script.ScriptContext; @@ -81,6 +83,9 @@ import java.util.concurrent.CompletableFuture; aliases = {"exec", "$"}, category = CommandCategory.DEBUG) public class DebugExec extends SubCommand { + + private static final Logger logger = LoggerFactory.getLogger(DebugExec.class); + private ScriptEngine engine; private Bindings scope; @@ -459,14 +464,12 @@ public class DebugExec extends SubCommand { } catch (ScriptException e) { e.printStackTrace(); } - PlotSquared - .log("> " + (System.currentTimeMillis() - start) + "ms -> " + result); + logger.info("> {}ms -> {}", System.currentTimeMillis() - start, result); }); } else { long start = System.currentTimeMillis(); Object result = this.engine.eval(script, this.scope); - PlotSquared - .log("> " + (System.currentTimeMillis() - start) + "ms -> " + result); + logger.info("> {}ms -> {}", System.currentTimeMillis() - start, result); } return true; } catch (ScriptException e) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 9a89b2230..4e63ad8a1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -36,6 +36,8 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.TaskManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.HashSet; @@ -53,6 +55,8 @@ import java.util.concurrent.atomic.AtomicBoolean; confirmation = true) public class Purge extends SubCommand { + private static final Logger logger = LoggerFactory.getLogger(Purge.class); + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { Captions.COMMAND_SYNTAX.send(player, getUsage()); @@ -170,6 +174,7 @@ public class Purge extends SubCommand { "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)"; boolean finalClear = clear; Runnable run = () -> { + logger.debug("Calculating plots to purge, please wait..."); PlotSquared.debug("Calculating plots to purge, please wait..."); HashSet ids = new HashSet<>(); Iterator iterator = toDelete.iterator(); @@ -183,22 +188,18 @@ public class Purge extends SubCommand { try { ids.add(plot.temp); if (finalClear) { - plot.clear(false, true, () -> PlotSquared - .debug("Plot " + plot.getId() + " cleared by purge.")); + plot.clear(false, true, () -> + logger.debug("Plot {} cleared by purge", plot.getId())); } else { plot.removeSign(); } plot.getArea().removePlot(plot.getId()); - for (PlotPlayer pp : plot.getPlayersInPlot()) { + for (PlotPlayer pp : plot.getPlayersInPlot()) { PlotListener.plotEntry(pp, plot); } } catch (NullPointerException e) { - PlotSquared.log( - "NullPointer during purge detected. This is likely because you are " - + "deleting a world that has been removed."); - if (Settings.DEBUG) { - e.printStackTrace(); - } + logger.error("NullPointer during purge detected. This is likely" + + " because you are deleting a world that has been removed", e); } } cleared.set(true); diff --git a/Core/src/main/java/com/plotsquared/core/command/Trim.java b/Core/src/main/java/com/plotsquared/core/command/Trim.java index ad5e5c0fe..0702c7c08 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -42,6 +42,8 @@ import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -62,6 +64,7 @@ import java.util.Set; category = CommandCategory.ADMINISTRATION) public class Trim extends SubCommand { + private static final Logger logger = LoggerFactory.getLogger(Trim.class); public static ArrayList expired = null; private static volatile boolean TASK = false; @@ -179,14 +182,15 @@ public class Trim extends SubCommand { @Override public void run(Set viable, final Set nonViable) { Runnable regenTask; if (regen) { - PlotSquared.log("Starting regen task:"); - PlotSquared.log(" - This is a VERY slow command"); - PlotSquared.log(" - It will say `Trim done!` when complete"); + logger.info("Starting regen task"); + logger.info(" - This is a VERY slow command"); + logger.info(" - It will say 'Trim done!' when complete"); regenTask = new Runnable() { @Override public void run() { if (nonViable.isEmpty()) { Trim.TASK = false; player.sendMessage("Trim done!"); + logger.info("Trim done!"); return; } Iterator iterator = nonViable.iterator(); diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index 80ae1deb4..d6e13a278 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -44,6 +44,8 @@ import com.plotsquared.core.util.Permissions; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.world.item.ItemTypes; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -57,6 +59,8 @@ import java.util.stream.Collectors; public class ComponentPresetManager { + private static final Logger logger = LoggerFactory.getLogger(ComponentPresetManager.class); + private final List presets; private final String guiName; @@ -70,7 +74,7 @@ public class ComponentPresetManager { e.printStackTrace(); } if (!created) { - PlotSquared.log(Captions.PREFIX + "Failed to create components.yml"); + logger.error("Failed to create components.yml"); this.guiName = "&cInvalid!"; this.presets = new ArrayList<>(); return; @@ -86,8 +90,7 @@ public class ComponentPresetManager { try { yamlConfiguration.save(file); } catch (IOException e) { - PlotSquared.log(Captions.PREFIX + "Failed to save default values to components.yml"); - e.printStackTrace(); + logger.error("Failed to save default values to components.yml", e); } } this.guiName = yamlConfiguration.getString("title", "&6Plot Components"); @@ -105,8 +108,7 @@ public class ComponentPresetManager { try { yamlConfiguration.save(file); } catch (final IOException e) { - PlotSquared.log(Captions.PREFIX + "Failed to save default values to components.yml"); - e.printStackTrace(); + logger.error("Failed to save default values to components.yml", e); } this.presets = defaultPreset; } diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index 6bb62e965..bab4ea1a5 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -27,7 +27,6 @@ package com.plotsquared.core.database; import com.google.common.base.Charsets; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; @@ -48,6 +47,8 @@ import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -79,6 +80,8 @@ import java.util.concurrent.atomic.AtomicInteger; @SuppressWarnings("SqlDialectInspection") public class SQLManager implements AbstractDB { + private static final Logger logger = LoggerFactory.getLogger(SQLManager.class); + // Public final public final String SET_OWNER; public final String GET_ALL_PLOTS; @@ -355,11 +358,12 @@ public class SQLManager implements AbstractDB { try { task.run(); } catch (Throwable e) { - PlotSquared.debug("============ DATABASE ERROR ============"); - PlotSquared.debug("There was an error updating the database."); - PlotSquared.debug(" - It will be corrected on shutdown"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("There was an error updating the database."); + logger.debug(" - It will be corrected on shutdown"); e.printStackTrace(); - PlotSquared.debug("========================================"); + logger.debug("========================================"); } } commit(); @@ -409,12 +413,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - PlotSquared.debug("============ DATABASE ERROR ============"); - PlotSquared.debug("There was an error updating the database."); - PlotSquared.debug(" - It will be corrected on shutdown"); - PlotSquared.debug("========================================"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("There was an error updating the database."); + logger.debug(" - It will be corrected on shutdown"); + logger.debug("========================================"); e.printStackTrace(); - PlotSquared.debug("========================================"); + logger.debug("========================================"); } } if (statement != null && task != null) { @@ -454,12 +458,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - PlotSquared.debug("============ DATABASE ERROR ============"); - PlotSquared.debug("There was an error updating the database."); - PlotSquared.debug(" - It will be corrected on shutdown"); - PlotSquared.debug("========================================"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("There was an error updating the database."); + logger.debug(" - It will be corrected on shutdown"); + logger.debug("========================================"); e.printStackTrace(); - PlotSquared.debug("========================================"); + logger.debug("========================================"); } } if (statement != null && task != null) { @@ -500,12 +504,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - PlotSquared.debug("============ DATABASE ERROR ============"); - PlotSquared.debug("There was an error updating the database."); - PlotSquared.debug(" - It will be corrected on shutdown"); - PlotSquared.debug("========================================"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("There was an error updating the database."); + logger.debug(" - It will be corrected on shutdown"); + logger.debug("========================================"); e.printStackTrace(); - PlotSquared.debug("========================================"); + logger.debug("========================================"); } } if (statement != null && task != null) { @@ -529,12 +533,12 @@ public class SQLManager implements AbstractDB { this.plotTasks.clear(); } } catch (Throwable e) { - PlotSquared.debug("============ DATABASE ERROR ============"); - PlotSquared.debug("There was an error updating the database."); - PlotSquared.debug(" - It will be corrected on shutdown"); - PlotSquared.debug("========================================"); + logger.debug("============ DATABASE ERROR ============"); + logger.debug("There was an error updating the database."); + logger.debug(" - It will be corrected on shutdown"); + logger.debug("========================================"); e.printStackTrace(); - PlotSquared.debug("========================================"); + logger.debug("========================================"); } return false; } @@ -633,8 +637,7 @@ public class SQLManager implements AbstractDB { } }); } catch (Exception e) { - e.printStackTrace(); - PlotSquared.debug("&7[WARN] Failed to set all helpers for plots"); + logger.debug("Warning! Failed to set all helper for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -703,21 +706,15 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() - + "Failed to store flag values for plot with entry ID: " + plot.getId()); - e.printStackTrace(); + logger.error("Failed to store flag values for plot with entry ID: {}", e); continue; } - PlotSquared.debug(Captions.PREFIX.getTranslated() - + "- Finished converting flags for plot with entry ID: " + plot.getId()); + logger.debug("- Finished converting flag values for plot with entry ID: {}", plot.getId()); } } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values:"); - e.printStackTrace(); + logger.error("Failed to store flag values", e); } - PlotSquared.log( - Captions.PREFIX.getTranslated() + "Finished converting flags (" + plots.size() - + " plots processed)"); + logger.info("Finished converting flags ({} plots processed)", plots.size()); whenDone.run(); } @@ -825,8 +822,7 @@ public class SQLManager implements AbstractDB { last = subList.size(); preparedStmt.addBatch(); } - PlotSquared.debug( - "&aBatch 1: " + count + " | " + objList.get(0).getClass().getCanonicalName()); + logger.debug("Batch 1: {} | {}", count, objList.get(0).getClass().getCanonicalName()); preparedStmt.executeBatch(); preparedStmt.clearParameters(); preparedStmt.close(); @@ -836,8 +832,8 @@ public class SQLManager implements AbstractDB { return; } catch (SQLException e) { if (this.mySQL) { + logger.error("1: | {}", objList.get(0).getClass().getCanonicalName()); e.printStackTrace(); - PlotSquared.debug("&cERROR 1: | " + objList.get(0).getClass().getCanonicalName()); } } try { @@ -869,26 +865,25 @@ public class SQLManager implements AbstractDB { last = subList.size(); preparedStmt.addBatch(); } - PlotSquared.debug( - "&aBatch 2: " + count + " | " + objList.get(0).getClass().getCanonicalName()); + logger.debug("Batch 2: {} | {}", count, objList.get(0).getClass().getCanonicalName()); preparedStmt.executeBatch(); preparedStmt.clearParameters(); preparedStmt.close(); } catch (SQLException e) { e.printStackTrace(); - PlotSquared.debug("&cERROR 2: | " + objList.get(0).getClass().getCanonicalName()); - PlotSquared.debug("&6[WARN] Could not bulk save!"); + logger.error("2: | {}", objList.get(0).getClass().getCanonicalName()); + logger.error("Could not bulk save!"); try (PreparedStatement preparedStmt = this.connection .prepareStatement(mod.getCreateSQL())) { for (T obj : objList) { mod.setSQL(preparedStmt, obj); preparedStmt.addBatch(); } - PlotSquared.debug("&aBatch 3"); + logger.debug("Batch 3"); preparedStmt.executeBatch(); } catch (SQLException e3) { + logger.error("Failed to save all", e); e3.printStackTrace(); - PlotSquared.debug("&c[ERROR] Failed to save all!"); } } if (whenDone != null) { @@ -939,9 +934,7 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() - + "Failed to store settings values for plot with entry ID: " - + legacySettings.id); + logger.error("Failed to store settings for plot with entry ID: {}", legacySettings.id); e.printStackTrace(); continue; } @@ -953,18 +946,13 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - PlotSquared - .log(Captions.PREFIX.getTranslated() + "Failed to store settings values"); - e.printStackTrace(); + logger.error("Failed to store settings", e); } } } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store settings values:"); - e.printStackTrace(); + logger.error("Failed to store settings", e); } - PlotSquared.log( - Captions.PREFIX.getTranslated() + "Finished converting settings (" + myList.size() - + " plots processed)"); + logger.info("Finished converting settihgs ({} plots processed)", myList.size()); whenDone.run(); } @@ -1143,7 +1131,7 @@ public class SQLManager implements AbstractDB { return; } boolean addConstraint = create == tables.length; - PlotSquared.debug("Creating tables"); + logger.debug("Creating tables"); try (Statement stmt = this.connection.createStatement()) { if (this.mySQL) { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" @@ -1383,9 +1371,8 @@ public class SQLManager implements AbstractDB { * @param plot */ @Override public void delete(final Plot plot) { - PlotSquared.debug( - "Deleting plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " - + plot.getOwnerAbs() + " Index: " + plot.temp); + logger.debug("Deleting plot. ID: {} | World: {} | Owner: {} | Index: {}", + plot.getId(), plot.getWorldName(), plot.getOwnerAbs(), plot.temp); deleteSettings(plot); deleteDenied(plot); deleteHelpers(plot); @@ -1411,9 +1398,8 @@ public class SQLManager implements AbstractDB { * @param plot */ @Override public void createPlotSettings(final int id, Plot plot) { - PlotSquared.debug( - "Creating plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " - + plot.getOwnerAbs() + " Index: " + id); + logger.debug("Creating plot plot. ID: {} | World: {} | Owner: {} | Index: {}", + plot.getId(), plot.getWorldName(), plot.getOwnerAbs(), plot.temp); addPlotTask(plot, new UniqueStatement("createPlotSettings") { @Override public void set(PreparedStatement statement) throws SQLException { statement.setInt(1, id); @@ -1571,7 +1557,7 @@ public class SQLManager implements AbstractDB { "SELECT plot_plot_id, user_uuid, COUNT(*) FROM " + this.prefix + table + " GROUP BY plot_plot_id, user_uuid HAVING COUNT(*) > 1"); if (result.next()) { - PlotSquared.debug("BACKING UP: " + this.prefix + table); + logger.debug("Backing up {}", this.prefix + table); result.close(); statement.executeUpdate( "CREATE TABLE " + this.prefix + table + "_tmp AS SELECT * FROM " @@ -1581,7 +1567,7 @@ public class SQLManager implements AbstractDB { "CREATE TABLE " + this.prefix + table + " AS SELECT * FROM " + this.prefix + table + "_tmp"); statement.executeUpdate("DROP TABLE " + this.prefix + table + "_tmp"); - PlotSquared.debug("RESTORING: " + this.prefix + table); + logger.debug("Restoring {}", this.prefix + table); } } } catch (SQLException e2) { @@ -1645,40 +1631,20 @@ public class SQLManager implements AbstractDB { try { String flag_str = split[1].replaceAll("¯", ":").replaceAll("\u00B4", ","); - /*PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(split[0]); - if (flag == null) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Flag not found and therefore ignored: " + split[0]); - continue; - }*/ flagMap.get(id).put(split[0], flag_str); } catch (Exception e) { e.printStackTrace(); } - } /*else { - element = element.replaceAll("\u00AF", ":").replaceAll("\u00B4", ","); - if (StringMan - .isAlpha(element.replaceAll("_", "").replaceAll("-", ""))) { - PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(element); - if (flag == null) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Flag not found and therefore ignored: " + element); - } - } else { - PlotSquared.log(Captions.PREFIX.getTranslated() + "INVALID FLAG: " + element); - } - }*/ + } } } } } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to load old flag values:"); - e.printStackTrace(); + logger.error("Failed to load old flag values", e); return false; } - PlotSquared.log(Captions.PREFIX.getTranslated() + "Loaded " + flagMap.size() - + " plot flag collections..."); - PlotSquared.log(Captions.PREFIX.getTranslated() - + "Attempting to store these flags in the new table..."); - // + logger.info("Loaded {} plot flag collections...", flagMap.size()); + logger.info("Attempting to store these flags in the new table..."); try (final PreparedStatement preparedStatement = this.connection.prepareStatement( "INSERT INTO `" + SQLManager.this.prefix + "plot_flags`(`plot_id`, `flag`, `value`) VALUES(?, ?, ?)")) { @@ -1706,9 +1672,7 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() - + "Failed to store flag values for plot with entry ID: " + plotFlagEntry - .getKey()); + logger.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey()); e.printStackTrace(); continue; } @@ -1716,19 +1680,14 @@ public class SQLManager implements AbstractDB { if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap .size()) { timeStarted = System.currentTimeMillis(); - PlotSquared.log( - Captions.PREFIX.getTranslated() + "... Flag conversion in progress. " - + String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100) - + "% Done"); + logger.info("... Flag conversion in progress. {}% done", + String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100)); } - PlotSquared.debug(Captions.PREFIX.getTranslated() - + "- Finished converting flags for plot with entry ID: " + plotFlagEntry - .getKey()); + logger.debug("- Finished converting flags for plot with entry ID: {}", plotFlagEntry.getKey()); } } catch (final Exception e) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "Failed to store flag values:"); - e.printStackTrace(); + logger.error("Failed to store flag values", e); return false; } return true; @@ -1820,9 +1779,8 @@ public class SQLManager implements AbstractDB { time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(parsable) .getTime(); } catch (ParseException e) { - PlotSquared.debug( - "Could not parse date for plot: #" + id + "(" + areaID + ";" - + plot_id + ") (" + parsable + ")"); + logger.error("Could not parse date for plot: #{}({};{}) ({})", + id, areaID, plot_id, parsable); time = System.currentTimeMillis() + id; } } @@ -1836,9 +1794,8 @@ public class SQLManager implements AbstractDB { if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(last.temp); } else { - PlotSquared.debug( - "&cPLOT #" + id + "(" + last + ") in `" + this.prefix - + "plot` is a duplicate. Delete this plot or set `database-purger: true` in the settings.yml."); + logger.debug("Plot #{}({}) in `{}plot` is a duplicate." + + " Delete this plot or set `database-purger: true` in the settings.yml", id, last, this.prefix); } } } else { @@ -1869,9 +1826,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cENTRY #" + id + "(" + plot - + ") in `plot_rating` does not exist. Create this plot or set `database-purger: true` in the " - + "settings.yml."); + logger.debug("Entry #{}({}) in `plot_rating` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } deleteRows(toDelete, this.prefix + "plot_rating", "plot_plot_id"); @@ -1898,9 +1854,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cENTRY #" + id + "(" + plot - + ") in `plot_helpers` does not exist. Create this plot or set `database-purger: true` in the settings" - + ".yml."); + logger.debug("Entry #{}({}) in `plot_helpers` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } deleteRows(toDelete, this.prefix + "plot_helpers", "plot_plot_id"); @@ -1926,9 +1881,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cENTRY #" + id + "(" + plot - + ") in `plot_trusted` does not exist. Create this plot or set `database-purger: true` in the settings" - + ".yml."); + logger.debug("Entry #{}({}) in `plot_trusted` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } deleteRows(toDelete, this.prefix + "plot_trusted", "plot_plot_id"); @@ -1954,8 +1908,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cENTRY " + id - + " in `plot_denied` does not exist. Create this plot or set `database-purger: true` in the settings.yml."); + logger.debug("Entry #{}({}) in `plot_denied` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } deleteRows(toDelete, this.prefix + "plot_denied", "plot_plot_id"); @@ -1976,19 +1930,16 @@ public class SQLManager implements AbstractDB { final PlotFlag plotFlag = GlobalFlagContainer.getInstance().getFlagFromString(flag); if (plotFlag == null) { - PlotSquared.debug("Adding unknown flag to plot with ID " + id); + logger.debug("Adding unknown flag {} to plot with ID {}", flag, id); plot.getFlagContainer().addUnknownFlag(flag, value); } else { try { plot.getFlagContainer().addFlag(plotFlag.parse(value)); } catch (final FlagParseException e) { e.printStackTrace(); - PlotSquared - .debug("Plot with ID " + id + " has an invalid value:"); - PlotSquared.debug(Captions.FLAG_PARSE_ERROR.getTranslated() - .replace("%flag_name%", plotFlag.getName()) - .replace("%flag_value%", e.getValue()) - .replace("%error%", e.getErrorMessage())); + logger.debug("Plot with ID {} has an invalid value:", id); + logger.debug("Failed to parse flag '{}', value '{}': {}", + plotFlag.getName(), e.getValue(), e.getErrorMessage()); if (!invalidFlags.containsKey(plot)) { invalidFlags.put(plot, new ArrayList<>()); } @@ -1998,8 +1949,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cPlot " + id - + " in `plot_flags` does not exist. Create this plot or set `database-purger: true` in the settings.yml."); + logger.debug("Entry #{}({}) in `plot_flags` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } BlockTypeListFlag.skipCategoryVerification = @@ -2008,9 +1959,8 @@ public class SQLManager implements AbstractDB { for (final Map.Entry>> plotFlagEntry : invalidFlags .entrySet()) { for (final PlotFlag flag : plotFlagEntry.getValue()) { - PlotSquared.debug("&cPlot \"" + plotFlagEntry.getKey() + "\"" - + " had an invalid flag (" + flag.getName() - + "). A fix has been attempted."); + logger.debug("Plot {} has an invalid flag ({}). A fix has been attempted", + plotFlagEntry.getKey(), flag.getName()); removeFlag(plotFlagEntry.getKey(), flag); } } @@ -2052,9 +2002,8 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else { - PlotSquared.debug("&cENTRY #" + id + "(" + plot - + ") in `plot_settings` does not exist. Create this plot or set `database-purger: true` in the settings" - + ".yml."); + logger.debug("Entry #{}({}) in `plot_settings` does not exist." + + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } deleteRows(toDelete, this.prefix + "plot_settings", "plot_plot_id"); @@ -2070,16 +2019,14 @@ public class SQLManager implements AbstractDB { for (Entry entry : noExist.entrySet()) { String worldName = entry.getKey(); invalidPlot = true; - PlotSquared.debug("&c[WARNING] Found " + entry.getValue().intValue() - + " plots in DB for non existent world; '" + worldName + "'."); + logger.debug("Warning! Found {} plots in DB for non existent world: '{}'", + entry.getValue().intValue(), worldName); } if (invalidPlot) { - PlotSquared.debug( - "&c[WARNING] - Please create the world/s or remove the plots using the purge command"); + logger.debug("Warning! Please create the world(s) or remove the plots using the purge command"); } } catch (SQLException e) { - PlotSquared.debug("&7[WARN] Failed to load plots."); - e.printStackTrace(); + logger.error("Failed to load plots", e); } return newPlots; } @@ -2120,9 +2067,7 @@ public class SQLManager implements AbstractDB { preparedStatement.setInt(3, id2); preparedStatement.execute(); } catch (final Exception e) { - PlotSquared.log( - Captions.PREFIX.getTranslated() + "Failed to persist swap of " + plot1 + " and " - + plot2 + "!"); + logger.error("Failed to persist wap of {} and {}", plot1, plot2); e.printStackTrace(); future.complete(false); return; @@ -2221,7 +2166,7 @@ public class SQLManager implements AbstractDB { int last = -1; for (int j = 0; j <= amount; j++) { int purging = Math.max(j * packet, size); - PlotSquared.debug("Purging " + purging + " / " + size); + logger.debug("Purging {}/{}", purging, size); List subList = uniqueIdsList.subList(j * packet, Math.min(size, (j + 1) * packet)); if (subList.isEmpty()) { @@ -2267,12 +2212,11 @@ public class SQLManager implements AbstractDB { commit(); } } catch (SQLException e) { - e.printStackTrace(); - PlotSquared.debug("&c[ERROR] FAILED TO PURGE PLOTS!"); + logger.error("Failed to purge plots", e); return; } } - PlotSquared.debug("&6[INFO] SUCCESSFULLY PURGED " + uniqueIds.size() + " PLOTS!"); + logger.debug("Successfully purged {} plots", uniqueIds.size()); } }); } @@ -2295,8 +2239,8 @@ public class SQLManager implements AbstractDB { } purgeIds(ids); } catch (SQLException e) { + logger.error("Failed to purge area '{}'", area); e.printStackTrace(); - PlotSquared.debug("&c[ERROR] FAILED TO PURGE AREA '" + area + "'!"); } for (Iterator iterator = plots.iterator(); iterator.hasNext(); ) { PlotId plotId = iterator.next(); @@ -2774,8 +2718,8 @@ public class SQLManager implements AbstractDB { if (cluster != null) { cluster.helpers.add(user); } else { - PlotSquared.debug("&cCluster #" + id + "(" + cluster - + ") in cluster_helpers does not exist. Please create the cluster or remove this entry."); + logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + + " Please create the cluster or remove this entry", id, cluster); } } // Getting invited @@ -2793,8 +2737,8 @@ public class SQLManager implements AbstractDB { if (cluster != null) { cluster.invited.add(user); } else { - PlotSquared.debug("&cCluster #" + id + "(" + cluster - + ") in cluster_invited does not exist. Please create the cluster or remove this entry."); + logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + + " Please create the cluster or remove this entry", id, cluster); } } resultSet = @@ -2828,8 +2772,8 @@ public class SQLManager implements AbstractDB { } cluster.settings.setMerged(merged); } else { - PlotSquared.debug("&cCluster #" + id + "(" + cluster - + ") in cluster_settings does not exist. Please create the cluster or remove this entry."); + logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + + " Please create the cluster or remove this entry", id, cluster); } } resultSet.close(); @@ -2838,16 +2782,13 @@ public class SQLManager implements AbstractDB { for (Entry entry : noExist.entrySet()) { String a = entry.getKey(); invalidPlot = true; - PlotSquared.debug("&c[WARNING] Found " + noExist.get(a) - + " clusters in DB for non existent area; '" + a + "'."); + logger.debug("Warning! Found {} clusters in DB for non existent area; '{}'", noExist.get(a), a); } if (invalidPlot) { - PlotSquared.debug( - "&c[WARNING] - Please create the world/s or remove the clusters using the purge command"); + logger.debug("Warning! Please create the world(s) or remove the clusters using the purge command"); } } catch (SQLException e) { - PlotSquared.debug("&7[WARN] Failed to load clusters."); - e.printStackTrace(); + logger.error("Failed to load clusters", e); } return newClusters; } @@ -3039,8 +2980,7 @@ public class SQLManager implements AbstractDB { if (!isValid()) { reconnect(); } - PlotSquared.debug( - "$1All DB transactions during this session are being validated (This may take a while if corrections need to be made)"); + logger.debug("All DB transactions during this session are being validated (This may take a while if corrections need to be made)"); commit(); while (true) { if (!sendBatch()) { @@ -3061,31 +3001,30 @@ public class SQLManager implements AbstractDB { continue; } if (plot.getArea() == null) { - PlotSquared.debug("CRITICAL ERROR IN VALIDATION TASK!"); - PlotSquared.debug("PLOT AREA CANNOT BE NULL! SKIPPING PLOT!"); + logger.error("CRITICAL ERROR IN VALIDATION TASK!"); + logger.error("PLOT AREA CANNOT BE NULL! SKIPPING PLOT!"); continue; } if (database == null) { - PlotSquared.debug("CRITICAL ERROR IN VALIDATION TASK!"); - PlotSquared.debug("DATABASE VARIABLE CANNOT BE NULL! NOW ENDING VALIDATION!!"); + logger.error("CRITICAL ERROR IN VALIDATION TASK!"); + logger.error("DATABASE VARIABLE CANNOT BE NULL! NOW ENDING VALIDATION!"); break; } HashMap worldPlots = database.get(plot.getArea().toString()); if (worldPlots == null) { - PlotSquared.debug("&8 - &7Creating plot (1): " + plot); + logger.debug(" - Creating plot (1): {}", plot); toCreate.add(plot); continue; } Plot dataPlot = worldPlots.remove(plot.getId()); if (dataPlot == null) { - PlotSquared.debug("&8 - &7Creating plot (2): " + plot); + logger.debug(" - Creating plot (2): {}", plot); toCreate.add(plot); continue; } // owner if (!plot.getOwnerAbs().equals(dataPlot.getOwnerAbs())) { - PlotSquared.debug("&8 - &7Setting owner: " + plot + " -> " + MainUtil - .getName(plot.getOwnerAbs())); + logger.debug(" - Setting owner: {} -> {}", plot, MainUtil.getName(plot.getOwnerAbs())); setOwner(plot, plot.getOwnerAbs()); } // trusted @@ -3094,9 +3033,7 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getTrusted().clone(); toRemove.removeAll(plot.getTrusted()); toAdd.removeAll(dataPlot.getTrusted()); - PlotSquared.debug( - "&8 - &7Correcting " + (toAdd.size() + toRemove.size()) + " trusted for: " - + plot); + logger.debug(" - Correcting {} trusted for: {}", toAdd.size() + toRemove.size(), plot); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeTrusted(plot, uuid); @@ -3113,9 +3050,7 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getMembers().clone(); toRemove.removeAll(plot.getMembers()); toAdd.removeAll(dataPlot.getMembers()); - PlotSquared.debug( - "&8 - &7Correcting " + (toAdd.size() + toRemove.size()) + " members for: " - + plot); + logger.debug(" - Correcting {} members for: {}", toAdd.size() + toRemove.size()); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeMember(plot, uuid); @@ -3132,9 +3067,7 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getDenied().clone(); toRemove.removeAll(plot.getDenied()); toAdd.removeAll(dataPlot.getDenied()); - PlotSquared.debug( - "&8 - &7Correcting " + (toAdd.size() + toRemove.size()) + " denied for: " - + plot); + logger.debug(" - Correcting {} denied for: {}", toAdd.size() + toRemove.size()); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeDenied(plot, uuid); @@ -3149,7 +3082,7 @@ public class SQLManager implements AbstractDB { boolean[] pm = plot.getMerged(); boolean[] dm = dataPlot.getMerged(); if (pm[0] != dm[0] || pm[1] != dm[1]) { - PlotSquared.debug(" - Correcting merge for: " + plot); + logger.debug(" - Correcting merge for: {}", plot); setMerged(dataPlot, plot.getMerged()); } Set> pf = plot.getFlags(); @@ -3157,7 +3090,6 @@ public class SQLManager implements AbstractDB { if (!pf.isEmpty() && !df.isEmpty()) { if (pf.size() != df.size() || !StringMan .isEqual(StringMan.joinOrdered(pf, ","), StringMan.joinOrdered(df, ","))) { - PlotSquared.debug(" - Correcting flags for: " + plot); // setFlags(plot, pf); // TODO: Re-implement } @@ -3168,8 +3100,7 @@ public class SQLManager implements AbstractDB { HashMap map = entry.getValue(); if (!map.isEmpty()) { for (Entry entry2 : map.entrySet()) { - PlotSquared.debug("$1Plot was deleted: " + entry2.getValue().toString() - + "// TODO implement this when sure safe"); + // TODO implement this when sure safe" } } } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index 49a5c0da4..f4e92ced6 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -51,6 +51,8 @@ import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.lang.reflect.Field; @@ -59,7 +61,8 @@ import java.util.Locale; public class HybridPlotWorld extends ClassicPlotWorld { - private static AffineTransform transform = new AffineTransform().rotateY(90); + private static final Logger logger = LoggerFactory.getLogger(HybridPlotWorld.class); + private static final AffineTransform transform = new AffineTransform().rotateY(90); public boolean ROAD_SCHEMATIC_ENABLED; public boolean PLOT_SCHEMATIC = false; public int PLOT_SCHEMATIC_HEIGHT = -1; @@ -158,13 +161,12 @@ public class HybridPlotWorld extends ClassicPlotWorld { setupSchematics(); } catch (Exception event) { event.printStackTrace(); - PlotSquared.debug("&c - road schematics are disabled for this world."); + logger.debug("- road schematics are disabled for this world"); } // Dump world settings if (Settings.DEBUG) { - PlotSquared.debug(String.format("- Dumping settings for ClassicPlotWorld with name %s", - this.getWorldName())); + logger.debug("- Dumping settings for ClassicPlotWorld with name {}", this.getWorldName()); final Field[] fields = this.getClass().getFields(); for (final Field field : fields) { final String name = field.getName().toLowerCase(Locale.ENGLISH); @@ -180,7 +182,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } catch (final IllegalAccessException e) { value = String.format("Failed to parse: %s", e.getMessage()); } - PlotSquared.debug(String.format("-- %s = %s", name, value)); + logger.debug("-- {} = {}", name, value); } } } @@ -360,7 +362,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { int pair = MathMan.pair(x, z); BaseBlock[] existing = this.G_SCH.computeIfAbsent(pair, k -> new BaseBlock[height]); if (y >= height) { - PlotSquared.log("Error adding overlay block. `y > height` "); + logger.error("Error adding overlay block. `y > height`"); return; } existing[y] = id; diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java index 75ada359f..084e0a33b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -61,6 +61,8 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.util.ArrayDeque; @@ -76,6 +78,8 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class HybridUtils { + private static final Logger logger = LoggerFactory.getLogger(HybridUtils.class); + public static HybridUtils manager; public static Set regions; public static int height; @@ -409,23 +413,23 @@ public abstract class HybridUtils { iter.remove(); boolean regenedRoad = regenerateRoad(area, chunk, extend); if (!regenedRoad) { - PlotSquared.debug("Failed to regenerate roads."); + logger.debug("Failed to regenerate roads"); } ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true); } - PlotSquared.debug("Cancelled road task"); + logger.debug("Cancelled road task"); return; } count.incrementAndGet(); if (count.intValue() % 20 == 0) { - PlotSquared.debug("PROGRESS: " + 100 * (2048 - chunks.size()) / 2048 + "%"); + logger.info("Progress: {}%", 100 * (2048 - chunks.size()) / 2048); } if (HybridUtils.regions.isEmpty() && chunks.isEmpty()) { - PlotSquared.debug("Regenerating plot walls"); + logger.debug("Regenerating plot walls"); regeneratePlotWalls(area); HybridUtils.UPDATE = false; - PlotSquared.log("Finished road conversion"); + logger.info("Finished road conversion"); // CANCEL TASK } else { final Runnable task = this; @@ -437,11 +441,8 @@ public abstract class HybridUtils { HybridUtils.regions.iterator(); BlockVector2 loc = iterator.next(); iterator.remove(); - PlotSquared.debug( - "Updating .mcr: " + loc.getX() + ", " + loc.getZ() - + " (approx 1024 chunks)"); - PlotSquared - .debug(" - Remaining: " + HybridUtils.regions.size()); + logger.debug("Updating .mcr: {}, {} (approx 1024 chunks)", loc.getX(), loc.getZ()); + logger.debug("- Remaining: {}", HybridUtils.regions.size()); chunks.addAll(getChunks(loc)); System.gc(); } @@ -458,7 +459,7 @@ public abstract class HybridUtils { boolean regenedRoads = regenerateRoad(area, chunk, extend); if (!regenedRoads) { - PlotSquared.debug("Failed to regenerate road."); + logger.debug("Failed to regenerate road"); } } } @@ -469,9 +470,8 @@ public abstract class HybridUtils { Iterator iterator = HybridUtils.regions.iterator(); BlockVector2 loc = iterator.next(); iterator.remove(); - PlotSquared.debug( - "[ERROR] Could not update '" + area.getWorldName() + "/region/r." - + loc.getX() + "." + loc.getZ() + ".mca' (Corrupt chunk?)"); + logger.debug("Error! Could not update '{}/region/r.{}.{}.mca' (Corrupt chunk?)", + area.getWorldHash(), loc.getX(), loc.getZ()); int sx = loc.getX() << 5; int sz = loc.getZ() << 5; for (int x = sx; x < sx + 32; x++) { @@ -481,8 +481,7 @@ public abstract class HybridUtils { true); } } - PlotSquared.debug(" - Potentially skipping 1024 chunks"); - PlotSquared.debug(" - TODO: recommend chunkster if corrupt"); + logger.debug("- Potentially skipping 1024 chunks"); } GlobalBlockQueue.IMP.addEmptyTask(() -> TaskManager.runTaskLater(task, 20)); }); diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index 9a97800e7..970aad919 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -38,11 +38,14 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.UUID; public class ConsolePlayer extends PlotPlayer { + private static final Logger logger = LoggerFactory.getLogger(ConsolePlayer.class); private static ConsolePlayer instance; private ConsolePlayer() { @@ -108,7 +111,7 @@ public class ConsolePlayer extends PlotPlayer { } @Override public void sendMessage(String message) { - PlotSquared.log(message); + logger.info(message); } @Override public void teleport(Location location, TeleportCause cause) { diff --git a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java index d329a8e23..7fbdc4fd4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java +++ b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.util; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; @@ -33,6 +32,8 @@ import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.plot.BlockBucket; import com.sk89q.worldedit.world.block.BlockState; import lombok.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Collection; import java.util.HashMap; @@ -45,6 +46,7 @@ import java.util.Map; @SuppressWarnings("unused") public final class LegacyConverter { + private static final Logger logger = LoggerFactory.getLogger(LegacyConverter.class); public static final String CONFIGURATION_VERSION = "post_flattening"; private static final HashMap TYPE_MAP = new HashMap<>(); @@ -109,7 +111,7 @@ public final class LegacyConverter { @NonNull final String key, @NonNull final String block) { final BlockBucket bucket = this.blockToBucket(block); this.setString(section, key, bucket); - PlotSquared.log(CaptionUtility + logger.info(CaptionUtility .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), block, bucket.toString())); } @@ -119,7 +121,7 @@ public final class LegacyConverter { final BlockState[] blocks = this.splitBlockList(blockList); final BlockBucket bucket = this.blockListToBucket(blocks); this.setString(section, key, bucket); - PlotSquared.log(CaptionUtility + logger.info(CaptionUtility .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), plotBlockArrayString(blocks), bucket.toString())); } diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 9e2a78853..dbe3599d6 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -56,6 +56,8 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -97,6 +99,7 @@ import java.util.stream.IntStream; */ public class MainUtil { + private static final Logger logger = LoggerFactory.getLogger(MainUtil.class); private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); static { @@ -516,11 +519,11 @@ public class MainUtil { * @param message If a message should be sent to the player if a plot cannot be found * @return The plot if only 1 result is found, or null */ - @Nullable public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { + @Nullable public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { if (arg == null) { if (player == null) { if (message) { - PlotSquared.log(Captions.NOT_VALID_PLOT_WORLD); + logger.info("No plot area string was supplied"); } return null; } @@ -643,7 +646,7 @@ public class MainUtil { if (player == null) { String message = CaptionUtility .format(null, (prefix ? Captions.PREFIX.getTranslated() : "") + msg); - PlotSquared.log(message); + logger.info(message); } else { player.sendMessage(CaptionUtility.format(player, (prefix ? Captions.PREFIX.getTranslated() : "") + Captions.color(msg))); @@ -678,7 +681,7 @@ public class MainUtil { TaskManager.runTaskAsync(() -> { String m = CaptionUtility.format(player, caption, args); if (player == null) { - PlotSquared.log(m); + logger.info(m); } else { player.sendMessage(m); } diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index ab3333a19..238f8345b 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -36,6 +36,8 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.util.Collection; @@ -44,6 +46,8 @@ import java.util.Set; public abstract class RegionManager { + private static final Logger logger = LoggerFactory.getLogger(RegionManager.class); + public static RegionManager manager = null; public static BlockVector2 getRegion(Location location) { @@ -141,7 +145,7 @@ public abstract class RegionManager { world + File.separator + "region" + File.separator + "r." + loc.getX() + "." + loc.getZ() + ".mca"; File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); - PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + logger.info("- Deleting file: {} (max 1024 chunks)", file.getName()); if (file.exists()) { file.delete(); } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java index 997cdfdc1..fc03f7326 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -33,6 +33,8 @@ import com.plotsquared.core.util.ThreadUtils; import com.plotsquared.core.util.task.TaskManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; @@ -62,6 +64,8 @@ import java.util.function.Function; */ public class UUIDPipeline { + private static final Logger logger = LoggerFactory.getLogger(UUIDPipeline.class); + private final Executor executor; private final List serviceList; private final List>> consumerList; @@ -164,7 +168,7 @@ public class UUIDPipeline { } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException ignored) { - PlotSquared.log(Captions.PREFIX + " (UUID) Request for " + username + " timed out"); + logger.warn("(UUID) Request for {} timed out", username); // This is completely valid, we just don't care anymore } return null; @@ -187,7 +191,7 @@ public class UUIDPipeline { } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException ignored) { - PlotSquared.log(Captions.PREFIX + " (UUID) Request for " + uuid + " timed out"); + logger.warn("(UUID) Request for {} timed out", uuid); // This is completely valid, we just don't care anymore } return null; @@ -321,7 +325,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - PlotSquared.log("Failed to find all usernames"); + logger.debug("Failed to find all usernames"); } if (Settings.UUID.UNKNOWN_AS_DEFAULT) { @@ -384,7 +388,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - PlotSquared.log("Failed to find all UUIDs"); + logger.debug("Failed to find all UUIDs"); } throw new ServiceError("End of pipeline"); From d76c9dad5215a120d5802a5faae4a52a0cf86d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 7 Jul 2020 12:56:43 +0200 Subject: [PATCH 04/35] Remove access to PlotSquared#IMP and rename IPlotMain to PlotPlatform, then rename PlotSquared#imp() to PlotSquared#platform() --- .../{BukkitMain.java => BukkitPlatform.java} | 18 +-- .../bukkit/entity/TeleportEntityWrapper.java | 6 +- .../generator/DelegatePlotGenerator.java | 2 +- .../bukkit/listener/ChunkListener.java | 2 +- .../bukkit/listener/EntitySpawnListener.java | 4 +- .../bukkit/listener/PlayerEvents.java | 20 +-- .../bukkit/placeholder/Placeholders.java | 2 +- .../bukkit/player/BukkitPlayer.java | 2 +- .../bukkit/util/BukkitEconHandler.java | 4 +- .../bukkit/util/BukkitRegionManager.java | 4 +- .../bukkit/util/BukkitSetupUtils.java | 4 +- .../bukkit/util/BukkitTaskManager.java | 6 +- .../plotsquared/bukkit/util/BukkitUtil.java | 10 +- .../com/plotsquared/bukkit/util/SetGenCB.java | 2 +- .../bukkit/uuid/SQLiteUUIDService.java | 2 +- Bukkit/src/main/resources/plugin.yml | 2 +- .../{IPlotMain.java => PlotPlatform.java} | 2 +- .../com/plotsquared/core/PlotSquared.java | 116 +++++++++--------- .../core/backup/BackupManager.java | 2 +- .../core/backup/NullBackupManager.java | 2 +- .../core/backup/SimpleBackupManager.java | 2 +- .../com/plotsquared/core/command/Area.java | 20 +-- .../com/plotsquared/core/command/Backup.java | 8 +- .../com/plotsquared/core/command/Buy.java | 4 +- .../com/plotsquared/core/command/Cluster.java | 4 +- .../com/plotsquared/core/command/Comment.java | 2 +- .../core/command/DatabaseCommand.java | 8 +- .../plotsquared/core/command/DebugExec.java | 12 +- .../core/command/DebugImportWorlds.java | 2 +- .../plotsquared/core/command/DebugPaste.java | 8 +- .../com/plotsquared/core/command/Deny.java | 2 +- .../com/plotsquared/core/command/Grant.java | 2 +- .../com/plotsquared/core/command/Kick.java | 2 +- .../com/plotsquared/core/command/ListCmd.java | 4 +- .../com/plotsquared/core/command/Merge.java | 4 +- .../com/plotsquared/core/command/Owner.java | 2 +- .../plotsquared/core/command/PluginCmd.java | 2 +- .../com/plotsquared/core/command/Setup.java | 2 +- .../plotsquared/core/command/Template.java | 10 +- .../com/plotsquared/core/command/Trim.java | 2 +- .../components/ComponentPresetManager.java | 2 +- .../com/plotsquared/core/database/SQLite.java | 4 +- .../plotsquared/core/generator/HybridGen.java | 2 +- .../core/generator/HybridPlotManager.java | 6 +- .../core/generator/HybridPlotWorld.java | 4 +- .../generator/IndependentPlotGenerator.java | 3 +- .../core/listener/PlotListener.java | 4 +- .../core/player/ConsolePlayer.java | 2 +- .../plotsquared/core/player/PlotPlayer.java | 6 +- .../java/com/plotsquared/core/plot/Plot.java | 8 +- .../core/plot/expiration/ExpireManager.java | 10 +- .../core/plot/message/PlotMessage.java | 4 +- .../core/plot/world/SinglePlotArea.java | 2 +- .../core/plot/world/SinglePlotManager.java | 2 +- .../core/queue/LocalBlockQueue.java | 2 +- .../core/setup/CommonSetupSteps.java | 8 +- .../core/setup/PlotAreaBuilder.java | 2 +- .../plotsquared/core/util/EconHandler.java | 14 +-- .../com/plotsquared/core/util/MainUtil.java | 2 +- .../plotsquared/core/util/RegionManager.java | 4 +- .../core/util/SchematicHandler.java | 10 +- .../plotsquared/core/util/TabCompletions.java | 2 +- .../com/plotsquared/core/util/WorldUtil.java | 4 +- 63 files changed, 211 insertions(+), 210 deletions(-) rename Bukkit/src/main/java/com/plotsquared/bukkit/{BukkitMain.java => BukkitPlatform.java} (98%) rename Core/src/main/java/com/plotsquared/core/{IPlotMain.java => PlotPlatform.java} (99%) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java similarity index 98% rename from Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java rename to Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 39a763d24..7e4b9605d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -59,7 +59,7 @@ import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService; import com.plotsquared.bukkit.uuid.PaperUUIDService; import com.plotsquared.bukkit.uuid.SQLiteUUIDService; import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService; -import com.plotsquared.core.IPlotMain; +import com.plotsquared.core.PlotPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.backup.NullBackupManager; @@ -159,7 +159,7 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID; import static com.plotsquared.core.util.PremiumVerification.getUserID; import static com.plotsquared.core.util.ReflectionUtils.getRefClass; -public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { +public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform { private static final int BSTATS_ID = 1404; @Getter private static WorldEdit worldEdit; @@ -214,7 +214,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< new PlotSquared(this, "Bukkit"); - if (PlotSquared.get().IMP.getServerVersion()[1] < 13) { + if (PlotSquared.platform().getServerVersion()[1] < 13) { System.out.println( "You can't use this version of PlotSquared on a server less than Minecraft 1.13.2."); System.out @@ -267,7 +267,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final SQLiteUUIDService legacyUUIDService; if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil - .getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db").exists()) { + .getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) { legacyUUIDService = new SQLiteUUIDService("usercache.db"); } else { legacyUUIDService = null; @@ -758,7 +758,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< if (currentPlotId != null) { entity.setMetadata("shulkerPlot", new FixedMetadataValue( - (Plugin) PlotSquared.get().IMP, currentPlotId)); + (Plugin) PlotSquared.platform(), currentPlotId)); } } } @@ -884,7 +884,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< if (id != null && id.equalsIgnoreCase("single")) { result = new SingleWorldGenerator(); } else { - result = PlotSquared.get().IMP.getDefaultGenerator(); + result = PlotSquared.platform().getDefaultGenerator(); if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) { return null; } @@ -983,7 +983,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } return new BukkitPlotGenerator(world, gen); } else { - return new BukkitPlotGenerator(world, PlotSquared.get().IMP.getDefaultGenerator()); + return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator()); } } @@ -1118,11 +1118,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return BukkitUtil.getPlayer((OfflinePlayer) player); } if (player instanceof String) { - return (PlotPlayer) PlotSquared.imp().getPlayerManager() + return (PlotPlayer) PlotSquared.platform().getPlayerManager() .getPlayerIfExists((String) player); } if (player instanceof UUID) { - return (PlotPlayer) PlotSquared.imp().getPlayerManager() + return (PlotPlayer) PlotSquared.platform().getPlayerManager() .getPlayerIfExists((UUID) player); } return null; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java index 45613a751..6a37571a3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java @@ -25,7 +25,7 @@ */ package com.plotsquared.bukkit.entity; -import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.BukkitPlatform; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -53,7 +53,7 @@ public class TeleportEntityWrapper extends EntityWrapper { getEntity().setInvulnerable(invulnerableOld); getEntity().setFireTicks(fireTicksOld); getEntity().setTicksLived(livingTicksOld); - getEntity().removeMetadata("ps-tmp-teleport", BukkitMain.getPlugin(BukkitMain.class)); + getEntity().removeMetadata("ps-tmp-teleport", BukkitPlatform.getPlugin(BukkitPlatform.class)); } return getEntity(); } @@ -78,7 +78,7 @@ public class TeleportEntityWrapper extends EntityWrapper { this.fireTicksOld = this.getEntity().getFireTicks(); this.livingTicksOld = this.getEntity().getTicksLived(); this.getEntity().setMetadata("ps-tmp-teleport", - new FixedMetadataValue(BukkitMain.getPlugin(BukkitMain.class), oldLocation)); + new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation)); final Chunk newChunk = getNewChunk(); this.getEntity().teleport( new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4)); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java index d5086b06d..bb6a46041 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java @@ -61,7 +61,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator { } @Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { - return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max); + return PlotSquared.platform().getDefaultGenerator().getNewPlotArea(world, id, min, max); } @Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index 1cfc897d4..19a892c43 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -73,7 +73,7 @@ public class ChunkListener implements Listener { this.mustSave = classChunk.getField("mustSave"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); } catch (Throwable ignored) { - PlotSquared.debug(PlotSquared.get().IMP.getPluginName() + PlotSquared.debug(PlotSquared.platform().getPluginName() + "/Server not compatible for chunk processor trim/gc"); Settings.Chunk_Processor.AUTO_TRIM = false; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index 0bf5e75e8..8b70143b1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -92,7 +92,7 @@ public class EntitySpawnListener implements Listener { if (meta.isEmpty()) { if (PlotSquared.get().hasPlotArea(world.getName())) { entity.setMetadata(KEY, - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation())); + new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation())); } } else { org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value(); @@ -161,7 +161,7 @@ public class EntitySpawnListener implements Listener { case SHULKER: if (!entity.hasMetadata("shulkerPlot")) { entity.setMetadata("shulkerPlot", - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot.getId())); + new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId())); } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index c8c16a4c6..b10370cfc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -253,7 +253,7 @@ public class PlayerEvents extends PlotListener implements Listener { int z = bloc.getBlockZ(); int distance = Bukkit.getViewDistance() * 16; - for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { Location location = player.getLocation(); if (location.getWorld().equals(world)) { if (16 * Math.abs(location.getX() - x) / 16 > distance @@ -355,18 +355,18 @@ public class PlayerEvents extends PlotListener implements Listener { if (plot.isMerged()) { disable = true; for (UUID owner : plot.getOwners()) { - if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner) != null) { disable = false; break; } } } else { - disable = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()) == null; + disable = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()) == null; } } if (disable) { for (UUID trusted : plot.getTrusted()) { - if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted) != null) { disable = false; break; } @@ -379,7 +379,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } if (Settings.Redstone.DISABLE_UNOCCUPIED) { - for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { if (plot.equals(player.getCurrentPlot())) { return; } @@ -794,7 +794,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } else if (toPlot != null) { vehicle.setMetadata("plot", - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot)); + new FixedMetadataValue((Plugin) PlotSquared.platform(), toPlot)); } } } @@ -960,7 +960,7 @@ public class PlayerEvents extends PlotListener implements Listener { Set recipients = event.getRecipients(); recipients.clear(); Set spies = new HashSet<>(); - for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { if (pp.getAttribute("chatspy")) { spies.add(((BukkitPlayer) pp).player); } else { @@ -1092,7 +1092,7 @@ public class PlayerEvents extends PlotListener implements Listener { .equals(EntityType.MINECART_TNT)) { if (!near.hasMetadata("plot")) { near.setMetadata("plot", - new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } } @@ -2185,7 +2185,7 @@ public class PlayerEvents extends PlotListener implements Listener { } } else if (event.getTo() == Material.AIR) { event.getEntity() - .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } @@ -2426,7 +2426,7 @@ public class PlayerEvents extends PlotListener implements Listener { } if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) { entity - .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot)); + .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot)); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java index 5457dbe0f..b0f428e8b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java @@ -65,7 +65,7 @@ public class Placeholders extends PlaceholderExpansion { } @Override public String onPlaceholderRequest(Player p, String identifier) { - final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId()); + final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId()); if (pl == null) { return ""; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 643039600..6f7284e5a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -143,7 +143,7 @@ public class BukkitPlayer extends PlotPlayer { private void callEvent(@NotNull final Event event) { final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); for (final RegisteredListener listener : listeners) { - if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) { + if (listener.getPlugin().getName().equals(PlotSquared.platform().getPluginName())) { continue; } try { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index e71c48158..60f574357 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -83,8 +83,8 @@ public class BukkitEconHandler extends EconHandler { * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead */ @Deprecated @Override public boolean hasPermission(String world, String player, String perm) { - if (PlotSquared.imp().getPermissionHandler() != null) { - return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm); + if (PlotSquared.platform().getPermissionHandler() != null) { + return PlotSquared.platform().getPermissionHandler().hasPermission(world, player, perm); } else { return false; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java index fc71c9d31..0f32ba37a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -25,7 +25,7 @@ */ package com.plotsquared.bukkit.util; -import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.location.Location; @@ -94,7 +94,7 @@ public class BukkitRegionManager extends RegionManager { PlotSquared.debug("Attempting to make an asynchronous call to getLoadedChunks." + " Will halt the calling thread until completed."); semaphore.acquire(); - Bukkit.getScheduler().runTask(BukkitMain.getPlugin(BukkitMain.class), () -> { + Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> { for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)) .getLoadedChunks()) { BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index 53185b608..b79e82250 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -200,7 +200,7 @@ public class BukkitSetupUtils extends SetupUtils { e.printStackTrace(); } - Objects.requireNonNull(PlotSquared.imp()).getWorldManager() + Objects.requireNonNull(PlotSquared.platform()).getWorldManager() .handleWorldCreation(object.world, object.setupGenerator); if (Bukkit.getWorld(world) != null) { @@ -313,7 +313,7 @@ public class BukkitSetupUtils extends SetupUtils { e.printStackTrace(); } - Objects.requireNonNull(PlotSquared.imp()).getWorldManager() + Objects.requireNonNull(PlotSquared.platform()).getWorldManager() .handleWorldCreation(builder.worldName(), builder.generatorName()); if (Bukkit.getWorld(world) != null) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java index b797708f2..cf85fa92c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java @@ -25,15 +25,15 @@ */ package com.plotsquared.bukkit.util; -import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.core.util.task.TaskManager; import org.bukkit.Bukkit; public class BukkitTaskManager extends TaskManager { - private final BukkitMain bukkitMain; + private final BukkitPlatform bukkitMain; - public BukkitTaskManager(BukkitMain bukkitMain) { + public BukkitTaskManager(BukkitPlatform bukkitMain) { this.bukkitMain = bukkitMain; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 5acdde298..6c35a542f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -25,7 +25,7 @@ */ package com.plotsquared.bukkit.util; -import com.plotsquared.bukkit.BukkitMain; +import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayerManager; import com.plotsquared.core.PlotSquared; @@ -120,7 +120,7 @@ public class BukkitUtil extends WorldUtil { lastPlayer = null; lastPlotPlayer = null; // Make sure that it's removed internally - PlotSquared.imp().getPlayerManager().removePlayer(uuid); + PlotSquared.platform().getPlayerManager().removePlayer(uuid); } public static PlotPlayer getPlayer(@NonNull final OfflinePlayer op) { @@ -271,7 +271,7 @@ public class BukkitUtil extends WorldUtil { if (player == lastPlayer) { return lastPlotPlayer; } - final PlayerManager playerManager = PlotSquared.imp().getPlayerManager(); + final PlayerManager playerManager = PlotSquared.platform().getPlayerManager(); return ((BukkitPlayerManager) playerManager).getPlayer(player); } @@ -458,7 +458,7 @@ public class BukkitUtil extends WorldUtil { } else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) { facing = BlockFace.SOUTH; } - if (PlotSquared.get().IMP.getServerVersion()[1] == 13) { + if (PlotSquared.platform().getServerVersion()[1] == 13) { block.setType(Material.valueOf("WALL_SIGN"), false); } else { block.setType(Material.valueOf("OAK_WALL_SIGN"), false); @@ -688,7 +688,7 @@ public class BukkitUtil extends WorldUtil { consumer.accept(value); } else { Bukkit.getScheduler() - .runTask(BukkitMain.getPlugin(BukkitMain.class), () -> consumer.accept(value)); + .runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value)); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SetGenCB.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SetGenCB.java index bd77fe27d..f7c588bf4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SetGenCB.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SetGenCB.java @@ -72,6 +72,6 @@ public class SetGenCB { .removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator); } PlotSquared.get() - .loadWorld(world.getName(), PlotSquared.get().IMP.getGenerator(world.getName(), null)); + .loadWorld(world.getName(), PlotSquared.platform().getGenerator(world.getName(), null)); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java index 16b3abff5..730d6c010 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java @@ -51,7 +51,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer Player type */ -public interface IPlotMain

extends ILogger { +public interface PlotPlatform

extends ILogger { /** * Logs a message to console. diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 30d738afc..20a74ac94 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -137,11 +137,13 @@ import java.util.zip.ZipInputStream; * An implementation of the core, with a static getter for easy access. */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class PlotSquared { +public class PlotSquared

{ + private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); - private static PlotSquared instance; + private static PlotSquared instance; + // Implementation - public final IPlotMain IMP; + private final PlotPlatform

platform; // Current thread private final Thread thread; // UUID pipelines @@ -177,17 +179,17 @@ public class PlotSquared { /** * Initialize PlotSquared with the desired Implementation class. * - * @param iPlotMain Implementation of {@link IPlotMain} used + * @param iPlotMain Implementation of {@link PlotPlatform} used * @param platform The platform being used */ - public PlotSquared(final IPlotMain iPlotMain, final String platform) { + public PlotSquared(final PlotPlatform

iPlotMain, final String platform) { if (instance != null) { throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton"); } instance = this; this.thread = Thread.currentThread(); - this.IMP = iPlotMain; + this.platform = iPlotMain; this.logger = iPlotMain; Settings.PLATFORM = platform; @@ -197,7 +199,7 @@ public class PlotSquared { ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket"); try { - new ReflectionUtils(this.IMP.getNMSPackage()); + new ReflectionUtils(this.platform.getNMSPackage()); try { URL url = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation(); this.jarFile = new File( @@ -205,22 +207,22 @@ public class PlotSquared { .toURI().getPath()); } catch (MalformedURLException | URISyntaxException | SecurityException e) { e.printStackTrace(); - this.jarFile = new File(this.IMP.getDirectory().getParentFile(), "PlotSquared.jar"); + this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar"); if (!this.jarFile.exists()) { - this.jarFile = new File(this.IMP.getDirectory().getParentFile(), + this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared-" + platform + ".jar"); } } - TaskManager.IMP = this.IMP.getTaskManager(); + TaskManager.IMP = this.platform.getTaskManager(); // World Util. Has to be done before config files are loaded - WorldUtil.IMP = this.IMP.initWorldUtil(); + WorldUtil.IMP = this.platform.initWorldUtil(); if (!setupConfigs()) { return; } - this.translationFile = MainUtil.getFile(this.IMP.getDirectory(), - Settings.Paths.TRANSLATIONS + File.separator + IMP.getPluginName() + this.translationFile = MainUtil.getFile(this.platform.getDirectory(), + Settings.Paths.TRANSLATIONS + File.separator + this.platform.getPluginName() + ".use_THIS.yml"); Captions.load(this.translationFile); @@ -251,44 +253,44 @@ public class PlotSquared { // Kill entities if (Settings.Enabled_Components.KILL_ROAD_MOBS || Settings.Enabled_Components.KILL_ROAD_VEHICLES) { - this.IMP.runEntityTask(); + this.platform.runEntityTask(); } if (Settings.Enabled_Components.EVENTS) { - this.IMP.registerPlayerEvents(); + this.platform.registerPlayerEvents(); } // Required - this.IMP.registerWorldEvents(); + this.platform.registerWorldEvents(); if (Settings.Enabled_Components.CHUNK_PROCESSOR) { - this.IMP.registerChunkProcessor(); + this.platform.registerChunkProcessor(); } // Create Event utility class eventDispatcher = new EventDispatcher(); // create Hybrid utility class - HybridUtils.manager = this.IMP.initHybridUtils(); + HybridUtils.manager = this.platform.initHybridUtils(); // Inventory utility class - InventoryUtil.manager = this.IMP.initInventoryUtil(); + InventoryUtil.manager = this.platform.initInventoryUtil(); // create setup util class - SetupUtils.manager = this.IMP.initSetupUtils(); + SetupUtils.manager = this.platform.initSetupUtils(); // Set block GlobalBlockQueue.IMP = - new GlobalBlockQueue(IMP.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME); + new GlobalBlockQueue(this.platform.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME); GlobalBlockQueue.IMP.runTask(); // Set chunk - ChunkManager.manager = this.IMP.initChunkManager(); - RegionManager.manager = this.IMP.initRegionManager(); + ChunkManager.manager = this.platform.initChunkManager(); + RegionManager.manager = this.platform.initRegionManager(); // Schematic handler - SchematicHandler.manager = this.IMP.initSchematicHandler(); + SchematicHandler.manager = this.platform.initSchematicHandler(); // Chat - ChatManager.manager = this.IMP.initChatManager(); + ChatManager.manager = this.platform.initChatManager(); // Commands if (Settings.Enabled_Components.COMMANDS) { - this.IMP.registerCommands(); + this.platform.registerCommands(); } // WorldEdit if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { - if (this.IMP.initWorldEdit()) { - PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName() + if (this.platform.initWorldEdit()) { + PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName() + " hooked into WorldEdit."); this.worldedit = WorldEdit.getInstance(); WorldEdit.getInstance().getEventBus().register(new WESubscriber()); @@ -324,7 +326,7 @@ public class PlotSquared { continue; } if (WorldUtil.IMP.isWorld(world)) { - this.IMP.setGenerator(world); + this.platform.setGenerator(world); } } TaskManager.runTaskLater(() -> { @@ -333,7 +335,7 @@ public class PlotSquared { continue; } if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { - debug("`" + world + "` was not properly loaded - " + IMP.getPluginName() + debug("`" + world + "` was not properly loaded - " + this.platform.getPluginName() + " will now try to load it properly: "); debug( " - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); @@ -341,7 +343,7 @@ public class PlotSquared { " - Your world management plugin may be faulty (or non existent)"); debug( " This message may also be a false positive and could be ignored."); - PlotSquared.this.IMP.setGenerator(world); + PlotSquared.this.platform.setGenerator(world); } } }, 1); @@ -373,7 +375,7 @@ public class PlotSquared { PlotSquared.log(Captions.PREFIX + CaptionUtility .format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(), - IMP.getPluginName())); + this.platform.getPluginName())); } /** @@ -381,13 +383,13 @@ public class PlotSquared { * * @return instance of PlotSquared */ - public static PlotSquared get() { + public static PlotSquared get() { return PlotSquared.instance; } - @NotNull public static IPlotMain imp() { - if (instance != null && instance.IMP != null) { - return instance.IMP; + @NotNull public static PlotPlatform platform() { + if (instance != null && instance.platform != null) { + return instance.platform; } throw new IllegalStateException("Plot main implementation is missing"); } @@ -396,7 +398,7 @@ public class PlotSquared { * Log a message to the IPlotMain logger. * * @param message Message to log - * @see IPlotMain#log(String) + * @see PlotPlatform#log(String) */ public static void log(Object message) { if (message == null || (message instanceof Caption ? @@ -415,7 +417,7 @@ public class PlotSquared { * Log a message to the IPlotMain logger. * * @param message Message to log - * @see IPlotMain#log(String) + * @see PlotPlatform#log(String) */ public static void debug(@Nullable Object message) { if (Settings.DEBUG) { @@ -539,7 +541,7 @@ public class PlotSquared { return; } File file = new File( - this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId() + this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId() + "_" + plotArea.getWorldName()); if (!file.exists()) { return; @@ -1137,13 +1139,13 @@ public class PlotSquared { } else if (worldSection != null) { String secondaryGeneratorName = worldSection.getString("generator.plugin"); GeneratorWrapper secondaryGenerator = - this.IMP.getGenerator(world, secondaryGeneratorName); + this.platform.getGenerator(world, secondaryGeneratorName); if (secondaryGenerator != null && secondaryGenerator.isFull()) { plotGenerator = secondaryGenerator.getPlotGenerator(); } else { String primaryGeneratorName = worldSection.getString("generator.init"); GeneratorWrapper primaryGenerator = - this.IMP.getGenerator(world, primaryGeneratorName); + this.platform.getGenerator(world, primaryGeneratorName); if (primaryGenerator != null && primaryGenerator.isFull()) { plotGenerator = primaryGenerator.getPlotGenerator(); } else { @@ -1187,7 +1189,7 @@ public class PlotSquared { return; } PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'"); - String gen_string = worldSection.getString("generator.plugin", IMP.getPluginName()); + String gen_string = worldSection.getString("generator.plugin", platform.getPluginName()); if (type == PlotAreaType.PARTIAL) { Set clusters = this.clusters_tmp != null ? this.clusters_tmp.get(world) : new HashSet<>(); @@ -1204,7 +1206,7 @@ public class PlotSquared { DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE PlotSquared.log(Captions.PREFIX + "&3 - " + name + "-" + pos1 + "-" + pos2); - GeneratorWrapper areaGen = this.IMP.getGenerator(world, gen_string); + GeneratorWrapper areaGen = this.platform.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); } @@ -1234,7 +1236,7 @@ public class PlotSquared { } return; } - GeneratorWrapper areaGen = this.IMP.getGenerator(world, gen_string); + GeneratorWrapper areaGen = this.platform.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); } @@ -1296,8 +1298,8 @@ public class PlotSquared { clone.set(key, worldSection.get(key)); } } - String gen_string = clone.getString("generator.plugin", IMP.getPluginName()); - GeneratorWrapper areaGen = this.IMP.getGenerator(world, gen_string); + String gen_string = clone.getString("generator.plugin", platform.getPluginName()); + GeneratorWrapper areaGen = this.platform.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); } @@ -1485,7 +1487,7 @@ public class PlotSquared { */ public void copyFile(String file, String folder) { try { - File output = this.IMP.getDirectory(); + File output = this.platform.getDirectory(); if (!output.exists()) { output.mkdirs(); } @@ -1493,7 +1495,7 @@ public class PlotSquared { if (newFile.exists()) { return; } - try (InputStream stream = this.IMP.getClass().getResourceAsStream(file)) { + try (InputStream stream = this.platform.getClass().getResourceAsStream(file)) { byte[] buffer = new byte[2048]; if (stream == null) { try (ZipInputStream zis = new ZipInputStream( @@ -1593,7 +1595,7 @@ public class PlotSquared { list.add(chunks); list.add(HybridUtils.height); File file = new File( - this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area + this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area .getId() + "_" + HybridUtils.area.getWorldName()); if (file.exists() && !file.delete()) { PlotSquared.log(Captions.PREFIX @@ -1622,11 +1624,11 @@ public class PlotSquared { database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE, Storage.MySQL.USER, Storage.MySQL.PASSWORD); } else if (Storage.SQLite.USE) { - File file = MainUtil.getFile(IMP.getDirectory(), Storage.SQLite.DB + ".db"); + File file = MainUtil.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db"); database = new SQLite(file); } else { PlotSquared.log(Captions.PREFIX + "&cNo storage type is set!"); - this.IMP.shutdown(); //shutdown used instead of disable because no database is set + this.platform.shutdown(); //shutdown used instead of disable because no database is set return; } DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, false); @@ -1654,9 +1656,9 @@ public class PlotSquared { "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); e.printStackTrace(); PlotSquared.log("&d==== End of stacktrace ===="); - PlotSquared.log("&6Please go to the " + IMP.getPluginName() + PlotSquared.log("&6Please go to the " + platform.getPluginName() + " 'storage.yml' and configure the database correctly."); - this.IMP.shutdown(); //shutdown used instead of disable because of database error + this.platform.shutdown(); //shutdown used instead of disable because of database error } } @@ -1680,7 +1682,7 @@ public class PlotSquared { try { worlds.save(worldsFile); } catch (IOException e) { - PlotSquared.debug("Failed to save " + IMP.getPluginName() + " worlds.yml"); + PlotSquared.debug("Failed to save " + platform.getPluginName() + " worlds.yml"); e.printStackTrace(); } } @@ -1711,7 +1713,7 @@ public class PlotSquared { * - Translation: PlotSquared.use_THIS.yml, style.yml
*/ public boolean setupConfigs() { - File folder = new File(this.IMP.getDirectory(), "config"); + File folder = new File(this.platform.getDirectory(), "config"); if (!folder.exists() && !folder.mkdirs()) { PlotSquared.log(Captions.PREFIX + "&cFailed to create the /plugins/config folder. Please create it manually."); @@ -1747,7 +1749,7 @@ public class PlotSquared { e.printStackTrace(); } // Disable plugin - this.IMP.shutdown(); + this.platform.shutdown(); return false; } } else { @@ -1768,7 +1770,7 @@ public class PlotSquared { PlotSquared.log("Failed to save settings.yml"); } try { - this.styleFile = MainUtil.getFile(IMP.getDirectory(), + this.styleFile = MainUtil.getFile(platform.getDirectory(), Settings.Paths.TRANSLATIONS + File.separator + "style.yml"); if (!this.styleFile.exists()) { if (!this.styleFile.getParentFile().exists()) { diff --git a/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java index 4ba4a44f4..1a2aa5e9b 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java @@ -46,7 +46,7 @@ public interface BackupManager { * @param whenDone Action that runs when the automatic backup has been completed */ static void backup(@Nullable PlotPlayer player, @NotNull final Plot plot, @NotNull Runnable whenDone) { - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().automaticBackup(player, plot, whenDone); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().automaticBackup(player, plot, whenDone); } /** diff --git a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java index 2d8c04a76..9ffc223c9 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java @@ -49,7 +49,7 @@ public class NullBackupManager implements BackupManager { } @Override @NotNull public Path getBackupPath() { - return Objects.requireNonNull(PlotSquared.imp()).getDirectory().toPath(); + return Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath(); } @Override public int getBackupLimit() { diff --git a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java index 57cbea1d8..468ee23ac 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java @@ -57,7 +57,7 @@ import java.util.concurrent.TimeUnit; .expireAfterAccess(3, TimeUnit.MINUTES).build(); public SimpleBackupManager() throws Exception { - this.backupPath = Objects.requireNonNull(PlotSquared.imp()).getDirectory().toPath().resolve("backups"); + this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups"); if (!Files.exists(backupPath)) { Files.createDirectory(backupPath); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 383076f0d..514030d6b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -138,7 +138,7 @@ public class Area extends SubCommand { // There's only one plot in the area... final PlotId plotId = new PlotId(1, 1); final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1], - Objects.requireNonNull(PlotSquared.imp()).getDefaultGenerator(), plotId, plotId); + Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId); // Plot size is the same as the region width hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); // We use a schematic generator @@ -153,7 +153,7 @@ public class Area extends SubCommand { hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY(); // No sign plz hybridPlotWorld.setAllowSigns(false); - final File parentFile = MainUtil.getFile(PlotSquared.imp().getDirectory(), "schematics" + File.separator + + final File parentFile = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator + hybridPlotWorld.getId()); if (!parentFile.exists() && !parentFile.mkdirs()) { @@ -187,8 +187,8 @@ public class Area extends SubCommand { // Now the schematic is saved, which is wonderful! PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld) - .plotManager(PlotSquared.imp().getPluginName()) - .generatorName(PlotSquared.imp().getPluginName()) + .plotManager(PlotSquared.platform().getPluginName()) + .generatorName(PlotSquared.platform().getPluginName()) .maximumId(plotId) .minimumId(plotId); Runnable singleRun = () -> { @@ -282,8 +282,8 @@ public class Area extends SubCommand { return false; } PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area) - .plotManager(PlotSquared.imp().getPluginName()) - .generatorName(PlotSquared.imp().getPluginName()) + .plotManager(PlotSquared.platform().getPluginName()) + .generatorName(PlotSquared.platform().getPluginName()) .minimumId(new PlotId(1, 1)) .maximumId(new PlotId(numX, numZ)); final String path = @@ -339,7 +339,7 @@ public class Area extends SubCommand { PlotAreaBuilder builder = new PlotAreaBuilder(); builder.worldName(split[0]); final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, - PlotSquared.get().IMP.getDefaultGenerator(), null, null); + PlotSquared.platform().getDefaultGenerator(), null, null); PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id); if (other != null && Objects.equals(pa.getId(), other.getId())) { Captions.SETUP_WORLD_TAKEN.send(player, pa.toString()); @@ -428,8 +428,8 @@ public class Area extends SubCommand { PlotSquared.get().worlds.getConfigurationSection(path); pa.saveConfiguration(section); pa.loadConfiguration(section); - builder.plotManager(PlotSquared.imp().getPluginName()); - builder.generatorName(PlotSquared.imp().getPluginName()); + builder.plotManager(PlotSquared.platform().getPluginName()); + builder.generatorName(PlotSquared.platform().getPluginName()); String world = SetupUtils.manager.setupWorld(builder); if (WorldUtil.IMP.isWorld(world)) { Captions.SETUP_FINISHED.send(player); @@ -661,7 +661,7 @@ public class Area extends SubCommand { case "remove": MainUtil.sendMessage(player, "$1World creation settings may be stored in multiple locations:" - + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PlotSquared.imp() + + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PlotSquared.platform() .getPluginName() + " settings.yml" + "\n$3 - $2Multiverse worlds.yml (or any world management plugin)" + "\n$1Stop the server and delete it from these locations."); diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java index 944eaaf6b..66af54666 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Backup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java @@ -91,7 +91,7 @@ public final class Backup extends Command { final Plot plot = player.getCurrentPlot(); if (plot != null) { final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(plot); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); if (backupProfile instanceof PlayerBackupProfile) { final CompletableFuture> backupList = backupProfile.listBackups(); @@ -136,7 +136,7 @@ public final class Backup extends Command { sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); } else { final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(plot); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); @@ -176,7 +176,7 @@ public final class Backup extends Command { sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); } else { final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(plot); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); @@ -238,7 +238,7 @@ public final class Backup extends Command { return; } final BackupProfile backupProfile = - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(plot); + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot); if (backupProfile instanceof NullBackupProfile) { sendMessage(player, Captions.BACKUP_IMPOSSIBLE, Captions.GENERIC_OTHER.getTranslated()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index 337801385..1d599d408 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -82,9 +82,9 @@ public class Buy extends Command { confirm.run(this, () -> { Captions.REMOVED_BALANCE.send(player, price); - EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); + EconHandler.getEconHandler().depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price); - PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()); + PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs()); if (owner != null) { Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index 557ba084b..060efdf3d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -385,7 +385,7 @@ public class Cluster extends SubCommand { DBFunc.setInvited(cluster, uuid); final PlotPlayer otherPlayer = - PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (otherPlayer != null) { MainUtil.sendMessage(otherPlayer, Captions.CLUSTER_INVITED, cluster.getName()); @@ -448,7 +448,7 @@ public class Cluster extends SubCommand { DBFunc.removeInvited(cluster, uuid); final PlotPlayer player2 = - PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (player2 != null) { MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, cluster.getName()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Comment.java b/Core/src/main/java/com/plotsquared/core/command/Comment.java index a5615533f..c9e3031ac 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Comment.java +++ b/Core/src/main/java/com/plotsquared/core/command/Comment.java @@ -96,7 +96,7 @@ public class Comment extends SubCommand { return false; } - for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { if (pp.getAttribute("chatspy")) { MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " ")); } diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 41690b5af..413aa35bd 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -102,7 +102,7 @@ public class DatabaseCommand extends SubCommand { .sendMessage(player, "/plot database import [prefix]"); return false; } - File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), + File file = MainUtil.getFile(PlotSquared.platform().getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db"); if (!file.exists()) { MainUtil.sendMessage(player, "&6Database does not exist: " + file); @@ -127,11 +127,11 @@ public class DatabaseCommand extends SubCommand { PlotId newId = newPlot.getId(); PlotId id = plot.getId(); File worldFile = - new File(PlotSquared.imp().getWorldContainer(), + new File(PlotSquared.platform().getWorldContainer(), id.toCommaSeparatedString()); if (worldFile.exists()) { File newFile = - new File(PlotSquared.imp().getWorldContainer(), + new File(PlotSquared.platform().getWorldContainer(), newId.toCommaSeparatedString()); worldFile.renameTo(newFile); } @@ -179,7 +179,7 @@ public class DatabaseCommand extends SubCommand { return MainUtil.sendMessage(player, "/plot database sqlite [file]"); } File sqliteFile = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), args[1] + ".db"); + MainUtil.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db"); implementation = new SQLite(sqliteFile); break; default: diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 3d6af68f1..036e5ed2a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -89,12 +89,12 @@ public class DebugExec extends SubCommand { /* try { if (PlotSquared.get() != null) { - File file = new File(PlotSquared.get().IMP.getDirectory(), + File file = new File(PlotSquared.imp().getDirectory(), Settings.Paths.SCRIPTS + File.separator + "start.js"); if (file.exists()) { init(); String script = StringMan.join(Files.readLines(new File(new File( - PlotSquared.get().IMP.getDirectory() + File.separator + PlotSquared.imp().getDirectory() + File.separator + Settings.Paths.SCRIPTS), "start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator")); this.scope.put("THIS", this); @@ -169,7 +169,7 @@ public class DebugExec extends SubCommand { this.scope.put("EconHandler", EconHandler.getEconHandler()); this.scope.put("DBFunc", DBFunc.dbManager); this.scope.put("HybridUtils", HybridUtils.manager); - this.scope.put("IMP", PlotSquared.get().IMP); + this.scope.put("IMP", PlotSquared.platform()); this.scope.put("MainCommand", MainCommand.getInstance()); // enums @@ -306,7 +306,7 @@ public class DebugExec extends SubCommand { case "addcmd": try { final String cmd = StringMan.join(Files.readLines(MainUtil.getFile(new File( - PlotSquared.get().IMP.getDirectory() + File.separator + PlotSquared.platform().getDirectory() + File.separator + Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator")); new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null, @@ -338,7 +338,7 @@ public class DebugExec extends SubCommand { case "run": try { script = StringMan.join(Files.readLines(MainUtil.getFile(new File( - PlotSquared.get().IMP.getDirectory() + File.separator + PlotSquared.platform().getDirectory() + File.separator + Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator")); if (args.length > 2) { @@ -354,7 +354,7 @@ public class DebugExec extends SubCommand { } break; case "list-scripts": - String path = PlotSquared.get().IMP.getDirectory() + File.separator + String path = PlotSquared.platform().getDirectory() + File.separator + Settings.Paths.SCRIPTS; File folder = new File(path); File[] filesArray = folder.listFiles(); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java index bdb5a13b2..832a8d5ea 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java @@ -63,7 +63,7 @@ public class DebugImportWorlds extends Command { } SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea(); PlotId id = new PlotId(0, 0); - File container = PlotSquared.imp().getWorldContainer(); + File container = PlotSquared.platform().getWorldContainer(); if (container.equals(new File("."))) { player.sendMessage( "World container must be configured to be a separate directory to your base files!"); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java index 441fbdd84..be5754cdb 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java @@ -87,13 +87,13 @@ public class DebugPaste extends SubCommand { b.append("This PlotSquared version is licensed to the spigot user ") .append(PremiumVerification.getUserID()).append("\n\n"); b.append("# Server Information\n"); - b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation()) + b.append("Server Version: ").append(PlotSquared.platform().getServerImplementation()) .append("\n"); b.append("online_mode: ").append(!Settings.UUID.OFFLINE).append(';') .append(!Settings.UUID.OFFLINE).append('\n'); b.append("Plugins:"); for (Map.Entry, Boolean> pluginInfo : PlotSquared - .get().IMP.getPluginIds()) { + .platform().getPluginIds()) { Map.Entry nameVersion = pluginInfo.getKey(); String name = nameVersion.getKey(); String version = nameVersion.getValue(); @@ -129,7 +129,7 @@ public class DebugPaste extends SubCommand { try { final File logFile = - new File(PlotSquared.get().IMP.getDirectory(), "../../logs/latest.log"); + new File(PlotSquared.platform().getDirectory(), "../../logs/latest.log"); if (Files.size(logFile.toPath()) > 14_000_000) { throw new IOException("Too big..."); } @@ -161,7 +161,7 @@ public class DebugPaste extends SubCommand { } try { - final File MultiverseWorlds = new File(PlotSquared.get().IMP.getDirectory(), + final File MultiverseWorlds = new File(PlotSquared.platform().getDirectory(), "../Multiverse-Core/worlds.yml"); incendoPaster.addFile(new IncendoPaster.PasteFile("MultiverseCore/worlds.yml", readFile(MultiverseWorlds))); diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index 1cb862304..edbdab068 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -96,7 +96,7 @@ public class Deny extends SubCommand { plot.addDenied(uuid); PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true); if (!uuid.equals(DBFunc.EVERYONE)) { - handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid), plot); + handleKick(PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid), plot); } else { for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) { // Ignore plot-owners diff --git a/Core/src/main/java/com/plotsquared/core/command/Grant.java b/Core/src/main/java/com/plotsquared/core/command/Grant.java index 2d41da2e3..59c1453a8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Grant.java +++ b/Core/src/main/java/com/plotsquared/core/command/Grant.java @@ -99,7 +99,7 @@ public class Grant extends Command { String key = "grantedPlots"; byte[] rawData = Ints.toByteArray(amount); - PlotPlayer online = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + PlotPlayer online = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (online != null) { online.setPersistentMeta(key, rawData); } else { diff --git a/Core/src/main/java/com/plotsquared/core/command/Kick.java b/Core/src/main/java/com/plotsquared/core/command/Kick.java index 911ea9810..978aeec29 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Kick.java +++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java @@ -86,7 +86,7 @@ public class Kick extends SubCommand { } continue; } - PlotPlayer pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (pp != null) { players.add(pp); } diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index a08de0cd0..0f5564055 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -383,7 +383,7 @@ public class ListCmd extends SubCommand { final List names = PlotSquared.get().getImpromptuUUIDPipeline() .getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); for (final UUIDMapping uuidMapping : names) { - PlotPlayer pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()); + PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()); if (pp != null) { message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1") .tooltip(new PlotMessage("Online").color("$4")); @@ -415,7 +415,7 @@ public class ListCmd extends SubCommand { completions.add("shared"); } if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) { - completions.addAll(PlotSquared.imp().getWorldManager().getWorlds()); + completions.addAll(PlotSquared.platform().getWorldManager().getWorlds()); } if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) { completions.add("top"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 33754c4b8..395f49704 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -212,7 +212,7 @@ public class Merge extends SubCommand { java.util.Set uuids = adjacent.getOwners(); boolean isOnline = false; for (final UUID owner : uuids) { - final PlotPlayer accepter = PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner); + final PlotPlayer accepter = PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner); if (!force && accepter == null) { continue; } @@ -221,7 +221,7 @@ public class Merge extends SubCommand { Runnable run = () -> { MainUtil.sendMessage(accepter, Captions.MERGE_ACCEPTED); plot.autoMerge(dir, maxSize - size, owner, terrain); - PlotPlayer plotPlayer = PlotSquared.imp().getPlayerManager().getPlayerIfExists(player.getUUID()); + PlotPlayer plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(player.getUUID()); if (plotPlayer == null) { sendMessage(accepter, Captions.MERGE_NOT_VALID); return; diff --git a/Core/src/main/java/com/plotsquared/core/command/Owner.java b/Core/src/main/java/com/plotsquared/core/command/Owner.java index f19790dc5..4176c312f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Owner.java +++ b/Core/src/main/java/com/plotsquared/core/command/Owner.java @@ -95,7 +95,7 @@ public class Owner extends SetCommand { MainUtil.sendMessage(player, Captions.SET_OWNER); return; } - final PlotPlayer other = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + final PlotPlayer other = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (plot.isOwner(uuid)) { Captions.ALREADY_OWNER.send(player, MainUtil.getName(uuid)); return; diff --git a/Core/src/main/java/com/plotsquared/core/command/PluginCmd.java b/Core/src/main/java/com/plotsquared/core/command/PluginCmd.java index b0bf24d40..67f498c67 100644 --- a/Core/src/main/java/com/plotsquared/core/command/PluginCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/PluginCmd.java @@ -42,7 +42,7 @@ public class PluginCmd extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { TaskManager.IMP.taskAsync(() -> { MainUtil.sendMessage(player, String.format( - "$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)", + "$2>> $1&l" + PlotSquared.platform().getPluginName() + " $2($1Version$2: $1%s$2)", PlotSquared.get().getVersion())); MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault $2& $1SirYwell"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Setup.java b/Core/src/main/java/com/plotsquared/core/command/Setup.java index bdcd20697..d61fd02da 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Setup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Setup.java @@ -52,7 +52,7 @@ public class Setup extends SubCommand { StringBuilder message = new StringBuilder(); message.append("&6What generator do you want?"); for (Entry> entry : SetupUtils.generators.entrySet()) { - if (entry.getKey().equals(PlotSquared.imp().getPluginName())) { + if (entry.getKey().equals(PlotSquared.platform().getPluginName())) { message.append("\n&8 - &2").append(entry.getKey()).append(" (Default Generator)"); } else if (entry.getValue().isFull()) { message.append("\n&8 - &7").append(entry.getKey()).append(" (Plot Generator)"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Template.java b/Core/src/main/java/com/plotsquared/core/command/Template.java index 02bc7af4d..5e5f9675b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -64,11 +64,11 @@ public class Template extends SubCommand { public static boolean extractAllFiles(String world, String template) { try { File folder = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.TEMPLATES); + MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES); if (!folder.exists()) { return false; } - File output = PlotSquared.get().IMP.getDirectory(); + File output = PlotSquared.platform().getDirectory(); if (!output.exists()) { output.mkdirs(); } @@ -120,7 +120,7 @@ public class Template extends SubCommand { public static void zipAll(String world, Set files) throws IOException { File output = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.TEMPLATES); + MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES); output.mkdirs(); try (FileOutputStream fos = new FileOutputStream( output + File.separator + world + ".template"); @@ -169,7 +169,7 @@ public class Template extends SubCommand { .sendMessage(player, "&cInvalid template file: " + args[2] + ".template"); return false; } - File worldFile = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), + File worldFile = MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml"); YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile); PlotSquared.get().worlds.set("worlds." + world, worldConfig.get("")); @@ -180,7 +180,7 @@ public class Template extends SubCommand { e.printStackTrace(); } String manager = - worldConfig.getString("generator.plugin", PlotSquared.imp().getPluginName()); + worldConfig.getString("generator.plugin", PlotSquared.platform().getPluginName()); String generator = worldConfig.getString("generator.init", manager); PlotAreaBuilder builder = new PlotAreaBuilder() .plotAreaType(MainUtil.getType(worldConfig)) diff --git a/Core/src/main/java/com/plotsquared/core/command/Trim.java b/Core/src/main/java/com/plotsquared/core/command/Trim.java index ad5e5c0fe..3a9124662 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -73,7 +73,7 @@ public class Trim extends SubCommand { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { String directory = world + File.separator + "region"; - File folder = new File(PlotSquared.get().IMP.getWorldContainer(), directory); + File folder = new File(PlotSquared.platform().getWorldContainer(), directory); File[] regionFiles = folder.listFiles(); for (File file : regionFiles) { String name = file.getName(); diff --git a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java index fb10eff9b..915a30bf1 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -61,7 +61,7 @@ public class ComponentPresetManager { private final String guiName; public ComponentPresetManager() { - final File file = new File(Objects.requireNonNull(PlotSquared.imp()).getDirectory(), "components.yml"); + final File file = new File(Objects.requireNonNull(PlotSquared.platform()).getDirectory(), "components.yml"); if (!file.exists()) { boolean created = false; try { diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLite.java b/Core/src/main/java/com/plotsquared/core/database/SQLite.java index 501033184..7c6ea7d49 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLite.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLite.java @@ -56,8 +56,8 @@ public class SQLite extends Database { if (checkConnection()) { return this.connection; } - if (!PlotSquared.get().IMP.getDirectory().exists()) { - PlotSquared.get().IMP.getDirectory().mkdirs(); + if (!PlotSquared.platform().getDirectory().exists()) { + PlotSquared.platform().getDirectory().mkdirs(); } File file = new File(this.dbLocation); if (!file.exists()) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java index e661e4c5f..5a8ace19e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -41,7 +41,7 @@ import org.jetbrains.annotations.NotNull; public class HybridGen extends IndependentPlotGenerator { @Override public String getName() { - return PlotSquared.imp().getPluginName(); + return PlotSquared.platform().getPluginName(); } private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX, diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java index 67ad6eb8b..04c6ad9bd 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java @@ -74,7 +74,7 @@ public class HybridPlotManager extends ClassicPlotManager { .getWorldName() + File.separator; try { File sideRoad = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schem"); + MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "sideroad.schem"); String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator; if (sideRoad.exists()) { @@ -82,12 +82,12 @@ public class HybridPlotManager extends ClassicPlotManager { Files.readAllBytes(sideRoad.toPath()))); } File intersection = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "intersection.schem"); + MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "intersection.schem"); if (intersection.exists()) { files.add(new FileBytes(newDir + "intersection.schem", Files.readAllBytes(intersection.toPath()))); } - File plot = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schem"); + File plot = MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "plot.schem"); if (plot.exists()) { files.add(new FileBytes(newDir + "plot.schem", Files.readAllBytes(plot.toPath()))); } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index a561a9ac3..e746e90ea 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -200,9 +200,9 @@ public class HybridPlotWorld extends ClassicPlotWorld { // Try to determine root. This means that plot areas can have separate schematic // directories - if (!(root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + + if (!(root = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName() + "/" + this.getId())).exists()) { - root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), + root = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName()); } diff --git a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java index 324f6d8d4..c42e54546 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java +++ b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java @@ -31,7 +31,6 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.SetupObject; import com.plotsquared.core.queue.ScopedLocalBlockQueue; import com.plotsquared.core.setup.PlotAreaBuilder; -import com.plotsquared.core.setup.SetupProcess; /** * This class allows for implementation independent world generation. @@ -104,7 +103,7 @@ public abstract class IndependentPlotGenerator { * @return */ public GeneratorWrapper specify(String world) { - return (GeneratorWrapper) PlotSquared.get().IMP.wrapPlotGenerator(world, this); + return (GeneratorWrapper) PlotSquared.platform().wrapPlotGenerator(world, this); } @Override public String toString() { diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 361a71b28..055c2e689 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -160,7 +160,7 @@ public class PlotListener { if (plot.getFlag(NotifyEnterFlag.class)) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { - final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + final PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (owner != null && !owner.getUUID().equals(player.getUUID())) { MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated() .replace("%player", player.getName()) @@ -336,7 +336,7 @@ public class PlotListener { if (plot.getFlag(NotifyLeaveFlag.class)) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { - final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + final PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if ((owner != null) && !owner.getUUID().equals(player.getUUID())) { MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated() .replace("%player", player.getName()) diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index 9a97800e7..e51552729 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -68,7 +68,7 @@ public class ConsolePlayer extends PlotPlayer { } @Override public Actor toActor() { - return PlotSquared.get().IMP.getConsole(); + return PlotSquared.platform().getConsole(); } @Override public Actor getPlatformPlayer() { diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 13efa6bfb..e18877739 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -129,7 +129,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer * @return Wrapped player */ public static PlotPlayer wrap(Object player) { - return PlotSquared.get().IMP.wrapPlayer(player); + return PlotSquared.platform().wrapPlayer(player); } public abstract Actor toActor(); @@ -588,8 +588,8 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer if (ExpireManager.IMP != null) { ExpireManager.IMP.storeDate(getUUID(), System.currentTimeMillis()); } - PlotSquared.imp().getPlayerManager().removePlayer(this); - PlotSquared.get().IMP.unregister(this); + PlotSquared.platform().getPlayerManager().removePlayer(this); + PlotSquared.platform().unregister(this); debugModeEnabled.remove(this); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 46ce9f24c..450835c25 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -401,7 +401,7 @@ public class Plot { */ public List> getPlayersInPlot() { final List> players = new ArrayList<>(); - for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer player : PlotSquared.platform().getPlayerManager().getPlayers()) { if (this.equals(player.getCurrentPlot())) { players.add(player); } @@ -1330,7 +1330,7 @@ public class Plot { if (Settings.Backup.DELETE_ON_UNCLAIM) { // Destroy all backups when the plot is unclaimed - Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(current) + Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(current) .destroy(); } @@ -3039,11 +3039,11 @@ public class Plot { return false; } if (!isMerged()) { - return PlotSquared.imp().getPlayerManager() + return PlotSquared.platform().getPlayerManager() .getPlayerIfExists(Objects.requireNonNull(this.getOwnerAbs())) != null; } for (final Plot current : getConnectedPlots()) { - if (current.hasOwner() && PlotSquared.imp().getPlayerManager() + if (current.hasOwner() && PlotSquared.platform().getPlayerManager() .getPlayerIfExists(Objects.requireNonNull(current.getOwnerAbs())) != null) { return true; } diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index 532134536..cb6c21fa1 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -409,13 +409,13 @@ public class ExpireManager { } } for (UUID helper : plot.getTrusted()) { - PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper); + PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); if (player != null) { MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString()); } } for (UUID helper : plot.getMembers()) { - PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper); + PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); if (player != null) { MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString()); } @@ -438,12 +438,12 @@ public class ExpireManager { } public long getAge(UUID uuid) { - if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid) != null) { + if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid) != null) { return 0; } Long last = this.dates_cache.get(uuid); if (last == null) { - OfflinePlotPlayer opp = PlotSquared.imp().getPlayerManager().getOfflinePlayer(uuid); + OfflinePlotPlayer opp = PlotSquared.platform().getPlayerManager().getOfflinePlayer(uuid); if (opp != null && (last = opp.getLastPlayed()) != 0) { this.dates_cache.put(uuid, last); } else { @@ -458,7 +458,7 @@ public class ExpireManager { public long getAge(Plot plot) { if (!plot.hasOwner() || Objects.equals(DBFunc.EVERYONE, plot.getOwner()) - || PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwner()) != null || plot.getRunning() > 0) { + || PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwner()) != null || plot.getRunning() > 0) { return 0; } diff --git a/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java b/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java index 95ae8e953..608974bc9 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java +++ b/Core/src/main/java/com/plotsquared/core/plot/message/PlotMessage.java @@ -39,8 +39,8 @@ public class PlotMessage { reset(ChatManager.manager); } catch (Throwable e) { PlotSquared.debug( - PlotSquared.imp().getPluginName() + " doesn't support fancy chat for " + PlotSquared - .get().IMP.getServerVersion()); + PlotSquared.platform().getPluginName() + " doesn't support fancy chat for " + PlotSquared + .platform().getServerVersion()); ChatManager.manager = new PlainChatManager(); reset(ChatManager.manager); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index a212a0506..09c1f3859 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -87,7 +87,7 @@ public class SinglePlotArea extends GridPlotWorld { .settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null)) .worldName(worldName); - File container = PlotSquared.imp().getWorldContainer(); + File container = PlotSquared.platform().getWorldContainer(); File destination = new File(container, worldName); {// convert old diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java index 0e014baba..6083434a8 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotManager.java @@ -63,7 +63,7 @@ public class SinglePlotManager extends PlotManager { @Override public boolean clearPlot(Plot plot, final Runnable whenDone) { SetupUtils.manager.unload(plot.getWorldName(), false); final File worldFolder = - new File(PlotSquared.get().IMP.getWorldContainer(), plot.getWorldName()); + new File(PlotSquared.platform().getWorldContainer(), plot.getWorldName()); TaskManager.IMP.taskAsync(() -> { MainUtil.deleteDirectory(worldFolder); if (whenDone != null) { diff --git a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java index 76fa5e28a..9f270ff32 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocalBlockQueue.java @@ -123,7 +123,7 @@ public abstract class LocalBlockQueue { fixChunkLighting(x, z); BlockVector2 loc = BlockVector2.at(x, z); - for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) { + for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) { Location pLoc = pp.getLocation(); if (!StringMan.isEqual(getWorld(), pLoc.getWorld()) || !pLoc.getBlockVector2() .equals(loc)) { diff --git a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java index 0a8c7ba9a..73ab84cb9 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java +++ b/Core/src/main/java/com/plotsquared/core/setup/CommonSetupSteps.java @@ -59,8 +59,8 @@ public enum CommonSetupSteps implements SetupStep { String prefix = "\n&8 - &7"; sendMessage(plotPlayer, Captions.SETUP_WORLD_GENERATOR_ERROR + prefix + StringMan .join(SetupUtils.generators.keySet(), prefix) - .replaceAll(PlotSquared.imp().getPluginName(), - "&2" + PlotSquared.imp().getPluginName())); + .replaceAll(PlotSquared.platform().getPluginName(), + "&2" + PlotSquared.platform().getPluginName())); return this; // invalid input -> same setup step } builder.generatorName(arg); @@ -72,7 +72,7 @@ public enum CommonSetupSteps implements SetupStep { } @Nullable @Override public String getDefaultValue() { - return PlotSquared.imp().getPluginName(); + return PlotSquared.platform().getPluginName(); } }, CHOOSE_PLOT_AREA_TYPE(PlotAreaType.class, Captions.SETUP_WORLD_TYPE) { @@ -110,7 +110,7 @@ public enum CommonSetupSteps implements SetupStep { SetupUtils.generators.get(builder.plotManager()).getPlotGenerator() .processAreaSetup(builder); } else { - builder.plotManager(PlotSquared.imp().getPluginName()); + builder.plotManager(PlotSquared.platform().getPluginName()); MainUtil.sendMessage(plotPlayer, Captions.SETUP_WRONG_GENERATOR); builder.settingsNodesWrapper(CommonSetupSteps.wrap(builder.plotManager())); // TODO why is processSetup not called here? diff --git a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java index d59e2d8f0..549c41b55 100644 --- a/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java +++ b/Core/src/main/java/com/plotsquared/core/setup/PlotAreaBuilder.java @@ -56,7 +56,7 @@ public class PlotAreaBuilder { .plotAreaType(area.getType()) .terrainType(area.getTerrain()) .generatorName(area.getGenerator().getName()) - .plotManager(PlotSquared.imp().getPluginName()) + .plotManager(PlotSquared.platform().getPluginName()) .minimumId(area.getMin()) .maximumId(area.getMax()) .settingsNodesWrapper(new SettingsNodesWrapper(area.getSettingNodes(), null)); diff --git a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java index a593e0cb0..6557bc1c5 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EconHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/EconHandler.java @@ -25,7 +25,7 @@ */ package com.plotsquared.core.util; -import com.plotsquared.core.IPlotMain; +import com.plotsquared.core.PlotPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; @@ -36,27 +36,27 @@ public abstract class EconHandler { /** * @deprecated This will be removed in the future, - * call {@link IPlotMain#getEconomyHandler()} instead. + * call {@link PlotPlatform#getEconomyHandler()} instead. */ @Deprecated @Nullable public static EconHandler manager; /** - * Initialize the economy handler using {@link IPlotMain#getEconomyHandler()} - * @deprecated Call {@link #init} instead or use {@link IPlotMain#getEconomyHandler()} + * Initialize the economy handler using {@link PlotPlatform#getEconomyHandler()} + * @deprecated Call {@link #init} instead or use {@link PlotPlatform#getEconomyHandler()} * which does this already. */ @Deprecated public static void initializeEconHandler() { - manager = PlotSquared.get().IMP.getEconomyHandler(); + manager = PlotSquared.platform().getEconomyHandler(); } /** * Return the econ handler instance, if one exists * * @return Economy handler instance - * @deprecated Call {@link IPlotMain#getEconomyHandler()} instead + * @deprecated Call {@link PlotPlatform#getEconomyHandler()} instead */ @Deprecated @Nullable public static EconHandler getEconHandler() { - manager = PlotSquared.get().IMP.getEconomyHandler(); + manager = PlotSquared.platform().getEconomyHandler(); return manager; } diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 9e2a78853..25797755d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -969,7 +969,7 @@ public class MainUtil { public static void getPersistentMeta(UUID uuid, final String key, final RunnableVal result) { - PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (player != null) { result.run(player.getPersistentMeta(key)); } else { diff --git a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java index 1349e6c9a..8e8316862 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -107,7 +107,7 @@ public abstract class RegionManager { public Set getChunkChunks(String world) { File folder = - new File(PlotSquared.get().IMP.getWorldContainer(), world + File.separator + "region"); + new File(PlotSquared.platform().getWorldContainer(), world + File.separator + "region"); File[] regionFiles = folder.listFiles(); if (regionFiles == null) { throw new RuntimeException( @@ -141,7 +141,7 @@ public abstract class RegionManager { String directory = world + File.separator + "region" + File.separator + "r." + loc.getX() + "." + loc.getZ() + ".mca"; - File file = new File(PlotSquared.get().IMP.getWorldContainer(), directory); + File file = new File(PlotSquared.platform().getWorldContainer(), directory); PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); if (file.exists()) { file.delete(); diff --git a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java index 92b1b2ef4..22ae0ff9f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -314,7 +314,7 @@ public abstract class SchematicHandler { */ public Schematic getSchematic(String name) throws UnsupportedFormatException { File parent = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS); + MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS); if (!parent.exists()) { if (!parent.mkdir()) { throw new RuntimeException("Could not create schematic parent directory"); @@ -323,10 +323,10 @@ public abstract class SchematicHandler { if (!name.endsWith(".schem") && !name.endsWith(".schematic")) { name = name + ".schem"; } - File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), + File file = MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name); if (!file.exists()) { - file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), + file = MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name); } return getSchematic(file); @@ -339,7 +339,7 @@ public abstract class SchematicHandler { */ public Collection getSchematicNames() { final File parent = - MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS); + MainUtil.getFile(PlotSquared.platform().getDirectory(), Settings.Paths.SCHEMATICS); final List names = new ArrayList<>(); if (parent.exists()) { final String[] rawNames = @@ -467,7 +467,7 @@ public abstract class SchematicHandler { return false; } try { - File tmp = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), path); + File tmp = MainUtil.getFile(PlotSquared.platform().getDirectory(), path); tmp.getParentFile().mkdirs(); try (NBTOutputStream nbtStream = new NBTOutputStream( new GZIPOutputStream(new FileOutputStream(tmp)))) { diff --git a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java index 56a3ff8fa..ebff5c94f 100644 --- a/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java +++ b/Core/src/main/java/com/plotsquared/core/util/TabCompletions.java @@ -161,7 +161,7 @@ public class TabCompletions { cachedCompletionValues.put(cacheIdentifier, players); } } else { - final Collection> onlinePlayers = PlotSquared.imp().getPlayerManager().getPlayers(); + final Collection> onlinePlayers = PlotSquared.platform().getPlayerManager().getPlayers(); players = new ArrayList<>(onlinePlayers.size()); for (final PlotPlayer player : onlinePlayers) { if (uuidFilter.test(player.getUUID())) { diff --git a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java index 4d733d5eb..29cb707fd 100644 --- a/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/WorldUtil.java @@ -187,7 +187,7 @@ public abstract class WorldUtil { public File getDat(String world) { File file = new File( - PlotSquared.get().IMP.getWorldContainer() + File.separator + world + File.separator + PlotSquared.platform().getWorldContainer() + File.separator + world + File.separator + "level.dat"); if (file.exists()) { return file; @@ -196,7 +196,7 @@ public abstract class WorldUtil { } public File getMcr(String world, int x, int z) { - File file = new File(PlotSquared.get().IMP.getWorldContainer(), + File file = new File(PlotSquared.platform().getWorldContainer(), world + File.separator + "region" + File.separator + "r." + x + '.' + z + ".mca"); if (file.exists()) { return file; From 196df855ac5d36b187870e9cb1de29110aceda03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 7 Jul 2020 13:37:03 +0200 Subject: [PATCH 05/35] Clean up PlotAreaManager and move a bunch of plot area related logic out of PlotSquared --- .../plotsquared/bukkit/BukkitPlatform.java | 4 +- .../bukkit/generator/BlockStatePopulator.java | 5 +- .../bukkit/generator/BukkitPlotGenerator.java | 6 +- .../bukkit/listener/ChunkListener.java | 10 +- .../bukkit/listener/EntitySpawnListener.java | 4 +- .../bukkit/listener/PaperListener.java | 2 +- .../bukkit/listener/PlayerEvents.java | 26 +-- .../com/plotsquared/core/PlotSquared.java | 161 ++++-------------- .../com/plotsquared/core/api/PlotAPI.java | 2 +- .../com/plotsquared/core/command/Area.java | 18 +- .../plotsquared/core/command/Condense.java | 2 +- .../core/command/DatabaseCommand.java | 4 +- .../com/plotsquared/core/command/Debug.java | 2 +- .../plotsquared/core/command/DebugExec.java | 2 +- .../plotsquared/core/command/Download.java | 2 +- .../com/plotsquared/core/command/ListCmd.java | 2 +- .../com/plotsquared/core/command/Load.java | 2 +- .../com/plotsquared/core/command/Move.java | 2 +- .../com/plotsquared/core/command/Purge.java | 2 +- .../core/command/RegenAllRoads.java | 2 +- .../com/plotsquared/core/command/Save.java | 2 +- .../core/command/SchematicCmd.java | 2 +- .../plotsquared/core/command/Template.java | 4 +- .../com/plotsquared/core/command/Trim.java | 2 +- .../com/plotsquared/core/command/Visit.java | 4 +- .../core/generator/AugmentedUtils.java | 2 +- .../core/generator/HybridUtils.java | 2 +- .../core/listener/WESubscriber.java | 6 +- .../plotsquared/core/location/Location.java | 5 +- .../core/player/ConsolePlayer.java | 8 +- .../plotsquared/core/player/PlotPlayer.java | 13 +- .../java/com/plotsquared/core/plot/Plot.java | 4 +- .../plot/world/DefaultPlotAreaManager.java | 20 +-- .../core/plot/world/PlotAreaManager.java | 149 ++++++++++++++-- .../plot/world/SinglePlotAreaManager.java | 30 ++-- .../core/queue/ScopedLocalBlockQueue.java | 2 +- .../core/setup/CommonSetupSteps.java | 4 +- .../com/plotsquared/core/util/MainUtil.java | 6 +- .../com/plotsquared/core/util/WEManager.java | 2 +- .../core/util/query/PlotQuery.java | 2 +- 40 files changed, 288 insertions(+), 241 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 7e4b9605d..4fc4d9619 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -1010,7 +1010,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } map.put(plotAreaType.name().toLowerCase(), terrainTypes); } - for (final PlotArea plotArea : PlotSquared.get().getPlotAreas()) { + for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) { final Map terrainTypeMap = map.get(plotArea.getType().name().toLowerCase()); terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(), @@ -1071,7 +1071,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl world = Bukkit.getWorld(worldName); } else { try { - if (!PlotSquared.get().hasPlotArea(worldName)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { SetGenCB.setGenerator(BukkitUtil.getWorld(worldName)); } } catch (Exception e) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java index a89588598..8359d1e61 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java @@ -54,7 +54,10 @@ final class BlockStatePopulator extends BlockPopulator { if (this.queue == null) { this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false); } - final PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); + final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null); + if (area == null) { + return; + } final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ()); final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 6f886904f..70688f4c7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -108,7 +108,7 @@ public class BukkitPlotGenerator extends ChunkGenerator if (!this.loaded) { String name = world.getName(); PlotSquared.get().loadWorld(name, this); - Set areas = PlotSquared.get().getPlotAreas(name); + final Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(name); if (!areas.isEmpty()) { PlotArea area = areas.iterator().next(); if (!area.isMobSpawning()) { @@ -198,8 +198,8 @@ public class BukkitPlotGenerator extends ChunkGenerator if (ChunkManager.preProcessChunk(loc, result)) { return; } - PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); - if (area == null && (area = PlotSquared.get().getPlotArea(this.levelName, null)) == null) { + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null); + if (area == null && (area = PlotSquared.get().getPlotAreaManager().getPlotArea(this.levelName, null)) == null) { throw new IllegalStateException( "Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc + ", world: " + world); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java index 19a892c43..3ace06fd9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -90,7 +90,7 @@ public class ChunkListener implements Listener { HashSet toUnload = new HashSet<>(); for (World world : Bukkit.getWorlds()) { String worldName = world.getName(); - if (!PlotSquared.get().hasPlotArea(worldName)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { continue; } Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world); @@ -177,7 +177,7 @@ public class ChunkListener implements Listener { Chunk chunk = event.getChunk(); if (Settings.Chunk_Processor.AUTO_TRIM) { String world = chunk.getWorld().getName(); - if (PlotSquared.get().hasPlotArea(world)) { + if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { if (unloadChunk(world, chunk, true)) { return; } @@ -200,7 +200,7 @@ public class ChunkListener implements Listener { event.setCancelled(true); return; } - if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); @@ -230,7 +230,7 @@ public class ChunkListener implements Listener { event.setCancelled(true); return; } - if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { return; } Entity[] entities = chunk.getEntities(); @@ -281,7 +281,7 @@ public class ChunkListener implements Listener { } public boolean processChunk(Chunk chunk, boolean unload) { - if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) { return false; } Entity[] entities = chunk.getEntities(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index 8b70143b1..b122b51d1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -78,7 +78,7 @@ public class EntitySpawnListener implements Listener { if (areaName == world.getName()) { } else { areaName = world.getName(); - hasPlotArea = PlotSquared.get().hasPlotArea(areaName); + hasPlotArea = PlotSquared.get().getPlotAreaManager().hasPlotArea(areaName); } if (!hasPlotArea) { return; @@ -90,7 +90,7 @@ public class EntitySpawnListener implements Listener { @NotNull World world = entity.getWorld(); List meta = entity.getMetadata(KEY); if (meta.isEmpty()) { - if (PlotSquared.get().hasPlotArea(world.getName())) { + if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) { entity.setMetadata(KEY, new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation())); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index a512189f7..9816709e3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -305,7 +305,7 @@ public class PaperListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index b10370cfc..13e22685d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -483,7 +483,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; } Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter); @@ -497,7 +497,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler public boolean onProjectileHit(ProjectileHitEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return true; } PlotArea area = location.getPlotArea(); @@ -1069,7 +1069,7 @@ public class PlayerEvents extends PlotListener implements Listener { PlotArea area = location.getPlotArea(); boolean plotArea = location.isPlotArea(); if (!plotArea) { - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } return; @@ -1165,7 +1165,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityBlockForm(EntityBlockFormEvent event) { String world = event.getBlock().getWorld().getName(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return; } Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); @@ -1495,7 +1495,7 @@ public class PlayerEvents extends PlotListener implements Listener { Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } for (Block block1 : event.getBlocks()) { @@ -1532,7 +1532,7 @@ public class PlayerEvents extends PlotListener implements Listener { Location location = BukkitUtil.getLocation(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } if (this.pistonBlocks) { @@ -1625,7 +1625,7 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onStructureGrow(StructureGrowEvent event) { - if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getWorld().getName())) { return; } List blocks = event.getBlocks(); @@ -1688,7 +1688,7 @@ public class PlayerEvents extends PlotListener implements Listener { return; }*/ HumanEntity entity = event.getWhoClicked(); - if (!(entity instanceof Player) || !PlotSquared.get() + if (!(entity instanceof Player) || !PlotSquared.get().getPlotAreaManager() .hasPlotArea(entity.getWorld().getName())) { return; } @@ -1819,7 +1819,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(LingeringPotionSplashEvent event) { Projectile entity = event.getEntity(); Location location = BukkitUtil.getLocation(entity); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } if (!this.onProjectileHit(event)) { @@ -1884,7 +1884,7 @@ public class PlayerEvents extends PlotListener implements Listener { Block block = event.getBlock(); Location location = BukkitUtil.getLocation(block.getLocation()); String world = location.getWorld(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return; } PlotArea area = location.getPlotArea(); @@ -2158,7 +2158,7 @@ public class PlayerEvents extends PlotListener implements Listener { Block block = event.getBlock(); World world = block.getWorld(); String worldName = world.getName(); - if (!PlotSquared.get().hasPlotArea(worldName)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) { return; } Location location = BukkitUtil.getLocation(block.getLocation()); @@ -2669,7 +2669,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onPotionSplash(PotionSplashEvent event) { ThrownPotion damager = event.getPotion(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } int count = 0; @@ -2699,7 +2699,7 @@ public class PlayerEvents extends PlotListener implements Listener { public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity damager = event.getDamager(); Location location = BukkitUtil.getLocation(damager); - if (!PlotSquared.get().hasPlotArea(location.getWorld())) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorld())) { return; } Entity victim = event.getEntity(); diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 20a74ac94..0371613b8 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -87,7 +87,6 @@ import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDPipeline; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.math.BlockVector2; -import com.sk89q.worldedit.regions.CuboidRegion; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -387,11 +386,17 @@ public class PlotSquared

{ return PlotSquared.instance; } + + /** + * Get the platform specific implementation of PlotSquared + * + * @return Platform implementation + */ @NotNull public static PlotPlatform platform() { if (instance != null && instance.platform != null) { return instance.platform; } - throw new IllegalStateException("Plot main implementation is missing"); + throw new IllegalStateException("Plot platform implementation is missing"); } /** @@ -480,9 +485,12 @@ public class PlotSquared

{ return plot.getArea().getPlotManager(); } - public PlotManager getPlotManager(Location location) { - PlotArea pa = getPlotAreaAbs(location); - return pa != null ? pa.getPlotManager() : null; + @Nullable public PlotManager getPlotManager(@NotNull final Location location) { + final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(location); + if (plotArea == null) { + return null; + } + return plotArea.getPlotManager(); } /** @@ -586,8 +594,8 @@ public class PlotSquared

{ setPlotsTmp(area); } - public void removePlotAreas(String world) { - for (PlotArea area : getPlotAreas(world)) { + public void removePlotAreas(@NotNull final String world) { + for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) { if (area.getWorldName().equals(world)) { removePlotArea(area); } @@ -609,9 +617,9 @@ public class PlotSquared

{ this.clusters_tmp.put(area.toString(), area.getClusters()); } - public Set getClusters(String world) { - Set set = new HashSet<>(); - for (PlotArea area : getPlotAreas(world)) { + public Set getClusters(@NotNull final String world) { + final Set set = new HashSet<>(); + for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) { set.addAll(area.getClusters()); } return Collections.unmodifiableSet(set); @@ -882,7 +890,7 @@ public class PlotSquared

{ */ @Deprecated public Set getPlots(final PlotFilter... filters) { final List areas = new LinkedList<>(); - for (final PlotArea plotArea : this.getPlotAreas()) { + for (final PlotArea plotArea : this.getPlotAreaManager().getAllPlotAreas()) { for (final PlotFilter filter : filters) { if (filter.allowsArea(plotArea)) { areas.add(plotArea); @@ -911,21 +919,20 @@ public class PlotSquared

{ return result; } - public void setPlots(HashMap> plots) { + public void setPlots(@NotNull final Map> plots) { if (this.plots_tmp == null) { this.plots_tmp = new HashMap<>(); } - for (Entry> entry : plots.entrySet()) { - String world = entry.getKey(); - PlotArea area = getPlotArea(world, null); - if (area == null) { - HashMap map = - this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>()); + for (final Entry> entry : plots.entrySet()) { + final String world = entry.getKey(); + final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(world, null); + if (plotArea == null) { + Map map = this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>()); map.putAll(entry.getValue()); } else { for (Plot plot : entry.getValue().values()) { - plot.setArea(area); - area.addPlot(plot); + plot.setArea(plotArea); + plotArea.addPlot(plot); } } } @@ -962,7 +969,7 @@ public class PlotSquared

{ * @param player the plot owner * @return Set of plot */ - public Set getPlots(String world, PlotPlayer player) { + public Set getPlots(String world, PlotPlayer player) { return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet(); } @@ -973,7 +980,7 @@ public class PlotSquared

{ * @param player the plot owner * @return Set of plot */ - public Set getPlots(PlotArea area, PlotPlayer player) { + public Set getPlots(PlotArea area, PlotPlayer player) { return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet(); } @@ -999,17 +1006,6 @@ public class PlotSquared

{ return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet(); } - /** - * Check if a plot world. - * - * @param world the world - * @return if a plot world is registered - * @see #getPlotAreaByString(String) to get the PlotArea object - */ - public boolean hasPlotArea(String world) { - return plotAreaManager.getPlotAreas(world, null).length != 0; - } - public Collection getPlots(String world) { return PlotQuery.newQuery().inWorld(world).asCollection(); } @@ -1020,7 +1016,7 @@ public class PlotSquared

{ * @param player the player to retrieve the plots for * @return Set of Plot */ - public Set getPlots(PlotPlayer player) { + public Set getPlots(PlotPlayer player) { return PlotQuery.newQuery().ownedBy(player).asSet(); } @@ -1032,7 +1028,7 @@ public class PlotSquared

{ return area == null ? null : id == null ? null : area.getPlot(id); } - public Set getBasePlots(PlotPlayer player) { + public Set getBasePlots(PlotPlayer player) { return getBasePlots(player.getUUID()); } @@ -1276,7 +1272,7 @@ public class PlotSquared

{ throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); } - PlotArea existing = getPlotArea(world, name); + final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name); if (existing != null && name.equals(existing.getId())) { continue; } @@ -1937,11 +1933,6 @@ public class PlotSquared

{ } } - public PlotArea getFirstPlotArea() { - PlotArea[] areas = plotAreaManager.getAllPlotAreas(); - return areas.length > 0 ? areas[0] : null; - } - public int getPlotAreaCount() { return this.plotAreaManager.getAllPlotAreas().length; } @@ -1951,12 +1942,6 @@ public class PlotSquared

{ .mapToInt(PlotArea::getPlotCount).sum(); } - public Set getPlotAreas() { - final Set set = new HashSet<>(); - Collections.addAll(set, plotAreaManager.getAllPlotAreas()); - return Collections.unmodifiableSet(set); - } - /** * Check if the chunk uses vanilla/non-PlotSquared generation * @@ -1979,81 +1964,6 @@ public class PlotSquared

{ return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL); } - /** - * Gets a list of PlotArea objects. - * - * @param world the world - * @return Collection of PlotArea objects - */ - public Set getPlotAreas(@NonNull final String world) { - final Set set = new HashSet<>(); - Collections.addAll(set, plotAreaManager.getPlotAreas(world, null)); - return set; - } - - /** - * Gets the relevant plot area for a specified location. - *

    - *
  • If there is only one plot area globally that will be returned. - *
  • If there is only one plot area in the world, it will return that. - *
  • If the plot area for a location cannot be unambiguously - * resolved, null will be returned. - *
- * Note: An applicable plot area may not include the location i.e. clusters - * - * @param location the location - * @return - */ - public PlotArea getApplicablePlotArea(@NonNull final Location location) { - return plotAreaManager.getApplicablePlotArea(location); - } - - public PlotArea getPlotArea(@NonNull final String world, final String id) { - return plotAreaManager.getPlotArea(world, id); - } - - /** - * Gets the {@code PlotArea} which contains a location. - *
    - *
  • If the plot area does not contain a location, null - * will be returned. - *
- * - * @param location the location - * @return the {@link PlotArea} in the location, null if non existent - */ - public PlotArea getPlotAreaAbs(@NonNull final Location location) { - return plotAreaManager.getPlotArea(location); - } - - public PlotArea getPlotAreaByString(@NonNull final String search) { - String[] split = search.split("[;,]"); - PlotArea[] areas = plotAreaManager.getPlotAreas(split[0], null); - if (areas == null) { - for (PlotArea area : plotAreaManager.getAllPlotAreas()) { - if (area.getWorldName().equalsIgnoreCase(split[0])) { - if (area.getId() == null || split.length == 2 && area.getId() - .equalsIgnoreCase(split[1])) { - return area; - } - } - } - return null; - } - if (areas.length == 1) { - return areas[0]; - } else if (split.length == 1) { - return null; - } else { - for (PlotArea area : areas) { - if (StringMan.isEqual(split[1], area.getId())) { - return area; - } - } - return null; - } - } - /** * Gets Plots based on alias * @@ -2066,13 +1976,6 @@ public class PlotSquared

{ return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet(); } - public Set getPlotAreas(final String world, final CuboidRegion region) { - final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region); - final Set set = new HashSet<>(); - Collections.addAll(set, areas); - return Collections.unmodifiableSet(set); - } - public YamlConfiguration getConfig() { return config; } diff --git a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java index 3991643a3..a88e404fe 100644 --- a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java @@ -157,7 +157,7 @@ import java.util.UUID; if (world == null) { return Collections.emptySet(); } - return PlotSquared.get().getPlotAreas(world); + return PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world); } /** diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 514030d6b..7f7e2bb1c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -70,6 +70,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -102,7 +104,7 @@ public class Area extends SubCommand { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME); return false; } - final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]); + final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorld(), args[1]); if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) { MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN); return false; @@ -274,8 +276,8 @@ public class Area extends SubCommand { final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); - Set areas = - PlotSquared.get().getPlotAreas(area.getWorldName(), region); + final Set areas = PlotSquared.get().getPlotAreaManager() + .getPlotAreasSet(area.getWorldName(), region); if (!areas.isEmpty()) { Captions.CLUSTER_INTERSECTION .send(player, areas.iterator().next().toString()); @@ -340,12 +342,12 @@ public class Area extends SubCommand { builder.worldName(split[0]); final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, PlotSquared.platform().getDefaultGenerator(), null, null); - PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id); + PlotArea other = PlotSquared.get().getPlotAreaManager().getPlotArea(pa.getWorldName(), id); if (other != null && Objects.equals(pa.getId(), other.getId())) { Captions.SETUP_WORLD_TAKEN.send(player, pa.toString()); return false; } - Set areas = PlotSquared.get().getPlotAreas(pa.getWorldName()); + Set areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(pa.getWorldName()); if (!areas.isEmpty()) { PlotArea area = areas.iterator().next(); pa.setType(area.getType()); @@ -490,7 +492,7 @@ public class Area extends SubCommand { area = player.getApplicablePlotArea(); break; case 2: - area = PlotSquared.get().getPlotAreaByString(args[1]); + area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); break; default: Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]"); @@ -552,7 +554,7 @@ public class Area extends SubCommand { Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]"); return false; } - ArrayList areas = new ArrayList<>(PlotSquared.get().getPlotAreas()); + final List areas = new ArrayList<>(Arrays.asList(PlotSquared.get().getPlotAreaManager().getAllPlotAreas())); paginate(player, areas, 8, page, new RunnableVal3() { @Override public void run(Integer i, PlotArea area, PlotMessage message) { @@ -635,7 +637,7 @@ public class Area extends SubCommand { Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]"); return false; } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java index 8f792ee7e..0e49ebd36 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Condense.java +++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java @@ -59,7 +59,7 @@ public class Condense extends SubCommand { MainUtil.sendMessage(player, getUsage()); return false; } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) { MainUtil.sendMessage(player, "INVALID AREA"); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 413aa35bd..84f2a67f7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -80,7 +80,7 @@ public class DatabaseCommand extends SubCommand { return false; } List plots; - PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); if (area != null) { plots = PlotSquared.get().sortPlotsByTemp(area.getPlots()); args = Arrays.copyOfRange(args, 1, args.length); @@ -116,7 +116,7 @@ public class DatabaseCommand extends SubCommand { plots = new ArrayList<>(); for (Entry> entry : map.entrySet()) { String areaName = entry.getKey(); - PlotArea pa = PlotSquared.get().getPlotAreaByString(areaName); + PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(areaName); if (pa != null) { for (Entry entry2 : entry.getValue().entrySet()) { Plot plot = entry2.getValue(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index 91997a4ec..28150d27c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -118,7 +118,7 @@ public class Debug extends SubCommand { information.append(header); information.append(getSection(section, "PlotArea")); information.append( - getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreas(), ", "))); + getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreaManager().getAllPlotAreas(), ", "))); information.append(getLine(line, "Owned Plots", PlotSquared.get().getPlots().size())); information.append(getSection(section, "Messages")); information.append(getLine(line, "Total Messages", Captions.values().length)); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 036e5ed2a..1f4967734 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -259,7 +259,7 @@ public class DebugExec extends SubCommand { "&cInvalid syntax: /plot debugexec start-rgar "); return false; } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); if (area == null) { MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index efd4079d5..26ce40575 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -52,7 +52,7 @@ public class Download extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 0f5564055..518e780a4 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -297,7 +297,7 @@ public class ListCmd extends SubCommand { plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term)); break; default: - if (PlotSquared.get().hasPlotArea(args[0])) { + if (PlotSquared.get().getPlotAreaManager().hasPlotArea(args[0])) { if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) { MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_WORLD); diff --git a/Core/src/main/java/com/plotsquared/core/command/Load.java b/Core/src/main/java/com/plotsquared/core/command/Load.java index aa952a007..30a503c76 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Load.java +++ b/Core/src/main/java/com/plotsquared/core/command/Load.java @@ -54,7 +54,7 @@ public class Load extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Move.java b/Core/src/main/java/com/plotsquared/core/command/Move.java index 136bbcfaa..f6debe194 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Move.java +++ b/Core/src/main/java/com/plotsquared/core/command/Move.java @@ -70,7 +70,7 @@ public class Move extends SubCommand { Captions.COMMAND_SYNTAX.send(player, getUsage()); return CompletableFuture.completedFuture(false); } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); Plot plot2; if (area == null) { plot2 = MainUtil.getPlotFromString(player, args[0], true); diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 9a89b2230..764825ca7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -78,7 +78,7 @@ public class Purge extends SubCommand { break; case "area": case "a": - area = PlotSquared.get().getPlotAreaByString(split[1]); + area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, split[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java b/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java index 69d0022f6..5f87a131a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java +++ b/Core/src/main/java/com/plotsquared/core/command/RegenAllRoads.java @@ -59,7 +59,7 @@ public class RegenAllRoads extends SubCommand { "/plot regenallroads [height]"); return false; } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Save.java b/Core/src/main/java/com/plotsquared/core/command/Save.java index 480167576..a9f55e31e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Save.java +++ b/Core/src/main/java/com/plotsquared/core/command/Save.java @@ -51,7 +51,7 @@ public class Save extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { String world = player.getLocation().getWorld(); - if (!PlotSquared.get().hasPlotArea(world)) { + if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) { return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD); } final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java index 66e4a0662..f6c971911 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/SchematicCmd.java @@ -150,7 +150,7 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_WORLD_ARGS); return false; } - PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]); + PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]); if (area == null) { Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Template.java b/Core/src/main/java/com/plotsquared/core/command/Template.java index 5e5f9675b..8234e7226 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Template.java +++ b/Core/src/main/java/com/plotsquared/core/command/Template.java @@ -159,7 +159,7 @@ public class Template extends SubCommand { "/plot template import