mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-02 14:29:07 +01:00
item boost now being controled by NBT data
cache is included for performance boost new commands itembonus and edititembonus old item updates on new command usage
This commit is contained in:
parent
3af38fdaa4
commit
15fd5b97a2
@ -136,6 +136,8 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
private static ConfigManager configManager;
|
||||
private static GeneralConfigManager GconfigManager;
|
||||
|
||||
private static Reflections reflections;
|
||||
|
||||
private static Logger pLogger;
|
||||
private static File dataFolder;
|
||||
@ -240,6 +242,12 @@ public class Jobs extends JavaPlugin {
|
||||
return BpManager;
|
||||
}
|
||||
|
||||
public static Reflections getReflections() {
|
||||
if (reflections == null)
|
||||
reflections = new Reflections(instance);
|
||||
return reflections;
|
||||
}
|
||||
|
||||
public static JobsManager getDBManager() {
|
||||
if (DBManager == null)
|
||||
DBManager = new JobsManager(instance);
|
||||
|
@ -16,4 +16,6 @@ public interface NMS {
|
||||
public ItemStack getItemInMainHand(Player player);
|
||||
|
||||
public Block getTargetBlock(Player player, int range);
|
||||
|
||||
void setItemInMainHand(Player player, ItemStack item);
|
||||
}
|
||||
|
@ -45,8 +45,10 @@ import com.gamingmesh.jobs.container.ArchivedJobs;
|
||||
import com.gamingmesh.jobs.container.Boost;
|
||||
import com.gamingmesh.jobs.container.BoostMultiplier;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.ItemBonusCache;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobCommands;
|
||||
import com.gamingmesh.jobs.container.JobItemBonus;
|
||||
import com.gamingmesh.jobs.container.JobItems;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
@ -727,30 +729,129 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
public BoostMultiplier getItemBoost(Player player, Job prog) {
|
||||
// public BoostMultiplier getItemBoost(Player player, Job prog) {
|
||||
// Long time = System.nanoTime();
|
||||
// BoostMultiplier data = new BoostMultiplier();
|
||||
// if (player == null)
|
||||
// return data;
|
||||
// if (prog == null)
|
||||
// return data;
|
||||
// ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
||||
// data = Jobs.getPlayerManager().getItemBoost(prog, iih);
|
||||
// for (ItemStack OneArmor : player.getInventory().getArmorContents()) {
|
||||
// if (OneArmor == null || OneArmor.getType() == Material.AIR)
|
||||
// continue;
|
||||
// BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoost(prog, OneArmor);
|
||||
// data.add(armorboost);
|
||||
// }
|
||||
// Debug.D("Calculated item boost in: " + (System.nanoTime() - time));
|
||||
//
|
||||
// return data;
|
||||
// }
|
||||
|
||||
HashMap<UUID, HashMap<Job, ItemBonusCache>> cache = new HashMap<UUID, HashMap<Job, ItemBonusCache>>();
|
||||
|
||||
public void resetiItemBonusCache(UUID uuid) {
|
||||
cache.remove(uuid);
|
||||
}
|
||||
|
||||
public BoostMultiplier getItemBoostNBT(Player player, Job prog) {
|
||||
|
||||
Long time = System.nanoTime();
|
||||
HashMap<Job, ItemBonusCache> cj = cache.get(player.getUniqueId());
|
||||
|
||||
if (cj == null) {
|
||||
cj = new HashMap<Job, ItemBonusCache>();
|
||||
cache.put(player.getUniqueId(), cj);
|
||||
}
|
||||
|
||||
ItemBonusCache c = cj.get(prog);
|
||||
if (c == null) {
|
||||
c = new ItemBonusCache(player, prog);
|
||||
c.recheck();
|
||||
cj.put(prog, c);
|
||||
Debug.D("NBT Calculated item boost in: " + (System.nanoTime() - time));
|
||||
return c.getBoostMultiplier();
|
||||
}
|
||||
|
||||
Debug.D("NBT Calculated item boost in: " + (System.nanoTime() - time));
|
||||
return c.getBoostMultiplier();
|
||||
}
|
||||
|
||||
public BoostMultiplier getInventoryBoost(Player player, Job prog) {
|
||||
BoostMultiplier data = new BoostMultiplier();
|
||||
if (player == null)
|
||||
return data;
|
||||
if (prog == null)
|
||||
return data;
|
||||
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
||||
data = Jobs.getPlayerManager().getItemBoost(prog, iih);
|
||||
data = Jobs.getPlayerManager().getItemBoostByNBT(prog, iih);
|
||||
for (ItemStack OneArmor : player.getInventory().getArmorContents()) {
|
||||
if (OneArmor == null || OneArmor.getType() == Material.AIR)
|
||||
continue;
|
||||
BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoost(prog, OneArmor);
|
||||
BoostMultiplier armorboost = Jobs.getPlayerManager().getItemBoostByNBT(prog, OneArmor);
|
||||
data.add(armorboost);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// @SuppressWarnings("deprecation")
|
||||
// public BoostMultiplier getItemBoost(Job prog, ItemStack item) {
|
||||
// BoostMultiplier bonus = new BoostMultiplier();
|
||||
// if (prog.getItemBonus().isEmpty())
|
||||
// return bonus;
|
||||
// if (item == null)
|
||||
// return bonus;
|
||||
//
|
||||
// ItemMeta meta = item.getItemMeta();
|
||||
// String name = null;
|
||||
// List<String> lore = new ArrayList<String>();
|
||||
//
|
||||
// if (item.hasItemMeta()) {
|
||||
// if (meta.hasDisplayName())
|
||||
// name = meta.getDisplayName();
|
||||
// if (meta.hasLore())
|
||||
// lore = meta.getLore();
|
||||
// }
|
||||
//
|
||||
// Map<Enchantment, Integer> enchants = item.getEnchantments();
|
||||
//
|
||||
// main: for (Entry<String, JobItems> one : prog.getItemBonus().entrySet()) {
|
||||
// JobItems oneItem = one.getValue();
|
||||
// if (oneItem.getId() != item.getTypeId())
|
||||
// continue;
|
||||
//
|
||||
// if (oneItem.getName() != null && name != null)
|
||||
// if (!org.bukkit.ChatColor.translateAlternateColorCodes('&', oneItem.getName()).equalsIgnoreCase(name))
|
||||
// continue;
|
||||
//
|
||||
// for (String onelore : oneItem.getLore()) {
|
||||
// if (lore.size() == 0 || !lore.contains(onelore))
|
||||
// continue main;
|
||||
// }
|
||||
//
|
||||
// for (Entry<Enchantment, Integer> oneE : enchants.entrySet()) {
|
||||
// if (oneItem.getEnchants().containsKey(oneE.getKey())) {
|
||||
// if (oneItem.getEnchants().get(oneE.getKey()) < oneE.getValue()) {
|
||||
// continue main;
|
||||
// }
|
||||
// } else
|
||||
// continue main;
|
||||
// }
|
||||
//
|
||||
// return oneItem.getBoost();
|
||||
// }
|
||||
//
|
||||
// return bonus;
|
||||
// }
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public BoostMultiplier getItemBoost(Job prog, ItemStack item) {
|
||||
BoostMultiplier bonus = new BoostMultiplier();
|
||||
if (prog.getItems().isEmpty())
|
||||
return bonus;
|
||||
public JobItems getOldItemBoost(Job prog, ItemStack item) {
|
||||
if (prog.getItemBonus().isEmpty())
|
||||
return null;
|
||||
if (item == null)
|
||||
return bonus;
|
||||
return null;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String name = null;
|
||||
@ -765,7 +866,8 @@ public class PlayerManager {
|
||||
|
||||
Map<Enchantment, Integer> enchants = item.getEnchantments();
|
||||
|
||||
main: for (JobItems oneItem : prog.getItems()) {
|
||||
main: for (Entry<String, JobItems> one : prog.getItemBonus().entrySet()) {
|
||||
JobItems oneItem = one.getValue();
|
||||
if (oneItem.getId() != item.getTypeId())
|
||||
continue;
|
||||
|
||||
@ -787,10 +889,84 @@ public class PlayerManager {
|
||||
continue main;
|
||||
}
|
||||
|
||||
return oneItem.getBoost();
|
||||
return oneItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean containsItemBoostByNBT(ItemStack item) {
|
||||
if (item == null)
|
||||
return false;
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
if (one.getItemBonus().isEmpty())
|
||||
continue;
|
||||
if (!Jobs.getReflections().hasNbt(item, "JobsItemBoost"))
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateOldItems(Player player) {
|
||||
|
||||
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
||||
if (iih != null && !iih.getType().equals(Material.AIR) && Jobs.getPlayerManager().containsItemBoostByNBT(iih) && !Jobs.getReflections().hasNbt(iih, "JobsItemBoost")) {
|
||||
boolean changed = false;
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
JobItems jitem = Jobs.getPlayerManager().getOldItemBoost(one, iih);
|
||||
if (jitem == null)
|
||||
continue;
|
||||
|
||||
iih = Jobs.getReflections().setNbt(iih, "JobsItemBoost", one.getName(), jitem.getNode());
|
||||
changed = true;
|
||||
}
|
||||
if (changed)
|
||||
Jobs.getNms().setItemInMainHand(player, iih);
|
||||
}
|
||||
|
||||
return bonus;
|
||||
ItemStack[] cont = player.getInventory().getArmorContents();
|
||||
|
||||
boolean gchanged = false;
|
||||
for (int i = 0; i < cont.length; i++) {
|
||||
ItemStack item = cont[i];
|
||||
if (item == null || item.getType().equals(Material.AIR) || Jobs.getReflections().hasNbt(iih, "JobsItemBoost"))
|
||||
continue;
|
||||
boolean changed = false;
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
JobItems jitem = Jobs.getPlayerManager().getOldItemBoost(one, item);
|
||||
if (jitem == null)
|
||||
continue;
|
||||
item = Jobs.getReflections().setNbt(item, "JobsItemBoost", one.getName(), jitem.getNode());
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
cont[i] = item;
|
||||
gchanged = true;
|
||||
}
|
||||
}
|
||||
if (gchanged)
|
||||
player.getInventory().setArmorContents(cont);
|
||||
}
|
||||
|
||||
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().hasNbt(item, "JobsItemBoost"))
|
||||
return bonus;
|
||||
|
||||
Object itemName = Jobs.getReflections().getNbt(item, "JobsItemBoost", prog.getName());
|
||||
|
||||
if (itemName == null)
|
||||
return bonus;
|
||||
JobItems b = prog.getItemBonus((String) itemName);
|
||||
if (b == null)
|
||||
return bonus;
|
||||
|
||||
return b.getBoost();
|
||||
}
|
||||
|
||||
public enum BoostOf {
|
||||
@ -856,7 +1032,8 @@ public class PlayerManager {
|
||||
boost.add(BoostOf.Global, prog.getBoost());
|
||||
if (Jobs.getGCManager().useDynamicPayment)
|
||||
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
|
||||
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
|
||||
// boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
|
||||
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoostNBT(player.getPlayer(), prog));
|
||||
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
|
||||
|
||||
return boost;
|
||||
|
321
src/main/java/com/gamingmesh/jobs/Reflections.java
Normal file
321
src/main/java/com/gamingmesh/jobs/Reflections.java
Normal file
@ -0,0 +1,321 @@
|
||||
/**
|
||||
* Copyright (C) 2017 Zrips
|
||||
*/
|
||||
|
||||
package com.gamingmesh.jobs;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Reflections {
|
||||
|
||||
private Class<?> CraftServerClass;
|
||||
private Object CraftServer;
|
||||
|
||||
private Class<?> NBTTagCompound;
|
||||
private Class<?> NBTBase;
|
||||
|
||||
private Class<?> CraftItemStack;
|
||||
private Class<?> Item;
|
||||
private Class<?> IStack;
|
||||
private Jobs plugin;
|
||||
|
||||
public Reflections(Jobs plugin) {
|
||||
this.plugin = plugin;
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
try {
|
||||
CraftServerClass = getBukkitClass("CraftServer");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
CraftServer = CraftServerClass.cast(Bukkit.getServer());
|
||||
} catch (SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
NBTTagCompound = getMinecraftClass("NBTTagCompound");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
NBTBase = getMinecraftClass("NBTBase");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
CraftItemStack = getBukkitClass("inventory.CraftItemStack");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Item = getMinecraftClass("Item");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
IStack = getMinecraftClass("ItemStack");
|
||||
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> getBukkitClass(String nmsClassString) throws ClassNotFoundException {
|
||||
return Class.forName("org.bukkit.craftbukkit." + Jobs.getVersionCheckManager().getVersion() + "." + nmsClassString);
|
||||
}
|
||||
|
||||
public Class<?> getMinecraftClass(String nmsClassString) throws ClassNotFoundException {
|
||||
return Class.forName("net.minecraft.server." + Jobs.getVersionCheckManager().getVersion() + "." + nmsClassString);
|
||||
}
|
||||
|
||||
public String getItemMinecraftName(ItemStack item) {
|
||||
try {
|
||||
Object nmsStack = asNMSCopy(item);
|
||||
Method itemMeth = Item.getMethod("getById", int.class);
|
||||
Object res = itemMeth.invoke(Item, item.getTypeId());
|
||||
|
||||
String ff = "b";
|
||||
switch (Jobs.getVersionCheckManager().getVersion()) {
|
||||
case v1_10_R1:
|
||||
case v1_9_R1:
|
||||
case v1_9_R2:
|
||||
case v1_8_R1:
|
||||
case v1_8_R3:
|
||||
case v1_8_R2:
|
||||
ff = "a";
|
||||
break;
|
||||
case v1_11_R1:
|
||||
case v1_11_R2:
|
||||
case v1_12_R1:
|
||||
case v1_13_R2:
|
||||
case v1_12_R2:
|
||||
case v1_13_R1:
|
||||
ff = "b";
|
||||
break;
|
||||
case v1_7_R1:
|
||||
case v1_7_R2:
|
||||
case v1_7_R3:
|
||||
case v1_7_R4:
|
||||
ff = "n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Method meth2 = res.getClass().getMethod(ff, IStack);
|
||||
Object name = meth2.invoke(res, nmsStack);
|
||||
return name.toString();
|
||||
} catch (Exception e) {
|
||||
return item != null ? item.getType().name() : "";
|
||||
}
|
||||
}
|
||||
|
||||
// public ItemStack removeNbt(ItemStack item, String path) {
|
||||
// if (item == null)
|
||||
// return null;
|
||||
// try {
|
||||
// Object nmsStack = asNMSCopy(item);
|
||||
// Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
// Object tag = methTag.invoke(nmsStack);
|
||||
// if (tag == null)
|
||||
// tag = NBTTagCompound.newInstance();
|
||||
// Method meth = tag.getClass().getMethod("remove", String.class);
|
||||
// meth.invoke(tag, path);
|
||||
// Method meth2 = nmsStack.getClass().getMethod("setTag", NBTTagCompound);
|
||||
// meth2.invoke(nmsStack, tag);
|
||||
// return (ItemStack) asBukkitCopy(nmsStack);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
public ItemStack removeNbt(ItemStack item, String base, String path) {
|
||||
if (item == null)
|
||||
return null;
|
||||
try {
|
||||
Object nmsStack = asNMSCopy(item);
|
||||
Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
Object tag = methTag.invoke(nmsStack);
|
||||
if (tag == null)
|
||||
return item;
|
||||
|
||||
Method compountMeth = tag.getClass().getMethod("getCompound", String.class);
|
||||
Object compountTag = compountMeth.invoke(tag, base);
|
||||
|
||||
if (compountTag == null)
|
||||
return item;
|
||||
|
||||
Method meth = compountTag.getClass().getMethod("remove", String.class);
|
||||
meth.invoke(compountTag, path);
|
||||
|
||||
Method mm = tag.getClass().getMethod("set", String.class, NBTBase);
|
||||
mm.invoke(tag, base, compountTag);
|
||||
|
||||
Method meth2 = nmsStack.getClass().getMethod("setTag", NBTTagCompound);
|
||||
meth2.invoke(nmsStack, tag);
|
||||
return (ItemStack) asBukkitCopy(nmsStack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// public boolean hasNbt(ItemStack item) {
|
||||
// if (item == null)
|
||||
// return false;
|
||||
// try {
|
||||
// Object nmsStack = asNMSCopy(item);
|
||||
// Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
// Object tag = methTag.invoke(nmsStack);
|
||||
// return tag != null;
|
||||
// } catch (Exception e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
public boolean hasNbt(ItemStack item, String base) {
|
||||
if (item == null)
|
||||
return false;
|
||||
try {
|
||||
Object nbt = getNbt(item);
|
||||
if (nbt == null)
|
||||
return false;
|
||||
Method meth = nbt.getClass().getMethod("getCompound", String.class);
|
||||
Object res = meth.invoke(nbt, base);
|
||||
return res != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getNbt(ItemStack item) {
|
||||
if (item == null)
|
||||
return null;
|
||||
try {
|
||||
Object nmsStack = asNMSCopy(item);
|
||||
Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
Object tag = methTag.invoke(nmsStack);
|
||||
return tag;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// public Object getNbt(ItemStack item, String path) {
|
||||
// if (item == null)
|
||||
// return null;
|
||||
// try {
|
||||
// Object nbt = getNbt(item);
|
||||
// if (nbt == null)
|
||||
// return null;
|
||||
// Method meth = nbt.getClass().getMethod("getString", String.class);
|
||||
// Object res = meth.invoke(nbt, path);
|
||||
// return res;
|
||||
// } catch (Exception 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 (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// public ItemStack setNbt(ItemStack item, String path, String value) {
|
||||
// if (item == null)
|
||||
// return null;
|
||||
// try {
|
||||
// Object nmsStack = asNMSCopy(item);
|
||||
// Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
// Object tag = methTag.invoke(nmsStack);
|
||||
// if (tag == null)
|
||||
// tag = NBTTagCompound.newInstance();
|
||||
// Method meth = tag.getClass().getMethod("setString", String.class, String.class);
|
||||
// meth.invoke(tag, path, value);
|
||||
// Method meth2 = nmsStack.getClass().getMethod("setTag", NBTTagCompound);
|
||||
// meth2.invoke(nmsStack, tag);
|
||||
// return (ItemStack) asBukkitCopy(nmsStack);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
public ItemStack setNbt(ItemStack item, String base, String path, String value) {
|
||||
if (item == null)
|
||||
return null;
|
||||
try {
|
||||
Object nmsStack = asNMSCopy(item);
|
||||
Method methTag = nmsStack.getClass().getMethod("getTag");
|
||||
Object tag = methTag.invoke(nmsStack);
|
||||
if (tag == null)
|
||||
tag = NBTTagCompound.newInstance();
|
||||
|
||||
Method compountMeth = tag.getClass().getMethod("getCompound", String.class);
|
||||
Object compountTag = compountMeth.invoke(tag, base);
|
||||
|
||||
if (compountTag == null)
|
||||
compountTag = NBTTagCompound.newInstance();
|
||||
|
||||
Method meth = compountTag.getClass().getMethod("setString", String.class, String.class);
|
||||
meth.invoke(compountTag, path, value);
|
||||
|
||||
Method mm = tag.getClass().getMethod("set", String.class, NBTBase);
|
||||
mm.invoke(tag, base, compountTag);
|
||||
|
||||
Method meth2 = nmsStack.getClass().getMethod("setTag", NBTTagCompound);
|
||||
meth2.invoke(nmsStack, tag);
|
||||
return (ItemStack) asBukkitCopy(nmsStack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object asNMSCopy(ItemStack item) {
|
||||
try {
|
||||
Method meth = CraftItemStack.getMethod("asNMSCopy", ItemStack.class);
|
||||
return meth.invoke(CraftItemStack, item);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object asBukkitCopy(Object item) {
|
||||
try {
|
||||
Method meth = CraftItemStack.getMethod("asBukkitCopy", IStack);
|
||||
return meth.invoke(CraftItemStack, item);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getCraftServer() {
|
||||
return CraftServer;
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -35,7 +36,6 @@ import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobInfo;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
import com.gamingmesh.jobs.stuff.PageInfo;
|
||||
import com.gamingmesh.jobs.stuff.RawMessage;
|
||||
|
||||
|
@ -42,6 +42,8 @@ public class bonus implements Cmd {
|
||||
if (jPlayer == null)
|
||||
return false;
|
||||
|
||||
Jobs.getPlayerManager().updateOldItems(player);
|
||||
|
||||
Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job, true, true);
|
||||
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline"));
|
||||
|
@ -0,0 +1,127 @@
|
||||
package com.gamingmesh.jobs.commands.list;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.commands.JobCommand;
|
||||
import com.gamingmesh.jobs.container.BoostMultiplier;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobItemBonus;
|
||||
import com.gamingmesh.jobs.container.JobItems;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
|
||||
public class edititembonus implements Cmd {
|
||||
|
||||
private enum actions {
|
||||
list, add, remove;
|
||||
public static actions getByname(String name) {
|
||||
for (actions one : actions.values()) {
|
||||
if (one.name().equalsIgnoreCase(name))
|
||||
return one;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@JobCommand(300)
|
||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1)
|
||||
return false;
|
||||
|
||||
actions action = null;
|
||||
Job job = null;
|
||||
JobItems jobitem = null;
|
||||
|
||||
for (String one : args) {
|
||||
if (action == null) {
|
||||
action = actions.getByname(one);
|
||||
if (action != null)
|
||||
continue;
|
||||
}
|
||||
if (job == null) {
|
||||
job = Jobs.getJob(one);
|
||||
if (job != null)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (job != null) {
|
||||
jobitem = job.getItemBonus(one);
|
||||
}
|
||||
}
|
||||
|
||||
if (action == null)
|
||||
return false;
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
|
||||
if (jPlayer == null)
|
||||
return false;
|
||||
|
||||
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
||||
|
||||
if (iih == null || iih.getType().equals(Material.AIR))
|
||||
return false;
|
||||
|
||||
switch (action) {
|
||||
case add:
|
||||
if (job == null || jobitem == null)
|
||||
return false;
|
||||
iih = Jobs.getReflections().setNbt(iih, "JobsItemBoost", job.getName(), jobitem.getNode());
|
||||
Jobs.getNms().setItemInMainHand(player, iih);
|
||||
break;
|
||||
case list:
|
||||
break;
|
||||
case remove:
|
||||
if (job == null)
|
||||
return false;
|
||||
iih = Jobs.getReflections().removeNbt(iih, "JobsItemBoost", job.getName());
|
||||
Jobs.getNms().setItemInMainHand(player, iih);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline"));
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
BoostMultiplier boost = Jobs.getPlayerManager().getItemBoostByNBT(one, iih);
|
||||
boolean any = false;
|
||||
for (CurrencyType oneC : CurrencyType.values()) {
|
||||
if (boost.get(oneC) != 0D)
|
||||
any = true;
|
||||
}
|
||||
if (!any)
|
||||
continue;
|
||||
String msg = Jobs.getLanguage().getMessage("command.itembonus.output.list",
|
||||
"[jobname]", one.getName(),
|
||||
"%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)),
|
||||
"%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)),
|
||||
"%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100)));
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String mc = ChatColor.DARK_GREEN.toString();
|
||||
String pc = ChatColor.GOLD.toString();
|
||||
String ec = ChatColor.YELLOW.toString();
|
||||
|
||||
private static String formatText(double amount) {
|
||||
return ((amount > 0 ? "+" : "") + amount + "%");
|
||||
}
|
||||
|
||||
}
|
@ -49,21 +49,14 @@ public class give implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
JobItems jItem = null;
|
||||
|
||||
for (JobItems item : job.getItems()) {
|
||||
if (item.getNode().equalsIgnoreCase(itemName)) {
|
||||
jItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
JobItems jItem = job.getItemBonus(itemName);
|
||||
|
||||
if (jItem == null || jItem.getItemStack(player) == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem"));
|
||||
return true;
|
||||
}
|
||||
|
||||
GiveItem.GiveItemForPlayer(player, jItem.getItemStack(player));
|
||||
|
||||
GiveItem.GiveItemForPlayer(player, jItem.getItemStack(player, job));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.gamingmesh.jobs.commands.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.commands.JobCommand;
|
||||
import com.gamingmesh.jobs.container.BoostMultiplier;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
import com.gamingmesh.jobs.stuff.RawMessage;
|
||||
|
||||
public class itembonus implements Cmd {
|
||||
|
||||
@Override
|
||||
@JobCommand(300)
|
||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
|
||||
return false;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
|
||||
if (jPlayer == null)
|
||||
return false;
|
||||
|
||||
Jobs.getPlayerManager().updateOldItems(player);
|
||||
|
||||
ItemStack iih = Jobs.getNms().getItemInMainHand(player);
|
||||
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
|
||||
if (iih != null && !iih.getType().equals(Material.AIR))
|
||||
items.add(iih);
|
||||
|
||||
for (ItemStack OneArmor : player.getInventory().getArmorContents()) {
|
||||
if (OneArmor == null || OneArmor.getType() == Material.AIR)
|
||||
continue;
|
||||
items.add(OneArmor);
|
||||
}
|
||||
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline"));
|
||||
|
||||
for (ItemStack oneI : items) {
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
BoostMultiplier boost = Jobs.getPlayerManager().getItemBoostByNBT(one, oneI);
|
||||
boolean any = false;
|
||||
for (CurrencyType oneC : CurrencyType.values()) {
|
||||
if (boost.get(oneC) != 0D)
|
||||
any = true;
|
||||
}
|
||||
if (!any)
|
||||
continue;
|
||||
String msg = Jobs.getLanguage().getMessage("command.itembonus.output.list",
|
||||
"[jobname]", one.getName(),
|
||||
"%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)),
|
||||
"%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)),
|
||||
"%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100)));
|
||||
RawMessage rm = new RawMessage();
|
||||
String name = oneI.getType().name().replace("_", " ").toLowerCase();
|
||||
name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
rm.add(msg, name);
|
||||
rm.show(sender);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
String mc = ChatColor.DARK_GREEN.toString();
|
||||
String pc = ChatColor.GOLD.toString();
|
||||
String ec = ChatColor.YELLOW.toString();
|
||||
|
||||
private static String formatText(double amount) {
|
||||
return ((amount > 0 ? "+" : "") + amount + "%");
|
||||
}
|
||||
|
||||
}
|
@ -610,7 +610,7 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
// Items
|
||||
ArrayList<JobItems> jobItems = new ArrayList<JobItems>();
|
||||
HashMap<String, JobItems> jobItems = new HashMap<String, JobItems>();
|
||||
ConfigurationSection itemsSection = jobSection.getConfigurationSection("items");
|
||||
if (itemsSection != null) {
|
||||
for (String itemKey : itemsSection.getKeys(false)) {
|
||||
@ -660,7 +660,7 @@ public class ConfigManager {
|
||||
if (itemSection.isDouble("expBoost"))
|
||||
b.add(CurrencyType.EXP, itemSection.getDouble("expBoost") - 1);
|
||||
|
||||
jobItems.add(new JobItems(node, id, 0, 1, name, lore, enchants, b));
|
||||
jobItems.put(node.toLowerCase(), new JobItems(node, id, 0, 1, name, lore, enchants, b));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,6 +194,14 @@ public class LanguageManager {
|
||||
c.get("command.expboost.output.boostadded", "Exp boost of &e%boost% &aadded for &e%jobname%!");
|
||||
c.get("command.expboost.output.infostats", "&c-----> &aExp rate x%boost% enabled&c <-------");
|
||||
|
||||
c.get("command.itembonus.help.info", "Check item bonus");
|
||||
c.get("command.itembonus.help.args", "");
|
||||
c.get("command.itembonus.output.list", "&e[jobname]: %money% %points% %exp%");
|
||||
|
||||
c.get("command.edititembonus.help.info", "Edit item boost bonus");
|
||||
c.get("command.edititembonus.help.args", "[list/add/remove] [jobsName] [itemBoostName]");
|
||||
Jobs.getGCManager().commandArgs.put("edititembonus", Arrays.asList("add%%remove", "[jobname]", "[jobitemname]"));
|
||||
|
||||
c.get("command.bonus.help.info", "Show job bonuses");
|
||||
c.get("command.bonus.help.args", "[jobname]");
|
||||
Jobs.getGCManager().commandArgs.put("bonus", Arrays.asList("[jobname]"));
|
||||
@ -208,6 +216,9 @@ public class LanguageManager {
|
||||
c.get("command.bonus.output.mcmmo", " &eMcMMO bonus: %money% %points% %exp%");
|
||||
c.get("command.bonus.output.final", " &eFinal bonus: %money% %points% %exp%");
|
||||
c.get("command.bonus.output.finalExplanation", " &eDoes not include Petpay and Near spawner bonus/penalty");
|
||||
|
||||
|
||||
|
||||
|
||||
c.get("command.convert.help.info",
|
||||
"Converts data base system from one system to another. if you currently running sqlite, this will convert to Mysql and vise versa.");
|
||||
|
53
src/main/java/com/gamingmesh/jobs/container/ArmorTypes.java
Normal file
53
src/main/java/com/gamingmesh/jobs/container/ArmorTypes.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public enum ArmorTypes {
|
||||
HELMET(5), CHESTPLATE(6), LEGGINGS(7), BOOTS(8), ELYTRA(6);
|
||||
|
||||
private final int slot;
|
||||
|
||||
ArmorTypes(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public final static ArmorTypes matchType(final ItemStack itemStack) {
|
||||
if (itemStack == null)
|
||||
return null;
|
||||
|
||||
switch (itemStack.getType()) {
|
||||
case DIAMOND_HELMET:
|
||||
case GOLD_HELMET:
|
||||
case IRON_HELMET:
|
||||
case CHAINMAIL_HELMET:
|
||||
case LEATHER_HELMET:
|
||||
return HELMET;
|
||||
case DIAMOND_CHESTPLATE:
|
||||
case GOLD_CHESTPLATE:
|
||||
case IRON_CHESTPLATE:
|
||||
case CHAINMAIL_CHESTPLATE:
|
||||
case LEATHER_CHESTPLATE:
|
||||
return CHESTPLATE;
|
||||
case DIAMOND_LEGGINGS:
|
||||
case GOLD_LEGGINGS:
|
||||
case IRON_LEGGINGS:
|
||||
case CHAINMAIL_LEGGINGS:
|
||||
case LEATHER_LEGGINGS:
|
||||
return LEGGINGS;
|
||||
case DIAMOND_BOOTS:
|
||||
case GOLD_BOOTS:
|
||||
case IRON_BOOTS:
|
||||
case CHAINMAIL_BOOTS:
|
||||
case LEATHER_BOOTS:
|
||||
return BOOTS;
|
||||
case ELYTRA:
|
||||
return ELYTRA;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
|
||||
public class ItemBonusCache {
|
||||
|
||||
Player player;
|
||||
private Long lastCheck = null;
|
||||
private BoostMultiplier bm = new BoostMultiplier();
|
||||
private Job job;
|
||||
|
||||
public ItemBonusCache(Player player, Job job) {
|
||||
this.player = player;
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public Long getLastCheck() {
|
||||
return lastCheck;
|
||||
}
|
||||
|
||||
public void setLastCheck(Long lastCheck) {
|
||||
this.lastCheck = lastCheck;
|
||||
}
|
||||
|
||||
public BoostMultiplier getBoostMultiplier() {
|
||||
if (lastCheck == null || System.currentTimeMillis() - lastCheck > 1000 * 60)
|
||||
recheck();
|
||||
return bm;
|
||||
}
|
||||
|
||||
public void setBoostMultiplier(BoostMultiplier bm) {
|
||||
this.bm = bm;
|
||||
}
|
||||
|
||||
public ItemBonusCache recheck() {
|
||||
Debug.D("recalculating item bonus");
|
||||
bm = Jobs.getPlayerManager().getInventoryBoost(player, job);
|
||||
lastCheck = System.currentTimeMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ package com.gamingmesh.jobs.container;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@ -43,7 +44,7 @@ public class Job {
|
||||
// conditions
|
||||
private List<JobConditions> jobConditions;
|
||||
// items
|
||||
private List<JobItems> jobItems;
|
||||
private HashMap<String, JobItems> jobItems;
|
||||
// limited items
|
||||
private List<JobLimitedItems> jobLimitedItems;
|
||||
// job name
|
||||
@ -106,7 +107,7 @@ public class Job {
|
||||
* @param jobConditions - jobs conditions
|
||||
*/
|
||||
public Job(String jobName, String jobShortName, String description, ChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
|
||||
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, List<JobItems> jobItems,
|
||||
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems,
|
||||
List<JobLimitedItems> jobLimitedItems, List<String> CmdOnJoin, List<String> CmdOnLeave, ItemStack GUIitem, String bossbar, Long rejoinCD) {
|
||||
this.jobName = jobName;
|
||||
this.jobShortName = jobShortName;
|
||||
@ -364,8 +365,12 @@ public class Job {
|
||||
* Get the item nodes for this job
|
||||
* @return Items for this job
|
||||
*/
|
||||
public List<JobItems> getItems() {
|
||||
return Collections.unmodifiableList(jobItems);
|
||||
public HashMap<String, JobItems> getItemBonus() {
|
||||
return jobItems;
|
||||
}
|
||||
|
||||
public JobItems getItemBonus(String key) {
|
||||
return jobItems.get(key.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Jobs Plugin for Bukkit
|
||||
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
public class JobItemBonus {
|
||||
private String node;
|
||||
private BoostMultiplier boostMultiplier = new BoostMultiplier();
|
||||
|
||||
public JobItemBonus(String node, BoostMultiplier boostMultiplier) {
|
||||
this.node = node;
|
||||
this.boostMultiplier = boostMultiplier;
|
||||
}
|
||||
|
||||
public String getNode() {
|
||||
return this.node;
|
||||
}
|
||||
|
||||
public BoostMultiplier getBoost() {
|
||||
return this.boostMultiplier.clone();
|
||||
}
|
||||
}
|
@ -30,6 +30,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class JobItems {
|
||||
private String node;
|
||||
private int id;
|
||||
@ -56,6 +58,10 @@ public class JobItems {
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player player) {
|
||||
return getItemStack(player, null);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(Player player, Job job) {
|
||||
try {
|
||||
ItemStack item = new ItemStack(Material.getMaterial(id), amount, (short) data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
@ -73,6 +79,10 @@ public class JobItems {
|
||||
meta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
|
||||
if (job != null)
|
||||
item = Jobs.getReflections().setNbt(item, "JobsItemBoost", job.getName(), node);
|
||||
|
||||
return item;
|
||||
} catch (Exception e) {
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
package com.gamingmesh.jobs.container;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class JobsArmorChangeEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final EquipMethod equipType;
|
||||
private final ArmorTypes type;
|
||||
private ItemStack oldArmorPiece, newArmorPiece;
|
||||
|
||||
public JobsArmorChangeEvent(final Player player, final EquipMethod equipType, ArmorTypes type, final ItemStack oldArmorPiece, final ItemStack newArmorPiece) {
|
||||
super(player);
|
||||
this.equipType = equipType;
|
||||
this.type = type;
|
||||
this.oldArmorPiece = oldArmorPiece;
|
||||
this.newArmorPiece = newArmorPiece;
|
||||
}
|
||||
|
||||
public final static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setCancelled(final boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public final ArmorTypes getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public final ItemStack getOldArmorPiece() {
|
||||
return oldArmorPiece;
|
||||
}
|
||||
|
||||
public final void setOldArmorPiece(final ItemStack oldArmorPiece) {
|
||||
this.oldArmorPiece = oldArmorPiece;
|
||||
}
|
||||
|
||||
public final ItemStack getNewArmorPiece() {
|
||||
return newArmorPiece;
|
||||
}
|
||||
|
||||
public final void setNewArmorPiece(final ItemStack newArmorPiece) {
|
||||
this.newArmorPiece = newArmorPiece;
|
||||
}
|
||||
|
||||
public EquipMethod getMethod() {
|
||||
return equipType;
|
||||
}
|
||||
|
||||
public enum EquipMethod {
|
||||
SHIFT_CLICK,
|
||||
DRAG,
|
||||
HOTBAR,
|
||||
HOTBAR_SWAP,
|
||||
DISPENSER,
|
||||
BROKE,
|
||||
DEATH;
|
||||
}
|
||||
}
|
@ -34,6 +34,8 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -42,20 +44,27 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockGrowEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemBreakEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
@ -65,9 +74,12 @@ import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.Gui.GuiInfoList;
|
||||
import com.gamingmesh.jobs.api.JobsAreaSelectionEvent;
|
||||
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
|
||||
import com.gamingmesh.jobs.container.ArmorTypes;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobLimitedItems;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsArmorChangeEvent;
|
||||
import com.gamingmesh.jobs.container.JobsArmorChangeEvent.EquipMethod;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
@ -719,4 +731,198 @@ public class JobsListener implements Listener {
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsChunkChangeEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
boolean shift = false, numberkey = false;
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
ClickType click = event.getClick();
|
||||
if (click.equals(ClickType.SHIFT_LEFT) || click.equals(ClickType.SHIFT_RIGHT))
|
||||
shift = true;
|
||||
|
||||
if (click.equals(ClickType.NUMBER_KEY))
|
||||
numberkey = true;
|
||||
|
||||
SlotType slotType = event.getSlotType();
|
||||
|
||||
if ((slotType != SlotType.ARMOR || slotType != SlotType.QUICKBAR) && !event.getInventory().getType().equals(InventoryType.CRAFTING))
|
||||
return;
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (event.getCurrentItem() == null)
|
||||
return;
|
||||
ArmorTypes newArmorType = ArmorTypes.matchType(shift ? event.getCurrentItem() : event.getCursor());
|
||||
if (!shift && newArmorType != null && event.getRawSlot() != newArmorType.getSlot())
|
||||
return;
|
||||
|
||||
if (shift) {
|
||||
newArmorType = ArmorTypes.matchType(event.getCurrentItem());
|
||||
if (newArmorType == null)
|
||||
return;
|
||||
boolean equipping = true;
|
||||
if (event.getRawSlot() == newArmorType.getSlot())
|
||||
equipping = false;
|
||||
|
||||
PlayerInventory inv = player.getInventory();
|
||||
|
||||
if (newArmorType.equals(ArmorTypes.HELMET) &&
|
||||
(equipping ? inv.getHelmet() == null : inv.getHelmet() != null) ||
|
||||
(newArmorType.equals(ArmorTypes.CHESTPLATE) || newArmorType.equals(ArmorTypes.ELYTRA)) &&
|
||||
(equipping ? inv.getChestplate() == null : inv.getChestplate() != null) ||
|
||||
newArmorType.equals(ArmorTypes.LEGGINGS) &&
|
||||
(equipping ? inv.getLeggings() == null : inv.getLeggings() != null) ||
|
||||
newArmorType.equals(ArmorTypes.BOOTS) &&
|
||||
(equipping ? inv.getBoots() == null : inv.getBoots() != null)) {
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event
|
||||
.getCurrentItem(), equipping ? event.getCurrentItem() : null);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
ItemStack newArmorPiece = event.getCursor();
|
||||
ItemStack oldArmorPiece = event.getCurrentItem();
|
||||
if (numberkey) {
|
||||
if (event.getClickedInventory().getType().equals(InventoryType.PLAYER)) {
|
||||
ItemStack hotbarItem = event.getClickedInventory().getItem(event.getHotbarButton());
|
||||
if (hotbarItem != null) {
|
||||
newArmorType = ArmorTypes.matchType(hotbarItem);
|
||||
newArmorPiece = hotbarItem;
|
||||
oldArmorPiece = event.getClickedInventory().getItem(event.getSlot());
|
||||
} else {
|
||||
newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newArmorType = ArmorTypes.matchType(oldArmorPiece != null && oldArmorPiece.getType() != Material.AIR ? oldArmorPiece : event.getCursor());
|
||||
}
|
||||
if (newArmorType != null && event.getRawSlot() == newArmorType.getSlot()) {
|
||||
EquipMethod method = EquipMethod.DRAG;
|
||||
if (event.getAction().equals(InventoryAction.HOTBAR_SWAP) || numberkey)
|
||||
method = EquipMethod.HOTBAR_SWAP;
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerInteractEvent(PlayerInteractEvent event) {
|
||||
// if (event.isCancelled())
|
||||
// return;
|
||||
|
||||
Action action = event.getAction();
|
||||
if (action == Action.PHYSICAL)
|
||||
return;
|
||||
if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
Player player = event.getPlayer();
|
||||
ArmorTypes newArmorType = ArmorTypes.matchType(event.getItem());
|
||||
if (newArmorType == null)
|
||||
return;
|
||||
PlayerInventory inv = player.getInventory();
|
||||
if (newArmorType.equals(ArmorTypes.HELMET) &&
|
||||
inv.getHelmet() == null ||
|
||||
(newArmorType.equals(ArmorTypes.CHESTPLATE) || newArmorType.equals(ArmorTypes.ELYTRA)) &&
|
||||
inv.getChestplate() == null ||
|
||||
newArmorType.equals(ArmorTypes.LEGGINGS) &&
|
||||
inv.getLeggings() == null ||
|
||||
newArmorType.equals(ArmorTypes.BOOTS) &&
|
||||
inv.getBoots() == null) {
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event
|
||||
.getItem());
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void dispenserFireEvent(BlockDispenseEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
ArmorTypes type = ArmorTypes.matchType(item);
|
||||
if (ArmorTypes.matchType(item) == null)
|
||||
return;
|
||||
Location loc = event.getBlock().getLocation();
|
||||
for (Player p : loc.getWorld().getPlayers()) {
|
||||
Location ploc = p.getLocation();
|
||||
if (loc.getBlockY() - ploc.getBlockY() >= -1 && loc.getBlockY() - ploc.getBlockY() <= 1) {
|
||||
|
||||
if (p.getInventory().getHelmet() == null && type.equals(ArmorTypes.HELMET) ||
|
||||
p.getInventory().getChestplate() == null && (type.equals(ArmorTypes.CHESTPLATE) || type.equals(ArmorTypes.ELYTRA)) ||
|
||||
p.getInventory().getLeggings() == null && type.equals(ArmorTypes.LEGGINGS) ||
|
||||
p.getInventory().getBoots() == null && type.equals(ArmorTypes.BOOTS)) {
|
||||
|
||||
if (!(event.getBlock().getState() instanceof Dispenser))
|
||||
continue;
|
||||
Dispenser dispenser = (Dispenser) event.getBlock().getState();
|
||||
org.bukkit.material.Dispenser dis = (org.bukkit.material.Dispenser) dispenser.getData();
|
||||
BlockFace directionFacing = dis.getFacing();
|
||||
if (directionFacing == BlockFace.EAST &&
|
||||
ploc.getBlockX() != loc.getBlockX() &&
|
||||
ploc.getX() <= loc.getX() + 2.3 &&
|
||||
ploc.getX() >= loc.getX() ||
|
||||
directionFacing == BlockFace.WEST &&
|
||||
ploc.getX() >= loc.getX() - 1.3 &&
|
||||
ploc.getX() <= loc.getX() ||
|
||||
directionFacing == BlockFace.SOUTH &&
|
||||
ploc.getBlockZ() != loc.getBlockZ() &&
|
||||
ploc.getZ() <= loc.getZ() + 2.3 &&
|
||||
ploc.getZ() >= loc.getZ() ||
|
||||
directionFacing == BlockFace.NORTH &&
|
||||
ploc.getZ() >= loc.getZ() - 1.3 &&
|
||||
ploc.getZ() <= loc.getZ()) {
|
||||
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void JobsArmorChangeEvent(JobsArmorChangeEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Jobs.getPlayerManager().resetiItemBonusCache(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerItemHeldEvent(PlayerItemHeldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Jobs.getPlayerManager().resetiItemBonusCache(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerItemBreakEvent(PlayerItemBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Jobs.getPlayerManager().resetiItemBonusCache(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void PlayerItemBreakEvent(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Jobs.getPlayerManager().resetiItemBonusCache(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,11 @@ public class v1_10 implements NMS {
|
||||
return player.getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
return player.getTargetBlock((Set<Material>) null, range);
|
||||
|
@ -31,6 +31,11 @@ public class v1_11 implements NMS {
|
||||
return player.getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInMainHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
return player.getTargetBlock((Set<Material>) null, range);
|
||||
|
@ -31,6 +31,11 @@ public class v1_12 implements NMS {
|
||||
return player.getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInMainHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
return player.getTargetBlock((Set<Material>) null, range);
|
||||
|
@ -58,6 +58,11 @@ public class v1_7 implements NMS {
|
||||
return player.getInventory().getItemInHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInHand(item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
|
@ -65,6 +65,11 @@ public class v1_8 implements NMS {
|
||||
return player.getInventory().getItemInHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
return player.getTargetBlock((Set<Material>) null, range);
|
||||
|
@ -64,6 +64,11 @@ public class v1_9 implements NMS {
|
||||
return player.getInventory().getItemInMainHand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInMainHand(Player player, ItemStack item) {
|
||||
player.getInventory().setItemInHand(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getTargetBlock(Player player, int range) {
|
||||
return player.getTargetBlock((Set<Material>) null, range);
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.util.StringUtil;
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.ActionType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobItemBonus;
|
||||
import com.gamingmesh.jobs.container.JobItems;
|
||||
import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
@ -76,8 +77,8 @@ public class TabComplete implements TabCompleter {
|
||||
case "[jobitemname]":
|
||||
Job oneJob = Jobs.getJob(args[i - 1]);
|
||||
if (oneJob != null)
|
||||
for (JobItems item : oneJob.getItems()) {
|
||||
temp.add(item.getNode());
|
||||
for (Entry<String, JobItems> item : oneJob.getItemBonus().entrySet()) {
|
||||
temp.add(item.getValue().getNode());
|
||||
}
|
||||
break;
|
||||
case "[oldjob]":
|
||||
|
Loading…
Reference in New Issue
Block a user