From 4a1793b2e182f3a38c616b036a7d80088d11c908 Mon Sep 17 00:00:00 2001 From: dragontamerfred Date: Thu, 3 Oct 2019 17:41:20 +0200 Subject: [PATCH] Add nether sponge drying. Fix bug with armor stand swapping. Fix bug with seed drop planting. --- README.md | 4 +++- .../ArmorStandSwappingHandler.java | 19 +++++++++++---- .../NetherSpongeHandler.java | 21 ++++++++++++++++ .../SeedDropPlanting/SeedDropPlanting.java | 24 ++++++++++++------- .../vanillatweaks/VanillaTweaks.java | 16 ++++--------- .../nl/kallestruik/vanillatweaks/config.java | 4 ++++ .../nl/kallestruik/vanillatweaks/util.java | 2 +- src/main/resources/config.yml | 3 +++ src/main/resources/plugin.yml | 2 +- 9 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 src/main/java/nl/kallestruik/vanillatweaks/NetherSpongeDrying/NetherSpongeHandler.java diff --git a/README.md b/README.md index ef7a564..58c3ad0 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,11 @@ Works for: ### Armor stand swapping Allow players to shift right-click on any armor stand to swap armor with it. +### Nether sponge drying +Instantly dry wet sponges when they are placed in the nether. + ## Planned tweaks - Dynamite - Sign editing -- 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 index 671384a..a294fd2 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/ArmorStandSwapping/ArmorStandSwappingHandler.java @@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.ItemStack; public class ArmorStandSwappingHandler implements Listener { @@ -19,12 +20,20 @@ public class ArmorStandSwappingHandler implements Listener { 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()); + ItemStack playerHelmet = playerEquipment.getHelmet(); + ItemStack playerChestpalte = playerEquipment.getChestplate(); + ItemStack playerLeggings = playerEquipment.getLeggings(); + ItemStack playerBoots = playerEquipment.getBoots(); - player.getInventory().setArmorContents(standEquipment.getArmorContents()); + player.getInventory().setHelmet(standEquipment.getHelmet()); + player.getInventory().setChestplate(standEquipment.getChestplate()); + player.getInventory().setLeggings(standEquipment.getLeggings()); + player.getInventory().setBoots(standEquipment.getBoots()); + + armorStand.setHelmet(playerHelmet); + armorStand.setChestplate(playerChestpalte); + armorStand.setLeggings(playerLeggings); + armorStand.setBoots(playerBoots); } event.setCancelled(true); diff --git a/src/main/java/nl/kallestruik/vanillatweaks/NetherSpongeDrying/NetherSpongeHandler.java b/src/main/java/nl/kallestruik/vanillatweaks/NetherSpongeDrying/NetherSpongeHandler.java new file mode 100644 index 0000000..37d9085 --- /dev/null +++ b/src/main/java/nl/kallestruik/vanillatweaks/NetherSpongeDrying/NetherSpongeHandler.java @@ -0,0 +1,21 @@ +package nl.kallestruik.vanillatweaks.NetherSpongeDrying; + +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; + +public class NetherSpongeHandler implements Listener { + + @EventHandler + public void onSpongePlaced(BlockPlaceEvent event) { + Block block = event.getBlockPlaced(); + if (block.getType() == Material.WET_SPONGE && + block.getWorld().getEnvironment() == World.Environment.NETHER) { + block.setType(Material.SPONGE); + block.getWorld().spawnParticle(Particle.CAMPFIRE_COSY_SMOKE, block.getLocation(), 3); + block.getWorld().playEffect(block.getLocation(), Effect.EXTINGUISH, 1, 10); + } + } +} diff --git a/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java b/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java index e912be7..288a3a1 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/SeedDropPlanting/SeedDropPlanting.java @@ -10,38 +10,44 @@ import org.bukkit.plugin.java.JavaPlugin; public class SeedDropPlanting { public static void init(JavaPlugin plugin) { - Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> { + Bukkit.getScheduler().runTaskTimer(plugin, () -> { for (World world : plugin.getServer().getWorlds()) { for (Entity entity : world.getEntities()) { if (entity instanceof Item) { Item item = ((Item) entity); Block b = world.getBlockAt(item.getLocation()); - Block below = world.getBlockAt(item.getLocation().add(0, -1, 0)); - if (b.getType() == Material.AIR && below.getType() == Material.FARMLAND) { + Block above = world.getBlockAt(item.getLocation().add(0, 1, 0)); + if (b.getType() == Material.FARMLAND && above.getType() == Material.AIR) { switch (item.getItemStack().getType()) { case WHEAT_SEEDS: - b.setType(Material.WHEAT); + above.setType(Material.WHEAT); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; case BEETROOT_SEEDS: - b.setType(Material.BEETROOT); + above.setType(Material.BEETROOTS); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; case MELON_SEEDS: - b.setType(Material.MELON_STEM); + above.setType(Material.MELON_STEM); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; case PUMPKIN_SEEDS: - b.setType(Material.PUMPKIN_STEM); + above.setType(Material.PUMPKIN_STEM); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; case POTATO: - b.setType(Material.POTATOES); + above.setType(Material.POTATOES); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; case CARROT: - b.setType(Material.CARROTS); + above.setType(Material.CARROTS); world.spawnParticle(Particle.VILLAGER_HAPPY, item.getLocation(), 10); + entity.remove(); break; } } diff --git a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java index 8f3861e..48d71a0 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/VanillaTweaks.java @@ -2,6 +2,7 @@ package nl.kallestruik.vanillatweaks; import nl.kallestruik.vanillatweaks.ArmorStandSwapping.ArmorStandSwappingHandler; import nl.kallestruik.vanillatweaks.CraftingTweaks.CraftingTweaks; +import nl.kallestruik.vanillatweaks.NetherSpongeDrying.NetherSpongeHandler; import nl.kallestruik.vanillatweaks.SeedDropPlanting.SeedDropPlanting; import nl.kallestruik.vanillatweaks.ToggleTrample.CommandToggletrample; import nl.kallestruik.vanillatweaks.ToggleTrample.TrampleHandler; @@ -38,22 +39,13 @@ public final class VanillaTweaks extends JavaPlugin { SeedDropPlanting.init(this); } - /** - * Sign editing - * - * Shift right-click on a sign to edit it. - */ - if (config.ARMOR_STAND_SWAPPING_ENABLED) { getServer().getPluginManager().registerEvents(new ArmorStandSwappingHandler(), this); } - /** - * Sponges in nether dry instantly - * - * Kind of what is says. - */ - + if (config.NETHER_SPONGE_DRYING_ENABLED) { + getServer().getPluginManager().registerEvents(new NetherSpongeHandler(), this); + } } catch (IOException | InvalidConfigurationException | NullPointerException e) { util.printException(e); diff --git a/src/main/java/nl/kallestruik/vanillatweaks/config.java b/src/main/java/nl/kallestruik/vanillatweaks/config.java index 02899ee..0a179ea 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/config.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/config.java @@ -20,6 +20,8 @@ public class config { public static boolean ARMOR_STAND_SWAPPING_ENABLED; + public static boolean NETHER_SPONGE_DRYING_ENABLED; + public static void load(File file) throws IOException, InvalidConfigurationException { if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); @@ -39,5 +41,7 @@ public class config { SEED_DROP_PLANTING_ENABLED = config.getBoolean("seed-drop-planting.enabled"); ARMOR_STAND_SWAPPING_ENABLED = config.getBoolean("armor-stand-swapping.enabled"); + + NETHER_SPONGE_DRYING_ENABLED = config.getBoolean("nether-sponge-drying.enabled"); } } diff --git a/src/main/java/nl/kallestruik/vanillatweaks/util.java b/src/main/java/nl/kallestruik/vanillatweaks/util.java index 597dd9f..d07ceea 100644 --- a/src/main/java/nl/kallestruik/vanillatweaks/util.java +++ b/src/main/java/nl/kallestruik/vanillatweaks/util.java @@ -15,7 +15,7 @@ public class util { } public static void ExportResource(String resourceName, File output) { - try (InputStream stream = VanillaTweaks.class.getResourceAsStream(resourceName); OutputStream resStreamOut = new FileOutputStream(output)) { + try (InputStream stream = VanillaTweaks.class.getResourceAsStream("/" + resourceName); OutputStream resStreamOut = new FileOutputStream(output)) { if (stream == null) { throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0684e02..2460a0f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,4 +12,7 @@ seed-drop-planting: enabled: true armor-stand-swapping: + enabled: true + +nether-sponge-drying: enabled: true \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e3f384b..dce510f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,4 +3,4 @@ version: @version@ main: nl.kallestruik.vanillatweaks.VanillaTweaks api-version: 1.13 commands: - toggeltrample: + toggletrample: