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

Boosted, limited and shop items new format recognition

This commit is contained in:
Zrips 2023-11-16 16:39:29 +02:00
parent 6a539686dd
commit 0ee8b59401
13 changed files with 610 additions and 787 deletions

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -10,8 +8,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Color;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.BoostMultiplier;
@ -20,216 +18,191 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.NBT.CMINBT;
public final class ItemBoostManager {
private static final Map<String, JobItems> ITEMS = new HashMap<>();
private static final Map<String, JobItems> LEGACY = new HashMap<>();
@SuppressWarnings("deprecation")
static boolean informed = false;
public static void load() {
ConfigReader cfg;
try {
cfg = new ConfigReader(Jobs.getInstance(), "boostedItems.yml");
} catch (Exception e2) {
e2.printStackTrace();
return;
}
ConfigReader cfg;
try {
cfg = new ConfigReader(Jobs.getInstance(), "boostedItems.yml");
} catch (Exception e2) {
e2.printStackTrace();
return;
}
ITEMS.clear();
LEGACY.clear();
ITEMS.clear();
// Converting from existing records in Jobs from old format which was located in jobConfig.yml file
boolean save = false;
for (Job one : Jobs.getJobs()) {
for (Entry<String, JobItems> oneI : one.getItemBonus().entrySet()) {
JobItems item = oneI.getValue();
Set<String> keys = cfg.getC().getKeys(false);
String name = one.getName() + "_" + oneI.getKey();
org.bukkit.inventory.ItemStack stack = item.getItemStack(null);
cfg.addComment("exampleBoost", "Attention! If category name has _ in it, that means its legacy item which was converted from jobConfig.yml file",
"Keep this format until you will be sure that all legacy items have been converted throw usage, which is automatic process when player uses items with boost in them",
"",
"Name which will be used to identify this particular item boost",
"This is EXAMPLE boost and will be ignored");
cfg.addComment("exampleBoost.ItemStack", "Item information, on usage read more at https://www.zrips.net/cmi/commands/icwol/",
"You can use ingame command /jobs edititemboost to give particular boost to any item you are holding");
cfg.get("exampleBoost.ItemStack", "Golden_shovel;n{&2Custom_item_name};l{&2Some_random\\n&5Lore_with_some\\n{#pink}Colors};FIRE_ASPECT:1,DAMAGE_ALL:1");
cfg.getC().set(name + ".id", CMIMaterial.get(stack).toString());
cfg.getC().set(name + ".jobs", Arrays.asList(one.getName()));
if (stack.hasItemMeta()) {
cfg.getC().set(name + ".name", stack.getItemMeta().hasDisplayName() ? CMIChatColor.deColorize(stack.getItemMeta().getDisplayName()) : null);
cfg.getC().set(name + ".lore", stack.getItemMeta().hasLore() ? CMIChatColor.deColorize(stack.getItemMeta().getLore()) : null);
}
List<String> ench = new ArrayList<>();
for (Entry<Enchantment, Integer> oneE : stack.getEnchantments().entrySet()) {
ench.add(CMIEnchantment.get(oneE.getKey()) + "=" + oneE.getValue());
}
cfg.getC().set(name + ".enchants", ench);
for (CurrencyType oneC : CurrencyType.values()) {
cfg.getC().set(name + "." + oneC.toString().toLowerCase() + "Boost", ((int) (item.getBoost().get(oneC) * 100D) / 100D) + 1D);
}
save = true;
}
cfg.addComment("exampleBoost.moneyBoost", "[Required] Money boost: 1.1 is equals 10% more income when 0.9 is equals 10% less from base income");
for (CurrencyType oneC : CurrencyType.values()) {
cfg.get("exampleBoost." + oneC.toString().toLowerCase() + "Boost", 1D);
}
cfg.addComment("exampleBoost.jobs", "[Required] Jobs which should receive this boost",
"Can be specific jobs or use 'all' to give this boost for every job");
cfg.get("exampleBoost.jobs", Arrays.asList("Miner", "Woodcutter", "all"));
one.getItemBonus().clear();
}
cfg.addComment("exampleBoost.levelFrom", "(Optional) Defines level of job from which this boost should be applied",
"Keep in mind that if boost have multiple jobs, then level will be checked by job which is requesting boost value");
cfg.get("exampleBoost.levelFrom", 0);
cfg.addComment("exampleBoost.levelUntil", "(Optional) Defines level of job until which this boost should be applied");
cfg.get("exampleBoost.levelUntil", 50);
if (save) {
try {
cfg.getC().save(new File(Jobs.getFolder(), "boostedItems.yml"));
} catch (IOException e1) {
e1.printStackTrace();
}
try {
cfg = new ConfigReader(Jobs.getInstance(), "boostedItems.yml");
} catch (Exception e) {
e.printStackTrace();
return;
}
}
for (String one : keys) {
if (!cfg.getC().isConfigurationSection(one))
continue;
Set<String> keys = cfg.getC().getKeys(false);
// Ignoring example boost
if (one.equalsIgnoreCase("exampleBoost"))
continue;
cfg.addComment("exampleBoost", "Attention! If category name has _ in it, that means its legacy item which was converted from jobConfig.yml file",
"Keep this format until you will be sure that all legacy items have been converted throw usage, which is automatic process when player uses items with boost in them",
"",
"Name which will be used to identify this particular item boost",
"This is EXAMPLE boost and will be ignored");
cfg.addComment("exampleBoost.id", "Item Id which can be any material name as of 1.13 update",
"This is only used when performing command like /jobs give, but boost itself is not dependent on item type",
"You can use ingame command /jobs edititemboost to give particular boost to any item you are holding");
cfg.get("exampleBoost.id", "Golden_shovel");
cfg.addComment("exampleBoost.name", "(Optional) Item custom name", "Custom colors like &2 &5 can be used");
cfg.get("exampleBoost.name", "&2Custom item name");
cfg.addComment("exampleBoost.lore", "(Optional) Item custom lore", "Same as name, supports color codes");
cfg.get("exampleBoost.lore", Arrays.asList("&2Some random", "&5Lore with some", "&7Colors"));
cfg.addComment("exampleBoost.enchants", "(Optional) Item custom enchants",
"All enchantment names can be found https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html");
cfg.get("exampleBoost.enchants", Arrays.asList("FIRE_ASPECT=1", "DAMAGE_ALL=1"));
cfg.addComment("exampleBoost.leather-color", "(Optional) Leather armour colors (0-255)");
cfg.get("exampleBoost.leather-color", "82,34,125");
cfg.addComment("exampleBoost.moneyBoost", "[Required] Money boost: 1.1 is equals 10% more income when 0.9 is equals 10% less from base income");
for (CurrencyType oneC : CurrencyType.values()) {
cfg.get("exampleBoost." + oneC.toString().toLowerCase() + "Boost", 1D);
}
cfg.addComment("exampleBoost.jobs", "[Required] Jobs which should receive this boost",
"Can be specific jobs or use 'all' to give this boost for every job");
cfg.get("exampleBoost.jobs", Arrays.asList("Miner", "Woodcutter", "all"));
List<Job> jobs = new ArrayList<>();
List<String> j = cfg.get(one + ".jobs", Arrays.asList(""));
cfg.addComment("exampleBoost.levelFrom", "(Optional) Defines level of job from which this boost should be applied",
"Keep in mind that if boost have multiple jobs, then level will be checked by job which is requesting boost value");
cfg.get("exampleBoost.levelFrom", 0);
cfg.addComment("exampleBoost.levelUntil", "(Optional) Defines level of job until which this boost should be applied");
cfg.get("exampleBoost.levelUntil", 50);
if (j.contains("all")) {
jobs.addAll(Jobs.getJobs());
} else {
for (String oneJ : j) {
Job job = Jobs.getJob(oneJ);
for (String one : keys) {
if (!cfg.getC().isConfigurationSection(one))
continue;
if (job != null) {
jobs.add(job);
} else {
Jobs.getPluginLogger().warning("Cant determine job by " + oneJ + " name for " + one + " boosted item!");
}
}
}
// Ignoring example boost
if (one.equalsIgnoreCase("exampleBoost"))
continue;
if (jobs.isEmpty()) {
Jobs.getPluginLogger().warning("Jobs list is empty for " + one + " boosted item!");
continue;
}
List<Job> jobs = new ArrayList<>();
List<String> j = cfg.get(one + ".jobs", Arrays.asList(""));
BoostMultiplier b = new BoostMultiplier();
for (CurrencyType oneC : CurrencyType.values()) {
String typeName = oneC.toString().toLowerCase();
if (j.contains("all")) {
jobs.addAll(Jobs.getJobs());
} else {
for (String oneJ : j) {
Job job = Jobs.getJob(oneJ);
if (cfg.getC().isDouble(one + "." + typeName + "Boost"))
b.add(oneC, cfg.get(one + "." + typeName + "Boost", 1D) - 1);
}
if (job != null) {
jobs.add(job);
} else {
Jobs.getPluginLogger().warning("Cant determine job by " + oneJ + " name for " + one + " boosted item!");
}
}
}
String node = one.toLowerCase();
if (jobs.isEmpty()) {
Jobs.getPluginLogger().warning("Jobs list is empty for " + one + " boosted item!");
continue;
}
JobItems jitem = new JobItems(node);
List<String> lore = cfg.get(one + ".lore", Arrays.asList(""));
for (int a = 0; a < lore.size(); a++) {
lore.set(a, CMIChatColor.translate(lore.get(a)));
}
jitem.setJobs(jobs);
jitem.setBoostMultiplier(b);
if (cfg.getC().isInt(one + ".levelFrom"))
jitem.setFromLevel(cfg.get(one + ".levelFrom", 0));
Map<Enchantment, Integer> enchants = new HashMap<>();
if (cfg.getC().isList(one + ".enchants"))
for (String eachLine : cfg.get(one + ".enchants", Arrays.asList(""))) {
String[] split = eachLine.split("=", 2);
if (split.length == 0)
continue;
if (cfg.getC().isInt(one + ".levelUntil"))
jitem.setUntilLevel(cfg.get(one + ".levelUntil", 1000));
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
int level = -1;
// Old format, should be removed down the line
if (cfg.getC().isString(one + ".id")) {
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
}
if (!informed) {
CMIMessages.consoleMessage("&5Update boosted item " + one + " item section to use new 'ItemStack' format");
informed = true;
}
if (ench != null && level != -1)
enchants.put(ench, level);
}
CMIMaterial mat = cfg.getC().isString(one + ".id") ? CMIMaterial.get(cfg.get(one + ".id", "Stone")) : null;
BoostMultiplier b = new BoostMultiplier();
for (CurrencyType oneC : CurrencyType.values()) {
String typeName = oneC.toString().toLowerCase();
String name = cfg.getC().isString(one + ".name") ? cfg.get(one + ".name", "") : null;
if (cfg.getC().isDouble(one + "." + typeName + "Boost"))
b.add(oneC, cfg.get(one + "." + typeName + "Boost", 1D) - 1);
}
if (mat == null) {
CMIMessages.consoleMessage("&cCould not determine boosted item material (" + node + ")");
continue;
}
List<String> lore = cfg.get(one + ".lore", new ArrayList<String>());
for (int a = 0; a < lore.size(); a++) {
lore.set(a, CMIChatColor.translate(lore.get(a)).replace(" ", "_"));
}
CMIMaterial mat = cfg.getC().isString(one + ".id") ? CMIMaterial.get(cfg.get(one + ".id", "Stone")) : null;
StringBuilder enchants = new StringBuilder();
String name = cfg.getC().isString(one + ".name") ? cfg.get(one + ".name", "") : null;
String node = one.toLowerCase();
if (cfg.getC().isList(one + ".enchants"))
for (String eachLine : cfg.get(one + ".enchants", Arrays.asList(""))) {
String[] split = eachLine.split("=", 2);
if (split.length == 0)
continue;
Color leatherColor = null;
String lc = cfg.getC().getString(one + ".leather-color", "");
if (!lc.isEmpty()) {
String[] split = lc.split(",", 3);
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
if (split.length != 0) {
int red = Integer.parseInt(split[0]);
int green = split.length > 0 ? Integer.parseInt(split[1]) : 0;
int blue = split.length > 1 ? Integer.parseInt(split[2]) : 0;
if (ench == null)
continue;
try {
leatherColor = Color.fromRGB(red, green, blue);
} catch (IllegalArgumentException e) {
}
}
}
int level = -1;
JobItems item = new JobItems(node, mat, 1, name, lore, enchants, b, jobs, null, leatherColor);
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
}
if (cfg.getC().isInt(one + ".levelFrom"))
item.setFromLevel(cfg.get(one + ".levelFrom", 0));
if (level == -1)
continue;
if (cfg.getC().isInt(one + ".levelUntil"))
item.setUntilLevel(cfg.get(one + ".levelUntil", 1000));
if (!enchants.toString().isEmpty())
enchants.append(",");
enchants.append(split[0] + ":" + level);
for (Job oneJ : jobs) {
oneJ.getItemBonus().put(node, item);
}
}
// Lets add into legacy map
String[] split = one.split("_", 2);
if (split.length > 1) {
item.setLegacyKey(split[1].toLowerCase());
LEGACY.put(item.getLegacyKey(), item);
}
String lc = cfg.getC().getString(one + ".leather-color", "");
ITEMS.put(node, item);
}
String itemSring = mat.toString();
if (name != null)
itemSring += ";n{" + name.replace(" ", "_") + "}";
cfg.save();
CMIMessages.consoleMessage("&eLoaded &6" + ITEMS.size() + " &eboosted items");
if (!lore.isEmpty())
itemSring += ";l{" + CMIList.listToString(lore, "\\n") + "}";
if (lc != null)
itemSring += ";" + lc;
if (!enchants.toString().isEmpty())
itemSring += ";" + enchants.toString();
jitem.setItemString(itemSring);
} else if (cfg.getC().isString(one + ".ItemStack")) {
String itemString = cfg.get(one + ".ItemStack", cfg.getC().getString(one + ".ItemStack"));
CMIItemStack item = CMIItemStack.deserialize(itemString, null);
if (item == null || item.getCMIType().isNone()) {
CMIMessages.consoleMessage("&cInvalid ItemStack for boosted item (" + node + ")");
continue;
}
jitem.setItemString(itemString);
}
ITEMS.put(node, jitem);
}
cfg.save();
CMIMessages.consoleMessage("&eLoaded &6" + ITEMS.size() + " &eboosted items");
}
/**
@ -239,13 +212,13 @@ public final class ItemBoostManager {
* @return List of {@link JobItems}
*/
public static List<JobItems> getItemsByJob(Job job) {
List<JobItems> ls = new ArrayList<>();
for (JobItems one : ITEMS.values()) {
if (one.getJobs().contains(job))
ls.add(one);
}
List<JobItems> ls = new ArrayList<>();
for (JobItems one : ITEMS.values()) {
if (one.getJobs().contains(job))
ls.add(one);
}
return ls;
return ls;
}
/** Returns a map of items from the specific job.
@ -254,13 +227,13 @@ public final class ItemBoostManager {
* @return map of items
*/
public static Map<String, JobItems> getItemsMapByJob(Job job) {
Map<String, JobItems> i = new HashMap<>();
for (Entry<String, JobItems> one : ITEMS.entrySet()) {
if (one.getValue().getJobs().contains(job))
i.put(one.getKey(), one.getValue());
}
Map<String, JobItems> i = new HashMap<>();
for (Entry<String, JobItems> one : ITEMS.entrySet()) {
if (one.getValue().getJobs().contains(job))
i.put(one.getKey(), one.getValue());
}
return i;
return i;
}
/**
@ -270,23 +243,53 @@ public final class ItemBoostManager {
* @return {@link JobItems}
*/
public static JobItems getItemByKey(String key) {
key = key.toLowerCase();
JobItems item = ITEMS.get(key);
return item != null ? item : LEGACY.get(key);
return ITEMS.get(key.toLowerCase());
}
/**
* @return the current cached map of items.
*/
public static Map<String, JobItems> getItems() {
return ITEMS;
return ITEMS;
}
/**
* @return the current cached map of legacy items.
*/
public static Map<String, JobItems> getLegacyItems() {
return LEGACY;
private static final String jobsItemBoost = "JobsItemBoost";
public static boolean containsItemBoostByNBT(ItemStack item) {
return item != null && new CMINBT(item).hasNBT(jobsItemBoost);
}
public static JobItems getJobsItemByNbt(ItemStack item) {
if (item == null)
return null;
Object itemName = new CMINBT(item).getString(jobsItemBoost);
if (itemName == null || itemName.toString().isEmpty()) {
// Checking old boost items and converting to new format if needed
if (new CMINBT(item).hasNBT(jobsItemBoost)) {
for (Job one : Jobs.getJobs()) {
itemName = new CMINBT(item).getString(jobsItemBoost + "." + one.getName());
if (itemName != null) {
JobItems b = getItemByKey(itemName.toString());
if (b != null) {
ItemStack ic = (ItemStack) new CMINBT(item).setString(jobsItemBoost, b.getNode());
item.setItemMeta(ic.getItemMeta());
}
break;
}
}
}
if (itemName == null)
return null;
}
return getItemByKey(itemName.toString());
}
public static ItemStack applyNBT(ItemStack item, String node) {
if (item == null)
return null;
return (ItemStack) new CMINBT(item).setString(jobsItemBoost, node);
}
}

