mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +01:00
Improvement on limitedItems processing
This commit is contained in:
parent
bd13bd52d0
commit
6a539686dd
@ -471,7 +471,6 @@ public class ConfigManager {
|
|||||||
cfg.addComment(pt + ".limitedItems", "Limit item use to jobs level");
|
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", "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.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.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");
|
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();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean informed = false;
|
boolean informedGUI = false;
|
||||||
|
boolean informedLimited = false;
|
||||||
|
|
||||||
private Job loadJobs(ConfigurationSection jobsSection) {
|
private Job loadJobs(ConfigurationSection jobsSection) {
|
||||||
java.util.logging.Logger log = Jobs.getPluginLogger();
|
java.util.logging.Logger log = Jobs.getPluginLogger();
|
||||||
@ -1205,9 +1205,9 @@ public class ConfigManager {
|
|||||||
if (material != CMIMaterial.NONE)
|
if (material != CMIMaterial.NONE)
|
||||||
guiItem = material.newItemStack();
|
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");
|
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")) {
|
} 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();
|
||||||
@ -1387,6 +1387,10 @@ public class ConfigManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String node = itemKey.toLowerCase();
|
||||||
|
|
||||||
|
if (itemSection.contains("id")) {
|
||||||
|
|
||||||
CMIMaterial mat = CMIMaterial.NONE;
|
CMIMaterial mat = CMIMaterial.NONE;
|
||||||
|
|
||||||
if (itemSection.isInt("id")) {
|
if (itemSection.isInt("id")) {
|
||||||
@ -1429,9 +1433,26 @@ public class ConfigManager {
|
|||||||
enchants.put(ench, level);
|
enchants.put(ench, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
String node = itemKey.toLowerCase();
|
|
||||||
|
|
||||||
jobLimitedItems.put(node, new JobLimitedItems(node, mat, 1, itemSection.getString("name"), lore, enchants, itemSection.getInt("level")));
|
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);
|
job.setLimitedItems(jobLimitedItems);
|
||||||
|
@ -29,20 +29,30 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import net.Zrips.CMILib.Colors.CMIChatColor;
|
import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||||
|
import net.Zrips.CMILib.Container.CMINumber;
|
||||||
|
import net.Zrips.CMILib.Items.CMIItemStack;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
|
|
||||||
public class JobLimitedItems {
|
public class JobLimitedItems {
|
||||||
private String node;
|
private String node;
|
||||||
CMIMaterial mat;
|
CMIMaterial mat;
|
||||||
private int amount;
|
|
||||||
private String name;
|
private String name;
|
||||||
|
private ItemStack item;
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
private Map<Enchantment, Integer> enchants;
|
private Map<Enchantment, Integer> enchants;
|
||||||
private int level;
|
private int level;
|
||||||
|
|
||||||
public JobLimitedItems(String node, CMIMaterial material, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, 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.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.name = name;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
this.enchants = enchants;
|
this.enchants = enchants;
|
||||||
@ -50,23 +60,34 @@ public class JobLimitedItems {
|
|||||||
this.mat = material;
|
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() {
|
public String getNode() {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemStack(Player player) {
|
public ItemStack getItemStack(Player player) {
|
||||||
|
|
||||||
ItemStack item = mat.newItemStack();
|
ItemStack item = this.item.clone();
|
||||||
item.setAmount(amount);
|
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null)
|
|
||||||
meta.setDisplayName(CMIChatColor.translate(name));
|
|
||||||
|
|
||||||
if (lore != null && !lore.isEmpty()) {
|
if (lore != null && !lore.isEmpty()) {
|
||||||
List<String> translatedLore = new ArrayList<>();
|
List<String> translatedLore = new ArrayList<>();
|
||||||
for (String oneLore : lore) {
|
for (String oneLore : lore) {
|
||||||
@ -76,11 +97,6 @@ public class JobLimitedItems {
|
|||||||
meta.setLore(translatedLore);
|
meta.setLore(translatedLore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enchants != null)
|
|
||||||
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
|
|
||||||
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user