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

Initial 1.14 support

This commit is contained in:
montlikadani 2019-05-01 13:19:13 +02:00
parent 6ee818594b
commit cd35cc75f2
7 changed files with 1304 additions and 758 deletions

View File

@ -115,69 +115,64 @@ public class ActionBarTitleMessages {
} }
public static void sendTitle(final Player receivingPacket, final Object title, final Object subtitle, final int fadeIn, final int keep, final int fadeOut) { public static void sendTitle(final Player receivingPacket, final Object title, final Object subtitle, final int fadeIn, final int keep, final int fadeOut) {
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> {
@SuppressWarnings("deprecation") String t = title == null ? null : CMIChatColor.translateAlternateColorCodes((String) title);
@Override String s = subtitle == null ? null : CMIChatColor.translateAlternateColorCodes((String) subtitle);
public void run() {
String t = title == null ? null : CMIChatColor.translateAlternateColorCodes((String) title); if (simpleTitleMessages) {
String s = subtitle == null ? null : CMIChatColor.translateAlternateColorCodes((String) subtitle); receivingPacket.sendMessage(t);
receivingPacket.sendMessage(s);
if (simpleTitleMessages) { return;
receivingPacket.sendMessage(t); }
receivingPacket.sendMessage(s); try {
return; switch (Version.getCurrent()) {
} case v1_9_R1:
try { case v1_9_R2:
switch (Version.getCurrent()) { case v1_10_R1:
case v1_9_R1: case v1_11_R1:
case v1_9_R2: receivingPacket.sendTitle(t, s);
case v1_10_R1: break;
case v1_11_R1: case v1_12_R1:
receivingPacket.sendTitle(t, s); case v1_13_R1:
break; case v1_13_R2:
case v1_12_R1: case v1_14_R1:
case v1_13_R1: case v1_14_R2:
case v1_13_R2: case v1_15_R1:
case v1_14_R1: case v1_15_R2:
case v1_14_R2: receivingPacket.sendTitle(t, s, fadeIn, keep, fadeOut);
case v1_15_R1: break;
case v1_15_R2: case v1_7_R1:
receivingPacket.sendTitle(t, s, fadeIn, keep, fadeOut); case v1_7_R2:
break; case v1_7_R3:
case v1_7_R1: case v1_7_R4:
case v1_7_R2: case v1_8_R1:
case v1_7_R3: case v1_8_R2:
case v1_7_R4: case v1_8_R3:
case v1_8_R1: if (title != null) {
case v1_8_R2: Object packetTitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("TITLE").get(null),
case v1_8_R3: ((Object[]) fromString.invoke(null, t))[0]);
if (title != null) {
Object packetTitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("TITLE").get(null),
((Object[]) fromString.invoke(null, t))[0]);
sendPacket(receivingPacket, packetTitle);
}
if (subtitle != null) {
if (title == null) {
Object packetTitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("TITLE").get(null), ((Object[]) fromString.invoke(null, ""))[0]);
sendPacket(receivingPacket, packetTitle); sendPacket(receivingPacket, packetTitle);
} }
Object packetSubtitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("SUBTITLE").get(null), if (subtitle != null) {
((Object[]) fromString.invoke(null, s))[0]); if (title == null) {
sendPacket(receivingPacket, packetSubtitle); Object packetTitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("TITLE").get(null), ((Object[]) fromString.invoke(null, ""))[0]);
sendPacket(receivingPacket, packetTitle);
}
Object packetSubtitle = nmsPacketPlayOutTitle.newInstance(enumTitleAction.getField("SUBTITLE").get(null),
((Object[]) fromString.invoke(null, s))[0]);
sendPacket(receivingPacket, packetSubtitle);
}
break;
default:
break;
} }
break; } catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException ex) {
default: simpleTitleMessages = true;
break; Bukkit.getLogger().log(Level.SEVERE, "Your server can't fully support title messages. They will be shown in chat instead.");
}
} catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException ex) {
simpleTitleMessages = true;
Bukkit.getLogger().log(Level.SEVERE, "Your server can't fully support title messages. They will be shown in chat instead.");
}
return;
} }
return;
}); });
} }

View File

