3
0
Mirror von https://github.com/St3venAU/ArmorStandTools.git synchronisiert 2024-12-27 12:00:07 +01:00
Dieser Commit ist enthalten in:
Steven 2021-07-12 00:53:56 +08:00
Ursprung 42b6b66f63
Commit 1e7a868862
6 geänderte Dateien mit 160 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.St3venAU.plugins</groupId> <groupId>com.gmail.St3venAU.plugins</groupId>
<artifactId>ArmorStandTools</artifactId> <artifactId>ArmorStandTools</artifactId>
<version>4.0.0</version> <version>4.0.1</version>
<name>ArmorStandTools</name> <name>ArmorStandTools</name>
<repositories> <repositories>
@ -71,8 +71,8 @@
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration> <configuration>
<source>16</source> <source>16</source>
<target>16</target> <target>16</target>

Datei anzeigen

@ -176,7 +176,10 @@ public class AST extends JavaPlugin {
Location l = b.getLocation(); Location l = b.getLocation();
debug("PlotSquaredHook.isPlotWorld(l): " + PlotSquaredHook.isPlotWorld(l)); debug("PlotSquaredHook.isPlotWorld(l): " + PlotSquaredHook.isPlotWorld(l));
if(PlotSquaredHook.isPlotWorld(l)) { if(PlotSquaredHook.isPlotWorld(l)) {
return PlotSquaredHook.checkPermission(p, l); Boolean hasPermission = PlotSquaredHook.checkPermission(p, l);
if(hasPermission != null) {
return hasPermission;
}
} }
} }
if(Config.worldGuardPlugin != null) { if(Config.worldGuardPlugin != null) {

Datei anzeigen

@ -8,6 +8,7 @@ import org.bukkit.command.TabCompleter;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -16,7 +17,7 @@ import java.util.List;
class Commands implements CommandExecutor, TabCompleter { class Commands implements CommandExecutor, TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
AST.plugin.getLogger().warning(Config.notConsole); AST.plugin.getLogger().warning(Config.notConsole);
return false; return false;
@ -168,7 +169,7 @@ class Commands implements CommandExecutor, TabCompleter {
return closest; return closest;
} }
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, String[] args) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
String cmd = command.getName().toLowerCase(); String cmd = command.getName().toLowerCase();
String typed = ""; String typed = "";

Datei anzeigen

@ -23,8 +23,8 @@ class PlotSquaredHook {
return l.getWorld() != null && api.getPlotSquared().getPlotAreaManager().hasPlotArea(l.getWorld().getName()); return l.getWorld() != null && api.getPlotSquared().getPlotAreaManager().hasPlotArea(l.getWorld().getName());
} }
public static boolean checkPermission(Player p, Location l) { public static Boolean checkPermission(Player p, Location l) {
if(l.getWorld() == null) return true; if(l.getWorld() == null) return null;
com.plotsquared.core.location.Location plotLocation com.plotsquared.core.location.Location plotLocation
= com.plotsquared.core.location.Location.at(l.getWorld().getName(), BlockVector3.at(l.getBlockX(), l.getBlockY(), l.getBlockZ())); = com.plotsquared.core.location.Location.at(l.getWorld().getName(), BlockVector3.at(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
PlotArea plotArea = plotLocation.getPlotArea(); PlotArea plotArea = plotLocation.getPlotArea();
@ -34,6 +34,7 @@ class PlotSquaredHook {
} }
Plot plot = plotArea.getPlot(plotLocation); Plot plot = plotArea.getPlot(plotLocation);
PlotPlayer<?> pp = api.wrapPlayer(p.getUniqueId()); PlotPlayer<?> pp = api.wrapPlayer(p.getUniqueId());
if(pp == null) return null;
AST.debug("Plot: " + plot); AST.debug("Plot: " + plot);
if (plot == null) { if (plot == null) {
AST.debug("plots.admin.build.road: " + pp.hasPermission("plots.admin.build.road")); AST.debug("plots.admin.build.road: " + pp.hasPermission("plots.admin.build.road"));

Datei anzeigen

@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -42,36 +43,52 @@ class Utils {
}.runTaskLater(AST.plugin, 2L); }.runTaskLater(AST.plugin, 2L);
} }
static final EquipmentSlot[] equipmentSlots = {
EquipmentSlot.HAND,
EquipmentSlot.OFF_HAND,
EquipmentSlot.HEAD,
EquipmentSlot.CHEST,
EquipmentSlot.LEGS,
EquipmentSlot.FEET
};
static boolean hasDisabledSlots(ArmorStand as) { static boolean hasDisabledSlots(ArmorStand as) {
for(EquipmentSlot slot : equipmentSlots) { for(EquipmentSlot slot : EquipmentSlot.values()) {
if(as.hasEquipmentLock(slot, ArmorStand.LockType.REMOVING_OR_CHANGING)) { for(ArmorStand.LockType lockType : ArmorStand.LockType.values()) {
return true; if(!as.hasEquipmentLock(slot, lockType)) {
return false;
}
} }
} }
return false; return true;
} }
static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) { static void setSlotsDisabled(ArmorStand as, boolean slotsDisabled) {
if(slotsDisabled) { for(EquipmentSlot slot : EquipmentSlot.values()) {
for(EquipmentSlot slot : equipmentSlots) { for(ArmorStand.LockType lockType : ArmorStand.LockType.values()) {
as.addEquipmentLock(slot, ArmorStand.LockType.REMOVING_OR_CHANGING); if(slotsDisabled) {
} as.addEquipmentLock(slot, lockType);
} else { } else {
for(EquipmentSlot slot : equipmentSlots) { as.removeEquipmentLock(slot, lockType);
as.removeEquipmentLock(slot, ArmorStand.LockType.REMOVING_OR_CHANGING); }
} }
} }
} }
static int disabledSlotsAsInteger(ArmorStand as) {
return (as.hasEquipmentLock(EquipmentSlot.HAND, ArmorStand.LockType.ADDING_OR_CHANGING) ? 1 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.FEET, ArmorStand.LockType.ADDING_OR_CHANGING) ? 2 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.LEGS, ArmorStand.LockType.ADDING_OR_CHANGING) ? 4 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.CHEST, ArmorStand.LockType.ADDING_OR_CHANGING) ? 8 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.HEAD, ArmorStand.LockType.ADDING_OR_CHANGING) ? 16 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.OFF_HAND, ArmorStand.LockType.ADDING_OR_CHANGING) ? 32 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.HAND, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 256 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.FEET, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 512 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.LEGS, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 1024 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.CHEST, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 2048 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.HEAD, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 4096 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.OFF_HAND, ArmorStand.LockType.REMOVING_OR_CHANGING) ? 8192 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.HAND, ArmorStand.LockType.ADDING) ? 65536 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.FEET, ArmorStand.LockType.ADDING) ? 131072 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.LEGS, ArmorStand.LockType.ADDING) ? 262144 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.CHEST, ArmorStand.LockType.ADDING) ? 524288 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.HEAD, ArmorStand.LockType.ADDING) ? 1048576 : 0)
+ (as.hasEquipmentLock(EquipmentSlot.OFF_HAND, ArmorStand.LockType.ADDING) ? 2097152 : 0);
}
static boolean toggleSlotsDisabled(ArmorStand as) { static boolean toggleSlotsDisabled(ArmorStand as) {
boolean slotsDisabled = !hasDisabledSlots(as); boolean slotsDisabled = !hasDisabledSlots(as);
setSlotsDisabled(as, slotsDisabled); setSlotsDisabled(as, slotsDisabled);
@ -105,7 +122,13 @@ class Utils {
clone.setSmall(as.isSmall()); clone.setSmall(as.isSmall());
clone.setInvulnerable(as.isInvulnerable()); clone.setInvulnerable(as.isInvulnerable());
clone.setGlowing(as.isGlowing()); clone.setGlowing(as.isGlowing());
Utils.setSlotsDisabled(clone, Utils.hasDisabledSlots(as)); for(EquipmentSlot slot : EquipmentSlot.values()) {
for(ArmorStand.LockType lockType : ArmorStand.LockType.values()) {
if(as.hasEquipmentLock(slot, lockType)) {
clone.addEquipmentLock(slot, lockType);
}
}
}
ArmorStandCmd asCmd = new ArmorStandCmd(as); ArmorStandCmd asCmd = new ArmorStandCmd(as);
if(asCmd.getCommand() != null) { if(asCmd.getCommand() != null) {
asCmd.cloneTo(clone); asCmd.cloneTo(clone);
@ -188,52 +211,119 @@ class Utils {
tags.setCharAt(tags.length() - 1, ']'); tags.setCharAt(tags.length() - 1, ']');
} }
return tags.length() == 0 ? "" : ("," + tags.toString()); return tags.length() == 0 ? "" : tags.toString();
} }
static private String skullOwner(ItemStack is) { static private String skullOwner(ItemStack is) {
if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) return ""; if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) return "";
SkullMeta skull = (SkullMeta) is.getItemMeta(); SkullMeta skull = (SkullMeta) is.getItemMeta();
return skull.getOwningPlayer() == null ? "" : ",SkullOwner:\"" + skull.getOwningPlayer().getName() + "\""; return skull.getOwningPlayer() == null ? "" : "SkullOwner:\"" + skull.getOwningPlayer().getName() + "\"";
}
static private boolean isEmpty(ItemStack is) {
return is == null || is.getType() == Material.AIR;
}
static private String itemInfo(ItemStack is) {
if(isEmpty(is)) return "{}";
StringBuilder sb = new StringBuilder("{id:");
sb.append(is.getType().getKey().getKey());
if(is.getAmount() > 0) {
sb.append(",Count:").append(is.getAmount());
}
String itemStackTags = getItemStackTags(is);
short durability = is.getDurability();
String skullOwner = skullOwner(is);
int n = 0;
if(itemStackTags.length() > 0 || durability > 0 || skullOwner.length() > 0) {
sb.append(",tag:{");
if(durability > 0) {
sb.append("Damage:").append(durability);
n++;
}
if(itemStackTags.length() > 0) {
if(n > 0) sb.append(",");
sb.append(itemStackTags);
n++;
}
if(skullOwner.length() > 0) {
if(n > 0) sb.append(",");
sb.append(skullOwner);
}
sb.append("}");
}
sb.append("}");
return sb.toString();
}
static private String armorItems(EntityEquipment e) {
if(e == null || (isEmpty(e.getBoots()) && isEmpty(e.getLeggings()) && isEmpty(e.getChestplate()) && isEmpty(e.getHelmet()))) {
return "";
}
return "ArmorItems:["
+ itemInfo(e.getBoots()) + ","
+ itemInfo(e.getLeggings()) + ","
+ itemInfo(e.getChestplate()) + ","
+ itemInfo(e.getHelmet())
+ "],";
}
static private String handItems(EntityEquipment e) {
if(e == null || (isEmpty(e.getItemInMainHand()) && isEmpty(e.getItemInOffHand()))) {
return "";
}
return "HandItems:["
+ itemInfo(e.getItemInMainHand()) + ","
+ itemInfo(e.getItemInOffHand())
+ "],";
}
static private String angleInfo(EulerAngle ea) {
return "[" + degrees(ea.getX()) + "f," + degrees(ea.getY()) + "f," + degrees(ea.getZ()) + "f]";
}
static private String pose(ArmorStand as) {
return "Pose:{"
+ "Body:" + angleInfo(as.getBodyPose()) + ","
+ "Head:" + angleInfo(as.getHeadPose()) + ","
+ "LeftLeg:" + angleInfo(as.getLeftLegPose()) + ","
+ "RightLeg:" + angleInfo(as.getRightLegPose()) + ","
+ "LeftArm:" + angleInfo(as.getLeftArmPose()) + ","
+ "RightArm:" + angleInfo(as.getRightArmPose())
+ "}";
}
static private String createSummonCommand(ArmorStand as) {
Location asLocation = as.getLocation();
EntityEquipment e = as.getEquipment();
StringBuilder sb = new StringBuilder("summon minecraft:armor_stand ");
sb.append(twoDec(asLocation.getX())).append(" ");
sb.append(twoDec(asLocation.getY())).append(" ");
sb.append(twoDec(asLocation.getZ())).append(" ");
sb.append("{");
if(!as.isVisible()) sb.append("Invisible:1,");
if(!as.hasBasePlate()) sb.append("NoBasePlate:1,");
if(!as.hasGravity()) sb.append("NoGravity:1,");
if(as.hasArms()) sb.append("ShowArms:1,");
if(as.isSmall()) sb.append("Small:1,");
if(as.isInvulnerable()) sb.append("Invulnerable:1,");
if(as.isGlowing()) sb.append("Glowing:1,");
if(hasDisabledSlots(as)) sb.append("DisabledSlots:").append(disabledSlotsAsInteger(as)).append(",");
if(as.isCustomNameVisible()) sb.append("CustomNameVisible:1,");
if(as.getCustomName() != null) sb.append("CustomName:\"\\\"").append(as.getCustomName()).append("\\\"\",");
if(as.getLocation().getYaw() != 0F) sb.append("Rotation:[").append(twoDec(as.getLocation().getYaw())).append("f],");
sb.append(armorItems(e));
sb.append(handItems(e));
sb.append(pose(as));
sb.append("}");
return sb.toString();
} }
static void generateCmdBlock(Location l, ArmorStand as) { static void generateCmdBlock(Location l, ArmorStand as) {
Block b = l.getBlock(); Block b = l.getBlock();
b.setType(Material.COMMAND_BLOCK); b.setType(Material.COMMAND_BLOCK);
CommandBlock cb = (CommandBlock) b.getState(); CommandBlock cb = (CommandBlock) b.getState();
EntityEquipment e = as.getEquipment(); cb.setCommand(createSummonCommand(as));
cb.setCommand("summon minecraft:armor_stand " + twoDec(as.getLocation().getX()) + " " + twoDec(as.getLocation().getY()) + " " + twoDec(as.getLocation().getZ()) + " "
+ "{"
+ (as.isVisible() ? "" : "Invisible:1," )
+ (as.hasBasePlate() ? "" : "NoBasePlate:1," )
+ (as.hasGravity() ? "" : "NoGravity:1," )
+ (as.hasArms() ? "ShowArms:1," : "" )
+ (as.isSmall() ? "Small:1," : "" )
+ (as.isInvulnerable() ? "Invulnerable:1," : "" )
+ (as.isGlowing() ? "Glowing:1," : "" )
+ (as.isCustomNameVisible() ? "CustomNameVisible:1," : "" )
+ (as.getCustomName() == null ? "" : ("CustomName:\"\\\"" + as.getCustomName() + "\\\"\",") )
+ (as.getLocation().getYaw() == 0F ? "" : ("Rotation:[" + twoDec(as.getLocation().getYaw()) + "f],"))
+ "ArmorItems:["
+ (e == null || e.getBoots() == null ? "{}," : ("{id:" + e.getBoots().getType().getKey().getKey() + ",Count:" + e.getBoots().getAmount() + ",tag:{Damage:" + e.getBoots().getDurability() + getItemStackTags(e.getBoots()) + "}},"))
+ (e == null || e.getLeggings() == null ? "{}," : ("{id:" + e.getLeggings().getType().getKey().getKey() + ",Count:" + e.getLeggings().getAmount() + ",tag:{Damage:" + e.getLeggings().getDurability() + getItemStackTags(e.getLeggings()) + "}},"))
+ (e == null || e.getChestplate() == null ? "{}," : ("{id:" + e.getChestplate().getType().getKey().getKey() + ",Count:" + e.getChestplate().getAmount() + ",tag:{Damage:" + e.getChestplate().getDurability() + getItemStackTags(e.getChestplate()) + "}},"))
+ (e == null || e.getHelmet() == null ? "{}" : ("{id:" + e.getHelmet().getType().getKey().getKey() + ",Count:" + e.getHelmet().getAmount() + ",tag:{Damage:" + e.getHelmet().getDurability() + getItemStackTags(e.getHelmet()) + skullOwner(e.getHelmet()) + "}}" ))
+ "],"
+ "HandItems:["
+ (e == null ? "{}," : ("{id:" + e.getItemInMainHand().getType().getKey().getKey() + ",Count:" + e.getItemInMainHand().getAmount() + ",tag:{Damage:" + e.getItemInMainHand().getDurability() + getItemStackTags(e.getItemInMainHand()) + "}},"))
+ (e == null ? "{}" : ("{id:" + e.getItemInOffHand().getType().getKey().getKey() + ",Count:" + e.getItemInOffHand().getAmount() + ",tag:{Damage:" + e.getItemInOffHand().getDurability() + getItemStackTags(e.getItemInOffHand()) + "}}" ))
+ "],"
+ "Pose:{"
+ "Body:[" + degrees(as.getBodyPose().getX()) + "f," + degrees(as.getBodyPose().getY()) + "f," + degrees(as.getBodyPose().getZ()) + "f],"
+ "Head:[" + degrees(as.getHeadPose().getX()) + "f," + degrees(as.getHeadPose().getY()) + "f," + degrees(as.getHeadPose().getZ()) + "f],"
+ "LeftLeg:[" + degrees(as.getLeftLegPose().getX()) + "f," + degrees(as.getLeftLegPose().getY()) + "f," + degrees(as.getLeftLegPose().getZ()) + "f],"
+ "RightLeg:[" + degrees(as.getRightLegPose().getX()) + "f," + degrees(as.getRightLegPose().getY()) + "f," + degrees(as.getRightLegPose().getZ()) + "f],"
+ "LeftArm:[" + degrees(as.getLeftArmPose().getX()) + "f," + degrees(as.getLeftArmPose().getY()) + "f," + degrees(as.getLeftArmPose().getZ()) + "f],"
+ "RightArm:[" + degrees(as.getRightArmPose().getX()) + "f," + degrees(as.getRightArmPose().getY()) + "f," + degrees(as.getRightArmPose().getZ()) + "f]"
+ "}"
+ "}"
);
cb.update(); cb.update();
} }

Datei anzeigen

@ -7,9 +7,9 @@ description: Armor stand manipulation tools
softdepend: [WorldGuard, PlotSquared] softdepend: [WorldGuard, PlotSquared]
commands: commands:
astools: astools:
description: Give yourself the armor stand tools description: Provides player instructions on how to use AST
aliases: ast aliases: ast
usage: Usage /astools or /astools reload usage: Usage /astools or /ast
ascmd: ascmd:
description: View/Remove/Assign the command assigned to the nearest armor stand description: View/Remove/Assign the command assigned to the nearest armor stand
usage: Usage /ascmd view, /ascmd remove, /ascmd assign <player/console> <command> usage: Usage /ascmd view, /ascmd remove, /ascmd assign <player/console> <command>