diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java index 1727343e..9f611382 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/ArmorStandEditorPlugin.java @@ -27,6 +27,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.entity.ArmorStand; +import org.bukkit.persistence.PersistentDataType; import java.io.File; @@ -46,6 +48,7 @@ public class ArmorStandEditorPlugin extends JavaPlugin{ boolean debug = false; //weather or not to broadcast messages via print(String message) double coarseRot; double fineRot; + private NamespacedKey lockedKey; public ArmorStandEditorPlugin(){ instance = this; @@ -146,11 +149,21 @@ public boolean isEditTool(ItemStack item){ } return true; } + + public boolean isLocked(ArmorStand armorStand) { + return armorStand.getPersistentDataContainer().has(this.getLockedKey(), PersistentDataType.BYTE); + } public NamespacedKey getIconKey() { if(iconKey == null) iconKey = new NamespacedKey(this, "command_icon"); return iconKey; } + + public NamespacedKey getLockedKey() { + if (lockedKey == null) lockedKey = new NamespacedKey(this, "locked"); + return lockedKey; + } + } //todo: //Access to "DisabledSlots" data (probably simplified just a toggle enable/disable) diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java index 82b565dd..bbdf7f2f 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditor.java @@ -35,8 +35,10 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataType; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.EulerAngle; @@ -102,6 +104,19 @@ public void setCopySlot(byte slot){ public void editArmorStand(ArmorStand armorStand) { if(!getPlayer().hasPermission("asedit.basic")) return; armorStand = attemptTarget(armorStand); + + switch(eMode){ + case LOCK: toggleLock(armorStand); + return; + case COPY: copy(armorStand); + return; + } + + if (plugin.isLocked(armorStand)) { + sendLockedMessage(getPlayer(), armorStand); + return; + } + switch(eMode){ case LEFTARM: armorStand.setLeftArmPose(subEulerAngle(armorStand.getLeftArmPose())); break; @@ -125,8 +140,6 @@ public void editArmorStand(ArmorStand armorStand) { break; case GRAVITY: toggleGravity(armorStand); break; - case COPY: copy(armorStand); - break; case PASTE: paste(armorStand); break; case PLACEMENT: move(armorStand); @@ -160,6 +173,19 @@ private void openEquipment(ArmorStand armorStand) { public void reverseEditArmorStand(ArmorStand armorStand){ if(!getPlayer().hasPermission("asedit.basic")) return; armorStand = attemptTarget(armorStand); + + switch(eMode){ + case LOCK: toggleLock(armorStand); + return; + case COPY: copy(armorStand); + return; + } + + if (plugin.isLocked(armorStand)) { + sendLockedMessage(getPlayer(), armorStand); + return; + } + switch(eMode){ case LEFTARM: armorStand.setLeftArmPose(addEulerAngle(armorStand.getLeftArmPose())); break; @@ -289,6 +315,19 @@ void cycleAxis(int i) { setAxis(Axis.values()[index]); } + void toggleLock(ArmorStand armorStand){ + if (plugin.isLocked(armorStand)) { + armorStand.getPersistentDataContainer().remove(plugin.getLockedKey()); + sendMessage("setlock", "unlocked"); + getPlayer().playSound(armorStand.getLocation(), Sound.BLOCK_CHEST_OPEN, 1, 1); + } + else { + armorStand.getPersistentDataContainer().set(plugin.getLockedKey(), PersistentDataType.BYTE, (byte)1); + sendMessage("setlock", "locked"); + getPlayer().playSound(armorStand.getLocation(), Sound.BLOCK_CHEST_CLOSE, 1, 1); + } + } + private EulerAngle addEulerAngle(EulerAngle angle) { switch(axis){ case X: angle = angle.setX(Util.addAngle(angle.getX(), eulerAngleChange)); @@ -377,6 +416,11 @@ void sendMessage(String path, String format, String option){ void sendMessage(String path, String option){ sendMessage(path, "info", option); } + + void sendLockedMessage (Player player, ArmorStand armorStand) { + sendMessage("locked", null); + getPlayer().playSound(armorStand.getLocation(), Sound.BLOCK_CHEST_LOCKED, 1, 1); + } private void highlight(ArmorStand armorStand){ armorStand.removePotionEffect(PotionEffectType.GLOWING); diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java index 27b2e4ca..c25f4a47 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/PlayerEditorManager.java @@ -106,7 +106,18 @@ void onArmorStandInteract(PlayerInteractAtEntityEvent event){ } else { name = null; } - + + if (plugin.isLocked(as)) { + event.setCancelled(true); + String asName = as.getCustomName(); + boolean asNameVisible = as.isCustomNameVisible(); + Bukkit.getScheduler().runTaskLater(plugin, () -> { + as.setCustomName(asName); + as.setCustomNameVisible(asNameVisible); + }, 1); + return; + } + if(name == null){ as.setCustomName(null); as.setCustomNameVisible(false); diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/menu/Menu.java b/src/main/java/io/github/rypofalem/armorstandeditor/menu/Menu.java index d20a48c3..007649b9 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/menu/Menu.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/menu/Menu.java @@ -52,7 +52,7 @@ private void fillInventory() { ItemStack xAxis= null, yAxis= null, zAxis= null, coarseAdj= null, fineAdj= null, rotate = null, place = null, headPos= null, rightArmPos= null, bodyPos= null, leftArmPos= null, reset = null, showArms= null, visibility= null, size= null, rightLegPos= null, equipment = null, leftLegPos= null, disableSlots = null, gravity= null, plate= null, copy= null, paste= null, - slot1= null, slot2= null, slot3= null, slot4= null, help= null; + slot1= null, slot2= null, slot3= null, slot4= null, help= null, lock = null; xAxis = createIcon(new ItemStack(Material.RED_WOOL, 1), "xaxis", "axis x"); @@ -112,6 +112,8 @@ private void fillInventory() { disableSlots = createIcon(new ItemStack(Material.BARRIER), "disableslots", "mode disableslots"); } + lock = createIcon( new ItemStack(Material.TRIPWIRE_HOOK), "lock", "mode lock"); + gravity = createIcon( new ItemStack(Material.SAND), "gravity", "mode gravity"); plate = createIcon( new ItemStack(Material.STONE_SLAB, 1), @@ -151,7 +153,7 @@ private void fillInventory() { xAxis, yAxis, zAxis, null, coarseAdj, fineAdj, null, rotate, place, null, headPos, null, null, null, null, null, null, null, rightArmPos, bodyPos, leftArmPos, reset, null, null, showArms, visibility, size, - rightLegPos, equipment, leftLegPos, null, null, null, null, gravity, plate, + rightLegPos, equipment, leftLegPos, null, null, null, lock, gravity, plate, null, copy, paste, null, null, null, null, null, null, slot1, slot2, slot3, slot4, null, null, null, null, help }; diff --git a/src/main/java/io/github/rypofalem/armorstandeditor/modes/EditMode.java b/src/main/java/io/github/rypofalem/armorstandeditor/modes/EditMode.java index da6d38c2..aadbfacb 100644 --- a/src/main/java/io/github/rypofalem/armorstandeditor/modes/EditMode.java +++ b/src/main/java/io/github/rypofalem/armorstandeditor/modes/EditMode.java @@ -22,7 +22,7 @@ public enum EditMode { NONE("None"), INVISIBLE("Invisible"), SHOWARMS("ShowArms"), GRAVITY("Gravity"), BASEPLATE("BasePlate"), SIZE("Size"), COPY("Copy"), PASTE("Paste"), HEAD("Head"), BODY("Body"), LEFTARM("LeftArm"), RIGHTARM("RightArm"), LEFTLEG("LeftLeg"), RIGHTLEG("RightLeg"), - PLACEMENT("Placement"), DISABLESLOTS("DisableSlots"), ROTATE("Rotate"), EQUIPMENT("Equipment"), RESET("Reset"); + PLACEMENT("Placement"), DISABLESLOTS("DisableSlots"), ROTATE("Rotate"), EQUIPMENT("Equipment"), RESET("Reset"), LOCK("Lock"); private String name; diff --git a/src/main/resources/lang/en_US.yml b/src/main/resources/lang/en_US.yml index 1fffc8bd..e099905c 100644 --- a/src/main/resources/lang/en_US.yml +++ b/src/main/resources/lang/en_US.yml @@ -57,6 +57,10 @@ target: msg: ArmorStand target locked. notarget: msg: ArmorStand target unlocked. +setlock: + msg: This Armor Stand is now + locked: locked + unlocked: unlocked help: msg: "1. Hold the editing tool() in your main hand @@ -91,7 +95,9 @@ noaxiscom: msg: You must specify an Axis! nomodecom: msg: You must specify a Mode! - +locked: + msg: This armor stand is locked! + #menutitle mainmenutitle: msg: Armor Stand Editor Menu @@ -199,6 +205,10 @@ helpgui: msg: Help! description: msg: Click here to get help! +lock: + msg: Lock + description: + msg: Prevent the armorstand from being edited #icons (equipment menu) disabled: