1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +01:00

Improvement on limitedItems processing

This commit is contained in:
Zrips 2023-11-15 17:58:14 +02:00
parent bd13bd52d0
commit 6a539686dd
2 changed files with 127 additions and 90 deletions

View File

@ -471,7 +471,6 @@ public class ConfigManager {
cfg.addComment(pt + ".limitedItems", "Limit item use to jobs level");
cfg.addComment(pt + ".limitedItems.firstOne", "Just name, don't have any impact");
cfg.addComment(pt + ".limitedItems.firstOne.ItemStack", "Tool/Weapon data. More information on usage www.zrips.net/cmi/commands/icwol/");
cfg.get(pt + ".limitedItems.firstOne.ItemStack", "DIAMOND_PICKAXE;n{&8Miner_Pickaxe};l{&eBobs_pick\\n&710%_bonus_XP};DAMAGE_ALL:1,FIRE_ASPECT:1");
cfg.addComment(pt + ".limitedItems.firstOne.level", "Level of this job player can start using this item");
@ -1007,7 +1006,8 @@ public class ConfigManager {
return result.toString();
}
boolean informed = false;
boolean informedGUI = false;
boolean informedLimited = false;
private Job loadJobs(ConfigurationSection jobsSection) {
java.util.logging.Logger log = Jobs.getPluginLogger();
@ -1205,9 +1205,9 @@ public class ConfigManager {
if (material != CMIMaterial.NONE)
guiItem = material.newItemStack();
if (!informed) {
if (!informedGUI) {
CMIMessages.consoleMessage("&5Update " + jobConfigName + " jobs gui item section to use `ItemStack` instead of `Item` sections format. More information inside _EXAMPLE job file");
informed = true;
informedGUI = true;
}
} else if (guiSection.isInt("Id") && guiSection.isInt("Data")) {
guiItem = CMIMaterial.get(guiSection.getInt("Id"), guiSection.getInt("Data")).newItemStack();
@ -1387,6 +1387,10 @@ public class ConfigManager {
continue;
}
String node = itemKey.toLowerCase();
if (itemSection.contains("id")) {
CMIMaterial mat = CMIMaterial.NONE;
if (itemSection.isInt("id")) {
@ -1429,9 +1433,26 @@ public class ConfigManager {
enchants.put(ench, level);
}
String node = itemKey.toLowerCase();
jobLimitedItems.put(node, new JobLimitedItems(node, mat, 1, itemSection.getString("name"), lore, enchants, itemSection.getInt("level")));
if (!informedLimited) {
CMIMessages.consoleMessage("&5Update " + jobConfigName
+ " jobs limited items section to use `ItemStack` instead of `id` sections format. More information inside _EXAMPLE job file");
informedLimited = true;
}
} else if (itemSection.contains("ItemStack")) {
CMIItemStack limitedItem = CMIItemStack.deserialize(itemSection.getString("ItemStack"));
if (limitedItem == null || limitedItem.getCMIType().isNone()) {
log.warning("Job " + jobConfigName + " has incorrect limitedItems material id!");
continue;
}
jobLimitedItems.put(node, new JobLimitedItems(node, limitedItem.getItemStack(), itemSection.getInt("level")));
}
}
}
job.setLimitedItems(jobLimitedItems);

View File

@ -29,20 +29,30 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMINumber;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
public class JobLimitedItems {
private String node;
CMIMaterial mat;
private int amount;
private String name;
private ItemStack item;
private List<String> lore;
private Map<Enchantment, Integer> enchants;
private int level;
public JobLimitedItems(String node, CMIMaterial material, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, int level) {
this.node = node;
this.amount = amount;
CMIItemStack ct = material.newCMIItemStack(CMINumber.clamp(amount, 1, material.getMaterial().getMaxStackSize()));
ct.setDisplayName(name);
ct.setLore(lore);
for (Entry<Enchantment, Integer> one : enchants.entrySet()) {
ct.addEnchant(one.getKey(), one.getValue());
}
this.item = ct.getItemStack();
this.name = name;
this.lore = lore;
this.enchants = enchants;
@ -50,23 +60,34 @@ public class JobLimitedItems {
this.mat = material;
}
public JobLimitedItems(String node, ItemStack item, int level) {
this.node = node;
this.item = item;
if (this.item.hasItemMeta()) {
ItemMeta meta = this.item.getItemMeta();
if (meta.hasDisplayName())
name = meta.getDisplayName();
if (meta.hasLore())
lore = meta.getLore();
}
enchants = item.getEnchantments();
this.level = level;
}
public String getNode() {
return node;
}
public ItemStack getItemStack(Player player) {
ItemStack item = mat.newItemStack();
item.setAmount(amount);
ItemStack item = this.item.clone();
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item;
}
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null && !lore.isEmpty()) {
List<String> translatedLore = new ArrayList<>();
for (String oneLore : lore) {
@ -76,11 +97,6 @@ public class JobLimitedItems {
meta.setLore(translatedLore);
}
if (enchants != null)
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
item.setItemMeta(meta);
return item;
}
@ -90,7 +106,7 @@ public class JobLimitedItems {
return mat.getId();
}
public CMIMaterial getType(){
public CMIMaterial getType() {
return mat;
}