View File

@ -66,6 +66,7 @@ import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Container.CMINumber;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.NBT.CMINBT;
import net.Zrips.CMILib.Version.Version;
@ -1073,46 +1074,25 @@ public class PlayerManager {
JobProgression progress = getJobsPlayer(player).getJobProgression(job);
for (JobItems jitem : jitems) {
if (jitem != null && jitem.getJobs().contains(job)) {
data.add(jitem.getBoost(progress));
}
if (jitem == null)
continue;
if (!jitem.getJobs().contains(job))
continue;
data.add(jitem.getBoost(progress));
}
return data;
}
private final String jobsItemBoost = "JobsItemBoost";
@Deprecated
public boolean containsItemBoostByNBT(ItemStack item) {
return item != null && new CMINBT(item).hasNBT(jobsItemBoost);
return containsItemBoostByNBT(item);
}
@Deprecated
public JobItems getJobsItemByNbt(ItemStack item) {
if (item == null)
return null;
Object itemName = new CMINBT(item).getString(jobsItemBoost);
if (itemName == null || itemName.toString().isEmpty()) {
// Checking old boost items and converting to new format if needed
if (new CMINBT(item).hasNBT(jobsItemBoost)) {
for (Job one : Jobs.getJobs()) {
itemName = new CMINBT(item).getString(jobsItemBoost + "." + one.getName());
if (itemName != null) {
JobItems b = ItemBoostManager.getItemByKey(itemName.toString());
if (b != null) {
ItemStack ic = (ItemStack) new CMINBT(item).setString(jobsItemBoost, b.getNode());
item.setItemMeta(ic.getItemMeta());
}
break;
}
}
}
if (itemName == null)
return null;
}
return ItemBoostManager.getItemByKey(itemName.toString());
return ItemBoostManager.getJobsItemByNbt(item);
}
public enum BoostOf {

View File

@ -14,6 +14,9 @@ import com.gamingmesh.jobs.container.JobLimitedItems;
import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.GiveItem;
import net.Zrips.CMILib.Items.CMIAsyncHead;
import net.Zrips.CMILib.Items.CMIItemStack;
public class give implements Cmd {
private enum actions {
@ -72,17 +75,27 @@ public class give implements Cmd {
return true;
}
Player p = player;
switch (name) {
case items:
JobItems jItem = ItemBoostManager.getItemByKey(itemName);
ItemStack item = jItem == null ? null : jItem.getItemStack(player);
if (item == null) {
CMIAsyncHead ahead = new CMIAsyncHead() {
@Override
public void afterAsyncUpdate(ItemStack item) {
GiveItem.giveItemForPlayer(p, ItemBoostManager.applyNBT(item, jItem.getNode()));
}
};
CMIItemStack item = jItem == null ? null : jItem.getItemStack(player, ahead);
if (jItem == null || item == null) {
Language.sendMessage(sender, "command.give.output.noitem");
return true;
}
GiveItem.giveItemForPlayer(player, item);
if (!ahead.isAsyncHead())
GiveItem.giveItemForPlayer(player, ItemBoostManager.applyNBT(item.getItemStack(), jItem.getNode()));
break;
case limiteditems:
if (job == null) {
@ -91,14 +104,23 @@ public class give implements Cmd {
}
JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase());
ItemStack limItem = jLItem == null ? null : jLItem.getItemStack(player);
ahead = new CMIAsyncHead() {
@Override
public void afterAsyncUpdate(ItemStack item) {
GiveItem.giveItemForPlayer(p, item);
}
};
CMIItemStack limItem = jLItem == null ? null : jLItem.getItemStack(player, ahead);
if (limItem == null) {
Language.sendMessage(sender, "command.give.output.noitem");
return true;
}
GiveItem.giveItemForPlayer(player, limItem);
if (!ahead.isAsyncHead())
GiveItem.giveItemForPlayer(player, limItem.getItemStack());
break;
default:
break;

View File

@ -52,9 +52,11 @@ import com.gamingmesh.jobs.container.JobLimitedItems;
import com.gamingmesh.jobs.container.JobPermission;
import com.gamingmesh.jobs.container.Quest;
import com.gamingmesh.jobs.container.QuestObjective;
import com.gamingmesh.jobs.listeners.JobsListener;
import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Equations.ParseError;
import net.Zrips.CMILib.Equations.Parser;
@ -1317,64 +1319,6 @@ public class ConfigManager {
}
job.setCommands(jobCommand);
// Items **OUTDATED** Moved to ItemBoostManager!!
HashMap<String, JobItems> jobItems = new HashMap<>();
ConfigurationSection itemsSection = jobSection.getConfigurationSection("items");
if (itemsSection != null) {
for (String itemKey : itemsSection.getKeys(false)) {
ConfigurationSection itemSection = itemsSection.getConfigurationSection(itemKey);
String node = itemKey.toLowerCase();
if (itemSection == null) {
log.warning("Job " + jobConfigName + " has an invalid item key " + itemKey + "!");
continue;
}
int id = itemSection.getInt("id");
String name = null;
if (itemSection.isString("name"))
name = itemSection.getString("name");
List<String> lore = new ArrayList<>();
if (itemSection.contains("lore"))
for (String eachLine : itemSection.getStringList("lore")) {
lore.add(CMIChatColor.translate(eachLine));
}
HashMap<Enchantment, Integer> enchants = new HashMap<>();
if (itemSection.contains("enchants"))
for (String eachLine : itemSection.getStringList("enchants")) {
if (!eachLine.contains("="))
continue;
Enchantment ench = CMIEnchantment.getEnchantment(eachLine.split("=")[0]);
Integer level = -1;
try {
level = Integer.parseInt(eachLine.split("=")[1]);
} catch (NumberFormatException e) {
continue;
}
if (ench != null && level != -1)
enchants.put(ench, level);
}
BoostMultiplier b = new BoostMultiplier();
if (itemSection.isDouble("moneyBoost"))
b.add(CurrencyType.MONEY, itemSection.getDouble("moneyBoost") - 1);
if (itemSection.isDouble("pointBoost"))
b.add(CurrencyType.POINTS, itemSection.getDouble("pointBoost") - 1);
if (itemSection.isDouble("expBoost"))
b.add(CurrencyType.EXP, itemSection.getDouble("expBoost") - 1);
jobItems.put(node.toLowerCase(), new JobItems(node, CMIMaterial.get(id), 1, name, lore, enchants, b, new ArrayList<Job>()));
}
CMIMessages.consoleMessage("&cRemove Items section from " + jobConfigName + " job, as of Jobs 4.10.0 version this was moved to boostedItems.yml file!");
}
job.setItemBonus(jobItems);
// Limited Items
Map<String, JobLimitedItems> jobLimitedItems = new HashMap<>();
ConfigurationSection limitedItemsSection = jobSection.getConfigurationSection("limitedItems");
@ -1406,11 +1350,12 @@ public class ConfigManager {
List<String> lore = itemSection.getStringList("lore");
for (int a = 0; a < lore.size(); a++) {
lore.set(a, CMIChatColor.translate(lore.get(a)));
}
if (lore != null)
for (int a = 0; a < lore.size(); a++) {
lore.set(a, CMIChatColor.translate(lore.get(a).replace(" ", "_")));
}
Map<Enchantment, Integer> enchants = new HashMap<>();
StringBuilder enchants = new StringBuilder();
for (String eachLine : itemSection.getStringList("enchants")) {
String[] split = eachLine.split("=", 2);
if (split.length == 0)
@ -1429,11 +1374,30 @@ public class ConfigManager {
}
}
if (level != -1)
enchants.put(ench, level);
if (level == -1)
continue;
if (!enchants.toString().isEmpty())
enchants.append(",");
enchants.append(split[0] + ":" + level);
}
jobLimitedItems.put(node, new JobLimitedItems(node, mat, 1, itemSection.getString("name"), lore, enchants, itemSection.getInt("level")));
String itemString = "";
String name = CMIChatColor.translate(itemSection.getString("name"));
if (name != null)
itemString += ";n{" + name.replace(" ", "_") + "}";
if (lore != null)
for (int b = 0; b < lore.size(); b++) {
lore.set(b, CMIChatColor.translate(lore.get(b).replace(" ", "_")));
}
if (lore != null && !lore.isEmpty())
itemString += ";l{" + CMIList.listToString(lore, "\\n") + "}";
jobLimitedItems.put(node, new JobLimitedItems(node, itemString, itemSection.getInt("level")));
if (!informedLimited) {
CMIMessages.consoleMessage("&5Update " + jobConfigName
@ -1450,11 +1414,12 @@ public class ConfigManager {
continue;
}
jobLimitedItems.put(node, new JobLimitedItems(node, limitedItem.getItemStack(), itemSection.getInt("level")));
jobLimitedItems.put(node, new JobLimitedItems(node, itemSection.getString("ItemStack"), itemSection.getInt("level")));
}
}
}
job.setLimitedItems(jobLimitedItems);
job.setCmdOnJoin(jobSection.getStringList("cmd-on-join"));

View File

@ -6,7 +6,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -16,31 +15,28 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.ShopItem;
import com.gamingmesh.jobs.stuff.GiveItem;
import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.GUI.CMIGui;
import net.Zrips.CMILib.GUI.CMIGuiButton;
import net.Zrips.CMILib.GUI.GUIManager.GUIClickType;
import net.Zrips.CMILib.GUI.GUIManager.GUIRows;
import net.Zrips.CMILib.Items.CMIAsyncHead;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.Version.Version;
@SuppressWarnings("deprecation")
public class ShopManager {
@ -110,7 +106,15 @@ public class ShopManager {
mainCycle: for (ShopItem item : ls) {
List<String> lore = new ArrayList<>();
CMIMaterial mat = CMIMaterial.get(item.getIconMaterial());
CMIAsyncHead ahead = new CMIAsyncHead() {
@Override
public void afterAsyncUpdate(ItemStack item) {
}
};
CMIItemStack icon = item.getIcon(player, ahead);
boolean hiddenLore = false;
@ -124,26 +128,18 @@ public class ShopManager {
if (item.isHideIfNoEnoughPoints() && item.getPointPrice() > 0 &&
jPlayer.getPointsData().getCurrentPoints() < item.getPointPrice()) {
mat = CMIMaterial.STONE_BUTTON;
icon = CMIMaterial.STONE_BUTTON.newCMIItemStack();
lore.add(Jobs.getLanguage().getMessage("command.shop.info.NoPoints"));
hiddenLore = true;
}
if (mat == CMIMaterial.NONE)
mat = CMIMaterial.STONE_BUTTON;
ItemStack guiItem = mat.newItemStack();
ItemStack guiItem = icon.getItemStack();
ItemMeta meta = guiItem.getItemMeta();
if (meta == null)
continue;
guiItem.setAmount(item.getIconAmount());
if (item.getIconName() != null)
meta.setDisplayName(item.getIconName());
if (!hiddenLore) {
lore.addAll(item.getIconLore());
lore.addAll(icon.getLore());
if (item.getPointPrice() > 0) {
String color = item.getPointPrice() >= points ? "" : Jobs.getLanguage().getMessage("command.shop.info.haveColor");
@ -190,32 +186,6 @@ public class ShopManager {
meta.setLore(lore);
if (item.getCustomHead() != null) {
guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(item.getIconAmount());
SkullMeta skullMeta = (SkullMeta) guiItem.getItemMeta();
if (skullMeta == null)
continue;
if (item.getIconName() != null)
skullMeta.setDisplayName(item.getIconName());
skullMeta.setLore(lore);
if (item.isHeadOwner()) {
Util.setSkullOwner(skullMeta, jPlayer.getPlayer());
} else {
try {
Util.setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(UUID.fromString(item.getCustomHead())));
} catch (IllegalArgumentException ex) {
Util.setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(item.getCustomHead()));
}
}
guiItem.setItemMeta(skullMeta);
} else
guiItem.setItemMeta(meta);
CMIGuiButton button = new CMIGuiButton(guiItem) {
@Override
public void click(GUIClickType type) {
@ -272,7 +242,15 @@ public class ShopManager {
}
for (JobItems one : item.getitems()) {
GiveItem.giveItemForPlayer(player, one.getItemStack(player));
CMIAsyncHead ahead = new CMIAsyncHead() {
@Override
public void afterAsyncUpdate(ItemStack item) {
GiveItem.giveItemForPlayer(player, item);
}
};
CMIItemStack citem = one.getItemStack(player, ahead);
if (citem != null && !ahead.isAsyncHead())
GiveItem.giveItemForPlayer(player, citem.getItemStack());
}
if (item.getPointPrice() > 0) {
@ -326,6 +304,8 @@ public class ShopManager {
return true;
}
boolean informed = false;
public void load() {
list.clear();
@ -361,27 +341,71 @@ public class ShopManager {
sItem.setPointPrice(pointPrice);
sItem.setVaultPrice(vaultPrice);
if (nameSection.isString("Icon.Id"))
sItem.setIconMaterial(nameSection.getString("Icon.Id"));
else {
if (nameSection.contains("Icon.Id")) {
String itemString = "";
if (!informed) {
CMIMessages.consoleMessage("&5Update shops items icon section and use 'ItemStack' instead");
informed = true;
}
CMIMaterial mat = null;
if (nameSection.isString("Icon.Id"))
mat = CMIMaterial.get(nameSection.getString("Icon.Id"));
if (mat == null) {
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid Icon name property. Skipping!");
continue;
}
int amount = nameSection.getInt("Icon.Amount", 1);
if (amount > 1)
itemString += ";" + amount;
String name = CMIChatColor.translate(nameSection.getString("Icon.Name"));
if (name != null)
itemString += ";n{" + name.replace(" ", "_") + "}";
List<String> lore = nameSection.getStringList("Icon.Lore");
if (lore != null)
for (int b = 0; b < lore.size(); b++) {
lore.set(b, CMIChatColor.translate(lore.get(b).replace(" ", "_")));
}
if (lore != null && !lore.isEmpty())
itemString += ";l{" + CMIList.listToString(lore, "\\n") + "}";
if (nameSection.isString("Icon.CustomHead.PlayerName")) {
itemString = mat.toString() + ":" + nameSection.getString("Icon.CustomHead.PlayerName") + itemString;
} else if (nameSection.getBoolean("Icon.CustomHead.UseCurrentPlayer", false)) {
itemString = mat.toString() + ":[player]" + itemString;
} else {
itemString = mat.toString() + itemString;
}
sItem.setIconString(itemString);
} else if (nameSection.contains("Icon.ItemStack")) {
String itemString = nameSection.getString("Icon.ItemStack");
CMIItemStack item = CMIItemStack.deserialize(itemString, null);
if (item == null || item.getCMIType().isNone()) {
CMIMessages.consoleMessage("&cInvalid ItemStack for shop icon item (" + category + ")");
continue;
}
sItem.setIconString(itemString);
}
if (sItem.getIconString() == null) {
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid Icon name property. Skipping!");
continue;
}
sItem.setIconAmount(nameSection.getInt("Icon.Amount", 1));
sItem.setIconName(CMIChatColor.translate(nameSection.getString("Icon.Name")));
List<String> lore = nameSection.getStringList("Icon.Lore");
for (int b = 0; b < lore.size(); b++) {
lore.set(b, CMIChatColor.translate(lore.get(b)));
}
sItem.setIconLore(lore);
if (nameSection.isString("Icon.CustomHead.PlayerName"))
sItem.setCustomHead(nameSection.getString("Icon.CustomHead.PlayerName"));
sItem.setCustomHeadOwner(nameSection.getBoolean("Icon.CustomHead.UseCurrentPlayer", true));
sItem.setHideIfThereIsNoEnoughPoints(nameSection.getBoolean("Icon.HideIfThereIsNoEnoughPoints"));
sItem.setHideWithoutPerm(nameSection.getBoolean("Icon.HideWithoutPermission"));
sItem.setRequiredPerm(nameSection.getStringList("RequiredPermission"));
@ -417,73 +441,114 @@ public class ShopManager {
}
sItem.setCommands(performCommands);
ConfigurationSection itemsSection = nameSection.getConfigurationSection("GiveItems");
if (itemsSection != null) {
if (nameSection.isList("GiveItems")) {
List<JobItems> items = new ArrayList<>();
for (String itemString : nameSection.getStringList("GiveItems")) {
for (String oneItemName : itemsSection.getKeys(false)) {
ConfigurationSection itemSection = itemsSection.getConfigurationSection(oneItemName);
if (itemSection == null)
continue;
CMIItemStack item = CMIItemStack.deserialize(itemString, null);
String id = null;
if (itemSection.isString("Id"))
id = itemSection.getString("Id");
else {
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems item id property. Skipping!");
if (item == null || item.getCMIType().isNone()) {
CMIMessages.consoleMessage("&cInvalid ItemStack for boosted item (" + itemString + ")");
continue;
}
int amount = itemSection.getInt("Amount", 1);
String name = CMIChatColor.translate(itemSection.getString("Name"));
List<String> giveLore = itemSection.getStringList("Lore");
for (int v = 0; v < giveLore.size(); v++) {
giveLore.set(v, CMIChatColor.translate(giveLore.get(v)));
}
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;
Integer level = 1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
}
enchants.put(ench, level);
}
Object potionData = null;
if (itemSection.contains("potion-type")) {
PotionType type;
try {
type = PotionType.valueOf(itemSection.getString("potion-type", "speed").toUpperCase());
} catch (IllegalArgumentException ex) {
type = PotionType.SPEED;
}
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
potionData = new PotionData(type);
} else {
potionData = new Potion(type, 1, false);
}
}
items.add(new JobItems(oneItemName.toLowerCase(), id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, giveLore,
enchants, new BoostMultiplier(), new ArrayList<>(), potionData, null));
JobItems jitem = new JobItems("");
jitem.setItemString(itemString);
items.add(jitem);
}
sItem.setitems(items);
} else {
// Outdated method
ConfigurationSection itemsSection = nameSection.getConfigurationSection("GiveItems");
if (itemsSection != null) {
List<JobItems> items = new ArrayList<>();
for (String oneItemName : itemsSection.getKeys(false)) {
ConfigurationSection itemSection = itemsSection.getConfigurationSection(oneItemName);
if (itemSection == null)
continue;
if (itemSection.contains("Id")) {
CMIMaterial mat = null;
if (itemSection.isString("Id"))
mat = CMIMaterial.get(itemSection.getString("Id"));
else {
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems item id property. Skipping!");
continue;
}
int amount = itemSection.getInt("Amount", 1);
String name = CMIChatColor.translate(itemSection.getString("Name"));
List<String> giveLore = itemSection.getStringList("Lore");
if (giveLore != null)
for (int v = 0; v < giveLore.size(); v++) {
giveLore.set(v, CMIChatColor.translate(giveLore.get(v)).replace(" ", "_"));
}
StringBuilder enchants = new StringBuilder();
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;
Integer level = 1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
}
if (!enchants.toString().isEmpty())
enchants.append(",");
enchants.append(split[0] + ":" + level);
}
String potionData = "";
if (itemSection.contains("potion-type")) {
PotionType type;
try {
type = PotionType.valueOf(itemSection.getString("potion-type", "speed").toUpperCase());
} catch (IllegalArgumentException ex) {
type = PotionType.SPEED;
}
potionData += type.toString() + ":false:false";
}
String itemSring = mat.toString();
if (name != null)
itemSring += ";n{" + name.replace(" ", "_") + "}";
if (amount > 1)
itemSring += ";" + amount;
if (giveLore != null && !giveLore.isEmpty())
itemSring += ";l{" + CMIList.listToString(giveLore, "\\n") + "}";
if (!potionData.isEmpty())
itemSring += ";" + potionData;
if (!enchants.toString().isEmpty())
itemSring += ";" + enchants.toString();
JobItems jitem = new JobItems(oneItemName.toLowerCase());
jitem.setItemString(itemSring);
items.add(jitem);
}
}
sItem.setitems(items);
}
}
i++;

View File

@ -58,7 +58,7 @@ public class Job {
private List<JobCommands> jobCommands;
private List<JobConditions> jobConditions;
private Map<String, JobItems> jobItems;
// private Map<String, JobItems> jobItems;
private Map<String, JobLimitedItems> jobLimitedItems;
private String jobName = "N/A";
@ -115,7 +115,7 @@ public class Job {
vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions,
jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, worldBlacklist);
this.jobItems = jobItems;
// this.jobItems = jobItems;
this.description = description;
}
@ -580,36 +580,6 @@ public class Job {
return this;
}
/**
* No longer used, moved to ItemBoostManager
* @return Items for this job
*/
@Deprecated
public Map<String, JobItems> getItemBonus() {
if (jobItems == null)
jobItems = new HashMap<String, JobItems>();
return jobItems;
}
/**
* No longer used, moved to ItemBoostManager
* @return Items for this job
*/
@Deprecated
public JobItems getItemBonus(String key) {
return jobItems.get(key.toLowerCase());
}
/**
* No longer used, moved to ItemBoostManager
* @return Items for this job
*/
@Deprecated
public Job setItemBonus(HashMap<String, JobItems> jobItems) {
this.jobItems = jobItems;
return this;
}
/**
* Get the limited item nodes for this job
* @return Limited items for this job

View File

@ -19,37 +19,19 @@
package com.gamingmesh.jobs.container;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Color;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.NBT.CMINBT;
import net.Zrips.CMILib.Version.Version;
import net.Zrips.CMILib.Items.CMIAsyncHead;
import net.Zrips.CMILib.Items.CMIItemStack;
@SuppressWarnings("deprecation")
public class JobItems {
private String node;
private String legacyKey;
private ItemStack item;
private Object potion;
private Color leatherColor;
private String itemString;
private final Map<Enchantment, Integer> enchants = new HashMap<>();
private BoostMultiplier boostMultiplier = new BoostMultiplier();
private final List<Job> jobs = new ArrayList<>();
@ -57,139 +39,16 @@ public class JobItems {
private int fromLevel = 0;
private int untilLevel = Integer.MAX_VALUE;
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs) {
this(node, mat, amount, name, lore, enchants, boostMultiplier, jobs, null, null);
}
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs,
Object potion, Color leatherColor) {
if (mat == null) {
mat = CMIMaterial.STONE;
}
if (enchants != null) {
this.enchants.putAll(enchants);
}
public JobItems(String node) {
this.node = node;
if (boostMultiplier != null) {
this.boostMultiplier = boostMultiplier;
}
setJobs(jobs);
ItemMeta meta = (item = mat.newItemStack()).getItemMeta();
if (potion != null && meta instanceof PotionMeta && CMIMaterial.isPotion(mat.getMaterial())) {
PotionMeta potionMeta = (PotionMeta) meta;
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && potion instanceof org.bukkit.potion.PotionData) {
potionMeta.setBasePotionData((org.bukkit.potion.PotionData) potion);
} else if (potion instanceof org.bukkit.potion.Potion) {
PotionEffectType effectType = ((org.bukkit.potion.Potion) potion).getType().getEffectType();
if (effectType != null) {
potionMeta.setMainEffect(effectType);
}
}
meta = potionMeta;
} else if (leatherColor != null && meta instanceof LeatherArmorMeta && CMIMaterial.isLeatherArmor(mat.getMaterial())) {
LeatherArmorMeta armorMeta = (LeatherArmorMeta) meta;
armorMeta.setColor(this.leatherColor = leatherColor);
meta = armorMeta;
}
if (meta != null) {
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
if (lore != null)
meta.setLore(lore);
if (enchants != null) {
if (mat == CMIMaterial.ENCHANTED_BOOK) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
}
}
item.setItemMeta(meta);
}
item.setAmount(amount);
CMINBT nbt = new CMINBT(item);
item = (ItemStack) nbt.setString("JobsItemBoost", node);
}
public String getNode() {
return node;
}
public ItemStack getItemStack(Player player) {
if (player == null)
return item;
ItemStack item = this.item.clone();
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item;
}
if (potion != null && CMIMaterial.isPotion(item.getType()) && meta instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) meta;
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && potion instanceof org.bukkit.potion.PotionData) {
potionMeta.setBasePotionData((org.bukkit.potion.PotionData) potion);
} else if (potion instanceof org.bukkit.potion.Potion) {
PotionEffectType effectType = ((org.bukkit.potion.Potion) potion).getType().getEffectType();
if (effectType != null) {
potionMeta.setMainEffect(effectType);
}
}
meta = potionMeta;
} else if (leatherColor != null && CMIMaterial.isLeatherArmor(item.getType()) && meta instanceof LeatherArmorMeta) {
LeatherArmorMeta armorMeta = (LeatherArmorMeta) meta;
armorMeta.setColor(leatherColor);
meta = armorMeta;
}
if (meta.hasDisplayName())
meta.setDisplayName(CMIChatColor.translate(meta.getDisplayName().replace("[player]", player.getName())));
if (meta.hasLore()) {
List<String> translatedLore = meta.getLore();
for (int a = 0; a < translatedLore.size(); a++) {
translatedLore.set(a, CMIChatColor.translate(translatedLore.get(a).replace("[player]", player.getName())));
}
meta.setLore(translatedLore);
}
if (enchants != null) {
if (item.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
meta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
}
}
item.setItemMeta(meta);
return item;
public CMIItemStack getItemStack(Player player, CMIAsyncHead ahead) {
return CMIItemStack.deserialize(itemString.replace("[player]", player == null ? "" : player.getName()), ahead);
}
public BoostMultiplier getBoost() {
@ -215,10 +74,6 @@ public class JobItems {
}
}
public Map<Enchantment, Integer> getEnchants() {
return enchants;
}
public int getFromLevel() {
return fromLevel;
}
@ -235,11 +90,16 @@ public class JobItems {
this.untilLevel = untilLevel;
}
public String getLegacyKey() {
return legacyKey;
public CMIItemStack getItem() {
return CMIItemStack.deserialize(itemString);
}
public void setLegacyKey(String legacyKey) {
this.legacyKey = legacyKey;
public void setItemString(String itemString) {
this.itemString = itemString.replace(" ", "_");
}
public void setBoostMultiplier(BoostMultiplier boostMultiplier) {
this.boostMultiplier = boostMultiplier;
}
}

View File

@ -18,59 +18,44 @@
package com.gamingmesh.jobs.container;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
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.CMIAsyncHead;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.NBT.CMINBT;
public class JobLimitedItems {
private String node;
CMIMaterial mat;
private String name;
private ItemStack item;
private String itemString;
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) {
public JobLimitedItems(String node, String itemString, int level) {
this.node = node;
this.itemString = itemString.replace(" ", "_");
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();
CMIItemStack citem = CMIItemStack.deserialize(itemString);
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();
ItemStack item = citem.getItemStack();
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (meta.hasDisplayName())
name = meta.getDisplayName();
if (meta.hasLore())
lore = meta.getLore();
}
enchants = item.getEnchantments();
mat = citem.getCMIType();
this.level = level;
}
@ -79,26 +64,8 @@ public class JobLimitedItems {
return node;
}
public ItemStack getItemStack(Player player) {
ItemStack item = this.item.clone();
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return item;
}
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);
}
item.setItemMeta(meta);
return item;
public CMIItemStack getItemStack(Player player, CMIAsyncHead ahead) {
return CMIItemStack.deserialize(itemString.replace("[player]", player == null ? "" : player.getName()), ahead);
}
@Deprecated
@ -125,4 +92,10 @@ public class JobLimitedItems {
public int getLevel() {
return level;
}
public static ItemStack applyNBT(ItemStack item, int jobId, String node) {
CMINBT nbt = new CMINBT(item);
nbt.setInt("JobsLimited", jobId);
return (ItemStack) nbt.setString("JobsLimitedNode", node);
}
}

View File

@ -5,6 +5,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.Zrips.CMILib.Items.CMIAsyncHead;
import net.Zrips.CMILib.Items.CMIItemStack;
public class ShopItem {
private double pointPrice = 0D;
@ -12,11 +18,8 @@ public class ShopItem {
private int slot = -1;
private int page = -1;
private int iconAmount = 1;
private String nodeName;
private String iconMaterial;
private String iconName;
private boolean hideWithoutPerm = false;
private boolean hideNoEnoughPoint = false;
@ -25,13 +28,19 @@ public class ShopItem {
private Map<String, Integer> requiredJobs = new HashMap<>();
private final List<String> iconLore = new ArrayList<>();
// private final List<String> iconLore = new ArrayList<>();
private final List<String> requiredPerm = new ArrayList<>();
private final List<String> commands = new ArrayList<>();
private final List<JobItems> items = new ArrayList<>();
private String playerName;
private boolean useCurrentPlayer = false;
// private String playerName;
// private boolean useCurrentPlayer = false;
private String iconString;
public CMIItemStack getIcon(Player player, CMIAsyncHead ahead) {
return CMIItemStack.deserialize(iconString.replace("[player]", player.getName()), ahead);
}
public ShopItem(String nodeName) {
this.nodeName = nodeName;
@ -110,28 +119,28 @@ public class ShopItem {
return hideWithoutPerm;
}
public void setIconLore(List<String> iconLore) {
this.iconLore.clear();
if (iconLore != null)
this.iconLore.addAll(iconLore);
}
public List<String> getIconLore() {
return iconLore;
}
// public void setIconLore(List<String> iconLore) {
// this.iconLore.clear();
//
// if (iconLore != null)
// this.iconLore.addAll(iconLore);
// }
//
// public List<String> getIconLore() {
// return iconLore;
// }
public String getNodeName() {
return nodeName;
}
public String getIconMaterial() {
return iconMaterial;
}
public void setIconMaterial(String iconMaterial) {
this.iconMaterial = iconMaterial;
}
// public String getIconMaterial() {
// return iconMaterial;
// }
//
// public void setIconMaterial(String iconMaterial) {
// this.iconMaterial = iconMaterial;
// }
@Deprecated
public double getPrice() {
@ -142,21 +151,21 @@ public class ShopItem {
return pointPrice;
}
public void setIconAmount(int iconAmount) {
this.iconAmount = iconAmount;
}
public int getIconAmount() {
return iconAmount;
}
public void setIconName(String iconName) {
this.iconName = iconName;
}
public String getIconName() {
return iconName;
}
// public void setIconAmount(int iconAmount) {
// this.iconAmount = iconAmount;
// }
//
// public int getIconAmount() {
// return iconAmount;
// }
//
// public void setIconName(String iconName) {
// this.iconName = iconName;
// }
//
// public String getIconName() {
// return iconName;
// }
public int getRequiredTotalLevels() {
return requiredTotalLevels;
@ -166,21 +175,21 @@ public class ShopItem {
this.requiredTotalLevels = requiredTotalLevels;
}
public String getCustomHead() {
return playerName;
}
public void setCustomHead(String playerName) {
this.playerName = playerName;
}
public boolean isHeadOwner() {
return useCurrentPlayer;
}
public void setCustomHeadOwner(boolean useCurrentPlayer) {
this.useCurrentPlayer = useCurrentPlayer;
}
// public String getCustomHead() {
// return playerName;
// }
//
// public void setCustomHead(String playerName) {
// this.playerName = playerName;
// }
//
// public boolean isHeadOwner() {
// return useCurrentPlayer;
// }
//
// public void setCustomHeadOwner(boolean useCurrentPlayer) {
// this.useCurrentPlayer = useCurrentPlayer;
// }
public double getVaultPrice() {
return vaultPrice;
@ -193,4 +202,12 @@ public class ShopItem {
public void setPointPrice(double pointPrice) {
this.pointPrice = pointPrice;
}
public String getIconString() {
return iconString;
}
public void setIconString(String iconString) {
this.iconString = iconString;
}
}

View File

@ -416,7 +416,7 @@ public class JobsListener implements Listener {
return false;
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLimitedItemInteract(PlayerInteractEvent event) {
@ -470,7 +470,7 @@ public class JobsListener implements Listener {
String itemNode = null;
CMIMaterial mat = CMIMaterial.get(iih);
Integer jobId = null;
int jobId = 0;
mein: for (JobProgression one : jPlayer.getJobProgression()) {
for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) {
if (one.getLevel() >= oneItem.getLevel() || !isThisItem(oneItem, mat, name, lore, enchants))
@ -486,9 +486,7 @@ public class JobsListener implements Listener {
event.setCancelled(true);
CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk));
CMINBT nbt = new CMINBT(iih);
nbt.setInt("JobsLimited", jobId);
iih = (ItemStack) nbt.setString("JobsLimitedNode", itemNode);
iih = JobLimitedItems.applyNBT(iih, jobId, itemNode);
try {
if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) {
CMIItemStack.setItemInOffHand(player, iih);
@ -502,8 +500,9 @@ public class JobsListener implements Listener {
}
private static boolean isThisItem(JobLimitedItems oneItem, CMIMaterial mat, String name, List<String> lore, Map<Enchantment, Integer> enchants) {
if (oneItem.getType() != mat)
if (oneItem.getType() != mat) {
return false;
}
if (oneItem.getName() != null && !CMIChatColor.translate(oneItem.getName()).equalsIgnoreCase(name)) {
return false;
@ -518,12 +517,12 @@ public class JobsListener implements Listener {
for (Entry<Enchantment, Integer> oneE : enchants.entrySet()) {
Integer value = oneItem.getEnchants().get(oneE.getKey());
if (value != null && value <= oneE.getValue()) {
return true;
if (value != null && value > oneE.getValue()) {
return false;
}
}
return false;
return true;
}
@EventHandler(ignoreCancelled = true)

View File

@ -1044,7 +1044,7 @@ public final class JobsPaymentListener implements Listener {
if (!Jobs.getGCManager().allowEnchantingBoostedItems) {
for (JobProgression prog : jPlayer.getJobProgression()) {
for (JobItems jobItem : ItemBoostManager.getItemsByJob(prog.getJob())) {
if (event.getItem().isSimilar(jobItem.getItemStack(player))) {
if (event.getItem().isSimilar(jobItem.getItemStack(player, null).getItemStack())) {
event.setCancelled(true);
return;
}

View File

@ -12,49 +12,54 @@ import org.bukkit.inventory.meta.ItemMeta;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Version.Schedulers.CMIScheduler;
public final class GiveItem {
public static void giveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore,
java.util.Map<Enchantment, Integer> enchants) {
ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack();
itemStack.setAmount(qty);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
java.util.Map<Enchantment, Integer> enchants) {
ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack();
itemStack.setAmount(qty);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return;
}
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())));
}
itemMeta.setLore(translatedLore);
}
itemMeta.setLore(translatedLore);
}
if (enchants != null) {
if (itemStack.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) itemMeta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
itemMeta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
}
}
if (enchants != null) {
if (itemStack.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) {
EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) itemMeta;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true);
}
} else {
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
itemMeta.addEnchant(oneEnchant.getKey(), oneEnchant.getValue(), true);
}
}
}
if (name != null)
itemMeta.setDisplayName(CMIChatColor.translate(name));
if (name != null)
itemMeta.setDisplayName(CMIChatColor.translate(name));
itemStack.setItemMeta(itemMeta);
giveItemForPlayer(player, itemStack);
itemStack.setItemMeta(itemMeta);
giveItemForPlayer(player, itemStack);
}
public static void giveItemForPlayer(Player player, ItemStack item) {
player.getInventory().addItem(item);
player.updateInventory();
if (player == null)
return;
CMIScheduler.runAtEntity(player, () -> {
player.getInventory().addItem(item);
player.updateInventory();
});
}
}

View File

@ -6,27 +6,12 @@ Items:
# Atleast one type of currency needs to be defined
vaultPrice: 10000.0
Icon:
# (REQUIRED) Icon item
Id: diamond_pickaxe
# (Optional - Default: 1) Icon item amount
Amount: 1
# (Optional) Icon name. Supports usual color codes
Name: "&eBest pick axe ever!"
# (Optional) Icon lore. Supports usual color codes
Lore:
- "&6Efficiency V"
- "&6Unbreaking III"
- "&eAnd one tasty apple!"
# (REQUIRED) Icon item. [player] can be used as a variable for the player who opens UI
ItemStack: diamond_pickaxe;&eBest_pick_axe_ever!;&6Efficiency_V\n&6Unbreaking_III\n&eAnd_one_tasty_apple!
# (Optional - default: false) Hides icon if player don't have permission to get this item
HideWithoutPermission: true
# (Optional - default: false) Hides icon if player don't have enough point levels to get this icon
HideIfThereIsNoEnoughPoints: false
# (Optional) When you want to use Player Head material with skin then use this
#CustomHead:
# You can specify here valid player name or uuid.
# PlayerName: playerNameOrUUID
# Use the current player who opened the gui, so the head skin will be this player who opened.
# UseCurrentPlayer: true
HideIfThereIsNoEnoughPoints: false
# (Optional) List of permissions required to buy this item
RequiredPermission:
- jobs.item.pickaxe
@ -44,30 +29,9 @@ Items:
- "msg &eThanks for buying this super pick axe!"
# (Optional) Gives items by defined criteria
GiveItems:
# Can be any word
PickAxe:
# (Required) Item name
Id: diamond_pickaxe
# (Optional - Default: 1) Item amount
Amount: 1
# (Optional) Item name
Name: "&eSuper PickAxe"
# (Optional) Item lore
Lore:
- "&eUber pickAxe"
# (Optional) Item enchants
Enchants:
- DIG_SPEED=5
- DURABILITY=3
Giving-Potion:
Id: potion
Amount: 1
Name: "&6Jump boost"
potion-type: jump
# Can be any word
Apple:
# (Required) Item name
Id: apple
- diamond_pickaxe;2;&eSuper_PickAxe;&eUber_pickAxe;DIG_SPEED:5,DURABILITY:3
- potion;n{&6Jump_boost};jump
- apple
WoodenShovel:
pointPrice: 100.0
Icon: