QUOTE: Enjoy small things, cherish moments.

Added Spawner Module and reload command - 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 7c1b2681b3814c33f7bb6a3b953a84e85655b1a0
parent 42df709e3b733113ac71ea103ca9a714dfa266de
Author: chunksize <reisingerluca@gmail.com>
Date:   Mon, 23 Jan 2023 00:20:39 +0100

Added Spawner Module and reload command

Diffstat:
Mres/plugin.yml | 4++++
Msrc/poppy/Main.java | 32+++++++++++++++++++++++++++++++-
Asrc/poppy/modules/SpawnerModule.java | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/res/plugin.yml b/res/plugin.yml @@ -17,4 +17,8 @@ commands: usage: /setwarp <name> warp: usage: /warp <name> + slime: + usage: /slime + r: + usage: /r info: diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -21,6 +21,7 @@ import poppy.modules.ChairModule; import poppy.modules.DoubleDoorModule; import poppy.modules.CommonModule; import poppy.modules.LeavesDecayModule; +import poppy.modules.SpawnerModule; public class Main extends JavaPlugin @@ -35,6 +36,7 @@ public class Main extends JavaPlugin private AutoWorkbenchModule autoWorkbenchModule; private LeavesDecayModule leavesDecayModule; private CauldronModule cauldronModule; + private SpawnerModule spawnerModule; @Override public void onEnable() @@ -61,6 +63,9 @@ public class Main extends JavaPlugin cauldronModule = new CauldronModule(this); pluginManager.registerEvents(cauldronModule, this); + + spawnerModule = new SpawnerModule(); + pluginManager.registerEvents(spawnerModule, this); } @Override @@ -96,6 +101,10 @@ public class Main extends JavaPlugin return setHome(player, args); case "setwarp": return setWarppoint(player, args); + case "slime": + return ifSlimeChunk(player, args); + case "r": + return reload(player, args); default: return false; } @@ -289,5 +298,26 @@ public class Main extends JavaPlugin return true; } - + + private boolean ifSlimeChunk(final Player player, final String[] args) + { + boolean isSlimeChunk = player.getLocation().getChunk().isSlimeChunk(); + + if(isSlimeChunk) + { + player.sendMessage(ChatColor.YELLOW + "This is a slime chunk!"); + return true; + } + else + { + player.sendMessage(ChatColor.RED + "This is not a slime chunk!"); + return true; + } + } + + private boolean reload(final Player player, final String[] args) + { + player.chat("/reload confirm"); + return true; + } } diff --git a/src/poppy/modules/SpawnerModule.java b/src/poppy/modules/SpawnerModule.java @@ -0,0 +1,69 @@ +package poppy.modules; + +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.bukkit.inventory.meta.ItemMeta; + +public class SpawnerModule implements Listener +{ + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + final Block block = event.getBlock(); + final Player player = event.getPlayer(); + final ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); + + if(block.getType() == Material.SPAWNER && itemInMainHand.containsEnchantment(Enchantment.SILK_TOUCH)) + { + final CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState(); + final ItemStack spawner = new ItemStack(Material.SPAWNER); + final ItemMeta spawnerItemMeta = spawner.getItemMeta(); + final ArrayList<String> spawneritemLore = new ArrayList<String>(); + final Location blockLocation = block.getLocation(); + final BlockStateMeta spawnerblockMeta = (BlockStateMeta) spawner.getItemMeta(); + + spawneritemLore.add(creatureSpawner.getSpawnedType().toString()); + spawnerItemMeta.setLore(spawneritemLore); + spawner.setItemMeta(spawnerItemMeta); + spawnerblockMeta.setBlockState(creatureSpawner); + blockLocation.getWorld().dropItemNaturally(blockLocation, spawner); + block.setType(Material.AIR); + event.setExpToDrop(0); + } + } + + @EventHandler + public void onPlaceEvent(BlockPlaceEvent event) + { + final Block block = event.getBlockPlaced(); + final ItemStack item = event.getItemInHand(); + final ItemMeta itemMeta = item.getItemMeta(); + + if(itemMeta.getLore() == null) + { + return; + } + + if(block.getType() == Material.SPAWNER) + { + final CreatureSpawner creatureSpawnerBlock = (CreatureSpawner) block.getState(); + final EntityType entityType = EntityType.valueOf(itemMeta.getLore().get(0)); + + creatureSpawnerBlock.setSpawnedType(entityType); + creatureSpawnerBlock.update(); + } + } +}