Skip to content

Always log debug messages #6154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
exclude group: "org.bukkit", module: "bukkit"
}
compileOnly 'net.luckperms:api:5.3'
compileOnly 'org.apache.logging.log4j:log4j-core:2.17.1'

api 'io.papermc:paperlib:1.0.6'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.earth2me.essentials;

import java.util.stream.Collectors;
import com.earth2me.essentials.utils.DebugLogUtil;
import net.ess3.provider.KnownCommandsProvider;
import org.bukkit.command.Command;
import org.bukkit.command.PluginIdentifiableCommand;
Expand All @@ -13,7 +13,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.stream.Collectors;

public class AlternativeCommandsHandler {
private final transient Map<String, List<WeakReference<Command>>> altCommands = new HashMap<>();
Expand Down Expand Up @@ -45,9 +45,7 @@ public final void addPlugin(final Plugin plugin) {
while (pluginCmdIterator.hasNext()) {
final Command cmd = pluginCmdIterator.next().get();
if (cmd == null) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Essentials: Alternative command for " + commandName + " removed due to garbage collection");
}
DebugLogUtil.debugLog("Essentials: Alternative command for " + commandName + " removed due to garbage collection");

pluginCmdIterator.remove();
continue;
Expand Down Expand Up @@ -136,9 +134,7 @@ public Command getAlternative(final String label) {
public void executed(final String label, final Command pc) {
if (pc instanceof PluginIdentifiableCommand) {
final String altString = ((PluginIdentifiableCommand) pc).getPlugin().getName() + ":" + pc.getName();
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString);
}
DebugLogUtil.debugLog("Essentials: Alternative command " + label + " found, using " + altString);
disabledList.put(label, altString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.earth2me.essentials.api.IAsyncTeleport;
import com.earth2me.essentials.commands.WarpNotFoundException;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.DebugLogUtil;
import com.earth2me.essentials.utils.LocationUtil;
import io.papermc.lib.PaperLib;
import net.ess3.api.IEssentials;
Expand Down Expand Up @@ -398,9 +399,7 @@ void respawnNow(final IUser teleportee, final TeleportCause cause, final Complet
if (location != null) {
nowAsync(teleportee, new LocationTarget(location), cause, future);
} else {
if (ess.getSettings().isDebug()) {
ess.getLogger().info("Could not find bed spawn, forcing respawn event.");
}
DebugLogUtil.debugLog("Could not find bed spawn, forcing respawn event.");
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
ess.getServer().getPluginManager().callEvent(pre);
nowAsync(teleportee, new LocationTarget(pre.getRespawnLocation()), cause, future);
Expand Down
24 changes: 9 additions & 15 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.earth2me.essentials.updatecheck.UpdateChecker;
import com.earth2me.essentials.userstorage.ModernUserMap;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.DebugLogUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import io.papermc.lib.PaperLib;
Expand Down Expand Up @@ -206,6 +207,7 @@ public ISettings getSettings() {
public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException {
TESTING = true;
LOGGER = new BaseLoggerProvider(this, BUKKIT_LOGGER);
DebugLogUtil.setEssentials(this);
final File dataFolder = File.createTempFile("essentialstest", "");
if (!dataFolder.delete()) {
throw new IOException();
Expand Down Expand Up @@ -437,9 +439,7 @@ public void onEnable() {
((Cancellable) event).setCancelled(true);
}
});
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Registered Paper Recipe Book Event Listener");
}
DebugLogUtil.debugLog("Registered Paper Recipe Book Event Listener");
} catch (final ClassNotFoundException ignored) {
}
}
Expand All @@ -458,6 +458,7 @@ public void onEnable() {
scheduleSyncRepeatingTask(timer, 1000, 50);

Economy.setEss(this);
DebugLogUtil.setEssentials(this);
execTimer.mark("RegHandler");

// Register /hat and /back default permissions
Expand All @@ -477,9 +478,7 @@ public void onEnable() {
execTimer.mark("Init(External)");

final String timeroutput = execTimer.end();
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Essentials load " + timeroutput);
}
DebugLogUtil.debugLog("Essentials load " + timeroutput);
} catch (final NumberFormatException ex) {
handleCrash(ex);
} catch (final Error ex) {
Expand All @@ -506,9 +505,7 @@ public void saveConfig() {
private void registerListeners(final PluginManager pm) {
HandlerList.unregisterAll(this);

if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Registering Listeners");
}
DebugLogUtil.debugLog("Registering Listeners");

final EssentialsPluginListener pluginListener = new EssentialsPluginListener(this);
pm.registerEvents(pluginListener, this);
Expand Down Expand Up @@ -589,6 +586,7 @@ public void onDisable() {
this.getPermissionsHandler().unregisterContexts();

Economy.setEss(null);
DebugLogUtil.setEssentials(null);
Trade.closeLog();
getUsers().shutdown();

Expand Down Expand Up @@ -729,9 +727,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
public boolean onCommandEssentials(final CommandSender cSender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module) {
// Allow plugins to override the command via onCommand
if (!getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))) {
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Searching for alternative to: " + commandLabel);
}
DebugLogUtil.debugLog("Searching for alternative to: " + commandLabel);
final Command pc = alternativeCommandsHandler.getAlternative(commandLabel);
if (pc != null) {
alternativeCommandsHandler.executed(commandLabel, pc);
Expand Down Expand Up @@ -893,9 +889,7 @@ public void showError(final CommandSource sender, final Throwable exception, fin
} else {
sender.sendTl("errorWithMessage", exception.getMessage());
}
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
}
DebugLogUtil.debugLog(AdventureUtil.miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.DebugLogUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.LocationUtil;
import com.earth2me.essentials.utils.MaterialUtil;
Expand Down Expand Up @@ -203,11 +204,8 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
}
}
} catch (final UnsupportedOperationException ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Ignore could not block chat due to custom chat plugin event.", ex);
} else {
ess.getLogger().info("Ignore could not block chat due to custom chat plugin event.");
}
DebugLogUtil.debugLog("Ignore could not block chat due to custom chat plugin event.", ex);
ess.getLogger().info("Ignore could not block chat due to custom chat plugin event.");
}

user.updateActivityOnChat(true);
Expand Down Expand Up @@ -383,9 +381,7 @@ public void run() {
final Player toVanish = ess.getServer().getPlayerExact(p);
if (toVanish != null && toVanish.isOnline()) {
user.getBase().hidePlayer(toVanish);
if (ess.getSettings().isDebug()) {
ess.getLogger().info("Hiding vanished player: " + p);
}
DebugLogUtil.debugLog("Hiding vanished player: " + p);
}
}
}
Expand Down Expand Up @@ -501,11 +497,8 @@ public void run() {
try {
tempInput = new TextInput(user.getSource(), "motd", true, ess);
} catch (final IOException ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);
} else {
ess.getLogger().log(Level.WARNING, ex.getMessage());
}
DebugLogUtil.debugLog(ex.getMessage(), ex);
ess.getLogger().log(Level.WARNING, ex.getMessage());
}
}

