From dc855411078e3091f398a32bc8e286a2cf6d4d73 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 25 Aug 2020 16:13:19 +0300 Subject: [PATCH] Lets support Hex color codes in titles --- .../gamingmesh/jobs/CMILib/CMIChatColor.java | 1 - .../jobs/commands/JobsCommands.java | 6 +- .../gamingmesh/jobs/commands/list/bonus.java | 4 +- .../gamingmesh/jobs/commands/list/browse.java | 4 +- .../gamingmesh/jobs/commands/list/demote.java | 4 +- .../jobs/commands/list/edititembonus.java | 8 +- .../jobs/commands/list/editquests.java | 948 +++++++++--------- .../jobs/commands/list/itembonus.java | 8 +- .../gamingmesh/jobs/commands/list/limit.java | 4 +- .../gamingmesh/jobs/config/ConfigManager.java | 77 +- .../gamingmesh/jobs/config/TitleManager.java | 29 +- .../com/gamingmesh/jobs/container/Job.java | 8 +- .../gamingmesh/jobs/container/JobsPlayer.java | 18 +- .../com/gamingmesh/jobs/stuff/ChatColor.java | 89 -- 14 files changed, 557 insertions(+), 651 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/stuff/ChatColor.java diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIChatColor.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIChatColor.java index 8eb4d6c7..1698dc7c 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIChatColor.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIChatColor.java @@ -522,7 +522,6 @@ public class CMIChatColor { if (or.contains(colorCodePrefix)) { Matcher match = hexColorRegexPatternLast.matcher(or); if (match.find()) { - return new CMIChatColor(match.group(2)); } match = hexColorNamePatternLast.matcher(or); diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 244277ba..35130131 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -25,6 +25,7 @@ import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.Title; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.PageInfo; import com.gamingmesh.jobs.stuff.Sorting; import com.gamingmesh.jobs.stuff.Util; @@ -81,7 +82,7 @@ public class JobsCommands implements CommandExecutor { if (!hasCommandPermission(sender, cmd)) { if (sender instanceof Player) { new RawMessage().addText(Jobs.getLanguage().getMessage("general.error.permission")) - .addHover("&2" + label + ".command." + cmd).show(sender); + .addHover("&2" + label + ".command." + cmd).show(sender); } else sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); return true; @@ -198,8 +199,7 @@ public class JobsCommands implements CommandExecutor { break; } } - - + } private static Class getClass(String cmd) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java index 9d9a0203..d13f4c9d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/bonus.java @@ -4,6 +4,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.PlayerManager.BoostOf; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.RawMessage; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; @@ -12,7 +13,6 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.hooks.HookManager; -import com.gamingmesh.jobs.stuff.ChatColor; public class bonus implements Cmd { @@ -75,7 +75,7 @@ public class bonus implements Cmd { } private static void printBoost(CommandSender sender, Boost boost, BoostOf type) { - String prefix = ChatColor.GOLD + "*"; + String prefix = CMIChatColor.GOLD + "*"; if (type != BoostOf.NearSpawner && type != BoostOf.PetPay) prefix = ""; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java index 2f2b3608..87ad0f74 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/browse.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/browse.java @@ -7,11 +7,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.RawMessage; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.PageInfo; public class browse implements Cmd { @@ -201,7 +201,7 @@ public class browse implements Cmd { builder.append(job.getChatColor().toString()); builder.append(job.getName()); if (job.getMaxLevel(sender) > 0) { - builder.append(ChatColor.WHITE.toString()); + builder.append(CMIChatColor.WHITE.toString()); builder.append(Jobs.getLanguage().getMessage("command.info.help.max")); builder.append(job.getMaxLevel(sender)); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java index c3853d64..a702fcb1 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/demote.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/demote.java @@ -5,11 +5,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.ChatColor; public class demote implements Cmd { @@ -42,7 +42,7 @@ public class demote implements Cmd { Player player = Bukkit.getServer().getPlayer(jPlayer.getUniqueId()); if (player != null) { String message = Jobs.getLanguage().getMessage("command.demote.output.target", - "%jobname%", job.getNameWithColor() + ChatColor.WHITE, + "%jobname%", job.getNameWithColor() + CMIChatColor.WHITE, "%levelslost%", levelsLost); player.sendMessage(message); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java index 603f4b79..824a326c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIReflections; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; @@ -15,7 +16,6 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.ChatColor; public class edititembonus implements Cmd { @@ -103,9 +103,9 @@ public class edititembonus implements Cmd { BoostMultiplier boost = item.getBoost(); - String mc = ChatColor.DARK_GREEN.toString(), - pc = ChatColor.GOLD.toString(), - ec = ChatColor.YELLOW.toString(); + String mc = CMIChatColor.DARK_GREEN.toString(), + pc = CMIChatColor.GOLD.toString(), + ec = CMIChatColor.YELLOW.toString(); for (Job one : item.getJobs()) { String msg = Jobs.getLanguage().getMessage("command.itembonus.output.list", diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java index ff0e7689..41d3b877 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java @@ -13,6 +13,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIEntityType; import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.ItemReflection; @@ -25,7 +26,6 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.Quest; import com.gamingmesh.jobs.container.QuestObjective; -import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.PageInfo; import com.gamingmesh.jobs.stuff.Util; @@ -38,130 +38,62 @@ public class editquests implements Cmd { if (!(sender instanceof Player)) return false; - Player player = (Player) sender; + Player player = (Player) sender; - if (args.length == 0) { - args = new String[] { "list" }; + if (args.length == 0) { + args = new String[] { "list" }; + } + + switch (args[0]) { + case "list": + if (args.length == 1) { + showPath(player, null, null, null, null); + + for (Job one : Jobs.getJobs()) { + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.jobs", "%jobname%", one.getNameWithColor()), + one.getName(), "jobs editquests list " + one.getName()); + rm.show(sender); + } + + Util.getQuestsEditorMap().remove(player.getUniqueId()); + return true; } - switch (args[0]) { - case "list": - if (args.length == 1) { - showPath(player, null, null, null, null); + if (args.length == 2) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; - for (Job one : Jobs.getJobs()) { - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.jobs", "%jobname%", one.getNameWithColor()), - one.getName(), "jobs editquests list " + one.getName()); - rm.show(sender); - } + showPath(player, job, null, null, null); - Util.getQuestsEditorMap().remove(player.getUniqueId()); - return true; - } + for (ActionType oneI : ActionType.values()) { + List action = job.getJobInfo(oneI); + if (action == null || action.isEmpty()) + continue; - if (args.length == 2) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - showPath(player, job, null, null, null); - - for (ActionType oneI : ActionType.values()) { - List action = job.getJobInfo(oneI); - if (action == null || action.isEmpty()) - continue; - - RawMessage rm = new RawMessage(); - for (Quest one : job.getQuests()) { - if (one.getJob().isSame(job)) { - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.actions", "%actionname%", oneI.getName()), - oneI.getName(), "jobs editquests list " + job.getName() + " " + oneI.getName() + " " + one.getConfigName() + " 1"); - rm.show(sender); - } - } - } - - Util.getQuestsEditorMap().remove(player.getUniqueId()); - return true; - } - - if (args.length == 5) { - Integer page = null; - try { - page = Integer.parseInt(args[4]); - } catch (NumberFormatException e) { - } - - if (page != null) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - showPath(player, job, actionT, null, null); - - Quest quest = job.getQuest(args[3]); - if (quest == null) { - return false; - } - - HashMap obj = quest.getObjectives().get(actionT); - - if (obj == null || obj.isEmpty()) - return false; - - QuestObjective o = null; - PageInfo pi = new PageInfo(15, obj.size(), page); - - for (Entry one : obj.entrySet()) { - if (!pi.isEntryOk()) - continue; - - o = one.getValue(); - - if (o != null && !o.getAction().equals(actionT)) - continue; - - String target = o == null ? "STONE" : o.getTargetName(); - - String objName = target.toLowerCase().replace('_', ' '); - objName = Character.toUpperCase(objName.charAt(0)) + objName.substring(1); - if (o != null) - objName = Jobs.getNameTranslatorManager().Translate(objName, o.getAction(), o.getTargetId(), - o.getTargetMeta(), target); - objName = org.bukkit.ChatColor.translateAlternateColorCodes('&', objName); - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectives", "%objectivename%", objName), - target, "jobs editquests list " + job.getName() + " " + actionT.getName() + " " + quest.getConfigName() + " " + target); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectiveRemove"), - "&cRemove", "jobs editquests remove " + job.getName() + " " + actionT.getName() - + " " + quest.getConfigName() + " " + target); + RawMessage rm = new RawMessage(); + for (Quest one : job.getQuests()) { + if (one.getJob().isSame(job)) { + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.actions", "%actionname%", oneI.getName()), + oneI.getName(), "jobs editquests list " + job.getName() + " " + oneI.getName() + " " + one.getConfigName() + " 1"); rm.show(sender); } - - RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectiveAdd"), - "&eAdd new", "jobs editquests add " + job.getName() + " " + quest.getConfigName() - + " " + (o == null ? "Unknown" : o.getAction().getName())); - rm.show(sender); - - Util.getQuestsEditorMap().remove(player.getUniqueId()); - - Jobs.getInstance().ShowPagination(sender, pi, "jobs editquests list " + job.getName() + " " + quest.getConfigName() + " " + 0); - return true; } } - if (args.length == 4) { + Util.getQuestsEditorMap().remove(player.getUniqueId()); + return true; + } + + if (args.length == 5) { + Integer page = null; + try { + page = Integer.parseInt(args[4]); + } catch (NumberFormatException e) { + } + + if (page != null) { Job job = Jobs.getJob(args[1]); if (job == null) return false; @@ -182,273 +114,341 @@ public class editquests implements Cmd { } HashMap obj = quest.getObjectives().get(actionT); + if (obj == null || obj.isEmpty()) return false; - player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() + " " - + quest.getConfigName() + " 1"); - return true; - } - break; - case "remove": - if (args.length == 5) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; - - ActionType actionT = ActionType.getByName(args[2]); - if (actionT == null) - return false; - - List action = job.getJobInfo(actionT); - if (action == null || action.isEmpty()) - return false; - - Quest q = job.getQuest(args[3]); - if (q == null) { - return false; - } - - HashMap obj = q.getObjectives().get(actionT); - if (obj == null || obj.isEmpty()) - return false; - - String target = args[4]; - if (target == null) { - return true; - } - - org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig(); - String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + "."; - - if (file.isString(j + "Target")) { - Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), target); - Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName()); - } else if (file.isList(j + "Objectives")) { - List list = file.getStringList(j + "Objectives"); - for (String s : list) { - String[] split = s.split(";"); - if (split[1].contains(target.toLowerCase())) { - list.remove(s); - break; - } - } - - File f = Jobs.getConfigManager().getJobFile(); - file.set(j + "Objectives", list); - - try { - file.save(f); - } catch (java.io.IOException e) { - e.printStackTrace(); - } - } + QuestObjective o = null; + PageInfo pi = new PageInfo(15, obj.size(), page); for (Entry one : obj.entrySet()) { - if (one.getKey().equalsIgnoreCase(target)) { - obj.remove(one.getKey()); - break; - } - } + if (!pi.isEntryOk()) + continue; - player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() - + " " + q.getConfigName() + " 1"); + o = one.getValue(); - Util.getQuestsEditorMap().remove(player.getUniqueId()); + if (o != null && !o.getAction().equals(actionT)) + continue; - return true; - } - break; - case "add": - if (args.length >= 4 && args.length <= 5) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; + String target = o == null ? "STONE" : o.getTargetName(); - Quest q = job.getQuest(args[2]); - if (q == null) { - return true; - } + String objName = target.toLowerCase().replace('_', ' '); + objName = Character.toUpperCase(objName.charAt(0)) + objName.substring(1); + if (o != null) + objName = Jobs.getNameTranslatorManager().Translate(objName, o.getAction(), o.getTargetId(), + o.getTargetMeta(), target); + objName = org.bukkit.ChatColor.translateAlternateColorCodes('&', objName); - ActionType actionT = ActionType.getByName(args[3]); - if (actionT == null) - return false; - - int amount = 0; - if (args.length == 5) { - try { - amount = Integer.parseInt(args[4]); - } catch (NumberFormatException e) { - } - } - - if (amount < 1) { - amount = 3; + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectives", "%objectivename%", objName), + target, "jobs editquests list " + job.getName() + " " + actionT.getName() + " " + quest.getConfigName() + " " + target); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectiveRemove"), + "&cRemove", "jobs editquests remove " + job.getName() + " " + actionT.getName() + + " " + quest.getConfigName() + " " + target); + rm.show(sender); } RawMessage rm = new RawMessage(); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.enter")); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.hand"), - Jobs.getLanguage().getMessage("command.editquests.help.modify.handHover"), "jobs editquests add " + job.getName() - + " " + q.getConfigName() + " " + actionT.getName() + " hand " + amount); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.or")); - rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.look"), - Jobs.getLanguage().getMessage("command.editquests.help.modify.lookHover"), "jobs editquests add " + job.getName() - + " " + q.getConfigName() + " " + actionT.getName() + " looking " + amount); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.list.objectiveAdd"), + "&eAdd new", "jobs editquests add " + job.getName() + " " + quest.getConfigName() + + " " + (o == null ? "Unknown" : o.getAction().getName())); rm.show(sender); - Util.getQuestsEditorMap().put(player.getUniqueId(), "jobs editquests add " + job.getName() + - " " + q.getConfigName() + " " + actionT.getName() + " " + amount); + Util.getQuestsEditorMap().remove(player.getUniqueId()); + + Jobs.getInstance().ShowPagination(sender, pi, "jobs editquests list " + job.getName() + " " + quest.getConfigName() + " " + 0); + return true; + } + } + + if (args.length == 4) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + showPath(player, job, actionT, null, null); + + Quest quest = job.getQuest(args[3]); + if (quest == null) { + return false; + } + + HashMap obj = quest.getObjectives().get(actionT); + if (obj == null || obj.isEmpty()) + return false; + + player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() + " " + + quest.getConfigName() + " 1"); + return true; + } + break; + case "remove": + if (args.length == 5) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + ActionType actionT = ActionType.getByName(args[2]); + if (actionT == null) + return false; + + List action = job.getJobInfo(actionT); + if (action == null || action.isEmpty()) + return false; + + Quest q = job.getQuest(args[3]); + if (q == null) { + return false; + } + + HashMap obj = q.getObjectives().get(actionT); + if (obj == null || obj.isEmpty()) + return false; + + String target = args[4]; + if (target == null) { return true; } - if (args.length >= 5 && args.length <= 6) { - Job job = Jobs.getJob(args[1]); - if (job == null) - return false; + org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig(); + String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + "."; - Quest q = job.getQuest(args[2]); - if (q == null) { - return true; - } - - ActionType actionT = ActionType.getByName(args[3]); - if (actionT == null) { - return false; - } - - String key = args[4]; - switch (args[4]) { - case "hand": - ItemStack item = Jobs.getNms().getItemInMainHand(player); - key = item.getType().name() + "-" + item.getData().getData(); - break; - case "offhand": - item = ItemReflection.getItemInOffHand(player); - key = item.getType().name() + "-" + item.getData().getData(); - break; - case "looking": - case "lookingat": - Block block = Util.getTargetBlock(player, 30); - key = block.getType().name() + "-" + block.getData(); - break; - default: - break; - } - - String myKey = key; - String type = null; - String subType = ""; - String meta = ""; - int id = 0; - - if (myKey.contains("-")) { - // uses subType - subType = ":" + myKey.split("-")[1]; - meta = myKey.split("-")[1]; - myKey = myKey.split("-")[0]; - } - - CMIMaterial material = null; - - switch (actionT) { - case KILL: - case MILK: - case MMKILL: - case BOSS: - case BREED: - case TAME: - case SHEAR: - case EXPLORE: - case CUSTOMKILL: - break; - case TNTBREAK: - case VTRADE: - case SMELT: - case REPAIR: - case PLACE: - case EAT: - case FISH: - case ENCHANT: - case DYE: - case CRAFT: - case BAKE: - case BREW: - case BREAK: - case STRIPLOGS: - material = CMIMaterial.get(myKey + (subType)); - - if (material == null) - material = CMIMaterial.get(myKey.replace(" ", "_").toUpperCase()); - - if (material == null) { - // try integer method - Integer matId = null; - try { - matId = Integer.valueOf(myKey); - } catch (NumberFormatException e) { - } - if (matId != null) { - material = CMIMaterial.get(matId); - if (material != null) { - Jobs.getPluginLogger().warning("Job " + job.getName() + " " + actionT.getName() + " is using ID: " + key + "!"); - Jobs.getPluginLogger().warning("Please use the Material name instead: " + material.toString() + "!"); - } - } - } - break; - default: - break; - - } - - c: if (material != null && material.getMaterial() != null) { - - // Need to include thos ones and count as regular blocks - switch (key.replace("_", "").toLowerCase()) { - case "itemframe": - type = "ITEM_FRAME"; - meta = "1"; - break c; - case "painting": - type = "PAINTING"; - meta = "1"; - break c; - case "armorstand": - type = "ARMOR_STAND"; - meta = "1"; - break c; - default: + if (file.isString(j + "Target")) { + Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), target); + Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName()); + } else if (file.isList(j + "Objectives")) { + List list = file.getStringList(j + "Objectives"); + for (String s : list) { + String[] split = s.split(";"); + if (split[1].contains(target.toLowerCase())) { + list.remove(s); break; } + } - if (actionT == ActionType.BREAK || actionT == ActionType.PLACE || actionT == ActionType.STRIPLOGS) { - if (!material.isBlock()) { - player.sendMessage(ChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + material - + "(" + key + ")! Material must be a block!"); - break; + File f = Jobs.getConfigManager().getJobFile(); + file.set(j + "Objectives", list); + + try { + file.save(f); + } catch (java.io.IOException e) { + e.printStackTrace(); + } + } + + for (Entry one : obj.entrySet()) { + if (one.getKey().equalsIgnoreCase(target)) { + obj.remove(one.getKey()); + break; + } + } + + player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() + + " " + q.getConfigName() + " 1"); + + Util.getQuestsEditorMap().remove(player.getUniqueId()); + + return true; + } + break; + case "add": + if (args.length >= 4 && args.length <= 5) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + Quest q = job.getQuest(args[2]); + if (q == null) { + return true; + } + + ActionType actionT = ActionType.getByName(args[3]); + if (actionT == null) + return false; + + int amount = 0; + if (args.length == 5) { + try { + amount = Integer.parseInt(args[4]); + } catch (NumberFormatException e) { + } + } + + if (amount < 1) { + amount = 3; + } + + RawMessage rm = new RawMessage(); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.enter")); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.hand"), + Jobs.getLanguage().getMessage("command.editquests.help.modify.handHover"), "jobs editquests add " + job.getName() + + " " + q.getConfigName() + " " + actionT.getName() + " hand " + amount); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.or")); + rm.add(Jobs.getLanguage().getMessage("command.editquests.help.modify.look"), + Jobs.getLanguage().getMessage("command.editquests.help.modify.lookHover"), "jobs editquests add " + job.getName() + + " " + q.getConfigName() + " " + actionT.getName() + " looking " + amount); + rm.show(sender); + + Util.getQuestsEditorMap().put(player.getUniqueId(), "jobs editquests add " + job.getName() + + " " + q.getConfigName() + " " + actionT.getName() + " " + amount); + return true; + } + + if (args.length >= 5 && args.length <= 6) { + Job job = Jobs.getJob(args[1]); + if (job == null) + return false; + + Quest q = job.getQuest(args[2]); + if (q == null) { + return true; + } + + ActionType actionT = ActionType.getByName(args[3]); + if (actionT == null) { + return false; + } + + String key = args[4]; + switch (args[4]) { + case "hand": + ItemStack item = Jobs.getNms().getItemInMainHand(player); + key = item.getType().name() + "-" + item.getData().getData(); + break; + case "offhand": + item = ItemReflection.getItemInOffHand(player); + key = item.getType().name() + "-" + item.getData().getData(); + break; + case "looking": + case "lookingat": + Block block = Util.getTargetBlock(player, 30); + key = block.getType().name() + "-" + block.getData(); + break; + default: + break; + } + + String myKey = key; + String type = null; + String subType = ""; + String meta = ""; + int id = 0; + + if (myKey.contains("-")) { + // uses subType + subType = ":" + myKey.split("-")[1]; + meta = myKey.split("-")[1]; + myKey = myKey.split("-")[0]; + } + + CMIMaterial material = null; + + switch (actionT) { + case KILL: + case MILK: + case MMKILL: + case BOSS: + case BREED: + case TAME: + case SHEAR: + case EXPLORE: + case CUSTOMKILL: + break; + case TNTBREAK: + case VTRADE: + case SMELT: + case REPAIR: + case PLACE: + case EAT: + case FISH: + case ENCHANT: + case DYE: + case CRAFT: + case BAKE: + case BREW: + case BREAK: + case STRIPLOGS: + material = CMIMaterial.get(myKey + (subType)); + + if (material == null) + material = CMIMaterial.get(myKey.replace(" ", "_").toUpperCase()); + + if (material == null) { + // try integer method + Integer matId = null; + try { + matId = Integer.valueOf(myKey); + } catch (NumberFormatException e) { + } + if (matId != null) { + material = CMIMaterial.get(matId); + if (material != null) { + Jobs.getPluginLogger().warning("Job " + job.getName() + " " + actionT.getName() + " is using ID: " + key + "!"); + Jobs.getPluginLogger().warning("Please use the Material name instead: " + material.toString() + "!"); } } - if (material == CMIMaterial.REDSTONE_ORE && actionT == ActionType.BREAK && Version.isCurrentLower(Version.v1_13_R1)) { - player.sendMessage(ChatColor.GOLD + "Quest " + q.getConfigName() + " is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE."); - player.sendMessage(ChatColor.GOLD + "Automatically changing block to GLOWING_REDSTONE_ORE. Please update your configuration."); - player.sendMessage(ChatColor.GOLD + "In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with."); - player.sendMessage(ChatColor.GOLD + "In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly."); - material = CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE; - } else if (material == CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE && actionT == ActionType.BREAK && Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { - player.sendMessage(ChatColor.GOLD + "Quest " + q.getConfigName() + " is using GLOWING_REDSTONE_ORE instead of REDSTONE_ORE."); - player.sendMessage(ChatColor.GOLD + "Automatically changing block to REDSTONE_ORE. Please update your configuration."); - material = CMIMaterial.REDSTONE_ORE; - } - id = material.getId(); - type = material.getMaterial().toString(); - } else if (actionT == ActionType.KILL || actionT == ActionType.TAME || actionT == ActionType.BREED || actionT == ActionType.MILK) { + } + break; + default: + break; - // check entities - EntityType entity = EntityType.fromName(myKey.toUpperCase()); - if (entity == null) { - entity = EntityType.valueOf(myKey.toUpperCase()); + } + + c: if (material != null && material.getMaterial() != null) { + + // Need to include thos ones and count as regular blocks + switch (key.replace("_", "").toLowerCase()) { + case "itemframe": + type = "ITEM_FRAME"; + meta = "1"; + break c; + case "painting": + type = "PAINTING"; + meta = "1"; + break c; + case "armorstand": + type = "ARMOR_STAND"; + meta = "1"; + break c; + default: + break; + } + + if (actionT == ActionType.BREAK || actionT == ActionType.PLACE || actionT == ActionType.STRIPLOGS) { + if (!material.isBlock()) { + player.sendMessage(CMIChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + material + + "(" + key + ")! Material must be a block!"); + break; } + } + if (material == CMIMaterial.REDSTONE_ORE && actionT == ActionType.BREAK && Version.isCurrentLower(Version.v1_13_R1)) { + player.sendMessage(CMIChatColor.GOLD + "Quest " + q.getConfigName() + " is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE."); + player.sendMessage(CMIChatColor.GOLD + "Automatically changing block to GLOWING_REDSTONE_ORE. Please update your configuration."); + player.sendMessage(CMIChatColor.GOLD + "In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with."); + player.sendMessage(CMIChatColor.GOLD + "In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly."); + material = CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE; + } else if (material == CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE && actionT == ActionType.BREAK && Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { + player.sendMessage(CMIChatColor.GOLD + "Quest " + q.getConfigName() + " is using GLOWING_REDSTONE_ORE instead of REDSTONE_ORE."); + player.sendMessage(CMIChatColor.GOLD + "Automatically changing block to REDSTONE_ORE. Please update your configuration."); + material = CMIMaterial.REDSTONE_ORE; + } + id = material.getId(); + type = material.getMaterial().toString(); + } else if (actionT == ActionType.KILL || actionT == ActionType.TAME || actionT == ActionType.BREED || actionT == ActionType.MILK) { + + // check entities + EntityType entity = EntityType.fromName(myKey.toUpperCase()); + if (entity == null) { + entity = EntityType.valueOf(myKey.toUpperCase()); + } if (entity != null) { if (entity.isAlive()) { @@ -462,141 +462,139 @@ public class editquests implements Cmd { type = entity.toString(); id = entity.getTypeId(); } - } - - if (entity == null) { - switch (key.toLowerCase()) { - case "skeletonwither": - type = CMIEntityType.WITHER_SKELETON.name(); - id = 51; - meta = "1"; - break; - case "skeletonstray": - type = CMIEntityType.STRAY.name(); - id = 51; - meta = "2"; - break; - case "zombievillager": - type = CMIEntityType.ZOMBIE_VILLAGER.name(); - id = 54; - meta = "1"; - break; - case "zombiehusk": - type = CMIEntityType.HUSK.name(); - id = 54; - meta = "2"; - break; - case "horseskeleton": - type = CMIEntityType.SKELETON_HORSE.name(); - id = 100; - meta = "1"; - break; - case "horsezombie": - type = CMIEntityType.ZOMBIE_HORSE.name(); - id = 100; - meta = "2"; - break; - case "guardianelder": - type = CMIEntityType.ELDER_GUARDIAN.name(); - id = 68; - meta = "1"; - break; - default: - type = CMIEntityType.getByName(myKey.toUpperCase()).name(); - id = CMIEntityType.getByName(myKey.toUpperCase()).getId(); - meta = "1"; - break; - } - } - - } else if (actionT == ActionType.ENCHANT) { - Enchantment enchant = Enchantment.getByName(myKey); - if (enchant != null) { - if (Jobs.getVersionCheckManager().getVersion().isEqualOrLower(Version.v1_12_R1)) { - try { - id = (int) enchant.getClass().getMethod("getId").invoke(enchant); - } catch (Exception e) { - } - } - } - type = myKey; - } else if (actionT == ActionType.CUSTOMKILL || actionT == ActionType.SHEAR || actionT == ActionType.MMKILL - || actionT == ActionType.COLLECT || actionT == ActionType.BAKE || actionT == ActionType.BOSS) - type = myKey; - else if (actionT == ActionType.EXPLORE) { - type = myKey; - int a = 10; - try { - a = Integer.valueOf(myKey); - } catch (NumberFormatException e) { - player.sendMessage(ChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + key + "!"); + } else { + switch (key.toLowerCase()) { + case "skeletonwither": + type = CMIEntityType.WITHER_SKELETON.name(); + id = 51; + meta = "1"; + break; + case "skeletonstray": + type = CMIEntityType.STRAY.name(); + id = 51; + meta = "2"; + break; + case "zombievillager": + type = CMIEntityType.ZOMBIE_VILLAGER.name(); + id = 54; + meta = "1"; + break; + case "zombiehusk": + type = CMIEntityType.HUSK.name(); + id = 54; + meta = "2"; + break; + case "horseskeleton": + type = CMIEntityType.SKELETON_HORSE.name(); + id = 100; + meta = "1"; + break; + case "horsezombie": + type = CMIEntityType.ZOMBIE_HORSE.name(); + id = 100; + meta = "2"; + break; + case "guardianelder": + type = CMIEntityType.ELDER_GUARDIAN.name(); + id = 68; + meta = "1"; + break; + default: + type = CMIEntityType.getByName(myKey.toUpperCase()).name(); + id = CMIEntityType.getByName(myKey.toUpperCase()).getId(); + meta = "1"; break; } + } - Jobs.getExplore().setExploreEnabled(); - Jobs.getExplore().setPlayerAmount(a); - } else if (actionT == ActionType.CRAFT && myKey.startsWith("!")) - type = myKey.substring(1, myKey.length()); - - if (type == null) { - player.sendMessage(ChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + key + "!"); + } else if (actionT == ActionType.ENCHANT) { + Enchantment enchant = Enchantment.getByName(myKey); + if (enchant != null) { + if (Jobs.getVersionCheckManager().getVersion().isEqualOrLower(Version.v1_12_R1)) { + try { + id = (int) enchant.getClass().getMethod("getId").invoke(enchant); + } catch (Exception e) { + } + } + } + type = myKey; + } else if (actionT == ActionType.CUSTOMKILL || actionT == ActionType.SHEAR || actionT == ActionType.MMKILL + || actionT == ActionType.COLLECT || actionT == ActionType.BAKE || actionT == ActionType.BOSS) + type = myKey; + else if (actionT == ActionType.EXPLORE) { + type = myKey; + int a = 10; + try { + a = Integer.valueOf(myKey); + } catch (NumberFormatException e) { + player.sendMessage(CMIChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + key + "!"); break; } - if (actionT == ActionType.TNTBREAK) - Jobs.getGCManager().setTntFinder(true); + Jobs.getExplore().setExploreEnabled(); + Jobs.getExplore().setPlayerAmount(a); + } else if (actionT == ActionType.CRAFT && myKey.startsWith("!")) + type = myKey.substring(1, myKey.length()); - int amount = 3; - if (args.length == 6) { - try { - amount = Integer.parseInt(args[5]); - } catch (NumberFormatException e) { - } - } - - if (amount < 1) { - amount = 3; - } - - q.addObjective(new QuestObjective(actionT, id, meta, (type + subType), amount)); - - player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() + " " + q.getConfigName() + " 1"); - - org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig(); - String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + "."; - - if (file.isString(j + "Target")) { - Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), (type + subType).toLowerCase()); - Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName()); - } else if (file.isList(j + "Objectives")) { - List list = file.getStringList(j + "Objectives"); - list.add(actionT.getName() + ";" + (type + subType).toLowerCase() + ";" + amount); - - file.set(j + "Objectives", list); - - try { - file.save(Jobs.getConfigManager().getJobFile()); - } catch (java.io.IOException e) { - e.printStackTrace(); - } - } - - Util.getQuestsEditorMap().remove(player.getUniqueId()); - return true; + if (type == null) { + player.sendMessage(CMIChatColor.GOLD + "Quest " + q.getConfigName() + " has an invalid " + actionT.getName() + " type property: " + key + "!"); + break; } - break; - default: - break; + if (actionT == ActionType.TNTBREAK) + Jobs.getGCManager().setTntFinder(true); + + int amount = 3; + if (args.length == 6) { + try { + amount = Integer.parseInt(args[5]); + } catch (NumberFormatException e) { + } + } + + if (amount < 1) { + amount = 3; + } + + q.addObjective(new QuestObjective(actionT, id, meta, (type + subType), amount)); + + player.performCommand("jobs editquests list " + job.getName() + " " + actionT.getName() + " " + q.getConfigName() + " 1"); + + org.bukkit.configuration.file.YamlConfiguration file = Jobs.getConfigManager().getJobConfig(); + String j = "Jobs." + job.getJobKeyName() + ".Quests." + q.getConfigName() + "."; + + if (file.isString(j + "Target")) { + Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Target"), (type + subType).toLowerCase()); + Jobs.getConfigManager().changeJobsSettings(file.getString(j + "Action"), actionT.getName()); + } else if (file.isList(j + "Objectives")) { + List list = file.getStringList(j + "Objectives"); + list.add(actionT.getName() + ";" + (type + subType).toLowerCase() + ";" + amount); + + file.set(j + "Objectives", list); + + try { + file.save(Jobs.getConfigManager().getJobFile()); + } catch (java.io.IOException e) { + e.printStackTrace(); + } + } + + Util.getQuestsEditorMap().remove(player.getUniqueId()); + return true; } + break; + default: + break; + } + return false; } private static void showPath(Player player, Job job, ActionType action, JobInfo jInfo, Quest q) { RawMessage rm = new RawMessage(); rm.addText(Jobs.getLanguage().getMessage("command.editquests.help.list.quest")).addHover("&eQuest list") - .addCommand("jobs editquests"); + .addCommand("jobs editquests"); rm.show(player); if (job != null) { @@ -610,7 +608,7 @@ public class editquests implements Cmd { rm = new RawMessage(); rm.addText(Jobs.getLanguage().getMessage("command.editquests.help.list.actions", "%actionname%", action.getName())) - .addHover(action.getName()).addCommand("jobs editquests list " + job.getName() + " " + action.getName() + " 1"); + .addHover(action.getName()).addCommand("jobs editquests list " + job.getName() + " " + action.getName() + " 1"); rm.show(player); } @@ -620,7 +618,7 @@ public class editquests implements Cmd { String materialName = jInfo.getRealisticName(); rm.addText(Jobs.getLanguage().getMessage("command.editquests.help.list.quests", "%questname%", q.getConfigName())) - .addHover(jInfo.getName()).addCommand("jobs editquests list " + job.getName() + " " + action.getName() + " " + q.getConfigName() + .addHover(jInfo.getName()).addCommand("jobs editquests list " + job.getName() + " " + action.getName() + " " + q.getConfigName() + " " + materialName); rm.show(player); } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java index 2709e755..0fab2258 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java @@ -16,7 +16,7 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.RawMessage; @@ -68,9 +68,9 @@ public class itembonus implements Cmd { if (!any) continue; - String mc = ChatColor.DARK_GREEN.toString(), - pc = ChatColor.GOLD.toString(), - ec = ChatColor.YELLOW.toString(), + String mc = CMIChatColor.DARK_GREEN.toString(), + pc = CMIChatColor.GOLD.toString(), + ec = CMIChatColor.YELLOW.toString(), msg = null; if (jPlayer.isInJob(one)) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java index 6436748d..24e9a915 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/limit.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/limit.java @@ -61,8 +61,8 @@ public class limit implements Cmd { continue; } if (limit.GetLeftTime(type) > 0) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.GetLeftTime(type)))); - sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "Limit", + sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "time", "%time%", TimeManage.to24hourShort(limit.GetLeftTime(type)))); + sender.sendMessage(Jobs.getLanguage().getMessage("command.limit.output." + type.getName().toLowerCase() + "Limit", "%current%", (int) (limit.GetAmount(type) * 100) / 100D, "%total%", JPlayer.getLimit(type))); } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index d34fa186..dc1c5ec3 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -28,7 +28,6 @@ import com.gamingmesh.jobs.ItemBoostManager; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.*; import com.gamingmesh.jobs.resources.jfep.Parser; -import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.Util; import org.apache.commons.lang.StringEscapeUtils; @@ -450,22 +449,22 @@ public class ConfigManager { } break; - default: + default: break; - } + } - if (actionType == ActionType.STRIPLOGS && Version.isCurrentLower(Version.v1_13_R1)) - return null; + if (actionType == ActionType.STRIPLOGS && Version.isCurrentLower(Version.v1_13_R1)) + return null; - if (material != null && material.getMaterial() != null && material.isAir()) { - Jobs.getPluginLogger().warning("Job " + jobName + " " + actionType.getName() + " can't recognize material! (" + myKey + ")"); - return null; - } + if (material != null && material.getMaterial() != null && material.isAir()) { + Jobs.getPluginLogger().warning("Job " + jobName + " " + actionType.getName() + " can't recognize material! (" + myKey + ")"); + return null; + } - if (material != null && Version.isCurrentLower(Version.v1_13_R1) && meta.isEmpty()) - meta = String.valueOf(material.getData()); + if (material != null && Version.isCurrentLower(Version.v1_13_R1) && meta.isEmpty()) + meta = String.valueOf(material.getData()); - c: if (material != null && material != CMIMaterial.NONE && material.getMaterial() != null) { + c: if (material != null && material != CMIMaterial.NONE && material.getMaterial() != null) { // Need to include those ones and count as regular blocks switch (myKey.replace("_", "").toLowerCase()) { case "itemframe": @@ -490,9 +489,9 @@ public class ConfigManager { // Break and Place actions MUST be blocks if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) { if (!material.isBlock()) { - Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material - + " (" + myKey + ")! Material must be a block! Use \"/jobs blockinfo\" on a target block"); - return null; + Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material + + " (" + myKey + ")! Material must be a block! Use \"/jobs blockinfo\" on a target block"); + return null; } } @@ -522,7 +521,7 @@ public class ConfigManager { type = material.getMaterial().toString(); id = material.getId(); - } else if (actionType == ActionType.KILL || actionType == ActionType.TAME || actionType == ActionType.BREED || actionType == ActionType.MILK) { + } else if (actionType == ActionType.KILL || actionType == ActionType.TAME || actionType == ActionType.BREED || actionType == ActionType.MILK) { // check entities CMIEntityType entity = CMIEntityType.getByName(myKey); @@ -540,8 +539,8 @@ public class ConfigManager { } } - // Pre 1.13 checks for custom names - if (entity == null) { + // Pre 1.13 checks for custom names + if (entity == null) { switch (myKey.toLowerCase()) { case "skeletonwither": type = CMIEntityType.WITHER_SKELETON.name(); @@ -741,16 +740,16 @@ public class ConfigManager { } } - ChatColor color = ChatColor.WHITE; + CMIChatColor color = CMIChatColor.WHITE; if (jobSection.contains("ChatColour")) { String c = jobSection.getString("ChatColour", ""); - color = ChatColor.matchColor(c); + color = CMIChatColor.getColor(c); if (color == null && !c.isEmpty()) - color = ChatColor.matchColor(c.charAt(0)); + color = CMIChatColor.getColor(String.valueOf("&" + c.charAt(0))); if (color == null) { - color = ChatColor.WHITE; + color = CMIChatColor.WHITE; log.warning("Job " + jobKey + " has an invalid ChatColour property. Defaulting to WHITE!"); } } @@ -872,24 +871,24 @@ public class ConfigManager { } else log.warning("Job " + jobKey + " has an invalid Gui property. Please fix this if you want to use it!"); - if (guiSection.isList("Enchantments")) { - for (String str4 : guiSection.getStringList("Enchantments")) { - String[] id = str4.split(":"); - if (GUIitem.getItemMeta() instanceof EnchantmentStorageMeta) { - EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); - enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]), true); - GUIitem.setItemMeta(enchantMeta); - } else - GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1])); + if (guiSection.isList("Enchantments")) { + for (String str4 : guiSection.getStringList("Enchantments")) { + String[] id = str4.split(":"); + if (GUIitem.getItemMeta() instanceof EnchantmentStorageMeta) { + EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); + enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]), true); + GUIitem.setItemMeta(enchantMeta); + } else + GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1])); + } } - } - if (guiSection.isString("CustomSkull")) { - GUIitem = Util.getSkull(guiSection.getString("CustomSkull")); - } + if (guiSection.isString("CustomSkull")) { + GUIitem = Util.getSkull(guiSection.getString("CustomSkull")); + } - if (guiSection.getInt("slot", -1) >= 0) - guiSlot = guiSection.getInt("slot"); + if (guiSection.getInt("slot", -1) >= 0) + guiSlot = guiSection.getInt("slot"); } // Permissions @@ -1205,8 +1204,8 @@ public class ConfigManager { int id = keyValue.getId(); String type = keyValue.getType(), - subType = keyValue.getSubType(), - meta = keyValue.getMeta(); + subType = keyValue.getSubType(), + meta = keyValue.getMeta(); if (actionType == ActionType.TNTBREAK) Jobs.getGCManager().setTntFinder(true); diff --git a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java index 85f1e9dd..2c190f89 100644 --- a/src/main/java/com/gamingmesh/jobs/config/TitleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/TitleManager.java @@ -7,9 +7,9 @@ import java.util.List; import org.bukkit.configuration.ConfigurationSection; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.ConfigReader; import com.gamingmesh.jobs.container.Title; -import com.gamingmesh.jobs.stuff.ChatColor; public class TitleManager { @@ -55,12 +55,13 @@ public class TitleManager { c.header(Arrays.asList( "Title configuration", "Stores the titles people gain at certain levels.", - "Each title requres to have a name, short name (used when the player has more than", - "1 job) the colour of the title and the level requrirement to attain the title.", + "Each title requires to have a name, short name (used when the player has more than 1 job)", + "the colour of the title and the level requirement to attain the title.", + "Colour can ether be a word like Brown, can be color character like &5 or hex color code like {#6600cc}", "It is recommended but not required to have a title at level 0.", "Titles are completely optional.", - "Posible variable are {level} to add current jobs level.", - "Optionaly you can set different titles based by job.", + "Possible variable are {level} to add current jobs level.", + "Optionally you can set different titles based by job.", " JobName: Miner")); ConfigurationSection titleSection = c.getC().getConfigurationSection("Titles"); @@ -70,56 +71,56 @@ public class TitleManager { titles.add(new Title( c.get("Titles.Novice.Name", "N"), c.get("Titles.Novice.ShortName", "N"), - ChatColor.matchColor(c.get("Titles.Novice.ChatColour", "YELLOW")), + CMIChatColor.getColor(c.get("Titles.Novice.ChatColour", "YELLOW")), c.get("Titles.Novice.levelReq", 0), null)); titles.add(new Title( c.get("Titles.Apprentice.Name", "A"), c.get("Titles.Apprentice.ShortName", "A"), - ChatColor.matchColor(c.get("Titles.Apprentice.ChatColour", "WHITE")), + CMIChatColor.getColor(c.get("Titles.Apprentice.ChatColour", "WHITE")), c.get("Titles.Apprentice.levelReq", 25), null)); titles.add(new Title( c.get("Titles.Initiate.Name", "I"), c.get("Titles.Initiate.ShortName", "I"), - ChatColor.matchColor(c.get("Titles.Initiate.ChatColour", "GOLD")), + CMIChatColor.getColor(c.get("Titles.Initiate.ChatColour", "GOLD")), c.get("Titles.Initiate.levelReq", 50), null)); titles.add(new Title( c.get("Titles.Journeyman.Name", "J"), c.get("Titles.Journeyman.ShortName", "J"), - ChatColor.matchColor(c.get("Titles.Journeyman.ChatColour", "DARK_GREEN")), + CMIChatColor.getColor(c.get("Titles.Journeyman.ChatColour", "DARK_GREEN")), c.get("Titles.Journeyman.levelReq", 75), null)); titles.add(new Title( c.get("Titles.Adept.Name", "Ad"), c.get("Titles.Adept.ShortName", "Ad"), - ChatColor.matchColor(c.get("Titles.Adept.ChatColour", "DARK_PURPLE")), + CMIChatColor.getColor(c.get("Titles.Adept.ChatColour", "DARK_PURPLE")), c.get("Titles.Adept.levelReq", 100), null)); titles.add(new Title( c.get("Titles.Master.Name", "M"), c.get("Titles.Master.ShortName", "M"), - ChatColor.matchColor(c.get("Titles.Master.ChatColour", "GRAY")), + CMIChatColor.getColor(c.get("Titles.Master.ChatColour", "GRAY")), c.get("Titles.Master.levelReq", 125), null)); titles.add(new Title( c.get("Titles.Grandmaster.Name", "GM"), c.get("Titles.Grandmaster.ShortName", "GM"), - ChatColor.matchColor(c.get("Titles.Grandmaster.ChatColour", "DARK_GRAY")), + CMIChatColor.getColor(c.get("Titles.Grandmaster.ChatColour", "DARK_GRAY")), c.get("Titles.Grandmaster.levelReq", 150), null)); titles.add(new Title( c.get("Titles.Legendary.Name", "L"), c.get("Titles.Legendary.ShortName", "L"), - ChatColor.matchColor(c.get("Titles.Legendary.ChatColour", "BLACK")), + CMIChatColor.getColor(c.get("Titles.Legendary.ChatColour", "BLACK")), c.get("Titles.Legendary.levelReq", 200), null)); c.save(); @@ -128,7 +129,7 @@ public class TitleManager { String jobName = null; String titleName = titleSection.getString(titleKey + ".Name"); String titleShortName = titleSection.getString(titleKey + ".ShortName"); - ChatColor titleColor = ChatColor.matchColor(titleSection.getString(titleKey + ".ChatColour", "")); + CMIChatColor titleColor = CMIChatColor.getColor(titleSection.getString(titleKey + ".ChatColour", "")); int levelReq = titleSection.getInt(titleKey + ".levelReq", -1); if (titleSection.isString(titleKey + ".JobName")) diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index b2b6ee50..aaa79b01 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -19,10 +19,10 @@ package com.gamingmesh.jobs.container; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.actions.PotionItemActionInfo; import com.gamingmesh.jobs.resources.jfep.Parser; -import com.gamingmesh.jobs.stuff.ChatColor; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; @@ -51,7 +51,7 @@ public class Job { private String jobShortName; private String description; - private ChatColor jobColour; + private CMIChatColor jobColour; private Parser maxExpEquation; private DisplayMethod displayMethod; @@ -85,7 +85,7 @@ public class Job { private int id = 0; - public Job(String jobName, String fullName, String jobShortName, String description, ChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, + public Job(String jobName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel, int vipmaxLevel, Integer maxSlots, List jobPermissions, List jobCommands, List jobConditions, HashMap jobItems, HashMap jobLimitedItems, List CmdOnJoin, List CmdOnLeave, ItemStack GUIitem, int guiSlot, String bossbar, Long rejoinCD, List worldBlacklist) { this.jobName = jobName == null ? "" : jobName; @@ -294,7 +294,7 @@ public class Job { * Get the Color of the job for chat * @return the Color of the job for chat */ - public ChatColor getChatColor() { + public CMIChatColor getChatColor() { return jobColour; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 73d9061c..3581ff1c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -38,7 +38,6 @@ import com.gamingmesh.jobs.Signs.SignTopType; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.resources.jfep.Parser; -import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.TimeManage; @@ -678,7 +677,7 @@ public class JobsPlayer { if (numJobs == 1) { if (method == DisplayMethod.FULL || method == DisplayMethod.TITLE) { if (title != null) { - String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE; + String honorificpart = title.getChatColor() + title.getName() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); builder.append(honorificpart); @@ -691,7 +690,7 @@ public class JobsPlayer { builder.append(" "); } - String honorificpart = prog.getJob().getNameWithColor() + ChatColor.WHITE; + String honorificpart = prog.getJob().getNameWithColor() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); @@ -703,7 +702,7 @@ public class JobsPlayer { if (numJobs > 1 && (method == DisplayMethod.FULL) || method == DisplayMethod.TITLE || method == DisplayMethod.SHORT_FULL || method == DisplayMethod.SHORT_TITLE) { // add title to honorific if (title != null) { - String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE; + String honorificpart = title.getChatColor() + title.getShortName() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); @@ -712,9 +711,8 @@ public class JobsPlayer { } } - if (numJobs > 1 && (method == DisplayMethod.FULL) || method == DisplayMethod.JOB || method == DisplayMethod.SHORT_FULL || method == - DisplayMethod.SHORT_JOB) { - String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE; + if (numJobs > 1 && (method == DisplayMethod.FULL) || method == DisplayMethod.JOB || method == DisplayMethod.SHORT_FULL || method == DisplayMethod.SHORT_JOB) { + String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel())); @@ -727,7 +725,7 @@ public class JobsPlayer { if (nonejob != null) { DisplayMethod metod = nonejob.getDisplayMethod(); if (metod == DisplayMethod.FULL || metod == DisplayMethod.TITLE) { - String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE; + String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", ""); @@ -735,7 +733,7 @@ public class JobsPlayer { } if (metod == DisplayMethod.SHORT_FULL || metod == DisplayMethod.SHORT_TITLE || metod == DisplayMethod.SHORT_JOB) { - String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE; + String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + CMIChatColor.WHITE; if (honorificpart.contains("{level}")) honorificpart = honorificpart.replace("{level}", ""); @@ -1225,7 +1223,7 @@ public class JobsPlayer { public int getMaxFurnacesAllowed(CMIMaterial type) { String perm = "jobs.max" + (type == CMIMaterial.FURNACE || type == CMIMaterial.LEGACY_BURNING_FURNACE - ? "furnaces" : type == CMIMaterial.BLAST_FURNACE ? "blastfurnaces" : type == CMIMaterial.SMOKER ? "smokers" : ""); + ? "furnaces" : type == CMIMaterial.BLAST_FURNACE ? "blastfurnaces" : type == CMIMaterial.SMOKER ? "smokers" : ""); if (perm.isEmpty()) return 0; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/ChatColor.java b/src/main/java/com/gamingmesh/jobs/stuff/ChatColor.java deleted file mode 100644 index 8260ce8b..00000000 --- a/src/main/java/com/gamingmesh/jobs/stuff/ChatColor.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs.stuff; - -import java.util.HashMap; -import java.util.Map; - -public enum ChatColor { - BLACK('0', 0), - DARK_BLUE('1', 1), - DARK_GREEN('2', 2), - DARK_AQUA('3', 3), - DARK_RED('4', 4), - DARK_PURPLE('5', 5), - GOLD('6', 6), - GRAY('7', 7), - DARK_GRAY('8', 8), - BLUE('9', 9), - GREEN('a', 10), - AQUA('b', 11), - RED('c', 12), - LIGHT_PURPLE('d', 13), - YELLOW('e', 14), - WHITE('f', 15), - BOLD('l', 16), - ITALIC('o', 17), - UNDERLINE('n', 18), - RESET('r', 19), - STRIKETHROUGH('m', 20); - - private static final char COLOR_CHAR = '\u00A7'; - private final char code; - private final int intCode; - private final String toString; - private final static Map intMap = new HashMap<>(); - private final static Map charMap = new HashMap<>(); - private final static Map stringMap = new HashMap<>(); - - private ChatColor(char code, int intCode) { - this.code = code; - this.intCode = intCode; - this.toString = new String(new char[] { COLOR_CHAR, code }); - } - - public char getChar() { - return code; - } - - @Override - public String toString() { - return toString; - } - - public static ChatColor matchColor(char code) { - return charMap.get(code); - } - - public static ChatColor matchColor(int code) { - return intMap.get(code); - } - - public static ChatColor matchColor(String name) { - return stringMap.get(name.toLowerCase()); - } - - static { - for (ChatColor color : values()) { - intMap.put(color.intCode, color); - charMap.put(color.code, color); - stringMap.put(color.name().toLowerCase(), color); - } - } -}