diff --git a/README.md b/README.md index 0fbb879..84c30ce 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ Assigning Commands - Use /ascmd to assign a command to an armor stand (see usage and permissions below) - When using /ascmd assign player , the command will be run by the player - When using /ascmd assign console , the command will be run by the console (see Warning below!) -- When a player with the astools.ascmd.execute permission right clicks on an armor stand, it's command is run. -- If a player is crouching when they right click the armor stand, the command will not be run. +- When a player with the astools.ascmd.execute permission right-clicks on an armor stand, it's command is run. +- If a player is crouching when they right-click the armor stand, the command will not be run. - Warning: Make sure you are careful when assigning console commands. Any player with the astools.ascmd.execute permission will be able to execute the command. - By default, any command assigned to an armor stand will use the default cooldown set in config.yml. This can be set on an individual basis using the /ascmd cooldown command. @@ -47,6 +47,8 @@ Commands - /ascmd cooldown : Sets the cooldown (in ticks) for the command on nearest armor stand (Setting this overrides the default cooldown from config.yml) - /ascmd cooldown remove : Removes the cooldown for the command on nearest armor stand (Default cooldown set in config.yml will be used) - /astools or /ast : Legacy command - instructs player to crouch right-click an armor stand to use AST. +- /astools new : Create a new armor stand - will spawn being carried by the player +- /astools reload : Reload the plugin (use when changing config files) WorldGuard Integration ---------------------- @@ -63,6 +65,7 @@ Permissions - astools.head: Permission to use the player head tool (Ability to specify a player head for an armor stand) - astools.summon: Permission to use the summon tool (Summons an armor stand without requiring the materials) - astools.cmdblock: Permission to use the save tool (Creates a command block) +- astools.reload: Permission to reload the plugin - astools.ascmd.assign.console: Permission to assign a console command to an armor stand - astools.ascmd.assign.player: Permission to assign a player command to an armor stand - astools.ascmd.remove: Permission to remove a command from an armor stand @@ -74,4 +77,4 @@ Permissions Config ------ - config.yml - The main config file allows you to set the default starting settings for newly summoned armor stands. This is useful if you plan on creating a lot of armor stands with similar equipment. -- language.yml - Contains all of the strings of text that the player will see. Edit this file if you wish to change the text or translate it into a different language. +- language.yml - Contains all the strings of text that the player will see. Edit this file if you wish to change the text or translate it into a different language. diff --git a/pom.xml b/pom.xml index 4cf7d36..9ba63ff 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gmail.St3venAU.plugins ArmorStandTools -4.0.2 +4.1.1 ArmorStandTools diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/AST.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/AST.java index e38d240..ec6beb9 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/AST.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/AST.java @@ -19,6 +19,7 @@ import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; +import java.util.ArrayList; import java.util.HashMap; import java.util.UUID; import java.util.logging.Level; @@ -29,6 +30,7 @@ public class AST extends JavaPlugin { final static HashMap activeTool = new HashMap<>(); final static HashMap selectedArmorStand = new HashMap<>(); + final static ArrayList showAdvancedTools = new ArrayList<>(); static AST plugin; diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java index 280e456..40ec33e 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java @@ -66,12 +66,13 @@ class ArmorStandGUI implements Listener { } else if(name.length() > 32) { name = name.substring(0, 32); } - i = Bukkit.createInventory(null, 54, name); + boolean showAdvancedTools = AST.showAdvancedTools.contains(p.getUniqueId()); + i = Bukkit.createInventory(null, showAdvancedTools ? 54 : 36, name); for(int slot = 0; slot < i.getSize(); slot++) { i.setItem(slot, filler); } for(ArmorStandTool tool : ArmorStandTool.values()) { - if(tool.isEnabled()) { + if(tool.isEnabled() && (!tool.isAdvanced() || showAdvancedTools)) { i.setItem(tool.getSlot(), tool.updateLore(as)); } } @@ -101,8 +102,7 @@ class ArmorStandGUI implements Listener { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player)) return; - Player p = (Player) event.getWhoClicked(); + if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player p)) return; if(event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT || event.getClick() == ClickType.NUMBER_KEY) { event.setCancelled(true); return; @@ -129,6 +129,12 @@ class ArmorStandGUI implements Listener { return; } UUID uuid = p.getUniqueId(); + if(t.isAdvanced()) { + AST.activeTool.put(uuid, t); + AST.selectedArmorStand.put(uuid, as); + p.closeInventory(); + t.showTitle(p); + } switch (t) { case HEAD: case BODY: @@ -196,10 +202,11 @@ class ArmorStandGUI implements Listener { AST.pickUpArmorStand(as, p); Utils.title(p, Config.carrying); break; - case UP: - case DOWN: - double dist = (t == ArmorStandTool.UP ? 1 : -1) * (rightClick ? 1 : 0.1); - l.add(0, dist,0); + case MOVE_X: + case MOVE_Y: + case MOVE_Z: + double dist = rightClick ? -0.1 : 0.1; + l.add(t == ArmorStandTool.MOVE_X ? dist : 0, t == ArmorStandTool.MOVE_Y ? dist : 0,t == ArmorStandTool.MOVE_Z ? dist : 0); if (!AST.playerHasPermission(p, l.getBlock(), null)) { p.closeInventory(); p.sendMessage(ChatColor.RED + Config.wgNoPerm); @@ -218,6 +225,24 @@ class ArmorStandGUI implements Listener { as.setGlowing(glowing); Utils.title(p, Config.glow + ": " + (glowing ? Config.isOn : Config.isOff)); break; + case ADVANCED: + if(AST.showAdvancedTools.contains(uuid)) { + AST.showAdvancedTools.remove(uuid); + } else { + AST.showAdvancedTools.add(uuid); + } + p.closeInventory(); + new BukkitRunnable() { + @Override + public void run() { + if(ArmorStandGUI.isInUse(as)) { + Utils.title(p, Config.guiInUse); + return; + } + new ArmorStandGUI(as, p); + } + }.runTaskLater(AST.plugin, 1L); + break; default: return; } @@ -226,8 +251,7 @@ class ArmorStandGUI implements Listener { @EventHandler public void onInventoryDrag(InventoryDragEvent event) { - if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player)) return; - Player p = (Player) event.getWhoClicked(); + if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player p)) return; boolean invModified = false; for(int slot : event.getRawSlots()) { if(slot < i.getSize()) { diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java index 153e491..af4c4d8 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandTool.java @@ -16,30 +16,56 @@ import java.util.UUID; public enum ArmorStandTool { - HEAD ("gui_head", Material.PLAYER_HEAD, 7, "astools.use", false), - BODY ("gui_body", Material.NETHER_BRICKS, 16, "astools.use", false), - RARM ("gui_rarm", Material.REDSTONE_TORCH, 15, "astools.use", true), - LARM ("gui_larm", Material.TORCH, 17, "astools.use", true), - RLEG ("gui_rleg", Material.BLAZE_ROD, 24, "astools.use", true), - LLEG ("gui_lleg", Material.BONE, 26, "astools.use", true), - MOVE ("gui_move", Material.FEATHER, 25, "astools.use", false), - CLONE ("gui_clone", Material.GLOWSTONE_DUST, 34, "astools.clone", false), + HEAD ("gui_head", Material.WITHER_SKELETON_SKULL, 7, "astools.use", false, false), + BODY ("gui_body", Material.NETHERITE_CHESTPLATE, 16, "astools.use", false, false), + RARM ("gui_rarm", Material.REDSTONE_TORCH, 15, "astools.use", true, false), + LARM ("gui_larm", Material.TORCH, 17, "astools.use", true, false), + RLEG ("gui_rleg", Material.BLAZE_ROD, 24, "astools.use", true, false), + LLEG ("gui_lleg", Material.BONE, 26, "astools.use", true, false), + MOVE ("gui_move", Material.FEATHER, 8, "astools.use", false, false), + + ROTATE ("gui_rotate", Material.ENDER_PEARL, 25, "astools.use", false, false), + MOVE_X ("gui_moveX", Material.ORANGE_CANDLE, 33, "astools.use", false, false), + MOVE_Y ("gui_moveY", Material.LIGHT_BLUE_CANDLE, 34, "astools.use", false, false), + MOVE_Z ("gui_moveZ", Material.LIME_CANDLE, 35, "astools.use", false, false), + + + NAME ("gui_name", Material.NAME_TAG, 3, "astools.use", false, false), + INVIS ("gui_invis", Material.GOLD_NUGGET, 4, "astools.use", false, false), + ARMS ("gui_arms", Material.ARROW, 5, "astools.use", false, false), + BASE ("gui_base", Material.STONE_SLAB, 12, "astools.use", false, false), + SIZE ("gui_size", Material.EMERALD, 14, "astools.use", false, false), + GRAV ("gui_grav", Material.GHAST_TEAR, 13, "astools.use", false, false), + INVUL ("gui_invul", Material.GLISTERING_MELON_SLICE, 21, "astools.use", false, false), + SLOTS ("gui_slots", Material.IRON_HOE, 22, "astools.use", false, false), + GLOW ("gui_glow", Material.GLOWSTONE, 23, "astools.glow", false, false), + PHEAD ("gui_pHead", Material.PLAYER_HEAD, 30, "astools.head", false, false), + SAVE ("gui_save", Material.DIAMOND, 31, "astools.cmdblock",false, false), + CLONE ("gui_clone", Material.ARMOR_STAND, 32, "astools.clone", false, false), + + ADVANCED("gui_advanced",Material.NETHER_STAR, 27, "astools.use", false, false), + + RARM_X ("gui_rArmX", Material.REDSTONE_TORCH, 36, "astools.use", false, true), + RARM_Y ("gui_rArmY", Material.REDSTONE_TORCH, 37, "astools.use", false, true), + RARM_Z ("gui_rArmZ", Material.REDSTONE_TORCH, 38, "astools.use", false, true), + LARM_X ("gui_lArmX", Material.TORCH, 39, "astools.use", false, true), + LARM_Y ("gui_lArmY", Material.TORCH, 40, "astools.use", false, true), + LARM_Z ("gui_lArmZ", Material.TORCH, 41, "astools.use", false, true), + HEAD_X ("gui_headX", Material.WITHER_SKELETON_SKULL, 42, "astools.use", false, true), + HEAD_Y ("gui_headY", Material.WITHER_SKELETON_SKULL, 43, "astools.use", false, true), + HEAD_Z ("gui_headZ", Material.WITHER_SKELETON_SKULL, 44, "astools.use", false, true), + + RLEG_X ("gui_rLegX", Material.BLAZE_ROD, 45, "astools.use", false, true), + RLEG_Y ("gui_rLegY", Material.BLAZE_ROD, 46, "astools.use", false, true), + RLEG_Z ("gui_rLegZ", Material.BLAZE_ROD, 47, "astools.use", false, true), + LLEG_X ("gui_lLegX", Material.BONE, 48, "astools.use", false, true), + LLEG_Y ("gui_lLegY", Material.BONE, 49, "astools.use", false, true), + LLEG_Z ("gui_lLegZ", Material.BONE, 50, "astools.use", false, true), + BODY_X ("gui_bodyX", Material.NETHERITE_CHESTPLATE, 51, "astools.use", false, true), + BODY_Y ("gui_bodyY", Material.NETHERITE_CHESTPLATE, 52, "astools.use", false, true), + BODY_Z ("gui_bodyZ", Material.NETHERITE_CHESTPLATE, 53, "astools.use", false, true); - UP ("gui_moveup", Material.LIGHTNING_ROD, 4, "astools.use", false), - DOWN ("gui_movedown",Material.LEVER, 13, "astools.use", false), - ROTATE ("gui_rotate", Material.ENDER_PEARL, 22, "astools.use", false), - PHEAD ("gui_pHead", Material.PLAYER_HEAD, 36, "astools.head", false), - NAME ("gui_name", Material.NAME_TAG, 45, "astools.use", false), - INVIS ("gui_invis", Material.GOLD_NUGGET, 46, "astools.use", false), - ARMS ("gui_arms", Material.ARROW, 47, "astools.use", false), - BASE ("gui_base", Material.STONE_SLAB, 48, "astools.use", false), - SIZE ("gui_size", Material.EMERALD, 49, "astools.use", false), - GRAV ("gui_grav", Material.GHAST_TEAR, 50, "astools.use", false), - INVUL ("gui_invul", Material.GLISTERING_MELON_SLICE, 51, "astools.use", false), - SLOTS ("gui_slots", Material.IRON_HOE, 52, "astools.use", false), - GLOW ("gui_glow", Material.GLOWSTONE, 53, "astools.glow", false), - SAVE ("gui_save", Material.DIAMOND, 44, "astools.cmdblock",false); private final ItemStack item; private final String config_id; @@ -47,15 +73,21 @@ public enum ArmorStandTool { private boolean enabled; private final String permission; private final boolean reverseSneaking; + private final boolean advanced; private String name; - ArmorStandTool(String config_id, Material m, int slot, String permission, boolean reverseSneaking) { + ArmorStandTool(String config_id, Material m, int slot, String permission, boolean reverseSneaking, boolean advanced) { item = new ItemStack(m); this.config_id = config_id; this.slot = slot; this.enabled = true; this.permission = permission; this.reverseSneaking = reverseSneaking; + this.advanced = advanced; + } + + boolean isAdvanced() { + return advanced; } void showTitle(Player p) { @@ -63,14 +95,20 @@ public enum ArmorStandTool { ChatColor offColor = ChatColor.WHITE; ChatColor onColor = ChatColor.YELLOW; ChatColor divColor = ChatColor.BLACK; - String msg = - (sneaking ? offColor : onColor) + - Config.normal + ": X/" + (reverseSneaking ? "Z" : "Y") + - divColor + " | " + - (sneaking ? onColor : offColor) + - Config.crouch + ": X/" + (reverseSneaking ? "Y" : "Z") + - divColor + " | " + - offColor + Config.click + ": " + Config.finish; + String msg; + if(advanced) { + msg = onColor + name + + divColor + " | " + + offColor + Config.click + ": " + Config.finish; + } else { + msg = (sneaking ? offColor : onColor) + + Config.normal + ": X/" + (reverseSneaking ? "Z" : "Y") + + divColor + " | " + + (sneaking ? onColor : offColor) + + Config.crouch + ": X/" + (reverseSneaking ? "Y" : "Z") + + divColor + " | " + + offColor + Config.click + ": " + Config.finish; + } p.sendTitle(" ", msg, 0, 600, 0); } @@ -106,52 +144,49 @@ public enum ArmorStandTool { AST.activeTool.remove(uuid); return; } - EulerAngle eulerAngle; - switch (this) { - case MOVE: - as.teleport(Utils.getLocationFacing(p.getLocation())); - Utils.title(p, Config.carrying); - return; - case HEAD: - eulerAngle = as.getHeadPose(); - break; - case BODY: - eulerAngle = as.getBodyPose(); - break; - case LARM: - eulerAngle = as.getLeftArmPose(); - break; - case RARM: - eulerAngle = as.getRightArmPose(); - break; - case LLEG: - eulerAngle = as.getLeftLegPose(); - break; - case RLEG: - eulerAngle = as.getRightLegPose(); - break; - default: - return; + if(this == MOVE) { + as.teleport(Utils.getLocationFacing(p.getLocation())); + Utils.title(p, Config.carrying); + return; } - eulerAngle = eulerAngle.setX(getPitch(p)); - boolean sneaking = reverseSneaking != p.isSneaking(); - double yaw = getRelativeYaw(p, as); - eulerAngle = sneaking ? eulerAngle.setZ(yaw) : eulerAngle.setY(yaw); showTitle(p); + EulerAngle eulerAngle = switch (this) { + case HEAD, HEAD_X, HEAD_Y, HEAD_Z -> as.getHeadPose(); + case BODY, BODY_X, BODY_Y, BODY_Z -> as.getBodyPose(); + case LARM, LARM_X, LARM_Y, LARM_Z -> as.getLeftArmPose(); + case RARM, RARM_X, RARM_Y, RARM_Z -> as.getRightArmPose(); + case LLEG, LLEG_X, LLEG_Y, LLEG_Z -> as.getLeftLegPose(); + case RLEG, RLEG_X, RLEG_Y, RLEG_Z -> as.getRightLegPose(); + default -> null; + }; + if(eulerAngle == null) return; + if(advanced) { + eulerAngle = switch (this) { + case HEAD_X, BODY_X, LARM_X, RARM_X, LLEG_X, RLEG_X -> eulerAngle.setX(getPitch(p, 8)); + case HEAD_Y, BODY_Y, LARM_Y, RARM_Y, LLEG_Y, RLEG_Y -> eulerAngle.setY(getPitch(p, 8)); + case HEAD_Z, BODY_Z, LARM_Z, RARM_Z, LLEG_Z, RLEG_Z -> eulerAngle.setZ(getPitch(p, 8)); + default -> eulerAngle; + }; + } else { + eulerAngle = eulerAngle.setX(getPitch(p, 4)); + boolean sneaking = reverseSneaking != p.isSneaking(); + double yaw = getRelativeYaw(p, as); + eulerAngle = sneaking ? eulerAngle.setZ(yaw) : eulerAngle.setY(yaw); + } switch (this) { - case HEAD -> as.setHeadPose(eulerAngle); - case BODY -> as.setBodyPose(eulerAngle); - case LARM -> as.setLeftArmPose(eulerAngle); - case RARM -> as.setRightArmPose(eulerAngle); - case LLEG -> as.setLeftLegPose(eulerAngle); - case RLEG -> as.setRightLegPose(eulerAngle); + case HEAD, HEAD_X, HEAD_Y, HEAD_Z -> as.setHeadPose(eulerAngle); + case BODY, BODY_X, BODY_Y, BODY_Z -> as.setBodyPose(eulerAngle); + case LARM, LARM_X, LARM_Y, LARM_Z -> as.setLeftArmPose(eulerAngle); + case RARM, RARM_X, RARM_Y, RARM_Z -> as.setRightArmPose(eulerAngle); + case LLEG, LLEG_X, LLEG_Y, LLEG_Z -> as.setLeftLegPose(eulerAngle); + case RLEG, RLEG_X, RLEG_Y, RLEG_Z -> as.setRightLegPose(eulerAngle); } } // Get pitch and format as 0 to 2pi radians - // Actual pitch quadrupled for increased sensitivity - private double getPitch(Player p) { - double pitch = p.getLocation().getPitch() * 4; + // Actual pitch multiplied for increased sensitivity + private double getPitch(Player p, int multiplier) { + double pitch = p.getLocation().getPitch() * multiplier; while(pitch < 0) { pitch += 360; } @@ -214,8 +249,7 @@ public enum ArmorStandTool { private String plrHeadName(ArmorStand as) { EntityEquipment entityEquipment = as.getEquipment(); - if(entityEquipment == null || entityEquipment.getHelmet() == null || !(entityEquipment.getHelmet().getItemMeta() instanceof SkullMeta)) return null; - SkullMeta meta = (SkullMeta) entityEquipment.getHelmet().getItemMeta(); + if(entityEquipment == null || entityEquipment.getHelmet() == null || !(entityEquipment.getHelmet().getItemMeta() instanceof SkullMeta meta)) return null; if(meta.getOwningPlayer() == null) return null; return meta.getOwningPlayer().getName(); } diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java index bcd26fb..c6262cd 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Commands.java @@ -20,12 +20,11 @@ class Commands implements CommandExecutor, TabCompleter { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - if (!(sender instanceof Player)) { + if (!(sender instanceof Player p)) { AST.plugin.getLogger().warning(Config.notConsole); return false; } String cmd = command.getName().toLowerCase(); - Player p = (Player) sender; if(cmd.equals("astools") || cmd.equals("ast")) { if (!Utils.hasPermissionNode(p, "astools.use")) { p.sendMessage(ChatColor.RED + Config.noCommandPerm); @@ -45,6 +44,14 @@ class Commands implements CommandExecutor, TabCompleter { ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); AST.pickUpArmorStand(as, p); Utils.title(p, Config.carrying); + } else if (args[0].equalsIgnoreCase("reload")) { + if (Utils.hasPermissionNode(p, "astools.reload")) { + Config.reload(null); + p.sendMessage(ChatColor.GREEN + Config.reloaded); + } else { + p.sendMessage(ChatColor.RED + Config.noCommandPerm); + } + return true; } p.sendMessage(ChatColor.AQUA + Config.instructions1 + ChatColor.GREEN + " /ast new " + ChatColor.AQUA + Config.instructions2); return true; diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java index 89029ee..7756e32 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Config.java @@ -39,10 +39,10 @@ class Config { cooldownRemovedFrom, isAnInvalidCooldown, cooldownSetTo, ticksFor, setCooldown, glow, removeCooldown, instructions1, instructions2, - crouch, click, finish, error; + crouch, click, finish, error, reloaded; static void reload(AST main) { - plugin = main; + if(main != null) plugin = main; reloadMainConfig(); saveDefaultLanguageConfig(); reloadLanguageConfig(); @@ -55,7 +55,7 @@ class Config { FileConfiguration config = plugin.getConfig(); allowMoveWorld = config.getBoolean("allowMovingStandsBetweenWorlds"); requireCreative = config.getBoolean("requireCreativeForSaveAsCmdBlock"); - defaultASCmdCooldownTicks = config.getInt("defaultASCmdCooldownTicks"); + defaultASCmdCooldownTicks = config.getInt( "defaultASCmdCooldownTicks"); ignoreWGForASCmdExecution = config.getBoolean("bypassWorldguardForASCmdExecution"); debug = config.getBoolean("showDebugMessages", false); @@ -165,6 +165,7 @@ class Config { click = languageConfig.getString("click"); finish = languageConfig.getString("finish"); error = languageConfig.getString("error"); + reloaded = languageConfig.getString("reloaded"); } } diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index 2cf12ad..d7c11cb 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -33,22 +33,16 @@ public class MainListener implements Listener { @EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { Player p = event.getPlayer(); - if(stopEditing(p, false)) { - event.setCancelled(true); - AST.debug("Interaction cancelled as player is already editing"); - } - if(!(event.getRightClicked() instanceof ArmorStand)) return; - ArmorStand as = (ArmorStand) event.getRightClicked(); - AST.debug(p.getName() + " right-clicked " + as.getName() + ", Crouching: " + p.isSneaking()); - if(event.isCancelled()) { - AST.debug("Interaction with Armor Stand was cancelled by a plugin"); - } - if(!event.isCancelled() && ArmorStandGUI.isInUse(as)) { - Utils.title(p, Config.guiInUse); - event.setCancelled(true); - return; - } - if(!event.isCancelled() && p.isSneaking()) { + if(!(event.getRightClicked() instanceof ArmorStand as)) return; + boolean hasAstPerm = Utils.hasPermissionNode(p, "astools.use"); + AST.debug(p.getName() + " right-clicked " + as.getName() + ", Crouching: " + p.isSneaking() + ", Has astools.use perm: " + hasAstPerm); + if(p.isSneaking() && hasAstPerm) { + if (ArmorStandGUI.isInUse(as)) { + Utils.title(p, Config.guiInUse); + event.setCancelled(true); + AST.debug("Interaction cancelled as Armor Stand GUI is in use"); + return; + } if (!AST.playerHasPermission(p, as.getLocation().getBlock(), null)) { p.sendMessage(ChatColor.RED + Config.generalNoPerm); return; @@ -130,8 +124,7 @@ public class MainListener implements Listener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if(event.getEntity() instanceof ArmorStand) { - ArmorStand as = (ArmorStand) event.getEntity(); + if(event.getEntity() instanceof ArmorStand as) { if(event.getDamager() instanceof Player && stopEditing((Player) event.getDamager(), false)) { event.setCancelled(true); return; @@ -144,8 +137,7 @@ public class MainListener implements Listener { @EventHandler public void onEntityDamage(EntityDamageEvent event) { - if(event.getEntity() instanceof ArmorStand) { - ArmorStand as = (ArmorStand) event.getEntity(); + if(event.getEntity() instanceof ArmorStand as) { if(ArmorStandGUI.isInUse(as) || as.isInvulnerable()) { event.setCancelled(true); } diff --git a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java index d4a5bbe..7a97a02 100644 --- a/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java +++ b/src/main/java/com/gmail/St3venAU/plugins/ArmorStandTools/Utils.java @@ -188,8 +188,7 @@ class Utils { return ""; } StringBuilder tags = new StringBuilder(); - if(is.getItemMeta() != null && is.getItemMeta() instanceof LeatherArmorMeta) { - LeatherArmorMeta armorMeta = (LeatherArmorMeta) is.getItemMeta(); + if(is.getItemMeta() != null && is.getItemMeta() instanceof LeatherArmorMeta armorMeta) { tags.append("display:{color:"); tags.append(armorMeta.getColor().asRGB()); tags.append("}"); @@ -215,9 +214,8 @@ class Utils { } static private String skullOwner(ItemStack is) { - if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta)) return ""; - SkullMeta skull = (SkullMeta) is.getItemMeta(); - return skull.getOwningPlayer() == null ? "" : "SkullOwner:\"" + skull.getOwningPlayer().getName() + "\""; + if(is == null || is.getItemMeta() == null || !(is.getItemMeta() instanceof SkullMeta skull)) return ""; + return skull.getOwningPlayer() == null ? "" : "SkullOwner:\"" + skull.getOwningPlayer().getName() + "\""; } static private boolean isEmpty(ItemStack is) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d83efb6..2e3e8b3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -27,6 +27,8 @@ # /ascmd cooldown Set the cooldown for the command on nearest armor stand (Setting this overrides the default cooldown from config.yml) # /ascmd cooldown remove Remove the cooldown for the command on nearest armor stand (Default cooldown set in config.yml will be used) # /astools or /ast Legacy command - now gives instructions for player to crouch right-click an armor stand +# /astools new Create a new armor stand - will spawn being carried by the player +# /astools reload Reload the plugin (use when changing config files) # Note: Armor stand commands may include a %player% placeholder, which will get replaced by the executing player's name at time of execution. # # Permissions: @@ -36,6 +38,7 @@ # astools.summon Permission to use the summon tool (Summons an armor stand without requiring the materials) # astools.head Permission to use the player head tool (Ability to specify a player head for an armor stand) # astools.cmdblock Permission to use the save tool (Creates a command block) +# astools.reload Permission to reload the plugin # astools.ascmd.assign.console Permission to assign a console command to an armor stand # astools.ascmd.assign.player Permission to assign a player command to an armor stand # astools.ascmd.remove Permission to remove a command from an armor stand @@ -71,13 +74,33 @@ enableTool: gui_pHead: true gui_invul: true gui_move: true - gui_moveup: true - gui_movedown: true gui_rotate: true + gui_moveX: true + gui_moveY: true + gui_moveZ: true gui_glow: true gui_head: true gui_body: true gui_larm: true gui_rarm: true gui_lleg: true - gui_rleg: true \ No newline at end of file + gui_rleg: true + gui_advanced: true + gui_lArmX: true + gui_lArmY: true + gui_lArmZ: true + gui_rArmX: true + gui_rArmY: true + gui_rArmZ: true + gui_headX: true + gui_headY: true + gui_headZ: true + gui_lLegX: true + gui_lLegY: true + gui_lLegZ: true + gui_rLegX: true + gui_rLegY: true + gui_rLegZ: true + gui_bodyX: true + gui_bodyY: true + gui_bodyZ: true diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 81b580b..c46a898 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -91,6 +91,8 @@ finish: 'Finish' instructions1: 'Crouch + right-click an armor stand to edit, or use command' instructions2: 'to summon a new armor stand' error: 'An error occured. Try again.' +#New since v4.1.0 +reloaded : 'Armor Stand Tools reloaded' # ############################# # Tool names & descriptions # @@ -100,18 +102,6 @@ tool: name: 'Pick Up (Move)' lore: - 'Pick up this armor stand to move it' - gui_moveup: - name: 'Move Up' - lore: - - 'Left click: Move up 0.1 block' - - 'Right click: Move up 1 block' - - '(Automatically disables gravity)' - gui_movedown: - name: 'Move Down' - lore: - - 'Left click: Move down 0.1 block' - - 'Right click: Move down 1 block' - - '(Automatically disables gravity)' gui_rotate: name: 'Rotate' lore: @@ -173,4 +163,96 @@ tool: lore: 'Change the left leg position' gui_rleg: name: 'Move Right Leg' - lore: 'Change the right leg position' \ No newline at end of file + lore: 'Change the right leg position' + gui_moveX: + name: 'Move X (East/West)' + lore: + - 'Left click: Move East (+0.1 X)' + - 'Right click: Move West (-0.1 X)' + - '(Automatically disables gravity)' + gui_moveY: + name: 'Move Y (Up/Down)' + lore: + - 'Left click: Move Up (+0.1 Y)' + - 'Right click: Move Down (-0.1 Y)' + - '(Automatically disables gravity)' + gui_moveZ: + name: 'Move Z (South/North)' + lore: + - 'Left click: Move South (+0.1 Z)' + - 'Right click: Move North (-0.1 Z)' + - '(Automatically disables gravity)' + gui_advanced: + name: 'Show/Hide Advanced Tools' + gui_headX: + name: 'Head X' + lore: + - 'Change head X position' + gui_headY: + name: 'Head Y' + lore: + - 'Change head Y position' + gui_headZ: + name: 'Head Z' + lore: + - 'Change head Z position' + gui_lArmX: + name: 'Left Arm X' + lore: + - 'Change left arm X position' + gui_lArmY: + name: 'Left Arm Y' + lore: + - 'Change left arm Y Position' + gui_lArmZ: + name: 'Left Arm Z' + lore: + - 'Change left arm Z Position' + gui_rArmX: + name: 'Right Arm X' + lore: + - 'Change right arm X position' + gui_rArmY: + name: 'Right Arm Y' + lore: + - 'Change right arm Y position' + gui_rArmZ: + name: 'Right Arm Z' + lore: + - 'Change right arm Z position' + gui_lLegX: + name: 'Left Leg X' + lore: + - 'Change left leg X position' + gui_lLegY: + name: 'Left Leg Y' + lore: + - 'Change left leg Y position' + gui_lLegZ: + name: 'Left Leg Z' + lore: + - 'Change left leg Z position' + gui_rLegX: + name: 'Right Leg X' + lore: + - 'Change right leg X position' + gui_rLegY: + name: 'Right Leg Y' + lore: + - 'Change right leg Y position' + gui_rLegZ: + name: 'Right Leg Z' + lore: + - 'Change right leg Z position' + gui_bodyX: + name: 'Body X' + lore: + - 'Change body X position' + gui_bodyY: + name: 'Body Y' + lore: + - 'Change body Y position' + gui_bodyZ: + name: 'Body Z' + lore: + - 'Change body Z position' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9a49e15..00552fc 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,7 +9,7 @@ commands: astools: description: Provides player instructions on how to use AST aliases: ast - usage: Usage /astools or /ast, /ast new + usage: Usage /astools or /ast, /ast new, /ast reload ascmd: description: View/Remove/Assign the command assigned to the nearest armor stand usage: Usage /ascmd view, /ascmd remove, /ascmd assign \ No newline at end of file