Expand Down Expand Up @@ -741,9 +734,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve
final Entry<Pattern, Long> cooldownEntry = ess.getSettings().getCommandCooldownEntry(fullCommand);

if (cooldownEntry != null) {
if (ess.getSettings().isDebug()) {
ess.getLogger().info("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + ".");
}
DebugLogUtil.debugLog("Applying " + cooldownEntry.getValue() + "ms cooldown on /" + fullCommand + " for" + user.getName() + ".");
final Date expiry = new Date(System.currentTimeMillis() + cooldownEntry.getValue());
user.addCommandCooldown(cooldownEntry.getKey(), expiry, ess.getSettings().isCommandCooldownPersistent(fullCommand));
}
Expand Down Expand Up @@ -881,9 +872,7 @@ public void run() {

ess.scheduleSyncDelayedTask(new DelayedClickJumpTask());
} catch (final Exception ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);
}
DebugLogUtil.debugLog(ex.getMessage(), ex);
}
}

Expand Down
26 changes: 8 additions & 18 deletions Essentials/src/main/java/com/earth2me/essentials/Jails.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.earth2me.essentials.config.EssentialsConfiguration;
import com.earth2me.essentials.config.entities.LazyLocation;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.DebugLogUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException;
Expand Down Expand Up @@ -75,9 +76,7 @@ private void registerListeners() {
final PluginManager pluginManager = ess.getServer().getPluginManager();
final JailListener blockListener = new JailListener();
pluginManager.registerEvents(blockListener, ess);
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Registering Jail listener");
}
DebugLogUtil.debugLog("Registering Jail listener");
}

