From d6804737cf2ad084e052a774438c9a8885731986 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Wed, 13 Mar 2019 19:51:48 -0700 Subject: [PATCH 1/3] Switch to SLF4J logging. --- config/checkstyle/import-control.xml | 1 + worldedit-bukkit/build.gradle | 1 + .../wepif/FlatFilePermissionsResolver.java | 10 ++-- .../sk89q/wepif/NijiPermissionsResolver.java | 15 +++-- .../wepif/PermissionsResolverManager.java | 14 ++--- .../bukkit/BukkitCommandInspector.java | 14 ++--- .../worldedit/bukkit/BukkitConfiguration.java | 3 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 20 +++---- .../worldedit/bukkit/WorldEditPlugin.java | 20 +++---- .../bukkit/adapter/BukkitImplLoader.java | 16 ++--- worldedit-core/build.gradle | 1 + .../util/commands/CommandsManager.java | 10 ++-- .../util/commands/SimpleInjector.java | 9 +-- .../java/com/sk89q/worldedit/EditSession.java | 23 ++++---- .../com/sk89q/worldedit/LocalSession.java | 7 +-- .../sk89q/worldedit/TracedEditSession.java | 8 +-- .../java/com/sk89q/worldedit/WorldEdit.java | 21 +++---- .../worldedit/command/SchematicCommands.java | 14 ++--- .../worldedit/command/SnapshotCommands.java | 6 +- .../command/SnapshotUtilCommands.java | 11 ++-- .../extension/platform/CommandManager.java | 26 ++++---- .../extension/platform/PlatformManager.java | 17 +++--- .../extent/clipboard/io/ClipboardFormats.java | 7 +-- .../clipboard/io/MCEditSchematicReader.java | 18 +++--- .../clipboard/io/SpongeSchematicReader.java | 9 +-- .../command/CommandLoggingHandler.java | 4 +- .../ReparametrisingInterpolation.java | 11 ++-- .../worldedit/session/SessionManager.java | 15 +++-- .../session/storage/JsonFileSessionStore.java | 16 ++--- .../util/PropertiesConfiguration.java | 10 ++-- .../worldedit/util/YAMLConfiguration.java | 5 +- .../worldedit/util/eventbus/EventBus.java | 13 ++-- .../com/sk89q/worldedit/util/io/Closer.java | 12 ++-- .../util/logging/WorldEditPrefixHandler.java | 59 ------------------- .../util/paste/ActorCallbackPaste.java | 8 +-- .../util/report/ShallowObjectReport.java | 9 +-- .../worldedit/world/block/BlockState.java | 2 +- .../worldedit/world/chunk/AnvilChunk.java | 5 +- .../sk89q/worldedit/world/chunk/OldChunk.java | 2 +- .../world/registry/BundledBlockData.java | 11 ++-- .../world/registry/BundledItemData.java | 11 ++-- .../world/registry/LegacyMapper.java | 15 +++-- .../worldedit/world/snapshot/Snapshot.java | 5 +- .../util/commands/CommandContextTest.java | 34 +++++------ worldedit-forge/build.gradle | 1 + .../sponge/adapter/SpongeImplLoader.java | 16 ++--- 46 files changed, 247 insertions(+), 318 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/WorldEditPrefixHandler.java diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index 9cc735070..28ccad1e4 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -15,6 +15,7 @@ + diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 8c2890bd3..944956fa8 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -14,6 +14,7 @@ dependencies { compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' // zzz compile 'org.bstats:bstats-bukkit:1.4' compile "io.papermc:paperlib:1.0.1" + compile 'org.slf4j:slf4j-jdk14:1.7.26' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java index 3f2324596..9b5229cf3 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/FlatFilePermissionsResolver.java @@ -22,6 +22,8 @@ package com.sk89q.wepif; import com.sk89q.util.yaml.YAMLProcessor; import org.bukkit.OfflinePlayer; import org.bukkit.Server; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.File; @@ -32,12 +34,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; public class FlatFilePermissionsResolver implements PermissionsResolver { - private static final Logger log = Logger.getLogger(FlatFilePermissionsResolver.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(FlatFilePermissionsResolver.class); private Map> userPermissionsCache; private Set defaultPermissionsCache; @@ -98,7 +98,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver { } } } catch (IOException e) { - log.log(Level.WARNING, "Failed to load permissions", e); + log.warn("Failed to load permissions", e); } finally { try { if (buff != null) { @@ -164,7 +164,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver { } } } catch (IOException e) { - log.log(Level.WARNING, "Failed to load permissions", e); + log.warn("Failed to load permissions", e); } finally { try { if (buff != null) { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java index fe23bfa46..ef12e2ff4 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/NijiPermissionsResolver.java @@ -28,13 +28,12 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; - -import java.util.logging.Level; -import java.util.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NijiPermissionsResolver implements PermissionsResolver { - private static final Logger log = Logger.getLogger(NijiPermissionsResolver.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(NijiPermissionsResolver.class); private Server server; private Permissions api; @@ -84,7 +83,7 @@ public class NijiPermissionsResolver implements PermissionsResolver { return api.Security.permission(player, permission); } } catch (Throwable t) { - log.log(Level.WARNING, "Failed to check permissions", t); + log.warn("Failed to check permissions", t); return false; } } @@ -98,7 +97,7 @@ public class NijiPermissionsResolver implements PermissionsResolver { return api.getHandler().has(server.getPlayerExact(name), permission); } } catch (Throwable t) { - log.log(Level.WARNING, "Failed to check permissions", t); + log.warn("Failed to check permissions", t); return false; } } @@ -115,7 +114,7 @@ public class NijiPermissionsResolver implements PermissionsResolver { return api.Security.inGroup(name, group); } } catch (Throwable t) { - log.log(Level.WARNING, "Failed to check groups", t); + log.warn("Failed to check groups", t); return false; } } @@ -139,7 +138,7 @@ public class NijiPermissionsResolver implements PermissionsResolver { return groups; } } catch (Throwable t) { - log.log(Level.WARNING, "Failed to get groups", t); + log.warn("Failed to get groups", t); return new String[0]; } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java index 4775d86c4..6514912a8 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java @@ -27,6 +27,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.Plugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -35,8 +37,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; public class PermissionsResolverManager implements PermissionsResolver { @@ -85,7 +85,7 @@ public class PermissionsResolverManager implements PermissionsResolver { private Server server; private PermissionsResolver permissionResolver; private YAMLProcessor config; - private Logger logger = Logger.getLogger(getClass().getCanonicalName()); + private Logger logger = LoggerFactory.getLogger(getClass()); private List> enabledResolvers = new ArrayList<>(); @SuppressWarnings("unchecked") @@ -119,7 +119,7 @@ public class PermissionsResolverManager implements PermissionsResolver { break; } } catch (Throwable e) { - logger.log(Level.WARNING, "Error in factory method for " + resolverClass.getSimpleName(), e); + logger.warn("Error in factory method for " + resolverClass.getSimpleName(), e); continue; } } @@ -195,14 +195,14 @@ public class PermissionsResolverManager implements PermissionsResolver { try { file.createNewFile(); } catch (IOException e) { - logger.log(Level.WARNING, "Failed to create new configuration file", e); + logger.warn("Failed to create new configuration file", e); } } config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED); try { config.load(); } catch (IOException e) { - logger.log(Level.WARNING, "Error loading WEPIF configuration", e); + logger.warn("Error loading WEPIF configuration", e); } List keys = config.getKeys(null); config.setHeader(CONFIG_HEADER); @@ -232,7 +232,7 @@ public class PermissionsResolverManager implements PermissionsResolver { } catch (ClassNotFoundException e) {} if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) { - logger.warning("WEPIF: Invalid or unknown class found in enabled resolvers: " + logger.warn("WEPIF: Invalid or unknown class found in enabled resolvers: " + nextName + ". Moving to disabled resolvers list."); i.remove(); disabledResolvers.add(nextName); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java index b392c50ac..fa3f2917f 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandInspector.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.bukkit; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.bukkit.util.CommandInspector; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.extension.platform.Actor; @@ -29,12 +27,14 @@ import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.logging.Logger; +import static com.google.common.base.Preconditions.checkNotNull; class BukkitCommandInspector implements CommandInspector { - private static final Logger logger = Logger.getLogger(BukkitCommandInspector.class.getCanonicalName()); + private static final Logger logger = LoggerFactory.getLogger(BukkitCommandInspector.class); private final WorldEditPlugin plugin; private final Dispatcher dispatcher; @@ -51,7 +51,7 @@ class BukkitCommandInspector implements CommandInspector { if (mapping != null) { return mapping.getDescription().getDescription(); } else { - logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'"); + logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'"); return "Help text not available"; } } @@ -63,7 +63,7 @@ class BukkitCommandInspector implements CommandInspector { Description description = mapping.getDescription(); return "Usage: " + description.getUsage() + (description.getHelp() != null ? "\n" + description.getHelp() : ""); } else { - logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'"); + logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'"); return "Help text not available"; } } @@ -76,7 +76,7 @@ class BukkitCommandInspector implements CommandInspector { locals.put(Actor.class, plugin.wrapCommandSender(sender)); return mapping.getCallable().testPermission(locals); } else { - logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'"); + logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'"); return false; } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java index 494a464ea..96c755083 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitConfiguration.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.worldedit.util.YAMLConfiguration; import com.sk89q.worldedit.util.report.Unreported; +import org.slf4j.LoggerFactory; import java.io.File; @@ -34,7 +35,7 @@ public class BukkitConfiguration extends YAMLConfiguration { @Unreported private final WorldEditPlugin plugin; public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) { - super(config, plugin.getLogger()); + super(config, LoggerFactory.getLogger(plugin.getLogger().getName())); this.plugin = plugin; } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 8490c891e..0eb37223e 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.bukkit; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; @@ -48,17 +46,17 @@ import org.bukkit.block.Chest; import org.bukkit.entity.Entity; import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.Inventory; +import org.slf4j.Logger; +import javax.annotation.Nullable; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; public class BukkitWorld extends AbstractWorld { @@ -118,9 +116,9 @@ public class BukkitWorld extends AbstractWorld { return null; } } catch (Exception e) { - logger.warning("Corrupt entity found when creating: " + entity.getType().getId()); + logger.warn("Corrupt entity found when creating: " + entity.getType().getId()); if (entity.getNbtData() != null) { - logger.warning(entity.getNbtData().toString()); + logger.warn(entity.getNbtData().toString()); } e.printStackTrace(); return null; @@ -183,7 +181,7 @@ public class BukkitWorld extends AbstractWorld { try { getWorld().regenerateChunk(chunk.getBlockX(), chunk.getBlockZ()); } catch (Throwable t) { - logger.log(Level.WARNING, "Chunk generation via Bukkit raised an error", t); + logger.warn("Chunk generation via Bukkit raised an error", t); } // Then restore @@ -280,7 +278,7 @@ public class BukkitWorld extends AbstractWorld { treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_MUSHROOM, TreeType.BROWN_MUSHROOM); for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) { if (treeTypeMapping.get(type) == null) { - WorldEdit.logger.severe("No TreeType mapping for TreeGenerator.TreeType." + type); + WorldEdit.logger.error("No TreeType mapping for TreeGenerator.TreeType." + type); } } } @@ -426,8 +424,8 @@ public class BukkitWorld extends AbstractWorld { return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight); } catch (Exception e) { if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) { - logger.warning("Tried to set a corrupt tile entity at " + position.toString()); - logger.warning(((BaseBlock) block).getNbtData().toString()); + logger.warn("Tried to set a corrupt tile entity at " + position.toString()); + logger.warn(((BaseBlock) block).getNbtData().toString()); } e.printStackTrace(); Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index d09578472..200444ab4 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.bukkit; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.base.Joiner; import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.wepif.PermissionsResolverManager; @@ -58,7 +56,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -68,17 +69,16 @@ import java.util.List; import java.util.Map; import java.util.jar.JarFile; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.ZipEntry; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; /** * Plugin for Bukkit. */ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { - private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(WorldEditPlugin.class); public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui"; private static WorldEditPlugin INSTANCE; @@ -194,23 +194,23 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { try { adapterLoader.addFromPath(getClass().getClassLoader()); } catch (IOException e) { - log.log(Level.WARNING, "Failed to search path for Bukkit adapters"); + log.warn("Failed to search path for Bukkit adapters"); } try { adapterLoader.addFromJar(getFile()); } catch (IOException e) { - log.log(Level.WARNING, "Failed to search " + getFile() + " for Bukkit adapters", e); + log.warn("Failed to search " + getFile() + " for Bukkit adapters", e); } try { bukkitAdapter = adapterLoader.loadAdapter(); - log.log(Level.INFO, "Using " + bukkitAdapter.getClass().getCanonicalName() + " as the Bukkit adapter"); + log.info("Using " + bukkitAdapter.getClass().getCanonicalName() + " as the Bukkit adapter"); } catch (AdapterLoadException e) { Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING); if (platform instanceof BukkitServerInterface) { - log.log(Level.WARNING, e.getMessage()); + log.warn(e.getMessage()); } else { - log.log(Level.INFO, "WorldEdit could not find a Bukkit adapter for this MC version, " + + log.info("WorldEdit could not find a Bukkit adapter for this MC version, " + "but it seems that you have another implementation of WorldEdit installed (" + platform.getPlatformName() + ") " + "that handles the world editing."); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java index 891106eca..a03a9f229 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java @@ -20,6 +20,8 @@ package com.sk89q.worldedit.bukkit.adapter; import com.sk89q.worldedit.util.io.Closer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -29,15 +31,13 @@ import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Loads Bukkit implementation adapters. */ public class BukkitImplLoader { - private static final Logger log = Logger.getLogger(BukkitImplLoader.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(BukkitImplLoader.class); private final List adapterCandidates = new ArrayList<>(); private String customCandidate; @@ -73,7 +73,7 @@ public class BukkitImplLoader { if (className != null) { customCandidate = className; adapterCandidates.add(className); - log.log(Level.INFO, "-Dworldedit.bukkit.adapter used to add " + className + " to the list of available Bukkit adapters"); + log.info("-Dworldedit.bukkit.adapter used to add " + className + " to the list of available Bukkit adapters"); } } @@ -157,18 +157,18 @@ public class BukkitImplLoader { if (BukkitImplAdapter.class.isAssignableFrom(cls)) { return (BukkitImplAdapter) cls.newInstance(); } else { - log.log(Level.WARNING, "Failed to load the Bukkit adapter class '" + className + + log.warn("Failed to load the Bukkit adapter class '" + className + "' because it does not implement " + BukkitImplAdapter.class.getCanonicalName()); } } catch (ClassNotFoundException e) { - log.log(Level.WARNING, "Failed to load the Bukkit adapter class '" + className + + log.warn("Failed to load the Bukkit adapter class '" + className + "' that is not supposed to be missing", e); } catch (IllegalAccessException e) { - log.log(Level.WARNING, "Failed to load the Bukkit adapter class '" + className + + log.warn("Failed to load the Bukkit adapter class '" + className + "' that is not supposed to be raising this error", e); } catch (Throwable e) { if (className.equals(customCandidate)) { - log.log(Level.WARNING, "Failed to load the Bukkit adapter class '" + className + "'", e); + log.warn("Failed to load the Bukkit adapter class '" + className + "'", e); } } } diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index da2c61c44..f91186083 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -12,6 +12,7 @@ dependencies { compile 'com.google.code.gson:gson:2.8.0' compile 'com.sk89q.lib:jlibnoise:1.0.0' compile 'com.googlecode.json-simple:json-simple:1.1.1' + compile 'org.slf4j:slf4j-api:1.7.26' //compile 'net.sf.trove4j:trove4j:3.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java index a8f49678b..df3b0806b 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -20,6 +20,8 @@ package com.sk89q.minecraft.util.commands; import com.sk89q.util.StringUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -30,8 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Manager for handling commands. This allows you to easily process commands, @@ -63,7 +63,7 @@ import java.util.logging.Logger; public abstract class CommandsManager { protected static final Logger logger = - Logger.getLogger(CommandsManager.class.getCanonicalName()); + LoggerFactory.getLogger(CommandsManager.class); /** * Mapping of commands (including aliases) with a description. Root @@ -142,7 +142,7 @@ public abstract class CommandsManager { return registerMethods(cls, parent, obj); } } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { - logger.log(Level.SEVERE, "Failed to register commands", e); + logger.error("Failed to register commands", e); } return null; } @@ -523,7 +523,7 @@ public abstract class CommandsManager { try { method.invoke(instance, methodArgs); } catch (IllegalArgumentException | IllegalAccessException e) { - logger.log(Level.SEVERE, "Failed to execute command", e); + logger.error("Failed to execute command", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java index eb6097512..652c69a5d 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java @@ -19,14 +19,15 @@ package com.sk89q.minecraft.util.commands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; -import java.util.logging.Logger; public class SimpleInjector implements Injector { - private static final Logger log = Logger.getLogger(SimpleInjector.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(SimpleInjector.class); private Object[] args; private Class[] argClasses; @@ -45,7 +46,7 @@ public class SimpleInjector implements Injector { ctr.setAccessible(true); return ctr.newInstance(args); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { - log.log(Level.SEVERE, "Error initializing commands class " + clazz, e); + log.error("Error initializing commands class " + clazz, e); return null; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 966479e98..39c72c93f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -19,12 +19,6 @@ package com.sk89q.worldedit; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.regions.Regions.asFlatRegion; -import static com.sk89q.worldedit.regions.Regions.maximumBlockY; -import static com.sk89q.worldedit.regions.Regions.minimumBlockY; - import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.event.extent.EditSessionEvent; @@ -117,7 +111,10 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -126,10 +123,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.regions.Regions.asFlatRegion; +import static com.sk89q.worldedit.regions.Regions.maximumBlockY; +import static com.sk89q.worldedit.regions.Regions.minimumBlockY; /** * An {@link Extent} that handles history, {@link BlockBag}s, change limits, @@ -142,7 +141,7 @@ import javax.annotation.Nullable; @SuppressWarnings({"FieldCanBeLocal"}) public class EditSession implements Extent, AutoCloseable { - private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(EditSession.class); /** * Used by {@link EditSession#setBlock(BlockVector3, BlockStateHolder, Stage)} to @@ -1958,7 +1957,7 @@ public class EditSession implements Extent, AutoCloseable { timedOut[0] = timedOut[0] + 1; return null; } catch (Exception e) { - log.log(Level.WARNING, "Failed to create shape", e); + log.warn("Failed to create shape", e); return null; } } @@ -2322,7 +2321,7 @@ public class EditSession implements Extent, AutoCloseable { timedOut[0] = timedOut[0] + 1; return null; } catch (Exception e) { - log.log(Level.WARNING, "Failed to create shape", e); + log.warn("Failed to create shape", e); return null; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 1d0968aa6..cadeec817 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.jchronic.Chronic; import com.sk89q.jchronic.Options; import com.sk89q.jchronic.utils.Span; @@ -53,6 +51,7 @@ import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.snapshot.Snapshot; +import javax.annotation.Nullable; import java.util.Calendar; import java.util.HashMap; import java.util.LinkedList; @@ -60,7 +59,7 @@ import java.util.Map; import java.util.TimeZone; import java.util.concurrent.atomic.AtomicBoolean; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; /** * Stores session information. @@ -798,7 +797,7 @@ public class LocalSession { try { setCUIVersion(Integer.parseInt(split[1])); } catch (NumberFormatException e) { - WorldEdit.logger.warning("Error while reading CUI init message: " + e.getMessage()); + WorldEdit.logger.warn("Error while reading CUI init message: " + e.getMessage()); this.failedCuiAttempts ++; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java index 5793a4f04..9832d084d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/TracedEditSession.java @@ -24,8 +24,6 @@ import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.World; -import java.util.logging.Level; - public class TracedEditSession extends EditSession { TracedEditSession(EventBus eventBus, World world, int maxBlocks, BlockBag blockBag, EditSessionEvent event) { @@ -39,9 +37,9 @@ public class TracedEditSession extends EditSession { super.finalize(); if (commitRequired()) { - WorldEdit.logger.warning("####### LEFTOVER BUFFER BLOCKS DETECTED #######"); - WorldEdit.logger.warning("This means that some code did not flush their EditSession."); - WorldEdit.logger.log(Level.WARNING, "Here is a stacktrace from the creation of this EditSession:", stacktrace); + WorldEdit.logger.warn("####### LEFTOVER BUFFER BLOCKS DETECTED #######"); + WorldEdit.logger.warn("This means that some code did not flush their EditSession."); + WorldEdit.logger.warn("Here is a stacktrace from the creation of this EditSession:", stacktrace); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 8dbd65389..1869c834a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -19,9 +19,6 @@ package com.sk89q.worldedit; -import static com.sk89q.worldedit.event.platform.Interaction.HIT; -import static com.sk89q.worldedit.event.platform.Interaction.OPEN; - import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.sk89q.worldedit.blocks.BaseItem; @@ -53,7 +50,6 @@ import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.InvalidFilenameException; -import com.sk89q.worldedit.util.logging.WorldEditPrefixHandler; import com.sk89q.worldedit.util.task.SimpleSupervisor; import com.sk89q.worldedit.util.task.Supervisor; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -61,7 +57,11 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BundledBlockData; import com.sk89q.worldedit.world.registry.BundledItemData; import com.sk89q.worldedit.world.registry.LegacyMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; +import javax.script.ScriptException; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; @@ -74,11 +74,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; -import javax.script.ScriptException; +import static com.sk89q.worldedit.event.platform.Interaction.HIT; +import static com.sk89q.worldedit.event.platform.Interaction.OPEN; /** * The entry point and container for a working implementation of WorldEdit. @@ -95,7 +93,7 @@ import javax.script.ScriptException; */ public final class WorldEdit { - public static final Logger logger = Logger.getLogger(WorldEdit.class.getCanonicalName()); + public static final Logger logger = LoggerFactory.getLogger(WorldEdit.class); private static final WorldEdit instance = new WorldEdit(); private static String version; @@ -112,7 +110,6 @@ public final class WorldEdit { private final PatternFactory patternFactory = new PatternFactory(this); static { - WorldEditPrefixHandler.register("com.sk89q.worldedit"); getVersion(); } @@ -655,13 +652,13 @@ public final class WorldEdit { } catch (ScriptException e) { player.printError("Failed to execute:"); player.printRaw(e.getMessage()); - logger.log(Level.WARNING, "Failed to execute script", e); + logger.warn("Failed to execute script", e); } catch (NumberFormatException | WorldEditException e) { throw e; } catch (Throwable e) { player.printError("Failed to execute (see console):"); player.printRaw(e.getClass().getCanonicalName()); - logger.log(Level.WARNING, "Failed to execute script", e); + logger.warn("Failed to execute script", e); } finally { for (EditSession editSession : scriptContext.getEditSessions()) { editSession.flushSession(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index cd7da8081..b75c4bdc1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.command; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.Multimap; import com.google.common.io.Files; import com.sk89q.minecraft.util.commands.Command; @@ -48,6 +46,8 @@ import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -58,10 +58,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Commands that work with schematic files. */ @@ -71,7 +71,7 @@ public class SchematicCommands { * 9 schematics per page fits in the MC chat window. */ private static final int SCHEMATICS_PER_PAGE = 9; - private static final Logger log = Logger.getLogger(SchematicCommands.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(SchematicCommands.class); private final WorldEdit worldEdit; /** @@ -123,7 +123,7 @@ public class SchematicCommands { player.print(filename + " loaded. Paste it with //paste"); } catch (IOException e) { player.printError("Schematic could not read or it does not exist: " + e.getMessage()); - log.log(Level.WARNING, "Failed to load a saved clipboard", e); + log.warn("Failed to load a saved clipboard", e); } } @@ -179,7 +179,7 @@ public class SchematicCommands { player.print(filename + " saved."); } catch (IOException e) { player.printError("Schematic could not written: " + e.getMessage()); - log.log(Level.WARNING, "Failed to write a saved clipboard", e); + log.warn("Failed to write a saved clipboard", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java index 4cd0e0079..7c01fc305 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java @@ -40,14 +40,12 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.List; -import java.util.logging.Logger; /** * Snapshot commands. */ public class SnapshotCommands { - private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); private final WorldEdit we; @@ -93,10 +91,10 @@ public class SnapshotCommands { File dir = config.snapshotRepo.getDirectory(); try { - logger.info("WorldEdit found no snapshots: looked in: " + WorldEdit.logger.info("WorldEdit found no snapshots: looked in: " + dir.getCanonicalPath()); } catch (IOException e) { - logger.info("WorldEdit found no snapshots: looked in " + WorldEdit.logger.info("WorldEdit found no snapshots: looked in " + "(NON-RESOLVABLE PATH - does it exist?): " + dir.getPath()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java index fcd5445a6..51c5695e5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.command; -import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; - import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; @@ -41,12 +39,11 @@ import com.sk89q.worldedit.world.storage.MissingWorldException; import java.io.File; import java.io.IOException; -import java.util.logging.Logger; + +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; public class SnapshotUtilCommands { - private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - private final WorldEdit we; public SnapshotUtilCommands(WorldEdit we) { @@ -97,10 +94,10 @@ public class SnapshotUtilCommands { File dir = config.snapshotRepo.getDirectory(); try { - logger.info("WorldEdit found no snapshots: looked in: " + WorldEdit.logger.info("WorldEdit found no snapshots: looked in: " + dir.getCanonicalPath()); } catch (IOException e) { - logger.info("WorldEdit found no snapshots: looked in " + WorldEdit.logger.info("WorldEdit found no snapshots: looked in " + "(NON-RESOLVABLE PATH - does it exist?): " + dir.getPath()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 297ccf318..01e8862e0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -19,9 +19,6 @@ package com.sk89q.worldedit.extension.platform; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt; - import com.google.common.base.Joiner; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; @@ -79,14 +76,18 @@ import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt; + /** * Handles the registration and invocation of commands. * @@ -95,8 +96,9 @@ import java.util.regex.Pattern; public final class CommandManager { public static final Pattern COMMAND_CLEAN_PATTERN = Pattern.compile("^[/]+"); - private static final Logger log = Logger.getLogger(CommandManager.class.getCanonicalName()); - private static final Logger commandLog = Logger.getLogger(CommandManager.class.getCanonicalName() + ".CommandLog"); + private static final Logger log = LoggerFactory.getLogger(CommandManager.class); + private static final java.util.logging.Logger commandLog = + java.util.logging.Logger.getLogger(CommandManager.class.getCanonicalName() + ".CommandLog"); private static final Pattern numberFormatExceptionPattern = Pattern.compile("^For input string: \"(.*)\"$"); private final WorldEdit worldEdit; @@ -189,7 +191,7 @@ public final class CommandManager { } void register(Platform platform) { - log.log(Level.FINE, "Registering commands with " + platform.getClass().getCanonicalName()); + log.info("Registering commands with " + platform.getClass().getCanonicalName()); LocalConfiguration config = platform.getConfiguration(); boolean logging = config.logCommands; @@ -203,12 +205,12 @@ public final class CommandManager { File file = new File(config.getWorkingDirectory(), path); commandLog.setLevel(Level.ALL); - log.log(Level.INFO, "Logging WorldEdit commands to " + file.getAbsolutePath()); + log.info("Logging WorldEdit commands to " + file.getAbsolutePath()); try { dynamicHandler.setHandler(new FileHandler(file.getAbsolutePath(), true)); } catch (IOException e) { - log.log(Level.WARNING, "Could not use command log file " + path + ": " + e.getMessage()); + log.warn("Could not use command log file " + path + ": " + e.getMessage()); } dynamicHandler.setFormatter(new LogFormat(config.logFormat)); @@ -302,14 +304,14 @@ public final class CommandManager { Throwable t = e.getCause(); actor.printError("Please report this error: [See console]"); actor.printRaw(t.getClass().getName() + ": " + t.getMessage()); - log.log(Level.SEVERE, "An unexpected error while handling a WorldEdit command", t); + log.error("An unexpected error while handling a WorldEdit command", t); } catch (CommandException e) { String message = e.getMessage(); if (message != null) { actor.printError(e.getMessage()); } else { actor.printError("An unknown error has occurred! Please see console."); - log.log(Level.SEVERE, "An unknown error occurred", e); + log.error("An unknown error occurred", e); } } finally { EditSession editSession = locals.get(EditSession.class); @@ -359,7 +361,7 @@ public final class CommandManager { return dispatcher; } - public static Logger getLogger() { + public static java.util.logging.Logger getLogger() { return commandLog; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index af45b642f..dd6c16ab1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.extension.platform; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -44,7 +42,10 @@ import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.World; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.EnumMap; import java.util.Iterator; @@ -52,10 +53,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; /** * Manages registered {@link Platform}s for WorldEdit. Platforms are @@ -65,7 +64,7 @@ import javax.annotation.Nullable; */ public class PlatformManager { - private static final Logger logger = Logger.getLogger(PlatformManager.class.getCanonicalName()); + private static final Logger logger = LoggerFactory.getLogger(PlatformManager.class); private final WorldEdit worldEdit; private final CommandManager commandManager; @@ -97,7 +96,7 @@ public class PlatformManager { public synchronized void register(Platform platform) { checkNotNull(platform); - logger.log(Level.FINE, "Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]"); + logger.info("Got request to register " + platform.getClass() + " with WorldEdit [" + super.toString() + "]"); // Just add the platform to the list of platforms: we'll pick favorites // once all the platforms have been loaded @@ -106,7 +105,7 @@ public class PlatformManager { // Make sure that versions are in sync if (firstSeenVersion != null) { if (!firstSeenVersion.equals(platform.getVersion())) { - logger.log(Level.WARNING, "Multiple ports of WorldEdit are installed but they report different versions ({0} and {1}). " + + logger.warn("Multiple ports of WorldEdit are installed but they report different versions ({0} and {1}). " + "If these two versions are truly different, then you may run into unexpected crashes and errors.", new Object[]{ firstSeenVersion, platform.getVersion() }); } @@ -129,7 +128,7 @@ public class PlatformManager { boolean removed = platforms.remove(platform); if (removed) { - logger.log(Level.FINE, "Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit"); + logger.info("Unregistering " + platform.getClass().getCanonicalName() + " from WorldEdit"); boolean choosePreferred = false; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java index 9663a9b1f..584b39f0c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/ClipboardFormats.java @@ -19,13 +19,12 @@ package com.sk89q.worldedit.extent.clipboard.io; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.sk89q.worldedit.WorldEdit; +import javax.annotation.Nullable; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -35,7 +34,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; public class ClipboardFormats { @@ -51,7 +50,7 @@ public class ClipboardFormats { ClipboardFormat old = aliasMap.put(lowKey, format); if (old != null) { aliasMap.put(lowKey, old); - WorldEdit.logger.warning(format.getClass().getName() + " cannot override existing alias '" + lowKey + "' used by " + old.getClass().getName()); + WorldEdit.logger.warn(format.getClass().getName() + " cannot override existing alias '" + lowKey + "' used by " + old.getClass().getName()); } } for (String ext : format.getFileExtensions()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java index 27e9a1d2c..c20c72df8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.extent.clipboard.io; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; @@ -45,14 +43,16 @@ import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.storage.NBTConversions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Reads schematic files that are compatible with MCEdit and other editors. @@ -66,7 +66,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { // TODO Add a handler for skulls, flower pots, note blocks, etc. } - private static final Logger log = Logger.getLogger(MCEditSchematicReader.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(MCEditSchematicReader.class); private final NBTInputStream inputStream; /** @@ -230,15 +230,15 @@ public class MCEditSchematicReader extends NBTSchematicReader { clipboard.setBlock(region.getMinimumPoint().add(pt), state); } } else { - log.warning("Unknown block when pasting schematic: " + blocks[index] + ":" + blockData[index] + ". Please report this issue."); + log.warn("Unknown block when pasting schematic: " + blocks[index] + ":" + blockData[index] + ". Please report this issue."); } } catch (WorldEditException e) { switch (failedBlockSets) { case 0: - log.log(Level.WARNING, "Failed to set block on a Clipboard", e); + log.warn("Failed to set block on a Clipboard", e); break; case 1: - log.log(Level.WARNING, "Failed to set block on a Clipboard (again) -- no more messages will be logged", e); + log.warn("Failed to set block on a Clipboard (again) -- no more messages will be logged", e); break; default: } @@ -268,7 +268,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { BaseEntity state = new BaseEntity(entityType, compound); clipboard.createEntity(location, state); } else { - log.warning("Unknown entity when pasting schematic: " + id.toLowerCase()); + log.warn("Unknown entity when pasting schematic: " + id.toLowerCase()); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index 9714fc0de..3b944018e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.extent.clipboard.io; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.Maps; import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.CompoundTag; @@ -42,15 +40,18 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Logger; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Reads schematic files using the Sponge Schematic Specification. */ @@ -62,7 +63,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { // If NBT Compat handlers are needed - add them here. } - private static final Logger log = Logger.getLogger(SpongeSchematicReader.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(SpongeSchematicReader.class); private final NBTInputStream inputStream; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index 262bdd0af..10ba092a3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.internal.command; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.Logging; @@ -40,6 +38,8 @@ import java.lang.reflect.Method; import java.util.logging.Handler; import java.util.logging.Logger; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Logs called commands to a logger. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java index 29a3ee5ee..23680f2bc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java @@ -21,14 +21,15 @@ package com.sk89q.worldedit.math.interpolation; -import static com.google.common.base.Preconditions.checkNotNull; - import com.sk89q.worldedit.math.Vector3; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map.Entry; import java.util.TreeMap; -import java.util.logging.Logger; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Reparametrises another interpolation function by arc length. @@ -38,7 +39,7 @@ import java.util.logging.Logger; */ public class ReparametrisingInterpolation implements Interpolation { - private static final Logger log = Logger.getLogger(ReparametrisingInterpolation.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(ReparametrisingInterpolation.class); private final Interpolation baseInterpolation; private double totalArcLength; @@ -102,7 +103,7 @@ public class ReparametrisingInterpolation implements Interpolation { Entry ceilingEntry = cache.ceilingEntry(arc); if (ceilingEntry == null) { - log.warning("Error in arcToParameter: no ceiling entry for " + arc + " found!"); + log.warn("Error in arcToParameter: no ceiling entry for " + arc + " found!"); return 0; } final double rightArc = ceilingEntry.getKey(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java index a1dd4d60a..1260fc327 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/SessionManager.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.session; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; @@ -36,7 +34,10 @@ import com.sk89q.worldedit.session.storage.VoidStore; import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors; import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.world.gamemode.GameModes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -46,10 +47,8 @@ import java.util.Timer; import java.util.TimerTask; import java.util.UUID; import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; /** * Session manager for WorldEdit. @@ -63,7 +62,7 @@ public class SessionManager { public static int EXPIRATION_GRACE = 600000; private static final int FLUSH_PERIOD = 1000 * 30; private static final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 5)); - private static final Logger log = Logger.getLogger(SessionManager.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(SessionManager.class); private final Timer timer = new Timer(); private final WorldEdit worldEdit; private final Map sessions = new HashMap<>(); @@ -149,7 +148,7 @@ public class SessionManager { session = store.load(getKey(sessionKey)); session.postLoad(); } catch (IOException e) { - log.log(Level.WARNING, "Failed to load saved session", e); + log.warn("Failed to load saved session", e); session = new LocalSession(); } @@ -210,7 +209,7 @@ public class SessionManager { try { store.save(getKey(key), entry.getValue()); } catch (IOException e) { - log.log(Level.WARNING, "Failed to write session for UUID " + getKey(key), e); + log.warn("Failed to write session for UUID " + getKey(key), e); exception = e; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java index d7b2a9893..ad8e422bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/storage/JsonFileSessionStore.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.session.storage; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonIOException; @@ -28,6 +26,8 @@ import com.google.gson.JsonParseException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.util.gson.GsonUtil; import com.sk89q.worldedit.util.io.Closer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -37,8 +37,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Stores sessions as JSON files in a directory. @@ -47,7 +47,7 @@ import java.util.logging.Logger; */ public class JsonFileSessionStore implements SessionStore { - private static final Logger log = Logger.getLogger(JsonFileSessionStore.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(JsonFileSessionStore.class); private final Gson gson; private final File dir; @@ -61,7 +61,7 @@ public class JsonFileSessionStore implements SessionStore { if (!dir.isDirectory()) { if (!dir.mkdirs()) { - log.log(Level.WARNING, "Failed to create directory '" + dir.getPath() + "' for sessions"); + log.warn("Failed to create directory '" + dir.getPath() + "' for sessions"); } } @@ -111,12 +111,12 @@ public class JsonFileSessionStore implements SessionStore { if (finalFile.exists()) { if (!finalFile.delete()) { - log.log(Level.WARNING, "Failed to delete " + finalFile.getPath() + " so the .tmp file can replace it"); + log.warn("Failed to delete " + finalFile.getPath() + " so the .tmp file can replace it"); } } if (!tempFile.renameTo(finalFile)) { - log.log(Level.WARNING, "Failed to rename temporary session file to " + finalFile.getPath()); + log.warn("Failed to rename temporary session file to " + finalFile.getPath()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index acc845914..12513b97d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -27,6 +27,8 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.util.report.Unreported; import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.snapshot.SnapshotRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; @@ -39,8 +41,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Properties; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Simple LocalConfiguration that loads settings using @@ -48,7 +48,7 @@ import java.util.logging.Logger; */ public class PropertiesConfiguration extends LocalConfiguration { - @Unreported private static final Logger log = Logger.getLogger(PropertiesConfiguration.class.getCanonicalName()); + @Unreported private static final Logger log = LoggerFactory.getLogger(PropertiesConfiguration.class); @Unreported protected Properties properties; @Unreported protected File path; @@ -70,7 +70,7 @@ public class PropertiesConfiguration extends LocalConfiguration { properties.load(stream); } catch (FileNotFoundException ignored) { } catch (IOException e) { - log.log(Level.WARNING, "Failed to read configuration", e); + log.warn("Failed to read configuration", e); } loadExtra(); @@ -131,7 +131,7 @@ public class PropertiesConfiguration extends LocalConfiguration { try (OutputStream output = new FileOutputStream(path)) { properties.store(output, "Don't put comments; they get removed"); } catch (IOException e) { - log.log(Level.WARNING, "Failed to write configuration", e); + log.warn("Failed to write configuration", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 10940bbd9..5a657584d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -26,11 +26,10 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.session.SessionManager; import com.sk89q.worldedit.util.report.Unreported; import com.sk89q.worldedit.world.snapshot.SnapshotRepository; +import org.slf4j.Logger; import java.io.IOException; import java.util.HashSet; -import java.util.logging.Level; -import java.util.logging.Logger; /** * A less simple implementation of {@link LocalConfiguration} @@ -51,7 +50,7 @@ public class YAMLConfiguration extends LocalConfiguration { try { config.load(); } catch (IOException e) { - logger.log(Level.WARNING, "Error loading WorldEdit configuration", e); + logger.warn("Error loading WorldEdit configuration", e); } profile = config.getBoolean("debug", profile); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java index d8cbe8b20..d97c090ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/eventbus/EventBus.java @@ -19,13 +19,13 @@ package com.sk89q.worldedit.util.eventbus; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; import com.google.common.eventbus.DeadEvent; import com.sk89q.worldedit.internal.annotation.RequiresNewerGuava; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -36,8 +36,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; + +import static com.google.common.base.Preconditions.checkNotNull; /** * Dispatches events to listeners, and provides ways for listeners to register @@ -53,7 +53,7 @@ import java.util.logging.Logger; */ public class EventBus { - private final Logger logger = Logger.getLogger(EventBus.class.getCanonicalName()); + private final Logger logger = LoggerFactory.getLogger(EventBus.class); private final SetMultimap, EventHandler> handlersByType = Multimaps.newSetMultimap(new HashMap<>(), this::newHandlerSet); @@ -186,8 +186,7 @@ public class EventBus { try { handler.handleEvent(event); } catch (InvocationTargetException e) { - logger.log(Level.SEVERE, - "Could not dispatch event: " + event + " to handler " + handler, e); + logger.error("Could not dispatch event: " + event + " to handler " + handler, e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java index 26ef6a0f9..1b7aceda3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/Closer.java @@ -19,23 +19,23 @@ package com.sk89q.worldedit.util.io; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Throwables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.Closeable; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayDeque; import java.util.Deque; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.ZipFile; +import static com.google.common.base.Preconditions.checkNotNull; + public final class Closer implements Closeable { - private static final Logger logger = Logger.getLogger(Closer.class.getCanonicalName()); + private static final Logger logger = LoggerFactory.getLogger(Closer.class); /** * The suppressor implementation to use for the current Java version. @@ -218,7 +218,7 @@ public final class Closer implements Closeable { @Override public void suppress(Object closeable, Throwable thrown, Throwable suppressed) { // log to the same place as Closeables - logger.log(Level.WARNING, "Suppressing exception thrown when closing " + closeable, suppressed); + logger.warn("Suppressing exception thrown when closing " + closeable, suppressed); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/WorldEditPrefixHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/WorldEditPrefixHandler.java deleted file mode 100644 index f2c8a0754..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/logging/WorldEditPrefixHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.logging; - -import java.util.logging.Handler; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -/** - * Adds a WorldEdit prefix to WorldEdit's logger messages using a handler. - */ -public final class WorldEditPrefixHandler extends Handler { - - private WorldEditPrefixHandler() { - } - - @Override - public void publish(LogRecord record) { - String message = record.getMessage(); - if (!message.startsWith("WorldEdit: ") && !message.startsWith("[WorldEdit] ")) { - record.setMessage("[WorldEdit] " + message); - } - } - - @Override - public void flush() { - } - - @Override - public void close() throws SecurityException { - } - - /** - * Add the handler to the following logger name. - * - * @param name the logger name - */ - public static void register(String name) { - Logger.getLogger(name).addHandler(new WorldEditPrefixHandler()); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java index a643146c7..bcacbfd8f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java @@ -26,14 +26,14 @@ import com.sk89q.worldedit.command.util.AsyncCommandHelper; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.task.Supervisor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; public class ActorCallbackPaste { - private static final Logger LOGGER = Logger.getLogger(ActorCallbackPaste.class.getSimpleName()); + private static final Logger LOGGER = LoggerFactory.getLogger(ActorCallbackPaste.class); private ActorCallbackPaste() { } @@ -62,7 +62,7 @@ public class ActorCallbackPaste { @Override public void onFailure(Throwable throwable) { - LOGGER.log(Level.WARNING, "Failed to submit pastebin", throwable); + LOGGER.warn("Failed to submit pastebin", throwable); sender.printError("Failed to submit to a pastebin. Please see console for the error."); } }); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/ShallowObjectReport.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/ShallowObjectReport.java index bb4abb1f3..18085bc0b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/ShallowObjectReport.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/ShallowObjectReport.java @@ -19,16 +19,17 @@ package com.sk89q.worldedit.util.report; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.logging.Level; -import java.util.logging.Logger; import static com.google.common.base.Preconditions.checkNotNull; public class ShallowObjectReport extends DataReport { - private static final Logger log = Logger.getLogger(ShallowObjectReport.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(ShallowObjectReport.class); public ShallowObjectReport(String title, Object object) { super(title); @@ -52,7 +53,7 @@ public class ShallowObjectReport extends DataReport { Object value = field.get(object); append(field.getName(), String.valueOf(value)); } catch (IllegalAccessException e) { - log.log(Level.WARNING, "Failed to get value of '" + field.getName() + "' on " + type); + log.warn("Failed to get value of '" + field.getName() + "' on " + type); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 6e4c5e721..d71430c52 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -107,7 +107,7 @@ public class BlockState implements BlockStateHolder { states.put(property, value, modifiedState); } else { System.out.println(stateMap); - WorldEdit.logger.warning("Found a null state at " + this.withValue(property, value)); + WorldEdit.logger.warn("Found a null state at " + this.withValue(property, value)); } } }); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java index 1d4b92c90..5eacec086 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java @@ -36,12 +36,11 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.storage.InvalidFormatException; +import javax.annotation.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; - public class AnvilChunk implements Chunk { private CompoundTag rootTag; @@ -259,7 +258,7 @@ public class AnvilChunk implements Chunk { BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, data); if (state == null) { - WorldEdit.logger.warning("Unknown legacy block " + id + ":" + data + " found when loading legacy anvil chunk."); + WorldEdit.logger.warn("Unknown legacy block " + id + ":" + data + " found when loading legacy anvil chunk."); return BlockTypes.AIR.getDefaultState().toBaseBlock(); } CompoundTag tileEntity = getBlockTileEntity(position); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java index 89bad5678..9f8bda52d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java @@ -182,7 +182,7 @@ public class OldChunk implements Chunk { BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, dataVal); if (state == null) { - WorldEdit.logger.warning("Unknown legacy block " + id + ":" + dataVal + " found when loading legacy anvil chunk."); + WorldEdit.logger.warn("Unknown legacy block " + id + ":" + dataVal + " found when loading legacy anvil chunk."); return BlockTypes.AIR.getDefaultState().toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index b98238dc0..4dffdb38f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -25,17 +25,16 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.IOException; import java.net.URL; import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.annotation.Nullable; /** * Provides block data based on the built-in block database that is bundled @@ -50,7 +49,7 @@ import javax.annotation.Nullable; */ public class BundledBlockData { - private static final Logger log = Logger.getLogger(BundledBlockData.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(BundledBlockData.class); private static BundledBlockData INSTANCE; private final Map idMap = new HashMap<>(); @@ -62,7 +61,7 @@ public class BundledBlockData { try { loadFromResource(); } catch (Throwable e) { - log.log(Level.WARNING, "Failed to load the built-in block registry", e); + log.warn("Failed to load the built-in block registry", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java index 2867b2e56..4bdac0c8a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java @@ -25,17 +25,16 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.IOException; import java.net.URL; import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.annotation.Nullable; /** * Provides item data based on the built-in item database that is bundled @@ -50,7 +49,7 @@ import javax.annotation.Nullable; */ public class BundledItemData { - private static final Logger log = Logger.getLogger(BundledItemData.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(BundledItemData.class); private static BundledItemData INSTANCE; private final Map idMap = new HashMap<>(); @@ -62,7 +61,7 @@ public class BundledItemData { try { loadFromResource(); } catch (Throwable e) { - log.log(Level.WARNING, "Failed to load the built-in item registry", e); + log.warn("Failed to load the built-in item registry", e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index ad2eac4c0..a41814abc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -32,22 +32,21 @@ import com.sk89q.worldedit.util.gson.VectorAdapter; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.io.IOException; import java.net.URL; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkNotNull; public class LegacyMapper { - private static final Logger log = Logger.getLogger(LegacyMapper.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(LegacyMapper.class); private static LegacyMapper INSTANCE; private Multimap stringToBlockMap = HashMultimap.create(); @@ -62,7 +61,7 @@ public class LegacyMapper { try { loadFromResource(); } catch (Throwable e) { - log.log(Level.WARNING, "Failed to load the built-in legacy id registry", e); + log.warn("Failed to load the built-in legacy id registry", e); } } @@ -94,7 +93,7 @@ public class LegacyMapper { blockToStringMap.put(state, id); stringToBlockMap.put(id, state); } catch (Exception e) { - log.warning("Unknown block: " + blockEntry.getValue()); + log.warn("Unknown block: " + blockEntry.getValue()); } } @@ -106,7 +105,7 @@ public class LegacyMapper { itemToStringMap.put(type, id); stringToItemMap.put(id, type); } catch (Exception e) { - log.warning("Unknown item: " + itemEntry.getValue()); + log.warn("Unknown item: " + itemEntry.getValue()); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java index 58525a7d2..0af2b6e18 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/Snapshot.java @@ -29,11 +29,12 @@ import com.sk89q.worldedit.world.storage.TrueZipLegacyChunkStore; import com.sk89q.worldedit.world.storage.TrueZipMcRegionChunkStore; import com.sk89q.worldedit.world.storage.ZippedLegacyChunkStore; import com.sk89q.worldedit.world.storage.ZippedMcRegionChunkStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.util.Calendar; -import java.util.logging.Logger; import java.util.zip.ZipFile; /** @@ -41,7 +42,7 @@ import java.util.zip.ZipFile; */ public class Snapshot implements Comparable { - protected static Logger logger = Logger.getLogger(Snapshot.class.getCanonicalName()); + protected static Logger logger = LoggerFactory.getLogger(Snapshot.class); protected File file; protected String name; diff --git a/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java b/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java index 5cc3c1086..555c83889 100644 --- a/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java +++ b/worldedit-core/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java @@ -19,23 +19,23 @@ package com.sk89q.minecraft.util.commands; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.HashSet; + import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.junit.Before; -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.logging.Level; -import java.util.logging.Logger; - public class CommandContextTest { - private static final Logger log = Logger.getLogger(CommandContextTest.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(CommandContextTest.class); private static final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something"; CommandContext firstCommand; @@ -44,7 +44,7 @@ public class CommandContextTest { try { firstCommand = new CommandContext(firstCmdString, new HashSet<>(Arrays.asList('o', 'w'))); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Unexpected exception when creating CommandContext"); } } @@ -83,7 +83,7 @@ public class CommandContextTest { new CommandContext(cmd); new CommandContext(cmd2); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -94,7 +94,7 @@ public class CommandContextTest { try { new CommandContext(cmd); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -105,7 +105,7 @@ public class CommandContextTest { try { new CommandContext(cmd); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -119,7 +119,7 @@ public class CommandContextTest { CommandContext context2 = new CommandContext("r hello -f world"); assertTrue(context2.hasFlag('f')); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -135,7 +135,7 @@ public class CommandContextTest { CommandContext context2 = new CommandContext("pm name \"hello world\" foo bar"); assertEquals("\"hello world\" foo bar", context2.getJoinedStrings(1)); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -147,7 +147,7 @@ public class CommandContextTest { assertArrayEquals(new String[] { "foo", "bar", "baz" }, context.getSlice(0)); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } @@ -158,7 +158,7 @@ public class CommandContextTest { CommandContext context = new CommandContext("region flag xmas blocked-cmds \"\""); assertEquals(context.argsLength(), 3); } catch (CommandException e) { - log.log(Level.WARNING, "Error", e); + log.warn("Error", e); fail("Error creating CommandContext"); } } diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 6666d74c4..7e46e4d05 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -18,6 +18,7 @@ def forgeVersion = "25.0.76" dependencies { compile project(':worldedit-core') + compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.2' minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplLoader.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplLoader.java index dac72425e..7f5bb0f84 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplLoader.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplLoader.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.sponge.adapter; import com.google.common.collect.Lists; import com.sk89q.worldedit.util.io.Closer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -30,15 +32,13 @@ import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Loads Sponge implementation adapters. */ public class SpongeImplLoader { - private static final Logger log = Logger.getLogger(SpongeImplLoader.class.getCanonicalName()); + private static final Logger log = LoggerFactory.getLogger(SpongeImplLoader.class); private final List adapterCandidates = new ArrayList<>(); private String customCandidate; @@ -71,7 +71,7 @@ public class SpongeImplLoader { if (className != null) { customCandidate = className; adapterCandidates.add(className); - log.log(Level.INFO, "-Dworldedit.sponge.adapter used to add " + className + " to the list of available Sponge adapters"); + log.info("-Dworldedit.sponge.adapter used to add " + className + " to the list of available Sponge adapters"); } } @@ -157,18 +157,18 @@ public class SpongeImplLoader { if (SpongeImplAdapter.class.isAssignableFrom(cls)) { suitableAdapters.add((SpongeImplAdapter) cls.newInstance()); } else { - log.log(Level.WARNING, "Failed to load the Sponge adapter class '" + className + + log.warn("Failed to load the Sponge adapter class '" + className + "' because it does not implement " + SpongeImplAdapter.class.getCanonicalName()); } } catch (ClassNotFoundException e) { - log.log(Level.WARNING, "Failed to load the Sponge adapter class '" + className + + log.warn("Failed to load the Sponge adapter class '" + className + "' that is not supposed to be missing", e); } catch (IllegalAccessException e) { - log.log(Level.WARNING, "Failed to load the Sponge adapter class '" + className + + log.warn("Failed to load the Sponge adapter class '" + className + "' that is not supposed to be raising this error", e); } catch (Throwable e) { if (className.equals(customCandidate)) { - log.log(Level.WARNING, "Failed to load the Sponge adapter class '" + className + "'", e); + log.warn("Failed to load the Sponge adapter class '" + className + "'", e); } } } From 4be72fb9836525e47c2dfad077b38dff777db6f0 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Wed, 13 Mar 2019 19:56:58 -0700 Subject: [PATCH 2/3] Shade logger bridges as well --- worldedit-bukkit/build.gradle | 2 ++ worldedit-forge/build.gradle | 1 + 2 files changed, 3 insertions(+) diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 944956fa8..ecff0db24 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -39,6 +39,8 @@ jar { shadowJar { dependencies { include(dependency(':worldedit-core')) + // Must not be relocated, for StaticLoggerBinder to work: + include(dependency("org.slf4j:slf4j-jdk14:1.7.26")) relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") { include(dependency("org.bstats:bstats-bukkit:1.4")) } diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 7e46e4d05..84dba2768 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -85,6 +85,7 @@ jar { shadowJar { dependencies { include(dependency(':worldedit-core')) + include(dependency("org.apache.logging.log4j:log4j-slf4j-impl:2.11.2")) } } From fba12b1282b54383dcfca7a5ac5163c45326e0f3 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Wed, 13 Mar 2019 20:15:01 -0700 Subject: [PATCH 3/3] More shading fixes --- worldedit-bukkit/build.gradle | 5 +++-- worldedit-forge/build.gradle | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index ecff0db24..335b96c0a 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -38,9 +38,10 @@ jar { shadowJar { dependencies { + relocate "org.slf4j", "com.sk89q.worldedit.slf4j" include(dependency(':worldedit-core')) - // Must not be relocated, for StaticLoggerBinder to work: - include(dependency("org.slf4j:slf4j-jdk14:1.7.26")) + include(dependency('org.slf4j:slf4j-api')) + include(dependency("org.slf4j:slf4j-jdk14")) relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") { include(dependency("org.bstats:bstats-bukkit:1.4")) } diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 84dba2768..8fe3fb9af 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -84,8 +84,12 @@ jar { shadowJar { dependencies { + relocate "org.slf4j", "com.sk89q.worldedit.slf4j" + relocate "org.apache.logging.slf4j", "com.sk89q.worldedit.log4jbridge" + include(dependency(':worldedit-core')) - include(dependency("org.apache.logging.log4j:log4j-slf4j-impl:2.11.2")) + include(dependency('org.slf4j:slf4j-api')) + include(dependency("org.apache.logging.log4j:log4j-slf4j-impl")) } }