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/12] 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/12] 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/12] 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 0fa5a16cd0dbc9dbcee370aba7e5039c88c237af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 12 Jul 2020 21:49:05 +0200 Subject: [PATCH 04/12] replace remaining debug calls --- .../entity/ReplicatingEntityWrapper.java | 11 +++--- .../bukkit/listener/ChunkListener.java | 18 ++++------ .../bukkit/listener/PlayerEvents.java | 4 +-- .../bukkit/queue/BukkitLocalQueue.java | 6 ---- .../bukkit/util/BukkitRegionManager.java | 7 ++-- .../plotsquared/bukkit/util/BukkitUtil.java | 1 - .../plotsquared/bukkit/util/ContentMap.java | 8 +++-- .../com/plotsquared/core/PlotSquared.java | 35 ++----------------- .../com/plotsquared/core/api/PlotAPI.java | 3 +- .../com/plotsquared/core/command/Claim.java | 8 +++-- .../plotsquared/core/command/DebugExec.java | 1 - .../com/plotsquared/core/command/Purge.java | 1 - .../com/plotsquared/core/command/Trim.java | 1 - .../core/configuration/Caption.java | 4 +-- .../configuration/file/YamlConfiguration.java | 13 ++++--- .../plotsquared/core/database/SQLManager.java | 7 ++-- .../com/plotsquared/core/database/SQLite.java | 6 +++- .../core/generator/HybridPlotWorld.java | 5 ++- .../core/generator/SquarePlotManager.java | 12 +++---- .../core/generator/SquarePlotWorld.java | 7 ++-- .../plotsquared/core/plot/PlotInventory.java | 8 +++-- .../core/plot/expiration/ExpireManager.java | 18 +++++----- .../com/plotsquared/core/util/MainUtil.java | 5 ++- .../core/util/SchematicHandler.java | 17 +++------ .../core/util/net/IncendoPaster.java | 7 ++-- 25 files changed, 95 insertions(+), 118 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java index f0ef20fba..9320fa39e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java @@ -25,7 +25,6 @@ */ package com.plotsquared.bukkit.entity; -import com.plotsquared.core.PlotSquared; import org.bukkit.Art; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -55,11 +54,15 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; public final class ReplicatingEntityWrapper extends EntityWrapper { + private static final Logger logger = LoggerFactory.getLogger(ReplicatingEntityWrapper.class); + private final short depth; private final int hash; private final EntityBaseStats base = new EntityBaseStats(); @@ -331,7 +334,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { return; // END LIVING // default: - PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType()); + logger.debug("Could not identify entity: {}", entity.getType()); } } @@ -387,7 +390,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { try { entity.getInventory().setContents(this.inventory); } catch (IllegalArgumentException e) { - PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage()); + logger.error("Failed to restore inventory", e); } } @@ -730,7 +733,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { restoreLiving((LivingEntity) entity); return entity; default: - PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType()); + logger.debug("Could not identify entity: {}", entity.getType()); return entity; // END LIVING } 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..feab438f6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -51,6 +51,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.Method; import java.util.HashSet; @@ -60,6 +62,8 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; @SuppressWarnings("unused") public class ChunkListener implements Listener { + private static final Logger logger = LoggerFactory.getLogger(ChunkListener.class); + private RefMethod methodGetHandleChunk; private RefField mustSave; private Chunk lastChunk; @@ -73,9 +77,6 @@ public class ChunkListener implements Listener { this.mustSave = classChunk.getField("mustSave"); this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle"); } catch (Throwable ignored) { - PlotSquared.debug(PlotSquared.get().IMP.getPluginName() - + "/Server not compatible for chunk processor trim/gc"); - Settings.Chunk_Processor.AUTO_TRIM = false; } } @@ -251,7 +252,6 @@ public class ChunkListener implements Listener { if (!chunk.isLoaded()) { Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); - PlotSquared.debug("Successfully processed and unloaded chunk!"); chunk.unload(true); return; } @@ -259,7 +259,6 @@ public class ChunkListener implements Listener { if (tiles.length == 0) { Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); - PlotSquared.debug("Successfully processed and unloaded chunk!"); chunk.unload(true); return; } @@ -269,7 +268,6 @@ public class ChunkListener implements Listener { if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) { Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); - PlotSquared.debug("Successfully processed and unloaded chunk!"); chunk.unload(true); return; } @@ -297,15 +295,11 @@ public class ChunkListener implements Listener { } } - PlotSquared.debug( - "PlotSquared detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + ( - chunk.getX() << 4)); + logger.debug("PlotSquared detected chunk and processed it: {},{}", chunk.getX() << 4, chunk.getZ() << 4); } if (tiles.length > Settings.Chunk_Processor.MAX_TILES) { if (unload) { - PlotSquared.debug( - "PlotSquared detected unsafe chunk: " + (chunk.getX() << 4) + "," + ( - chunk.getX() << 4)); + logger.debug("PlotSquared detected chunk: {},{}", chunk.getX() << 4, chunk.getZ() << 4); cleanChunk(chunk); return true; } 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 643f80611..2c0cc77bc 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -987,7 +987,8 @@ public class PlayerEvents extends PlotListener implements Listener { player.sendMessage(spyMessage); } } - PlotSquared.debug(full); + // TODO: Re-implement + // PlotSquared.debug(full); } @EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) { @@ -2435,7 +2436,6 @@ public class PlayerEvents extends PlotListener implements Listener { } Player p = event.getPlayer(); if (p == null) { - PlotSquared.debug("PlotSquared does not support HangingPlaceEvent for non-players."); event.setCancelled(true); return; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java index c8d6d929f..b5197ce23 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java @@ -27,11 +27,9 @@ package com.plotsquared.bukkit.queue; import com.plotsquared.bukkit.schematic.StateWrapper; import com.plotsquared.bukkit.util.BukkitBlockUtil; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.queue.BasicLocalBlockQueue; import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.MainUtil; -import com.plotsquared.core.util.task.TaskManager; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; @@ -85,8 +83,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { World worldObj = Bukkit.getWorld(getWorld()); if (worldObj != null) { worldObj.refreshChunk(x, z); - } else { - PlotSquared.debug("Error Refreshing Chunk"); } } @@ -109,8 +105,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { world.regenerate(region, editSession); } } - } else { - PlotSquared.debug("Error Regenerating Chunk"); } } 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 158f90928..f54cedccf 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -26,7 +26,6 @@ package com.plotsquared.bukkit.util; import com.plotsquared.bukkit.BukkitMain; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; @@ -55,6 +54,8 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayDeque; import java.util.ArrayList; @@ -75,6 +76,8 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; public class BukkitRegionManager extends RegionManager { + private static final Logger logger = LoggerFactory.getLogger(BukkitRegionManager.class); + public static boolean isIn(CuboidRegion region, int x, int z) { return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() && z >= region.getMinimumPoint().getZ() && z <= region.getMaximumPoint().getZ(); @@ -90,7 +93,7 @@ public class BukkitRegionManager extends RegionManager { } else { final Semaphore semaphore = new Semaphore(1); try { - PlotSquared.debug("Attempting to make an asynchronous call to getLoadedChunks." + logger.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), () -> { 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 a9dcd4a66..373dac19a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -468,7 +468,6 @@ public class BukkitUtil extends WorldUtil { block.setType(Material.valueOf("OAK_WALL_SIGN"), false); } if (!(block.getBlockData() instanceof WallSign)) { - PlotSquared.debug(block.getBlockData().getAsString()); throw new RuntimeException("Something went wrong generating a sign"); } final Directional sign = (Directional) block.getBlockData(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java index 08381ee22..3563b125b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java @@ -27,7 +27,6 @@ package com.plotsquared.bukkit.util; import com.plotsquared.bukkit.entity.EntityWrapper; import com.plotsquared.bukkit.entity.ReplicatingEntityWrapper; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; import com.sk89q.worldedit.bukkit.BukkitWorld; @@ -38,6 +37,8 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.HashSet; @@ -46,6 +47,8 @@ import java.util.Set; public class ContentMap { + private static final Logger logger = LoggerFactory.getLogger(ContentMap.class); + final Set entities; final Map allBlocks; @@ -123,8 +126,7 @@ public class ContentMap { try { entity.spawn(world, xOffset, zOffset); } catch (Exception e) { - PlotSquared.debug("Failed to restore entity (e): " + e.toString()); - e.printStackTrace(); + logger.error("Failed to restore entity", e); } } this.entities.clear(); diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index d6ccfd81d..f8f38e963 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -383,35 +383,6 @@ public class PlotSquared { throw new IllegalStateException("Plot main implementation is missing"); } - /** - * Log a message to the IPlotMain logger. - * - * @param message Message to log - * @see IPlotMain#log(String) - * @deprecated Use slf4j - */ - @Deprecated public static void log(Object message) { - if (message == null || (message instanceof Caption ? - ((Caption) message).getTranslated().isEmpty() : - message.toString().isEmpty())) { - return; - } - logger.info(StringMan.getString(message)); - } - - /** - * Log a message to the IPlotMain logger. - * - * @param message Message to log - * @see IPlotMain#log(String) - * @deprecated Use sl4j - */ - @Deprecated public static void debug(@Nullable Object message) { - if (Settings.DEBUG) { - logger.debug(StringMan.getString(message)); - } - } - private void startExpiryTasks() { if (Settings.Enabled_Components.PLOT_EXPIRY) { ExpireManager.IMP = new ExpireManager(); @@ -540,8 +511,8 @@ public class PlotSquared { chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1]))); int height = (int) list.get(2); logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height); - PlotSquared.debug(" Regions: " + regions.size()); - PlotSquared.debug(" Chunks: " + chunks.size()); + logger.debug(" Regions: {}", regions.size()); + logger.debug(" Chunks: {}", chunks.size()); HybridUtils.UPDATE = true; HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks); } catch (IOException | ClassNotFoundException e) { @@ -1108,7 +1079,7 @@ public class PlotSquared { } if (type == PlotAreaType.NORMAL) { if (plotAreaManager.getPlotAreas(world, null).length != 0) { - debug("World possibly already loaded: " + world); + logger.debug("Would possibly already loaded: {}", world); return; } IndependentPlotGenerator plotGenerator; 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..9dc992c29 100644 --- a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java @@ -167,7 +167,8 @@ import java.util.UUID; * @see MainUtil#sendConsoleMessage(Captions, String...) */ public void sendConsoleMessage(String message) { - PlotSquared.log(message); + // TODO: Re-implement + // PlotSquared.log(message); } /** diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 488b2dc84..02990a107 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -44,6 +44,8 @@ import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @CommandDeclaration(command = "claim", aliases = "c", @@ -54,6 +56,8 @@ import com.plotsquared.core.util.task.TaskManager; usage = "/plot claim") public class Claim extends SubCommand { + private static final Logger logger = LoggerFactory.getLogger(Claim.class); + @Override public boolean onCommand(final PlotPlayer player, String[] args) { String schematic = null; if (args.length >= 1) { @@ -133,7 +137,7 @@ public class Claim extends SubCommand { DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { if (!plot.claim(player, true, finalSchematic, false)) { - PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String + logger.info(Captions.PREFIX.getTranslated() + String .format("Failed to claim plot %s", plot.getId().toCommaSeparatedString())); sendMessage(player, Captions.PLOT_NOT_CLAIMED); plot.setOwnerAbs(null); @@ -148,7 +152,7 @@ public class Claim extends SubCommand { } } }), () -> { - PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String + logger.info(Captions.PREFIX.getTranslated() + String .format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString())); sendMessage(player, Captions.PLOT_NOT_CLAIMED); 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 53d6b00a5..91b9fbf91 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -452,7 +452,6 @@ public class DebugExec extends SubCommand { } init(); this.scope.put("PlotPlayer", player); - PlotSquared.debug("> " + script); try { if (async) { final String toExec = script; 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 4e63ad8a1..8c155fff5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -175,7 +175,6 @@ public class Purge extends SubCommand { 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(); AtomicBoolean cleared = new AtomicBoolean(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 0702c7c08..d90277602 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -111,7 +111,6 @@ public class Trim extends SubCommand { BlockVector2 loc = BlockVector2.at(x, z); empty.add(loc); } catch (NumberFormatException ignored) { - PlotSquared.debug("INVALID MCA: " + name); } } }); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Caption.java b/Core/src/main/java/com/plotsquared/core/configuration/Caption.java index bb9cf098f..081bc774a 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Caption.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Caption.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.configuration; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.StringMan; @@ -44,7 +43,8 @@ public interface Caption { default boolean send(PlotPlayer caller, Object... args) { String msg = CaptionUtility.format(caller, this, args); if (caller == null) { - PlotSquared.log(msg); + // TODO: Replace with adventure + System.out.println(msg); } else { caller.sendMessage(msg); } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java index f57cc56f8..ee1dec7d5 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java @@ -29,6 +29,8 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Configuration; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.InvalidConfigurationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.error.YAMLException; @@ -45,6 +47,9 @@ import java.util.Map; * Note that this implementation is not synchronized. */ public class YamlConfiguration extends FileConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(YamlConfiguration.class); + private static final String COMMENT_PREFIX = "# "; private static final String BLANK_CONFIG = "{}\n"; private final DumperOptions yamlOptions = new DumperOptions(); @@ -76,11 +81,11 @@ public class YamlConfiguration extends FileConfiguration { dest = new File(file.getAbsolutePath() + "_broken_" + i++); } Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); - PlotSquared.debug("&dCould not read: &7" + file); - PlotSquared.debug("&dRenamed to: &7" + dest.getName()); - PlotSquared.debug("&c============ Full stacktrace ============"); + logger.debug("Could not read: {}", file); + logger.debug("Renamed to: {}", file); + logger.debug("============ Full stacktrace ============"); ex.printStackTrace(); - PlotSquared.debug("&c========================================="); + logger.debug("========================================="); } catch (IOException e) { e.printStackTrace(); } 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 bab4ea1a5..a58eec7f9 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -626,9 +626,7 @@ public class SQLManager implements AbstractDB { } }))))); } catch (SQLException e) { - e.printStackTrace(); - PlotSquared - .debug("&7[WARN] Failed to set all flags and member tiers for plots"); + logger.error("Failed to set all flags and member tiers for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -2496,8 +2494,7 @@ public class SQLManager implements AbstractDB { } } } catch (SQLException e) { - PlotSquared - .debug("&7[WARN] Failed to fetch rating for plot " + plot.getId().toString()); + logger.error("Failed to fetch rating for plot {}", plot.getId().toString()); e.printStackTrace(); } return map; 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..eb12a4672 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLite.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLite.java @@ -26,6 +26,8 @@ package com.plotsquared.core.database; import com.plotsquared.core.PlotSquared; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -40,6 +42,8 @@ import java.sql.Statement; */ public class SQLite extends Database { + private static final Logger logger = LoggerFactory.getLogger(SQLite.class); + private final String dbLocation; private Connection connection; @@ -64,7 +68,7 @@ public class SQLite extends Database { try { file.createNewFile(); } catch (IOException ignored) { - PlotSquared.debug("&cUnable to create database!"); + logger.error("Unable to create database"); } } Class.forName("org.sqlite.JDBC"); 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 f4e92ced6..4e1b2157d 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -26,7 +26,6 @@ package com.plotsquared.core.generator; 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.location.Location; @@ -283,10 +282,10 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } - PlotSquared.debug(Captions.PREFIX + "&3 - plot schematic: &7" + schematic3File.getPath()); + logger.debug(" - plot schematic: {}", schematic3File.getPath()); } if (schematic1 == null || schematic2 == null || this.ROAD_WIDTH == 0) { - PlotSquared.debug(Captions.PREFIX + "&3 - schematic: &7false"); + logger.debug(" - schematic: false"); return; } this.ROAD_SCHEMATIC_ENABLED = true; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java index 9dbd2c611..531d2de92 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.generator; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; @@ -34,8 +33,9 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.RegionManager; import com.sk89q.worldedit.regions.CuboidRegion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.Arrays; import java.util.Iterator; import java.util.Set; @@ -44,6 +44,8 @@ import java.util.Set; */ public abstract class SquarePlotManager extends GridPlotManager { + private static final Logger logger = LoggerFactory.getLogger(SquarePlotManager.class); + private final SquarePlotWorld squarePlotWorld; public SquarePlotManager(SquarePlotWorld squarePlotWorld) { @@ -226,11 +228,9 @@ public abstract class SquarePlotManager extends GridPlotManager { // northwest return plot.getMerged(Direction.NORTHWEST) ? id : null; } - PlotSquared.debug("invalid location: " + Arrays.toString(merged)); } catch (Exception ignored) { - PlotSquared.debug( - "Invalid plot / road width in settings.yml for world: " + squarePlotWorld - .getWorldName()); + logger.debug( "Invalid plot / road width in settings.yml for world: {}", squarePlotWorld + .getWorldName()); } return null; } diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index 026b13ddc..a7270105e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -25,13 +25,16 @@ */ package com.plotsquared.core.generator; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.plot.PlotId; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public abstract class SquarePlotWorld extends GridPlotWorld { + private static final Logger logger = LoggerFactory.getLogger(SquarePlotWorld.class); + public int PLOT_WIDTH = 42; public int ROAD_WIDTH = 7; public int ROAD_OFFSET_X = 0; @@ -44,7 +47,7 @@ public abstract class SquarePlotWorld extends GridPlotWorld { @Override public void loadConfiguration(ConfigurationSection config) { if (!config.contains("plot.height")) { - PlotSquared.debug(" - &cConfiguration is null? (" + config.getCurrentPath() + ')'); + logger.debug(" - Configuration is null? ({})", config.getCurrentPath()); } this.PLOT_WIDTH = config.getInt("plot.size"); this.ROAD_WIDTH = config.getInt("road.width"); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java index 88f9c100c..d52536e22 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java @@ -29,9 +29,13 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.InventoryUtil; import lombok.NonNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PlotInventory { + private static final Logger logger = LoggerFactory.getLogger(PlotInventory.class); + private static final String META_KEY = "inventory"; public final PlotPlayer player; public final int size; @@ -79,8 +83,8 @@ public class PlotInventory { return; } if (hasPlotInventoryOpen(player)) { - PlotSquared.debug(String.format("Failed to open plot inventory for %s " - + "because the player already has an open plot inventory", player.getName())); + logger.debug("Failed to open plot inventory for {} because" + + " the player already has an open plot inventory", player.getName()); } else { this.open = true; setPlotInventoryOpen(player, this); 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..96499df87 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 @@ -47,6 +47,8 @@ import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayDeque; import java.util.ArrayList; @@ -62,6 +64,8 @@ import java.util.concurrent.ConcurrentLinkedDeque; public class ExpireManager { + private final Logger logger = LoggerFactory.getLogger(ExpireManager.class); + public static ExpireManager IMP; private final ConcurrentHashMap dates_cache; private final ConcurrentHashMap account_age_cache; @@ -79,7 +83,7 @@ public class ExpireManager { } public void addTask(ExpiryTask task) { - PlotSquared.debug("Adding new expiry task!"); + logger.debug("Adding new expiry task!"); this.tasks.add(task); } @@ -425,15 +429,13 @@ public class ExpireManager { PlotAnalysis changed = plot.getComplexity(null); int changes = changed == null ? 0 : changed.changes_sd; int modified = changed == null ? 0 : changed.changes; - PlotSquared.debug( - "$2[&5Expire&dManager$2] &cDeleted expired plot: " + plot + " User:" + plot.getOwner() - + " Delta:" + changes + "/" + modified + " Connected: " + StringMan - .getString(plots)); - PlotSquared.debug("$4 - Area: " + plot.getArea()); + logger.debug("Deleted expired plot: {} | User: {} | Delta: {}/{} | Connected: {}", + plot, plot.getOwner(), changes, modified, StringMan.getString(plots)); + logger.debug(" - Area: {}", plot.getArea()); if (plot.hasOwner()) { - PlotSquared.debug("$4 - Owner: " + plot.getOwner()); + logger.debug(" - Owner: {}", plot.getOwner()); } else { - PlotSquared.debug("$4 - Owner: Unowned"); + logger.debug(" - Owner: Unowned"); } } 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 dbe3599d6..11b17cc02 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -156,7 +156,7 @@ public class MainUtil { public static void upload(UUID uuid, String file, String extension, final RunnableVal writeTask, final RunnableVal whenDone) { if (writeTask == null) { - PlotSquared.debug("&cWrite task cannot be null"); + logger.debug("Write task cannot be null"); TaskManager.runTask(whenDone); return; } @@ -218,7 +218,6 @@ public class MainUtil { content = scanner.next().trim(); } if (!content.startsWith("<")) { - PlotSquared.debug(content); } int responseCode = ((HttpURLConnection) con).getResponseCode(); if (responseCode == 200) { @@ -899,7 +898,7 @@ public class MainUtil { if (file.isDirectory()) { deleteDirectory(file); } else { - PlotSquared.debug("Deleting file: " + file + " | " + file.delete()); + logger.debug("Deleting file: {} | {}", file, 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 547741e6f..c4fee2dbe 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -61,6 +61,8 @@ import com.sk89q.worldedit.world.block.BaseBlock; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -93,6 +95,8 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; public abstract class SchematicHandler { + + private static final Logger logger = LoggerFactory.getLogger(SchematicHandler.class); public static SchematicHandler manager; private boolean exportAll = false; @@ -187,7 +191,6 @@ public abstract class SchematicHandler { whenDone.value = false; } if (schematic == null) { - PlotSquared.debug("Schematic == null :|"); TaskManager.runTask(whenDone); return; } @@ -203,12 +206,7 @@ public abstract class SchematicHandler { + 1) < WIDTH) || ( (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { - PlotSquared.debug("Schematic is too large"); - PlotSquared.debug( - "(" + WIDTH + ',' + LENGTH + ',' + HEIGHT + ") is bigger than (" + ( - region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) + ',' - + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) - + ",256)"); + logger.debug("Schematic is too large"); TaskManager.runTask(whenDone); return; } @@ -405,8 +403,6 @@ public abstract class SchematicHandler { return new Schematic(clip); } catch (IOException e) { e.printStackTrace(); - PlotSquared.debug(is.toString() + " | " + is.getClass().getCanonicalName() - + " is not in GZIP format : " + e.getMessage()); } } return null; @@ -432,14 +428,12 @@ public abstract class SchematicHandler { return schematics; } catch (JSONException | IOException e) { e.printStackTrace(); - PlotSquared.debug("ERROR PARSING: " + rawJSON); } return null; } public void upload(final CompoundTag tag, UUID uuid, String file, RunnableVal whenDone) { if (tag == null) { - PlotSquared.debug("&cCannot save empty tag"); TaskManager.runTask(whenDone); return; } @@ -464,7 +458,6 @@ public abstract class SchematicHandler { */ public boolean save(CompoundTag tag, String path) { if (tag == null) { - PlotSquared.debug("&cCannot save empty tag"); return false; } try { diff --git a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java index 46ae63f7d..1189bc5cb 100644 --- a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java +++ b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java @@ -26,7 +26,8 @@ package com.plotsquared.core.util.net; import com.google.common.base.Charsets; -import com.plotsquared.core.PlotSquared; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -47,6 +48,8 @@ import java.util.Locale; @SuppressWarnings({"unused", "WeakerAccess"}) public final class IncendoPaster { + private static Logger logger = LoggerFactory.getLogger(IncendoPaster.class); + /** * Upload service URL */ @@ -158,7 +161,7 @@ public final class IncendoPaster { if (!httpURLConnection.getResponseMessage().contains("OK")) { if (httpURLConnection.getResponseCode() == 413) { final long size = content.length; - PlotSquared.debug(String.format("Paste Too Big > Size: %dMB", size / 1_000_000)); + logger.debug("Paste too big > size: {}MB", size / 1_000_000); } throw new IllegalStateException(String .format("Server returned status: %d %s", httpURLConnection.getResponseCode(), From c6962ef4d2450c7350b76d82a8f0180f373b53ed Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Mon, 13 Jul 2020 19:56:34 +0200 Subject: [PATCH 05/12] Shift a few more messages to debug --- Bukkit/pom.xml | 6 ++++++ .../src/main/java/com/plotsquared/bukkit/BukkitMain.java | 2 +- Core/pom.xml | 6 ++++++ .../java/com/plotsquared/core/util/SchematicHandler.java | 9 ++++----- .../java/com/plotsquared/core/uuid/UUIDPipeline.java | 4 ++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index d01f91307..fa9ecf402 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -78,6 +78,12 @@ + + org.slf4j + slf4j-jdk14 + 2.0.0-alpha1 + compile + com.sk89q.worldedit worldedit-core diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 780c36326..1c9588b90 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -536,7 +536,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< uuidList.clear(); // Print progress final double percentage = ((double) read / (double) totalSize) * 100.0D; - logger.info("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); + logger.debug("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); } catch (final InterruptedException | ExecutionException e) { logger.error("(UUID) Failed to retrieve last batch. Will try again", e); e.printStackTrace(); diff --git a/Core/pom.xml b/Core/pom.xml index d69f10a99..3a66b7985 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -98,6 +98,12 @@ 1.7.0-SNAPSHOT runtime + + org.slf4j + slf4j-api + 2.0.0-alpha1 + runtime + junit junit 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 c4fee2dbe..d16ecbe7b 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -152,17 +152,16 @@ public abstract class SchematicHandler { SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { @Override public void run(final CompoundTag value) { if (value == null) { - MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.getId()); + logger.debug("Skipped plot {}", plot.getId()); } else { TaskManager.runTaskAsync(() -> { - MainUtil.sendMessage(null, "&6ID: " + plot.getId()); + logger.debug("ID: {}", plot.getId()); boolean result = SchematicHandler.manager .save(value, directory + File.separator + name + ".schem"); if (!result) { - MainUtil - .sendMessage(null, "&7 - Failed to save &c" + plot.getId()); + logger.error("Failed to save {}", plot.getId()); } else { - MainUtil.sendMessage(null, "&7 - &a success: " + plot.getId()); + logger.debug("success: {}", plot.getId()); } TaskManager.runTask(THIS); }); 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 fc03f7326..88dfaeb11 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -325,7 +325,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.debug("Failed to find all usernames"); + logger.debug("(UUID) Failed to find all usernames"); } if (Settings.UUID.UNKNOWN_AS_DEFAULT) { @@ -388,7 +388,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.debug("Failed to find all UUIDs"); + logger.debug("(UUID) Failed to find all UUIDs"); } throw new ServiceError("End of pipeline"); From e84d82315cef95858aad5932e61a1237ee070a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 20:39:52 +0200 Subject: [PATCH 06/12] Add log4j config (this might work :p) --- Bukkit/build.gradle | 9 ++++++- Core/build.gradle | 5 +++- .../core/configuration/Config.java | 11 ++++---- .../java/com/plotsquared/core/plot/Plot.java | 25 ++++++++----------- .../com/plotsquared/core/plot/PlotArea.java | 13 +++++----- Core/src/main/resources/log4j.xml | 13 ++++++++++ 6 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 Core/src/main/resources/log4j.xml diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index d28377f6a..53ad254f7 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -37,7 +37,10 @@ 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") + // logging + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') + implementation('org.apache.logging.log4j:log4j-core:2.13.3') + implementation('org.apache.logging.log4j:log4j-api:2.13.3') } sourceCompatibility = 1.8 @@ -97,12 +100,16 @@ shadowJar { 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")) + include(dependency('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3')) + include(dependency('org.apache.logging.log4j:log4j-core:2.13.3')) + include(dependency('org.apache.logging.log4j:log4j-api:2.13.3')) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') + relocate('org.apache.logging.log4j', 'com.plotsquared.logging') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Core/build.gradle b/Core/build.gradle index 206568547..0f3e54412 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -18,7 +18,10 @@ 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") + // logging + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') + implementation('org.apache.logging.log4j:log4j-core:2.13.3') + implementation('org.apache.logging.log4j:log4j-api:2.13.3') } sourceCompatibility = 1.8 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 402ee7cd9..139e0dffd 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Config.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Config.java @@ -99,8 +99,8 @@ public class Config { field.set(instance, value); return; } catch (final Throwable e) { - logger.atDebug().addArgument(key).addArgument(value).addArgument(root.getSimpleName()) - .setCause(e).log("Invalid configuration value '{}: {}' in {}"); + logger.debug("Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); + e.printStackTrace(); } } } @@ -289,9 +289,10 @@ public class Config { Field field = instance.getClass().getField(toFieldName(split[split.length - 1])); setAccessible(field); return field; - } catch (Throwable e) { - logger.atDebug().addArgument(StringMan.join(split, ".")).setCause(e) - .addArgument(toNodeName(instance.getClass().getSimpleName())).log("Invalid config field: {} for {}"); + } catch (final Throwable e) { + logger.debug("Invalid config field: {} for {}", + StringMan.join(split, "."), toNodeName(instance.getClass().getSimpleName())); + e.printStackTrace(); return 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 bccf03232..621c9ee6f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1735,8 +1735,8 @@ public class Plot { public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { - logger.atDebug().addArgument(player.getName()).addArgument(this.getId().toCommaSeparatedString()) - .log("Player {} attempted to claim plot {}, but was not allowed"); + logger.debug("Player {} attempted to claim plot {}, but was not allowed", + player.getName(), this.getId().toCommaSeparatedString()); return false; } return claim(player, teleport, schematic, true); @@ -1835,8 +1835,8 @@ public class Plot { }); return true; } - logger.atInfo().addArgument(this.getId().toCommaSeparatedString()) - .addArgument(this.area.toString()).log("Failed to add plot {} to plot area {}"); + logger.info("Failed to add plot {} to plot area {}", + this.getId().toCommaSeparatedString(), this.area.toString()); return false; } @@ -1934,12 +1934,12 @@ public class Plot { */ public boolean moveData(Plot plot, Runnable whenDone) { if (!this.hasOwner()) { - logger.atDebug().addArgument(plot).log("{} is unowned (single)"); + logger.debug("{} is unowned (single)", plot); TaskManager.runTask(whenDone); return false; } if (plot.hasOwner()) { - logger.atDebug().addArgument(plot).log("{} is unowned (multi)"); + logger.debug("{} is unowned (multi)", plot); TaskManager.runTask(whenDone); return false; } @@ -2647,7 +2647,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2664,7 +2664,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.WEST)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2681,7 +2681,7 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.NORTH)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2697,7 +2697,7 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); if (!tmp.getMerged(Direction.EAST)) { // invalid merge - logger.atDebug().addArgument(this).log("Fixing invalid merge: {}"); + logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2712,10 +2712,7 @@ public class Plot { Plot current; while ((current = frontier.poll()) != null) { if (!current.hasOwner() || current.settings == null) { - // Invalid plot - // merged onto unclaimed plot - logger.atDebug().addArgument(current).addArgument(current.getOwnerAbs()) - .log("Ignoring invalid merged plot: {} | {}"); + logger.debug("Ignoring invalid merged plot: {} | {}", current, current.getOwnerAbs()); 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 64fc305b6..e74e51d2c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -1063,13 +1063,12 @@ public abstract class PlotArea { try { flags.add(flagInstance.parse(split[1])); } catch (final FlagParseException e) { - 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."); + logger.warn("Failed to parse default flag with key '{}' and value '{}'. " + + "Reason: {}. This flag will not be added as a default flag.", + e.getFlag().getName(), + e.getValue(), + e.getErrorMessage()); + e.printStackTrace(); } } } diff --git a/Core/src/main/resources/log4j.xml b/Core/src/main/resources/log4j.xml new file mode 100644 index 000000000..b450c1eca --- /dev/null +++ b/Core/src/main/resources/log4j.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + From d141b040d6fcbf85dd293c6591f655a1201a2953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 20:45:04 +0200 Subject: [PATCH 07/12] Fix relocations --- Bukkit/build.gradle | 3 ++- Bukkit/pom.xml | 24 ++++++++++++++++++------ Core/pom.xml | 18 +++++++++++++++--- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 53ad254f7..80d527cb1 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -109,7 +109,8 @@ shadowJar { relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') - relocate('org.apache.logging.log4j', 'com.plotsquared.logging') + relocate('org.apache.logging', 'com.plotsquared.logging.apache') + relocate('org.slf4j', 'com.plotsquared.logging.slf4j') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index fa9ecf402..81b4e9cf2 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -78,12 +78,6 @@ - - org.slf4j - slf4j-jdk14 - 2.0.0-alpha1 - compile - com.sk89q.worldedit worldedit-core @@ -170,6 +164,24 @@ 4.0-dev-106 runtime + + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-core + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-api + 2.13.3 + runtime + junit junit diff --git a/Core/pom.xml b/Core/pom.xml index 3a66b7985..75d0d059e 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -99,9 +99,21 @@ runtime - org.slf4j - slf4j-api - 2.0.0-alpha1 + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-core + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-api + 2.13.3 runtime From 1388f280e668bece1369eb843812cbc852bbb010 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Mon, 13 Jul 2020 20:46:34 +0200 Subject: [PATCH 08/12] Update module poms --- Bukkit/pom.xml | 24 ++++++++++++++++++------ Core/pom.xml | 18 +++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index fa9ecf402..81b4e9cf2 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -78,12 +78,6 @@ - - org.slf4j - slf4j-jdk14 - 2.0.0-alpha1 - compile - com.sk89q.worldedit worldedit-core @@ -170,6 +164,24 @@ 4.0-dev-106 runtime + + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-core + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-api + 2.13.3 + runtime + junit junit diff --git a/Core/pom.xml b/Core/pom.xml index 3a66b7985..75d0d059e 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -99,9 +99,21 @@ runtime - org.slf4j - slf4j-api - 2.0.0-alpha1 + org.apache.logging.log4j + log4j-slf4j-impl + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-core + 2.13.3 + runtime + + + org.apache.logging.log4j + log4j-api + 2.13.3 runtime From b109b7612051352f86c58d9c58db375a1f3791b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 20:50:49 +0200 Subject: [PATCH 09/12] Nevermind, it doesn't allow for relocations --- Bukkit/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 80d527cb1..eedb1cb4e 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -103,14 +103,15 @@ shadowJar { include(dependency('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3')) include(dependency('org.apache.logging.log4j:log4j-core:2.13.3')) include(dependency('org.apache.logging.log4j:log4j-api:2.13.3')) + include(dependency('org.slf4j:slf4j-api:1.7.26')) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') - relocate('org.apache.logging', 'com.plotsquared.logging.apache') - relocate('org.slf4j', 'com.plotsquared.logging.slf4j') + // relocate('org.apache.logging', 'com.plotsquared.logging.apache') + // relocate('org.slf4j', 'com.plotsquared.logging.slf4j') archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } From a1f262b5b206fbaf7b0d84332fb4cc03e1021a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 22:51:57 +0200 Subject: [PATCH 10/12] Fix gradle setup and replace all debug calls --- Bukkit/build.gradle | 17 +- Bukkit/pom.xml | 14 +- .../com/plotsquared/bukkit/BukkitMain.java | 12 +- .../entity/ReplicatingEntityWrapper.java | 10 +- .../bukkit/listener/ChunkListener.java | 5 +- .../bukkit/util/BukkitRegionManager.java | 4 +- .../plotsquared/bukkit/util/BukkitUtil.java | 2 +- .../plotsquared/bukkit/util/ContentMap.java | 2 +- .../bukkit/util/UpdateUtility.java | 2 +- Core/build.gradle | 4 +- Core/pom.xml | 14 +- .../com/plotsquared/core/PlotSquared.java | 25 ++- .../com/plotsquared/core/command/Claim.java | 2 +- .../com/plotsquared/core/command/Debug.java | 2 +- .../plotsquared/core/command/DebugExec.java | 2 +- .../com/plotsquared/core/command/Purge.java | 13 +- .../com/plotsquared/core/command/Trim.java | 2 +- .../components/ComponentPresetManager.java | 2 +- .../core/configuration/Config.java | 9 +- .../configuration/file/YamlConfiguration.java | 16 +- .../plotsquared/core/database/SQLManager.java | 160 +++++++++--------- .../com/plotsquared/core/database/SQLite.java | 2 +- .../core/generator/HybridPlotWorld.java | 15 +- .../core/generator/HybridUtils.java | 25 +-- .../core/generator/SquarePlotManager.java | 4 +- .../core/generator/SquarePlotWorld.java | 8 +- .../core/listener/ProcessedWEExtent.java | 4 +- .../core/player/ConsolePlayer.java | 2 +- .../plotsquared/core/player/PlotPlayer.java | 7 +- .../java/com/plotsquared/core/plot/Plot.java | 13 +- .../com/plotsquared/core/plot/PlotArea.java | 2 +- .../plotsquared/core/plot/PlotInventory.java | 8 +- .../core/plot/expiration/ExpireManager.java | 17 +- .../core/plot/expiration/PlotAnalysis.java | 133 +++++++++++---- .../core/plot/flag/FlagContainer.java | 2 +- .../plot/flag/types/BlockTypeWrapper.java | 7 +- .../core/plot/message/PlotMessage.java | 2 +- ...LocationOffsetDelegateLocalBlockQueue.java | 5 +- .../com/plotsquared/core/util/Expression.java | 8 +- .../core/util/LegacyConverter.java | 2 +- .../com/plotsquared/core/util/MainUtil.java | 5 +- .../plotsquared/core/util/RegionManager.java | 2 +- .../core/util/SchematicHandler.java | 10 +- .../core/util/net/IncendoPaster.java | 4 +- .../plotsquared/core/uuid/UUIDPipeline.java | 6 +- Core/src/main/resources/log4j.xml | 13 -- 46 files changed, 308 insertions(+), 317 deletions(-) delete mode 100644 Core/src/main/resources/log4j.xml diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index eedb1cb4e..91bcb10af 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -38,9 +38,7 @@ dependencies { compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } // logging - implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') - implementation('org.apache.logging.log4j:log4j-core:2.13.3') - implementation('org.apache.logging.log4j:log4j-api:2.13.3') + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1') } sourceCompatibility = 1.8 @@ -99,19 +97,18 @@ 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")) - include(dependency('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3')) - include(dependency('org.apache.logging.log4j:log4j-core:2.13.3')) - include(dependency('org.apache.logging.log4j:log4j-api:2.13.3')) - include(dependency('org.slf4j:slf4j-api:1.7.26')) + include(dependency('org.apache.logging.log4j:log4j-slf4j-impl')) + include(dependency('org.slf4j:slf4j-api')) } relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("org.bstats", "com.plotsquared.metrics") relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid') relocate('org.khelekore.prtree', 'com.plotsquared.prtree') - // relocate('org.apache.logging', 'com.plotsquared.logging.apache') - // relocate('org.slf4j', 'com.plotsquared.logging.slf4j') + relocate('org.apache.logging.slf4j', 'com.plotsquared.logging.apache') + relocate('org.slf4j', 'com.plotsquared.logging.slf4j') + + archiveFileName = "${project.name}-${parent.version}.jar" destinationDirectory = file "../target" } diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index 81b4e9cf2..f06146a52 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -167,19 +167,7 @@ org.apache.logging.log4j log4j-slf4j-impl - 2.13.3 - runtime - - - org.apache.logging.log4j - log4j-core - 2.13.3 - runtime - - - org.apache.logging.log4j - log4j-api - 2.13.3 + 2.8.1 runtime diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 1c9588b90..ca3406018 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -101,7 +101,6 @@ import com.plotsquared.core.util.ReflectionUtils; import com.plotsquared.core.util.RegionManager; 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.task.TaskManager; import com.plotsquared.core.uuid.CacheUUIDService; @@ -161,7 +160,7 @@ 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 Logger logger = LoggerFactory.getLogger("P2/" + BukkitMain.class.getSimpleName()); private static final int BSTATS_ID = 1404; @Getter private static WorldEdit worldEdit; @@ -195,8 +194,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } } catch (NumberFormatException e) { e.printStackTrace(); - logger.debug(StringMan.getString(Bukkit.getBukkitVersion())); - logger.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\."))); return new int[] {1, 13, 0}; } } @@ -445,7 +442,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final Chunk[] chunks = world.getLoadedChunks(); if (chunks.length == 0) { if (!Bukkit.unloadWorld(world, true)) { - logger.debug("Failed to unload {}", world.getName()); + logger.warn("Failed to unload {}", world.getName()); } return; } else { @@ -536,7 +533,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< uuidList.clear(); // Print progress final double percentage = ((double) read / (double) totalSize) * 100.0D; - logger.debug("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); + if (Settings.DEBUG) { + logger.info("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); + } } catch (final InterruptedException | ExecutionException e) { logger.error("(UUID) Failed to retrieve last batch. Will try again", e); e.printStackTrace(); @@ -897,7 +896,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return econ; } } catch (Throwable ignored) { - logger.debug("No economy handler detected"); } return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java index 9320fa39e..253de36ae 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java @@ -25,6 +25,7 @@ */ package com.plotsquared.bukkit.entity; +import com.plotsquared.core.configuration.Settings; import org.bukkit.Art; import org.bukkit.DyeColor; import org.bukkit.Location; @@ -61,7 +62,7 @@ import java.util.List; public final class ReplicatingEntityWrapper extends EntityWrapper { - private static final Logger logger = LoggerFactory.getLogger(ReplicatingEntityWrapper.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ReplicatingEntityWrapper.class.getSimpleName()); private final short depth; private final int hash; @@ -331,10 +332,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { this.dataByte = (byte) 0; } storeLiving((LivingEntity) entity); - return; // END LIVING // - default: - logger.debug("Could not identify entity: {}", entity.getType()); } } @@ -733,7 +731,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { restoreLiving((LivingEntity) entity); return entity; default: - logger.debug("Could not identify entity: {}", entity.getType()); + if (Settings.DEBUG) { + logger.info("Could not identify entity: {}", entity.getType()); + } return entity; // END LIVING } 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 feab438f6..39384ad0f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java @@ -62,7 +62,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; @SuppressWarnings("unused") public class ChunkListener implements Listener { - private static final Logger logger = LoggerFactory.getLogger(ChunkListener.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ChunkListener.class.getSimpleName()); private RefMethod methodGetHandleChunk; private RefField mustSave; @@ -294,12 +294,9 @@ public class ChunkListener implements Listener { toRemove--; } } - - logger.debug("PlotSquared detected chunk and processed it: {},{}", chunk.getX() << 4, chunk.getZ() << 4); } if (tiles.length > Settings.Chunk_Processor.MAX_TILES) { if (unload) { - logger.debug("PlotSquared detected chunk: {},{}", chunk.getX() << 4, chunk.getZ() << 4); cleanChunk(chunk); return true; } 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 f54cedccf..0c1bd798b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java @@ -76,7 +76,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; public class BukkitRegionManager extends RegionManager { - private static final Logger logger = LoggerFactory.getLogger(BukkitRegionManager.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName()); public static boolean isIn(CuboidRegion region, int x, int z) { return x >= region.getMinimumPoint().getX() && x <= region.getMaximumPoint().getX() @@ -93,8 +93,6 @@ public class BukkitRegionManager extends RegionManager { } else { final Semaphore semaphore = new Semaphore(1); try { - logger.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), () -> { for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)) 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 373dac19a..286458614 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -112,7 +112,7 @@ import java.util.stream.Stream; @SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil { - private static final Logger logger = LoggerFactory.getLogger(BukkitUtil.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName()); private static String lastString = null; private static World lastWorld = null; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java index 3563b125b..78d941808 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java @@ -47,7 +47,7 @@ import java.util.Set; public class ContentMap { - private static final Logger logger = LoggerFactory.getLogger(ContentMap.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ContentMap.class.getSimpleName()); final Set entities; final Map allBlocks; 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 d3ed81cb8..c28fe8740 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -45,7 +45,7 @@ import java.net.URL; public class UpdateUtility implements Listener { - private static final Logger logger = LoggerFactory.getLogger(UpdateUtility.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + UpdateUtility.class.getSimpleName()); public static PlotVersion internalVersion; public static String spigotVersion; diff --git a/Core/build.gradle b/Core/build.gradle index 0f3e54412..3b3779868 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -19,9 +19,7 @@ dependencies { implementation("org.jetbrains:annotations:19.0.0") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") // logging - implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.13.3') - implementation('org.apache.logging.log4j:log4j-core:2.13.3') - implementation('org.apache.logging.log4j:log4j-api:2.13.3') + implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.8.1") } sourceCompatibility = 1.8 diff --git a/Core/pom.xml b/Core/pom.xml index 75d0d059e..f69929bfa 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -101,19 +101,7 @@ org.apache.logging.log4j log4j-slf4j-impl - 2.13.3 - runtime - - - org.apache.logging.log4j - log4j-core - 2.13.3 - runtime - - - org.apache.logging.log4j - log4j-api - 2.13.3 + 2.8.1 runtime diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index f8f38e963..4c50026e4 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -27,7 +27,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.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; @@ -137,7 +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 Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName()); + private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet()); private static PlotSquared instance; // Implementation @@ -196,9 +196,9 @@ public class PlotSquared { try { new ReflectionUtils(this.IMP.getNMSPackage()); try { - URL url = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation(); + URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation(); this.jarFile = new File( - new URL(url.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file")) + new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file")) .toURI().getPath()); } catch (MalformedURLException | URISyntaxException | SecurityException e) { e.printStackTrace(); @@ -329,11 +329,11 @@ public class PlotSquared { continue; } if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { - logger.debug("`{}` was not properly loaded - {} will now try to load it properly", + logger.warn("`{}` 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."); + logger.warn(" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); + logger.warn(" - Your world management plugin may be faulty (or non existent)"); + logger.warn(" This message may also be a false positive and could be ignored."); PlotSquared.this.IMP.setGenerator(world); } } @@ -364,7 +364,6 @@ public class PlotSquared { e.printStackTrace(); } - logger.debug("{} is now enabled!", imp().getPluginName()); } /** @@ -511,8 +510,8 @@ public class PlotSquared { chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1]))); int height = (int) list.get(2); logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height); - logger.debug(" Regions: {}", regions.size()); - logger.debug(" Chunks: {}", chunks.size()); + logger.info(" - Regions: {}", regions.size()); + logger.info(" - Chunks: {}", chunks.size()); HybridUtils.UPDATE = true; HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks); } catch (IOException | ClassNotFoundException e) { @@ -1079,7 +1078,6 @@ public class PlotSquared { } if (type == PlotAreaType.NORMAL) { if (plotAreaManager.getPlotAreas(world, null).length != 0) { - logger.debug("Would possibly already loaded: {}", world); return; } IndependentPlotGenerator plotGenerator; @@ -1132,7 +1130,6 @@ public class PlotSquared { ConfigurationSection areasSection = worldSection.getConfigurationSection("areas"); if (areasSection == null) { if (plotAreaManager.getPlotAreas(world, null).length != 0) { - logger.debug("World possibly already loaded: {}", world); return; } logger.info("Detected world load for '{}'", world); @@ -1765,7 +1762,7 @@ public class PlotSquared { if (Settings.DEBUG) { Map components = Settings.getFields(Settings.Enabled_Components.class); for (Entry component : components.entrySet()) { - logger.debug("Key: {} | Value: {}", component.getKey(), component.getValue()); + logger.info("Key: {} | Value: {}", component.getKey(), component.getValue()); } } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 02990a107..6dcda8c43 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -56,7 +56,7 @@ import org.slf4j.LoggerFactory; usage = "/plot claim") public class Claim extends SubCommand { - private static final Logger logger = LoggerFactory.getLogger(Claim.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName()); @Override public boolean onCommand(final PlotPlayer player, String[] args) { String schematic = null; 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 677003483..c395f09d8 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -50,7 +50,7 @@ import java.util.Map; permission = "plots.admin") public class Debug extends SubCommand { - private static final Logger logger = LoggerFactory.getLogger(Debug.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Debug.class.getSimpleName()); @Override public boolean onCommand(PlotPlayer player, String[] args) { if (args.length > 0) { 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 91b9fbf91..842d403b7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -84,7 +84,7 @@ import java.util.concurrent.CompletableFuture; category = CommandCategory.DEBUG) public class DebugExec extends SubCommand { - private static final Logger logger = LoggerFactory.getLogger(DebugExec.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + DebugExec.class.getSimpleName()); private ScriptEngine engine; private Bindings scope; 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 8c155fff5..7d714a224 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -55,7 +55,7 @@ import java.util.concurrent.atomic.AtomicBoolean; confirmation = true) public class Purge extends SubCommand { - private static final Logger logger = LoggerFactory.getLogger(Purge.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Purge.class.getSimpleName()); @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { @@ -174,7 +174,9 @@ 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..."); + if (Settings.DEBUG) { + logger.info("Calculating plots to purge, please wait..."); + } HashSet ids = new HashSet<>(); Iterator iterator = toDelete.iterator(); AtomicBoolean cleared = new AtomicBoolean(true); @@ -187,8 +189,11 @@ public class Purge extends SubCommand { try { ids.add(plot.temp); if (finalClear) { - plot.clear(false, true, () -> - logger.debug("Plot {} cleared by purge", plot.getId())); + plot.clear(false, true, () -> { + if (Settings.DEBUG) { + logger.info("Plot {} cleared by purge", plot.getId()); + } + }); } else { plot.removeSign(); } 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 d90277602..cd8e14434 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -64,7 +64,7 @@ import java.util.Set; category = CommandCategory.ADMINISTRATION) public class Trim extends SubCommand { - private static final Logger logger = LoggerFactory.getLogger(Trim.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Trim.class.getSimpleName()); public static ArrayList expired = null; private static volatile boolean TASK = false; 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 d6e13a278..76b4d8ab2 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -59,7 +59,7 @@ import java.util.stream.Collectors; public class ComponentPresetManager { - private static final Logger logger = LoggerFactory.getLogger(ComponentPresetManager.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ComponentPresetManager.class.getSimpleName()); private final List presets; private final String guiName; 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 139e0dffd..3f75eb56f 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Config.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Config.java @@ -47,7 +47,7 @@ import java.util.Map; public class Config { - private static final Logger logger = LoggerFactory.getLogger(Config.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Config.class.getSimpleName()); /** * Get the value for a node
@@ -71,7 +71,6 @@ public class Config { } } } - logger.debug("Failed to get config option: {}", key); return null; } @@ -99,12 +98,12 @@ public class Config { field.set(instance, value); return; } catch (final Throwable e) { - logger.debug("Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); + logger.error("Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); e.printStackTrace(); } } } - logger.debug("Failed to set config option '{}: {}' | {}", key, value, instance); + logger.error("Failed to set config option '{}: {}' | {}", key, value, instance); } public static boolean load(File file, Class root) { @@ -290,7 +289,7 @@ public class Config { setAccessible(field); return field; } catch (final Throwable e) { - logger.debug("Invalid config field: {} for {}", + logger.error("Invalid config field: {} for {}", StringMan.join(split, "."), toNodeName(instance.getClass().getSimpleName())); e.printStackTrace(); return null; diff --git a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java index ee1dec7d5..027ee7d4c 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java @@ -25,10 +25,10 @@ */ package com.plotsquared.core.configuration.file; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Configuration; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.InvalidConfigurationException; +import com.plotsquared.core.configuration.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.DumperOptions; @@ -48,7 +48,7 @@ import java.util.Map; */ public class YamlConfiguration extends FileConfiguration { - private static final Logger logger = LoggerFactory.getLogger(YamlConfiguration.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + YamlConfiguration.class.getSimpleName()); private static final String COMMENT_PREFIX = "# "; private static final String BLANK_CONFIG = "{}\n"; @@ -81,11 +81,13 @@ public class YamlConfiguration extends FileConfiguration { dest = new File(file.getAbsolutePath() + "_broken_" + i++); } Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); - logger.debug("Could not read: {}", file); - logger.debug("Renamed to: {}", file); - logger.debug("============ Full stacktrace ============"); - ex.printStackTrace(); - logger.debug("========================================="); + if (Settings.DEBUG) { + logger.error("Could not read: {}", file); + logger.error("Renamed to: {}", file); + logger.error("============ Full stacktrace ============"); + ex.printStackTrace(); + logger.error("========================================="); + } } catch (IOException e) { e.printStackTrace(); } 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 a58eec7f9..c2a363d6b 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -80,7 +80,7 @@ import java.util.concurrent.atomic.AtomicInteger; @SuppressWarnings("SqlDialectInspection") public class SQLManager implements AbstractDB { - private static final Logger logger = LoggerFactory.getLogger(SQLManager.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + SQLManager.class.getSimpleName()); // Public final public final String SET_OWNER; @@ -358,12 +358,12 @@ public class SQLManager implements AbstractDB { try { task.run(); } catch (Throwable e) { - 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"); + logger.error("============ DATABASE ERROR ============"); + logger.error("============ DATABASE ERROR ============"); + logger.error("There was an error updating the database."); + logger.error(" - It will be corrected on shutdown"); e.printStackTrace(); - logger.debug("========================================"); + logger.error("========================================"); } } commit(); @@ -413,12 +413,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.debug("============ DATABASE ERROR ============"); - logger.debug("There was an error updating the database."); - logger.debug(" - It will be corrected on shutdown"); - logger.debug("========================================"); + logger.error("============ DATABASE ERROR ============"); + logger.error("There was an error updating the database."); + logger.error(" - It will be corrected on shutdown"); + logger.error("========================================"); e.printStackTrace(); - logger.debug("========================================"); + logger.error("========================================"); } } if (statement != null && task != null) { @@ -458,12 +458,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.debug("============ DATABASE ERROR ============"); - logger.debug("There was an error updating the database."); - logger.debug(" - It will be corrected on shutdown"); - logger.debug("========================================"); + logger.error("============ DATABASE ERROR ============"); + logger.error("There was an error updating the database."); + logger.error(" - It will be corrected on shutdown"); + logger.error("========================================"); e.printStackTrace(); - logger.debug("========================================"); + logger.error("========================================"); } } if (statement != null && task != null) { @@ -504,12 +504,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.debug("============ DATABASE ERROR ============"); - logger.debug("There was an error updating the database."); - logger.debug(" - It will be corrected on shutdown"); - logger.debug("========================================"); + logger.error("============ DATABASE ERROR ============"); + logger.error("There was an error updating the database."); + logger.error(" - It will be corrected on shutdown"); + logger.error("========================================"); e.printStackTrace(); - logger.debug("========================================"); + logger.error("========================================"); } } if (statement != null && task != null) { @@ -533,12 +533,12 @@ public class SQLManager implements AbstractDB { this.plotTasks.clear(); } } catch (Throwable e) { - logger.debug("============ DATABASE ERROR ============"); - logger.debug("There was an error updating the database."); - logger.debug(" - It will be corrected on shutdown"); - logger.debug("========================================"); + logger.error("============ DATABASE ERROR ============"); + logger.error("There was an error updating the database."); + logger.error(" - It will be corrected on shutdown"); + logger.error("========================================"); e.printStackTrace(); - logger.debug("========================================"); + logger.error("========================================"); } return false; } @@ -626,7 +626,7 @@ public class SQLManager implements AbstractDB { } }))))); } catch (SQLException e) { - logger.error("Failed to set all flags and member tiers for plots", e); + logger.warn("Failed to set all flags and member tiers for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -635,7 +635,7 @@ public class SQLManager implements AbstractDB { } }); } catch (Exception e) { - logger.debug("Warning! Failed to set all helper for plots", e); + logger.warn("Warning! Failed to set all helper for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -704,10 +704,14 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - logger.error("Failed to store flag values for plot with entry ID: {}", e); + logger.error("Failed to store flag values for plot with entry ID: {}", plot); + e.printStackTrace(); continue; } - logger.debug("- Finished converting flag values for plot with entry ID: {}", plot.getId()); + if (Settings.DEBUG) { + logger.info("- Finished converting flag values for plot with entry ID: {}", + plot.getId()); + } } } catch (final Exception e) { logger.error("Failed to store flag values", e); @@ -820,7 +824,6 @@ public class SQLManager implements AbstractDB { last = subList.size(); preparedStmt.addBatch(); } - logger.debug("Batch 1: {} | {}", count, objList.get(0).getClass().getCanonicalName()); preparedStmt.executeBatch(); preparedStmt.clearParameters(); preparedStmt.close(); @@ -863,7 +866,6 @@ public class SQLManager implements AbstractDB { last = subList.size(); preparedStmt.addBatch(); } - logger.debug("Batch 2: {} | {}", count, objList.get(0).getClass().getCanonicalName()); preparedStmt.executeBatch(); preparedStmt.clearParameters(); preparedStmt.close(); @@ -877,7 +879,6 @@ public class SQLManager implements AbstractDB { mod.setSQL(preparedStmt, obj); preparedStmt.addBatch(); } - logger.debug("Batch 3"); preparedStmt.executeBatch(); } catch (SQLException e3) { logger.error("Failed to save all", e); @@ -1129,7 +1130,6 @@ public class SQLManager implements AbstractDB { return; } boolean addConstraint = create == tables.length; - logger.debug("Creating tables"); try (Statement stmt = this.connection.createStatement()) { if (this.mySQL) { stmt.addBatch("CREATE TABLE IF NOT EXISTS `" + this.prefix + "plot` (" @@ -1369,8 +1369,6 @@ public class SQLManager implements AbstractDB { * @param plot */ @Override public void delete(final Plot plot) { - logger.debug("Deleting plot. ID: {} | World: {} | Owner: {} | Index: {}", - plot.getId(), plot.getWorldName(), plot.getOwnerAbs(), plot.temp); deleteSettings(plot); deleteDenied(plot); deleteHelpers(plot); @@ -1396,8 +1394,6 @@ public class SQLManager implements AbstractDB { * @param plot */ @Override public void createPlotSettings(final int id, Plot plot) { - 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); @@ -1555,7 +1551,6 @@ 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()) { - logger.debug("Backing up {}", this.prefix + table); result.close(); statement.executeUpdate( "CREATE TABLE " + this.prefix + table + "_tmp AS SELECT * FROM " @@ -1565,7 +1560,6 @@ 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"); - logger.debug("Restoring {}", this.prefix + table); } } } catch (SQLException e2) { @@ -1682,7 +1676,10 @@ public class SQLManager implements AbstractDB { String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100)); } - logger.debug("- Finished converting flags for plot with entry ID: {}", plotFlagEntry.getKey()); + if (Settings.DEBUG) { + logger.info("- Finished converting flags for plot with entry ID: {}", + plotFlagEntry.getKey()); + } } } catch (final Exception e) { logger.error("Failed to store flag values", e); @@ -1791,8 +1788,8 @@ public class SQLManager implements AbstractDB { if (last != null) { if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(last.temp); - } else { - logger.debug("Plot #{}({}) in `{}plot` is a duplicate." + } else if (Settings.DEBUG) { + logger.info("Plot #{}({}) in `{}plot` is a duplicate." + " Delete this plot or set `database-purger: true` in the settings.yml", id, last, this.prefix); } } @@ -1823,8 +1820,8 @@ public class SQLManager implements AbstractDB { plot.getSettings().getRatings().put(user, r.getInt("rating")); } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_rating` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_rating` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1851,8 +1848,8 @@ public class SQLManager implements AbstractDB { plot.getTrusted().add(user); } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_helpers` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_helpers` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1878,8 +1875,8 @@ public class SQLManager implements AbstractDB { plot.getMembers().add(user); } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_trusted` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_trusted` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1905,8 +1902,8 @@ public class SQLManager implements AbstractDB { plot.getDenied().add(user); } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_denied` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_denied` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1928,15 +1925,14 @@ public class SQLManager implements AbstractDB { final PlotFlag plotFlag = GlobalFlagContainer.getInstance().getFlagFromString(flag); if (plotFlag == null) { - 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(); - logger.debug("Plot with ID {} has an invalid value:", id); - logger.debug("Failed to parse flag '{}', value '{}': {}", + logger.error("Plot with ID {} has an invalid value:", id); + logger.error("Failed to parse flag '{}', value '{}': {}", plotFlag.getName(), e.getValue(), e.getErrorMessage()); if (!invalidFlags.containsKey(plot)) { invalidFlags.put(plot, new ArrayList<>()); @@ -1946,8 +1942,8 @@ public class SQLManager implements AbstractDB { } } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_flags` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_flags` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1957,8 +1953,11 @@ public class SQLManager implements AbstractDB { for (final Map.Entry>> plotFlagEntry : invalidFlags .entrySet()) { for (final PlotFlag flag : plotFlagEntry.getValue()) { - logger.debug("Plot {} has an invalid flag ({}). A fix has been attempted", - plotFlagEntry.getKey(), flag.getName()); + if (Settings.DEBUG) { + logger.info( + "Plot {} has an invalid flag ({}). A fix has been attempted", + plotFlagEntry.getKey(), flag.getName()); + } removeFlag(plotFlagEntry.getKey(), flag); } } @@ -1999,8 +1998,8 @@ public class SQLManager implements AbstractDB { plot.getSettings().setMerged(merged); } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); - } else { - logger.debug("Entry #{}({}) in `plot_settings` does not exist." + } else if (Settings.DEBUG) { + logger.info("Entry #{}({}) in `plot_settings` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -2017,11 +2016,13 @@ public class SQLManager implements AbstractDB { for (Entry entry : noExist.entrySet()) { String worldName = entry.getKey(); invalidPlot = true; - logger.debug("Warning! Found {} plots in DB for non existent world: '{}'", - entry.getValue().intValue(), worldName); + if (Settings.DEBUG) { + logger.info("Warning! Found {} plots in DB for non existent world: '{}'", + entry.getValue().intValue(), worldName); + } } - if (invalidPlot) { - logger.debug("Warning! Please create the world(s) or remove the plots using the purge command"); + if (invalidPlot && Settings.DEBUG) { + logger.info("Warning! Please create the world(s) or remove the plots using the purge command"); } } catch (SQLException e) { logger.error("Failed to load plots", e); @@ -2163,8 +2164,6 @@ public class SQLManager implements AbstractDB { int count = 0; int last = -1; for (int j = 0; j <= amount; j++) { - int purging = Math.max(j * packet, size); - logger.debug("Purging {}/{}", purging, size); List subList = uniqueIdsList.subList(j * packet, Math.min(size, (j + 1) * packet)); if (subList.isEmpty()) { @@ -2214,7 +2213,9 @@ public class SQLManager implements AbstractDB { return; } } - logger.debug("Successfully purged {} plots", uniqueIds.size()); + if (Settings.DEBUG) { + logger.info("Successfully purged {} plots", uniqueIds.size()); + } } }); } @@ -2714,8 +2715,8 @@ public class SQLManager implements AbstractDB { cluster = clusters.get(id); if (cluster != null) { cluster.helpers.add(user); - } else { - logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + } else if (Settings.DEBUG) { + logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2733,8 +2734,8 @@ public class SQLManager implements AbstractDB { cluster = clusters.get(id); if (cluster != null) { cluster.invited.add(user); - } else { - logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + } else if (Settings.DEBUG) { + logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2768,8 +2769,8 @@ public class SQLManager implements AbstractDB { merged[3 - i] = (m & 1 << i) != 0; } cluster.settings.setMerged(merged); - } else { - logger.debug("Cluster #{}({}) in cluster_helpers does not exist." + } else if (Settings.DEBUG) { + logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2779,10 +2780,10 @@ public class SQLManager implements AbstractDB { for (Entry entry : noExist.entrySet()) { String a = entry.getKey(); invalidPlot = true; - logger.debug("Warning! Found {} clusters in DB for non existent area; '{}'", noExist.get(a), a); + logger.warn("Warning! Found {} clusters in DB for non existent area; '{}'", noExist.get(a), a); } if (invalidPlot) { - logger.debug("Warning! Please create the world(s) or remove the clusters using the purge command"); + logger.warn("Warning! Please create the world(s) or remove the clusters using the purge command"); } } catch (SQLException e) { logger.error("Failed to load clusters", e); @@ -2977,7 +2978,7 @@ public class SQLManager implements AbstractDB { if (!isValid()) { reconnect(); } - logger.debug("All DB transactions during this session are being validated (This may take a while if corrections need to be made)"); + logger.info("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()) { @@ -3009,19 +3010,16 @@ public class SQLManager implements AbstractDB { } HashMap worldPlots = database.get(plot.getArea().toString()); if (worldPlots == null) { - logger.debug(" - Creating plot (1): {}", plot); toCreate.add(plot); continue; } Plot dataPlot = worldPlots.remove(plot.getId()); if (dataPlot == null) { - logger.debug(" - Creating plot (2): {}", plot); toCreate.add(plot); continue; } // owner if (!plot.getOwnerAbs().equals(dataPlot.getOwnerAbs())) { - logger.debug(" - Setting owner: {} -> {}", plot, MainUtil.getName(plot.getOwnerAbs())); setOwner(plot, plot.getOwnerAbs()); } // trusted @@ -3030,7 +3028,6 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getTrusted().clone(); toRemove.removeAll(plot.getTrusted()); toAdd.removeAll(dataPlot.getTrusted()); - logger.debug(" - Correcting {} trusted for: {}", toAdd.size() + toRemove.size(), plot); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeTrusted(plot, uuid); @@ -3047,7 +3044,6 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getMembers().clone(); toRemove.removeAll(plot.getMembers()); toAdd.removeAll(dataPlot.getMembers()); - logger.debug(" - Correcting {} members for: {}", toAdd.size() + toRemove.size()); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeMember(plot, uuid); @@ -3064,7 +3060,6 @@ public class SQLManager implements AbstractDB { HashSet toRemove = (HashSet) dataPlot.getDenied().clone(); toRemove.removeAll(plot.getDenied()); toAdd.removeAll(dataPlot.getDenied()); - logger.debug(" - Correcting {} denied for: {}", toAdd.size() + toRemove.size()); if (!toRemove.isEmpty()) { for (UUID uuid : toRemove) { removeDenied(plot, uuid); @@ -3079,7 +3074,6 @@ public class SQLManager implements AbstractDB { boolean[] pm = plot.getMerged(); boolean[] dm = dataPlot.getMerged(); if (pm[0] != dm[0] || pm[1] != dm[1]) { - logger.debug(" - Correcting merge for: {}", plot); setMerged(dataPlot, plot.getMerged()); } Set> pf = plot.getFlags(); 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 eb12a4672..fd9ba5027 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLite.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLite.java @@ -42,7 +42,7 @@ import java.sql.Statement; */ public class SQLite extends Database { - private static final Logger logger = LoggerFactory.getLogger(SQLite.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + SQLite.class.getSimpleName()); private final String dbLocation; private Connection connection; 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 4e1b2157d..496acc747 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -60,7 +60,7 @@ import java.util.Locale; public class HybridPlotWorld extends ClassicPlotWorld { - private static final Logger logger = LoggerFactory.getLogger(HybridPlotWorld.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + HybridPlotWorld.class.getSimpleName()); private static final AffineTransform transform = new AffineTransform().rotateY(90); public boolean ROAD_SCHEMATIC_ENABLED; public boolean PLOT_SCHEMATIC = false; @@ -160,12 +160,11 @@ public class HybridPlotWorld extends ClassicPlotWorld { setupSchematics(); } catch (Exception event) { event.printStackTrace(); - logger.debug("- road schematics are disabled for this world"); } // Dump world settings if (Settings.DEBUG) { - logger.debug("- Dumping settings for ClassicPlotWorld with name {}", this.getWorldName()); + logger.info("- 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); @@ -181,7 +180,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } catch (final IllegalAccessException e) { value = String.format("Failed to parse: %s", e.getMessage()); } - logger.debug("-- {} = {}", name, value); + logger.info("-- {} = {}", name, value); } } } @@ -282,10 +281,14 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } - logger.debug(" - plot schematic: {}", schematic3File.getPath()); + if (Settings.DEBUG) { + logger.info(" - plot schematic: {}", schematic3File.getPath()); + } } if (schematic1 == null || schematic2 == null || this.ROAD_WIDTH == 0) { - logger.debug(" - schematic: false"); + if (Settings.DEBUG) { + logger.info(" - schematic: false"); + } return; } this.ROAD_SCHEMATIC_ENABLED = true; 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 084e0a33b..209eddec1 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -78,7 +78,7 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class HybridUtils { - private static final Logger logger = LoggerFactory.getLogger(HybridUtils.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + HybridUtils.class.getSimpleName()); public static HybridUtils manager; public static Set regions; @@ -412,12 +412,14 @@ public abstract class HybridUtils { BlockVector2 chunk = iter.next(); iter.remove(); boolean regenedRoad = regenerateRoad(area, chunk, extend); - if (!regenedRoad) { - logger.debug("Failed to regenerate roads"); + if (!regenedRoad && Settings.DEBUG) { + logger.info("Failed to regenerate roads"); } ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true); } - logger.debug("Cancelled road task"); + if (Settings.DEBUG) { + logger.info("Cancelled road task"); + } return; } count.incrementAndGet(); @@ -425,7 +427,6 @@ public abstract class HybridUtils { logger.info("Progress: {}%", 100 * (2048 - chunks.size()) / 2048); } if (HybridUtils.regions.isEmpty() && chunks.isEmpty()) { - logger.debug("Regenerating plot walls"); regeneratePlotWalls(area); HybridUtils.UPDATE = false; @@ -441,8 +442,11 @@ public abstract class HybridUtils { HybridUtils.regions.iterator(); BlockVector2 loc = iterator.next(); iterator.remove(); - logger.debug("Updating .mcr: {}, {} (approx 1024 chunks)", loc.getX(), loc.getZ()); - logger.debug("- Remaining: {}", HybridUtils.regions.size()); + if (Settings.DEBUG) { + logger.info("Updating .mcr: {}, {} (approx 1024 chunks)", + loc.getX(), loc.getZ()); + logger.info("- Remaining: {}", HybridUtils.regions.size()); + } chunks.addAll(getChunks(loc)); System.gc(); } @@ -458,8 +462,8 @@ public abstract class HybridUtils { iterator.remove(); boolean regenedRoads = regenerateRoad(area, chunk, extend); - if (!regenedRoads) { - logger.debug("Failed to regenerate road"); + if (!regenedRoads && Settings.DEBUG) { + logger.info("Failed to regenerate road"); } } } @@ -470,7 +474,7 @@ public abstract class HybridUtils { Iterator iterator = HybridUtils.regions.iterator(); BlockVector2 loc = iterator.next(); iterator.remove(); - logger.debug("Error! Could not update '{}/region/r.{}.{}.mca' (Corrupt chunk?)", + logger.error("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; @@ -481,7 +485,6 @@ public abstract class HybridUtils { true); } } - logger.debug("- Potentially skipping 1024 chunks"); } GlobalBlockQueue.IMP.addEmptyTask(() -> TaskManager.runTaskLater(task, 20)); }); diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java index 531d2de92..1da8d0ed3 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java @@ -44,7 +44,7 @@ import java.util.Set; */ public abstract class SquarePlotManager extends GridPlotManager { - private static final Logger logger = LoggerFactory.getLogger(SquarePlotManager.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + SquarePlotManager.class.getSimpleName()); private final SquarePlotWorld squarePlotWorld; @@ -229,7 +229,7 @@ public abstract class SquarePlotManager extends GridPlotManager { return plot.getMerged(Direction.NORTHWEST) ? id : null; } } catch (Exception ignored) { - logger.debug( "Invalid plot / road width in settings.yml for world: {}", squarePlotWorld + logger.error( "Invalid plot / road width in settings.yml for world: {}", squarePlotWorld .getWorldName()); } return null; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index a7270105e..f2a6b2284 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -26,6 +26,7 @@ package com.plotsquared.core.generator; import com.plotsquared.core.configuration.ConfigurationSection; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.plot.PlotId; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -33,7 +34,7 @@ import org.slf4j.LoggerFactory; public abstract class SquarePlotWorld extends GridPlotWorld { - private static final Logger logger = LoggerFactory.getLogger(SquarePlotWorld.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + SquarePlotWorld.class.getSimpleName()); public int PLOT_WIDTH = 42; public int ROAD_WIDTH = 7; @@ -47,7 +48,10 @@ public abstract class SquarePlotWorld extends GridPlotWorld { @Override public void loadConfiguration(ConfigurationSection config) { if (!config.contains("plot.height")) { - logger.debug(" - Configuration is null? ({})", config.getCurrentPath()); + if (Settings.DEBUG) { + logger.info(" - Configuration is null? ({})", config.getCurrentPath()); + } + } this.PLOT_WIDTH = config.getInt("plot.size"); this.ROAD_WIDTH = config.getInt("road.width"); 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 191309c99..3e52f8a95 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java +++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java @@ -52,7 +52,7 @@ import java.util.Set; public class ProcessedWEExtent extends AbstractDelegateExtent { - private static final Logger logger = LoggerFactory.getLogger(ProcessedWEExtent.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ProcessedWEExtent.class.getSimpleName()); private final Set mask; private final String world; @@ -103,7 +103,6 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { return false; } else { tileEntityCount[0]++; - logger.debug("Detected unsafe WorldEdit: {},{},{}", location.getX(), location.getY(), location.getZ()); } } if (WEManager.maskContains(this.mask, location.getX(), location.getY(), location.getZ())) { @@ -134,7 +133,6 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { this.Ecount++; if (this.Ecount > Settings.Chunk_Processor.MAX_ENTITIES) { this.Eblocked = true; - 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/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index 970aad919..410b20925 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -45,7 +45,7 @@ import java.util.UUID; public class ConsolePlayer extends PlotPlayer { - private static final Logger logger = LoggerFactory.getLogger(ConsolePlayer.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + ConsolePlayer.class.getSimpleName()); private static ConsolePlayer instance; private ConsolePlayer() { 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 56a32e328..304317c10 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -75,7 +75,7 @@ import java.util.stream.Collectors; */ public abstract class PlotPlayer

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

implements CommandCaller, OfflinePlotPlayer if (Settings.Enabled_Components.BAN_DELETER && isBanned()) { for (Plot owned : getPlots()) { owned.deletePlot(null); - logger.debug("Plot {} was deleted + cleared due to {} getting banned", - owned.getId(), getName()); + if (Settings.DEBUG) { + logger.info("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 621c9ee6f..be1efa86e 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -119,7 +119,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE; */ public class Plot { - private static final Logger logger = LoggerFactory.getLogger(Plot.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName()); public static final int MAX_HEIGHT = 256; @@ -1735,8 +1735,6 @@ public class Plot { public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { - logger.debug("Player {} attempted to claim plot {}, but was not allowed", - player.getName(), this.getId().toCommaSeparatedString()); return false; } return claim(player, teleport, schematic, true); @@ -1747,7 +1745,7 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { - logger.debug("Player {} attempted to claim plot {}, but the database failed to update", + logger.error("Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString()); return false; } @@ -1934,12 +1932,10 @@ public class Plot { */ public boolean moveData(Plot plot, Runnable whenDone) { if (!this.hasOwner()) { - logger.debug("{} is unowned (single)", plot); TaskManager.runTask(whenDone); return false; } if (plot.hasOwner()) { - logger.debug("{} is unowned (multi)", plot); TaskManager.runTask(whenDone); return false; } @@ -2647,7 +2643,6 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH)); if (!tmp.getMerged(Direction.SOUTH)) { // invalid merge - logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.SOUTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2664,7 +2659,6 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.WEST)) { // invalid merge - logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.WEST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2681,7 +2675,6 @@ public class Plot { assert tmp != null; if (!tmp.getMerged(Direction.NORTH)) { // invalid merge - logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.NORTH, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2697,7 +2690,6 @@ public class Plot { tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST)); if (!tmp.getMerged(Direction.EAST)) { // invalid merge - logger.debug("Fixing invalid merge: {}", this); if (tmp.isOwnerAbs(this.getOwnerAbs())) { tmp.getSettings().setMerged(Direction.EAST, true); DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); @@ -2712,7 +2704,6 @@ public class Plot { Plot current; while ((current = frontier.poll()) != null) { if (!current.hasOwner() || current.settings == null) { - logger.debug("Ignoring invalid merged plot: {} | {}", current, current.getOwnerAbs()); 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 e74e51d2c..32b650a2a 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -87,7 +87,7 @@ import java.util.function.Consumer; */ public abstract class PlotArea { - private static final Logger logger = LoggerFactory.getLogger(PlotArea.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotArea.class.getSimpleName()); protected final ConcurrentHashMap plots = new ConcurrentHashMap<>(); @Getter @NotNull private final String worldName; diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java index d52536e22..814aba558 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.plot; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.InventoryUtil; import lombok.NonNull; @@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory; public class PlotInventory { - private static final Logger logger = LoggerFactory.getLogger(PlotInventory.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName()); private static final String META_KEY = "inventory"; public final PlotPlayer player; @@ -82,10 +81,7 @@ public class PlotInventory { if (this.title == null) { return; } - if (hasPlotInventoryOpen(player)) { - logger.debug("Failed to open plot inventory for {} because" - + " the player already has an open plot inventory", player.getName()); - } else { + if (!hasPlotInventoryOpen(player)) { this.open = true; setPlotInventoryOpen(player, this); InventoryUtil.manager.open(this); 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 96499df87..b697db52c 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 @@ -43,7 +43,6 @@ import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.util.MainUtil; -import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; @@ -57,14 +56,13 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Objects; -import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; public class ExpireManager { - private final Logger logger = LoggerFactory.getLogger(ExpireManager.class); + private final Logger logger = LoggerFactory.getLogger("P2/" + ExpireManager.class); public static ExpireManager IMP; private final ConcurrentHashMap dates_cache; @@ -83,7 +81,6 @@ public class ExpireManager { } public void addTask(ExpiryTask task) { - logger.debug("Adding new expiry task!"); this.tasks.add(task); } @@ -424,19 +421,7 @@ public class ExpireManager { MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString()); } } - Set plots = plot.getConnectedPlots(); plot.deletePlot(whenDone); - PlotAnalysis changed = plot.getComplexity(null); - int changes = changed == null ? 0 : changed.changes_sd; - int modified = changed == null ? 0 : changed.changes; - logger.debug("Deleted expired plot: {} | User: {} | Delta: {}/{} | Connected: {}", - plot, plot.getOwner(), changes, modified, StringMan.getString(plots)); - logger.debug(" - Area: {}", plot.getArea()); - if (plot.hasOwner()) { - logger.debug(" - Owner: {}", plot.getOwner()); - } else { - logger.debug(" - Owner: Unowned"); - } } public long getAge(UUID uuid) { 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 ed4b1453f..d3e9e956e 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 @@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class PlotAnalysis { - private static final Logger logger = LoggerFactory.getLogger(PlotAnalysis.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotAnalysis.class.getSimpleName()); public static boolean running = false; public int changes; @@ -96,20 +96,26 @@ public class PlotAnalysis { */ public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) { if (running) { - logger.debug("Calibration task already in progress!"); + if (Settings.DEBUG) { + logger.info("Calibration task already in progress!"); + } return; } if (threshold <= 0 || threshold >= 1) { - logger.debug("Invalid threshold provided! (Cannot be 0 or 100 as then there's no point in calibrating)"); + if (Settings.DEBUG) { + logger.info( + "Invalid threshold provided! (Cannot be 0 or 100 as then there's no point in calibrating)"); + } return; } running = true; - 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(); - logger.debug("- Reducing {} plots to those with sufficient data", plots.size()); + if (Settings.DEBUG) { + logger.info("- Reducing {} plots to those with sufficient data", plots.size()); + } while (iterator.hasNext()) { Plot plot = iterator.next(); if (plot.getSettings().getRatings() == null || plot.getSettings().getRatings() @@ -119,10 +125,12 @@ public class PlotAnalysis { plot.addRunning(); } } - logger.debug("- | Reduced to {} plots", plots.size()); if (plots.size() < 3) { - logger.debug("Calibration cancelled due to insufficient comparison data, please try again later"); + if (Settings.DEBUG) { + logger.info( + "Calibration cancelled due to insufficient comparison data, please try again later"); + } running = false; for (Plot plot : plots) { plot.removeRunning(); @@ -130,7 +138,9 @@ public class PlotAnalysis { return; } - logger.debug("- Analyzing plot contents (this may take a while)"); + if (Settings.DEBUG) { + logger.info("- Analyzing plot contents (this may take a while)"); + } int[] changes = new int[plots.size()]; int[] faces = new int[plots.size()]; @@ -156,7 +166,9 @@ public class PlotAnalysis { ratings[i] = (int) ( (plot.getAverageRating() + plot.getSettings().getRatings().size()) * 100); - logger.debug(" | {} (rating) {}", plot, ratings[i]); + if (Settings.DEBUG) { + logger.info(" | {} (rating) {}", plot, ratings[i]); + } } } }); @@ -168,7 +180,9 @@ public class PlotAnalysis { if (queuePlot == null) { break; } - logger.debug(" | {}", queuePlot); + if (Settings.DEBUG) { + logger.info(" | {}", queuePlot); + } final Object lock = new Object(); TaskManager.runTask(new Runnable() { @Override public void run() { @@ -198,7 +212,9 @@ public class PlotAnalysis { } } - logger.debug(" - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size()); + if (Settings.DEBUG) { + logger.info(" - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size()); + } try { ratingAnalysis.join(); @@ -206,10 +222,15 @@ public class PlotAnalysis { e.printStackTrace(); } - logger.debug(" - Processing and grouping single plot analysis for bulk processing"); + if (Settings.DEBUG) { + logger.info( + " - Processing and grouping single plot analysis for bulk processing"); + } for (int i = 0; i < plots.size(); i++) { Plot plot = plots.get(i); - logger.debug(" | {}", plot); + if (Settings.DEBUG) { + logger.info(" | {}", plot); + } PlotAnalysis analysis = plot.getComplexity(null); changes[i] = analysis.changes; @@ -225,16 +246,22 @@ public class PlotAnalysis { variety_sd[i] = analysis.variety_sd; } - logger.debug(" - Calculating rankings"); + if (Settings.DEBUG) { + logger.info(" - Calculating rankings"); + } int[] rankRatings = rank(ratings); int n = rankRatings.length; int optimalIndex = (int) Math.round((1 - threshold) * (n - 1)); - 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"); + if (Settings.DEBUG) { + logger.info(" - Calculating rank correlation: "); + logger.info( + " - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking"); + logger.info( + " - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing"); + } Settings.Auto_Clear settings = new Settings.Auto_Clear(); @@ -246,7 +273,10 @@ public class PlotAnalysis { settings.CALIBRATION.CHANGES = factorChanges == 1 ? 0 : (int) (factorChanges * 1000 / MathMan.getMean(changes)); - logger.debug(" - | changes {}", factorChanges); + + if (Settings.DEBUG) { + logger.info(" - | changes {}", factorChanges); + } int[] rankFaces = rank(faces); int[] sdFaces = getSD(rankFaces, rankRatings); @@ -255,7 +285,10 @@ public class PlotAnalysis { double factorFaces = getCC(n, sumFaces); settings.CALIBRATION.FACES = factorFaces == 1 ? 0 : (int) (factorFaces * 1000 / MathMan.getMean(faces)); - logger.debug(" - | faces {}", factorFaces); + + if (Settings.DEBUG) { + logger.info(" - | faces {}", factorFaces); + } int[] rankData = rank(data); int[] sdData = getSD(rankData, rankRatings); @@ -264,7 +297,10 @@ public class PlotAnalysis { double factor_data = getCC(n, sum_data); settings.CALIBRATION.DATA = factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data)); - logger.debug(" - | data {}", factor_data); + + if (Settings.DEBUG) { + logger.info(" - | data {}", factor_data); + } int[] rank_air = rank(air); int[] sd_air = getSD(rank_air, rankRatings); @@ -273,7 +309,10 @@ public class PlotAnalysis { double factor_air = getCC(n, sum_air); settings.CALIBRATION.AIR = factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air)); - logger.debug("- | air {}", factor_air); + + if (Settings.DEBUG) { + logger.info("- | air {}", factor_air); + } int[] rank_variety = rank(variety); int[] sd_variety = getSD(rank_variety, rankRatings); @@ -283,7 +322,10 @@ public class PlotAnalysis { settings.CALIBRATION.VARIETY = factor_variety == 1 ? 0 : (int) (factor_variety * 1000 / MathMan.getMean(variety)); - logger.debug("- | variety {}", factor_variety); + + if (Settings.DEBUG) { + logger.info("- | variety {}", factor_variety); + } int[] rank_changes_sd = rank(changes_sd); int[] sd_changes_sd = getSD(rank_changes_sd, rankRatings); @@ -293,7 +335,10 @@ public class PlotAnalysis { settings.CALIBRATION.CHANGES_SD = factor_changes_sd == 1 ? 0 : (int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd)); - logger.debug(" - | changed_sd {}", factor_changes_sd); + + if (Settings.DEBUG) { + logger.info(" - | changed_sd {}", factor_changes_sd); + } int[] rank_faces_sd = rank(faces_sd); int[] sd_faces_sd = getSD(rank_faces_sd, rankRatings); @@ -303,7 +348,10 @@ public class PlotAnalysis { settings.CALIBRATION.FACES_SD = factor_faces_sd == 1 ? 0 : (int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd)); - logger.debug(" - | faced_sd {}", factor_faces_sd); + + if (Settings.DEBUG) { + logger.info(" - | faced_sd {}", factor_faces_sd); + } int[] rank_data_sd = rank(data_sd); int[] sd_data_sd = getSD(rank_data_sd, rankRatings); @@ -313,7 +361,10 @@ public class PlotAnalysis { settings.CALIBRATION.DATA_SD = factor_data_sd == 1 ? 0 : (int) (factor_data_sd * 1000 / MathMan.getMean(data_sd)); - logger.debug(" - | data_sd {}", factor_data_sd); + + if (Settings.DEBUG) { + logger.info(" - | data_sd {}", factor_data_sd); + } int[] rank_air_sd = rank(air_sd); int[] sd_air_sd = getSD(rank_air_sd, rankRatings); @@ -322,7 +373,10 @@ 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)); - logger.debug(" - | air_sd {}", factor_air_sd); + + if (Settings.DEBUG) { + logger.info(" - | air_sd {}", factor_air_sd); + } int[] rank_variety_sd = rank(variety_sd); int[] sd_variety_sd = getSD(rank_variety_sd, rankRatings); @@ -332,11 +386,17 @@ public class PlotAnalysis { settings.CALIBRATION.VARIETY_SD = factor_variety_sd == 1 ? 0 : (int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd)); - logger.debug(" - | variety_sd {}", factor_variety_sd); + + if (Settings.DEBUG) { + logger.info(" - | variety_sd {}", factor_variety_sd); + } int[] complexity = new int[n]; - logger.debug(" Calculating threshold"); + if (Settings.DEBUG) { + logger.info(" Calculating threshold"); + } + int max = 0; int min = 0; for (int i = 0; i < n; i++) { @@ -365,7 +425,10 @@ public class PlotAnalysis { logln("Correlation: "); logln(getCC(n, sum(square(getSD(rankComplexity, rankRatings))))); if (optimalComplexity == Integer.MAX_VALUE) { - logger.debug("Insufficient data to determine correlation! {} | {}", optimalIndex, n); + if (Settings.DEBUG) { + logger.info("Insufficient data to determine correlation! {} | {}", + optimalIndex, n); + } running = false; for (Plot plot : plots) { plot.removeRunning(); @@ -383,21 +446,27 @@ public class PlotAnalysis { } // Save calibration - logger.debug(" Saving calibration"); + if (Settings.DEBUG) { + logger.info(" Saving calibration"); + } Settings.AUTO_CLEAR.put("auto-calibrated", settings); Settings.save(PlotSquared.get().worldsFile); - logger.debug("Done!"); running = false; for (Plot plot : plots) { plot.removeRunning(); } + if (Settings.DEBUG) { + logger.info(" Done!"); + } whenDone.run(); } }); } public static void logln(Object obj) { - logger.debug(log(obj)); + if (Settings.DEBUG) { + logger.info(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 b55c6a96d..2c398d1c7 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 @@ -45,7 +45,7 @@ import java.util.Map; */ @EqualsAndHashCode(of = "flagMap") public class FlagContainer { - private static final Logger logger = LoggerFactory.getLogger(FlagContainer.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + FlagContainer.class.getSimpleName()); private final Map unknownFlags = new HashMap<>(); private final Map, PlotFlag> flagMap = new HashMap<>(); 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 6197327a6..a2d4d4a94 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,6 +27,7 @@ package com.plotsquared.core.plot.flag.types; import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.plotsquared.core.configuration.Settings; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -45,7 +46,7 @@ import java.util.Map; */ public class BlockTypeWrapper { - private static final Logger logger = LoggerFactory.getLogger(BlockTypeWrapper.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + BlockTypeWrapper.class.getSimpleName()); private static final Map blockTypes = new HashMap<>(); private static final Map blockCategories = new HashMap<>(); @@ -132,7 +133,9 @@ 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()) { - logger.debug("- Block category #{} does not exist", this.blockCategoryId); + if (Settings.DEBUG) { + logger.info("- 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 7e192dbe8..f72dc9aef 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 @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; public class PlotMessage { - private static final Logger logger = LoggerFactory.getLogger(PlotMessage.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotMessage.class.getSimpleName()); private Object builder; 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 d3ad4e36e..eefae99d3 100644 --- a/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java +++ b/Core/src/main/java/com/plotsquared/core/queue/LocationOffsetDelegateLocalBlockQueue.java @@ -37,7 +37,7 @@ import javax.annotation.Nullable; public class LocationOffsetDelegateLocalBlockQueue extends DelegateLocalBlockQueue { - private static final Logger logger = LoggerFactory.getLogger(LocationOffsetDelegateLocalBlockQueue.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + LocationOffsetDelegateLocalBlockQueue.class.getSimpleName()); private final boolean[][] canPlace; private final int blockX; @@ -64,9 +64,6 @@ public class LocationOffsetDelegateLocalBlockQueue extends DelegateLocalBlockQue return super.setBlock(x, y, z, id); } } catch (final Exception e) { - 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 da25e4ed1..40b3d1c78 100644 --- a/Core/src/main/java/com/plotsquared/core/util/Expression.java +++ b/Core/src/main/java/com/plotsquared/core/util/Expression.java @@ -25,9 +25,9 @@ */ package com.plotsquared.core.util; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.DebugExec; import com.plotsquared.core.command.MainCommand; +import com.plotsquared.core.configuration.Settings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +35,7 @@ import javax.script.ScriptException; public abstract class Expression { - private static final Logger logger = LoggerFactory.getLogger(Expression.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + Expression.class.getSimpleName()); public static Expression constant(final U value) { return new Expression() { @@ -71,7 +71,9 @@ public abstract class Expression { try { return (Double) exec.getEngine().eval(expression.replace("{arg}", "" + arg)); } catch (ScriptException e) { - logger.debug("Invalid expression: {}", expression); + if (Settings.DEBUG) { + logger.info("Invalid expression: {}", expression); + } e.printStackTrace(); } return 0d; 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 7fbdc4fd4..70e46e406 100644 --- a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java +++ b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java @@ -46,7 +46,7 @@ import java.util.Map; @SuppressWarnings("unused") public final class LegacyConverter { - private static final Logger logger = LoggerFactory.getLogger(LegacyConverter.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + LegacyConverter.class.getSimpleName()); public static final String CONFIGURATION_VERSION = "post_flattening"; private static final HashMap TYPE_MAP = new HashMap<>(); 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 11b17cc02..5c5799c78 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -99,7 +99,7 @@ import java.util.stream.IntStream; */ public class MainUtil { - private static final Logger logger = LoggerFactory.getLogger(MainUtil.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + MainUtil.class.getSimpleName()); private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); static { @@ -156,7 +156,6 @@ public class MainUtil { public static void upload(UUID uuid, String file, String extension, final RunnableVal writeTask, final RunnableVal whenDone) { if (writeTask == null) { - logger.debug("Write task cannot be null"); TaskManager.runTask(whenDone); return; } @@ -897,8 +896,6 @@ public class MainUtil { for (File file : files) { if (file.isDirectory()) { deleteDirectory(file); - } else { - logger.debug("Deleting file: {} | {}", file, file.delete()); } } } 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 238f8345b..eae87a02b 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -46,7 +46,7 @@ import java.util.Set; public abstract class RegionManager { - private static final Logger logger = LoggerFactory.getLogger(RegionManager.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName()); public static RegionManager manager = null; 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 d16ecbe7b..c79e680a8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -96,7 +96,7 @@ import java.util.zip.GZIPOutputStream; public abstract class SchematicHandler { - private static final Logger logger = LoggerFactory.getLogger(SchematicHandler.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + SchematicHandler.class.getSimpleName()); public static SchematicHandler manager; private boolean exportAll = false; @@ -151,17 +151,12 @@ public abstract class SchematicHandler { final Runnable THIS = this; SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { @Override public void run(final CompoundTag value) { - if (value == null) { - logger.debug("Skipped plot {}", plot.getId()); - } else { + if (value != null) { TaskManager.runTaskAsync(() -> { - logger.debug("ID: {}", plot.getId()); boolean result = SchematicHandler.manager .save(value, directory + File.separator + name + ".schem"); if (!result) { logger.error("Failed to save {}", plot.getId()); - } else { - logger.debug("success: {}", plot.getId()); } TaskManager.runTask(THIS); }); @@ -205,7 +200,6 @@ public abstract class SchematicHandler { + 1) < WIDTH) || ( (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ() + zOffset + 1) < LENGTH) || (HEIGHT > 256)) { - logger.debug("Schematic is too large"); TaskManager.runTask(whenDone); return; } diff --git a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java index 1189bc5cb..8c8359865 100644 --- a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java +++ b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java @@ -48,7 +48,7 @@ import java.util.Locale; @SuppressWarnings({"unused", "WeakerAccess"}) public final class IncendoPaster { - private static Logger logger = LoggerFactory.getLogger(IncendoPaster.class); + private static Logger logger = LoggerFactory.getLogger("P2/" + IncendoPaster.class); /** * Upload service URL @@ -161,7 +161,7 @@ public final class IncendoPaster { if (!httpURLConnection.getResponseMessage().contains("OK")) { if (httpURLConnection.getResponseCode() == 413) { final long size = content.length; - logger.debug("Paste too big > size: {}MB", size / 1_000_000); + logger.error("Paste too big > size: {}MB", size / 1_000_000); } throw new IllegalStateException(String .format("Server returned status: %d %s", httpURLConnection.getResponseCode(), 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 88dfaeb11..8d1e38337 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -64,7 +64,7 @@ import java.util.function.Function; */ public class UUIDPipeline { - private static final Logger logger = LoggerFactory.getLogger(UUIDPipeline.class); + private static final Logger logger = LoggerFactory.getLogger("P2/" + UUIDPipeline.class.getSimpleName()); private final Executor executor; private final List serviceList; @@ -325,7 +325,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.debug("(UUID) Failed to find all usernames"); + logger.info("(UUID) Failed to find all usernames"); } if (Settings.UUID.UNKNOWN_AS_DEFAULT) { @@ -388,7 +388,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.debug("(UUID) Failed to find all UUIDs"); + logger.info("(UUID) Failed to find all UUIDs"); } throw new ServiceError("End of pipeline"); diff --git a/Core/src/main/resources/log4j.xml b/Core/src/main/resources/log4j.xml deleted file mode 100644 index b450c1eca..000000000 --- a/Core/src/main/resources/log4j.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - From 6664d49928a8ee9da8bfcb873c1e32a0b8300b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 13 Jul 2020 23:04:27 +0200 Subject: [PATCH 11/12] Prefix all log messages --- .../com/plotsquared/bukkit/BukkitMain.java | 49 +++--- .../entity/ReplicatingEntityWrapper.java | 4 +- .../plotsquared/bukkit/util/BukkitUtil.java | 4 +- .../plotsquared/bukkit/util/ContentMap.java | 2 +- .../bukkit/util/UpdateUtility.java | 10 +- .../com/plotsquared/core/PlotSquared.java | 120 +++++++------- .../com/plotsquared/core/command/Debug.java | 8 +- .../plotsquared/core/command/DebugExec.java | 4 +- .../com/plotsquared/core/command/Purge.java | 6 +- .../com/plotsquared/core/command/Trim.java | 8 +- .../components/ComponentPresetManager.java | 6 +- .../core/configuration/Config.java | 6 +- .../configuration/file/YamlConfiguration.java | 8 +- .../plotsquared/core/database/SQLManager.java | 150 +++++++++--------- .../com/plotsquared/core/database/SQLite.java | 2 +- .../core/generator/HybridPlotWorld.java | 10 +- .../core/generator/HybridUtils.java | 16 +- .../core/generator/SquarePlotWorld.java | 2 +- .../plotsquared/core/player/PlotPlayer.java | 2 +- .../java/com/plotsquared/core/plot/Plot.java | 4 +- .../com/plotsquared/core/plot/PlotArea.java | 2 +- .../core/plot/expiration/PlotAnalysis.java | 48 +++--- .../core/plot/flag/FlagContainer.java | 2 +- .../plot/flag/types/BlockTypeWrapper.java | 2 +- .../core/plot/message/PlotMessage.java | 2 +- .../com/plotsquared/core/util/Expression.java | 2 +- .../com/plotsquared/core/util/MainUtil.java | 2 +- .../plotsquared/core/util/RegionManager.java | 2 +- .../core/util/SchematicHandler.java | 2 +- .../core/util/net/IncendoPaster.java | 2 +- .../plotsquared/core/uuid/UUIDPipeline.java | 8 +- 31 files changed, 247 insertions(+), 248 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ca3406018..85c3bc5b5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -225,12 +225,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } if (PremiumVerification.isPremium()) { - 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 :)"); + logger.info("[P2] PlotSquared version licensed to Spigot user {}", getUserID()); + logger.info("[P2] https://www.spigotmc.org/resources/{}", getResourceID()); + logger.info("[P2] Download ID: {}", getDownloadID()); + logger.info("[P2] Thanks for supporting us :)"); } else { - logger.info("Couldn't verify purchase :("); + logger.info("[P2] Couldn't verify purchase :("); } final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline(); @@ -250,7 +250,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService(); impromptuPipeline.registerService(offlineModeUUIDService); backgroundPipeline.registerService(offlineModeUUIDService); - logger.info("(UUID) Using the offline mode UUID service"); + logger.info("[P2] (UUID) Using the offline mode UUID service"); } final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService(); @@ -270,7 +270,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final LuckPermsUUIDService luckPermsUUIDService; if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { luckPermsUUIDService = new LuckPermsUUIDService(); - logger.info("(UUID) Using LuckPerms as a complementary UUID service"); + logger.info("[P2] (UUID) Using LuckPerms as a complementary UUID service"); } else { luckPermsUUIDService = null; } @@ -278,7 +278,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final BungeePermsUUIDService bungeePermsUUIDService; if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) { bungeePermsUUIDService = new BungeePermsUUIDService(); - logger.info("(UUID) Using BungeePerms as a complementary UUID service"); + logger.info("[P2] (UUID) Using BungeePerms as a complementary UUID service"); } else { bungeePermsUUIDService = null; } @@ -286,7 +286,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final EssentialsUUIDService essentialsUUIDService; if (Bukkit.getPluginManager().getPlugin("Essentials") != null) { essentialsUUIDService = new EssentialsUUIDService(); - logger.info("(UUID) Using Essentials as a complementary UUID service"); + logger.info("[P2] (UUID) Using Essentials as a complementary UUID service"); } else { essentialsUUIDService = null; } @@ -297,7 +297,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final PaperUUIDService paperUUIDService = new PaperUUIDService(); impromptuPipeline.registerService(paperUUIDService); backgroundPipeline.registerService(paperUUIDService); - logger.info("(UUID) Using Paper as a complementary UUID service"); + logger.info("[P2] (UUID) Using Paper as a complementary UUID service"); } impromptuPipeline.registerService(sqLiteUUIDService); @@ -350,9 +350,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) { ChatFormatter.formatters.add(new PlaceholderFormatter()); } - logger.info("PlotSquared hooked into PlaceholderAPI"); + logger.info("[P2] PlotSquared hooked into PlaceholderAPI"); } else { - logger.info("PlaceholderAPI is not in use. Hook deactivated"); + logger.info("[P2] PlaceholderAPI is not in use. Hook deactivated"); } this.startMetrics(); @@ -368,8 +368,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< try { this.backupManager = new SimpleBackupManager(); } catch (final Exception e) { - logger.error("Failed to initialize backup manager", e); - logger.error("Backup features will be disabled"); + logger.error("[P2] Failed to initialize backup manager", e); + logger.error("[P2] Backup features will be disabled"); this.backupManager = new NullBackupManager(); } @@ -381,7 +381,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< this.worldManager = new BukkitWorldManager(); } - logger.info("Using platform world manager: {}", this.worldManager.getName()); + logger.info("[P2] Using platform world manager: {}", this.worldManager.getName()); // Clean up potential memory leak Bukkit.getScheduler().runTaskTimer(this, () -> { @@ -442,7 +442,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< final Chunk[] chunks = world.getLoadedChunks(); if (chunks.length == 0) { if (!Bukkit.unloadWorld(world, true)) { - logger.warn("Failed to unload {}", world.getName()); + logger.warn("[P2] Failed to unload {}", world.getName()); } return; } else { @@ -493,7 +493,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } }); - logger.info("(UUID) {} UUIDs will be cached", uuidQueue.size()); + logger.info("[P2] (UUID) {} UUIDs will be cached", uuidQueue.size()); Executors.newSingleThreadScheduledExecutor().schedule(() -> { // Begin by reading all the SQLite cache at once @@ -501,7 +501,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; - logger.info("(UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT); + logger.info("[P2] (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 @@ -509,7 +509,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) { if (!uuidList.isEmpty() && secondRun) { - logger.warn("(UUID) Giving up on last batch. Fetching new batch instead"); + logger.warn("[P2] (UUID) Giving up on last batch. Fetching new batch instead"); uuidList.clear(); } if (uuidList.isEmpty()) { @@ -534,14 +534,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< // Print progress final double percentage = ((double) read / (double) totalSize) * 100.0D; if (Settings.DEBUG) { - logger.info("(UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); + logger.info("[P2] (UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage)); } } catch (final InterruptedException | ExecutionException e) { - logger.error("(UUID) Failed to retrieve last batch. Will try again", e); - e.printStackTrace(); + logger.error("[P2] (UUID) Failed to retrieve last batch. Will try again", e); } } - logger.info("(UUID) PlotSquared has cached all UUIDs"); + logger.info("[P2] (UUID) PlotSquared has cached all UUIDs"); }, 10, TimeUnit.SECONDS); } @@ -603,7 +602,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< } @Override @SuppressWarnings("deprecation") public void runEntityTask() { - logger.info("KillAllEntities started"); + logger.info("[P2] KillAllEntities started"); TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> { final World world = Bukkit.getWorld(plotArea.getWorldName()); try { @@ -1013,7 +1012,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< SetGenCB.setGenerator(BukkitUtil.getWorld(worldName)); } } catch (final Exception e) { - logger.error("Failed to reload world: {} | {}", world, e.getMessage()); + logger.error("[P2] Failed to reload world: {} | {}", world, e.getMessage()); Bukkit.getServer().unloadWorld(world, false); return; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java index 253de36ae..11e653141 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java @@ -388,7 +388,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { try { entity.getInventory().setContents(this.inventory); } catch (IllegalArgumentException e) { - logger.error("Failed to restore inventory", e); + logger.error("[P2] Failed to restore inventory", e); } } @@ -732,7 +732,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { return entity; default: if (Settings.DEBUG) { - logger.info("Could not identify entity: {}", entity.getType()); + logger.info("[P2] Could not identify entity: {}", entity.getType()); } return entity; // END LIVING 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 286458614..c72d40b0e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -508,7 +508,7 @@ public class BukkitUtil extends WorldUtil { @NonNull final BiomeType biomeType) { final World world = getWorld(worldName); if (world == null) { - logger.warn("An error occured while setting the biome because the world was null", new RuntimeException()); + logger.warn("[P2] An error occured while setting the biome because the world was null", new RuntimeException()); return; } final Biome biome = BukkitAdapter.adapt(biomeType); @@ -622,7 +622,7 @@ public class BukkitUtil extends WorldUtil { } break; default: { - logger.error("Unknown entity category requested: {}", category); + logger.error("[P2] Unknown entity category requested: {}", category); } break; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java index 78d941808..47d6d23ec 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/ContentMap.java @@ -126,7 +126,7 @@ public class ContentMap { try { entity.spawn(world, xOffset, zOffset); } catch (Exception e) { - logger.error("Failed to restore entity", e); + logger.error("[P2] Failed to restore entity", e); } } this.entities.clear(); 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 c28fe8740..88594abd5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -71,22 +71,22 @@ public class UpdateUtility implements Listener { .getAsJsonObject(); spigotVersion = result.get("current_version").getAsString(); } catch (IOException e) { - logger.error("Unable to check for updates. Error: {}", e.getMessage()); + logger.error("[P2] Unable to check for updates. Error: {}", e.getMessage()); return; } if (internalVersion.isLaterVersion(spigotVersion)) { - logger.info("There appears to be a PlotSquared update available!"); - logger.info("You are running version {}, the latest version is {}", + logger.info("[P2] There appears to be a PlotSquared update available!"); + logger.info("[P2] You are running version {}, the latest version is {}", internalVersion.versionString(), spigotVersion); - logger.info("https://www.spigotmc.org/resources/77506/updates"); + logger.info("[P2] https://www.spigotmc.org/resources/77506/updates"); hasUpdate = true; if (Settings.UpdateChecker.NOTIFY_ONCE) { cancelTask(); } } else if (notify) { notify = false; - logger.info("Congratulations! You are running the latest PlotSquared version"); + logger.info("[P2] 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 4c50026e4..b213460be 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -237,7 +237,7 @@ public class PlotSquared { if (!getConfigurationVersion().equalsIgnoreCase("v5")) { // Perform upgrade if (DBFunc.dbManager.convertFlags()) { - logger.info("Flags were converted successfully"); + logger.info("[P2] Flags were converted successfully"); // Update the config version setConfigurationVersion("v5"); } @@ -285,7 +285,7 @@ public class PlotSquared { if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { if (this.IMP.initWorldEdit()) { - logger.info("{} hooked into WorldEdit", imp().getPluginName()); + logger.info("[P2] {} hooked into WorldEdit", imp().getPluginName()); this.worldedit = WorldEdit.getInstance(); WorldEdit.getInstance().getEventBus().register(new WESubscriber()); if (Settings.Enabled_Components.COMMANDS) { @@ -294,7 +294,7 @@ public class PlotSquared { } } catch (Throwable e) { - logger.error("Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); + logger.error("[P2] Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master"); } } @@ -308,7 +308,7 @@ public class PlotSquared { try { new ComponentPresetManager(); } catch (final Exception e) { - logger.error("Failed to initialize the preset system", e); + logger.error("[P2] Failed to initialize the preset system", e); } } @@ -329,11 +329,11 @@ public class PlotSquared { continue; } if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { - logger.warn("`{}` was not properly loaded - {} will now try to load it properly", + logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly", world, imp().getPluginName()); - logger.warn(" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); - logger.warn(" - Your world management plugin may be faulty (or non existent)"); - logger.warn(" This message may also be a false positive and could be ignored."); + logger.warn("[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml"); + logger.warn("[P2] - Your world management plugin may be faulty (or non existent)"); + logger.warn("[P2] This message may also be a false positive and could be ignored."); PlotSquared.this.IMP.setGenerator(world); } } @@ -509,16 +509,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); - logger.info("Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height); - logger.info(" - Regions: {}", regions.size()); - logger.info(" - Chunks: {}", chunks.size()); + logger.info("[P2] Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height); + logger.info("[P2] - Regions: {}", regions.size()); + logger.info("[P2] - Chunks: {}", chunks.size()); HybridUtils.UPDATE = true; HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks); } catch (IOException | ClassNotFoundException e) { - logger.error("Error restarting road regeneration", e); + logger.error("[P2] Error restarting road regeneration", e); } finally { if (!file.delete()) { - logger.error("Error deleting persistent_regen_data_{}. Please delete this file manually", plotArea.getId()); + logger.error("[P2] Error deleting persistent_regen_data_{}. Please delete this file manually", plotArea.getId()); } } }); @@ -1105,10 +1105,10 @@ public class PlotSquared { // Conventional plot generator PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null); PlotManager plotManager = plotArea.getPlotManager(); - 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()); + logger.info("[P2] Detected world load for '{}'", world); + logger.info("[P2] - generator: {}>{}", baseGenerator, plotGenerator); + logger.info("[P2] - plot world: {}", plotArea.getClass().getCanonicalName()); + logger.info("[P2] - plot area manager: {}", plotManager.getClass().getCanonicalName()); if (!this.worlds.contains(path)) { this.worlds.createSection(path); worldSection = this.worlds.getConfigurationSection(path); @@ -1132,7 +1132,7 @@ public class PlotSquared { if (plotAreaManager.getPlotAreas(world, null).length != 0) { return; } - logger.info("Detected world load for '{}'", world); + logger.info("[P2] Detected world load for '{}'", world); String gen_string = worldSection.getString("generator.plugin", IMP.getPluginName()); if (type == PlotAreaType.PARTIAL) { Set clusters = @@ -1148,7 +1148,7 @@ public class PlotSquared { String fullId = name + "-" + pos1 + "-" + pos2; worldSection.createSection("areas." + fullId); DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE - logger.info(" - {}-{}-{}", name, pos1, pos2); + logger.info("[P2] - {}-{}-{}", name, pos1, pos2); GeneratorWrapper areaGen = this.IMP.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); @@ -1162,10 +1162,10 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - 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); + logger.info("[P2] | generator: {}>{}", baseGenerator, areaGen); + logger.info("[P2] | plot world: {}", pa); + logger.info("[P2] | manager: {}", pa); + logger.info("[P2] Note: Area created for cluster '{}' (invalid or old configuration?)", name); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); toLoad.add(pa); @@ -1187,9 +1187,9 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - logger.info(" - generator: {}>{}", baseGenerator, areaGen); - logger.info(" - plot world: {}", pa); - logger.info(" - plot area manager: {}", pa.getPlotManager()); + logger.info("[P2] - generator: {}>{}", baseGenerator, areaGen); + logger.info("[P2] - plot world: {}", pa); + logger.info("[P2] - plot area manager: {}", pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1201,7 +1201,7 @@ public class PlotSquared { + PlotAreaType.AUGMENTED + "`"); } for (String areaId : areasSection.getKeys(false)) { - logger.info(" - {}", areaId); + logger.info("[P2] - {}", areaId); String[] split = areaId.split("(?<=[^;-])-"); if (split.length != 3) { throw new IllegalArgumentException("Invalid Area identifier: " + areaId @@ -1263,10 +1263,10 @@ public class PlotSquared { } catch (IOException e) { e.printStackTrace(); } - logger.info("Detected area load for '{}'", world); - logger.info(" | generator: {}>{}", baseGenerator, areaGen); - logger.info(" | plot world: {}", pa); - logger.info(" | manager: {}", pa.getPlotManager()); + logger.info("[P2] Detected area load for '{}'", world); + logger.info("[P2] | generator: {}>{}", baseGenerator, areaGen); + logger.info("[P2] | plot world: {}", pa); + logger.info("[P2] | manager: {}", pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1335,7 +1335,7 @@ public class PlotSquared { for (String element : split) { String[] pair = element.split("="); if (pair.length != 2) { - logger.error("No value provided for '{}'", element); + logger.error("[P2] No value provided for '{}'", element); return false; } String key = pair[0].toLowerCase(); @@ -1383,11 +1383,11 @@ public class PlotSquared { ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); break; default: - logger.error("Key not found: {}", element); + logger.error("[P2] Key not found: {}", element); return false; } } catch (Exception e) { - logger.error("Invalid value '{}' for arg '{}'", value, element); + logger.error("[P2] Invalid value '{}' for arg '{}'", value, element); e.printStackTrace(); return false; } @@ -1466,7 +1466,7 @@ public class PlotSquared { } } } catch (IOException e) { - logger.error("Could not save {}", file); + logger.error("[P2] Could not save {}", file); e.printStackTrace(); } } @@ -1502,7 +1502,7 @@ public class PlotSquared { // Close the connection DBFunc.close(); } catch (NullPointerException throwable) { - logger.error("Could not close database connection", throwable); + logger.error("[P2] Could not close database connection", throwable); throwable.printStackTrace(); } } @@ -1515,9 +1515,9 @@ public class PlotSquared { HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) { return; } - logger.info("Road regeneration incomplete. Saving incomplete regions to disk"); - logger.info(" - regions: {}", HybridUtils.regions.size()); - logger.info(" - chunks: {}", HybridUtils.chunks.size()); + logger.info("[P2] Road regeneration incomplete. Saving incomplete regions to disk"); + logger.info("[P2] - regions: {}", HybridUtils.regions.size()); + logger.info("[P2] - chunks: {}", HybridUtils.chunks.size()); ArrayList regions = new ArrayList<>(); ArrayList chunks = new ArrayList<>(); for (BlockVector2 r : HybridUtils.regions) { @@ -1534,14 +1534,14 @@ public class PlotSquared { this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area .getId() + "_" + HybridUtils.area.getWorldName()); if (file.exists() && !file.delete()) { - logger.error("persistent_regene_data file already exists and could not be deleted"); + logger.error("[P2] 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) { - logger.error("Error creating persistent_region_data file", e); + logger.error("[P2] Error creating persistent_region_data file", e); } } @@ -1561,7 +1561,7 @@ public class PlotSquared { File file = MainUtil.getFile(IMP.getDirectory(), Storage.SQLite.DB + ".db"); database = new SQLite(file); } else { - logger.error("No storage type is set. Disabling PlotSquared"); + logger.error("[P2] No storage type is set. Disabling PlotSquared"); this.IMP.shutdown(); //shutdown used instead of disable because no database is set return; } @@ -1579,11 +1579,11 @@ public class PlotSquared { } this.clusters_tmp = DBFunc.getClusters(); } catch (ClassNotFoundException | SQLException e) { - 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 ==="); + logger.error("[P2] Failed to open database connection ({}). Disabling PlotSquared", Storage.MySQL.USE ? "MySQL" : "SQLite"); + logger.error("[P2] ==== Here is an ugly stacktrace, if you are interested in those things ==="); e.printStackTrace(); - logger.error("&d==== End of stacktrace ===="); - logger.error("&6Please go to the {} 'storage.yml' and configure the database correctly", + logger.error("[P2] &d==== End of stacktrace ===="); + logger.error("[P2] &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 } @@ -1609,7 +1609,7 @@ public class PlotSquared { try { worlds.save(worldsFile); } catch (IOException e) { - logger.error("Failed to save worlds.yml", e); + logger.error("[P2] Failed to save worlds.yml", e); e.printStackTrace(); } } @@ -1642,12 +1642,12 @@ public class PlotSquared { public boolean setupConfigs() { File folder = new File(this.IMP.getDirectory(), "config"); if (!folder.exists() && !folder.mkdirs()) { - logger.error("Failed to create the /plugins/config folder. Please create it manually"); + logger.error("[P2] 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()) { - logger.error("Could not create the worlds file. Please create 'worlds.yml' manually"); + logger.error("[P2] Could not create the worlds file. Please create 'worlds.yml' manually"); } this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile); @@ -1680,17 +1680,17 @@ public class PlotSquared { this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION); } } catch (IOException ignored) { - logger.error("Failed to save worlds.yml"); + logger.error("[P2] Failed to save worlds.yml"); } try { this.configFile = new File(folder, "settings.yml"); if (!this.configFile.exists() && !this.configFile.createNewFile()) { - logger.error("Could not create the settings file. Please create 'settings.yml' manually"); + logger.error("[P2] Could not create the settings file. Please create 'settings.yml' manually"); } this.config = YamlConfiguration.loadConfiguration(this.configFile); setupConfig(); } catch (IOException ignored) { - logger.error("Failed to save settings.yml"); + logger.error("[P2] Failed to save settings.yml"); } try { this.styleFile = MainUtil.getFile(IMP.getDirectory(), @@ -1700,38 +1700,38 @@ public class PlotSquared { this.styleFile.getParentFile().mkdirs(); } if (!this.styleFile.createNewFile()) { - logger.error("Failed to create the style file. Please create 'translations/style.yml' manually"); + logger.error("[P2] Failed to create the style file. Please create 'translations/style.yml' manually"); } } this.style = YamlConfiguration.loadConfiguration(this.styleFile); setupStyle(); } catch (IOException ignored) { - logger.error("Failed to save style.yml"); + logger.error("[P2] Failed to save style.yml"); } try { this.storageFile = new File(folder, "storage.yml"); if (!this.storageFile.exists() && !this.storageFile.createNewFile()) { - logger.error("Could not create the storage settings file. Please create 'storage.yml' manually"); + logger.error("[P2] Could not create the storage settings file. Please create 'storage.yml' manually"); } this.storage = YamlConfiguration.loadConfiguration(this.storageFile); setupStorage(); } catch (IOException ignored) { - logger.error("Failed to save storage.yml"); + logger.error("[P2] Failed to save storage.yml"); } try { this.commandsFile = new File(folder, "commands.yml"); if (!this.commandsFile.exists() && !this.commandsFile.createNewFile()) { - logger.error("Could not create the commands file. Please create 'commands.yml' manually"); + logger.error("[P2] Could not create the commands file. Please create 'commands.yml' manually"); } this.commands = YamlConfiguration.loadConfiguration(this.commandsFile); } catch (IOException ignored) { - logger.error("Failed to save commands.yml"); + logger.error("[P2] Failed to save commands.yml"); } try { this.style.save(this.styleFile); this.commands.save(this.commandsFile); } catch (IOException e) { - logger.error("Configuration file saving failed", e); + logger.error("[P2] Configuration file saving failed", e); } return true; } @@ -1762,7 +1762,7 @@ public class PlotSquared { if (Settings.DEBUG) { Map components = Settings.getFields(Settings.Enabled_Components.class); for (Entry component : components.entrySet()) { - logger.info("Key: {} | Value: {}", component.getKey(), component.getValue()); + logger.info("[P2] 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 c395f09d8..cff10feeb 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -84,10 +84,10 @@ 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!"); + logger.info("[P2] Info!"); + logger.warn("[P2] Warning!"); + logger.error("[P2] Error!", new RuntimeException()); + logger.debug("[P2] Debug!"); return true; } if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) { 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 842d403b7..52bb92069 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -463,12 +463,12 @@ public class DebugExec extends SubCommand { } catch (ScriptException e) { e.printStackTrace(); } - logger.info("> {}ms -> {}", System.currentTimeMillis() - start, result); + logger.info("[P2] > {}ms -> {}", System.currentTimeMillis() - start, result); }); } else { long start = System.currentTimeMillis(); Object result = this.engine.eval(script, this.scope); - logger.info("> {}ms -> {}", System.currentTimeMillis() - start, result); + logger.info("[P2] > {}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 7d714a224..7056bd836 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -175,7 +175,7 @@ public class Purge extends SubCommand { boolean finalClear = clear; Runnable run = () -> { if (Settings.DEBUG) { - logger.info("Calculating plots to purge, please wait..."); + logger.info("[P2] Calculating plots to purge, please wait..."); } HashSet ids = new HashSet<>(); Iterator iterator = toDelete.iterator(); @@ -191,7 +191,7 @@ public class Purge extends SubCommand { if (finalClear) { plot.clear(false, true, () -> { if (Settings.DEBUG) { - logger.info("Plot {} cleared by purge", plot.getId()); + logger.info("[P2] Plot {} cleared by purge", plot.getId()); } }); } else { @@ -202,7 +202,7 @@ public class Purge extends SubCommand { PlotListener.plotEntry(pp, plot); } } catch (NullPointerException e) { - logger.error("NullPointer during purge detected. This is likely" + logger.error("[P2] NullPointer during purge detected. This is likely" + " because you are deleting a world that has been removed", e); } } 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 cd8e14434..e7444face 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trim.java @@ -181,15 +181,15 @@ public class Trim extends SubCommand { @Override public void run(Set viable, final Set nonViable) { Runnable regenTask; if (regen) { - logger.info("Starting regen task"); - logger.info(" - This is a VERY slow command"); - logger.info(" - It will say 'Trim done!' when complete"); + logger.info("[P2] Starting regen task"); + logger.info("[P2] - This is a VERY slow command"); + logger.info("[P2] - 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!"); + logger.info("[P2] 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 76b4d8ab2..a3b2f76e4 100644 --- a/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java +++ b/Core/src/main/java/com/plotsquared/core/components/ComponentPresetManager.java @@ -74,7 +74,7 @@ public class ComponentPresetManager { e.printStackTrace(); } if (!created) { - logger.error("Failed to create components.yml"); + logger.error("[P2] Failed to create components.yml"); this.guiName = "&cInvalid!"; this.presets = new ArrayList<>(); return; @@ -90,7 +90,7 @@ public class ComponentPresetManager { try { yamlConfiguration.save(file); } catch (IOException e) { - logger.error("Failed to save default values to components.yml", e); + logger.error("[P2] Failed to save default values to components.yml", e); } } this.guiName = yamlConfiguration.getString("title", "&6Plot Components"); @@ -108,7 +108,7 @@ public class ComponentPresetManager { try { yamlConfiguration.save(file); } catch (final IOException e) { - logger.error("Failed to save default values to components.yml", e); + logger.error("[P2] Failed to save default values to components.yml", e); } this.presets = defaultPreset; } 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 3f75eb56f..3995ff964 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Config.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Config.java @@ -98,12 +98,12 @@ public class Config { field.set(instance, value); return; } catch (final Throwable e) { - logger.error("Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); + logger.error("[P2] Invalid configuration value '{}: {}' in {}", key, value, root.getSimpleName()); e.printStackTrace(); } } } - logger.error("Failed to set config option '{}: {}' | {}", key, value, instance); + logger.error("[P2] Failed to set config option '{}: {}' | {}", key, value, instance); } public static boolean load(File file, Class root) { @@ -289,7 +289,7 @@ public class Config { setAccessible(field); return field; } catch (final Throwable e) { - logger.error("Invalid config field: {} for {}", + logger.error("[P2] Invalid config field: {} for {}", StringMan.join(split, "."), toNodeName(instance.getClass().getSimpleName())); e.printStackTrace(); return null; diff --git a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java index 027ee7d4c..3008ca451 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/file/YamlConfiguration.java @@ -82,11 +82,11 @@ public class YamlConfiguration extends FileConfiguration { } Files.copy(file.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); if (Settings.DEBUG) { - logger.error("Could not read: {}", file); - logger.error("Renamed to: {}", file); - logger.error("============ Full stacktrace ============"); + logger.error("[P2] Could not read: {}", file); + logger.error("[P2] Renamed to: {}", file); + logger.error("[P2] ============ Full stacktrace ============"); ex.printStackTrace(); - logger.error("========================================="); + logger.error("[P2] ========================================="); } } catch (IOException e) { e.printStackTrace(); 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 c2a363d6b..be9758fb5 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -358,12 +358,12 @@ public class SQLManager implements AbstractDB { try { task.run(); } catch (Throwable e) { - logger.error("============ DATABASE ERROR ============"); - logger.error("============ DATABASE ERROR ============"); - logger.error("There was an error updating the database."); - logger.error(" - It will be corrected on shutdown"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] There was an error updating the database."); + logger.error("[P2] - It will be corrected on shutdown"); e.printStackTrace(); - logger.error("========================================"); + logger.error("[P2] ========================================"); } } commit(); @@ -413,12 +413,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.error("============ DATABASE ERROR ============"); - logger.error("There was an error updating the database."); - logger.error(" - It will be corrected on shutdown"); - logger.error("========================================"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] There was an error updating the database."); + logger.error("[P2] - It will be corrected on shutdown"); + logger.error("[P2] ========================================"); e.printStackTrace(); - logger.error("========================================"); + logger.error("[P2] ========================================"); } } if (statement != null && task != null) { @@ -458,12 +458,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.error("============ DATABASE ERROR ============"); - logger.error("There was an error updating the database."); - logger.error(" - It will be corrected on shutdown"); - logger.error("========================================"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] There was an error updating the database."); + logger.error("[P2] - It will be corrected on shutdown"); + logger.error("[P2] ========================================"); e.printStackTrace(); - logger.error("========================================"); + logger.error("[P2] ========================================"); } } if (statement != null && task != null) { @@ -504,12 +504,12 @@ public class SQLManager implements AbstractDB { } lastTask = task; } catch (Throwable e) { - logger.error("============ DATABASE ERROR ============"); - logger.error("There was an error updating the database."); - logger.error(" - It will be corrected on shutdown"); - logger.error("========================================"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] There was an error updating the database."); + logger.error("[P2] - It will be corrected on shutdown"); + logger.error("[P2] ========================================"); e.printStackTrace(); - logger.error("========================================"); + logger.error("[P2] ========================================"); } } if (statement != null && task != null) { @@ -533,12 +533,12 @@ public class SQLManager implements AbstractDB { this.plotTasks.clear(); } } catch (Throwable e) { - logger.error("============ DATABASE ERROR ============"); - logger.error("There was an error updating the database."); - logger.error(" - It will be corrected on shutdown"); - logger.error("========================================"); + logger.error("[P2] ============ DATABASE ERROR ============"); + logger.error("[P2] There was an error updating the database."); + logger.error("[P2] - It will be corrected on shutdown"); + logger.error("[P2] ========================================"); e.printStackTrace(); - logger.error("========================================"); + logger.error("[P2] ========================================"); } return false; } @@ -626,7 +626,7 @@ public class SQLManager implements AbstractDB { } }))))); } catch (SQLException e) { - logger.warn("Failed to set all flags and member tiers for plots", e); + logger.warn("[P2] Failed to set all flags and member tiers for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -635,7 +635,7 @@ public class SQLManager implements AbstractDB { } }); } catch (Exception e) { - logger.warn("Warning! Failed to set all helper for plots", e); + logger.warn("[P2] Warning! Failed to set all helper for plots", e); try { SQLManager.this.connection.commit(); } catch (SQLException e1) { @@ -704,19 +704,19 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - logger.error("Failed to store flag values for plot with entry ID: {}", plot); + logger.error("[P2] Failed to store flag values for plot with entry ID: {}", plot); e.printStackTrace(); continue; } if (Settings.DEBUG) { - logger.info("- Finished converting flag values for plot with entry ID: {}", + logger.info("[P2] - Finished converting flag values for plot with entry ID: {}", plot.getId()); } } } catch (final Exception e) { - logger.error("Failed to store flag values", e); + logger.error("[P2] Failed to store flag values", e); } - logger.info("Finished converting flags ({} plots processed)", plots.size()); + logger.info("[P2] Finished converting flags ({} plots processed)", plots.size()); whenDone.run(); } @@ -833,7 +833,7 @@ public class SQLManager implements AbstractDB { return; } catch (SQLException e) { if (this.mySQL) { - logger.error("1: | {}", objList.get(0).getClass().getCanonicalName()); + logger.error("[P2] 1: | {}", objList.get(0).getClass().getCanonicalName()); e.printStackTrace(); } } @@ -871,8 +871,8 @@ public class SQLManager implements AbstractDB { preparedStmt.close(); } catch (SQLException e) { e.printStackTrace(); - logger.error("2: | {}", objList.get(0).getClass().getCanonicalName()); - logger.error("Could not bulk save!"); + logger.error("[P2] 2: | {}", objList.get(0).getClass().getCanonicalName()); + logger.error("[P2] Could not bulk save!"); try (PreparedStatement preparedStmt = this.connection .prepareStatement(mod.getCreateSQL())) { for (T obj : objList) { @@ -881,7 +881,7 @@ public class SQLManager implements AbstractDB { } preparedStmt.executeBatch(); } catch (SQLException e3) { - logger.error("Failed to save all", e); + logger.error("[P2] Failed to save all", e); e3.printStackTrace(); } } @@ -933,7 +933,7 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - logger.error("Failed to store settings for plot with entry ID: {}", legacySettings.id); + logger.error("[P2] Failed to store settings for plot with entry ID: {}", legacySettings.id); e.printStackTrace(); continue; } @@ -945,13 +945,13 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - logger.error("Failed to store settings", e); + logger.error("[P2] Failed to store settings", e); } } } catch (final Exception e) { - logger.error("Failed to store settings", e); + logger.error("[P2] Failed to store settings", e); } - logger.info("Finished converting settihgs ({} plots processed)", myList.size()); + logger.info("[P2] Finished converting settihgs ({} plots processed)", myList.size()); whenDone.run(); } @@ -1632,11 +1632,11 @@ public class SQLManager implements AbstractDB { } } } catch (final Exception e) { - logger.error("Failed to load old flag values", e); + logger.error("[P2] Failed to load old flag values", e); return false; } - logger.info("Loaded {} plot flag collections...", flagMap.size()); - logger.info("Attempting to store these flags in the new table..."); + logger.info("[P2] Loaded {} plot flag collections...", flagMap.size()); + logger.info("[P2] 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(?, ?, ?)")) { @@ -1664,7 +1664,7 @@ public class SQLManager implements AbstractDB { try { preparedStatement.executeBatch(); } catch (final Exception e) { - logger.error("Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey()); + logger.error("[P2] Failed to store flag values for plot with entry ID: {}", plotFlagEntry.getKey()); e.printStackTrace(); continue; } @@ -1672,17 +1672,17 @@ public class SQLManager implements AbstractDB { if (System.currentTimeMillis() - timeStarted >= 1000L || plotsProcessed >= flagMap .size()) { timeStarted = System.currentTimeMillis(); - logger.info("... Flag conversion in progress. {}% done", + logger.info("[P2] ... Flag conversion in progress. {}% done", String.format("%.1f", ((float) flagsProcessed / totalFlags) * 100)); } if (Settings.DEBUG) { - logger.info("- Finished converting flags for plot with entry ID: {}", + logger.info("[P2] - Finished converting flags for plot with entry ID: {}", plotFlagEntry.getKey()); } } } catch (final Exception e) { - logger.error("Failed to store flag values", e); + logger.error("[P2] Failed to store flag values", e); return false; } return true; @@ -1774,7 +1774,7 @@ public class SQLManager implements AbstractDB { time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(parsable) .getTime(); } catch (ParseException e) { - logger.error("Could not parse date for plot: #{}({};{}) ({})", + logger.error("[P2] Could not parse date for plot: #{}({};{}) ({})", id, areaID, plot_id, parsable); time = System.currentTimeMillis() + id; } @@ -1789,7 +1789,7 @@ public class SQLManager implements AbstractDB { if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(last.temp); } else if (Settings.DEBUG) { - logger.info("Plot #{}({}) in `{}plot` is a duplicate." + logger.info("[P2] Plot #{}({}) in `{}plot` is a duplicate." + " Delete this plot or set `database-purger: true` in the settings.yml", id, last, this.prefix); } } @@ -1821,7 +1821,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_rating` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_rating` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1849,7 +1849,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_helpers` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_helpers` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1876,7 +1876,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_trusted` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_trusted` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1903,7 +1903,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_denied` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_denied` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1931,8 +1931,8 @@ public class SQLManager implements AbstractDB { plot.getFlagContainer().addFlag(plotFlag.parse(value)); } catch (final FlagParseException e) { e.printStackTrace(); - logger.error("Plot with ID {} has an invalid value:", id); - logger.error("Failed to parse flag '{}', value '{}': {}", + logger.error("[P2] Plot with ID {} has an invalid value:", id); + logger.error("[P2] Failed to parse flag '{}', value '{}': {}", plotFlag.getName(), e.getValue(), e.getErrorMessage()); if (!invalidFlags.containsKey(plot)) { invalidFlags.put(plot, new ArrayList<>()); @@ -1943,7 +1943,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_flags` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_flags` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -1999,7 +1999,7 @@ public class SQLManager implements AbstractDB { } else if (Settings.Enabled_Components.DATABASE_PURGER) { toDelete.add(id); } else if (Settings.DEBUG) { - logger.info("Entry #{}({}) in `plot_settings` does not exist." + logger.info("[P2] Entry #{}({}) in `plot_settings` does not exist." + " Create this plot or set `database-purger: true` in settings.yml", id, plot); } } @@ -2017,15 +2017,15 @@ public class SQLManager implements AbstractDB { String worldName = entry.getKey(); invalidPlot = true; if (Settings.DEBUG) { - logger.info("Warning! Found {} plots in DB for non existent world: '{}'", + logger.info("[P2] Warning! Found {} plots in DB for non existent world: '{}'", entry.getValue().intValue(), worldName); } } if (invalidPlot && Settings.DEBUG) { - logger.info("Warning! Please create the world(s) or remove the plots using the purge command"); + logger.info("[P2] Warning! Please create the world(s) or remove the plots using the purge command"); } } catch (SQLException e) { - logger.error("Failed to load plots", e); + logger.error("[P2] Failed to load plots", e); } return newPlots; } @@ -2066,7 +2066,7 @@ public class SQLManager implements AbstractDB { preparedStatement.setInt(3, id2); preparedStatement.execute(); } catch (final Exception e) { - logger.error("Failed to persist wap of {} and {}", plot1, plot2); + logger.error("[P2] Failed to persist wap of {} and {}", plot1, plot2); e.printStackTrace(); future.complete(false); return; @@ -2209,12 +2209,12 @@ public class SQLManager implements AbstractDB { commit(); } } catch (SQLException e) { - logger.error("Failed to purge plots", e); + logger.error("[P2] Failed to purge plots", e); return; } } if (Settings.DEBUG) { - logger.info("Successfully purged {} plots", uniqueIds.size()); + logger.info("[P2] Successfully purged {} plots", uniqueIds.size()); } } }); @@ -2238,7 +2238,7 @@ public class SQLManager implements AbstractDB { } purgeIds(ids); } catch (SQLException e) { - logger.error("Failed to purge area '{}'", area); + logger.error("[P2] Failed to purge area '{}'", area); e.printStackTrace(); } for (Iterator iterator = plots.iterator(); iterator.hasNext(); ) { @@ -2495,7 +2495,7 @@ public class SQLManager implements AbstractDB { } } } catch (SQLException e) { - logger.error("Failed to fetch rating for plot {}", plot.getId().toString()); + logger.error("[P2] Failed to fetch rating for plot {}", plot.getId().toString()); e.printStackTrace(); } return map; @@ -2716,7 +2716,7 @@ public class SQLManager implements AbstractDB { if (cluster != null) { cluster.helpers.add(user); } else if (Settings.DEBUG) { - logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + logger.warn("[P2] Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2735,7 +2735,7 @@ public class SQLManager implements AbstractDB { if (cluster != null) { cluster.invited.add(user); } else if (Settings.DEBUG) { - logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + logger.warn("[P2] Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2770,7 +2770,7 @@ public class SQLManager implements AbstractDB { } cluster.settings.setMerged(merged); } else if (Settings.DEBUG) { - logger.warn("Cluster #{}({}) in cluster_helpers does not exist." + logger.warn("[P2] Cluster #{}({}) in cluster_helpers does not exist." + " Please create the cluster or remove this entry", id, cluster); } } @@ -2780,13 +2780,13 @@ public class SQLManager implements AbstractDB { for (Entry entry : noExist.entrySet()) { String a = entry.getKey(); invalidPlot = true; - logger.warn("Warning! Found {} clusters in DB for non existent area; '{}'", noExist.get(a), a); + logger.warn("[P2] Warning! Found {} clusters in DB for non existent area; '{}'", noExist.get(a), a); } if (invalidPlot) { - logger.warn("Warning! Please create the world(s) or remove the clusters using the purge command"); + logger.warn("[P2] Warning! Please create the world(s) or remove the clusters using the purge command"); } } catch (SQLException e) { - logger.error("Failed to load clusters", e); + logger.error("[P2] Failed to load clusters", e); } return newClusters; } @@ -2978,7 +2978,7 @@ public class SQLManager implements AbstractDB { if (!isValid()) { reconnect(); } - logger.info("All DB transactions during this session are being validated (This may take a while if corrections need to be made)"); + logger.info("[P2] 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()) { @@ -2999,13 +2999,13 @@ public class SQLManager implements AbstractDB { continue; } if (plot.getArea() == null) { - logger.error("CRITICAL ERROR IN VALIDATION TASK!"); - logger.error("PLOT AREA CANNOT BE NULL! SKIPPING PLOT!"); + logger.error("[P2] CRITICAL ERROR IN VALIDATION TASK!"); + logger.error("[P2] PLOT AREA CANNOT BE NULL! SKIPPING PLOT!"); continue; } if (database == null) { - logger.error("CRITICAL ERROR IN VALIDATION TASK!"); - logger.error("DATABASE VARIABLE CANNOT BE NULL! NOW ENDING VALIDATION!"); + logger.error("[P2] CRITICAL ERROR IN VALIDATION TASK!"); + logger.error("[P2] DATABASE VARIABLE CANNOT BE NULL! NOW ENDING VALIDATION!"); break; } HashMap worldPlots = database.get(plot.getArea().toString()); 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 fd9ba5027..00f1bce1a 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLite.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLite.java @@ -68,7 +68,7 @@ public class SQLite extends Database { try { file.createNewFile(); } catch (IOException ignored) { - logger.error("Unable to create database"); + logger.error("[P2] Unable to create database"); } } Class.forName("org.sqlite.JDBC"); 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 496acc747..82f87eb90 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -164,7 +164,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { // Dump world settings if (Settings.DEBUG) { - logger.info("- Dumping settings for ClassicPlotWorld with name {}", this.getWorldName()); + logger.info("[P2] - 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 +180,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } catch (final IllegalAccessException e) { value = String.format("Failed to parse: %s", e.getMessage()); } - logger.info("-- {} = {}", name, value); + logger.info("[P2] -- {} = {}", name, value); } } } @@ -282,12 +282,12 @@ public class HybridPlotWorld extends ClassicPlotWorld { } if (Settings.DEBUG) { - logger.info(" - plot schematic: {}", schematic3File.getPath()); + logger.info("[P2] - plot schematic: {}", schematic3File.getPath()); } } if (schematic1 == null || schematic2 == null || this.ROAD_WIDTH == 0) { if (Settings.DEBUG) { - logger.info(" - schematic: false"); + logger.info("[P2] - schematic: false"); } return; } @@ -364,7 +364,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) { - logger.error("Error adding overlay block. `y > height`"); + logger.error("[P2] 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 209eddec1..7d21d9579 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java @@ -413,24 +413,24 @@ public abstract class HybridUtils { iter.remove(); boolean regenedRoad = regenerateRoad(area, chunk, extend); if (!regenedRoad && Settings.DEBUG) { - logger.info("Failed to regenerate roads"); + logger.info("[P2] Failed to regenerate roads"); } ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true); } if (Settings.DEBUG) { - logger.info("Cancelled road task"); + logger.info("[P2] Cancelled road task"); } return; } count.incrementAndGet(); if (count.intValue() % 20 == 0) { - logger.info("Progress: {}%", 100 * (2048 - chunks.size()) / 2048); + logger.info("[P2] Progress: {}%", 100 * (2048 - chunks.size()) / 2048); } if (HybridUtils.regions.isEmpty() && chunks.isEmpty()) { regeneratePlotWalls(area); HybridUtils.UPDATE = false; - logger.info("Finished road conversion"); + logger.info("[P2] Finished road conversion"); // CANCEL TASK } else { final Runnable task = this; @@ -443,9 +443,9 @@ public abstract class HybridUtils { BlockVector2 loc = iterator.next(); iterator.remove(); if (Settings.DEBUG) { - logger.info("Updating .mcr: {}, {} (approx 1024 chunks)", + logger.info("[P2] Updating .mcr: {}, {} (approx 1024 chunks)", loc.getX(), loc.getZ()); - logger.info("- Remaining: {}", HybridUtils.regions.size()); + logger.info("[P2] - Remaining: {}", HybridUtils.regions.size()); } chunks.addAll(getChunks(loc)); System.gc(); @@ -463,7 +463,7 @@ public abstract class HybridUtils { boolean regenedRoads = regenerateRoad(area, chunk, extend); if (!regenedRoads && Settings.DEBUG) { - logger.info("Failed to regenerate road"); + logger.info("[P2] Failed to regenerate road"); } } } @@ -474,7 +474,7 @@ public abstract class HybridUtils { Iterator iterator = HybridUtils.regions.iterator(); BlockVector2 loc = iterator.next(); iterator.remove(); - logger.error("Error! Could not update '{}/region/r.{}.{}.mca' (Corrupt chunk?)", + logger.error("[P2] 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; diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index f2a6b2284..53d00089b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -49,7 +49,7 @@ public abstract class SquarePlotWorld extends GridPlotWorld { @Override public void loadConfiguration(ConfigurationSection config) { if (!config.contains("plot.height")) { if (Settings.DEBUG) { - logger.info(" - Configuration is null? ({})", config.getCurrentPath()); + logger.info("[P2] - Configuration is null? ({})", config.getCurrentPath()); } } 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 304317c10..07307f37a 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -585,7 +585,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer for (Plot owned : getPlots()) { owned.deletePlot(null); if (Settings.DEBUG) { - logger.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName()); + logger.info("[P2] Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName()); } } } 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 be1efa86e..a746dd272 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -1745,7 +1745,7 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { - logger.error("Player {} attempted to claim plot {}, but the database failed to update", + logger.error("[P2] Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString()); return false; } @@ -1833,7 +1833,7 @@ public class Plot { }); return true; } - logger.info("Failed to add plot {} to plot area {}", + logger.info("[P2] Failed to add plot {} to plot area {}", this.getId().toCommaSeparatedString(), this.area.toString()); return false; } 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 32b650a2a..9501768ed 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -1063,7 +1063,7 @@ public abstract class PlotArea { try { flags.add(flagInstance.parse(split[1])); } catch (final FlagParseException e) { - logger.warn("Failed to parse default flag with key '{}' and value '{}'. " + logger.warn("[P2] Failed to parse default flag with key '{}' and value '{}'. " + "Reason: {}. This flag will not be added as a default flag.", e.getFlag().getName(), e.getValue(), 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 d3e9e956e..0cfa1e1d9 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 @@ -97,7 +97,7 @@ public class PlotAnalysis { public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) { if (running) { if (Settings.DEBUG) { - logger.info("Calibration task already in progress!"); + logger.info("[P2] Calibration task already in progress!"); } return; } @@ -114,7 +114,7 @@ public class PlotAnalysis { @Override public void run() { Iterator iterator = plots.iterator(); if (Settings.DEBUG) { - logger.info("- Reducing {} plots to those with sufficient data", plots.size()); + logger.info("[P2] - Reducing {} plots to those with sufficient data", plots.size()); } while (iterator.hasNext()) { Plot plot = iterator.next(); @@ -139,7 +139,7 @@ public class PlotAnalysis { } if (Settings.DEBUG) { - logger.info("- Analyzing plot contents (this may take a while)"); + logger.info("[P2] - Analyzing plot contents (this may take a while)"); } int[] changes = new int[plots.size()]; @@ -167,7 +167,7 @@ public class PlotAnalysis { (plot.getAverageRating() + plot.getSettings().getRatings().size()) * 100); if (Settings.DEBUG) { - logger.info(" | {} (rating) {}", plot, ratings[i]); + logger.info("[P2] | {} (rating) {}", plot, ratings[i]); } } } @@ -181,7 +181,7 @@ public class PlotAnalysis { break; } if (Settings.DEBUG) { - logger.info(" | {}", queuePlot); + logger.info("[P2] | {}", queuePlot); } final Object lock = new Object(); TaskManager.runTask(new Runnable() { @@ -213,7 +213,7 @@ public class PlotAnalysis { } if (Settings.DEBUG) { - logger.info(" - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size()); + logger.info("[P2] - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size()); } try { @@ -229,7 +229,7 @@ public class PlotAnalysis { for (int i = 0; i < plots.size(); i++) { Plot plot = plots.get(i); if (Settings.DEBUG) { - logger.info(" | {}", plot); + logger.info("[P2] | {}", plot); } PlotAnalysis analysis = plot.getComplexity(null); @@ -247,7 +247,7 @@ public class PlotAnalysis { } if (Settings.DEBUG) { - logger.info(" - Calculating rankings"); + logger.info("[P2] - Calculating rankings"); } int[] rankRatings = rank(ratings); @@ -256,7 +256,7 @@ public class PlotAnalysis { int optimalIndex = (int) Math.round((1 - threshold) * (n - 1)); if (Settings.DEBUG) { - logger.info(" - Calculating rank correlation: "); + logger.info("[P2] - Calculating rank correlation: "); logger.info( " - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking"); logger.info( @@ -275,7 +275,7 @@ public class PlotAnalysis { (int) (factorChanges * 1000 / MathMan.getMean(changes)); if (Settings.DEBUG) { - logger.info(" - | changes {}", factorChanges); + logger.info("[P2] - | changes {}", factorChanges); } int[] rankFaces = rank(faces); @@ -287,7 +287,7 @@ public class PlotAnalysis { factorFaces == 1 ? 0 : (int) (factorFaces * 1000 / MathMan.getMean(faces)); if (Settings.DEBUG) { - logger.info(" - | faces {}", factorFaces); + logger.info("[P2] - | faces {}", factorFaces); } int[] rankData = rank(data); @@ -299,7 +299,7 @@ public class PlotAnalysis { factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data)); if (Settings.DEBUG) { - logger.info(" - | data {}", factor_data); + logger.info("[P2] - | data {}", factor_data); } int[] rank_air = rank(air); @@ -311,7 +311,7 @@ public class PlotAnalysis { factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air)); if (Settings.DEBUG) { - logger.info("- | air {}", factor_air); + logger.info("[P2] - | air {}", factor_air); } int[] rank_variety = rank(variety); @@ -324,7 +324,7 @@ public class PlotAnalysis { (int) (factor_variety * 1000 / MathMan.getMean(variety)); if (Settings.DEBUG) { - logger.info("- | variety {}", factor_variety); + logger.info("[P2] - | variety {}", factor_variety); } int[] rank_changes_sd = rank(changes_sd); @@ -337,7 +337,7 @@ public class PlotAnalysis { (int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd)); if (Settings.DEBUG) { - logger.info(" - | changed_sd {}", factor_changes_sd); + logger.info("[P2] - | changed_sd {}", factor_changes_sd); } int[] rank_faces_sd = rank(faces_sd); @@ -350,7 +350,7 @@ public class PlotAnalysis { (int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd)); if (Settings.DEBUG) { - logger.info(" - | faced_sd {}", factor_faces_sd); + logger.info("[P2] - | faced_sd {}", factor_faces_sd); } int[] rank_data_sd = rank(data_sd); @@ -363,7 +363,7 @@ public class PlotAnalysis { (int) (factor_data_sd * 1000 / MathMan.getMean(data_sd)); if (Settings.DEBUG) { - logger.info(" - | data_sd {}", factor_data_sd); + logger.info("[P2] - | data_sd {}", factor_data_sd); } int[] rank_air_sd = rank(air_sd); @@ -375,7 +375,7 @@ public class PlotAnalysis { factor_air_sd == 1 ? 0 : (int) (factor_air_sd * 1000 / MathMan.getMean(air_sd)); if (Settings.DEBUG) { - logger.info(" - | air_sd {}", factor_air_sd); + logger.info("[P2] - | air_sd {}", factor_air_sd); } int[] rank_variety_sd = rank(variety_sd); @@ -388,13 +388,13 @@ public class PlotAnalysis { (int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd)); if (Settings.DEBUG) { - logger.info(" - | variety_sd {}", factor_variety_sd); + logger.info("[P2] - | variety_sd {}", factor_variety_sd); } int[] complexity = new int[n]; if (Settings.DEBUG) { - logger.info(" Calculating threshold"); + logger.info("[P2] Calculating threshold"); } int max = 0; @@ -426,7 +426,7 @@ public class PlotAnalysis { logln(getCC(n, sum(square(getSD(rankComplexity, rankRatings))))); if (optimalComplexity == Integer.MAX_VALUE) { if (Settings.DEBUG) { - logger.info("Insufficient data to determine correlation! {} | {}", + logger.info("[P2] Insufficient data to determine correlation! {} | {}", optimalIndex, n); } running = false; @@ -447,7 +447,7 @@ public class PlotAnalysis { // Save calibration if (Settings.DEBUG) { - logger.info(" Saving calibration"); + logger.info("[P2] Saving calibration"); } Settings.AUTO_CLEAR.put("auto-calibrated", settings); Settings.save(PlotSquared.get().worldsFile); @@ -456,7 +456,7 @@ public class PlotAnalysis { plot.removeRunning(); } if (Settings.DEBUG) { - logger.info(" Done!"); + logger.info("[P2] Done!"); } whenDone.run(); } @@ -465,7 +465,7 @@ public class PlotAnalysis { public static void logln(Object obj) { if (Settings.DEBUG) { - logger.info(log(obj)); + logger.info("[P2] " + log(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 2c398d1c7..871cf48c7 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 @@ -148,7 +148,7 @@ import java.util.Map; this.updateSubscribers .forEach(subscriber -> subscriber.handle(flag, plotFlagUpdateType)); } catch (IllegalStateException e) { - logger.info("Flag {} (class '{}') could not be added to the container because the " + logger.info("[P2] 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 a2d4d4a94..dd5dd34af 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 @@ -134,7 +134,7 @@ public class BlockTypeWrapper { this.blockCategory = BlockCategory.REGISTRY.get(this.blockCategoryId); if (this.blockCategory == null && !BlockCategory.REGISTRY.values().isEmpty()) { if (Settings.DEBUG) { - logger.info("- Block category #{} does not exist", this.blockCategoryId); + logger.info("[P2] - 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 f72dc9aef..e5d431935 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 @@ -42,7 +42,7 @@ public class PlotMessage { try { reset(ChatManager.manager); } catch (Throwable e) { - logger.error("{} doesn't support fancy chat for {}", PlotSquared.imp().getPluginName(), PlotSquared.get().IMP.getServerVersion()); + logger.error("[P2] {} 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/util/Expression.java b/Core/src/main/java/com/plotsquared/core/util/Expression.java index 40b3d1c78..94d1aefc8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/Expression.java +++ b/Core/src/main/java/com/plotsquared/core/util/Expression.java @@ -72,7 +72,7 @@ public abstract class Expression { return (Double) exec.getEngine().eval(expression.replace("{arg}", "" + arg)); } catch (ScriptException e) { if (Settings.DEBUG) { - logger.info("Invalid expression: {}", expression); + logger.info("[P2] Invalid expression: {}", expression); } e.printStackTrace(); } 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 5c5799c78..df0e253d6 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -521,7 +521,7 @@ public class MainUtil { if (arg == null) { if (player == null) { if (message) { - logger.info("No plot area string was supplied"); + logger.info("[P2] No plot area string was supplied"); } return null; } 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 eae87a02b..c0162b0d5 100644 --- a/Core/src/main/java/com/plotsquared/core/util/RegionManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/RegionManager.java @@ -145,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); - logger.info("- Deleting file: {} (max 1024 chunks)", file.getName()); + logger.info("[P2] - Deleting file: {} (max 1024 chunks)", file.getName()); 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 c79e680a8..0784ca825 100644 --- a/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java +++ b/Core/src/main/java/com/plotsquared/core/util/SchematicHandler.java @@ -156,7 +156,7 @@ public abstract class SchematicHandler { boolean result = SchematicHandler.manager .save(value, directory + File.separator + name + ".schem"); if (!result) { - logger.error("Failed to save {}", plot.getId()); + logger.error("[P2] Failed to save {}", plot.getId()); } TaskManager.runTask(THIS); }); diff --git a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java index 8c8359865..e37744590 100644 --- a/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java +++ b/Core/src/main/java/com/plotsquared/core/util/net/IncendoPaster.java @@ -161,7 +161,7 @@ public final class IncendoPaster { if (!httpURLConnection.getResponseMessage().contains("OK")) { if (httpURLConnection.getResponseCode() == 413) { final long size = content.length; - logger.error("Paste too big > size: {}MB", size / 1_000_000); + logger.error("[P2] Paste too big > size: {}MB", size / 1_000_000); } throw new IllegalStateException(String .format("Server returned status: %d %s", httpURLConnection.getResponseCode(), 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 8d1e38337..7520b66a6 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -168,7 +168,7 @@ public class UUIDPipeline { } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException ignored) { - logger.warn("(UUID) Request for {} timed out", username); + logger.warn("[P2] (UUID) Request for {} timed out", username); // This is completely valid, we just don't care anymore } return null; @@ -191,7 +191,7 @@ public class UUIDPipeline { } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } catch (TimeoutException ignored) { - logger.warn("(UUID) Request for {} timed out", uuid); + logger.warn("[P2] (UUID) Request for {} timed out", uuid); // This is completely valid, we just don't care anymore } return null; @@ -325,7 +325,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.info("(UUID) Failed to find all usernames"); + logger.info("[P2] (UUID) Failed to find all usernames"); } if (Settings.UUID.UNKNOWN_AS_DEFAULT) { @@ -388,7 +388,7 @@ public class UUIDPipeline { this.consume(mappings); return mappings; } else if (Settings.DEBUG) { - logger.info("(UUID) Failed to find all UUIDs"); + logger.info("[P2] (UUID) Failed to find all UUIDs"); } throw new ServiceError("End of pipeline"); From 1dc4da8beb39f3458409888afa22a955ae96ff02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 14 Jul 2020 13:21:59 +0200 Subject: [PATCH 12/12] Fix issues from previous merge --- .../java/com/plotsquared/bukkit/BukkitMain.java | 1 - .../bukkit/uuid/SquirrelIdUUIDService.java | 15 ++++++++++----- .../java/com/plotsquared/core/PlotSquared.java | 10 ---------- .../java/com/plotsquared/core/plot/PlotArea.java | 3 ++- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index 083f7e58d..e68466d6a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -933,7 +933,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain< return perm; } } catch (Throwable ignored) { - PlotSquared.debug("No permissions detected!"); } return null; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java index 8c8dfca83..bb1640d33 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java @@ -26,14 +26,15 @@ package com.plotsquared.bukkit.uuid; import com.google.common.util.concurrent.RateLimiter; -import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.uuid.UUIDMapping; import com.plotsquared.core.uuid.UUIDService; import com.sk89q.squirrelid.Profile; import com.sk89q.squirrelid.resolver.HttpRepositoryService; import com.sk89q.squirrelid.resolver.ProfileService; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; @@ -47,6 +48,8 @@ import java.util.UUID; @SuppressWarnings("UnstableApiUsage") public class SquirrelIdUUIDService implements UUIDService { + private static final Logger logger = LoggerFactory.getLogger("P2/" + SquirrelIdUUIDService.class.getSimpleName()); + private final ProfileService profileService; private final RateLimiter rateLimiter; @@ -78,7 +81,9 @@ public class SquirrelIdUUIDService implements UUIDService { // go through them one by one // if (uuids.size() >= 2) { - PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID in batch. Will try each UUID individually."); + if (Settings.DEBUG) { + logger.info("[P2] (UUID) Found invalid UUID in batch. Will try each UUID individually."); + } for (final UUID uuid : uuids) { final List result = this.getNames(Collections.singletonList(uuid)); if (result.isEmpty()) { @@ -86,8 +91,8 @@ public class SquirrelIdUUIDService implements UUIDService { } results.add(result.get(0)); } - } else if (uuids.size() == 1) { - PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID: " + uuids.get(0)); + } else if (uuids.size() == 1 && Settings.DEBUG) { + logger.info("[P2] (UUID) Found invalid UUID: {}", uuids.get(0)); } } } catch (IOException | InterruptedException e) { diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index 25e62db2a..d5618ed0f 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -1716,18 +1716,8 @@ public class PlotSquared { } catch (IOException ignored) { logger.error("[P2] Failed to save storage.yml"); } - try { - this.commandsFile = new File(folder, "commands.yml"); - if (!this.commandsFile.exists() && !this.commandsFile.createNewFile()) { - logger.error("[P2] Could not create the commands file. Please create 'commands.yml' manually"); - } - this.commands = YamlConfiguration.loadConfiguration(this.commandsFile); - } catch (IOException ignored) { - logger.error("[P2] Failed to save commands.yml"); - } try { this.style.save(this.styleFile); - this.commands.save(this.commandsFile); } catch (IOException e) { logger.error("[P2] Configuration file saving failed", e); } 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 d2e0d3fda..25230ab89 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -408,7 +408,8 @@ public abstract class PlotArea { prefix = ", "; } } - PlotSquared.log(Captions.PREFIX + "&3 - road flags: &7" + roadFlagBuilder.toString()); + + logger.info("[P2] - road flags: {}", roadFlagBuilder.toString()); loadConfiguration(config); }