From 6ec44a92cf827af3e469d9b18dbc5bfca7954450 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 4 Jul 2020 16:43:10 +0200 Subject: [PATCH] Now you can add slot numbers to browse gui items Closes #840 --- .../gamingmesh/jobs/CMILib/CMIEntityType.java | 5 +- .../gamingmesh/jobs/CMILib/CMIMaterial.java | 9 ++- .../com/gamingmesh/jobs/Gui/GuiManager.java | 13 ++-- .../gamingmesh/jobs/config/ConfigManager.java | 60 ++++++++++--------- .../com/gamingmesh/jobs/container/Job.java | 43 ++++++------- 5 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIEntityType.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIEntityType.java index 2f811857..fae00bc4 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIEntityType.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIEntityType.java @@ -2,7 +2,6 @@ package com.gamingmesh.jobs.CMILib; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import org.bukkit.block.CreatureSpawner; @@ -261,7 +260,6 @@ public enum CMIEntityType { private String name; private String secondaryName; EntityType type = null; - public static HashMap cache = new HashMap<>(); CMIEntityType(int id, String name, List headTextures) { this(id, name, null, headTextures); @@ -335,6 +333,7 @@ public enum CMIEntityType { main = name.split("_")[0]; sub = name.split("_")[1]; } + if (name.contains(":")) { main = name.split(":")[0]; sub = name.split(":")[1]; @@ -348,7 +347,7 @@ public enum CMIEntityType { Integer id = null; try { id = Integer.parseInt(main); - } catch (Exception e) { + } catch (NumberFormatException e) { } for (CMIEntityType one : CMIEntityType.values()) { diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java index e652cd78..128a77f9 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIMaterial.java @@ -1364,7 +1364,7 @@ public enum CMIMaterial { return CMIMaterial.NONE; Integer data = null; - id = id.replace("_", "").replace(" ", "").replace("minecraft:", "").toLowerCase(); + id = id.replaceAll("_| |minecraft:", "").toLowerCase(); if (id.contains(":")) { try { @@ -1392,10 +1392,15 @@ public enum CMIMaterial { } } catch (Exception ex) { } + + String metaTag = id.split(":")[1]; + CMIMaterial mat = ItemManager.byName.get(id + ":" + metaTag); + if (mat != null) { + return mat; + } } CMIMaterial mat = ItemManager.byName.get(id); - if (mat != null) { return mat; } diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index ed9cde67..776e4781 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -60,24 +60,26 @@ public class GuiManager { // Changing start position to 0 in case we have more jobs then we can fit in current setup pos = JobsList.size() > 28 ? JobsList.size() <= 42 ? 0 : -1 : pos; + int group = 0; main: for (int z = 0; z < JobsList.size(); z++) { group++; if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) { group = 1; + // Only add skip if we can fit all of them in max sized Gui if (JobsList.size() <= 42) { pos += Jobs.getGCManager().getJobsGUISkipAmount(); - } } pos++; + if (i >= JobsList.size()) break main; - Job job = JobsList.get(i); + Job job = JobsList.get(i); ArrayList Lore = new ArrayList<>(); for (JobProgression onePJob : JPlayer.getJobProgression()) { @@ -123,13 +125,16 @@ public class GuiManager { Lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick")); ItemStack GuiItem = job.getGuiItem(); - ItemMeta meta = GuiItem.getItemMeta(); meta.setDisplayName(job.getChatColor() + job.getName()); meta.setLore(Lore); GuiItem.setItemMeta(meta); - gui.addButton(new CMIGuiButton(pos, GuiItem) { + int lastPos = pos; + if (job.getGuiSlot() >= 0) + lastPos = job.getGuiSlot(); + + gui.addButton(new CMIGuiButton(lastPos, GuiItem) { @Override public void click(GUIClickType type) { diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 44c2e1e5..1b325fc4 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -164,6 +164,8 @@ public class ConfigManager { cfg.addComment(pt + ".Gui", "GUI icon information when using GUI function"); cfg.addComment(pt + ".Gui.Item", "Name of the material"); cfg.get(pt + ".Gui.Item", "LOG:2"); + cfg.addComment(pt + ".Gui.slot", "Slot number to show the item in the specified row"); + cfg.get(pt + ".Gui.slot", 5); cfg.addComment(pt + ".Gui.Enchantments", "Enchants of the item"); cfg.get(pt + ".Gui.Enchantments", Arrays.asList("DURABILITY:1")); @@ -603,6 +605,11 @@ public class ConfigManager { return null; } + if (":ALL".equalsIgnoreCase(subType)) { + meta = "ALL"; + type = CMIMaterial.getGeneralMaterialName(type); + } + KeyValues kv = new KeyValues(); kv.setId(id); kv.setMeta(meta); @@ -802,6 +809,7 @@ public class ConfigManager { } // Gui item + int guiSlot = -1; ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); if (jobSection.contains("Gui")) { ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); @@ -838,37 +846,29 @@ public class ConfigManager { if (material != null) GUIitem = material.newItemStack(); - - if (guiSection.contains("Enchantments")) { - for (String str4 : guiSection.getStringList("Enchantments")) { - String[] enchantid = str4.split(":"); - if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { - EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); - enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(enchantid[0]), Integer.parseInt(enchantid[1]), true); - GUIitem.setItemMeta(enchantMeta); - } else - GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(enchantid[0]), Integer.parseInt(enchantid[1])); - } - } else if (guiSection.contains("CustomSkull")) { - GUIitem = Util.getSkull(guiSection.getString("CustomSkull")); - } } else if (guiSection.isInt("Id") && guiSection.isInt("Data")) { GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); - if (guiSection.contains("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])); - } - } else if (guiSection.contains("CustomSkull")) { - GUIitem = Util.getSkull(guiSection.getString("CustomSkull")); - } } 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.isString("CustomSkull")) { + GUIitem = Util.getSkull(guiSection.getString("CustomSkull")); + } + + if (guiSection.getInt("slot", -1) >= 0) + guiSlot = guiSection.getInt("slot"); } // Permissions @@ -1056,7 +1056,7 @@ public class ConfigManager { } Job job = new Job(jobKey, jobFullName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, vipmaxLevel, maxSlots, jobPermissions, jobCommand, - jobConditions, jobItems, jobLimitedItems, JobsCommandOnJoin, JobsCommandOnLeave, GUIitem, bossbar, rejoinCd, worldBlacklist); + jobConditions, jobItems, jobLimitedItems, JobsCommandOnJoin, JobsCommandOnLeave, GUIitem, guiSlot, bossbar, rejoinCd, worldBlacklist); job.setFullDescription(fDescription); job.setMoneyEquation(incomeEquation); @@ -1176,6 +1176,10 @@ public class ConfigManager { if (typeSection != null) { for (String key : typeSection.getKeys(false)) { ConfigurationSection section = typeSection.getConfigurationSection(key); + if (section == null) { + continue; + } + String myKey = key, type = null, subType = "", diff --git a/src/main/java/com/gamingmesh/jobs/container/Job.java b/src/main/java/com/gamingmesh/jobs/container/Job.java index becc5806..1d8ec007 100644 --- a/src/main/java/com/gamingmesh/jobs/container/Job.java +++ b/src/main/java/com/gamingmesh/jobs/container/Job.java @@ -36,26 +36,36 @@ import java.util.function.BiPredicate; public class Job { private EnumMap> jobInfo = new EnumMap<>(ActionType.class); + private List jobPermissions; private List jobCommands; private List jobConditions; + private HashMap jobItems; private HashMap jobLimitedItems; + private String jobName = "N/A"; private String fullName = "N/A"; + // job short name (for use in multiple jobs) private String jobShortName; private String description; + private ChatColor jobColour; private Parser maxExpEquation; private DisplayMethod displayMethod; + private int maxLevel; private int vipmaxLevel = 0; + // max number of people allowed with this job on the server. private Integer maxSlots; - private List CmdOnJoin = new ArrayList<>(); - private List CmdOnLeave = new ArrayList<>(); + + private List CmdOnJoin = new ArrayList<>(), CmdOnLeave = new ArrayList<>(); + private ItemStack GUIitem; + private int guiSlot = 0; + private Long rejoinCd = 0L; private int totalPlayers = -1; @@ -75,29 +85,9 @@ public class Job { private int id = 0; - /** - * Constructor - * @param jobName - the name of the job - * @param fullName - the full name of the job - * @param jobShortName - the shortened version of the name of the job. - * @param description - a short description of the job. - * @param jobColour - the colour of the job title as displayed in chat. - * @param maxExpEquation - the equation by which the exp needed to level up is calculated - * @param displayMethod - the display method for this job. - * @param maxLevel - the maximum level allowed (null for no max level) - * @param vipmaxLevel - the maximum vip level allowed (null for no max level) - * @param maxSlots - the maximum number of people allowed to have this job at one time (null for no limits) - * @param jobPermissions - permissions gained for having the job - * @param jobCommands - commands to perform on levelup - * @param jobItems - items with boost - * @param jobLimitedItems - limited items by lvl - * @param CmdOnJoin - commands performed on player join - * @param CmdOnLeave - commands performed on player leave - * @param jobConditions - jobs conditions - */ public Job(String jobName, String fullName, String jobShortName, String description, ChatColor 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, String bossbar, Long rejoinCD, List worldBlacklist) { + HashMap jobLimitedItems, List CmdOnJoin, List CmdOnLeave, ItemStack GUIitem, int guiSlot, String bossbar, Long rejoinCD, List worldBlacklist) { this.jobName = jobName == null ? "" : jobName; this.fullName = fullName == null ? "" : fullName; this.jobShortName = jobShortName; @@ -116,6 +106,7 @@ public class Job { this.CmdOnJoin = CmdOnJoin; this.CmdOnLeave = CmdOnLeave; this.GUIitem = GUIitem; + this.guiSlot = guiSlot; this.bossbar = bossbar; this.rejoinCd = rejoinCD; this.worldBlacklist = worldBlacklist; @@ -199,6 +190,10 @@ public class Job { return GUIitem; } + public int getGuiSlot() { + return guiSlot; + } + /** * Sets job info for action type * @param type - The action type @@ -213,7 +208,6 @@ public class Job { * @param type - The action type * @return Job info list */ - public List getJobInfo(ActionType type) { return jobInfo.get(type); } @@ -222,7 +216,6 @@ public class Job { * Gets the job info list * @return Job info list */ - public EnumMap> getJobInfoList() { return jobInfo; }