Mirror von
https://github.com/St3venAU/ArmorStandTools.git
synchronisiert 2024-12-29 04:50:09 +01:00
Update to 1.11
Dieser Commit ist enthalten in:
Ursprung
148065dbdc
Commit
8127efe8a2
@ -42,9 +42,7 @@ class ArmorStandGUI implements Listener {
|
|||||||
im.setDisplayName(" ");
|
im.setDisplayName(" ");
|
||||||
filler.setItemMeta(im);
|
filler.setItemMeta(im);
|
||||||
invSlots.add(10);
|
invSlots.add(10);
|
||||||
if(!Main.oneEight) {
|
invSlots.add(12);
|
||||||
invSlots.add(12);
|
|
||||||
}
|
|
||||||
invSlots.add(2);
|
invSlots.add(2);
|
||||||
invSlots.add(11);
|
invSlots.add(11);
|
||||||
invSlots.add(20);
|
invSlots.add(20);
|
||||||
@ -68,12 +66,9 @@ class ArmorStandGUI implements Listener {
|
|||||||
i.setItem(tool.getSlot(), updateLore(tool));
|
i.setItem(tool.getSlot(), updateLore(tool));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Main.oneEight) {
|
|
||||||
i.setItem(10, as.getItemInHand());
|
i.setItem(10, as.getEquipment().getItemInMainHand());
|
||||||
} else {
|
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(2, as.getHelmet());
|
||||||
i.setItem(11, as.getChestplate());
|
i.setItem(11, as.getChestplate());
|
||||||
i.setItem(20, as.getLeggings());
|
i.setItem(20, as.getLeggings());
|
||||||
@ -96,7 +91,7 @@ class ArmorStandGUI implements Listener {
|
|||||||
case ARMS:
|
case ARMS:
|
||||||
return Utils.setLore(item, ChatColor.AQUA + Config.arms + ": " + (as.hasArms() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff)));
|
return Utils.setLore(item, ChatColor.AQUA + Config.arms + ": " + (as.hasArms() ? (ChatColor.GREEN + Config.isOn) : (ChatColor.RED + Config.isOff)));
|
||||||
case INVUL:
|
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:
|
case SLOTS:
|
||||||
return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked)));
|
return Utils.setLore(item, ChatColor.AQUA + Config.equip + ": " + (NBT.getDisabledSlots(as) == 2039583 ? (ChatColor.GREEN + Config.locked) : (ChatColor.RED + Config.unLocked)));
|
||||||
case NODEL:
|
case NODEL:
|
||||||
@ -253,12 +248,8 @@ class ArmorStandGUI implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if(as == null || i == null) return;
|
if(as == null || i == null) return;
|
||||||
if(Main.oneEight) {
|
as.getEquipment().setItemInMainHand(i.getItem(10));
|
||||||
as.setItemInHand(i.getItem(10));
|
as.getEquipment().setItemInOffHand(i.getItem(12));
|
||||||
} else {
|
|
||||||
as.getEquipment().setItemInMainHand(i.getItem(10));
|
|
||||||
as.getEquipment().setItemInOffHand(i.getItem(12));
|
|
||||||
}
|
|
||||||
as.setHelmet(i.getItem(2));
|
as.setHelmet(i.getItem(2));
|
||||||
as.setChestplate(i.getItem(11));
|
as.setChestplate(i.getItem(11));
|
||||||
as.setLeggings(i.getItem(20));
|
as.setLeggings(i.getItem(20));
|
||||||
|
@ -105,9 +105,6 @@ public enum ArmorStandTool {
|
|||||||
|
|
||||||
static void give(Player p) {
|
static void give(Player p) {
|
||||||
PlayerInventory i = p.getInventory();
|
PlayerInventory i = p.getInventory();
|
||||||
for(int slot = 0; slot < 36; slot++) {
|
|
||||||
i.setItem(slot, null);
|
|
||||||
}
|
|
||||||
for(ArmorStandTool t : values()) {
|
for(ArmorStandTool t : values()) {
|
||||||
if(t.enabled && !t.forGui) {
|
if(t.enabled && !t.forGui) {
|
||||||
i.setItem(t.slot, t.item);
|
i.setItem(t.slot, t.item);
|
||||||
@ -125,7 +122,7 @@ public enum ArmorStandTool {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
static ArmorStandTool get(Player p) {
|
static ArmorStandTool get(Player p) {
|
||||||
return get(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand());
|
return get(p.getInventory().getItemInMainHand());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isTool(ItemStack is) {
|
static boolean isTool(ItemStack is) {
|
||||||
@ -134,6 +131,6 @@ public enum ArmorStandTool {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
static boolean isHoldingTool(Player p) {
|
static boolean isHoldingTool(Player p) {
|
||||||
return isTool(Main.oneEight ? p.getItemInHand() : p.getInventory().getItemInMainHand());
|
return isTool(p.getInventory().getItemInMainHand());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,12 +30,10 @@ class Commands implements CommandExecutor {
|
|||||||
if(args.length == 0) {
|
if(args.length == 0) {
|
||||||
UUID uuid = p.getUniqueId();
|
UUID uuid = p.getUniqueId();
|
||||||
if(plugin.savedInventories.containsKey(uuid)) {
|
if(plugin.savedInventories.containsKey(uuid)) {
|
||||||
p.getInventory().setContents(plugin.savedInventories.get(uuid));
|
plugin.restoreInventory(p);
|
||||||
plugin.savedInventories.remove(uuid);
|
|
||||||
p.sendMessage(ChatColor.GREEN + Config.invReturned);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
plugin.savedInventories.put(uuid, p.getInventory().getContents());
|
plugin.saveInventoryAndClear(p);
|
||||||
ArmorStandTool.give(p);
|
ArmorStandTool.give(p);
|
||||||
p.sendMessage(ChatColor.GREEN + Config.giveMsg1);
|
p.sendMessage(ChatColor.GREEN + Config.giveMsg1);
|
||||||
p.sendMessage(ChatColor.AQUA + Config.giveMsg2);
|
p.sendMessage(ChatColor.AQUA + Config.giveMsg2);
|
||||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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[]>();
|
public final HashMap<UUID, ItemStack[]> savedInventories = new HashMap<UUID, ItemStack[]>();
|
||||||
private final EulerAngle zero = new EulerAngle(0D, 0D, 0D);
|
private final EulerAngle zero = new EulerAngle(0D, 0D, 0D);
|
||||||
static String NMS_VERSION;
|
static String NMS_VERSION;
|
||||||
static boolean oneEight, oneNineFour, oneTen;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
NMS_VERSION = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
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);
|
getServer().getPluginManager().registerEvents(new MainListener(this), this);
|
||||||
CommandExecutor ce = new Commands(this);
|
CommandExecutor ce = new Commands(this);
|
||||||
getCommand("astools").setExecutor(ce);
|
getCommand("astools").setExecutor(ce);
|
||||||
@ -50,8 +47,7 @@ public class Main extends JavaPlugin {
|
|||||||
for(UUID uuid : savedInventories.keySet()) {
|
for(UUID uuid : savedInventories.keySet()) {
|
||||||
p = getServer().getPlayer(uuid);
|
p = getServer().getPlayer(uuid);
|
||||||
if(p != null && p.isOnline()) {
|
if(p != null && p.isOnline()) {
|
||||||
p.getInventory().setContents(savedInventories.get(uuid));
|
restoreInventory(p);
|
||||||
p.sendMessage(ChatColor.GREEN + Config.invReturned);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
savedInventories.clear();
|
savedInventories.clear();
|
||||||
@ -70,36 +66,66 @@ public class Main extends JavaPlugin {
|
|||||||
as.remove();
|
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) {
|
void pickUpArmorStand(ArmorStand as, Player p, boolean newlySummoned) {
|
||||||
carryingArmorStand.put(p.getUniqueId(), as);
|
carryingArmorStand.put(p.getUniqueId(), as);
|
||||||
if(newlySummoned) return;
|
if(newlySummoned) return;
|
||||||
as.setMetadata("startLoc", new FixedMetadataValue(this, as.getLocation()));
|
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"})
|
@SuppressWarnings({"deprecation", "ConstantConditions"})
|
||||||
void generateCmdBlock(Location l, ArmorStand as) {
|
void generateCmdBlock(Location l, ArmorStand as) {
|
||||||
Location loc = as.getLocation();
|
Location loc = as.getLocation();
|
||||||
int dSlots = NBT.getDisabledSlots(as);
|
int dSlots = NBT.getDisabledSlots(as);
|
||||||
String hand, boots, legs, chest, helm, offHand = "0";
|
String hand, boots, legs, chest, helm, offHand;
|
||||||
int handDmg, offHandDmg = 0;
|
int handDmg, offHandDmg;
|
||||||
if(oneEight) {
|
hand = as.getEquipment().getItemInMainHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInMainHand().getType());
|
||||||
hand = as.getItemInHand() == null ? "0" : String.valueOf(as.getItemInHand().getTypeId());
|
offHand = as.getEquipment().getItemInOffHand() == null ? "air" : Utils.getNmsName(as.getEquipment().getItemInOffHand().getType());
|
||||||
boots = as.getBoots() == null ? "0" : String.valueOf(as.getBoots().getTypeId());
|
boots = as.getBoots() == null ? "air" : Utils.getNmsName(as.getBoots().getType());
|
||||||
legs = as.getLeggings() == null ? "0" : String.valueOf(as.getLeggings().getTypeId());
|
legs = as.getLeggings() == null ? "air" : Utils.getNmsName(as.getLeggings().getType());
|
||||||
chest = as.getChestplate() == null ? "0" : String.valueOf(as.getChestplate().getTypeId());
|
chest = as.getChestplate() == null ? "air" : Utils.getNmsName(as.getChestplate().getType());
|
||||||
helm = as.getHelmet() == null ? "0" : String.valueOf(as.getHelmet().getTypeId());
|
helm = as.getHelmet() == null ? "air" : Utils.getNmsName(as.getHelmet().getType());
|
||||||
handDmg = as.getItemInHand() == null ? 0 : as.getItemInHand().getDurability();
|
handDmg = as.getEquipment().getItemInMainHand() == null ? 0 : as.getEquipment().getItemInMainHand().getDurability();
|
||||||
|
offHandDmg = as.getEquipment().getItemInOffHand() == null ? 0 : as.getEquipment().getItemInOffHand().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();
|
|
||||||
}
|
|
||||||
|
|
||||||
int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
|
int bootsDmg = as.getBoots() == null ? 0 : as.getBoots().getDurability();
|
||||||
int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
|
int legsDmg = as.getLeggings() == null ? 0 : as.getLeggings().getDurability();
|
||||||
@ -111,16 +137,14 @@ public class Main extends JavaPlugin {
|
|||||||
EulerAngle la = as.getLeftArmPose();
|
EulerAngle la = as.getLeftArmPose();
|
||||||
EulerAngle ra = as.getRightArmPose();
|
EulerAngle ra = as.getRightArmPose();
|
||||||
EulerAngle bo = as.getBodyPose();
|
EulerAngle bo = as.getBodyPose();
|
||||||
String cmd;
|
String cmd = "summon " + getSummonEntityName() + " " + Utils.twoDec(loc.getX()) + " " + Utils.twoDec(loc.getY()) + " " + Utils.twoDec(loc.getZ()) + " {"
|
||||||
if(!oneEight) {
|
|
||||||
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.getMaxHealth() != 20 ? "Attributes:[{Name:\"generic.maxHealth\", Base:" + as.getMaxHealth() + "}]," : "")
|
||||||
+ (as.isVisible() ? "" : "Invisible:1,")
|
+ (as.isVisible() ? "" : "Invisible:1,")
|
||||||
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
|
+ (as.hasBasePlate() ? "" : "NoBasePlate:1,")
|
||||||
+ (as.hasGravity() ? "" : "NoGravity:1,")
|
+ (as.hasGravity() ? "" : "NoGravity:1,")
|
||||||
+ (as.hasArms() ? "ShowArms:1," : "")
|
+ (as.hasArms() ? "ShowArms:1," : "")
|
||||||
+ (as.isSmall() ? "Small:1," : "")
|
+ (as.isSmall() ? "Small:1," : "")
|
||||||
+ (NBT.isInvulnerable(as) ? "Invulnerable:1," : "")
|
+ (as.isInvulnerable() ? "Invulnerable:1," : "")
|
||||||
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
|
+ (dSlots == 0 ? "" : ("DisabledSlots:" + dSlots + ","))
|
||||||
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
|
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "")
|
||||||
+ (as.getCustomName() == null ? "" : ("CustomName:\"" + as.getCustomName() + "\","))
|
+ (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],"))
|
+ (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],"))
|
+ (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]}}";
|
+ "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();
|
Block b = l.getBlock();
|
||||||
b.setType(Material.COMMAND);
|
b.setType(Material.COMMAND);
|
||||||
b.setData((byte) 0);
|
b.setData((byte) 0);
|
||||||
@ -185,12 +181,8 @@ public class Main extends JavaPlugin {
|
|||||||
clone.setChestplate(as.getChestplate());
|
clone.setChestplate(as.getChestplate());
|
||||||
clone.setLeggings(as.getLeggings());
|
clone.setLeggings(as.getLeggings());
|
||||||
clone.setBoots(as.getBoots());
|
clone.setBoots(as.getBoots());
|
||||||
if(oneEight) {
|
clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand());
|
||||||
clone.setItemInHand(as.getItemInHand());
|
clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand());
|
||||||
} else {
|
|
||||||
clone.getEquipment().setItemInMainHand(as.getEquipment().getItemInMainHand());
|
|
||||||
clone.getEquipment().setItemInOffHand(as.getEquipment().getItemInOffHand());
|
|
||||||
}
|
|
||||||
clone.setHeadPose(as.getHeadPose());
|
clone.setHeadPose(as.getHeadPose());
|
||||||
clone.setBodyPose(as.getBodyPose());
|
clone.setBodyPose(as.getBodyPose());
|
||||||
clone.setLeftArmPose(as.getLeftArmPose());
|
clone.setLeftArmPose(as.getLeftArmPose());
|
||||||
@ -205,7 +197,7 @@ public class Main extends JavaPlugin {
|
|||||||
clone.setSmall(as.isSmall());
|
clone.setSmall(as.isSmall());
|
||||||
clone.setMaxHealth(as.getMaxHealth());
|
clone.setMaxHealth(as.getMaxHealth());
|
||||||
NBT.setSlotsDisabled(clone, NBT.getDisabledSlots(as) == 2039583);
|
NBT.setSlotsDisabled(clone, NBT.getDisabledSlots(as) == 2039583);
|
||||||
NBT.setInvulnerable(clone, NBT.isInvulnerable(as));
|
clone.setInvulnerable(as.isInvulnerable());
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,14 +217,12 @@ public class MainListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.carryingArmorStand.remove(uuid);
|
plugin.carryingArmorStand.remove(uuid);
|
||||||
if (plugin.savedInventories.containsKey(uuid)) {
|
if (plugin.savedInventories.containsKey(uuid)) {
|
||||||
p.getInventory().setContents(plugin.savedInventories.get(uuid));
|
plugin.restoreInventory(p);
|
||||||
plugin.savedInventories.remove(uuid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Config.deactivateOnWorldChange && !sameWorld && plugin.savedInventories.containsKey(p.getUniqueId())) {
|
if(Config.deactivateOnWorldChange && !sameWorld && plugin.savedInventories.containsKey(p.getUniqueId())) {
|
||||||
p.getInventory().setContents(plugin.savedInventories.get(p.getUniqueId()));
|
plugin.restoreInventory(p);
|
||||||
plugin.savedInventories.remove(p.getUniqueId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,8 +285,7 @@ public class MainListener implements Listener {
|
|||||||
plugin.carryingArmorStand.remove(uuid);
|
plugin.carryingArmorStand.remove(uuid);
|
||||||
}
|
}
|
||||||
if(plugin.savedInventories.containsKey(uuid)) {
|
if(plugin.savedInventories.containsKey(uuid)) {
|
||||||
event.getPlayer().getInventory().setContents(plugin.savedInventories.get(uuid));
|
plugin.restoreInventory(event.getPlayer());
|
||||||
plugin.savedInventories.remove(uuid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +330,7 @@ public class MainListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
if(event.getEntity() instanceof ArmorStand) {
|
if(event.getEntity() instanceof ArmorStand) {
|
||||||
if(NBT.isInvulnerable((ArmorStand) event.getEntity())) {
|
if(event.getEntity().isInvulnerable()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
if(event.getDamager() instanceof Player && ArmorStandTool.isHoldingTool((Player) event.getDamager())) {
|
if(event.getDamager() instanceof Player && ArmorStandTool.isHoldingTool((Player) event.getDamager())) {
|
||||||
@ -360,12 +357,8 @@ public class MainListener implements Listener {
|
|||||||
as.setChestplate(Config.chest);
|
as.setChestplate(Config.chest);
|
||||||
as.setLeggings(Config.pants);
|
as.setLeggings(Config.pants);
|
||||||
as.setBoots(Config.boots);
|
as.setBoots(Config.boots);
|
||||||
if(Main.oneEight) {
|
as.getEquipment().setItemInMainHand(Config.itemInHand);
|
||||||
as.setItemInHand(Config.itemInHand);
|
as.getEquipment().setItemInOffHand(Config.itemInOffHand);
|
||||||
} else {
|
|
||||||
as.getEquipment().setItemInMainHand(Config.itemInHand);
|
|
||||||
as.getEquipment().setItemInOffHand(Config.itemInOffHand);
|
|
||||||
}
|
|
||||||
as.setVisible(Config.isVisible);
|
as.setVisible(Config.isVisible);
|
||||||
as.setSmall(Config.isSmall);
|
as.setSmall(Config.isSmall);
|
||||||
as.setArms(Config.hasArms);
|
as.setArms(Config.hasArms);
|
||||||
@ -376,7 +369,7 @@ public class MainListener implements Listener {
|
|||||||
as.setCustomNameVisible(true);
|
as.setCustomNameVisible(true);
|
||||||
}
|
}
|
||||||
NBT.setSlotsDisabled(as, Config.equipmentLock);
|
NBT.setSlotsDisabled(as, Config.equipmentLock);
|
||||||
NBT.setInvulnerable(as, Config.invulnerable);
|
as.setInvulnerable(Config.invulnerable);
|
||||||
return as;
|
return as;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,25 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
|
|||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class NBT {
|
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) {
|
static boolean toggleSlotsDisabled(ArmorStand as) {
|
||||||
boolean slotsDisabled = getDisabledSlots(as) == 0;
|
boolean slotsDisabled = getDisabledSlots(as) == 0;
|
||||||
setSlotsDisabled(as, slotsDisabled);
|
setSlotsDisabled(as, slotsDisabled);
|
||||||
@ -21,115 +35,46 @@ class NBT {
|
|||||||
static int getDisabledSlots(ArmorStand as) {
|
static int getDisabledSlots(ArmorStand as) {
|
||||||
Object nmsEntity = getNmsEntity(as);
|
Object nmsEntity = getNmsEntity(as);
|
||||||
if(nmsEntity == null) return 0;
|
if(nmsEntity == null) return 0;
|
||||||
if(Main.oneEight) {
|
Field f;
|
||||||
Object tag = getTag(nmsEntity);
|
try {
|
||||||
if (tag == null) return 0;
|
f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName());
|
||||||
return getInt(tag, "DisabledSlots");
|
} catch (NoSuchFieldException e) {
|
||||||
} else {
|
e.printStackTrace();
|
||||||
Field f;
|
return 0;
|
||||||
try {
|
}
|
||||||
f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz"));
|
f.setAccessible(true);
|
||||||
} catch (NoSuchFieldException e) {
|
try {
|
||||||
e.printStackTrace();
|
return (Integer) f.get(nmsEntity);
|
||||||
return 0;
|
} catch (IllegalAccessException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
f.setAccessible(true);
|
return 0;
|
||||||
try {
|
|
||||||
return (Integer) f.get(nmsEntity);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) {
|
static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) {
|
||||||
Object nmsEntity = getNmsEntity(as);
|
Object nmsEntity = getNmsEntity(as);
|
||||||
if (nmsEntity == null) return;
|
if (nmsEntity == null) return;
|
||||||
if(Main.oneEight) {
|
Field f;
|
||||||
Object tag = getTag(nmsEntity);
|
try {
|
||||||
if (tag == null) return;
|
f = nmsEntity.getClass().getDeclaredField(getDisabledSlotsFieldName());
|
||||||
setInt(tag, "DisabledSlots", slotsDisabled ? 2039583 : 0);
|
} catch (NoSuchFieldException e) {
|
||||||
saveTagA(nmsEntity, tag);
|
e.printStackTrace();
|
||||||
} else {
|
return;
|
||||||
Field f;
|
}
|
||||||
try {
|
f.setAccessible(true);
|
||||||
f = nmsEntity.getClass().getDeclaredField(Main.oneNineFour ? "bA" : (Main.oneTen ? "bB" : "bz"));
|
try {
|
||||||
} catch (NoSuchFieldException e) {
|
f.set(nmsEntity, slotsDisabled ? 2039583 : 0);
|
||||||
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
||||||
return;
|
e.printStackTrace();
|
||||||
}
|
|
||||||
f.setAccessible(true);
|
|
||||||
try {
|
|
||||||
f.set(nmsEntity, slotsDisabled ? 2039583 : 0);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean toggleInvulnerability(ArmorStand as) {
|
static boolean toggleInvulnerability(ArmorStand as) {
|
||||||
boolean isInvulnerable = !isInvulnerable(as);
|
boolean isInvulnerable = !as.isInvulnerable();
|
||||||
setInvulnerable(as, isInvulnerable);
|
as.setInvulnerable(isInvulnerable);
|
||||||
return 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) {
|
private static Object getNmsEntity(org.bukkit.entity.Entity entity) {
|
||||||
try {
|
try {
|
||||||
return entity.getClass().getMethod("getHandle").invoke(entity);
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
static String getItemStackTags(ItemStack is) {
|
static String getItemStackTags(ItemStack is) {
|
||||||
if(is == null) {
|
if(is == null) {
|
||||||
@ -199,58 +127,4 @@ class NBT {
|
|||||||
return "";
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package com.gmail.St3venAU.plugins.ArmorStandTools;
|
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.api.PlotAPI;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
class PlotSquaredHook {
|
class PlotSquaredHook {
|
||||||
|
@ -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")) {
|
if(nmsClassString.equals("ChatSerializer") && !Main.NMS_VERSION.equals("v1_8_R1")) {
|
||||||
nmsClassString = "IChatBaseComponent$ChatSerializer";
|
nmsClassString = "IChatBaseComponent$ChatSerializer";
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Main Config
|
# 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
|
# (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)
|
# config to allow it to be re-created. There may be new config options)
|
||||||
#
|
#
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# Language Config
|
# 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
|
# (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)
|
# config to allow it to be re-created. There may be new config options)
|
||||||
#
|
#
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
main: com.gmail.St3venAU.plugins.ArmorStandTools.Main
|
main: com.gmail.St3venAU.plugins.ArmorStandTools.Main
|
||||||
name: ArmorStandTools
|
name: ArmorStandTools
|
||||||
version: 2.1.4
|
version: 2.2.0
|
||||||
author: St3venAU
|
author: St3venAU
|
||||||
description: Armor stand manipulation tools
|
description: Armor stand manipulation tools
|
||||||
softdepend: [WorldGuard, PlotSquared]
|
softdepend: [WorldGuard, PlotSquared]
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren