Rename messages class
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2023-02-11 20:57:11 +01:00
parent 0839161bb2
commit 7f792b5ca8
14 changed files with 57 additions and 58 deletions

View File

@ -41,7 +41,7 @@ public class HubCommand implements CommandExecutor
Player teleportingPlayer = plugin.getServer().getPlayer(teleportingPlayerName); Player teleportingPlayer = plugin.getServer().getPlayer(teleportingPlayerName);
if(teleportingPlayer == null) if(teleportingPlayer == null)
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }
@ -54,7 +54,7 @@ public class HubCommand implements CommandExecutor
else else
{ {
// Warn the player he doesn't have permissions to teleport others to the hub. // Warn the player he doesn't have permissions to teleport others to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT_OTHERS.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT_OTHERS.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }
@ -65,7 +65,7 @@ public class HubCommand implements CommandExecutor
boolean senderIsConsole = !(commandSender instanceof Player); boolean senderIsConsole = !(commandSender instanceof Player);
if(senderIsConsole) if(senderIsConsole)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_CONSOLE_ACCESS_BLOCKED);
return true; return true;
} }
@ -94,7 +94,7 @@ public class HubCommand implements CommandExecutor
// Warn the player about the delay. // Warn the player about the delay.
String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_TELEPORT_DELAY, false); String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_TELEPORT_DELAY, false);
delayMessage = delayMessage.replace("%delay%", delay + ""); delayMessage = delayMessage.replace("%delay%", delay + "");
MessageUtils.sendColorizedMessage(commandSender, delayMessage); MessageUtils.sendColorizedMessage(commandSender, delayMessage);
@ -118,7 +118,7 @@ public class HubCommand implements CommandExecutor
else else
{ {
// Send a message to the player stating it, and do nothing. // Send a message to the player stating it, and do nothing.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_ALREADY_TELEPORTING); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_ALREADY_TELEPORTING);
return true; return true;
} }
} }
@ -126,7 +126,7 @@ public class HubCommand implements CommandExecutor
else else
{ {
// Warn the player he doesn't have permissions to go to the hub. // Warn the player he doesn't have permissions to go to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_TELEPORT.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }

View File

@ -29,7 +29,7 @@ public class SetHubCommand implements CommandExecutor
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender); boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole) if(senderIsConsole)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_CONSOLE_ACCESS_BLOCKED);
return true; return true;
} }
@ -61,7 +61,7 @@ public class SetHubCommand implements CommandExecutor
FileUtils.saveExistingYaml(FileUtils.FileType.HUB_YAML); FileUtils.saveExistingYaml(FileUtils.FileType.HUB_YAML);
// Tell the player he set the hub successfully. // Tell the player he set the hub successfully.
String hubSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_HUB_SET, false); String hubSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_HUB_SET, false);
hubSetMessage = hubSetMessage.replace("%w%", worldName); hubSetMessage = hubSetMessage.replace("%w%", worldName);
hubSetMessage = hubSetMessage.replace("%x%", (int)x + ""); hubSetMessage = hubSetMessage.replace("%x%", (int)x + "");
hubSetMessage = hubSetMessage.replace("%y%", (int)y + ""); hubSetMessage = hubSetMessage.replace("%y%", (int)y + "");
@ -70,7 +70,7 @@ public class SetHubCommand implements CommandExecutor
} }
else else
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_SET.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.HUB_SET.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
} }
return true; return true;

View File

