QUOTE: Let your heart guide you always.

feat: Added PlayerMountModule - 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 c634d2a7350a3c56ecb00882d8a30085ac7b844e
parent d19697fb6a4ab9ef5b69e65986b0ac7e44c297e4
Author: typable <contact@typable.dev>
Date:   Thu, 23 Feb 2023 12:50:19 +0100

feat: Added PlayerMountModule

Diffstat:
Msrc/poppy/Main.java | 22++++++++++++++++------
Msrc/poppy/modules/CommonModule.java | 10----------
Asrc/poppy/modules/PlayerMountModule.java | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+), 16 deletions(-)

diff --git a/src/poppy/Main.java b/src/poppy/Main.java @@ -26,6 +26,7 @@ import poppy.modules.HopperSorterModule; import poppy.modules.CommonModule; import poppy.modules.LeavesDecayModule; import poppy.modules.SpawnerModule; +import poppy.modules.PlayerMountModule; public class Main extends JavaPlugin @@ -44,6 +45,7 @@ public class Main extends JavaPlugin private HopperSorterModule hopperSorterModule; private AutoPlacerModule autoPlacerModule; private AutoBreakerModule autoBreakerModule; + private PlayerMountModule playerMountModule; @Override public void onEnable() @@ -82,6 +84,9 @@ public class Main extends JavaPlugin autoBreakerModule = new AutoBreakerModule(this); pluginManager.registerEvents(autoBreakerModule, this); + + playerMountModule = new PlayerMountModule(); + pluginManager.registerEvents(playerMountModule, this); } @Override @@ -118,11 +123,11 @@ public class Main extends JavaPlugin case "setwarp": return setWarppoint(player, args); case "slime": - return ifSlimeChunk(player, args); + return isSlimeChunk(player, args); case "r": - return reload(player, args); + return doReload(player, args); case "up": - return blockBelow(player, args); + return placeBlockBelow(player, args); default: return false; } @@ -136,6 +141,11 @@ public class Main extends JavaPlugin final ItemStack item = player.getInventory().getItemInMainHand(); final ItemStack head = player.getInventory().getHelmet(); + if(head != null && head.getType().equals(Material.SADDLE)) + { + player.eject(); + } + player.getInventory().setHelmet(item); player.getInventory().setItemInMainHand((new ItemStack(Material.AIR))); @@ -317,7 +327,7 @@ public class Main extends JavaPlugin return true; } - private boolean ifSlimeChunk(final Player player, final String[] args) + private boolean isSlimeChunk(final Player player, final String[] args) { boolean isSlimeChunk = player.getLocation().getChunk().isSlimeChunk(); @@ -333,13 +343,13 @@ public class Main extends JavaPlugin } } - private boolean reload(final Player player, final String[] args) + private boolean doReload(final Player player, final String[] args) { player.chat("/reload confirm"); return true; } - private boolean blockBelow(final Player player, final String[] args) + private boolean placeBlockBelow(final Player player, final String[] args) { Location playerLocation = player.getLocation().clone(); Block blockBelow = playerLocation.add(0, -1, 0).getBlock(); diff --git a/src/poppy/modules/CommonModule.java b/src/poppy/modules/CommonModule.java @@ -169,16 +169,6 @@ public class CommonModule implements Listener event.setCancelled(true); } } - - if(event.getRightClicked().getType().equals(EntityType.PLAYER)) - { - final Player clickedPlayer = (Player) event.getRightClicked(); - - if(clickedPlayer.getInventory().getHelmet().getType().equals(Material.SADDLE) && player.getPassengers().size() <= 0) - { - clickedPlayer.addPassenger(player); - } - } } @EventHandler diff --git a/src/poppy/modules/PlayerMountModule.java b/src/poppy/modules/PlayerMountModule.java @@ -0,0 +1,67 @@ +package poppy.modules; + +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.Listener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType.SlotType; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +public class PlayerMountModule implements Listener +{ + @EventHandler + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) + { + final Player player = event.getPlayer(); + final Entity entity = event.getRightClicked(); + + if(entity instanceof Player) + { + final Player mountablePlayer = (Player) entity; + final Material helmet = mountablePlayer.getInventory().getHelmet().getType(); + + if(helmet.equals(Material.SADDLE) && mountablePlayer.getPassengers().size() == 0) + { + mountablePlayer.addPassenger(player); + } + } + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) + { + final HumanEntity entity = event.getWhoClicked(); + + if(entity instanceof Player) + { + final Player player = (Player) entity; + final SlotType slotType = event.getSlotType(); + + if(slotType != SlotType.ARMOR) + { + return; + } + + final ClickType clickType = event.getClick(); + + if(!(clickType == ClickType.LEFT || clickType == ClickType.RIGHT)) + { + return; + } + + final ItemStack head = event.getCurrentItem(); + + if(head == null || head.getType() != Material.SADDLE) + { + return; + } + + player.eject(); + } + } +}