1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-08 01:08:23 +01:00

Now you can add slot numbers to browse gui items

Closes #840
This commit is contained in:
montlikadani 2020-07-04 16:43:10 +02:00
parent 433f87f738
commit 6ec44a92cf
5 changed files with 68 additions and 62 deletions

View File

@ -2,7 +2,6 @@ package com.gamingmesh.jobs.CMILib;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
@ -261,7 +260,6 @@ public enum CMIEntityType {
private String name; private String name;
private String secondaryName; private String secondaryName;
EntityType type = null; EntityType type = null;
public static HashMap<String, ItemStack> cache = new HashMap<>();
CMIEntityType(int id, String name, List<String> headTextures) { CMIEntityType(int id, String name, List<String> headTextures) {
this(id, name, null, headTextures); this(id, name, null, headTextures);
@ -335,6 +333,7 @@ public enum CMIEntityType {
main = name.split("_")[0]; main = name.split("_")[0];
sub = name.split("_")[1]; sub = name.split("_")[1];
} }
if (name.contains(":")) { if (name.contains(":")) {
main = name.split(":")[0]; main = name.split(":")[0];
sub = name.split(":")[1]; sub = name.split(":")[1];
@ -348,7 +347,7 @@ public enum CMIEntityType {
Integer id = null; Integer id = null;
try { try {
id = Integer.parseInt(main); id = Integer.parseInt(main);
} catch (Exception e) { } catch (NumberFormatException e) {
} }
for (CMIEntityType one : CMIEntityType.values()) { for (CMIEntityType one : CMIEntityType.values()) {

View File

@ -1364,7 +1364,7 @@ public enum CMIMaterial {
return CMIMaterial.NONE; return CMIMaterial.NONE;
Integer data = null; Integer data = null;
id = id.replace("_", "").replace(" ", "").replace("minecraft:", "").toLowerCase(); id = id.replaceAll("_| |minecraft:", "").toLowerCase();
if (id.contains(":")) { if (id.contains(":")) {
try { try {
@ -1392,10 +1392,15 @@ public enum CMIMaterial {
} }
} catch (Exception ex) { } 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); CMIMaterial mat = ItemManager.byName.get(id);
if (mat != null) { if (mat != null) {
return mat; return mat;
} }

View File

@ -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 // 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; pos = JobsList.size() > 28 ? JobsList.size() <= 42 ? 0 : -1 : pos;
int group = 0; int group = 0;
main: for (int z = 0; z < JobsList.size(); z++) { main: for (int z = 0; z < JobsList.size(); z++) {
group++; group++;
if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) { if (group > Jobs.getGCManager().getJobsGUIGroupAmount()) {
group = 1; group = 1;
// Only add skip if we can fit all of them in max sized Gui // Only add skip if we can fit all of them in max sized Gui
if (JobsList.size() <= 42) { if (JobsList.size() <= 42) {
pos += Jobs.getGCManager().getJobsGUISkipAmount(); pos += Jobs.getGCManager().getJobsGUISkipAmount();
} }
} }
pos++; pos++;
if (i >= JobsList.size()) if (i >= JobsList.size())
break main; break main;
Job job = JobsList.get(i);
Job job = JobsList.get(i);
ArrayList<String> Lore = new ArrayList<>(); ArrayList<String> Lore = new ArrayList<>();
for (JobProgression onePJob : JPlayer.getJobProgression()) { for (JobProgression onePJob : JPlayer.getJobProgression()) {
@ -123,13 +125,16 @@ public class GuiManager {
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick")); Lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
ItemStack GuiItem = job.getGuiItem(); ItemStack GuiItem = job.getGuiItem();
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = GuiItem.getItemMeta();
meta.setDisplayName(job.getChatColor() + job.getName()); meta.setDisplayName(job.getChatColor() + job.getName());
meta.setLore(Lore); meta.setLore(Lore);
GuiItem.setItemMeta(meta); 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 @Override
public void click(GUIClickType type) { public void click(GUIClickType type) {

View File

@ -164,6 +164,8 @@ public class ConfigManager {
cfg.addComment(pt + ".Gui", "GUI icon information when using GUI function"); cfg.addComment(pt + ".Gui", "GUI icon information when using GUI function");
cfg.addComment(pt + ".Gui.Item", "Name of the material"); cfg.addComment(pt + ".Gui.Item", "Name of the material");
cfg.get(pt + ".Gui.Item", "LOG:2"); 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.addComment(pt + ".Gui.Enchantments", "Enchants of the item");
cfg.get(pt + ".Gui.Enchantments", Arrays.asList("DURABILITY:1")); cfg.get(pt + ".Gui.Enchantments", Arrays.asList("DURABILITY:1"));
@ -603,6 +605,11 @@ public class ConfigManager {
return null; return null;
} }
if (":ALL".equalsIgnoreCase(subType)) {
meta = "ALL";
type = CMIMaterial.getGeneralMaterialName(type);
}
KeyValues kv = new KeyValues(); KeyValues kv = new KeyValues();
kv.setId(id); kv.setId(id);
kv.setMeta(meta); kv.setMeta(meta);
@ -802,6 +809,7 @@ public class ConfigManager {
} }
// Gui item // Gui item
int guiSlot = -1;
ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack(); ItemStack GUIitem = CMIMaterial.GREEN_WOOL.newItemStack();
if (jobSection.contains("Gui")) { if (jobSection.contains("Gui")) {
ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui"); ConfigurationSection guiSection = jobSection.getConfigurationSection("Gui");
@ -838,37 +846,29 @@ public class ConfigManager {
if (material != null) if (material != null)
GUIitem = material.newItemStack(); 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")) { } else if (guiSection.isInt("Id") && guiSection.isInt("Data")) {
GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack(); GUIitem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
if (guiSection.contains("Enchantments")) { } 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")) { for (String str4 : guiSection.getStringList("Enchantments")) {
String[] id = str4.split(":"); String[] id = str4.split(":");
if ((GUIitem.getItemMeta() instanceof EnchantmentStorageMeta)) { if (GUIitem.getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta(); EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) GUIitem.getItemMeta();
enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]), true); enchantMeta.addStoredEnchant(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]), true);
GUIitem.setItemMeta(enchantMeta); GUIitem.setItemMeta(enchantMeta);
} else } else
GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1])); GUIitem.addUnsafeEnchantment(CMIEnchantment.getEnchantment(id[0]), Integer.parseInt(id[1]));
} }
} else if (guiSection.contains("CustomSkull")) { }
if (guiSection.isString("CustomSkull")) {
GUIitem = Util.getSkull(guiSection.getString("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.getInt("slot", -1) >= 0)
guiSlot = guiSection.getInt("slot");
} }
// Permissions // Permissions
@ -1056,7 +1056,7 @@ public class ConfigManager {
} }
Job job = new Job(jobKey, jobFullName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, vipmaxLevel, maxSlots, jobPermissions, jobCommand, 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.setFullDescription(fDescription);
job.setMoneyEquation(incomeEquation); job.setMoneyEquation(incomeEquation);
@ -1176,6 +1176,10 @@ public class ConfigManager {
if (typeSection != null) { if (typeSection != null) {
for (String key : typeSection.getKeys(false)) { for (String key : typeSection.getKeys(false)) {
ConfigurationSection section = typeSection.getConfigurationSection(key); ConfigurationSection section = typeSection.getConfigurationSection(key);
if (section == null) {
continue;
}
String myKey = key, String myKey = key,
type = null, type = null,
subType = "", subType = "",

View File

@ -36,26 +36,36 @@ import java.util.function.BiPredicate;
public class Job { public class Job {
private EnumMap<ActionType, List<JobInfo>> jobInfo = new EnumMap<>(ActionType.class); private EnumMap<ActionType, List<JobInfo>> jobInfo = new EnumMap<>(ActionType.class);
private List<JobPermission> jobPermissions; private List<JobPermission> jobPermissions;
private List<JobCommands> jobCommands; private List<JobCommands> jobCommands;
private List<JobConditions> jobConditions; private List<JobConditions> jobConditions;
private HashMap<String, JobItems> jobItems; private HashMap<String, JobItems> jobItems;
private HashMap<String, JobLimitedItems> jobLimitedItems; private HashMap<String, JobLimitedItems> jobLimitedItems;
private String jobName = "N/A"; private String jobName = "N/A";
private String fullName = "N/A"; private String fullName = "N/A";
// job short name (for use in multiple jobs) // job short name (for use in multiple jobs)
private String jobShortName; private String jobShortName;
private String description; private String description;
private ChatColor jobColour; private ChatColor jobColour;
private Parser maxExpEquation; private Parser maxExpEquation;
private DisplayMethod displayMethod; private DisplayMethod displayMethod;
private int maxLevel; private int maxLevel;
private int vipmaxLevel = 0; private int vipmaxLevel = 0;
// max number of people allowed with this job on the server. // max number of people allowed with this job on the server.
private Integer maxSlots; private Integer maxSlots;
private List<String> CmdOnJoin = new ArrayList<>();
private List<String> CmdOnLeave = new ArrayList<>(); private List<String> CmdOnJoin = new ArrayList<>(), CmdOnLeave = new ArrayList<>();
private ItemStack GUIitem; private ItemStack GUIitem;
private int guiSlot = 0;
private Long rejoinCd = 0L; private Long rejoinCd = 0L;
private int totalPlayers = -1; private int totalPlayers = -1;
@ -75,29 +85,9 @@ public class Job {
private int id = 0; 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, public Job(String jobName, String fullName, String jobShortName, String description, ChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems, int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, String bossbar, Long rejoinCD, List<String> worldBlacklist) { HashMap<String, JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this.jobName = jobName == null ? "" : jobName; this.jobName = jobName == null ? "" : jobName;
this.fullName = fullName == null ? "" : fullName; this.fullName = fullName == null ? "" : fullName;
this.jobShortName = jobShortName; this.jobShortName = jobShortName;
@ -116,6 +106,7 @@ public class Job {
this.CmdOnJoin = CmdOnJoin; this.CmdOnJoin = CmdOnJoin;
this.CmdOnLeave = CmdOnLeave; this.CmdOnLeave = CmdOnLeave;
this.GUIitem = GUIitem; this.GUIitem = GUIitem;
this.guiSlot = guiSlot;
this.bossbar = bossbar; this.bossbar = bossbar;
this.rejoinCd = rejoinCD; this.rejoinCd = rejoinCD;
this.worldBlacklist = worldBlacklist; this.worldBlacklist = worldBlacklist;
@ -199,6 +190,10 @@ public class Job {
return GUIitem; return GUIitem;
} }
public int getGuiSlot() {
return guiSlot;
}
/** /**
* Sets job info for action type * Sets job info for action type
* @param type - The action type * @param type - The action type
@ -213,7 +208,6 @@ public class Job {
* @param type - The action type * @param type - The action type
* @return Job info list * @return Job info list
*/ */
public List<JobInfo> getJobInfo(ActionType type) { public List<JobInfo> getJobInfo(ActionType type) {
return jobInfo.get(type); return jobInfo.get(type);
} }
@ -222,7 +216,6 @@ public class Job {
* Gets the job info list * Gets the job info list
* @return Job info list * @return Job info list
*/ */
public EnumMap<ActionType, List<JobInfo>> getJobInfoList() { public EnumMap<ActionType, List<JobInfo>> getJobInfoList() {
return jobInfo; return jobInfo;
} }