QUOTE: Enjoy small things, cherish moments.

Added cauldron module and fixed player interact bug - poppy - A feature-rich Minecraft plugin which enhances gaming experience

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://192.168.2.2/poppy
Log | Files | Refs | README

commit fda176b55b0474e543a05b0670158fcb753691e4
parent 98cbe37c6166dfdaa1aad2c1f4bdacdb71065bc1
Author: chunksize <reisingerluca@gmail.com>
Date:   Fri, 13 Jan 2023 00:38:16 +0100

Added cauldron module and fixed player interact bug

Diffstat:
Agradle.properties | 2++
Msrc/poppy/Config.java | 4+---
Msrc/poppy/Main.java | 26+++++++++-----------------
Msrc/poppy/Utils.java | 4----
Asrc/poppy/modules/CauldronModule.java | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/poppy/modules/ChairModule.java | 1-
Msrc/poppy/modules/CommonModule.java | 33+++++++++++++++------------------
Msrc/poppy/modules/DoubleDoorModule.java | 13++++++++++++-
8 files changed, 107 insertions(+), 44 deletions(-)

diff --git a/gradle.properties b/gradle.properties @@ -0,0 +1 @@ +org.gradle.console = plain +\ No newline at end of file diff --git a/src/poppy/Config.java b/src/poppy/Config.java @@ -10,8 +10,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.Location; -import poppy.Utils; - public class Config { private File file; @@ -69,7 +67,7 @@ public class Config try { this.configuration.load(this.file); - pages = (List<String>) this.configuration.getList(path); + pages = this.configuration.getStringList(path); } catch(Exception ex) { diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -1,34 +1,22 @@ package poppy; -import java.io.File; -import java.io.IOException; -import java.net.BindException; -import java.net.ServerSocket; -import java.net.Socket; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.material.Tree; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import poppy.Constants; -import poppy.Config; -import poppy.Utils; import poppy.modules.AutoWorkbenchModule; +import poppy.modules.CauldronModule; import poppy.modules.ChairModule; import poppy.modules.DoubleDoorModule; import poppy.modules.CommonModule; @@ -40,12 +28,13 @@ public class Main extends JavaPlugin private Plugin plugin; private Config config; private PluginManager pluginManager; - + + private CommonModule commonModule; private DoubleDoorModule doubleDoorModule; private ChairModule chairModule; private AutoWorkbenchModule autoWorkbenchModule; private LeavesDecayModule leavesDecayModule; - private CommonModule commonModule; + private CauldronModule cauldronModule; @Override public void onEnable() @@ -55,6 +44,9 @@ public class Main extends JavaPlugin pluginManager = Bukkit.getPluginManager(); + commonModule = new CommonModule(); + pluginManager.registerEvents(commonModule, this); + doubleDoorModule = new DoubleDoorModule(); pluginManager.registerEvents(doubleDoorModule, this); @@ -67,8 +59,8 @@ public class Main extends JavaPlugin leavesDecayModule = new LeavesDecayModule(this); pluginManager.registerEvents(leavesDecayModule, this); - commonModule = new CommonModule(); - pluginManager.registerEvents(commonModule, this); + cauldronModule = new CauldronModule(this); + pluginManager.registerEvents(cauldronModule, this); } @Override diff --git a/src/poppy/Utils.java b/src/poppy/Utils.java @@ -10,16 +10,12 @@ import org.bukkit.entity.Entity; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import org.bukkit.Location; import org.bukkit.GameMode; -import org.bukkit.plugin.Plugin; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import poppy.Constants; - public class Utils { diff --git a/src/poppy/modules/CauldronModule.java b/src/poppy/modules/CauldronModule.java @@ -0,0 +1,68 @@ +package poppy.modules; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Dispenser; +import org.bukkit.block.data.Directional; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + + +public class CauldronModule implements Listener +{ + private Plugin plugin; + + public CauldronModule(Plugin plugin) + { + this.plugin = plugin; + } + + @EventHandler + public void onBlockDispenseEvent(BlockDispenseEvent event) + { + final Block block = event.getBlock(); + final BlockState blockState = block.getState(); + + if(blockState instanceof Dispenser) + { + final Dispenser dispenser = (Dispenser) blockState; + final ItemStack item = event.getItem(); + + if(block.getBlockData() instanceof Directional) + { + final Directional direction = (Directional) dispenser.getBlockData(); + final Block cauldron = dispenser.getBlock().getRelative(direction.getFacing()); + + if(item.getType() == Material.BUCKET) + { + if(cauldron.getType() == Material.WATER_CAULDRON) + { + cauldron.setType(Material.CAULDRON); + removeSnapshotItem(dispenser, item.getType(), 1); + event.setItem(new ItemStack(Material.WATER_BUCKET)); + } + + if(cauldron.getType() == Material.LAVA_CAULDRON) + { + cauldron.setType(Material.CAULDRON); + removeSnapshotItem(dispenser, item.getType(), 1); + event.setItem(new ItemStack(Material.LAVA_BUCKET)); + } + } + } + } + } + + public void removeSnapshotItem(Dispenser dispenser, Material material, int amount) + { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + dispenser.getSnapshotInventory().addItem(new ItemStack(material, -amount)); + dispenser.update(); + }, 1); + } +} diff --git a/src/poppy/modules/ChairModule.java b/src/poppy/modules/ChairModule.java @@ -18,7 +18,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.util.Vector; import org.spigotmc.event.entity.EntityDismountEvent; import poppy.Utils; diff --git a/src/poppy/modules/CommonModule.java b/src/poppy/modules/CommonModule.java @@ -33,8 +33,7 @@ public class CommonModule implements Listener @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - - Player player = event.getPlayer(); + final Player player = event.getPlayer(); if(event.getAction() == Action.PHYSICAL) { @@ -47,33 +46,32 @@ public class CommonModule implements Listener } } - EquipmentSlot equip = event.getHand(); - - if(equip.equals(EquipmentSlot.HAND)) + if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { + final EquipmentSlot equip = event.getHand(); - if(event.getAction() == Action.RIGHT_CLICK_BLOCK) + if(equip.equals(EquipmentSlot.HAND)) { - Block block = event.getClickedBlock(); + final Block block = event.getClickedBlock(); if(block == null) { return; } - Material material = block.getType(); + final Material material = block.getType(); if(player.isSneaking()) { return; } - BlockData blockdata = block.getBlockData(); + final BlockData blockdata = block.getBlockData(); if(blockdata instanceof Ageable) { - Ageable ageable = (Ageable) blockdata; + final Ageable ageable = (Ageable) blockdata; if(Utils.isFarmable(material) && ageable.getAge() == ageable.getMaximumAge()) { @@ -83,7 +81,7 @@ public class CommonModule implements Listener if(blockdata instanceof Directional) { Directional directional = (Directional) blockdata; - BlockFace blockface = directional.getFacing(); + final BlockFace blockface = directional.getFacing(); block.breakNaturally(player.getItemInUse()); block.setType(material); @@ -94,7 +92,6 @@ public class CommonModule implements Listener } else { - block.breakNaturally(player.getItemInUse()); block.setType(material); } @@ -131,11 +128,11 @@ public class CommonModule implements Listener { if(event.getDamager() instanceof Snowball) { - Snowball snowball = (Snowball) event.getDamager(); + final Snowball snowball = (Snowball) event.getDamager(); if(snowball.getShooter() instanceof Player) { - Player player = (Player) event.getEntity(); + final Player player = (Player) event.getEntity(); player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 2, 1)); event.setDamage(1); @@ -146,15 +143,15 @@ public class CommonModule implements Listener @EventHandler public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { - Player player = event.getPlayer(); + final Player player = event.getPlayer(); if(event.getRightClicked().getType().equals(EntityType.ARMOR_STAND)) { - ItemStack item = player.getInventory().getItemInMainHand(); + final ItemStack item = player.getInventory().getItemInMainHand(); if(item.getType() == Material.STICK && item.getAmount() > 1 && player.isSneaking()) { - ArmorStand armorstand = (ArmorStand) event.getRightClicked(); + final ArmorStand armorstand = (ArmorStand) event.getRightClicked(); armorstand.setArms(true); item.setAmount(item.getAmount() - 2); @@ -169,7 +166,7 @@ public class CommonModule implements Listener { if(event.getEntity() instanceof ArmorStand) { - ArmorStand armorstand = (ArmorStand) event.getEntity(); + final ArmorStand armorstand = (ArmorStand) event.getEntity(); if(armorstand.hasArms()) { diff --git a/src/poppy/modules/DoubleDoorModule.java b/src/poppy/modules/DoubleDoorModule.java @@ -17,7 +17,18 @@ import poppy.Utils; public class DoubleDoorModule implements Listener { - private static final Material[] DOOR_TYPE = new Material[] { Material.OAK_DOOR, Material.SPRUCE_DOOR, Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR, Material.ACACIA_DOOR, Material.CRIMSON_DOOR, Material.WARPED_DOOR }; + private static final Material[] DOOR_TYPE = new Material[] + { + Material.OAK_DOOR, + Material.SPRUCE_DOOR, + Material.BIRCH_DOOR, + Material.JUNGLE_DOOR, + Material.ACACIA_DOOR, + Material.DARK_OAK_DOOR, + Material.ACACIA_DOOR, + Material.CRIMSON_DOOR, + Material.WARPED_DOOR + }; @EventHandler public void onPlayerInteract(PlayerInteractEvent event)