From a4afc5fe88dc11392fe92b89d215f2614ee5ba45 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 26 Mar 2022 14:36:50 +0100 Subject: [PATCH] Player Seat Listener --- .../lobby/listener/TeleporterListener.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/listener/TeleporterListener.java b/src/de/steamwar/lobby/listener/TeleporterListener.java index a5dd4da..08d4d6a 100644 --- a/src/de/steamwar/lobby/listener/TeleporterListener.java +++ b/src/de/steamwar/lobby/listener/TeleporterListener.java @@ -3,14 +3,18 @@ package de.steamwar.lobby.listener; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; +import de.steamwar.lobby.Config; import de.steamwar.lobby.particle.SpecialParticle; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; @@ -20,6 +24,11 @@ import org.bukkit.inventory.meta.ItemMeta; 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); + private static final Location team = new Location(world,1524,55,1440); + private static final Location map = new Location(world,2337,38,1424); static { inventory = createInventory(); @@ -34,16 +43,21 @@ public class TeleporterListener extends BasicListener{ } @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerInventoryInteract(PlayerInteractEvent event) { - ItemStack item = event.getItem(); + public void handlePlayerInventoryInteract(InventoryClickEvent event) { + Player player = (Player) event.getWhoClicked(); + ItemStack item = event.getCurrentItem(); + if(item == null) return; - if(item.getType() == Material.MAGMA_CREAM && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { - //TODO: TP zum Spawn - }else if(item.getType() == Material.MAP && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { - //TODO: TP zur Map + 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); } + } private static Inventory createInventory() { @@ -55,6 +69,12 @@ public class TeleporterListener extends BasicListener{ 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");