Added proper placeholders and integrated prefix.

This commit is contained in:
Brianna 2019-07-17 23:24:07 -04:00
parent afddbca954
commit 2ad3d6b72e
15 changed files with 173 additions and 115 deletions

View File

@ -27,6 +27,7 @@ import com.songoda.epicfurnaces.utils.ConfigWrapper;
import com.songoda.epicfurnaces.utils.Methods;
import com.songoda.epicfurnaces.utils.Metrics;
import com.songoda.epicfurnaces.utils.ServerVersion;
import com.songoda.epicfurnaces.utils.locale.Locale;
import com.songoda.epicfurnaces.utils.settings.Setting;
import com.songoda.epicfurnaces.utils.settings.SettingsManager;
import com.songoda.epicfurnaces.utils.updateModules.LocaleModule;
@ -50,7 +51,6 @@ import java.util.UUID;
public class EpicFurnaces extends JavaPlugin {
private static CommandSender console = Bukkit.getConsoleSender();
private static EpicFurnaces INSTANCE;
private References references = null;
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
@ -121,7 +121,6 @@ public class EpicFurnaces extends JavaPlugin {
loadFromFile();
setupRecipies();
references = new References();
// Start Tasks
FurnaceTask.startTask(this);
@ -266,7 +265,6 @@ public class EpicFurnaces extends JavaPlugin {
this.locale.reloadMessages();
this.settingsManager.reloadConfig();
this.blacklistHandler.reload();
references = new References();
}
private void loadDataFile() {
@ -357,10 +355,6 @@ public class EpicFurnaces extends JavaPlugin {
return blacklistHandler;
}
public References getReferences() {
return references;
}
public FurnaceManager getFurnaceManager() {
return furnaceManager;
}

View File

@ -1,14 +0,0 @@
package com.songoda.epicfurnaces;
public class References {
private String prefix;
public References() {
prefix = EpicFurnaces.getInstance().getLocale().getMessage("general.nametag.prefix") + " ";
}
public String getPrefix() {
return this.prefix;
}
}

View File

@ -2,7 +2,6 @@ package com.songoda.epicfurnaces.command;
import com.songoda.epicfurnaces.EpicFurnaces;
import com.songoda.epicfurnaces.command.commands.*;
import com.songoda.epicfurnaces.utils.Methods;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -53,7 +52,7 @@ public class CommandManager implements CommandExecutor {
}
}
}
commandSender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly."));
plugin.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender);
return true;
}
@ -65,12 +64,12 @@ public class CommandManager implements CommandExecutor {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
AbstractCommand.ReturnType returnType = command.runCommand(plugin, sender, strings);
if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) {
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!"));
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7."));
plugin.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender);
plugin.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender);
}
return;
}
sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
plugin.getLocale().newMessage("event.general.nopermission").sendPrefixedMessage(sender);
}
public List<AbstractCommand> getCommands() {

View File

@ -22,10 +22,10 @@ public class CommandBoost extends AbstractCommand {
return ReturnType.SYNTAX_ERROR;
}
if (Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&cThat player does not exist..."));
plugin.getLocale().newMessage("&cThat player does not exist...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (!Methods.isInt(args[2])) {
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number..."));
plugin.getLocale().newMessage("&6" + args[2] + " &7is not a number...").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else {
Calendar c = Calendar.getInstance();
@ -52,7 +52,7 @@ public class CommandBoost extends AbstractCommand {
c.add(Calendar.YEAR, Integer.parseInt(arr2[1]));
time = " &7for &6" + arr2[1] + " years&7.";
} else {
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid."));
plugin.getLocale().newMessage("&7" + args[3] + " &7is invalid.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}
} else {
@ -61,7 +61,8 @@ public class CommandBoost extends AbstractCommand {
BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId());
plugin.getBoostManager().addBoostToPlayer(boostData);
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7furnaces reward amounts by &6" + args[2] + "x" + time));
plugin.getLocale().newMessage("&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName()
+ "'s &7furnaces reward amounts by &6" + args[2] + "x" + time).sendPrefixedMessage(sender);
}
return ReturnType.FAILURE;
}

View File

@ -14,7 +14,8 @@ public class CommandEpicFurnaces extends AbstractCommand {
@Override
protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) {
sender.sendMessage("");
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
plugin.getLocale().newMessage("&7Version " + plugin.getDescription().getVersion()
+ " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender);
for (AbstractCommand command : plugin.getCommandManager().getCommands()) {
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {

View File

@ -22,11 +22,11 @@ public class CommandGive extends AbstractCommand {
Level level = plugin.getLevelManager().getLowestLevel();
Player player;
if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) {
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline."));
plugin.getLocale().newMessage("&cThat player does not exist or is currently offline.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (args.length == 1) {
if (!(sender instanceof Player)) {
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cYou need to be a player to give a farm item to yourself."));
plugin.getLocale().newMessage("&cYou need to be a player to give a farm item to yourself.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
player = (Player) sender;
@ -36,14 +36,17 @@ public class CommandGive extends AbstractCommand {
if (args.length >= 3 && !plugin.getLevelManager().isLevel(Integer.parseInt(args[2]))) {
sender.sendMessage(plugin.getReferences().getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + plugin.getLevelManager().getLowestLevel().getLevel() + "-" + plugin.getLevelManager().getHighestLevel().getLevel() + "&c."));
plugin.getLocale().newMessage("&cNot a valid level... The current valid levels are: &4"
+ plugin.getLevelManager().getLowestLevel().getLevel() + "-"
+ plugin.getLevelManager().getHighestLevel().getLevel() + "&c.").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
} else if (args.length != 1) {
level = plugin.getLevelManager().getLevel(Integer.parseInt(args[2]));
}
player.getInventory().addItem(plugin.createLeveledFurnace(Material.FURNACE, level.getLevel(), 0));
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("command.give.success", level.getLevel()));
plugin.getLocale().getMessage("command.give.success")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand {
@Override
protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) {
plugin.reload();
sender.sendMessage(Methods.formatText(plugin.getReferences().getPrefix() + "&7Configuration and Language files reloaded."));
plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS;
}

View File

@ -19,7 +19,7 @@ public class CommandRemote extends AbstractCommand {
protected ReturnType runCommand(EpicFurnaces plugin, CommandSender sender, String... args) {
if (!plugin.getConfig().getBoolean("Main.Access Furnaces Remotely") || !sender.hasPermission("EpicFurnaces.Remote")) {
sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}
if (!plugin.getDataFile().getConfig().contains("data.charged")) {
@ -36,7 +36,7 @@ public class CommandRemote extends AbstractCommand {
if (furnace.getNickname() == null) continue;
if (!furnace.getNickname().equalsIgnoreCase(name.toString())) {
sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
continue;
}
for (UUID uuid : furnace.getAccessList()) {
@ -50,7 +50,7 @@ public class CommandRemote extends AbstractCommand {
}
}
sender.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.notfound"));
plugin.getLocale().getMessage("event.remote.notfound").sendPrefixedMessage(sender);
return ReturnType.FAILURE;
}

View File

@ -120,7 +120,8 @@ public class Furnace {
return;
}
if (!plugin.getEconomy().hasBalance(player, cost)) {
player.sendMessage(plugin.getReferences().getPrefix() + EpicFurnaces.getInstance().getLocale().getMessage("event.upgrade.cannotafford"));
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
return;
}
plugin.getEconomy().withdrawBalance(player, cost);
@ -132,7 +133,7 @@ public class Furnace {
}
upgradeFinal(level, player);
} else {
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.upgrade.cannotafford"));
plugin.getLocale().getMessage("event.upgrade.cannotafford").sendPrefixedMessage(player);
}
}
}
@ -142,9 +143,12 @@ public class Furnace {
this.level = level;
syncName();
if (plugin.getLevelManager().getHighestLevel() != level) {
player.sendMessage(plugin.getLocale().getMessage("event.upgrade.success", level.getLevel()));
plugin.getLocale().getMessage("event.upgrade.success")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
} else {
player.sendMessage(plugin.getLocale().getMessage("event.upgrade.maxed", level.getLevel()));
plugin.getLocale().getMessage("event.upgrade.maxed")
.processPlaceholder("level", level.getLevel()).sendPrefixedMessage(player);
}
Location loc = location.clone().add(.5, .5, .5);

View File

@ -26,19 +26,24 @@ public class Level {
EpicFurnaces plugin = EpicFurnaces.getInstance();
if (performance != 0)
description.add(plugin.getLocale().getMessage("interface.furnace.performance", performance + "%"));
description.add(plugin.getLocale().getMessage("interface.furnace.performance")
.processPlaceholder("amount", performance + "%").getMessage());
if (reward != null)
description.add(plugin.getLocale().getMessage("interface.furnace.reward", reward.split("%:")[0] + "%"));
description.add(plugin.getLocale().getMessage("interface.furnace.reward")
.processPlaceholder("amount", reward.split("%:")[0] + "%").getMessage());
if (fuelDuration != 0)
description.add(plugin.getLocale().getMessage("interface.furnace.fuelduration", fuelDuration + "%"));
description.add(plugin.getLocale().getMessage("interface.furnace.fuelduration")
.processPlaceholder("amount", fuelDuration + "%").getMessage());
if (fuelShare != 0)
description.add(plugin.getLocale().getMessage("interface.furnace.fuelshare", fuelShare));
description.add(plugin.getLocale().getMessage("interface.furnace.fuelshare")
.processPlaceholder("amount", fuelShare).getMessage());
if (overheat != 0)
description.add(plugin.getLocale().getMessage("interface.furnace.overheat", overheat));
description.add(plugin.getLocale().getMessage("interface.furnace.overheat")
.processPlaceholder("amount", overheat).getMessage());
}

View File

@ -52,25 +52,35 @@ public class GUIOverview extends AbstractGUI {
ItemStack item = new ItemStack(Material.FURNACE, 1);
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.currentlevel", level.getLevel()));
itemmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.currentlevel")
.processPlaceholder("level", level.getLevel()).getMessage());
ArrayList<String> lore = new ArrayList<>();
lore.add(plugin.getLocale().getMessage("interface.furnace.smeltedx", furnace.getUses()));
lore.add(plugin.getLocale().getMessage("interface.furnace.smeltedx")
.processPlaceholder("amount", furnace.getUses()).getMessage());
lore.addAll(level.getDescription());
lore.add("");
if (nextLevel == null)
lore.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed"));
lore.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed").getMessage());
else {
lore.add(plugin.getLocale().getMessage("interface.furnace.level", nextLevel.getLevel()));
lore.add(plugin.getLocale().getMessage("interface.furnace.level")
.processPlaceholder("level", nextLevel.getLevel()).getMessage());
lore.addAll(nextLevel.getDescription());
if (plugin.getConfig().getBoolean("Main.Upgrade By Smelting Materials")) {
lore.add(plugin.getLocale().getMessage("interface.furnace.tolevel", needed, Methods.cleanString(plugin.getConfig().getString("Main.Furnace Upgrade Cost"))));
lore.add(plugin.getLocale().getMessage("interface.furnace.tolevel")
.processPlaceholder("amount", needed)
.processPlaceholder("type",
Methods.cleanString(plugin.getConfig().getString("Main.Furnace Upgrade Cost")))
.getMessage());
}
}
BoostData boostData = plugin.getBoostManager().getBoost(furnace.getPlacedBy());
if (boostData != null) {
String[] parts = plugin.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|");
String[] parts = plugin.getLocale().getMessage("interface.button.boostedstats")
.processPlaceholder("amount", Integer.toString(boostData.getMultiplier()))
.processPlaceholder("time", Methods.makeReadable(boostData.getEndTime()
- System.currentTimeMillis())).getMessage().split("\\|");
lore.add("");
for (String line : parts)
lore.add(Methods.formatText(line));
@ -88,10 +98,11 @@ public class GUIOverview extends AbstractGUI {
ItemStack item2 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Performance Icon")), 1);
ItemMeta itemmeta2 = item2.getItemMeta();
itemmeta2.setDisplayName(plugin.getLocale().getMessage("interface.furnace.performancetitle")); //greyed out until available
itemmeta2.setDisplayName(plugin.getLocale().getMessage("interface.furnace.performancetitle").getMessage()); //greyed out until available
ArrayList<String> lore2 = new ArrayList<>();
String[] parts = plugin.getLocale().getMessage("interface.furnace.performanceinfo", level.getPerformance()).split("\\|");
String[] parts = plugin.getLocale().getMessage("interface.furnace.performanceinfo")
.processPlaceholder("amount", level.getPerformance()).getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore2.add(Methods.formatText(line));
@ -101,10 +112,12 @@ public class GUIOverview extends AbstractGUI {
ItemStack item3 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Reward Icon")), 1);
ItemMeta itemmeta3 = item3.getItemMeta();
itemmeta3.setDisplayName(plugin.getLocale().getMessage("interface.furnace.rewardtitle"));
itemmeta3.setDisplayName(plugin.getLocale().getMessage("interface.furnace.rewardtitle").getMessage());
ArrayList<String> lore3 = new ArrayList<>();
parts = plugin.getLocale().getMessage("interface.furnace.rewardinfo", level.getReward().split(":")[0].replace("%", "")).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.rewardinfo")
.processPlaceholder("amount", level.getReward().split(":")[0].replace("%", ""))
.getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore3.add(Methods.formatText(line));
@ -115,10 +128,11 @@ public class GUIOverview extends AbstractGUI {
ItemStack item4 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.FuelDuration Icon")), 1);
ItemMeta itemmeta4 = item4.getItemMeta();
itemmeta4.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fueldurationtitle"));
itemmeta4.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fueldurationtitle").getMessage());
ArrayList<String> lore4 = new ArrayList<>();
parts = plugin.getLocale().getMessage("interface.furnace.fueldurationinfo", level.getFuelDuration()).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.fueldurationinfo")
.processPlaceholder("amount", level.getFuelDuration()).getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore4.add(Methods.formatText(line));
@ -128,10 +142,13 @@ public class GUIOverview extends AbstractGUI {
ItemStack item5 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Overheat Icon")), 1);
ItemMeta itemmeta5 = item4.getItemMeta();
itemmeta5.setDisplayName(plugin.getLocale().getMessage("interface.furnace.overheattitle"));
itemmeta5.setDisplayName(plugin.getLocale().getMessage("interface.furnace.overheattitle").getMessage());
ArrayList<String> lore5 = new ArrayList<>();
parts = plugin.getLocale().getMessage("interface.furnace.overheatinfo", level.getOverheat() * 3).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.overheatinfo")
.processPlaceholder("amount", level.getOverheat() * 3)
.getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore5.add(Methods.formatText(line));
@ -141,10 +158,11 @@ public class GUIOverview extends AbstractGUI {
ItemStack item6 = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.FuelShare Icon")), 1);
ItemMeta itemmeta6 = item4.getItemMeta();
itemmeta6.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fuelsharetitle"));
itemmeta6.setDisplayName(plugin.getLocale().getMessage("interface.furnace.fuelsharetitle").getMessage());
ArrayList<String> lore6 = new ArrayList<>();
parts = plugin.getLocale().getMessage("interface.furnace.fuelshareinfo", level.getOverheat() * 3).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.fuelshareinfo")
.processPlaceholder("amount", level.getOverheat() * 3).getMessage().split("\\|");
lore.add("");
for (String line : parts) {
lore6.add(Methods.formatText(line));
@ -154,23 +172,26 @@ public class GUIOverview extends AbstractGUI {
ItemStack itemXP = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.XP Icon")), 1);
ItemMeta itemmetaXP = itemXP.getItemMeta();
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewithxp"));
itemmetaXP.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewithxp").getMessage());
ArrayList<String> loreXP = new ArrayList<>();
if (nextLevel != null)
loreXP.add(plugin.getLocale().getMessage("interface.furnace.upgradewithxplore", nextLevel.getCostExperience()));
loreXP.add(plugin.getLocale().getMessage("interface.furnace.upgradewithxplore")
.processPlaceholder("cost", nextLevel.getCostExperience()).getMessage());
else
loreXP.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed"));
loreXP.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed").getMessage());
itemmetaXP.setLore(loreXP);
itemXP.setItemMeta(itemmetaXP);
ItemStack itemECO = new ItemStack(Material.valueOf(plugin.getConfig().getString("Interfaces.Economy Icon")), 1);
ItemMeta itemmetaECO = itemECO.getItemMeta();
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomy"));
itemmetaECO.setDisplayName(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomy").getMessage());
ArrayList<String> loreECO = new ArrayList<>();
if (nextLevel != null)
loreECO.add(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy())));
loreECO.add(plugin.getLocale().getMessage("interface.furnace.upgradewitheconomylore")
.processPlaceholder("cost", Methods.formatEconomy(nextLevel.getCostEconomy()))
.getMessage());
else
loreECO.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed"));
loreECO.add(plugin.getLocale().getMessage("interface.furnace.alreadymaxed").getMessage());
itemmetaECO.setLore(loreECO);
itemECO.setItemMeta(itemmetaECO);
@ -249,25 +270,27 @@ public class GUIOverview extends AbstractGUI {
ItemStack hook = new ItemStack(Material.TRIPWIRE_HOOK, 1);
ItemMeta hookmeta = hook.getItemMeta();
hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.remotefurnace"));
hookmeta.setDisplayName(plugin.getLocale().getMessage("interface.furnace.remotefurnace").getMessage());
ArrayList<String> lorehook = new ArrayList<>();
String nickname = furnace.getNickname();
parts = plugin.getLocale().getMessage("interface.furnace.remotefurnacelore", nickname == null ? "Unset" : nickname).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.remotefurnacelore")
.processPlaceholder("nickname", nickname == null ? "Unset" : nickname).getMessage().split("\\|");
for (String line : parts) {
lorehook.add(Methods.formatText(line));
}
if (nickname != null) {
parts = plugin.getLocale().getMessage("interface.furnace.utilize", nickname).split("\\|");
parts = plugin.getLocale().getMessage("interface.furnace.utilize")
.processPlaceholder("nickname", nickname).getMessage().split("\\|");
for (String line : parts) {
lorehook.add(Methods.formatText(line));
}
}
lorehook.add("");
lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist"));
lorehook.add(plugin.getLocale().getMessage("interface.furnace.remotelist").getMessage());
for (String line : furnace.getRawAccessList()) {
String[] halfs = line.split(":");
String name = halfs[1];
@ -293,13 +316,13 @@ public class GUIOverview extends AbstractGUI {
}
if (other.getNickname().equalsIgnoreCase(anvilEvent.getName())) {
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.nicknameinuse"));
plugin.getLocale().getMessage("event.remote.nicknameinuse").sendPrefixedMessage(player);
return;
}
}
furnace.setNickname(anvilEvent.getName());
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.nicknamesuccess"));
plugin.getLocale().getMessage("event.remote.nicknamesuccess").sendPrefixedMessage(player);
});
gui.setOnClose((player2, inventory2) -> init(setTitle, inventory.getSize()));
@ -311,7 +334,7 @@ public class GUIOverview extends AbstractGUI {
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, itemO);
gui.open();
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.remote.enter"));
plugin.getLocale().getMessage("event.remote.enter").sendPrefixedMessage(player);
} else if (type == ClickType.RIGHT) {

View File

@ -83,7 +83,7 @@ public abstract class Hologram {
String progress = Methods.formatText(sb.toString());
if (furnaceBlock.getInventory().getFuel() == null) {
progress = plugin.getLocale().getMessage("general.hologram.outoffuel");
progress = plugin.getLocale().getMessage("general.hologram.outoffuel").getMessage();
}
int inAmt = 0;
@ -95,7 +95,10 @@ public abstract class Hologram {
outAmt = furnaceBlock.getInventory().getResult().getAmount();
}
String stats = plugin.getLocale().getMessage("general.hologram.stats", inAmt, outAmt > 64 ? 64 : outAmt);
String stats = plugin.getLocale().getMessage("general.hologram.stats")
.processPlaceholder("in", inAmt)
.processPlaceholder("out", outAmt > 64 ? 64 : outAmt).getMessage();
lines.add(progress);
lines.add(stats);

View File

@ -56,7 +56,9 @@ public class Methods {
}
public static String formatName(int level, int uses, boolean full) {
String name = EpicFurnaces.getInstance().getLocale().getMessage("general.nametag.nameformat", level);
String name = EpicFurnaces.getInstance().getLocale().getMessage("general.nametag.nameformat")
.processPlaceholder("level", level).getMessage();
String info = "";
if (full) {

View File

@ -1,6 +1,5 @@
package com.songoda.epicfurnaces;
package com.songoda.epicfurnaces.utils.locale;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
@ -168,7 +167,6 @@ public class Locale {
}
}
public boolean reloadMessages() {
if (!this.file.exists()) {
plugin.getLogger().warning("Could not find file for locale \"" + this.name + "\"");
@ -188,7 +186,7 @@ public class Locale {
continue;
}
nodes.put(matcher.group(1), matcher.group(2));
nodes.put(matcher.group(1),matcher.group(2));
}
} catch (IOException e) {
e.printStackTrace();
@ -197,44 +195,24 @@ public class Locale {
return true;
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @return the message for the specified node
*/
public String getMessage(String node) {
return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node));
private Message applyPrefix(Message message) {
return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]"));
}
/**
* Get a message set for a specific node and replace its params with a supplied arguments.
*
* @param node the node to get
* @param args the replacement arguments
* @return the message for the specified node
*/
public String getMessage(String node, Object... args) {
String message = getMessage(node);
for (Object arg : args) {
message = message.replaceFirst("\\%.*?\\%", arg.toString());
}
return message;
public Message newMessage(String message) {
return applyPrefix(new Message(message));
}
/**
* Get a message set for a specific node
*
* @param node the node to get
* @param defaultValue the default value given that a value for the node was not found
* @return the message for the specified node. Default if none found
*/
public String getMessageOrDefault(String node, String defaultValue) {
return this.nodes.getOrDefault(node, defaultValue);
public Message getMessage(String node) {
return this.getMessageOrDefault(node, node);
}
public Message getMessageOrDefault(String node, String defaultValue) {
return applyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue)));
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,59 @@
package com.songoda.epicfurnaces.utils.locale;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Message {
private String prefix = null;
private String message;
Message(String message) {
this.message = message;
}
public void sendMessage(Player player) {
player.sendMessage(this.getMessage());
}
public void sendPrefixedMessage(Player player) {
player.sendMessage(this.getPrefixedMessage());
}
public void sendMessage(CommandSender sender) {
sender.sendMessage(this.getMessage());
}
public void sendPrefixedMessage(CommandSender sender) {
sender.sendMessage(this.getPrefixedMessage());
}
public String getPrefixedMessage() {
return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix)
+ " " + this.message);
}
public String getMessage() {
return ChatColor.translateAlternateColorCodes('&', this.message);
}
public String getUnformattedMessage() {
return this.message;
}
public Message processPlaceholder(String placeholder, Object replacement) {
this.message = message.replace("%" + placeholder + "%", replacement.toString());
return this;
}
Message setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String toString() {
return this.message;
}
}