From ea73d24b8b428d4d68d2563a8e2b6d1338f64f67 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Mar 2022 16:42:37 +0100 Subject: [PATCH] Update TeleporterListener --- .../lobby/listener/TeleporterListener.java | 89 +++++-------------- 1 file changed, 20 insertions(+), 69 deletions(-) diff --git a/src/de/steamwar/lobby/listener/TeleporterListener.java b/src/de/steamwar/lobby/listener/TeleporterListener.java index 84ff9fa..035d499 100644 --- a/src/de/steamwar/lobby/listener/TeleporterListener.java +++ b/src/de/steamwar/lobby/listener/TeleporterListener.java @@ -19,6 +19,8 @@ package de.steamwar.lobby.listener; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -26,16 +28,11 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -public class TeleporterListener extends BasicListener{ +public class TeleporterListener extends BasicListener { - private static final Inventory inventory; private static final World world = Bukkit.getWorlds().get(0); private static final Location spawn = world.getSpawnLocation().clone().add(0.5, 0, 0.5); @@ -44,75 +41,29 @@ public class TeleporterListener extends BasicListener{ private static final Location bau = new Location(world,1951,66,1337); private static final Location arenen = new Location(world,2255,21,1450); - static { - inventory = createInventory(); - } - @EventHandler(priority = EventPriority.NORMAL) public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!PlayerSpawn.NETHER_STAR.equals(event.getItem())) return; - player.openInventory(inventory); - } - - @EventHandler - public void handlePlayerInventoryInteract(InventoryClickEvent event) { - Player player = (Player) event.getWhoClicked(); - ItemStack item = event.getCurrentItem(); - - if(item == null) - return; - - if(event.getClickedInventory().getContents() != inventory.getContents()) return; - - if(item.getType() == Material.MAGMA_CREAM) { - player.teleport(spawn); - }else if(item.getType() == Material.BEACON) { - player.teleport(team); - }else if(item.getType() == Material.MAP) { - player.teleport(map); - }else if(item.getType() == Material.WOODEN_AXE) { + SWInventory swInventory = new SWInventory(player, () -> { + return Bukkit.createInventory(null, InventoryType.HOPPER, "§6Teleporter"); + }); + swInventory.setItem(0, new SWItem(Material.WOODEN_AXE, "§eBaubereich").getItemStack(), clickType -> { player.teleport(bau); - }else if(item.getType() == Material.CLOCK) { + }); + swInventory.setItem(1, new SWItem(Material.MAGMA_CREAM, "§eSpawn").getItemStack(), clickType -> { + player.teleport(spawn); + }); + swInventory.setItem(1, new SWItem(Material.BEACON, "§eTeamhalle").getItemStack(), clickType -> { + player.teleport(team); + }); + swInventory.setItem(1, new SWItem(Material.MAP, "§eMap").getItemStack(), clickType -> { + player.teleport(map); + }); + swInventory.setItem(1, new SWItem(Material.CLOCK, "§eArenen").getItemStack(), clickType -> { player.teleport(arenen); - } + }); + swInventory.open(); } - - private static Inventory createInventory() { - Inventory inv = Bukkit.createInventory(null, InventoryType.HOPPER, "§6Teleporter"); - - ItemStack item = new ItemStack(Material.WOODEN_AXE, 1); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName("§eBaubereich"); - item.setItemMeta(meta); - inv.setItem(0, item); - - ItemStack item1 = new ItemStack(Material.MAGMA_CREAM, 1); - ItemMeta meta1 = item1.getItemMeta(); - meta1.setDisplayName("§eSpawn"); - item1.setItemMeta(meta1); - inv.setItem(1, item1); - - ItemStack item2 = new ItemStack(Material.BEACON, 1); - ItemMeta meta2 = item2.getItemMeta(); - meta2.setDisplayName("§eTeamhalle"); - item2.setItemMeta(meta2); - inv.setItem(2, item2); - - ItemStack item3 = new ItemStack(Material.MAP, 1); - ItemMeta meta3 = item3.getItemMeta(); - meta3.setDisplayName("§eMap"); - item3.setItemMeta(meta3); - inv.setItem(3, item3); - - ItemStack item4 = new ItemStack(Material.CLOCK, 1); - ItemMeta meta4 = item4.getItemMeta(); - meta4.setDisplayName("§eArenen"); - item4.setItemMeta(meta4); - inv.setItem(4, item4); - - return inv; - } - }