From 6d78b656de7fcdb4d4ef48975a599e53e3c26d70 Mon Sep 17 00:00:00 2001 From: dragontamerfred Date: Wed, 2 Oct 2019 19:49:30 +0200 Subject: [PATCH] Add armor stand swapping --- README.md | 4 ++- .../ArmorStandSwappingHandler.java | 35 +++++++++++++++++++ .../vanillatweaks/VanillaTweaks.java | 9 +++-- .../nl/kallestruik/vanillatweaks/config.java | 8 ++--- src/main/resources/config.yml | 3 ++ 5 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java diff --git a/README.md b/README.md index 671a390..ef7a564 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,12 @@ Works for: - Melon - Pumpkin +### Armor stand swapping +Allow players to shift right-click on any armor stand to swap armor with it. + ## Planned tweaks - Dynamite - Sign editing -- Armor stand swapping - Nether sponge drying diff --git a/src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java b/src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java new file mode 100644 index 0000000..671384a --- /dev/null +++ b/src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java @@ -0,0 +1,35 @@ +package nl.kallestruik.vanillatweaks.ArmorStandSwapping; + +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.inventory.EntityEquipment; + +public class ArmorStandSwappingHandler implements Listener { + + @EventHandler + public void onClickEntity(PlayerInteractAtEntityEvent event) { + if (event.getPlayer().isSneaking()) { + if (event.getRightClicked() instanceof ArmorStand) { + ArmorStand armorStand = ((ArmorStand) event.getRightClicked()); + EntityEquipment standEquipment = armorStand.getEquipment(); + Player player = event.getPlayer(); + EntityEquipment playerEquipment = player.getEquipment(); + + if (standEquipment != null && playerEquipment != null) { + armorStand.setHelmet(playerEquipment.getHelmet()); + armorStand.setChestplate(playerEquipment.getChestplate()); + armorStand.setLeggings(playerEquipment.getLeggings()); + armorStand.setBoots(playerEquipment.getBoots()); + + player.getInventory().setArmorContents(standEquipment.getArmorContents()); + } + + event.setCancelled(true); + + } + } + } +} diff --git a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java index 49169e3..8f3861e 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java @@ -1,5 +1,6 @@ package nl.kallestruik.vanillatweaks; +import nl.kallestruik.vanillatweaks.ArmorStandSwapping.ArmorStandSwappingHandler; import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks; import nl.kallestruik.vanillatweaks.SeedDropPlanting.SeedDropPlanting; import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample; @@ -43,11 +44,9 @@ public final class VanillaTweaks extends JavaPlugin { * Shift right-click on a sign to edit it. */ - /** - * Armour stand swap - * - * Shift right-click on armour stand to swap armour with it. - */ + if (config.ARMOR_STAND_SWAPPING_ENABLED) { + getServer().getPluginManager().registerEvents(new ArmorStandSwappingHandler(), this); + } /** * Sponges in nether dry instantly diff --git a/src/main/java/nl/kallestruik/vanillatweaks/config.java b/src/main/java/nl/kallestruik/vanillatweaks/config.java index d28e7c4..02899ee 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/config.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/config.java @@ -18,6 +18,8 @@ public class config { public static boolean SEED_DROP_PLANTING_ENABLED; + public static boolean ARMOR_STAND_SWAPPING_ENABLED; + public static void load(File file) throws IOException, InvalidConfigurationException { if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); @@ -34,10 +36,8 @@ public class config { CRAFTING_TWEAKS_WOOL_TO_STRING = config.getBoolean("crafting-tweaks.wool-to-string"); CRAFTING_TWEAKS_SADDLE = config.getBoolean("crafting-tweaks.saddle"); + SEED_DROP_PLANTING_ENABLED = config.getBoolean("seed-drop-planting.enabled"); - - - - + ARMOR_STAND_SWAPPING_ENABLED = config.getBoolean("armor-stand-swapping.enabled"); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 149b254..0684e02 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,4 +9,7 @@ crafting-tweaks: saddle: true seed-drop-planting: + enabled: true + +armor-stand-swapping: enabled: true \ No newline at end of file