From 8c24167358b2649fbcf10431e8e06ee8ceacb597 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 12 Feb 2022 12:47:55 +0100 Subject: [PATCH] Dunno if this code works or not --- .../lobby/inventories/LobbyInventory.java | 14 ++-- .../listener/features/ElytraListener.java | 59 +++++++++++++++++ .../listener/features/EnderpearlListener.java | 64 ------------------- src/de/steamwar/lobby/util/LobbyPlayer.java | 15 ++--- 4 files changed, 75 insertions(+), 77 deletions(-) create mode 100644 src/de/steamwar/lobby/listener/features/ElytraListener.java delete mode 100644 src/de/steamwar/lobby/listener/features/EnderpearlListener.java diff --git a/src/de/steamwar/lobby/inventories/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java index a5a2c96..08dfb68 100644 --- a/src/de/steamwar/lobby/inventories/LobbyInventory.java +++ b/src/de/steamwar/lobby/inventories/LobbyInventory.java @@ -4,20 +4,25 @@ import de.steamwar.lobby.util.ItemBuilder; import de.steamwar.lobby.util.LobbyPlayer; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; public class LobbyInventory { private LobbyInventory() {} public static Material PARTICLE = Material.NAME_TAG; - public static Material ENDERPEARL_USED = Material.FIREWORK_STAR; - public static Material ENDERPEARL_READY = Material.ENDER_PEARL; + public static Material ELYTRA_USED = Material.FIREWORK_STAR; + public static Material ELYTRA_READY = Material.ELYTRA; public static void givePlayerLobbyItems(Player player) { + + player.getInventory().setChestplate(new ItemStack(Material.AIR)); + player.getInventory().setItem(8, new ItemStack(Material.AIR)); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - player.getInventory().setItem(3, new ItemBuilder(lobbyPlayer.isEnderPearlUsed() ? ENDERPEARL_USED : ENDERPEARL_READY) - .setDisplayName("§5Enderperle") + player.getInventory().setItem(3, new ItemBuilder(lobbyPlayer.isFlyingElytra() ? ELYTRA_USED : ELYTRA_READY) + .setDisplayName("§5Elytra") .setUnbreakable(true) .removeAllAtributs() .build()); @@ -27,6 +32,7 @@ public class LobbyInventory { .setUnbreakable(true) .removeAllAtributs() .build()); + } } diff --git a/src/de/steamwar/lobby/listener/features/ElytraListener.java b/src/de/steamwar/lobby/listener/features/ElytraListener.java new file mode 100644 index 0000000..63e56ef --- /dev/null +++ b/src/de/steamwar/lobby/listener/features/ElytraListener.java @@ -0,0 +1,59 @@ +package de.steamwar.lobby.listener.features; + +import de.steamwar.lobby.inventories.LobbyInventory; +import de.steamwar.lobby.listener.BasicListener; +import de.steamwar.lobby.util.ItemBuilder; +import de.steamwar.lobby.util.LobbyPlayer; +import org.bukkit.Material; +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.entity.EntityToggleGlideEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class ElytraListener extends BasicListener { + + @EventHandler(priority = EventPriority.NORMAL) + public void handlePlayerInteract(PlayerInteractEvent event) { + if(event.getMaterial() != LobbyInventory.ELYTRA_READY) return; + Action action = event.getAction(); + if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; + + event.setCancelled(true); + + Player player = event.getPlayer(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + + player.getInventory().setChestplate(new ItemStack(Material.ELYTRA)); + + LobbyInventory.givePlayerLobbyItems(player); + + lobbyPlayer.setFlyingElytra(true); + + if(event.getItem().equals(new ItemStack(Material.FIREWORK_ROCKET))) { + event.getItem().setAmount(1); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerToggleGlide(EntityToggleGlideEvent event) { + if(!(event.getEntity() instanceof Player)) return; + Player player = (Player) event.getEntity(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + + if(!event.isGliding() && lobbyPlayer.isFlyingElytra()) { + lobbyPlayer.setFlyingElytra(false); + LobbyInventory.givePlayerLobbyItems(player); + } + } + + public void givePlayerFirework(Player player) { + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + + if(!lobbyPlayer.isFlyingElytra()) return; + + player.getInventory().setItem(8, new ItemBuilder(Material.FIREWORK_ROCKET, 1).setDisplayName("§5Rakete").build()); + } +} diff --git a/src/de/steamwar/lobby/listener/features/EnderpearlListener.java b/src/de/steamwar/lobby/listener/features/EnderpearlListener.java deleted file mode 100644 index 49f885d..0000000 --- a/src/de/steamwar/lobby/listener/features/EnderpearlListener.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.steamwar.lobby.listener.features; - -import de.steamwar.lobby.LobbySystem; -import de.steamwar.lobby.inventories.LobbyInventory; -import de.steamwar.lobby.listener.BasicListener; -import de.steamwar.lobby.util.LobbyPlayer; -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.entity.EnderPearl; -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.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.vehicle.VehicleExitEvent; - -public class EnderpearlListener extends BasicListener { - - @EventHandler(priority = EventPriority.NORMAL) - public void handlePlayerInteract(PlayerInteractEvent event) { - if(event.getMaterial() != LobbyInventory.ENDERPEARL_READY) return; - Action action = event.getAction(); - if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; - - event.setCancelled(true); - - Player player = event.getPlayer(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - lobbyPlayer.setEnderPearlUsed(true); - - EnderPearl enderPearl = player.launchProjectile(EnderPearl.class); - enderPearl.setPassenger(player); - - LobbyInventory.givePlayerLobbyItems(player); - - Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> { - lobbyPlayer.setEnderPearlUsed(false); - - if(player == null) //in case of player leave - return; - LobbyInventory.givePlayerLobbyItems(player); - }, 20 * 3); - } - - @EventHandler - public void handleVehicleExit(VehicleExitEvent event) { - if(!(event.getExited() instanceof Player)) - return; - Player player = (Player) event.getExited(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - - lobbyPlayer.setEnderPearlUsed(false); - LobbyInventory.givePlayerLobbyItems(player); - player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0F, 0.5F); - } - - @EventHandler(priority = EventPriority.NORMAL) - public void handlePlayerTeleport(PlayerTeleportEvent event) { - if(event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; - if(event.getPlayer().isInsideVehicle()) return; - event.setCancelled(true); - } -} diff --git a/src/de/steamwar/lobby/util/LobbyPlayer.java b/src/de/steamwar/lobby/util/LobbyPlayer.java index 0c8c63a..31c4b73 100644 --- a/src/de/steamwar/lobby/util/LobbyPlayer.java +++ b/src/de/steamwar/lobby/util/LobbyPlayer.java @@ -1,6 +1,8 @@ package de.steamwar.lobby.util; import de.steamwar.lobby.particle.SpecialParticle; +import lombok.Getter; +import lombok.Setter; import org.bukkit.entity.Player; import java.util.HashMap; @@ -13,7 +15,10 @@ public class LobbyPlayer { private SpecialParticle specialParticle; - private boolean enderPearlUsed; + @Getter + @Setter + private boolean flyingElytra; + private boolean fly; private LobbyPlayer(UUID uuid) { @@ -37,14 +42,6 @@ public class LobbyPlayer { this.specialParticle = specialParticle; } - public boolean isEnderPearlUsed() { - return enderPearlUsed; - } - - public void setEnderPearlUsed(boolean enderPearlUsed) { - this.enderPearlUsed = enderPearlUsed; - } - public static LobbyPlayer getLobbyPlayer(UUID uuid) { LobbyPlayer lobbyPlayer = cache.get(uuid); return lobbyPlayer == null ? new LobbyPlayer(uuid) : lobbyPlayer;