From 76b050a788711f9f34f4afa6dc050b5060286563 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 14 Jun 2021 20:43:04 +0200 Subject: [PATCH] So lets properly recognize materials with name and data --- .../gamingmesh/jobs/CMILib/CMIMaterial.java | 13 +- .../com/gamingmesh/jobs/HookEconomyTask.java | 2 +- .../gamingmesh/jobs/PermissionManager.java | 16 ++- .../gamingmesh/jobs/config/ConfigManager.java | 113 ++++++++---------- .../jobs/config/NameTranslatorManager.java | 106 +++++++--------- .../gamingmesh/jobs/config/ShopManager.java | 2 +- .../gamingmesh/jobs/container/ActionType.java | 12 +- 7 files changed, 123 insertions(+), 141 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java index d0bb8538..384dc9ba 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java @@ -1406,7 +1406,18 @@ public enum CMIMaterial { id = split[0]; CMIMaterial mat = ItemManager.byName.get(id + ":" + data); - if (mat != null && mat.getLegacyId() > 0 && (mat = get(mat.getLegacyId(), data)) != null) { + + if (mat == null) + mat = ItemManager.byName.get(id); + + if (mat != null) { + if (mat.getLegacyId() > 0) { + CMIMaterial m = get(mat.getLegacyId(), data); + + if (m != null) + mat = m; + } + return mat; } } catch (NumberFormatException ex) { diff --git a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java index b64bd4b5..e7aa36ae 100644 --- a/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java +++ b/src/main/java/com/gamingmesh/jobs/HookEconomyTask.java @@ -44,7 +44,7 @@ public class HookEconomyTask implements Runnable { Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!"); Jobs.getPluginLogger().severe("Please install them first!"); Jobs.getPluginLogger().severe("You can find the latest versions here:"); - Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/vault.34315/"); + Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/"); Jobs.getPluginLogger().severe("=============================================="); } diff --git a/src/main/java/com/gamingmesh/jobs/PermissionManager.java b/src/main/java/com/gamingmesh/jobs/PermissionManager.java index 358093da..f64f3711 100644 --- a/src/main/java/com/gamingmesh/jobs/PermissionManager.java +++ b/src/main/java/com/gamingmesh/jobs/PermissionManager.java @@ -156,7 +156,11 @@ public class PermissionManager { * @return the max value */ public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) { - if (jPlayer == null || jPlayer.getPlayer() == null) + if (jPlayer == null) + return 0D; + + Player player = jPlayer.getPlayer(); + if (player == null) return 0D; perm = perm.toLowerCase(); @@ -165,7 +169,7 @@ public class PermissionManager { Map permissions = jPlayer.getPermissionsCache(); if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) { - permissions = getAll(jPlayer.getPlayer()); + permissions = getAll(player); jPlayer.setPermissionsCache(permissions); jPlayer.setLastPermissionUpdate(System.currentTimeMillis()); } @@ -190,12 +194,16 @@ public class PermissionManager { } public boolean hasPermission(JobsPlayer jPlayer, String perm) { - if (jPlayer == null || jPlayer.getPlayer() == null) + if (jPlayer == null) + return false; + + Player player = jPlayer.getPlayer(); + if (player == null) return false; Map permissions = jPlayer.getPermissionsCache(); if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) { - permissions = getAll(jPlayer.getPlayer()); + permissions = getAll(player); jPlayer.setPermissionsCache(permissions); jPlayer.setLastPermissionUpdate(System.currentTimeMillis()); } diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 592b5fbf..f238e77a 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -660,7 +660,7 @@ public class ConfigManager { break; } - // Break and Place actions MUST be blocks + // These actions MUST be blocks if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) { if (!material.isBlock() || material.getMaterial().toString().equalsIgnoreCase("AIR")) { Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material @@ -987,16 +987,13 @@ public class ConfigManager { String description = CMIChatColor.translate(jobSection.getString("description", "")); - List fDescription = new ArrayList<>(); - if (jobSection.contains("FullDescription")) { - if (jobSection.isString("FullDescription")) - fDescription.add(jobSection.getString("FullDescription")); - else if (jobSection.isList("FullDescription")) - fDescription.addAll(jobSection.getStringList("FullDescription")); + List fDescription = jobSection.getStringList("FullDescription"); - for (int i = 0; i < fDescription.size(); i++) { - fDescription.set(i, CMIChatColor.translate(fDescription.get(i))); - } + if (jobSection.isString("FullDescription")) + fDescription.add(jobSection.getString("FullDescription")); + + for (int i = 0; i < fDescription.size(); i++) { + fDescription.set(i, CMIChatColor.translate(fDescription.get(i))); } CMIChatColor color = CMIChatColor.WHITE; @@ -1218,11 +1215,10 @@ public class ConfigManager { continue; } - List commands = new ArrayList<>(); + List commands = commandSection.getStringList("command"); + if (commandSection.isString("command")) commands.add(commandSection.getString("command")); - else if (commandSection.isList("command")) - commands.addAll(commandSection.getStringList("command")); int levelFrom = commandSection.getInt("levelFrom", 0); int levelUntil = commandSection.getInt("levelUntil", maxLevel); @@ -1374,83 +1370,72 @@ public class ConfigManager { continue; Quest quest = new Quest(sqsection.getString("Name", one), job); + ActionType actionType = ActionType.getByName(sqsection.getString("Action")); - if (sqsection.isString("Target")) { - ActionType actionType = ActionType.getByName(sqsection.getString("Action")); - - if (actionType == null) - continue; - + if (actionType != null) { KeyValues kv = getKeyValue(sqsection.getString("Target").toUpperCase(), actionType, jobFullName); + if (kv != null) { int amount = sqsection.getInt("Amount", 1); quest.addObjective(new QuestObjective(actionType, kv.getId(), kv.getMeta(), (kv.getType() + kv.getSubType()).toUpperCase(), amount)); } } - if (sqsection.isList("Objectives")) { - for (String oneObjective : sqsection.getStringList("Objectives")) { - String[] split = oneObjective.split(";", 3); + for (String oneObjective : sqsection.getStringList("Objectives")) { + String[] split = oneObjective.split(";", 3); - if (split.length < 2) { - log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); + if (split.length < 2) { + log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); + continue; + } + + try { + if ((actionType = ActionType.getByName(split[0])) == null) continue; - } - try { - ActionType actionType = ActionType.getByName(split[0]); - if (actionType == null) - continue; + String mats = split[1].toUpperCase(); + String[] co = mats.split(","); - String mats = split[1].toUpperCase(); - String[] co = mats.split(","); + int amount = 1; + if (split.length <= 3) + amount = Integer.parseInt(split[2]); - int amount = 1; - if (split.length <= 3) { - amount = Integer.parseInt(split[2]); + if (co.length > 0) { + for (String materials : co) { + KeyValues kv = getKeyValue(materials, actionType, jobFullName); + + if (kv == null) + continue; + + QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(), + (kv.getType() + kv.getSubType()).toUpperCase(), amount); + quest.addObjective(objective); } + } else { + KeyValues kv = getKeyValue(mats, actionType, jobFullName); - if (co.length > 0) { - for (String materials : co) { - KeyValues kv = getKeyValue(materials, actionType, jobFullName); - if (kv == null) { - continue; - } - - QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(), - (kv.getType() + kv.getSubType()).toUpperCase(), amount); - quest.addObjective(objective); - } - } else { - KeyValues kv = getKeyValue(mats, actionType, jobFullName); - if (kv != null) { - QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(), - (kv.getType() + kv.getSubType()).toUpperCase(), amount); - quest.addObjective(objective); - } + if (kv != null) { + QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(), + (kv.getType() + kv.getSubType()).toUpperCase(), amount); + quest.addObjective(objective); } - } catch (Exception e) { - log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); } + } catch (Exception e) { + log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!"); } } - int chance = sqsection.getInt("Chance", 100); - - List commands = sqsection.getStringList("RewardCommands"), - desc = sqsection.getStringList("RewardDesc"), - areas = sqsection.getStringList("RestrictedAreas"); - quest.setMinLvl(sqsection.getInt("fromLevel")); if (sqsection.isInt("toLevel")) quest.setMaxLvl(sqsection.getInt("toLevel")); quest.setConfigName(one); - quest.setChance(chance); - quest.setRewardCmds(commands); - quest.setDescription(desc); - quest.setRestrictedArea(areas); + quest.setChance(sqsection.getInt("Chance", 100)); + quest.setRewardCmds(sqsection.getStringList("RewardCommands")); + quest.setDescription(sqsection.getStringList("RewardDesc")); + quest.setRestrictedArea(sqsection.getStringList("RestrictedAreas")); + quests.add(quest); } catch (Exception e) { Jobs.consoleMsg("&c[Jobs] Can't load " + one + " quest for " + jobFullName); diff --git a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java index 2fabac83..4d2ad608 100644 --- a/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/NameTranslatorManager.java @@ -46,35 +46,9 @@ public class NameTranslatorManager { case BREW: case FISH: case STRIPLOGS: + String matName = materialName; materialName = materialName.replace(" ", ""); - if (meta != null && !meta.isEmpty()) { - CMIMaterial mat = CMIMaterial.get(materialName + ":" + meta); - NameList nameLs = listOfNames.get(mat); - - if (nameLs == null) { - mat = CMIMaterial.get(materialName.replace(" ", "")); - - if ((nameLs = listOfNames.get(mat)) != null) { - NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", ""))); - - if (nameMeta != null) { - return nameLs + ":" + nameMeta; - } - } - - if (mat == CMIMaterial.NONE) { - String fallbackMaterialName = Arrays.stream(materialName.split("\\s|:")) - .map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()) - .collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This) - - return fallbackMaterialName; - } - - return mat.getName(); - } - } - CMIMaterial mat = CMIMaterial.get(materialName); NameList nameLs = listOfNames.get(mat); @@ -88,6 +62,30 @@ public class NameTranslatorManager { } } + if (meta != null && !meta.isEmpty()) { + mat = CMIMaterial.get(materialName + ":" + meta); + + if ((nameLs = listOfNames.get(mat)) == null) { + mat = CMIMaterial.get(materialName.replace(" ", "")); + + if ((nameLs = listOfNames.get(mat)) != null) { + NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", ""))); + + if (nameMeta != null) { + return nameLs.getName() + ":" + nameMeta.getMeta(); + } + } + + if (mat == CMIMaterial.NONE) { + return Arrays.stream(matName.split("\\s|:")) + .map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()) + .collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This) + } + + return mat.getName(); + } + } + if (id > 0 && meta != null && !meta.isEmpty()) { mat = CMIMaterial.get(id + ":" + meta); nameLs = listOfNames.get(mat); @@ -145,10 +143,9 @@ public class NameTranslatorManager { } } - String fallbackColorName = Arrays.stream(name.split("\\s|:|-")) - .map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()) - .collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This) - return fallbackColorName; + return name == null ? "nocolor" : Arrays.stream(name.split("\\s|:|-")) + .map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase()) + .collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This) case MMKILL: NameList got = listOfMMEntities.get(materialName.toLowerCase()); @@ -311,56 +308,40 @@ public class NameTranslatorManager { } String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData()); - String name = null; + String name = c.getC().getString("ItemList." + mat.toString()); - if (c.getC().isString("ItemList." + mat.toString())) { - name = c.getC().getString("ItemList." + mat.toString()); - } - - if (name == null && c.getC().isConfigurationSection("ItemList." + n)) { + if (name == null) { name = c.getC().getString("ItemList." + n + ".Name"); } if (name == null) { n = mat.getLegacyId() + ":" + mat.getLegacyData(); - if (c.getC().isConfigurationSection("ItemList." + n)) { - name = c.getC().getString("ItemList." + n + ".Name"); - } + name = c.getC().getString("ItemList." + n + ".Name"); } if (name == null) { n = String.valueOf(mat.getLegacyId()); - if (c.getC().isConfigurationSection("ItemList." + n)) { - name = c.getC().getString("ItemList." + n + ".Name"); - } + name = c.getC().getString("ItemList." + n + ".Name"); } if (name == null) { n = String.valueOf(mat.getId()); - if (c.getC().isConfigurationSection("ItemList." + n)) { - name = c.getC().getString("ItemList." + n + ".Name"); - } + name = c.getC().getString("ItemList." + n + ".Name"); } if (name == null) { n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName(); - if (c.getC().isString("ItemList." + n)) { - name = c.getC().getString("ItemList." + n); - } + name = c.getC().getString("ItemList." + n); } if (name == null) { - n = String.valueOf(mat.getLegacyId()) + "-" + mat.getBukkitName(); - if (c.getC().isString("ItemList." + n)) { - name = c.getC().getString("ItemList." + n); - } + n = mat.getLegacyId() + "-" + mat.getBukkitName(); + name = c.getC().getString("ItemList." + n); } if (name == null) { - n = String.valueOf(mat.getId()) + "-" + mat.getBukkitName(); - if (c.getC().isString("ItemList." + n)) { - name = c.getC().getString("ItemList." + n); - } + n = mat.getId() + "-" + mat.getBukkitName(); + name = c.getC().getString("ItemList." + n); } if (name == null) { @@ -376,18 +357,11 @@ public class NameTranslatorManager { continue; String n = Integer.toString(ent.getId()); - - String name = null; - - if (c.getC().isConfigurationSection("EntityList." + n)) { - name = c.getC().getString("EntityList." + n + ".Name"); - } + String name = c.getC().getString("EntityList." + n + ".Name"); if (name == null) { n += "-" + ent.toString(); - if (c.getC().isConfigurationSection("EntityList." + n)) { - name = c.getC().getString("EntityList." + n); - } + name = c.getC().getString("EntityList." + n); } if (name == null) { diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index 1b3e087a..f8459c4a 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -399,7 +399,7 @@ public class ShopManager { if (itemSection.isString("Id")) id = itemSection.getString("Id"); else { - Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems name property. Skipping!"); + Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems item id property. Skipping!"); continue; } diff --git a/src/main/java/com/gamingmesh/jobs/container/ActionType.java b/src/main/java/com/gamingmesh/jobs/container/ActionType.java index 70148428..0b9a1a9d 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ActionType.java +++ b/src/main/java/com/gamingmesh/jobs/container/ActionType.java @@ -54,11 +54,15 @@ public enum ActionType { } public static ActionType getByName(String name) { - name = name.replace("_", ""); - for (ActionType one : ActionType.values()) { - if (one.name.equalsIgnoreCase(name)) - return one; + if (name != null) { + name = name.replace("_", ""); + + for (ActionType one : ActionType.values()) { + if (one.name.equalsIgnoreCase(name)) + return one; + } } + return null; } }