From d873e4bebe166e8a47f058a19d7b12984ca683c1 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:19:25 -0800 Subject: [PATCH 1/6] Don't send empty messages --- src/main/java/tsp/headdb/util/Utils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/tsp/headdb/util/Utils.java b/src/main/java/tsp/headdb/util/Utils.java index cea3e34..ca26eac 100644 --- a/src/main/java/tsp/headdb/util/Utils.java +++ b/src/main/java/tsp/headdb/util/Utils.java @@ -37,7 +37,9 @@ public class Utils { } public static void sendMessage(CommandSender sender, String message) { - sender.sendMessage(colorize(message)); + if (!message.isEmpty()) { + sender.sendMessage(colorize(message)); + } } public static String colorize(String string) { From 169e0e86ff75c23c63d068a6cd9145bb333eb9b8 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:31:39 -0800 Subject: [PATCH 2/6] Localized head names in the main gui --- .../java/tsp/headdb/inventory/InventoryUtils.java | 2 +- src/main/resources/messages.yml | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index d9e7c3d..72bec9a 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -181,7 +181,7 @@ public class InventoryUtils { for (Category category : Category.cache) { ItemStack item = getUIItem(category.getName(), category.getItem()); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Utils.colorize(category.getColor() + "&l" + category.getName().toUpperCase())); + meta.setDisplayName(Utils.colorize(localization.getMessage("menu.heads." + category.getName()))); List lore = new ArrayList<>(); lore.add(Utils.colorize("&e" + HeadAPI.getHeads(category).size() + " heads")); meta.setLore(lore); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 651efb6..b6550dc 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -10,4 +10,15 @@ menu: tagSearch: "&c&lHeadDB &8- &eTag Search: %search%" search: "&c&lHeadDB &8- &eSearch: %search%" favorites: "&c&lHeadDB &8- &eFavorites: %player%" - local: "&c&lHeadDB &8- &aLocal Heads &7(%size%)" \ No newline at end of file + local: "&c&lHeadDB &8- &aLocal Heads &7(%size%)" + heads: + alphabet: "&e&lALPHABET" + animals: "&3&lANIMALS" + blocks: "&8&lBLOCKS" + decoration: "&6&lDECORATION" + food-drinks: "&6&lFOOD-DRINKS" + humans: "&1&lHUMANS" + humanoid: "&b&lHUMANOID" + miscellaneous: "&2&lMISCELLANEOUS" + monsters: "&c&lMONSTERS" + plants: "&a&lPLANTS" \ No newline at end of file From 9201d497f7863802aea5c84db238433e743b1d78 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 16:38:18 -0800 Subject: [PATCH 3/6] Localized lore --- src/main/java/tsp/headdb/inventory/InventoryUtils.java | 2 +- src/main/resources/messages.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index 72bec9a..233cb04 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -183,7 +183,7 @@ public class InventoryUtils { ItemMeta meta = item.getItemMeta(); meta.setDisplayName(Utils.colorize(localization.getMessage("menu.heads." + category.getName()))); List lore = new ArrayList<>(); - lore.add(Utils.colorize("&e" + HeadAPI.getHeads(category).size() + " heads")); + lore.add(Utils.colorize(localization.getMessage("menu.lore").replace("%size%", String.valueOf(HeadAPI.getHeads(category).size())))); meta.setLore(lore); item.setItemMeta(meta); inventory.setItem(getUILocation(category.getName(), category.getLocation()), item); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index b6550dc..6507fb0 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -11,6 +11,7 @@ menu: search: "&c&lHeadDB &8- &eSearch: %search%" favorites: "&c&lHeadDB &8- &eFavorites: %player%" local: "&c&lHeadDB &8- &aLocal Heads &7(%size%)" + lore: "&e%size% heads" heads: alphabet: "&e&lALPHABET" animals: "&3&lANIMALS" From ba556ec94203b3a085e915f428e92ca696575b47 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 18:04:59 -0800 Subject: [PATCH 4/6] Addressed requested changes --- src/main/java/tsp/headdb/inventory/InventoryUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index 233cb04..14fcc94 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -183,7 +183,7 @@ public class InventoryUtils { ItemMeta meta = item.getItemMeta(); meta.setDisplayName(Utils.colorize(localization.getMessage("menu.heads." + category.getName()))); List lore = new ArrayList<>(); - lore.add(Utils.colorize(localization.getMessage("menu.lore").replace("%size%", String.valueOf(HeadAPI.getHeads(category).size())))); + lore.add(Utils.colorize(replace(localization.getMessage("menu.lore"), HeadAPI.getHeads(category).size(), "Main", "None", player))); meta.setLore(lore); item.setItemMeta(meta); inventory.setItem(getUILocation(category.getName(), category.getLocation()), item); From 04d5f2843158fb793ea8c4011f456cce17c491f4 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 18:30:18 -0800 Subject: [PATCH 5/6] Localize some economy messages --- src/main/java/tsp/headdb/inventory/InventoryUtils.java | 8 ++++---- src/main/resources/messages.yml | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index 14fcc94..329f75b 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -312,7 +312,7 @@ public class InventoryUtils { // If economy is disabled or no plugin is present, the item is free. // Don't mention receiving it for free in this case, since it is always free. if (economy == null) { - Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s&7!", amount, description)); + Utils.sendMessage(player, String.format(localization.getMessage("noEconomy"), amount, description)); Utils.playSound(player, "noEconomy"); return true; } @@ -323,17 +323,17 @@ public class InventoryUtils { if (cost > 0) { if (economy.has(player, cost)) { economy.withdrawPlayer(player, cost); - Utils.sendMessage(player, String.format("&7You purchased &e%d &7x &e%s &7for &e%.2f&7!", amount, description, cost)); + Utils.sendMessage(player, String.format(localization.getMessage("purchasedHead"), amount, description, cost)); Utils.playSound(player, "paid"); return true; } - Utils.sendMessage(player, String.format("&cYou do not have enough to purchase &e%d &cx &e%s&7.", amount, description)); + Utils.sendMessage(player, String.format(localization.getMessage("notEnoughMoney"), amount, description)); Utils.playSound(player, "unavailable"); return false; } // Otherwise, the item is free. - Utils.sendMessage(player, String.format("&7You received &e%d &7x &e%s &7for &efree&7!", amount, description)); + Utils.sendMessage(player, String.format(localization.getMessage("free"), amount, description)); Utils.playSound(player, "free"); return true; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 6fe1394..5068574 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -3,6 +3,10 @@ onlyPlayers: "&cOnly players may open the database." databaseOpen: "&7Opening &cHead Database" invalidPlayer: "&cPlayer is not online!" localFavorites: "&cLocal heads can not be added to favorites!" +noEconomy: "&7You received &e%d &7x &e%s&7!" +purchasedHead: "&7You purchased &e%d &7x &e%s &7for &e%.2f&7!" +notEnoughMoney: "&cYou do not have enough to purchase &e%d &cx &e%s&7." +free: "&7You received &e%d &7x &e%s &7for &efree&7!" menu: main: "&c&lHeadDB &7(%size%)" From 2f4fddbb6923c0a51a488f9ad802683f2a294253 Mon Sep 17 00:00:00 2001 From: Altruiis <71913030+Altruiis@users.noreply.github.com> Date: Wed, 16 Feb 2022 18:41:13 -0800 Subject: [PATCH 6/6] Localized reload message + added permission check --- src/main/java/tsp/headdb/command/CommandHeadDB.java | 6 +++++- src/main/resources/messages.yml | 1 + src/main/resources/plugin.yml | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/tsp/headdb/command/CommandHeadDB.java b/src/main/java/tsp/headdb/command/CommandHeadDB.java index 2d779f8..43f70e7 100644 --- a/src/main/java/tsp/headdb/command/CommandHeadDB.java +++ b/src/main/java/tsp/headdb/command/CommandHeadDB.java @@ -46,8 +46,12 @@ public class CommandHeadDB implements CommandExecutor { } if (sub.equalsIgnoreCase("reload") || sub.equalsIgnoreCase("r")) { + if (!sender.hasPermission("headdb.reload")) { + Utils.sendMessage(sender, localization.getMessage("noPermission")); + return true; + } HeadDB.getInstance().getLocalization().load(); - Utils.sendMessage(sender, "&aReloaded messages file!"); + Utils.sendMessage(sender, localization.getMessage("reloadMessages")); return true; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 5068574..6838218 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -7,6 +7,7 @@ noEconomy: "&7You received &e%d &7x &e%s&7!" purchasedHead: "&7You purchased &e%d &7x &e%s &7for &e%.2f&7!" notEnoughMoney: "&cYou do not have enough to purchase &e%d &cx &e%s&7." free: "&7You received &e%d &7x &e%s &7for &efree&7!" +reloadMessages: "&aReloaded messages file!" menu: main: "&c&lHeadDB &7(%size%)" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0a40ed8..1b602f4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -24,6 +24,7 @@ permissions: headdb.local: true headdb.tagsearch: true headdb.update: true + headdb.reload: true headdb.open: default: op headdb.search: @@ -37,4 +38,6 @@ permissions: headdb.tagsearch: default: op headdb.update: + default: op + headdb.reload: default: op \ No newline at end of file