@ -1,6 +1,3 @@
/**
* Copyright (C) 2017 Zrips
*/
package com.gamingmesh.jobs.CMILib; package com.gamingmesh.jobs.CMILib;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,14 +7,17 @@ import java.util.Map.Entry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
@ -30,15 +30,19 @@ public class CMIItemStack {
private String bukkitName = null; private String bukkitName = null;
private String mojangName = null; private String mojangName = null;
private CMIMaterial material = null; private CMIMaterial cmiMaterial = null;
private Material material = null;
private ItemStack item; private ItemStack item;
public CMIItemStack(Material material) { public CMIItemStack(Material material) {
this.material = CMIMaterial.get(material); this.material = material;
this.cmiMaterial = CMIMaterial.get(material);
} }
public CMIItemStack(CMIMaterial material) { public CMIItemStack(CMIMaterial cmiMaterial) {
this.material = material; this.cmiMaterial = cmiMaterial;
if (cmiMaterial != null)
this.material = cmiMaterial.getMaterial();
} }
public CMIItemStack(ItemStack item) { public CMIItemStack(ItemStack item) {
@ -54,7 +58,8 @@ public class CMIItemStack {
cm.setDurability(durability); cm.setDurability(durability);
cm.setBukkitName(bukkitName); cm.setBukkitName(bukkitName);
cm.setMojangName(mojangName); cm.setMojangName(mojangName);
cm.setCMIMaterial(material); cm.setCMIMaterial(cmiMaterial);
cm.setMaterial(material);
cm.setItemStack(this.item != null ? this.item.clone() : null); cm.setItemStack(this.item != null ? this.item.clone() : null);
return cm; return cm;
} }
@ -63,7 +68,7 @@ public class CMIItemStack {
return id; return id;
} }
public void setId(int id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
@ -73,17 +78,19 @@ public class CMIItemStack {
public boolean isTool() { public boolean isTool() {
return getMaxDurability() > 0; return getMaxDurability() > 0;
} }
public short getDurability() { public short getDurability() {
return this.getItemStack().getDurability(); return this.getItemStack().getDurability();
} }
public short getMaxDurability() { public short getMaxDurability() {
return material.getMaxDurability(); return this.material.getMaxDurability();
} }
public void setData(short data) { public void setData(short data) {
// CMIMaterial got = CMIMaterial.get(id, data);
// if (got != null && got.getLegacyData() == data)
this.data = data; this.data = data;
} }
@ -101,7 +108,7 @@ public class CMIItemStack {
public String getDisplayName() { public String getDisplayName() {
ItemMeta meta = this.getItemStack().getItemMeta(); ItemMeta meta = this.getItemStack().getItemMeta();
return meta == null || meta.getDisplayName() == null || meta.getDisplayName().isEmpty() ? this.material.getName() : meta.getDisplayName(); return meta == null || meta.getDisplayName() == null || meta.getDisplayName().isEmpty() ? getRealName() : meta.getDisplayName();
} }
public CMIItemStack addLore(String string) { public CMIItemStack addLore(String string) {
@ -110,7 +117,7 @@ public class CMIItemStack {
ItemMeta meta = this.getItemStack().getItemMeta(); ItemMeta meta = this.getItemStack().getItemMeta();
List<String> lore = meta.getLore(); List<String> lore = meta.getLore();
if (lore == null) if (lore == null)
lore = new ArrayList<>(); lore = new ArrayList<String>();
lore.add(ChatColor.translateAlternateColorCodes('&', string)); lore.add(ChatColor.translateAlternateColorCodes('&', string));
meta.setLore(lore); meta.setLore(lore);
this.getItemStack().setItemMeta(meta); this.getItemStack().setItemMeta(meta);
@ -139,58 +146,78 @@ public class CMIItemStack {
} }
public CMIItemStack addEnchant(Enchantment enchant, Integer level) { public CMIItemStack addEnchant(Enchantment enchant, Integer level) {
if (enchant == null) if (enchant == null)
return this; return this;
ItemMeta meta = this.getItemStack().getItemMeta(); ItemMeta meta = this.getItemStack().getItemMeta();
meta.addEnchant(enchant, level, true); meta.addEnchant(enchant, level, true);
this.getItemStack().setItemMeta(meta); this.getItemStack().setItemMeta(meta);
return this; return this;
} }
public CMIItemStack addEnchant(HashMap<Enchantment, Integer> enchants) { public CMIItemStack addEnchant(HashMap<Enchantment, Integer> enchants) {
if (enchants == null || enchants.isEmpty()) if (enchants == null || enchants.isEmpty())
return this; return this;
for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) { for (Entry<Enchantment, Integer> oneEnch : enchants.entrySet()) {
this.addEnchant(oneEnch.getKey(), oneEnch.getValue()); this.addEnchant(oneEnch.getKey(), oneEnch.getValue());
} }
return this; return this;
} }
public CMIItemStack clearEnchants() { public CMIItemStack clearEnchants() {
ItemMeta meta = this.getItemStack().getItemMeta(); ItemMeta meta = this.getItemStack().getItemMeta();
meta.getEnchants().clear(); meta.getEnchants().clear();
this.getItemStack().setItemMeta(meta); this.getItemStack().setItemMeta(meta);
return this; return this;
} }
public List<String> getLore() { public List<String> getLore() {
ItemMeta meta = this.getItemStack().getItemMeta(); ItemMeta meta = this.getItemStack().getItemMeta();
if (meta != null) { // List<String> lore = null;
List<String> lore = meta.getLore(); if (meta != null) {
if (lore == null || lore.isEmpty()) { List<String> lore = meta.getLore();
lore = new ArrayList<>(); if (lore == null) {
meta.setLore(lore); lore = new ArrayList<String>();
} meta.setLore(lore);
// this.getItemStack().setItemMeta(meta);
}
return meta.getLore() == null ? new ArrayList<String>() : meta.getLore(); return meta.getLore() == null ? new ArrayList<String>() : meta.getLore();
} }
return new ArrayList<>(); return new ArrayList<String>();
} }
public String getRealName() { public String getRealName() {
return material.getName(); return this.getCMIType() == null || this.getCMIType() == CMIMaterial.NONE ? this.getType().name() : this.getCMIType().getName();
// if (this.getItemStack() != null) {
//
//// String translated = CMI.getInstance().getItemManager().getTranslatedName(this.getItemStack());
//// if (translated != null)
//// return translated;
// try {
// return CMI.getInstance().getRef().getItemMinecraftName(this.getItemStack());
// } catch (Exception e) {
// }
// }
// return CMI.getInstance().getItemManager().getRealName(this, true).getName();
} }
public String getBukkitName() { public String getBukkitName() {
return bukkitName == null || bukkitName.isEmpty() ? null : bukkitName; return bukkitName == null || bukkitName.isEmpty() ? null : bukkitName;
} }
public void setBukkitName(String bukkitName) { public void setBukkitName(String bukkitName) {
this.bukkitName = bukkitName; this.bukkitName = bukkitName;
} }
public String getMojangName() { public String getMojangName() {
return mojangName == null || mojangName.isEmpty() ? null : mojangName; // if (getCMIType().isSkull() && !Version.isCurrentEqualOrHigher(Version.v1_13_R1))
// mojangName = "skull";
// try {
// mojangName = CMI.getInstance().getRef().getItemMinecraftName(getItemStack()).replace("minecraft:", "");
// } catch (Exception e) {
//
// }
return mojangName == null || mojangName.isEmpty() ? this.getCMIType().getMaterial().name() : mojangName;
} }
public void setMojangName(String mojangName) { public void setMojangName(String mojangName) {
@ -199,13 +226,13 @@ public class CMIItemStack {
} }
public Material getType() { public Material getType() {
if (material == null) if (material == null && cmiMaterial != null)
return null; return cmiMaterial.getMaterial();
return material.getMaterial(); return material;
} }
public CMIMaterial getCMIType() { public CMIMaterial getCMIType() {
return material; return cmiMaterial == null ? CMIMaterial.get(material) : cmiMaterial;
} }
@Deprecated @Deprecated
@ -214,31 +241,40 @@ public class CMIItemStack {
} }
public void setMaterial(Material material) { public void setMaterial(Material material) {
this.material = CMIMaterial.get(material); this.cmiMaterial = CMIMaterial.get(material);
this.material = material;
} }
public void setCMIMaterial(CMIMaterial material) { public void setCMIMaterial(CMIMaterial material) {
this.material = material; this.cmiMaterial = material;
this.material = material == null ? null : material.getMaterial();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemStack getItemStack() { public ItemStack getItemStack() {
if (item == null) { if (item == null) {
if (Jobs.getVersionCheckManager().getVersion().isEqualOrHigher(Version.v1_13_R1)) { if (cmiMaterial.isMonsterEgg()) {
this.item = new ItemStack(material.getMaterial(), this.amount == 0 ? 1 : this.amount); if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
this.item = new ItemStack(this.getType());
this.item.setAmount(this.getAmount());
} else
this.item = new ItemStack(this.getType(), this.amount == 0 ? 1 : this.amount, data == 0 ? (short) 90 : data);
} else { } else {
this.item = new ItemStack(material.getMaterial(), this.amount == 0 ? 1 : this.amount, data); if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
this.item = new ItemStack(this.getType());
this.item.setAmount(this.getAmount());
} else
this.item = new ItemStack(this.getType(), this.amount == 0 ? 1 : this.amount, data);
} }
if (this.item.getType() == Material.POTION || item.getType().name().contains("SPLASH_POTION") || item.getType().name().contains("TIPPED_ARROW")) { if (this.getCMIType().isPotion() || item.getType().name().contains("SPLASH_POTION") || item.getType().name().contains("TIPPED_ARROW")) {
PotionMeta potion = (PotionMeta) item.getItemMeta(); PotionMeta potion = (PotionMeta) item.getItemMeta();
PotionEffectType effect = PotionEffectType.getById(data); PotionEffectType effect = PotionEffectType.getById(data);
if (effect != null) { if (effect != null) {
potion.addCustomEffect(new PotionEffect(PotionEffectType.getById(data), 60, 0), true); potion.addCustomEffect(new PotionEffect(effect, 60, 0), true);
} }
item.setItemMeta(potion); item.setItemMeta(potion);
item.setDurability((short) 0); item.setDurability((short) 0);
potion = (PotionMeta) item.getItemMeta(); potion = (PotionMeta) item.getItemMeta();
potion.setDisplayName(this.getRealName()); potion.setDisplayName(this.getRealName());
item.setItemMeta(potion); item.setItemMeta(potion);
@ -249,44 +285,48 @@ public class CMIItemStack {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public CMIItemStack setItemStack(ItemStack item) { public CMIItemStack setItemStack(ItemStack item) {
this.item = item; this.item = item == null ? null : item;
if (item != null) { if (item != null) {
this.id = item.getType().getId();
this.amount = item.getAmount(); this.amount = item.getAmount();
this.material = CMIMaterial.get(item); this.material = item.getType();
if ((material.isBlock() || material.isSolid())) { this.cmiMaterial = CMIMaterial.get(this.material);
data = item.getData().getData(); if (Version.isCurrentEqualOrLower(Version.v1_13_R2))
this.id = item.getType().getId();
else if (cmiMaterial != null) {
this.id = cmiMaterial.getId();
} }
if (item.getType().getMaxDurability() - item.getDurability() < 0) { if ((this.getType().isBlock() || this.getType().isSolid()))
data = item.getData().getData(); data = item.getData().getData();
}
if (item.getType().getMaxDurability() > 15) { if (item.getType().getMaxDurability() - item.getDurability() < 0)
data = item.getData().getData();
if (item.getType().getMaxDurability() > 15)
data = (short) 0; data = (short) 0;
}
if (item.getType() == Material.POTION || item.getType().name().contains("SPLASH_POTION") || item.getType().name().contains("TIPPED_ARROW")) { if (CMIMaterial.SPAWNER.equals(item.getType()))
PotionMeta meta = (PotionMeta) item.getItemMeta(); data = getEntityType().getTypeId();
if (meta instanceof PotionMeta) { else if (item.getType() == Material.POTION || item.getType().name().contains("SPLASH_POTION") || item.getType().name().contains("TIPPED_ARROW")) {
PotionMeta potionMeta = (PotionMeta) meta; PotionMeta potion = (PotionMeta) item.getItemMeta();
try { try {
if (potionMeta != null && potionMeta.getBasePotionData() != null && potionMeta.getBasePotionData() != null && potionMeta.getBasePotionData().getType().getEffectType() != null) { if (potion != null && potion.getBasePotionData() != null && potion.getBasePotionData().getType() != null && potion.getBasePotionData().getType().getEffectType() != null) {
data = (short) potionMeta.getBasePotionData().getType().getEffectType().getId(); data = (short) potion.getBasePotionData().getType().getEffectType().getId();
} }
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {
} }
}
} }
} }
return this; return this;
} }
public int getAmount() { public int getAmount() {
return amount; return amount <= 0 ? 1 : amount;
} }
public void setAmount(int amount) { public void setAmount(int amount) {
this.amount = amount; this.amount = amount;
if (item != null)
this.item.setAmount(this.amount == 0 ? item.getAmount() : this.amount);
} }
public boolean isSimilar(ItemStack item) { public boolean isSimilar(ItemStack item) {
@ -296,54 +336,117 @@ public class CMIItemStack {
public boolean isSimilar(CMIItemStack item) { public boolean isSimilar(CMIItemStack item) {
if (item == null) if (item == null)
return false; return false;
return this.material.equals(item.material) && this.getData() == item.getData();
try {
if ((item.getCMIType().isPotion() || item.getCMIType().equals(CMIMaterial.TIPPED_ARROW)) &&
(this.getCMIType().isPotion() || this.getCMIType().equals(CMIMaterial.TIPPED_ARROW)) &&
this.getType().equals(item.getType())) {
PotionMeta potion = (PotionMeta) item.getItemStack().getItemMeta();
PotionMeta potion2 = (PotionMeta) this.getItemStack().getItemMeta();
try {
if (potion != null && potion.getBasePotionData() != null) {
PotionData base1 = potion.getBasePotionData();
if (base1.getType() != null) {
if (potion2 != null && potion2.getBasePotionData() != null) {
PotionData base2 = potion2.getBasePotionData();
if (base2.getType() != null) {
if (base1.getType().equals(base2.getType()) && base1.isExtended() == base2.isExtended() && base1.isUpgraded() == base2.isUpgraded())
return true;
}
}
}
}
return false;
} catch (NoSuchMethodError e) {
}
}
} catch (Throwable e) {
e.printStackTrace();
}
try {
if (this.getItemStack().getItemMeta() instanceof EnchantmentStorageMeta && item.getItemStack().getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta meta1 = (EnchantmentStorageMeta) this.getItemStack().getItemMeta();
EnchantmentStorageMeta meta2 = (EnchantmentStorageMeta) item.getItemStack().getItemMeta();
for (Entry<Enchantment, Integer> one : meta1.getEnchants().entrySet()) {
if (!meta2.getEnchants().containsKey(one.getKey()) || meta2.getEnchants().get(one.getKey()) != one.getValue())
return false;
}
for (Entry<Enchantment, Integer> one : meta1.getStoredEnchants().entrySet()) {
if (!meta2.getStoredEnchants().containsKey(one.getKey()) || meta2.getStoredEnchants().get(one.getKey()) != one.getValue())
return false;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
if ((item.getCMIType() == CMIMaterial.SPAWNER || item.getCMIType().isMonsterEgg()) && (getCMIType() == CMIMaterial.SPAWNER || getCMIType().isMonsterEgg())) {
if (this.cmiMaterial != item.cmiMaterial)
return false;
if (getEntityType() != item.getEntityType())
return false;
return true;
}
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1))
return this.cmiMaterial == item.cmiMaterial;
return this.cmiMaterial == item.cmiMaterial && this.getData() == item.getData();
} }
// public boolean hasNbtTag() { public EntityType getEntityType() {
// return CMI.getInstance().getRef().hasNbt(this.getItemStack()); if (this.getItemStack() == null)
// } return null;
ItemStack is = this.getItemStack().clone();
if (is.getItemMeta() instanceof org.bukkit.inventory.meta.BlockStateMeta) {
org.bukkit.inventory.meta.BlockStateMeta bsm = (org.bukkit.inventory.meta.BlockStateMeta) is.getItemMeta();
if (bsm.getBlockState() instanceof CreatureSpawner) {
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
return bs.getSpawnedType();
}
}
// public List<Recipe> getRecipesFor() { return EntityType.fromId(is.getData().getData());
// ItemStack i = getItemStack().clone(); }
// i.getData().setData((byte) data);
// if (i.getType().getMaxDurability() > 15)
// i.setDurability((short) 0);
// return Bukkit.getRecipesFor(i);
// }
//
// public List<Recipe> getRecipesFrom() {
// ItemStack i = getItemStack().clone();
// i.getData().setData((byte) data);
// if (i.getType().getMaxDurability() > 15)
// i.setDurability((short) 0);
// Iterator<Recipe> it = Bukkit.recipeIterator();
// List<Recipe> recipes = new ArrayList<Recipe>();
// while (it.hasNext()) {
// Recipe rec = it.next();
// for (ItemStack one : CMI.getInstance().getRecipeManager().getIngredientsList(rec)) {
// if (one.isSimilar(i)) {
// recipes.add(rec);
// break;
// }
// }
// }
//
// return recipes;
// }
public void setDurability(short durability) { public void setDurability(short durability) {
this.durability = durability; this.durability = durability;
} }
// public Set<Enchantment> getValidEnchants() { public String toOneLiner() {
// Set<Enchantment> enchants = new HashSet<Enchantment>(); String liner = this.getType().toString();
// for (Enchantment one : CMIEnchantment.values()) { if (this.getCMIType().isPotion() || this.getType().name().contains("TIPPED_ARROW")) {
// if (!CMIEnchantment.isEnabled(one)) PotionMeta potion = (PotionMeta) item.getItemMeta();
// continue; try {
// if (one.canEnchantItem(this.getItemStack())) if (potion != null && potion.getBasePotionData() != null && potion.getBasePotionData().getType() != null && potion.getBasePotionData().getType().getEffectType() != null) {
// enchants.add(one); liner += ":" + potion.getBasePotionData().getType().getEffectType().getName() + "-" + potion.getBasePotionData().isUpgraded() + "-" + potion.getBasePotionData().isExtended();
// } }
// return enchants; } catch (NoSuchMethodError e) {
// } }
} else {
if (Version.isCurrentLower(Version.v1_13_R1))
liner += ":" + this.getData();
}
if (this.getItemStack().getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) this.getItemStack().getItemMeta();
String s = "";
for (Entry<Enchantment, Integer> one : meta.getStoredEnchants().entrySet()) {
if (!s.isEmpty())
s += ";";
s += one.getKey().getName() + "x" + one.getValue();
}
for (Entry<Enchantment, Integer> one : meta.getEnchants().entrySet()) {
if (!s.isEmpty())
s += ";";
s += one.getKey().getName() + "x" + one.getValue();
}
if (!s.isEmpty())
liner += ":" + s;
}
return liner;
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -82,53 +82,6 @@ public class ItemReflection {
} }
} }
public static String getItemRealName(ItemStack item) {
try {
Object nmsStack = asNMSCopy(item);
Method itemMeth = Item.getMethod("getById", int.class);
@SuppressWarnings("deprecation")
Object res = itemMeth.invoke(Item, item.getType().getId());
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_12_R1:
ff = "b";
break;
case v1_13_R2:
case v1_13_R1:
case v1_14_R2:
case v1_14_R1:
case v1_15_R2:
case v1_15_R1:
ff = "h";
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 (Throwable e) {
return item != null ? item.getType().name() : "";
}
}
public String getItemMinecraftNamePath(ItemStack item) { public String getItemMinecraftNamePath(ItemStack item) {
try { try {
Object nmsStack = asNMSCopy(item); Object nmsStack = asNMSCopy(item);

View File

@ -22,7 +22,7 @@ public class VersionChecker {
version = Version.getCurrent(); version = Version.getCurrent();
} }
private static Version version = Version.v1_13_R2; private static Version version = Version.v1_14_R1;
public Version getVersion() { public Version getVersion() {
return Version.getCurrent(); return Version.getCurrent();
@ -151,25 +151,22 @@ public class VersionChecker {
if (!Jobs.getGCManager().isShowNewVersion()) if (!Jobs.getGCManager().isShowNewVersion())
return; return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@Override String currentVersion = plugin.getDescription().getVersion();
public void run() { String newVersion = getNewVersion();
String currentVersion = plugin.getDescription().getVersion(); if (newVersion == null || newVersion.equalsIgnoreCase(currentVersion))
String newVersion = getNewVersion(); return;
if (newVersion == null || newVersion.equalsIgnoreCase(currentVersion)) List<String> msg = Arrays.asList(
return; ChatColor.GREEN + "*********************** " + plugin.getDescription().getName() + " **************************",
List<String> msg = Arrays.asList( ChatColor.GREEN + "* " + newVersion + " is now available! Your version: " + currentVersion,
ChatColor.GREEN + "*********************** " + plugin.getDescription().getName() + " **************************", ChatColor.GREEN + "* " + ChatColor.DARK_GREEN + plugin.getDescription().getWebsite(),
ChatColor.GREEN + "* " + newVersion + " is now available! Your version: " + currentVersion, ChatColor.GREEN + "************************************************************");
ChatColor.GREEN + "* " + ChatColor.DARK_GREEN + plugin.getDescription().getWebsite(), for (String one : msg)
ChatColor.GREEN + "************************************************************"); if (player != null)
for (String one : msg) player.sendMessage(one);
if (player != null) else
player.sendMessage(one); Jobs.consoleMsg(one);
else });
Jobs.consoleMsg(one);
}
});
} }
public String getNewVersion() { public String getNewVersion() {
@ -181,7 +178,7 @@ public class VersionChecker {
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 7) if (version.length() <= 7)
return version; return version;
} catch (Throwable ex) { } catch (Throwable t) {
Jobs.consoleMsg("&cFailed to check for " + plugin.getDescription().getName() + " update on spigot web page."); Jobs.consoleMsg("&cFailed to check for " + plugin.getDescription().getName() + " update on spigot web page.");
} }
return null; return null;

View File

@ -26,8 +26,8 @@ public class RestrictedBlockManager {
ConfigReader cfg = null; ConfigReader cfg = null;
try { try {
cfg = new ConfigReader("restrictedBlocks.yml"); cfg = new ConfigReader("restrictedBlocks.yml");
} catch (Throwable e1) { } catch (Throwable t) {
e1.printStackTrace(); t.printStackTrace();
} }
if (cfg == null) if (cfg == null)
return; return;
@ -43,7 +43,7 @@ public class RestrictedBlockManager {
for (String one : lss) { for (String one : lss) {
if (((cfg.getC().isString("blocksTimer." + one + ".id")) || (cfg.getC().isInt("blocksTimer." + one + ".id"))) && (cfg.getC().isInt("blocksTimer." + one if (((cfg.getC().isString("blocksTimer." + one + ".id")) || (cfg.getC().isInt("blocksTimer." + one + ".id"))) && (cfg.getC().isInt("blocksTimer." + one
+ ".cd"))) { + ".cd"))) {
CMIItemStack cm = ItemManager.getItem(cfg.getC().getString("blocksTimer." + one + ".id")); CMIItemStack cm = ItemManager.getItem(CMIMaterial.get(cfg.getC().getString("blocksTimer." + one + ".id")));
if ((cm == null) || (!cm.getCMIType().isBlock())) { if ((cm == null) || (!cm.getCMIType().isBlock())) {
Jobs.consoleMsg("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!"); Jobs.consoleMsg("&e[Jobs] Your defined (" + one + ") protected block id/name is not correct!");
continue; continue;

View File

@ -484,12 +484,14 @@ public class JobsListener implements Listener {
} }
com.gamingmesh.jobs.Signs.Sign signInfo = new com.gamingmesh.jobs.Signs.Sign(); com.gamingmesh.jobs.Signs.Sign signInfo = new com.gamingmesh.jobs.Signs.Sign();
com.gamingmesh.jobs.Signs.SignUtil signUtil = Jobs.getSignUtil();
Location loc = sign.getLocation(); Location loc = sign.getLocation();
int category = 1; int category = 1;
if (Jobs.getSignUtil().getSigns().GetAllSigns().size() > 0) if (signUtil.getSigns().GetAllSigns().size() > 0)
category = Jobs.getSignUtil().getSigns().GetAllSigns().get(Jobs.getSignUtil().getSigns().GetAllSigns().size() - 1).GetCategory() + 1; category = signUtil.getSigns().GetAllSigns().get(signUtil.getSigns().GetAllSigns().size() - 1).GetCategory() + 1;
signInfo.setNumber(Number); signInfo.setNumber(Number);
signInfo.setWorld(loc.getWorld().getName()); signInfo.setWorld(loc.getWorld().getName());
signInfo.setX(loc.getX()); signInfo.setX(loc.getX());
@ -502,17 +504,17 @@ public class JobsListener implements Listener {
signInfo.setJobName("gtoplist"); signInfo.setJobName("gtoplist");
signInfo.setSpecial(special); signInfo.setSpecial(special);
Jobs.getSignUtil().getSigns().addSign(signInfo); signUtil.getSigns().addSign(signInfo);
Jobs.getSignUtil().saveSigns(); signUtil.saveSigns();
event.setCancelled(true); event.setCancelled(true);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
if (!signtype.contains("gtoplist") && job != null) if (!signtype.contains("gtoplist") && job != null)
Jobs.getSignUtil().SignUpdate(job.getName()); signUtil.SignUpdate(job.getName());
else else
Jobs.getSignUtil().SignUpdate("gtoplist"); signUtil.SignUpdate("gtoplist");
return; return;
} }
}, 1L); }, 1L);