@ -41,7 +41,7 @@ public class SetSpawnCommand implements CommandExecutor
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender); boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole) if(senderIsConsole)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_CONSOLE_ACCESS_BLOCKED);
return true; return true;
} }
@ -83,7 +83,7 @@ public class SetSpawnCommand implements CommandExecutor
{ {
// Warn the player and stop. // Warn the player and stop.
// Tell the player that the world does not exist. // Tell the player that the world does not exist.
String errorWorldNotExistingMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, false); String errorWorldNotExistingMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_WORLD_NOT_EXISTING, false);
errorWorldNotExistingMessage = errorWorldNotExistingMessage.replace("%w%", worldYouAreSettingTheSpawnOf); errorWorldNotExistingMessage = errorWorldNotExistingMessage.replace("%w%", worldYouAreSettingTheSpawnOf);
MessageUtils.sendColorizedMessage(commandSender, errorWorldNotExistingMessage); MessageUtils.sendColorizedMessage(commandSender, errorWorldNotExistingMessage);
return true; return true;
@ -104,7 +104,7 @@ public class SetSpawnCommand implements CommandExecutor
FileUtils.saveExistingYaml(FileUtils.FileType.SPAWN_YAML); FileUtils.saveExistingYaml(FileUtils.FileType.SPAWN_YAML);
// Tell the player he set the spawn successfully. // Tell the player he set the spawn successfully.
String spawnSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_SPAWN_SET, false) String spawnSetMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_SPAWN_SET, false)
.replace("%dw%", worldYouAreSettingTheSpawnOf) .replace("%dw%", worldYouAreSettingTheSpawnOf)
.replace("%cw%", currentWorldName) .replace("%cw%", currentWorldName)
.replace("%x%", (int)x + "") .replace("%x%", (int)x + "")
@ -115,7 +115,7 @@ public class SetSpawnCommand implements CommandExecutor
} }
else else
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_SET.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_SET.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
} }

View File

@ -42,7 +42,7 @@ public class SpawnCommand implements CommandExecutor
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender); boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole) if(senderIsConsole)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_CONSOLE_ACCESS_BLOCKED);
return true; return true;
} }
@ -56,14 +56,14 @@ public class SpawnCommand implements CommandExecutor
Player teleportPlayer = plugin.getServer().getPlayer(teleportingPlayerName); Player teleportPlayer = plugin.getServer().getPlayer(teleportingPlayerName);
if(teleportPlayer == null) if(teleportPlayer == null)
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_PLAYER_OFFLINE, true).replace("%player%", teleportingPlayerName);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }
if(plugin.getServer().getWorld(worldName) == null) if(plugin.getServer().getWorld(worldName) == null)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_SPAWN_NOT_SET); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_SPAWN_NOT_SET);
return true; return true;
} }
@ -73,7 +73,7 @@ public class SpawnCommand implements CommandExecutor
else else
{ {
// Warn the player he doesn't have permissions to teleport others to the hub. // Warn the player he doesn't have permissions to teleport others to the hub.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_OTHERS.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_OTHERS.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }
@ -103,14 +103,14 @@ public class SpawnCommand implements CommandExecutor
if(!PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_TELEPORT_ANOTHER_WORLD)) if(!PermissionUtils.playerHasPermission(commandSender, Permissions.SPAWN_TELEPORT_ANOTHER_WORLD))
{ {
// Tell the player he has no permission to teleport to another world's spawn. // Tell the player he has no permission to teleport to another world's spawn.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_ANOTHER_WORLD.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT_ANOTHER_WORLD.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return true; return true;
} }
if(plugin.getServer().getWorld(args[0]) == null) if(plugin.getServer().getWorld(args[0]) == null)
{ {
String erroMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, true).replace("%w%", args[0]); String erroMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_WORLD_NOT_EXISTING, true).replace("%w%", args[0]);
commandSender.sendMessage(erroMessage); commandSender.sendMessage(erroMessage);
return true; return true;
} }
@ -121,7 +121,7 @@ public class SpawnCommand implements CommandExecutor
int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.SPAWN_DELAY.path); int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.SPAWN_DELAY.path);
// Warn the player about the delay. // Warn the player about the delay.
String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_TELEPORT_DELAY, false); String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_TELEPORT_DELAY, false);
delayMessage = delayMessage.replace("%delay%", delay + ""); delayMessage = delayMessage.replace("%delay%", delay + "");
MessageUtils.sendColorizedMessage(commandSender, delayMessage); MessageUtils.sendColorizedMessage(commandSender, delayMessage);
@ -146,7 +146,7 @@ public class SpawnCommand implements CommandExecutor
else else
{ {
// Send a message to the player stating it, and do nothing. // Send a message to the player stating it, and do nothing.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_ALREADY_TELEPORTING); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_ALREADY_TELEPORTING);
return true; return true;
} }
} }
@ -154,7 +154,7 @@ public class SpawnCommand implements CommandExecutor
else else
{ {
// Warn the player he doesn't have permissions to go to the spawn. // Warn the player he doesn't have permissions to go to the spawn.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.SPAWN_TELEPORT.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
} }

