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:
parent
bd13bd52d0
commit
6a539686dd
@ -470,12 +470,11 @@ 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.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.get(pt + ".limitedItems.firstOne.level", 5);
|
||||
cfg.get(pt + ".limitedItems.firstOne.level", 5);
|
||||
|
||||
cfg.save();
|
||||
}
|
||||
@ -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();
|
||||
@ -1169,7 +1169,7 @@ public class ConfigManager {
|
||||
CMIItemStack item = CMIItemStack.deserialize(guiSection.getString("ItemStack"), ahead);
|
||||
if (!ahead.isAsyncHead() && item != null && item.getCMIType().isNone())
|
||||
gItem.setGuiItem(item.getItemStack());
|
||||
|
||||
|
||||
} else if (guiSection.isString("Item")) {
|
||||
String item = guiSection.getString("Item");
|
||||
|
||||
@ -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,51 +1387,72 @@ public class ConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
CMIMaterial mat = CMIMaterial.NONE;
|
||||
|
||||
if (itemSection.isInt("id")) {
|
||||
mat = CMIMaterial.get(itemSection.getInt("id"));
|
||||
} else {
|
||||
mat = CMIMaterial.get(itemSection.getString("id"));
|
||||
}
|
||||
|
||||
if (mat == CMIMaterial.NONE) {
|
||||
log.warning("Job " + jobConfigName + " has incorrect limitedItems material id!");
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> lore = itemSection.getStringList("lore");
|
||||
|
||||
for (int a = 0; a < lore.size(); a++) {
|
||||
lore.set(a, CMIChatColor.translate(lore.get(a)));
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
for (String eachLine : itemSection.getStringList("enchants")) {
|
||||
String[] split = eachLine.split("=", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
|
||||
if (ench == null)
|
||||
continue;
|
||||
|
||||
int level = -1;
|
||||
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (level != -1)
|
||||
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 (itemSection.contains("id")) {
|
||||
|
||||
CMIMaterial mat = CMIMaterial.NONE;
|
||||
|
||||
if (itemSection.isInt("id")) {
|
||||
mat = CMIMaterial.get(itemSection.getInt("id"));
|
||||
} else {
|
||||
mat = CMIMaterial.get(itemSection.getString("id"));
|
||||
}
|
||||
|
||||
if (mat == CMIMaterial.NONE) {
|
||||
log.warning("Job " + jobConfigName + " has incorrect limitedItems material id!");
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> lore = itemSection.getStringList("lore");
|
||||
|
||||
for (int a = 0; a < lore.size(); a++) {
|
||||
lore.set(a, CMIChatColor.translate(lore.get(a)));
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
for (String eachLine : itemSection.getStringList("enchants")) {
|
||||
String[] split = eachLine.split("=", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
|
||||
if (ench == null)
|
||||
continue;
|
||||
|
||||
int level = -1;
|
||||
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (level != -1)
|
||||
enchants.put(ench, 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);
|
||||
|
@ -29,84 +29,100 @@ 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;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.enchants = enchants;
|
||||
this.level = level;
|
||||
this.mat = material;
|
||||
this.node = node;
|
||||
|
||||
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;
|
||||
this.level = level;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
|
||||
}
|
||||
|
||||
if (lore != null && !lore.isEmpty()) {
|
||||
List<String> translatedLore = new ArrayList<>();
|
||||
for (String oneLore : lore) {
|
||||
translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName())));
|
||||
}
|
||||
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);
|
||||
return item;
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getId() {
|
||||
return mat.getId();
|
||||
return mat.getId();
|
||||
}
|
||||
|
||||
public CMIMaterial getType(){
|
||||
return mat;
|
||||
public CMIMaterial getType() {
|
||||
return mat;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getLore() {
|
||||
return lore;
|
||||
return lore;
|
||||
}
|
||||
|
||||
public Map<Enchantment, Integer> getEnchants() {
|
||||
return enchants;
|
||||
return enchants;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user