13
0

Dunno if this code works or not

Dieser Commit ist enthalten in:
zOnlyKroks 2022-02-12 12:47:55 +01:00
Ursprung ccefd3ca5c
Commit 8c24167358
4 geänderte Dateien mit 75 neuen und 77 gelöschten Zeilen

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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;