View File

@ -36,7 +36,7 @@ public class WorldListCommand implements CommandExecutor
if(PermissionUtils.playerHasPermission(commandSender, Permissions.WORLD_LIST)) if(PermissionUtils.playerHasPermission(commandSender, Permissions.WORLD_LIST))
{ {
// send the translated title. // send the translated title.
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.INFO_WORLDS_LIST); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.INFO_WORLDS_LIST);
MessageUtils.sendColorizedMessage(commandSender, "&7---------"); MessageUtils.sendColorizedMessage(commandSender, "&7---------");
@ -77,7 +77,7 @@ public class WorldListCommand implements CommandExecutor
else // If player doesn't have permissions... else // If player doesn't have permissions...
{ {
// Tell him. // Tell him.
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.WORLD_LIST.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.WORLD_LIST.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
} }
return true; return true;

View File

@ -40,7 +40,7 @@ public class WorldTpCommand implements CommandExecutor
boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender); boolean senderIsConsole = (commandSender instanceof ConsoleCommandSender);
if(senderIsConsole) if(senderIsConsole)
{ {
MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessages.ERROR_CONSOLE_ACCESS_BLOCKED); MessageUtils.sendLocalizedMessage(commandSender, LocalizedMessage.ERROR_CONSOLE_ACCESS_BLOCKED);
return true; return true;
} }
@ -51,7 +51,7 @@ public class WorldTpCommand implements CommandExecutor
if(args.length != 1) if(args.length != 1)
{ {
// Warn the player in case it's wrong. // Warn the player in case it's wrong.
String wrongUsageMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WRONG_USAGE, false).replace("%usage%", "/worldtp <world>"); String wrongUsageMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_WRONG_USAGE, false).replace("%usage%", "/worldtp <world>");
MessageUtils.sendColorizedMessage(commandSender, wrongUsageMessage); MessageUtils.sendColorizedMessage(commandSender, wrongUsageMessage);
return true; return true;
} }
@ -62,7 +62,7 @@ public class WorldTpCommand implements CommandExecutor
// If the world does not exist, warn the player. // If the world does not exist, warn the player.
if(destinationWorld == null) if(destinationWorld == null)
{ {
String worldDoesNotExistMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, false); String worldDoesNotExistMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_WORLD_NOT_EXISTING, false);
worldDoesNotExistMessage = worldDoesNotExistMessage.replace("%w%", destinationWorldName); worldDoesNotExistMessage = worldDoesNotExistMessage.replace("%w%", destinationWorldName);
MessageUtils.sendColorizedMessage(commandSender, worldDoesNotExistMessage); MessageUtils.sendColorizedMessage(commandSender, worldDoesNotExistMessage);
return true; return true;
@ -77,7 +77,7 @@ public class WorldTpCommand implements CommandExecutor
plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(destinationLocation), 1); plugin.getServer().getScheduler().runTaskLater(plugin, () -> player.teleport(destinationLocation), 1);
fixInvisibilityAfter(player); fixInvisibilityAfter(player);
// Tell the player he has been teleported. // Tell the player he has been teleported.
String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_WORLDTP_TELEPORTED, false); String teleportedMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_WORLDTP_TELEPORTED, false);
teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName); teleportedMessage = teleportedMessage.replace("%world%", destinationWorldName).replace("%w%", destinationWorldName);
MessageUtils.sendColorizedMessage(commandSender, teleportedMessage); MessageUtils.sendColorizedMessage(commandSender, teleportedMessage);
} }

View File

@ -1,6 +1,6 @@
package wtf.beatrice.hubthat.commands.hubthatcommands; package wtf.beatrice.hubthat.commands.hubthatcommands;
import wtf.beatrice.hubthat.utils.LocalizedMessages; import wtf.beatrice.hubthat.utils.LocalizedMessage;
import wtf.beatrice.hubthat.utils.MessageUtils; import wtf.beatrice.hubthat.utils.MessageUtils;
import wtf.beatrice.hubthat.utils.PermissionUtils; import wtf.beatrice.hubthat.utils.PermissionUtils;
import wtf.beatrice.hubthat.utils.Permissions; import wtf.beatrice.hubthat.utils.Permissions;
@ -13,7 +13,7 @@ public class HelpCommand
{ {
if(!PermissionUtils.playerHasPermission(commandSender, Permissions.HELP_MESSAGE)) if(!PermissionUtils.playerHasPermission(commandSender, Permissions.HELP_MESSAGE))
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.HELP_MESSAGE.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.HELP_MESSAGE.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
return; return;
} }

