Skip to content

Commit

Permalink
Fix placeholders not parsing inside log messages (#5635)
Browse files Browse the repository at this point in the history
  • Loading branch information
JRoy authored Feb 4, 2024
1 parent 746627c commit 23093b6
Show file tree
Hide file tree
Showing 36 changed files with 123 additions and 92 deletions.
5 changes: 3 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Backup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import net.ess3.api.IEssentials;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void run() {
taskLock.complete(new Object());
return;
}
ess.getLogger().log(Level.INFO, tlLiteral("backupStarted"));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupStarted")));
final CommandSender cs = server.getConsoleSender();
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
Expand Down Expand Up @@ -118,7 +119,7 @@ public void run() {
}
active = false;
taskLock.complete(new Object());
ess.getLogger().log(Level.INFO, tlLiteral("backupFinished"));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupFinished")));
}
}

Expand Down
36 changes: 18 additions & 18 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void setupForTesting(final Server server) throws IOException, InvalidDesc
i18n.updateLocale("en");
Console.setInstance(this);

LOGGER.log(Level.INFO, tlLiteral("usingTempFolderForTesting"));
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("usingTempFolderForTesting")));
LOGGER.log(Level.INFO, dataFolder.toString());
settings = new Settings(this);
mail = new MailServiceImpl(this);
Expand Down Expand Up @@ -282,33 +282,33 @@ public void onEnable() {

switch (VersionUtil.getServerSupportStatus()) {
case NMS_CLEANROOM:
getLogger().severe(tlLiteral("serverUnsupportedCleanroom"));
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedCleanroom")));
break;
case DANGEROUS_FORK:
getLogger().severe(tlLiteral("serverUnsupportedDangerous"));
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDangerous")));
break;
case STUPID_PLUGIN:
getLogger().severe(tlLiteral("serverUnsupportedDumbPlugins"));
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDumbPlugins")));
break;
case UNSTABLE:
getLogger().severe(tlLiteral("serverUnsupportedMods"));
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedMods")));
break;
case OUTDATED:
getLogger().severe(tlLiteral("serverUnsupported"));
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupported")));
break;
case LIMITED:
getLogger().info(tlLiteral("serverUnsupportedLimitedApi"));
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedLimitedApi")));
break;
}

if (VersionUtil.getSupportStatusClass() != null) {
getLogger().info(tlLiteral("serverUnsupportedClass", VersionUtil.getSupportStatusClass()));
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedClass", VersionUtil.getSupportStatusClass())));
}

final PluginManager pm = getServer().getPluginManager();
for (final Plugin plugin : pm.getPlugins()) {
if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) {
getLogger().warning(tlLiteral("versionMismatch", plugin.getDescription().getName()));
getLogger().warning(AdventureUtil.miniToLegacy(tlLiteral("versionMismatch", plugin.getDescription().getName())));
}
}

Expand Down Expand Up @@ -582,7 +582,7 @@ private void registerListeners(final PluginManager pm) {
public void onDisable() {
final boolean stopping = getServerStateProvider().isStopping();
if (!stopping) {
LOGGER.log(Level.SEVERE, tlLiteral("serverReloading"));
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));
}
getBackup().setPendingShutdown(true);
for (final User user : getOnlineUsers()) {
Expand All @@ -602,7 +602,7 @@ public void onDisable() {
}
cleanupOpenInventories();
if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) {
LOGGER.log(Level.SEVERE, tlLiteral("backupInProgress"));
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("backupInProgress")));
getBackup().getTaskLock().join();
}
if (i18n != null) {
Expand Down Expand Up @@ -709,7 +709,7 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
} catch (final Exception ex) {
sender.sendTl("commandNotLoaded", commandLabel);
LOGGER.log(Level.SEVERE, tlLiteral("commandNotLoaded", commandLabel), ex);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
return Collections.emptyList();
}

Expand All @@ -732,11 +732,11 @@ public List<String> onTabCompleteEssentials(final CommandSender cSender, final C
} catch (final Exception ex) {
showError(sender, ex, commandLabel);
// Tab completion shouldn't fail
LOGGER.log(Level.SEVERE, tlLiteral("commandFailed", commandLabel), ex);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return Collections.emptyList();
}
} catch (final Throwable ex) {
LOGGER.log(Level.SEVERE, tlLiteral("commandFailed", commandLabel), ex);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return Collections.emptyList();
}
}
Expand Down Expand Up @@ -820,13 +820,13 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
} catch (final Exception ex) {
sender.sendTl("commandNotLoaded", commandLabel);
LOGGER.log(Level.SEVERE, tlLiteral("commandNotLoaded", commandLabel), ex);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
return true;
}

// Check authorization
if (user != null && !user.isAuthorized(cmd, permissionPrefix)) {
LOGGER.log(Level.INFO, tlLiteral("deniedAccessCommand", user.getName()));
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("deniedAccessCommand", user.getName())));
user.sendTl("noAccessCommand");
return true;
}
Expand Down Expand Up @@ -877,7 +877,7 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co
return true;
}
} catch (final Throwable ex) {
LOGGER.log(Level.SEVERE, tlLiteral("commandFailed", commandLabel), ex);
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
return true;
}
}
Expand Down Expand Up @@ -909,7 +909,7 @@ public void showError(final CommandSource sender, final Throwable exception, fin
sender.sendTl("errorWithMessage", exception.getMessage());
}
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, tlLiteral("errorCallingCommand", commandLabel), exception);
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FormatUtil;
Expand Down Expand Up @@ -188,7 +189,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
}
}

ess.getLogger().info(tlLiteral("mutedUserSpeaks", user.getName(), event.getMessage()));
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("mutedUserSpeaks", user.getName(), event.getMessage())));
}
try {
final Iterator<Player> it = event.getRecipients().iterator();
Expand Down Expand Up @@ -669,7 +670,7 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve
user.sendTl("voiceSilencedTime", dateDiff);
}
}
ess.getLogger().info(tlLiteral("mutedUserSpeaks", player.getName(), event.getMessage()));
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("mutedUserSpeaks", player.getName(), event.getMessage())));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ private void moveMotdRulesToFile(final String name) {
doneFile.setProperty("move" + name + "ToFile", true);
doneFile.save();
} catch (final IOException e) {
ess.getLogger().log(Level.SEVERE, tlLiteral("upgradingFilesError"), e);
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("upgradingFilesError")), e);
}
}

Expand Down Expand Up @@ -658,15 +658,15 @@ private void sanitizeAllUserFilenames() {
final File tmpFile = new File(listOfFile.getParentFile(), sanitizedFilename + ".tmp");
final File newFile = new File(listOfFile.getParentFile(), sanitizedFilename);
if (!listOfFile.renameTo(tmpFile)) {
ess.getLogger().log(Level.WARNING, tlLiteral("userdataMoveError", filename, sanitizedFilename));
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("userdataMoveError", filename, sanitizedFilename)));
continue;
}
if (newFile.exists()) {
ess.getLogger().log(Level.WARNING, tlLiteral("duplicatedUserdata", filename, sanitizedFilename));
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("duplicatedUserdata", filename, sanitizedFilename)));
continue;
}
if (!tmpFile.renameTo(newFile)) {
ess.getLogger().log(Level.WARNING, tlLiteral("userdataMoveBackError", sanitizedFilename, sanitizedFilename));
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("userdataMoveBackError", sanitizedFilename, sanitizedFilename)));
}
}
doneFile.setProperty("sanitizeAllUserFilenames", true);
Expand Down
13 changes: 7 additions & 6 deletions Essentials/src/main/java/com/earth2me/essentials/Jails.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.earth2me.essentials.config.ConfigurateUtil;
import com.earth2me.essentials.config.EssentialsConfiguration;
import com.earth2me.essentials.config.entities.LazyLocation;
import com.earth2me.essentials.utils.AdventureUtil;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException;
Expand Down Expand Up @@ -294,9 +295,9 @@ public void onJailPlayerRespawn(final PlayerRespawnEvent event) {
event.setRespawnLocation(getJail(user.getJail()));
} catch (final Exception ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
}
}
Expand All @@ -316,9 +317,9 @@ public void onJailPlayerTeleport(final PlayerTeleportEvent event) {
event.setTo(getJail(user.getJail()));
} catch (final Exception ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
}
user.sendTl("jailMessage");
Expand All @@ -340,9 +341,9 @@ public void onJailPlayerJoin(final PlayerJoinEvent event) {
final CompletableFuture<Boolean> future = new CompletableFuture<>();
future.exceptionally(ex -> {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
} else {
ess.getLogger().log(Level.INFO, tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
}
return false;
});
Expand Down
3 changes: 2 additions & 1 deletion Essentials/src/main/java/com/earth2me/essentials/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
Expand Down Expand Up @@ -193,7 +194,7 @@ public boolean expandItems(final User user, final List<String> items) throws Exc

if (kitItem.startsWith("@")) {
if (ess.getSerializationProvider() == null) {
ess.getLogger().log(Level.WARNING, tlLiteral("kitError3", kitName, user.getName()));
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("kitError3", kitName, user.getName())));
continue;
}
stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
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.AdventureUtil;
import net.ess3.api.IEssentials;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ManagedFile(final String filename, final IEssentials ess) {
try {
copyResourceAscii("/" + filename, file);
} catch (final IOException ex) {
Essentials.getWrappedLogger().log(Level.SEVERE, tlLiteral("itemsCsvNotLoaded", filename), ex);
Essentials.getWrappedLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("itemsCsvNotLoaded", filename)), ex);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Essentials/src/main/java/com/earth2me/essentials/Mob.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.EnumUtil;
import org.bukkit.Location;
import org.bukkit.Server;
Expand Down Expand Up @@ -171,7 +172,7 @@ public static Mob fromBukkitType(final EntityType type) {
public Entity spawn(final World world, final Server server, final Location loc) throws MobException {
final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass());
if (entity == null) {
Essentials.getWrappedLogger().log(Level.WARNING, tlLiteral("unableToSpawnMob"));
Essentials.getWrappedLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("unableToSpawnMob")));
throw new MobException();
}
return entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ private List<Material> _getItemSpawnBlacklist() {
final ItemStack iStack = itemDb.get(itemName);
epItemSpwn.add(iStack.getType());
} catch (final Exception ex) {
ess.getLogger().log(Level.SEVERE, tlLiteral("unknownItemInList", itemName, "item-spawn-blacklist"), ex);
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", itemName, "item-spawn-blacklist")), ex);
}
}
return epItemSpwn;
Expand Down Expand Up @@ -846,7 +846,7 @@ private List<EssentialsSign> _getEnabledSigns() {
try {
newSigns.add(Signs.valueOf(signName).getSign());
} catch (final Exception ex) {
ess.getLogger().log(Level.SEVERE, tlLiteral("unknownItemInList", signName, "enabledSigns"));
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", signName, "enabledSigns")));
continue;
}
signsEnabled = true;
Expand Down Expand Up @@ -965,7 +965,7 @@ public List<Material> getProtectList(final String configName) {
}

if (mat == null) {
ess.getLogger().log(Level.SEVERE, tlLiteral("unknownItemInList", itemName, configName));
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", itemName, configName)));
} else {
list.add(mat);
}
Expand Down Expand Up @@ -1713,7 +1713,7 @@ private List<EssentialsSign> _getUnprotectedSign() {
try {
newSigns.add(Signs.valueOf(signName).getSign());
} catch (final Exception ex) {
ess.getLogger().log(Level.SEVERE, tlLiteral("unknownItemInList", signName, "unprotected-sign-names"));
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", signName, "unprotected-sign-names")));
}
}
return newSigns;
Expand Down
3 changes: 2 additions & 1 deletion Essentials/src/main/java/com/earth2me/essentials/Warps.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.earth2me.essentials.commands.WarpNotFoundException;
import com.earth2me.essentials.config.EssentialsConfiguration;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.StringUtil;
import net.ess3.api.InvalidNameException;
import net.ess3.api.InvalidWorldException;
Expand Down Expand Up @@ -134,7 +135,7 @@ public final void reloadConfig() {
warpPoints.put(new StringIgnoreCase(name), conf);
}
} catch (final Exception ex) {
Essentials.getWrappedLogger().log(Level.WARNING, tlLiteral("loadWarpError", filename), ex);
Essentials.getWrappedLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("loadWarpError", filename)), ex);
}
}
}
Expand Down
Loading

0 comments on commit 23093b6

Please sign in to comment.