From 88c6d1fc380fe68ea4c04ef1433e262aa3966dc7 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 19 Aug 2019 18:31:29 +0200 Subject: [PATCH] Re-worked the quest list to support crowdin - Fixed %titlename% placeholder does not showed anything - Re-added Cat, Cat is ALIVE!! --- pom.xml | 8 ++--- .../gamingmesh/jobs/CMILib/ItemManager.java | 31 ++++++++----------- .../jobs/CMILib/ItemReflection.java | 10 +++--- .../jobs/commands/JobsCommands.java | 24 +++++++++----- .../jobs/commands/list/editjobs.java | 2 +- .../gamingmesh/jobs/commands/list/exp.java | 2 +- .../jobs/commands/list/expboost.java | 16 +++------- .../jobs/commands/list/moneyboost.java | 17 ++++------ .../gamingmesh/jobs/commands/list/quests.java | 14 +-------- .../jobs/config/LanguageManager.java | 6 ++-- .../java/com/gamingmesh/jobs/stuff/Util.java | 6 ++-- 11 files changed, 59 insertions(+), 77 deletions(-) diff --git a/pom.xml b/pom.xml index 3145370b..e4a80934 100644 --- a/pom.xml +++ b/pom.xml @@ -77,8 +77,8 @@ com.sk89q.worldguard - worldguard-legacy - 7.0.0-SNAPSHOT + worldguard-bukkit + 7.0.1-SNAPSHOT bukkit @@ -94,7 +94,7 @@ com.sk89q.worldedit worldedit-bukkit - 7.0.0-SNAPSHOT + 7.1.0-SNAPSHOT bukkit @@ -109,7 +109,7 @@ com.sk89q.worldedit worldedit-core - 7.0.0-SNAPSHOT + 7.1.0-SNAPSHOT bukkit diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java index 841e637b..eaabeccb 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java @@ -63,7 +63,7 @@ public class ItemManager { String bukkitName = one.name(); String mojangName = one.name(); - + try { mojangName = ItemReflection.getItemMinecraftName(new ItemStack(mat)); } catch (Throwable e) { @@ -132,7 +132,6 @@ public class ItemManager { /** * Gets the item by material - * * @deprecated Use {@link #getItem(ItemStack)} * @param mat Material * @return {@link CMIItemStack} @@ -181,7 +180,7 @@ public class ItemManager { String a = name.split("-")[1]; try { amount = Integer.parseInt(a); - } catch (Throwable e) { + } catch (NumberFormatException e) { } name = name.split("-")[0]; } @@ -191,7 +190,7 @@ public class ItemManager { if (name.contains(":")) { try { data = (short) Integer.parseInt(name.split(":")[1]); - } catch (Throwable e) { + } catch (NumberFormatException e) { } try { CMIEntityType e = CMIEntityType.getByName(name.split(":")[1]); @@ -276,7 +275,7 @@ public class ItemManager { if (cm == null) { try { cm = byId.get(Integer.parseInt(name)); - } catch (Throwable e) { + } catch (NumberFormatException e) { } if (cm == null) { @@ -354,7 +353,7 @@ public class ItemManager { if (ncm != null && subdata != null) { - if (ncm.getCMIType().isPotion() || ncm.getCMIType().equals(CMIMaterial.SPLASH_POTION) || ncm.getCMIType().equals(CMIMaterial.TIPPED_ARROW)) { + if (ncm.getCMIType().isPotion() || ncm.getCMIType().equals(CMIMaterial.TIPPED_ARROW)) { Integer d = null; PotionEffectType type = null; Boolean upgraded = false; @@ -632,6 +631,7 @@ public class ItemManager { ENDERMITE(67, "Endermite"), GUARDIAN(68, "Guardian"), SHULKER(69, "Shulker"), + CAT(75, "Cat"), PIG(90, "Pig"), SHEEP(91, "Sheep"), COW(92, "Cow"), @@ -640,7 +640,7 @@ public class ItemManager { WOLF(95, "Wolf"), MUSHROOM_COW(96, "Mushroom Cow", "Mooshroom"), SNOWMAN(97, "Snowman"), - OCELOT(98, "Ocelot", "Cat"), + OCELOT(98, "Ocelot"), IRON_GOLEM(99, "Iron Golem"), HORSE(100, "Horse"), RABBIT(101, "Rabbit"), @@ -732,7 +732,7 @@ public class ItemManager { } public static CMIEntityType getByName(String name) { - String main = name; + String main = name; String sub = null; if (name.contains("_")) { @@ -752,7 +752,7 @@ public class ItemManager { Integer id = null; try { id = Integer.parseInt(main); - } catch (Exception e) { + } catch (NumberFormatException e) { } for (CMIEntityType one : CMIEntityType.values()) { @@ -761,7 +761,7 @@ public class ItemManager { break; } } - + if (type == null) for (CMIEntityType one : CMIEntityType.values()) { if (one.secondaryName == null) @@ -774,7 +774,7 @@ public class ItemManager { break; } } - + if (type == null) for (CMIEntityType one : CMIEntityType.values()) { if (one.name.replace("_", "").contains(updated)) { @@ -1910,7 +1910,6 @@ public class ItemManager { /** * Get the legacy id from the material enum - * * @deprecated Not used, above 1.13 * @return legacy id */ @@ -1921,7 +1920,6 @@ public class ItemManager { /** * Get the id from the material enum - * * @deprecated If the id is exist under 1.13 then success * @return id */ @@ -1997,7 +1995,6 @@ public class ItemManager { /** * Get the data - * * @deprecated Not used, above 1.13+ * @return data */ @@ -2011,7 +2008,6 @@ public class ItemManager { /** * Get the legacy data - * * @deprecated Not used, above 1.13+ * @return legacy data */ @@ -2021,7 +2017,6 @@ public class ItemManager { } public static CMIMaterial getRandom(CMIMaterial mat) { - List ls = new ArrayList(); for (CMIMaterial one : CMIMaterial.values()) { @@ -2077,7 +2072,7 @@ public class ItemManager { if (Version.isCurrentEqualOrLower(Version.v1_13_R2)) { try { ids = Integer.parseInt(id); - } catch (Throwable e) { + } catch (NumberFormatException e) { if (id.contains(":")) { try { ids = Integer.parseInt(id.split(":")[0]); @@ -2089,7 +2084,7 @@ public class ItemManager { try { data = Integer.parseInt(id.split(":")[1]); id = id.split(":")[0]; - } catch (Throwable t) { + } catch (NumberFormatException t) { } } } diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/ItemReflection.java b/src/main/java/com/gamingmesh/jobs/CMILib/ItemReflection.java index af104453..886524ac 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/ItemReflection.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/ItemReflection.java @@ -33,27 +33,27 @@ public class ItemReflection { private static void initialize() { try { CraftServerClass = getBukkitClass("CraftServer"); - } catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); } try { CraftServer = CraftServerClass.cast(Bukkit.getServer()); - } catch (SecurityException | IllegalArgumentException e) { + } catch (ClassCastException e) { e.printStackTrace(); } try { CraftItemStack = getBukkitClass("inventory.CraftItemStack"); - } catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); } try { Item = getMinecraftClass("Item"); - } catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); } try { IStack = getMinecraftClass("ItemStack"); - } catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) { + } catch (ClassNotFoundException e) { e.printStackTrace(); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 751de4b7..21dce41c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -36,8 +36,9 @@ import com.gamingmesh.jobs.container.Job; 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.container.QuestProgression; import com.gamingmesh.jobs.stuff.PageInfo; +import com.gamingmesh.jobs.stuff.TimeManage; public class JobsCommands implements CommandExecutor { private static final String label = "jobs"; @@ -488,17 +489,12 @@ public class JobsCommands implements CommandExecutor { * @return the message */ public String jobStatsMessage(JobProgression jobProg) { - Title t = null; - for (Title title : new ArrayList()) { - if (t == null) - t = title; - } String message = Jobs.getLanguage().getMessage("command.stats.output", "%joblevel%", jobProg.getLevel(), "%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName(), "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, "%jobmaxxp%", jobProg.getMaxExperience(), - "%titlename%", t == null ? "" : t.getName()); + "%titlename%", Jobs.gettitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()).getName()); return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message; } @@ -539,4 +535,18 @@ public class JobsCommands implements CommandExecutor { "%jobmaxxp%", jobProg.getMaxExperience(level)); return " " + jobProgressMessage(jobProg.getMaxExperience(level), exp) + " " + message; } + + public String jobsQuestMessage(QuestProgression qp, JobProgression prog) { + String hoverMsg = Jobs.getLanguage().getMessage("command.quests.output.hover"); + hoverMsg = hoverMsg.replace("[jobName]", prog.getJob().getName()) + .replace("[time]", TimeManage.to24hourShort(qp.getValidUntil() - System.currentTimeMillis())); + + if (hoverMsg.contains("[desc]")) { + for (String one : qp.getQuest().getDescription()) { + hoverMsg = hoverMsg.replace("[desc]", one); + } + } + + return hoverMsg; + } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java index c59c3673..8f9f5912 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java @@ -76,7 +76,7 @@ public class editjobs implements Cmd { Integer page = null; try { page = Integer.parseInt(args[3]); - } catch (Throwable e) { + } catch (NumberFormatException e) { } if (page != null) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/exp.java b/src/main/java/com/gamingmesh/jobs/commands/list/exp.java index 31d3cc92..0c91e68f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/exp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/exp.java @@ -55,7 +55,7 @@ public class exp implements Cmd { double amount = 0.0; try { amount = Double.parseDouble(args[3]); - } catch (Throwable e) { + } catch (NumberFormatException e) { sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error")); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java index 049c5eb6..a4c6ed11 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java @@ -27,12 +27,9 @@ public class expboost implements Cmd { return true; } - String PlayerName = sender.getName(); - String jobName = args[0]; - Job job = Jobs.getJob(jobName); - - if (PlayerName == null) { - Jobs.getCommandManager().sendUsage(sender, "expboost"); + Job job = Jobs.getJob(args[0]); + if (job == null) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } @@ -40,6 +37,7 @@ public class expboost implements Cmd { for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.EXP, 1.0); } + sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.allreset")); return true; } else if (args[0].equalsIgnoreCase("reset")) { @@ -59,7 +57,6 @@ public class expboost implements Cmd { } if (args[0].equalsIgnoreCase("all")) { - for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.EXP, rate); } @@ -67,10 +64,7 @@ public class expboost implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate)); return true; } - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + job.addBoost(CurrencyType.EXP, rate); sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName())); return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java index 97e58173..fe542a72 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java @@ -28,19 +28,18 @@ public class moneyboost implements Cmd { return true; } - String PlayerName = sender.getName(); - String jobName = args[0]; - Job job = Jobs.getJob(jobName); - - if (PlayerName == null) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); + Job job = Jobs.getJob(args[0]); + if (job == null) { + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } + if (args[0].equalsIgnoreCase("reset") && args[1].equalsIgnoreCase("all")) { for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.MONEY, 1.0); } + sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.allreset")); return true; } else if (args[0].equalsIgnoreCase("reset")) { @@ -60,7 +59,6 @@ public class moneyboost implements Cmd { } if (args[0].equalsIgnoreCase("all")) { - for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.MONEY, rate); } @@ -68,10 +66,7 @@ public class moneyboost implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate)); return true; } - if (job == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); - return true; - } + job.addBoost(CurrencyType.MONEY, rate); sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName())); return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java index 0fba181a..11d1dad1 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/quests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/quests.java @@ -15,7 +15,6 @@ import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.QuestObjective; import com.gamingmesh.jobs.container.QuestProgression; import com.gamingmesh.jobs.CMILib.RawMessage; -import com.gamingmesh.jobs.stuff.TimeManage; public class quests implements Cmd { @@ -64,19 +63,8 @@ public class quests implements Cmd { String msg = Jobs.getLanguage().getMessage("command.quests.output.questLine", "[progress]", progressLine, "[questName]", q.getQuest().getQuestName(), "[done]", q.getTotalAmountDone(), "[required]", q.getTotalAmountNeeded()); - List<String> hoverMsgs = Jobs.getLanguage().getMessageList("command.quests.output.hover"); List<String> hoverList = new ArrayList<>(); - - for (String current : hoverMsgs) { - current = current.replace("[jobName]", jobProg.getJob().getName()); - current = current.replace("[time]", TimeManage.to24hourShort(q.getValidUntil() - System.currentTimeMillis())); - if (current.contains("[desc]")) { - for (String one : q.getQuest().getDescription()) { - hoverList.add(one); - } - } else - hoverList.add(current); - } + hoverList.add(Jobs.getCommandManager().jobsQuestMessage(q, jobProg)); for (Entry<String, QuestObjective> oneObjective : q.getQuest().getObjectives().entrySet()) { hoverList.add(Jobs.getLanguage().getMessage("command.info.output." + oneObjective.getValue().getAction().toString().toLowerCase() + ".info") + " " + diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index c3a9b37a..36dca245 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -157,7 +157,7 @@ public class LanguageManager { c.get("command.help.output.label", "Jobs"); c.get("command.help.output.cmdInfoFormat", "[command] &f- &2[description]"); - c.get("command.help.output.cmdFormat", "&7/[command]&f[arguments]"); + c.get("command.help.output.cmdFormat", "&7/[command] &f[arguments]"); c.get("command.help.output.helpPageDescription", "&2* [description]"); c.get("command.help.output.title", "&e-------&e ======= &6Jobs &e======= &e-------"); @@ -485,10 +485,10 @@ public class LanguageManager { c.get("command.quests.help.args", "[playername]"); Jobs.getGCManager().getCommandArgs().put("quests", Arrays.asList("[playername]")); c.get("command.quests.error.noquests", "&cThere are no quests"); - c.get("command.quests.toplineseparator", "&7*********************** &6[playerName]&2(&f[questsDone]&2) &7***********************"); + c.get("command.quests.toplineseparator", "&7*********************** &6[playerName] &2(&f[questsDone]&2) &7***********************"); c.get("command.quests.output.completed", "&2 !Completed!&r "); c.get("command.quests.output.questLine", "[progress] &7[questName] &f[done]&7/&8[required]"); - c.get("command.quests.output.hover", Arrays.asList("&f[jobName]", "[desc]", "&7New quest in: [time]")); + c.get("command.quests.output.hover", "&f[jobName] \n[desc] \n&7New quest in: [time]"); c.get("command.fire.help.info", "Fire the player from the job."); c.get("command.fire.help.args", "[playername] [jobname]"); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 1f08856e..78d79a92 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -29,13 +29,13 @@ public class Util { public static List<String> confirmLeave = new ArrayList<>(); @SuppressWarnings("deprecation") - public static ItemStack setEntityType(ItemStack is, EntityType type) throws IllegalArgumentException { + public static ItemStack setEntityType(ItemStack is, EntityType type) { boolean useMeta; try { ItemStack testis = CMIMaterial.SPAWNER.newItemStack(); ItemMeta meta = testis.getItemMeta(); useMeta = meta instanceof BlockStateMeta; - } catch (Throwable e) { + } catch (Exception e) { useMeta = false; } @@ -126,7 +126,7 @@ public class Util { continue; if (lookingFor == null) { - if (!CMIMaterial.AIR.equals(material) && !CMIMaterial.CAVE_AIR.equals(material) && !CMIMaterial.VOID_AIR.equals(material)) { + if (!CMIMaterial.isAir(material)) { break; } } else {