View File

@ -28,7 +28,7 @@ public class ReloadCommand
} }
else else
{ {
String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.NO_PERMISSION, true).replace("%permission%", Permissions.RELOAD_CONFIG.permission); String errorMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.NO_PERMISSION, true).replace("%permission%", Permissions.RELOAD_CONFIG.permission);
commandSender.sendMessage(errorMessage); commandSender.sendMessage(errorMessage);
} }

View File

@ -2,7 +2,7 @@ package wtf.beatrice.hubthat.listeners;
import wtf.beatrice.hubthat.utils.PluginCache; import wtf.beatrice.hubthat.utils.PluginCache;
import wtf.beatrice.hubthat.utils.ConfigEntries; import wtf.beatrice.hubthat.utils.ConfigEntries;
import wtf.beatrice.hubthat.utils.LocalizedMessages; import wtf.beatrice.hubthat.utils.LocalizedMessage;
import wtf.beatrice.hubthat.utils.MessageUtils; import wtf.beatrice.hubthat.utils.MessageUtils;
import wtf.beatrice.hubthat.utils.files.FileUtils; import wtf.beatrice.hubthat.utils.files.FileUtils;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -33,7 +33,7 @@ public class PlayerMoveListener implements Listener
// Remove the player from the list and warn him. // Remove the player from the list and warn him.
PluginCache.teleporting.remove(playerName); PluginCache.teleporting.remove(playerName);
PluginCache.cancelRunnable.add(playerName); PluginCache.cancelRunnable.add(playerName);
MessageUtils.sendLocalizedMessage(event.getPlayer(), LocalizedMessages.WARNING_TELEPORTATION_CANCELLED); MessageUtils.sendLocalizedMessage(event.getPlayer(), LocalizedMessage.WARNING_TELEPORTATION_CANCELLED);
} }
} }
} }

View File

