1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Lets add option to limit boosts by levels

This commit is contained in:
Zrips 2019-01-31 16:47:52 +02:00
parent f310ad0677
commit 84681df41a
10 changed files with 168 additions and 76 deletions

View File

@ -21,7 +21,7 @@ import com.gamingmesh.jobs.container.JobItems;
public class ItemBoostManager {
static HashMap<String, JobItems> items = new HashMap<String, JobItems>();
private static HashMap<String, JobItems> items = new HashMap<String, JobItems>();
public ItemBoostManager() {
@ -82,24 +82,59 @@ public class ItemBoostManager {
Set<String> keys = cfg.getC().getKeys(false);
cfg.addComment("exampleBoost", "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.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"));
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);
for (String one : keys) {
if (!cfg.getC().isConfigurationSection(one))
continue;
CMIMaterial mat = CMIMaterial.get(cfg.get(one + ".id", "Stone"));
if (mat == null) {
Jobs.getPluginLogger().warning("Cant load " + one + " boosted item!");
// Ignoring example job
if (one.equalsIgnoreCase("exampleBoost"))
continue;
CMIMaterial mat = null;
if (cfg.getC().isString(one + ".id")) {
mat = CMIMaterial.get(cfg.get(one + ".id", "Stone"));
}
String name = null;
if (cfg.getC().isString(one + ".name"))
if (cfg.getC().isString(one + ".name")) {
name = cfg.get(one + ".name", "");
}
List<String> lore = new ArrayList<>();
if (cfg.getC().getStringList(one + ".lore") != null && !cfg.getC().getStringList(one + ".lore").isEmpty())
if (cfg.getC().getStringList(one + ".lore") != null && !cfg.getC().getStringList(one + ".lore").isEmpty()) {
for (String eachLine : cfg.get(one + ".lore", Arrays.asList(""))) {
lore.add(org.bukkit.ChatColor.translateAlternateColorCodes('&', eachLine));
}
}
HashMap<Enchantment, Integer> enchants = new HashMap<>();
if (cfg.getC().getStringList(one + ".enchants") != null && !cfg.getC().getStringList(one + ".enchants").isEmpty())
@ -132,7 +167,10 @@ public class ItemBoostManager {
Jobs.getPluginLogger().warning("Cant determine job by " + oneJ + " name for " + one + " boosted item!");
continue;
}
jobs.add(job);
if (oneJ.equalsIgnoreCase("all")) {
jobs.addAll(Jobs.getJobs());
} else if (job != null)
jobs.add(job);
}
if (jobs.isEmpty()) {
@ -140,7 +178,18 @@ public class ItemBoostManager {
continue;
}
JobItems item = new JobItems(one.toLowerCase(), mat, 1, name, lore, enchants, b, jobs);
if (cfg.getC().isInt(one + ".levelFrom")) {
item.setFromLevel(cfg.get(one + ".levelFrom", 0));
}
if (cfg.getC().isInt(one + ".levelUntil")) {
item.setUntilLevel(cfg.get(one + ".levelUntil", 1000));
}
Jobs.consoleMsg(one.toLowerCase() + " " + (item == null) + "");
for (Job oneJ : jobs) {
if (oneJ == null)
continue;
oneJ.getItemBonus().put(one.toLowerCase(), item);
}
@ -172,4 +221,12 @@ public class ItemBoostManager {
public static JobItems getItemByKey(String key) {
return items.get(key.toLowerCase());
}
public static HashMap<String, JobItems> getItems() {
return items;
}
public static void setItems(HashMap<String, JobItems> items) {
ItemBoostManager.items = items;
}
}

View File

@ -58,6 +58,7 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.dao.JobsDAOData;
import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.PerformCommands;
public class PlayerManager {
@ -758,7 +759,7 @@ public class PlayerManager {
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
JobItems jitem = getJobsItemByNbt(iih);
if (jitem != null && jitem.getJobs().contains(prog))
data.add(jitem.getBoost());
data.add(jitem.getBoost(this.getJobsPlayer(player).getJobProgression(prog)));
for (ItemStack OneArmor : player.getInventory().getArmorContents()) {
if (OneArmor == null || OneArmor.getType() == Material.AIR)
@ -768,7 +769,7 @@ public class PlayerManager {
if (armorboost == null || !armorboost.getJobs().contains(prog))
return data;
data.add(armorboost.getBoost());
data.add(armorboost.getBoost(this.getJobsPlayer(player).getJobProgression(prog)));
}
return data;
@ -777,40 +778,33 @@ public class PlayerManager {
public boolean containsItemBoostByNBT(ItemStack item) {
if (item == null)
return false;
return Jobs.getReflections().hasNbtString(item, "JobsItemBoost") || Jobs.getReflections().hasNbt(item, "JobsItemBoost");
return Jobs.getReflections().hasNbtString(item, "JobsItemBoost");
}
// public BoostMultiplier getItemBoostByNBT(Job prog, ItemStack item) {
// BoostMultiplier bonus = new BoostMultiplier();
//// if (prog.getItemBonus().isEmpty())
//// return bonus;
// if (item == null)
// return bonus;
//
// if (!Jobs.getReflections().hasNbtString(item, "JobsItemBoost"))
// return bonus;
//
//// Object itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost", prog.getName());
// Object itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost");
//
// if (itemName == null)
// return bonus;
// JobItems b = ItemBoostManager.getItemByKey((String) itemName);
// if (b == null)
// return bonus;
//
// return b.getBoost();
// }
public JobItems getJobsItemByNbt(ItemStack item) {
if (item == null)
return null;
// Object itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost", prog.getName());
Object itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost");
if (itemName == null) {
return null;
if (itemName == null || ((String) itemName).isEmpty()) {
// Checking old boost items and converting to new format if needed
if (Jobs.getReflections().hasNbt(item, "JobsItemBoost")) {
for (Job one : Jobs.getJobs()) {
itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost", one.getName());
if (itemName != null) {
JobItems b = ItemBoostManager.getItemByKey((String) itemName);
if (b != null) {
ItemStack ic = Jobs.getReflections().setNbt(item, "JobsItemBoost", b.getNode());
item.setItemMeta(ic.getItemMeta());
}
break;
}
}
}
if (itemName == null)
return null;
}
JobItems b = ItemBoostManager.getItemByKey((String) itemName);
if (b == null)
@ -819,12 +813,12 @@ public class PlayerManager {
return b;
}
public BoostMultiplier getJobsBoostByNbt(ItemStack item) {
JobItems b = getJobsItemByNbt(item);
if (b == null)
return null;
return b.getBoost();
}
// public BoostMultiplier getJobsBoostByNbt(ItemStack item) {
// JobItems b = getJobsItemByNbt(item);
// if (b == null)
// return null;
// return b.getBoost();
// }
public enum BoostOf {
McMMO, PetPay, NearSpawner, Permission, Global, Dynamic, Item, Area

View File

@ -215,27 +215,27 @@ public class Reflections {
}
}
// public Object getNbt(ItemStack item, String base, String path) {
// if (item == null)
// return null;
// try {
// Object nbt = getNbt(item);
// if (nbt == null)
// return null;
//
// Method compoundMeth = nbt.getClass().getMethod("getCompound", String.class);
// Object compoundRes = compoundMeth.invoke(nbt, base);
//
// if (compoundRes == null)
// return null;
//
// Method meth = compoundRes.getClass().getMethod("getString", String.class);
// Object res = meth.invoke(compoundRes, path);
// return res;
// } catch (Throwable e) {
// return null;
// }
// }
public Object getNbt(ItemStack item, String base, String path) {
if (item == null)
return null;
try {
Object nbt = getNbt(item);
if (nbt == null)
return null;
Method compoundMeth = nbt.getClass().getMethod("getCompound", String.class);
Object compoundRes = compoundMeth.invoke(nbt, base);
if (compoundRes == null)
return null;
Method meth = compoundRes.getClass().getMethod("getString", String.class);
Object res = meth.invoke(compoundRes, path);
return res;
} catch (Throwable e) {
return null;
}
}
//
// public ItemStack setNbt(ItemStack item, String base, String path, String value) {
// if (item == null)

View File

@ -103,6 +103,9 @@ public class edititembonus implements Cmd {
JobItems item = ItemBoostManager.getItemByKey((String) key);
if (item == null)
return true;
BoostMultiplier boost = item.getBoost();
for (Job one : item.getJobs()) {

View File

@ -63,8 +63,11 @@ public class give implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0]));
return true;
}
if (name == null)
name = actions.items;
if (name == null || itemName == null) {
if (itemName == null) {
Jobs.getCommandManager().sendUsage(sender, "give");
return true;
}

View File

@ -59,7 +59,7 @@ public class itembonus implements Cmd {
if (jitem == null)
continue;
for (Job one : jitem.getJobs()) {
BoostMultiplier boost = jitem.getBoost();
BoostMultiplier boost = jitem.getBoost(jPlayer.getJobProgression(one));
boolean any = false;
for (CurrencyType oneC : CurrencyType.values()) {
if (boost.get(oneC) != 0D)

View File

@ -209,7 +209,7 @@ public class LanguageManager {
c.get("command.edititembonus.help.info", "Edit item boost bonus");
c.get("command.edititembonus.help.args", "list/add/remove [jobname] [itemBoostName]");
Jobs.getGCManager().commandArgs.put("edititembonus", Arrays.asList("list%%add%%remove", "[jobname]", "[jobitemname]"));
Jobs.getGCManager().commandArgs.put("edititembonus", Arrays.asList("list%%add%%remove", "[boosteditems]"));
c.get("command.bonus.help.info", "Show job bonuses");
c.get("command.bonus.help.args", "[jobname]");

View File

@ -369,6 +369,8 @@ public class Job {
*/
@Deprecated
public HashMap<String, JobItems> getItemBonus() {
if (jobItems == null)
jobItems = new HashMap<String, JobItems>();
return jobItems;
}

View File

@ -38,9 +38,11 @@ public class JobItems {
ItemStack item;
private BoostMultiplier boostMultiplier = new BoostMultiplier();
private List<Job> jobs = new ArrayList<Job>();
private int fromLevel = 0;
private int untilLevel = Integer.MAX_VALUE;
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs) {
mat = mat == null ? CMIMaterial.STONE : mat;
try {
item = mat.newItemStack();
item.setAmount(amount);
@ -103,6 +105,14 @@ public class JobItems {
return boostMultiplier.clone();
}
public BoostMultiplier getBoost(JobProgression job) {
if (job == null || !this.jobs.contains(job.getJob()))
return new BoostMultiplier();
if (job.getLevel() < getFromLevel() || job.getLevel() > getUntilLevel())
return new BoostMultiplier();
return boostMultiplier.clone();
}
public List<Job> getJobs() {
return jobs;
}
@ -110,4 +120,20 @@ public class JobItems {
public void setJobs(List<Job> jobs) {
this.jobs = jobs;
}
public int getFromLevel() {
return fromLevel;
}
public void setFromLevel(int fromLevel) {
this.fromLevel = fromLevel;
}
public int getUntilLevel() {
return untilLevel;
}
public void setUntilLevel(int untilLevel) {
this.untilLevel = untilLevel;
}
}

View File

@ -76,17 +76,24 @@ public class TabComplete implements TabCompleter {
}
break;
case "[jobitemname]":
Job oneJob = Jobs.getJob(args[i - 1]);
if (oneJob != null)
if (args[3].equals("items")) {
for (Entry<String, JobItems> item : ItemBoostManager.getItemsMapByJob(oneJob).entrySet()) {
temp.add(item.getValue().getNode());
}
} else if (args[3].equals("limiteditems")) {
for (Entry<String, JobLimitedItems> limitedItem : oneJob.getLimitedItems().entrySet()) {
temp.add(limitedItem.getValue().getNode());
}
if (args[3].equals("items")) {
for (Entry<String, JobItems> one : ItemBoostManager.getItems().entrySet()) {
temp.add(one.getValue().getNode());
}
} else if (args[3].equals("limiteditems")) {
Job oneJob = Jobs.getJob(args[i - 1]);
if (oneJob != null)
if (args[3].equals("limiteditems")) {
for (Entry<String, JobLimitedItems> limitedItem : oneJob.getLimitedItems().entrySet()) {
temp.add(limitedItem.getValue().getNode());
}
}
}
break;
case "[boosteditems]":
for (Entry<String, JobItems> one : ItemBoostManager.getItems().entrySet()) {
temp.add(one.getValue().getNode());
}
break;
case "[oldjob]":
JobsPlayer onePlayerJob = Jobs.getPlayerManager().getJobsPlayer(args[i - 1]);