public void resetListener() {
Expand Down Expand Up @@ -272,11 +271,8 @@ public void onJailPlayerRespawn(final PlayerRespawnEvent event) {
try {
event.setRespawnLocation(getJail(user.getJail()));
} catch (final Exception ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
DebugLogUtil.debugLog(AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
}

Expand All @@ -294,11 +290,8 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) {
try {
event.setTo(getJail(user.getJail()));
} catch (final Exception ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
DebugLogUtil.debugLog(AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
user.sendTl("jailMessage");
}
Expand All @@ -318,11 +311,8 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) {

final CompletableFuture<Boolean> future = new CompletableFuture<>();
future.exceptionally(ex -> {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
DebugLogUtil.debugLog(AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
return false;
});
future.thenAccept(success -> user.sendTl("jailMessage"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.earth2me.essentials.textreader.BookInput;
import com.earth2me.essentials.textreader.BookPager;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.utils.DebugLogUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import com.earth2me.essentials.utils.NumberUtil;
Expand Down Expand Up @@ -41,7 +42,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.regex.Pattern;

public class MetaItemStack {
Expand Down Expand Up @@ -138,9 +138,7 @@ public boolean canSpawn(final IEssentials ess) {
} catch (final NoSuchMethodError nsme) {
return true;
} catch (final Throwable npe) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
DebugLogUtil.debugLog("Itemstack is invalid", npe);
return false;
}
}
Expand All @@ -158,9 +156,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf
try {
stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)));
} catch (final NullPointerException npe) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
DebugLogUtil.debugLog("Itemstack is invalid", npe);
} catch (final NoSuchMethodError nsme) {
throw new TranslatableException(nsme, "noMetaJson");
} catch (final Throwable throwable) {
Expand All @@ -176,9 +172,7 @@ public void parseStringMeta(final CommandSource sender, final boolean allowUnsaf
// modifyItemStack requires that the item namespaced key is prepended to the components for some reason
stack = ess.getServer().getUnsafe().modifyItemStack(stack, stack.getType().getKey() + components);
} catch (final NullPointerException npe) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
}
DebugLogUtil.debugLog("Itemstack is invalid", npe);
} catch (final Throwable throwable) {
throw new Exception(throwable.getMessage(), throwable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.DebugLogUtil;
import io.papermc.lib.PaperLib;
import net.ess3.provider.Provider;
import net.essentialsx.providers.NullableProvider;
Expand Down Expand Up @@ -46,9 +47,7 @@ public final void registerProvider(final Class<? extends Provider>... toRegister
if (Provider.class.isAssignableFrom(superclass)) {
//noinspection unchecked
registeredProviders.computeIfAbsent((Class<? extends Provider>) superclass, k -> new ArrayList<>()).add(provider);
if (essentials.getSettings().isDebug()) {
essentials.getLogger().info("Registered provider " + provider.getSimpleName() + " for " + superclass.getSimpleName());
}
DebugLogUtil.debugLog("Registered provider " + provider.getSimpleName() + " for " + superclass.getSimpleName());
}
}
}
Expand Down
Loading
Loading