@ -1,6 +1,6 @@
package wtf.beatrice.hubthat.utils; package wtf.beatrice.hubthat.utils;
public enum LocalizedMessages public enum LocalizedMessage
{ {
@ -49,7 +49,7 @@ public enum LocalizedMessages
public String path; public String path;
LocalizedMessages(String path) LocalizedMessage(String path)
{ {
this.path = path; this.path = path;
} }

View File

@ -14,7 +14,7 @@ public class MessageUtils
private static final Debugger debugger = new Debugger(MessageUtils.class.getName()); private static final Debugger debugger = new Debugger(MessageUtils.class.getName());
// Method to automatically load and send a localized message to the CommandSender. // Method to automatically load and send a localized message to the CommandSender.
public static void sendLocalizedMessage(CommandSender sender, LocalizedMessages messageEnum) public static void sendLocalizedMessage(CommandSender sender, LocalizedMessage messageEnum)
{ {
// If we actually have a sender, send it the message and color it! // If we actually have a sender, send it the message and color it!
if(sender != null) sender.sendMessage(getLocalizedMessage(messageEnum, true)); if(sender != null) sender.sendMessage(getLocalizedMessage(messageEnum, true));
@ -32,7 +32,7 @@ public class MessageUtils
else debugger.sendDebugMessage(Level.SEVERE, "Sender is null!"); else debugger.sendDebugMessage(Level.SEVERE, "Sender is null!");
} }
public static String getLocalizedMessage(LocalizedMessages messageEnum, boolean applyColor) public static String getLocalizedMessage(LocalizedMessage messageEnum, boolean applyColor)
{ {
/* /*
@ -47,7 +47,7 @@ public class MessageUtils
YamlConfiguration langFile = FileUtils.FileType.LANG_YAML.yaml; YamlConfiguration langFile = FileUtils.FileType.LANG_YAML.yaml;
// Initialize the message string and store the String from the lang file to it. // Initialize the message string and store the String from the lang file to it.
String localizedMessage = langFile.getString(LocalizedMessages.INFO_PREFIX.path) + langFile.getString(path); String localizedMessage = langFile.getString(LocalizedMessage.INFO_PREFIX.path) + langFile.getString(path);
// Check if the message is null and if we have to color the message or leave the symbols inside for further elaboration. // Check if the message is null and if we have to color the message or leave the symbols inside for further elaboration.
if (localizedMessage != null) if (localizedMessage != null)

View File

@ -4,7 +4,6 @@ import org.bukkit.command.CommandSender;
public class PermissionUtils public class PermissionUtils
{ {
// Method to get the permission string from the Permissions enum. // Method to get the permission string from the Permissions enum.
public static boolean playerHasPermission(CommandSender user, Permissions permission) public static boolean playerHasPermission(CommandSender user, Permissions permission)
{ {

View File

@ -88,12 +88,12 @@ public class TeleportUtils
if(type == FileUtils.FileType.HUB_YAML) if(type == FileUtils.FileType.HUB_YAML)
{ {
// send a message about the hub being not set // send a message about the hub being not set
if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessages.ERROR_HUB_NOT_SET); if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessage.ERROR_HUB_NOT_SET);
} }
else if(type == FileUtils.FileType.SPAWN_YAML) else if(type == FileUtils.FileType.SPAWN_YAML)
{ {
// send a message about the spawn being not set. // send a message about the spawn being not set.
if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessages.ERROR_SPAWN_NOT_SET); if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessage.ERROR_SPAWN_NOT_SET);
} }
else else
{ {
@ -109,7 +109,7 @@ public class TeleportUtils
if(worldName.equals("__UNSET__") && type == FileUtils.FileType.HUB_YAML) if(worldName.equals("__UNSET__") && type == FileUtils.FileType.HUB_YAML)
{ {
// Warn the player about the hub not being set. // Warn the player about the hub not being set.
if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessages.ERROR_HUB_NOT_SET); if(sendMessage) MessageUtils.sendLocalizedMessage(sender, LocalizedMessage.ERROR_HUB_NOT_SET);
// Stop. // Stop.
return; return;
} }
@ -122,7 +122,7 @@ public class TeleportUtils
// Tell the player that the world does not exist. // Tell the player that the world does not exist.
if(sendMessage) if(sendMessage)
{ {
String errorWorldNotExistingMessage = MessageUtils.getLocalizedMessage(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, false); String errorWorldNotExistingMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.ERROR_WORLD_NOT_EXISTING, false);
errorWorldNotExistingMessage = errorWorldNotExistingMessage.replace("%w%", worldName); errorWorldNotExistingMessage = errorWorldNotExistingMessage.replace("%w%", worldName);
MessageUtils.sendColorizedMessage(player, errorWorldNotExistingMessage); MessageUtils.sendColorizedMessage(player, errorWorldNotExistingMessage);
} }
@ -143,21 +143,21 @@ public class TeleportUtils
if(type == FileUtils.FileType.HUB_YAML) if(type == FileUtils.FileType.HUB_YAML)
{ {
// Send a message to the player about him being successfully teleported. // Send a message to the player about him being successfully teleported.
if(sendMessage) MessageUtils.sendLocalizedMessage(player, LocalizedMessages.INFO_HUB_TELEPORTED); if(sendMessage) MessageUtils.sendLocalizedMessage(player, LocalizedMessage.INFO_HUB_TELEPORTED);
if((sender != player) && (sendMessage)) if((sender != player) && (sendMessage))
{ {
String message = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_HUB_TELEPORTED_OTHER, true).replace("%player%", player.getName()); String message = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_HUB_TELEPORTED_OTHER, true).replace("%player%", player.getName());
sender.sendMessage(message); sender.sendMessage(message);
} }
} }
else //if(type == FileUtils.FileType.SPAWN_YAML) // left here but commented, for easy understanding else //if(type == FileUtils.FileType.SPAWN_YAML) // left here but commented, for easy understanding
{ {
if(sendMessage) MessageUtils.sendLocalizedMessage(player, LocalizedMessages.INFO_SPAWN_TELEPORTED); if(sendMessage) MessageUtils.sendLocalizedMessage(player, LocalizedMessage.INFO_SPAWN_TELEPORTED);
if((sender != player) && (sendMessage)) if((sender != player) && (sendMessage))
{ {
String message = MessageUtils.getLocalizedMessage(LocalizedMessages.INFO_SPAWN_TELEPORTED_OTHER, true).replace("%player%", player.getName()).replace("%world%", worldName); String message = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_SPAWN_TELEPORTED_OTHER, true).replace("%player%", player.getName()).replace("%world%", worldName);
sender.sendMessage(message); sender.sendMessage(message);
} }
} }

View File

@ -2,7 +2,7 @@ package wtf.beatrice.hubthat.utils.files;
import wtf.beatrice.hubthat.HubThat; import wtf.beatrice.hubthat.HubThat;
import wtf.beatrice.hubthat.utils.ConfigEntries; import wtf.beatrice.hubthat.utils.ConfigEntries;
import wtf.beatrice.hubthat.utils.LocalizedMessages; import wtf.beatrice.hubthat.utils.LocalizedMessage;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
@ -62,18 +62,18 @@ public class OldConfigConversion
logger.warning("Done with config.yml!"); logger.warning("Done with config.yml!");
logger.warning("Loading lang entries..."); logger.warning("Loading lang entries...");
HashMap<LocalizedMessages, String>newAndOldLangEntries = new HashMap<>(); HashMap<LocalizedMessage, String>newAndOldLangEntries = new HashMap<>();
newAndOldLangEntries.put(LocalizedMessages.ERROR_ALREADY_TELEPORTING, "global.ALREADY-TELEPORTING"); newAndOldLangEntries.put(LocalizedMessage.ERROR_ALREADY_TELEPORTING, "global.ALREADY-TELEPORTING");
newAndOldLangEntries.put(LocalizedMessages.ERROR_HUB_NOT_SET, "hub.HUB_NOT_SET"); newAndOldLangEntries.put(LocalizedMessage.ERROR_HUB_NOT_SET, "hub.HUB_NOT_SET");
newAndOldLangEntries.put(LocalizedMessages.ERROR_SPAWN_NOT_SET, "spawn.SPAWN_NOT_SET"); newAndOldLangEntries.put(LocalizedMessage.ERROR_SPAWN_NOT_SET, "spawn.SPAWN_NOT_SET");
newAndOldLangEntries.put(LocalizedMessages.ERROR_WORLD_NOT_EXISTING, "worldtp.UNKNOWN_WORLD"); newAndOldLangEntries.put(LocalizedMessage.ERROR_WORLD_NOT_EXISTING, "worldtp.UNKNOWN_WORLD");
newAndOldLangEntries.put(LocalizedMessages.WARNING_TELEPORTATION_CANCELLED, "global.MOVED"); newAndOldLangEntries.put(LocalizedMessage.WARNING_TELEPORTATION_CANCELLED, "global.MOVED");
newAndOldLangEntries.put(LocalizedMessages.INFO_HUB_TELEPORTED, "hub.TELEPORTED"); newAndOldLangEntries.put(LocalizedMessage.INFO_HUB_TELEPORTED, "hub.TELEPORTED");
newAndOldLangEntries.put(LocalizedMessages.INFO_SPAWN_TELEPORTED, "spawn.TELEPORTED"); newAndOldLangEntries.put(LocalizedMessage.INFO_SPAWN_TELEPORTED, "spawn.TELEPORTED");
newAndOldLangEntries.put(LocalizedMessages.INFO_WORLDTP_TELEPORTED, "worldtp.TELEPORTED"); newAndOldLangEntries.put(LocalizedMessage.INFO_WORLDTP_TELEPORTED, "worldtp.TELEPORTED");
logger.warning("Converting lang entries..."); logger.warning("Converting lang entries...");
for(LocalizedMessages message : newAndOldLangEntries.keySet()) for(LocalizedMessage message : newAndOldLangEntries.keySet())
{ {
logger.warning("Entry: " + message.path); logger.warning("Entry: " + message.path);
FileUtils.FileType.LANG_YAML.yaml.set(message.path, oldConfig.get(newAndOldLangEntries.get(message))); FileUtils.FileType.LANG_YAML.yaml.set(message.path, oldConfig.get(newAndOldLangEntries.get(message)));