3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-28 04:20:08 +01:00
Dieser Commit ist enthalten in:
Steven 2016-11-24 02:09:08 +08:00
Ursprung 148065dbdc
Commit 8127efe8a2
11 geänderte Dateien mit 126 neuen und 282 gelöschten Zeilen

Datei anzeigen

@ -42,9 +42,7 @@ class ArmorStandGUI implements Listener {
im.setDisplayName(" ");
filler.setItemMeta(im);
invSlots.add(10);
if(!Main.oneEight) {
invSlots.add(12);
}
invSlots.add(12);
invSlots.add(2);
invSlots.add(11);
invSlots.add(20);
@ -68,12 +66,9 @@ class ArmorStandGUI implements Listener {
i.setItem(tool.getSlot(), updateLore(tool));
}
}
if(Main.oneEight) {
i.setItem(10, as.getItemInHand());
} else {
i.setItem(10, as.getEquipment().getItemInMainHand());
i.setItem(12, as.getEquipment().getItemInOffHand());
}
i.setItem(10, as.getEquipment().getItemInMainHand());
i.setItem(12, as.getEquipment().getItemInOffHand());
i.setItem(2, as.getHelmet());
i.setItem(11, as.getChestplate());
i.setItem(20, as.getLeggings());
@ -96,7 +91,7 @@ class ArmorStandGUI implements Listener {
case ARMS:
return Utils.setLore(item, ChatColor.AQUA + Config.arms + ": " + (as.hasArms() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff)));
case INVUL:
return Utils.setLore(item, ChatColor.AQUA + Config.invul + ": " + (NBT.isInvulnerable(as) ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff)));
return Utils.setLore(item, ChatColor.AQUA + Config.invul + ": " + (as.isInvulnerable() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff)));
case SLOTS:
return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked)));
case NODEL:
@ -253,12 +248,8 @@ class ArmorStandGUI implements Listener {
@Override
public void run() {
if(as == null || i == null) return;
if(Main.oneEight) {
as.setItemInHand(i.getItem(10));
} else {
as.getEquipment().setItemInMainHand(i.getItem(10));
as.getEquipment().setItemInOffHand(i.getItem(12));
}
as.getEquipment().setItemInMainHand(i.getItem(10));
as.getEquipment().setItemInOffHand(i.getItem(12));
as.setHelmet(i.getItem(2));
as.setChestplate(i.getItem(11));
as.setLeggings(i.getItem(20));

Datei anzeigen

@ -105,9 +105,6 @@ public enum ArmorStandTool {
static void give(Player p) {
PlayerInventory i = p.getInventory();
for(int slot = 0; slot < 36; slot++) {
i.setItem(slot, null);
}
for(ArmorStandTool t : values()) {
if(t.enabled && !t.forGui) {
i.setItem(t.slot, t.item);
@ -125,7 +122,7 @@ public enum ArmorStandTool {
@SuppressWarnings("deprecation")
static ArmorStandTool get(Player p) {
return get(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand());
return get(p.getInventory().getItemInMainHand());
}
static boolean isTool(ItemStack is) {
@ -134,6 +131,6 @@ public enum ArmorStandTool {
@SuppressWarnings("deprecation")
static boolean isHoldingTool(Player p) {
return isTool(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand());
return isTool(p.getInventory().getItemInMainHand());
}
}

Datei anzeigen

@ -30,12 +30,10 @@ class Commands implements CommandExecutor {
if(args.length == 0) {
UUID uuid = p.getUniqueId();
if(plugin.savedInventories.containsKey(uuid)) {
p.getInventory().setContents(plugin.savedInventories.get(uuid));
plugin.savedInventories.remove(uuid);
p.sendMessage(ChatColor.GREEN + Config.invReturned);
plugin.restoreInventory(p);
return true;
} else {
plugin.savedInventories.put(uuid, p.getInventory().getContents());
plugin.saveInventoryAndClear(p);
ArmorStandTool.give(p);
p.sendMessage(ChatColor.GREEN + Config.giveMsg1);
p.sendMessage(ChatColor.AQUA + Config.giveMsg2);

Datei anzeigen

@ -12,6 +12,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
@ -26,14 +27,10 @@ public class Main extends JavaPlugin {
public final HashMap<UUID, ItemStack[]> savedInventories = new HashMap<UUID, ItemStack[]>();
private final EulerAngle zero = new EulerAngle(0D, 0D, 0D);
static String NMS_VERSION;
static boolean oneEight, oneNineFour, oneTen;
@Override
public void onEnable() {
NMS_VERSION = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
oneEight = NMS_VERSION.startsWith("v1_8");
oneNineFour = NMS_VERSION.startsWith("v1_9_R2");
oneTen = NMS_VERSION.startsWith("v1_10");
getServer().getPluginManager().registerEvents(new MainListener(this), this);
CommandExecutor ce = new Commands(this);
getCommand("astools").setExecutor(ce);
@ -50,8 +47,7 @@ public class Main extends JavaPlugin {
for(UUID uuid : savedInventories.keySet()) {
p = getServer().getPlayer(uuid);
if(p != null && p.isOnline()) {
p.getInventory().setContents(savedInventories.get(uuid));
p.sendMessage(ChatColor.GREEN + Config.invReturned);
restoreInventory(p);
}
}
savedInventories.clear();
@ -70,36 +66,66 @@ public class Main extends JavaPlugin {
as.remove();
}
private void removeAllTools(Player p) {
PlayerInventory i = p.getInventory();
for(ArmorStandTool t : ArmorStandTool.values()) {
i.remove(t.getItem());
}
}
public void saveInventoryAndClear(Player p) {
ItemStack[] inv = p.getInventory().getContents().clone();
savedInventories.put(p.getUniqueId(), inv);
p.getInventory().clear();
}
void restoreInventory(Player p) {
removeAllTools(p);
UUID uuid = p.getUniqueId();
ItemStack[] savedInv = savedInventories.get(uuid);
if(savedInv == null) return;
PlayerInventory plrInv = p.getInventory();
ItemStack[] newItems = plrInv.getContents().clone();
plrInv.setContents(savedInv);
savedInventories.remove(uuid);
for(ItemStack i : newItems) {
if(i == null) continue;
HashMap<Integer, ItemStack> couldntFit = plrInv.addItem(i);
for (ItemStack is : couldntFit.values()) {
p.getWorld().dropItem(p.getLocation(), is);
}
}
p.sendMessage(ChatColor.GREEN + Config.invReturned);
}
void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) {
carryingArmorStand.put(p.getUniqueId(), as);
if(newlySummoned) return;
as.setMetadata("startLoc", new FixedMetadataValue(this, as.getLocation()));
}
private String getSummonEntityName() {
if(NMS_VERSION.startsWith("v1_9_R2") || NMS_VERSION.startsWith("v1_10")) {
return "ArmorStand";
} else {
return "minecraft:armor_stand";
}
}
@SuppressWarnings({"deprecation", "ConstantConditions"})
void generateCmdBlock(Location l, ArmorStand as) {
Location loc = as.getLocation();
int dSlots = NBT.getDisabledSlots(as);
String hand, boots, legs, chest, helm, offHand = "0";
int handDmg, offHandDmg = 0;
if(oneEight) {
hand = as.getItemInHand() == null ? "0" : String.valueOf(as.getItemInHand().getTypeId());
boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId());
legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId());
chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId());
helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId());
handDmg = as.getItemInHand() == null ? 0 : as.getItemInHand().getDurability();
} else {
hand = as.getEquipment().getItemInMainHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInMainHand().getType());
offHand = as.getEquipment().getItemInOffHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInOffHand().getType());
boots = as.getBoots() == null ? "air" : Utils.getNmsName(as.getBoots().getType());
legs = as.getLeggings() == null ? "air" : Utils.getNmsName(as.getLeggings().getType());
chest = as.getChestplate() == null ? "air" : Utils.getNmsName(as.getChestplate().getType());
helm = as.getHelmet() == null ? "air" : Utils.getNmsName(as.getHelmet().getType());
handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability();
offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability();
}
String hand, boots, legs, chest, helm, offHand;
int handDmg, offHandDmg;
hand = as.getEquipment().getItemInMainHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInMainHand().getType());
offHand = as.getEquipment().getItemInOffHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInOffHand().getType());
boots = as.getBoots() == null ? "air" : Utils.getNmsName(as.getBoots().getType());
legs = as.getLeggings() == null ? "air" : Utils.getNmsName(as.getLeggings().getType());
chest = as.getChestplate() == null ? "air" : Utils.getNmsName(as.getChestplate().getType());
helm = as.getHelmet() == null ? "air" : Utils.getNmsName(as.getHelmet().getType());
handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability();
offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().getDurability();
int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
@ -111,16 +137,14 @@ public class Main extends JavaPlugin {
EulerAngle la = as.getLeftArmPose();
EulerAngle ra = as.getRightArmPose();
EulerAngle bo = as.getBodyPose();
String cmd;
if(!oneEight) {
cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
String cmd = "summon " + getSummonEntityName() + " " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
+ (as.getMaxHealth() != 20 ? "Attributes:[{Name:\"generic.maxHealth\", Base:" + as.getMaxHealth() + "}]," : "")
+ (as.isVisible() ? "" : "Invisible:1,")
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
+ (as.hasGravity() ? "" : "NoGravity:1,")
+ (as.hasArms() ? "ShowArms:1," : "")
+ (as.isSmall() ? "Small:1," : "")
+ (NBT.isInvulnerable(as) ? "Invulnerable:1," : "")
+ (as.isInvulnerable() ? "Invulnerable:1," : "")
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
+ (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
@ -142,34 +166,6 @@ public class Main extends JavaPlugin {
+ (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
+ (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
+ "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
} else {
cmd = "summon ArmorStand " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
+ (as.getMaxHealth() != 20 ? "Attributes:[{Name:\"generic.maxHealth\", Base:" + as.getMaxHealth() + "}]," : "")
+ (as.isVisible() ? "" : "Invisible:1,")
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
+ (as.hasGravity() ? "" : "NoGravity:1,")
+ (as.hasArms() ? "ShowArms:1," : "")
+ (as.isSmall() ? "Small:1," : "")
+ (NBT.isInvulnerable(as) ? "Invulnerable:1," : "")
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
+ (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
+ (loc.getYaw() == 0F ? "" : ("Rotation:[" + Utils.twoDec(loc.getYaw()) + "f],"))
+ (as.getItemInHand() == null && as.getBoots() == null && as.getLeggings() == null && as.getChestplate() == null && as.getHelmet() == null ? "" : (
"Equipment:["
+ "{id:" + hand + ",Count:" + as.getItemInHand().getAmount() + ",Damage:" + handDmg + NBT.getItemStackTags(as.getItemInHand()) + "},"
+ "{id:" + boots + ",Count:" + as.getBoots().getAmount() + ",Damage:" + bootsDmg + NBT.getItemStackTags(as.getBoots()) + "},"
+ "{id:" + legs + ",Count:" + as.getLeggings().getAmount() + ",Damage:" + legsDmg + NBT.getItemStackTags(as.getLeggings()) + "},"
+ "{id:" + chest + ",Count:" + as.getChestplate().getAmount() + ",Damage:" + chestDmg + NBT.getItemStackTags(as.getChestplate()) + "},"
+ "{id:" + helm + ",Count:" + as.getHelmet().getAmount() + ",Damage:" + helmDmg + NBT.getItemStackTags(as.getHelmet()) + NBT.skullOwner(as.getHelmet()) + "}],"))
+ "Pose:{"
+ (bo.equals(zero) ? "" : ("Body:[" + Utils.angle(bo.getX()) + "f," + Utils.angle(bo.getY()) + "f," + Utils.angle(bo.getZ()) + "f],"))
+ (he.equals(zero) ? "" : ("Head:[" + Utils.angle(he.getX()) + "f," + Utils.angle(he.getY()) + "f," + Utils.angle(he.getZ()) + "f],"))
+ (ll.equals(zero) ? "" : ("LeftLeg:[" + Utils.angle(ll.getX()) + "f," + Utils.angle(ll.getY()) + "f," + Utils.angle(ll.getZ()) + "f],"))
+ (rl.equals(zero) ? "" : ("RightLeg:[" + Utils.angle(rl.getX()) + "f," + Utils.angle(rl.getY()) + "f," + Utils.angle(rl.getZ()) + "f],"))
+ (la.equals(zero) ? "" : ("LeftArm:[" + Utils.angle(la.getX()) + "f," + Utils.angle(la.getY()) + "f," + Utils.angle(la.getZ()) + "f],"))
+ "RightArm:[" + Utils.angle(ra.getX()) + "f," + Utils.angle(ra.getY()) + "f," + Utils.angle(ra.getZ()) + "f]}}";
}
Block b = l.getBlock();
b.setType(Material.COMMAND);
b.setData((byte) 0);
@ -185,12 +181,8 @@ public class Main extends JavaPlugin {
clone.setChestplate(as.getChestplate());
clone.setLeggings(as.getLeggings());
clone.setBoots(as.getBoots());
if(oneEight) {
clone.setItemInHand(as.getItemInHand());
} else {
clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand());
clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand());
}
clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand());
clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand());
clone.setHeadPose(as.getHeadPose());
clone.setBodyPose(as.getBodyPose());
clone.setLeftArmPose(as.getLeftArmPose());
@ -205,7 +197,7 @@ public class Main extends JavaPlugin {
clone.setSmall(as.isSmall());
clone.setMaxHealth(as.getMaxHealth());
NBT.setSlotsDisabled(clone, NBT.getDisabledSlots(as) == 2039583);
NBT.setInvulnerable(clone, NBT.isInvulnerable(as));
clone.setInvulnerable(as.isInvulnerable());
return clone;
}

Datei anzeigen

@ -217,14 +217,12 @@ public class MainListener implements Listener {
} else {
plugin.carryingArmorStand.remove(uuid);
if (plugin.savedInventories.containsKey(uuid)) {
p.getInventory().setContents(plugin.savedInventories.get(uuid));
plugin.savedInventories.remove(uuid);
plugin.restoreInventory(p);
}
}
}
if(Config.deactivateOnWorldChange && !sameWorld && plugin.savedInventories.containsKey(p.getUniqueId())) {
p.getInventory().setContents(plugin.savedInventories.get(p.getUniqueId()));
plugin.savedInventories.remove(p.getUniqueId());
plugin.restoreInventory(p);
}
}
@ -287,8 +285,7 @@ public class MainListener implements Listener {
plugin.carryingArmorStand.remove(uuid);
}
if(plugin.savedInventories.containsKey(uuid)) {
event.getPlayer().getInventory().setContents(plugin.savedInventories.get(uuid));
plugin.savedInventories.remove(uuid);
plugin.restoreInventory(event.getPlayer());
}
}
@ -333,7 +330,7 @@ public class MainListener implements Listener {
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if(event.getEntity() instanceof ArmorStand) {
if(NBT.isInvulnerable((ArmorStand) event.getEntity())) {
if(event.getEntity().isInvulnerable()) {
event.setCancelled(true);
}
if(event.getDamager() instanceof Player && ArmorStandTool.isHoldingTool((Player) event.getDamager())) {
@ -360,12 +357,8 @@ public class MainListener implements Listener {
as.setChestplate(Config.chest);
as.setLeggings(Config.pants);
as.setBoots(Config.boots);
if(Main.oneEight) {
as.setItemInHand(Config.itemInHand);
} else {
as.getEquipment().setItemInMainHand(Config.itemInHand);
as.getEquipment().setItemInOffHand(Config.itemInOffHand);
}
as.getEquipment().setItemInMainHand(Config.itemInHand);
as.getEquipment().setItemInOffHand(Config.itemInOffHand);
as.setVisible(Config.isVisible);
as.setSmall(Config.isSmall);
as.setArms(Config.hasArms);
@ -376,7 +369,7 @@ public class MainListener implements Listener {
as.setCustomNameVisible(true);
}
NBT.setSlotsDisabled(as, Config.equipmentLock);
NBT.setInvulnerable(as, Config.invulnerable);
as.setInvulnerable(Config.invulnerable);
return as;
}

Datei anzeigen

@ -7,11 +7,25 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;
class NBT {
private static String disabledSlotsFieldName;
private static String getDisabledSlotsFieldName() {
if(disabledSlotsFieldName != null) return disabledSlotsFieldName;
if(Main.NMS_VERSION.startsWith("v1_9_R2")) {
disabledSlotsFieldName = "bA";
} else if(Main.NMS_VERSION.startsWith("v1_10")) {
disabledSlotsFieldName = "bB";
} else if(Main.NMS_VERSION.startsWith("v1_11")) {
disabledSlotsFieldName = "bA";
} else {
disabledSlotsFieldName = "bA"; // If ver greater than 1.11 then assume the same as 1.11 and hope that it didn't change :)
}
return disabledSlotsFieldName;
}
static boolean toggleSlotsDisabled(ArmorStand as) {
boolean slotsDisabled = getDisabledSlots(as) == 0;
setSlotsDisabled(as, slotsDisabled);
@ -21,115 +35,46 @@ class NBT {
static int getDisabledSlots(ArmorStand as) {
Object nmsEntity = getNmsEntity(as);
if(nmsEntity == null) return 0;
if(Main.oneEight) {
Object tag = getTag(nmsEntity);
if (tag == null) return 0;
return getInt(tag, "DisabledSlots");
} else {
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz"));
} catch (NoSuchFieldException e) {
e.printStackTrace();
return 0;
}
f.setAccessible(true);
try {
return (Integer) f.get(nmsEntity);
} catch (IllegalAccessException e) {
e.printStackTrace();
return 0;
}
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName());
} catch (NoSuchFieldException e) {
e.printStackTrace();
return 0;
}
f.setAccessible(true);
try {
return (Integer) f.get(nmsEntity);
} catch (IllegalAccessException e) {
e.printStackTrace();
return 0;
}
}
static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) {
Object nmsEntity = getNmsEntity(as);
if (nmsEntity == null) return;
if(Main.oneEight) {
Object tag = getTag(nmsEntity);
if (tag == null) return;
setInt(tag, "DisabledSlots", slotsDisabled ? 2039583 : 0);
saveTagA(nmsEntity, tag);
} else {
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz"));
} catch (NoSuchFieldException e) {
e.printStackTrace();
return;
}
f.setAccessible(true);
try {
f.set(nmsEntity, slotsDisabled ? 2039583 : 0);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Field f;
try {
f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName());
} catch (NoSuchFieldException e) {
e.printStackTrace();
return;
}
f.setAccessible(true);
try {
f.set(nmsEntity, slotsDisabled ? 2039583 : 0);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
static boolean toggleInvulnerability(ArmorStand as) {
boolean isInvulnerable = !isInvulnerable(as);
setInvulnerable(as, isInvulnerable);
boolean isInvulnerable = !as.isInvulnerable();
as.setInvulnerable(isInvulnerable);
return isInvulnerable;
}
static boolean isInvulnerable(ArmorStand as) {
if(Main.oneNineFour || Main.oneTen) {
return as.isInvulnerable();
}
Object nmsEntity = getNmsEntity(as);
if (nmsEntity == null) return false;
if(Main.oneEight) {
Object tag = getTag(nmsEntity);
return tag != null && getBoolean(tag, "Invulnerable");
} else {
Field f;
try {
f = Utils.getNMSClass("Entity").getDeclaredField("invulnerable");
} catch (Exception e) {
e.printStackTrace();
return false;
}
f.setAccessible(true);
try {
return (Boolean) f.get(nmsEntity);
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
}
}
}
static void setInvulnerable(ArmorStand as, boolean invulnerable) {
if(Main.oneNineFour || Main.oneTen) {
as.setInvulnerable(invulnerable);
}
Object nmsEntity = getNmsEntity(as);
if (nmsEntity == null) return;
if(Main.oneEight) {
Object tag = getTag(nmsEntity);
if(tag == null) return;
setBoolean(tag, "Invulnerable", invulnerable);
saveTagF(nmsEntity, tag);
} else {
Field f;
try {
f = Utils.getNMSClass("Entity").getDeclaredField("invulnerable");
} catch (Exception e) {
e.printStackTrace();
return;
}
f.setAccessible(true);
try {
f.set(nmsEntity, invulnerable);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static Object getNmsEntity(org.bukkit.entity.Entity entity) {
try {
return entity.getClass().getMethod("getHandle").invoke(entity);
@ -139,23 +84,6 @@ class NBT {
}
}
private static Object getTag(Object nmsEntity) {
try {
Method method = nmsEntity.getClass().getMethod("getNBTTag");
Object tag = method.invoke(nmsEntity);
if(tag == null) {
tag = Utils.getNMSClass("NBTTagCompound").newInstance();
}
method = nmsEntity.getClass().getMethod("c", Utils.getNMSClass("NBTTagCompound"));
method.invoke(nmsEntity, tag);
return tag;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@SuppressWarnings("deprecation")
static String getItemStackTags(ItemStack is) {
if(is == null) {
@ -199,58 +127,4 @@ class NBT {
return "";
}
}
@SuppressWarnings("SameParameterValue")
private static int getInt(Object tag, String name) {
try {
return (Integer) tag.getClass().getMethod("getInt", String.class).invoke(tag, name);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
@SuppressWarnings("SameParameterValue")
private static boolean getBoolean(Object tag, String name) {
try {
return (Boolean) tag.getClass().getMethod("getBoolean", String.class).invoke(tag, name);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
@SuppressWarnings("SameParameterValue")
private static void setInt(Object tag, String name, int value) {
try {
tag.getClass().getMethod("setInt", String.class, int.class).invoke(tag, name, value);
} catch (Exception e) {
e.printStackTrace();
}
}
@SuppressWarnings("SameParameterValue")
private static void setBoolean(Object tag, String name, boolean value) {
try {
tag.getClass().getMethod("setBoolean", String.class, boolean.class).invoke(tag, name, value);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void saveTagA(Object nmsEntity, Object tag) {
try {
nmsEntity.getClass().getMethod("a", Utils.getNMSClass("NBTTagCompound")).invoke(nmsEntity, tag);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void saveTagF(Object nmsEntity, Object tag) {
try {
nmsEntity.getClass().getMethod("f", Utils.getNMSClass("NBTTagCompound")).invoke(nmsEntity, tag);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Datei anzeigen

@ -1,14 +1,13 @@
package com.gmail.St3venAU.plugins.ArmorStandTools;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.UUID;
@SuppressWarnings("deprecation")
class PlotSquaredHook {

Datei anzeigen

@ -114,7 +114,7 @@ class Utils {
}
}
static Class<?> getNMSClass(String nmsClassString) throws ClassNotFoundException {
private static Class<?> getNMSClass(String nmsClassString) throws ClassNotFoundException {
if(nmsClassString.equals("ChatSerializer") && !Main.NMS_VERSION.equals("v1_8_R1")) {
nmsClassString = "IChatBaseComponent$ChatSerializer";
}

Datei anzeigen

@ -4,7 +4,7 @@
#
# Main Config
#
# File generated by: v2.1.4
# File generated by: v2.2.0
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
#

Datei anzeigen

@ -4,7 +4,7 @@
#
# Language Config
#
# File generated by: v2.1.4
# File generated by: v2.2.0
# (If this is not the version you are running, consider deleting this
# config to allow it to be re-created. There may be new config options)
#

Datei anzeigen

@ -1,6 +1,6 @@
main: com.gmail.St3venAU.plugins.ArmorStandTools.Main
name: ArmorStandTools
version: 2.1.4
version: 2.2.0
author: St3venAU
description: Armor stand manipulation tools
softdepend: [WorldGuard, PlotSquared]