fix: add custom messages to plugin

fix: add custom messages to several options:
1. Join Cooldown Protection
2. No Portal Permission
3. No Portal Cooldown

This is all moved to a new configuration file called messages.yml so that config.yml doesn't become convoluted

Fixes
#144
#224
This commit is contained in:
TreemanKing 2023-09-12 12:58:17 +10:00
parent 2c919bff06
commit fd2c3d6534
5 changed files with 49 additions and 16 deletions

View File

@ -61,6 +61,10 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml");
destinationConfig.saveDefaultConfig();
ConfigAccessor messagesConfig = new ConfigAccessor(this, "messages.yml");
messagesConfig.saveDefaultConfig();;
this.settings = new Settings(this);
// Loads the portal and destination editors

View File

@ -6,12 +6,15 @@ import org.bukkit.command.CommandSender;
public class PluginMessages {
private static String WARP_MESSAGE;
private static String COOLDOWN_PROTECTION_MESSAGE;
private static String PORTAL_COOLDOWN_MESSAGE;
private static String NO_PERMISSION_PORTAL;
public boolean useCustomPrefix = false;
public static String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]";
public static String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]";
public PluginMessages (AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "config.yml");
ConfigAccessor config = new ConfigAccessor(plugin, "messages.yml");
this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix");
if (useCustomPrefix) {
PluginMessages.customPrefix = config.getConfig().getString("CustomPrefix").replaceAll("&(?=[0-9a-fk-or])", "\u00A7");
@ -19,6 +22,9 @@ public class PluginMessages {
}
WARP_MESSAGE = ChatColor.translateAlternateColorCodes('&', config.getConfig().getString("WarpMessage", "&aYou have warped to &e<warp>&a"));
COOLDOWN_PROTECTION_MESSAGE = ChatColor.translateAlternateColorCodes('&', config.getConfig().getString("CooldownMessage", "&cThere is &e<time>&c join cooldown protection left."));
NO_PERMISSION_PORTAL = ChatColor.translateAlternateColorCodes('&', config.getConfig().getString("NoPermissionPortal", "&cYou do not have permission to use this portal!"));
PORTAL_COOLDOWN_MESSAGE = ChatColor.translateAlternateColorCodes('&', config.getConfig().getString("PortalCooldownMessage", "&cPlease wait &e<time> &cuntil attempting to enter this portal again"));
}
// This class is so then the common messages in commands or just messages over the commands are the same and can be
@ -29,6 +35,20 @@ public class PluginMessages {
return WARP_MESSAGE.replace("<warp>", cleanedWarp);
}
public static String getCooldownProtectionMessage(int time) {
String secondsOrSecond = (time == 1) ? " second" : " seconds";
return COOLDOWN_PROTECTION_MESSAGE.replace("<time>", time + secondsOrSecond);
}
public static String getPortalCooldownMessage(int time) {
String secondsOrSecond = (time == 1) ? " second" : " seconds";
return COOLDOWN_PROTECTION_MESSAGE.replace("<time>", time + secondsOrSecond);
}
public static String getNoPermissionPortal() {
return NO_PERMISSION_PORTAL;
}
public static void UnknownCommand(CommandSender sender, String command) {
sender.sendMessage(customPrefixFail + " You need to type something after /" + command + "\n");
sender.sendMessage("\u00A7cIf you do not know what you can put or would like some help with the commands please type \u00A7e" + '"' + "\u00A7e/" + command + " help" + '"' + "\u00A7c\n");

View File

@ -459,7 +459,7 @@ public class Portal {
if (!(permission == null || ((!invertPermission && player.hasPermission(permission)) || (invertPermission && !player.hasPermission(permission))) || player.isOp())) {
if(!noMessage) {
player.sendMessage(
PluginMessages.customPrefixFail + "\u00A7c You do not have permission to use this portal!");
String.join(" ", PluginMessages.customPrefixFail, PluginMessages.getNoPermissionPortal()));
failSound(player, portal);
if(doKnockback)
throwPlayerBack(player);
@ -472,7 +472,7 @@ public class Portal {
int diff = (int) ((System.currentTimeMillis() - joinCD) / 1000);
if (diff < joinCooldownDelay) {
int time = (joinCooldownDelay - diff);
player.sendMessage(ChatColor.RED + "There is " + ChatColor.YELLOW + time + ChatColor.RED + (time == 1 ? " second" : " seconds") + " join cooldown protection left.");
player.sendMessage(PluginMessages.getCooldownProtectionMessage(time));
failSound(player, portal);
if(doKnockback)
throwPlayerBack(player);
@ -493,8 +493,7 @@ public class Portal {
}
if (diff < portalCooldown) {
int time = (portalCooldown - diff);
player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + time + ChatColor.RED
+ (time == 1 ? " second" : " seconds") + " until attempting to enter this portal again.");
player.sendMessage(PluginMessages.getPortalCooldownMessage(time));
failSound(player, portal);
if(doKnockback)
throwPlayerBack(player);

View File

@ -57,17 +57,6 @@ WarpMessageDisplay: 2
# Use plugin name in the warp messages
UseWarpPrefix: true
# If this is true a custom prefix can be used, (not fully coded yet!!)
UseCustomPrefix: false
CustomPrefix: '&a[&eAdvancedPortals&a]'
CustomPrefixFail: '&c[&7AdvancedPortals&c]'
# Message sent to player in chat/action bar on warp
WarpMessage: '&aYou have warped to &e<warp>&a.'
BlockSpectatorMode: false
PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate.

View File

@ -0,0 +1,21 @@
# Advanced Portals Messages
# If this is true a custom prefix can be used, (not fully coded yet!!)
UseCustomPrefix: false
CustomPrefix: '&a[&eAdvancedPortals&a]'
CustomPrefixFail: '&c[&7AdvancedPortals&c]'
# Message sent to player in chat/action bar on warp
WarpMessage: '&aYou have warped to &e<warp>&a.'
# Message sent to player that has just joined the server trying to use a portal
CooldownProtectionMessage: '&cThere is &e<time>&c join cooldown protection left.'
# Message sent to player that doesn't have permission to use a portal
NoPermissionPortal: '&cYou do not have permission to use this portal!'
# Message sent to player that has a portal cooldown
PortalCooldownMessage: '&cPlease wait &e<time> &cuntil attempting to enter this portal again!'