From 7e40a439aded20c783ae1466bdbe370eb7dc27bb Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 15:47:46 +0100 Subject: [PATCH 1/8] Update LobbySystem --- src/de/steamwar/lobby/LobbySystem.java | 5 +- .../steamwar/lobby/commands/FlyCommand.java | 56 +++++++++++ .../lobby/inventories/LobbyInventory.java | 14 +-- .../lobby/inventories/ParticleInventory.java | 60 ++++++------ .../lobby/listener/DoubleJumpListener.java | 10 +- .../lobby/listener/EnderPearlListener.java | 4 +- .../lobby/listener/ParticleListener.java | 10 +- .../listener/PlayerConnectionListener.java | 7 +- .../lobby/listener/PlayerHiderListener.java | 96 ------------------ .../lobby/listener/PlayerMoveListener.java | 19 ++-- .../lobby/listener/PlayerSeatListener.java | 66 +++++++++++++ .../PlayerWorldInteractionListener.java | 5 +- src/de/steamwar/lobby/utils/ItemBuilder.java | 10 +- .../steamwar/lobby/utils/LobbyParticle.java | 57 +++++++++++ src/de/steamwar/lobby/utils/LobbyPlayer.java | 97 +++---------------- src/plugin.yml | 5 +- 16 files changed, 273 insertions(+), 248 deletions(-) create mode 100644 src/de/steamwar/lobby/commands/FlyCommand.java delete mode 100644 src/de/steamwar/lobby/listener/PlayerHiderListener.java create mode 100644 src/de/steamwar/lobby/listener/PlayerSeatListener.java create mode 100644 src/de/steamwar/lobby/utils/LobbyParticle.java diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index f171e66..26513be 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -19,6 +19,7 @@ package de.steamwar.lobby; +import de.steamwar.lobby.commands.FlyCommand; import de.steamwar.lobby.listener.*; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; @@ -32,6 +33,8 @@ public class LobbySystem extends JavaPlugin { public void onEnable() { instance = this; + getCommand("fly").setExecutor(new FlyCommand()); + PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new PlayerMoveListener(), instance); @@ -40,7 +43,7 @@ public class LobbySystem extends JavaPlugin { pm.registerEvents(new PlayerWorldInteractionListener(), instance); pm.registerEvents(new DoubleJumpListener(), instance); pm.registerEvents(new ParticleListener(), instance); - pm.registerEvents(new PlayerHiderListener(), instance); + pm.registerEvents(new PlayerSeatListener(), instance); pm.registerEvents(new EnderPearlListener(), instance); } diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java new file mode 100644 index 0000000..268593d --- /dev/null +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -0,0 +1,56 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.lobby.commands; + +import de.steamwar.lobby.utils.LobbyPlayer; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserGroup; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class FlyCommand implements CommandExecutor { + + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + + Player player = (Player) sender; + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + + if (userGroup == UserGroup.Member) { + player.sendMessage("§cDu verfügst nicht über die benötigten Rechte!"); + return false; + } + + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); + boolean newFlightState = !lobbyPlayer.isFly(); + + lobbyPlayer.setFly(newFlightState); + player.setAllowFlight(newFlightState); + player.setFlying(newFlightState); + player.sendMessage("§7Du kannst jetzt " + (newFlightState ? "§afliegen§7." : "§cnicht §7mehr fliegen.")); + return false; + } +} diff --git a/src/de/steamwar/lobby/inventories/LobbyInventory.java b/src/de/steamwar/lobby/inventories/LobbyInventory.java index 7b43226..8ae054a 100644 --- a/src/de/steamwar/lobby/inventories/LobbyInventory.java +++ b/src/de/steamwar/lobby/inventories/LobbyInventory.java @@ -28,28 +28,22 @@ public class LobbyInventory { private LobbyInventory() {} - public static Material PLAYER_HIDER = Material.BLAZE_ROD; 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 SHIELD = Material.SHIELD; public static void givePlayerLobbyItems(Player player) { - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - player.getInventory().setItem(2, new ItemBuilder(PLAYER_HIDER) - .setDisplayName(lobbyPlayer.getHiderState().getName()) - .setUnbreakable(true) - .removeAllAtributs() - .build()); + // 2, 4, 6 - player.getInventory().setItem(4, new ItemBuilder(lobbyPlayer.isEnderPearlUsed() ? ENDERPEARL_USED : ENDERPEARL_READY) + player.getInventory().setItem(3, new ItemBuilder(lobbyPlayer.isEnderPearlUsed() ? ENDERPEARL_USED : ENDERPEARL_READY) .setDisplayName("§5Enderperle") .setUnbreakable(true) .removeAllAtributs() .build()); - player.getInventory().setItem(6, new ItemBuilder(PARTICLE) + player.getInventory().setItem(5, new ItemBuilder(PARTICLE) .setDisplayName("§6Partikel") .setUnbreakable(true) .removeAllAtributs() diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 15ca3ca..7ad5c68 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -21,6 +21,7 @@ package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; +import de.steamwar.lobby.utils.LobbyParticle; import de.steamwar.lobby.utils.LobbyPlayer; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; @@ -38,9 +39,10 @@ public class ParticleInventory { private static List lore = Arrays.asList("§aKlicken zum Auswählen"); private static SWInventory createInventory(Player player) { - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); + LobbyParticle lobbyParticle = lobbyPlayer.getLobbyParticle(); SWInventory swInventory; if (userGroup == UserGroup.Member) { @@ -49,51 +51,51 @@ public class ParticleInventory { swInventory = new SWInventory(player, 9*6, "§6Partikel"); } - add(swInventory, Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 10, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 11, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA, 12, player, lobbyPlayer); - add(swInventory, Material.RED_DYE, "§cHerzen", lore, Particle.HEART, 13, player, lobbyPlayer); - add(swInventory, Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER, 14, player, lobbyPlayer); - add(swInventory, Material.NOTE_BLOCK, "§eNoten", lore, Particle.NOTE, 15, player, lobbyPlayer); - add(swInventory, Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 16, player, lobbyPlayer, true, 0.2F, 0F, 0.2F, 0.01); + add(swInventory, Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 10, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); + add(swInventory, Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 11, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); + add(swInventory, Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA, 12, player, lobbyParticle); + add(swInventory, Material.RED_DYE, "§cHerzen", lore, Particle.HEART, 13, player, lobbyParticle); + add(swInventory, Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER, 14, player, lobbyParticle); + add(swInventory, Material.NOTE_BLOCK, "§eNoten", lore, Particle.NOTE, 15, player, lobbyParticle); + add(swInventory, Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 16, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 19, player, lobbyPlayer, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 20, player, lobbyPlayer, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 21, player, lobbyPlayer, true, 0F, 0.2F, 0F, 0.01); - add(swInventory, Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 22, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 23, player, lobbyPlayer, true, 0.2F, 0.02F, 0.2F, 0.01); - add(swInventory, Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME, 24, player, lobbyPlayer); - add(swInventory, Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB, 25, player, lobbyPlayer); + add(swInventory, Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 19, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); + add(swInventory, Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 20, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); + add(swInventory, Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 21, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.01); + add(swInventory, Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 22, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); + add(swInventory, Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 23, player, lobbyParticle, true, 0.2F, 0.02F, 0.2F, 0.01); + add(swInventory, Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME, 24, player, lobbyParticle); + add(swInventory, Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB, 25, player, lobbyParticle); if (userGroup == UserGroup.Member) { - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 31, player, lobbyPlayer); + add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 31, player, lobbyParticle); } else { - add(swInventory, Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 28, player, lobbyPlayer, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH, 29, player, lobbyPlayer); - add(swInventory, Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE, 30, player, lobbyPlayer); - add(swInventory, Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 31, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 32, player, lobbyPlayer, true, 0F, 0.2F, 0F, 0.01); - add(swInventory, Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 33, player, lobbyPlayer, true, 0F, 0.2F, 0F, 0.2); - add(swInventory, Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 34, player, lobbyPlayer, true, 0.2F, 0.2F, 0.2F, 0.01); + add(swInventory, Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 28, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); + add(swInventory, Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH, 29, player, lobbyParticle); + add(swInventory, Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE, 30, player, lobbyParticle); + add(swInventory, Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 31, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); + add(swInventory, Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 32, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.01); + add(swInventory, Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 33, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.2); + add(swInventory, Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 34, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 40, player, lobbyPlayer); + add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 40, player, lobbyParticle); } return swInventory; } - private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyPlayer lobbyPlayer, boolean customVelocity, float vx, float vy, float vz, double time) { + private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyParticle lobbyParticle, boolean customVelocity, float vx, float vy, float vz, double time) { SWItem swItem = new SWItem(material, name, lore, false, clickType -> { - lobbyPlayer.setParticle(particle, customVelocity); - lobbyPlayer.setParticle(vx, vy, vz, time); + lobbyParticle.setParticle(particle, customVelocity); + lobbyParticle.setParticle(vx, vy, vz, time); player.closeInventory(); }); swInventory.setItem(slot, swItem); } - private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyPlayer lobbyPlayer) { + private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyParticle lobbyParticle) { SWItem swItem = new SWItem(material, name, lore, false, clickType -> { - lobbyPlayer.setParticle(particle); + lobbyParticle.setParticle(particle); player.closeInventory(); }); swInventory.setItem(slot, swItem); diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index d094c5a..05c65f2 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -19,6 +19,7 @@ package de.steamwar.lobby.listener; +import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; @@ -47,6 +48,9 @@ public class DoubleJumpListener implements Listener { if (player.getGameMode() != GameMode.ADVENTURE && player.getGameMode() != GameMode.SURVIVAL) { return; } + if (LobbyPlayer.getLobbyPlayer(player).isFly()) { + return; + } event.setCancelled(true); player.setAllowFlight(false); @@ -65,8 +69,12 @@ public class DoubleJumpListener implements Listener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) + if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) { return; + } + if (LobbyPlayer.getLobbyPlayer(player).isFly()) { + return; + } player.setAllowFlight(true); if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { diff --git a/src/de/steamwar/lobby/listener/EnderPearlListener.java b/src/de/steamwar/lobby/listener/EnderPearlListener.java index 2a8c9e9..f110e32 100644 --- a/src/de/steamwar/lobby/listener/EnderPearlListener.java +++ b/src/de/steamwar/lobby/listener/EnderPearlListener.java @@ -45,7 +45,7 @@ public class EnderPearlListener implements Listener { event.setCancelled(true); Player player = event.getPlayer(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); lobbyPlayer.setEnderPearlUsed(true); EnderPearl enderPearl = player.launchProjectile(EnderPearl.class); @@ -67,7 +67,7 @@ public class EnderPearlListener implements Listener { if(!(event.getExited() instanceof Player)) return; Player player = (Player) event.getExited(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); lobbyPlayer.setEnderPearlUsed(false); LobbyInventory.givePlayerLobbyItems(player); diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index 87c3509..e43a1d8 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -21,6 +21,7 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.inventories.ParticleInventory; +import de.steamwar.lobby.utils.LobbyParticle; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Color; import org.bukkit.Particle; @@ -49,8 +50,9 @@ public class ParticleListener implements Listener { @EventHandler public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - Particle particle = lobbyPlayer.getParticle(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); + LobbyParticle lobbyParticle = lobbyPlayer.getLobbyParticle(); + Particle particle = lobbyParticle.getParticle(); if (particle == null) return; if (particle == Particle.REDSTONE) { @@ -59,8 +61,8 @@ public class ParticleListener implements Listener { return; } - if (lobbyPlayer.isCustomVelocity()) { - player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5, lobbyPlayer.getParticle_vx(), lobbyPlayer.getParticle_vy(), lobbyPlayer.getParticle_vz(), lobbyPlayer.getParticle_time()); + if (lobbyParticle.isCustomVelocity()) { + player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5, lobbyParticle.getParticle_vx(), lobbyParticle.getParticle_vy(), lobbyParticle.getParticle_vz(), lobbyParticle.getParticle_time()); } else { player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5); } diff --git a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java index ab66243..236e13d 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -41,14 +41,15 @@ public class PlayerConnectionListener implements Listener { event.setJoinMessage(null); Player player = event.getPlayer(); - LobbyPlayer.getLobbyPlayer(player.getUniqueId()); //initialisiert einen neuen LP falls nicht vorhanden + LobbyPlayer.getLobbyPlayer(player); //initialisiert einen neuen LP falls nicht vorhanden player.teleport(new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ, Config.Yaw, Config.Pitch)); - player.getInventory().clear(); - LobbyInventory.givePlayerLobbyItems(player); player.setGameMode(GameMode.ADVENTURE); player.setHealth(20); player.setFoodLevel(20); + + player.getInventory().clear(); + LobbyInventory.givePlayerLobbyItems(player); } @EventHandler(priority = EventPriority.HIGH) diff --git a/src/de/steamwar/lobby/listener/PlayerHiderListener.java b/src/de/steamwar/lobby/listener/PlayerHiderListener.java deleted file mode 100644 index 431a3a8..0000000 --- a/src/de/steamwar/lobby/listener/PlayerHiderListener.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.lobby.listener; - -import de.steamwar.lobby.inventories.LobbyInventory; -import de.steamwar.lobby.utils.LobbyPlayer; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserGroup; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerHiderListener implements Listener { - - @EventHandler(priority = EventPriority.NORMAL) - public void handlePlayerInteract(PlayerInteractEvent event) { - Material material = event.getMaterial(); - if(material != LobbyInventory.PLAYER_HIDER) - return; - - Player player = event.getPlayer(); - LobbyPlayer.getLobbyPlayer(player.getUniqueId()).nexthHiderState(); - updateHider(player); - LobbyInventory.givePlayerLobbyItems(event.getPlayer()); - } - - @EventHandler - public void handlePlayerJoin(PlayerJoinEvent event) { - updateHider(event.getPlayer()); - } - - private void updateHider(Player player) { - LobbyPlayer.PlayerHiderState hiderState = LobbyPlayer.getLobbyPlayer(player.getUniqueId()).getHiderState(); - - Bukkit.getServer().getOnlinePlayers().forEach(currentPlayer -> { - if(currentPlayer.getUniqueId().equals(player.getUniqueId())) return; - - switch (hiderState) { - case SHOW_ALL: - player.showPlayer(currentPlayer); - break; - case SHOW_TEAM: - UserGroup userGroup = SteamwarUser.get(currentPlayer.getUniqueId()).getUserGroup(); - if(userGroup == UserGroup.Member) - player.hidePlayer(currentPlayer); - else - player.showPlayer(currentPlayer); - break; - case SHOW_NOBODY: - player.hidePlayer(currentPlayer); - break; - } - - LobbyPlayer.PlayerHiderState cpHiderState = LobbyPlayer.getLobbyPlayer(currentPlayer.getUniqueId()).getHiderState(); - switch (cpHiderState) { - case SHOW_ALL: - currentPlayer.showPlayer(player); - break; - case SHOW_TEAM: - UserGroup userGroup = SteamwarUser.get(player.getUniqueId()).getUserGroup(); - if(userGroup == UserGroup.Member) - currentPlayer.hidePlayer(player); - else - currentPlayer.showPlayer(player); - break; - case SHOW_NOBODY: - currentPlayer.hidePlayer(player); - break; - } - }); - } - - -} diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index e5daf07..2d4b9f0 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -20,7 +20,6 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.utils.Config; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -32,17 +31,12 @@ public class PlayerMoveListener implements Listener { @EventHandler public void handleWorldBorder(PlayerMoveEvent event) { Location to = event.getTo(); - if(!isInRegion( + if (!isInRegion( new Vector(Config.BorderMinX, Config.BorderMinY, Config.BorderMinZ), new Vector(Config.BorderMaxX, Config.BorderMaxY, Config.BorderMaxZ), - to.toVector())) - event.getPlayer().teleport(new Location( - Bukkit.getWorlds().get(0), - Config.SpawnX, - Config.SpawnY, - Config.SpawnZ, - Config.Yaw, - Config.Pitch)); + to.toVector())) { + event.getPlayer().teleport(event.getFrom()); + } } private boolean isInRegion(Vector minPoint, Vector maxPoint, Vector location) { @@ -50,15 +44,16 @@ public class PlayerMoveListener implements Listener { int y = location.getBlockY(); int z = location.getBlockZ(); - if(x >= minPoint.getBlockX() + if (x >= minPoint.getBlockX() && x <= maxPoint.getBlockX() && y >= minPoint.getBlockY() && y <= maxPoint.getBlockY() && z >= minPoint.getBlockZ() && z <= maxPoint.getBlockZ()) { return true; - } else + } else { return false; + } } diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java new file mode 100644 index 0000000..75b92ea --- /dev/null +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -0,0 +1,66 @@ +package de.steamwar.lobby.listener; + +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.type.Stairs; +import org.bukkit.entity.AbstractArrow; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.spigotmc.event.entity.EntityDismountEvent; + +public class PlayerSeatListener implements Listener { + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + if (!event.getClickedBlock().getType().name().toLowerCase().contains("stairs")) + return; + + if (event.getPlayer().getGameMode() != GameMode.ADVENTURE && event.getPlayer().getGameMode() != GameMode.SURVIVAL) + return; + + if (((Stairs) event.getClickedBlock().getBlockData()).getHalf() != Bisected.Half.BOTTOM) + return; + + if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT) + return; + + if (event.getPlayer().isInsideVehicle()) + event.getPlayer().getVehicle().remove(); + + if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) + return; + + Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(event.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.ARROW); + arrow.setGravity(false); + arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); + arrow.addPassenger(event.getPlayer()); + arrow.setPersistent(true); + } + + @EventHandler + public void onEntityDismount(EntityDismountEvent event) { + if (event.getDismounted().getType() != EntityType.ARROW) + return; + + if (event.getEntityType() != EntityType.PLAYER) + return; + + event.getDismounted().remove(); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer().isInsideVehicle()) + event.getPlayer().getVehicle().remove(); + } + +} diff --git a/src/de/steamwar/lobby/listener/PlayerWorldInteractionListener.java b/src/de/steamwar/lobby/listener/PlayerWorldInteractionListener.java index 29ecc26..9b68496 100644 --- a/src/de/steamwar/lobby/listener/PlayerWorldInteractionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerWorldInteractionListener.java @@ -37,8 +37,9 @@ public class PlayerWorldInteractionListener implements Listener { @EventHandler public void handleEntityDamage(EntityDamageEvent event) { - if(event.getEntityType() != EntityType.PLAYER) return; - event.setCancelled(true); + if (event.getEntityType() == EntityType.FOX || event.getEntityType() == EntityType.PLAYER) { + event.setCancelled(true); + } } @EventHandler diff --git a/src/de/steamwar/lobby/utils/ItemBuilder.java b/src/de/steamwar/lobby/utils/ItemBuilder.java index 686ffb8..fd84bf7 100644 --- a/src/de/steamwar/lobby/utils/ItemBuilder.java +++ b/src/de/steamwar/lobby/utils/ItemBuilder.java @@ -71,15 +71,15 @@ public class ItemBuilder { meta.addEnchant(enchantment, level, true); return this; } - - public ItemStack build() { - item.setItemMeta(meta); - return item; - } public ItemBuilder setUnbreakable(boolean unbreakable) { meta.setUnbreakable(unbreakable); return this; } + public ItemStack build() { + item.setItemMeta(meta); + return item; + } + } diff --git a/src/de/steamwar/lobby/utils/LobbyParticle.java b/src/de/steamwar/lobby/utils/LobbyParticle.java new file mode 100644 index 0000000..b6789ef --- /dev/null +++ b/src/de/steamwar/lobby/utils/LobbyParticle.java @@ -0,0 +1,57 @@ +package de.steamwar.lobby.utils; + +import org.bukkit.Particle; + +public class LobbyParticle { + + private Particle particle; + private boolean customVelocity = false; + private float particle_vx = 0; + private float particle_vy = 0; + private float particle_vz = 0; + private double particle_time = 0.001; + + public Particle getParticle() { + return particle; + } + + public boolean isCustomVelocity() { + return customVelocity; + } + + public float getParticle_vx() { + return particle_vx; + } + + public float getParticle_vy() { + return particle_vy; + } + + public float getParticle_vz() { + return particle_vz; + } + + public double getParticle_time() { + return particle_time; + } + + public void setParticle(Particle particle) { + this.particle = particle; + this.customVelocity = false; + setParticle(0, 0, 0, 0.001); + } + + public void setParticle(Particle particle, boolean customVelocity) { + this.particle = particle; + this.customVelocity = customVelocity; + setParticle(0, 0, 0, 0.001); + } + + public void setParticle(float vx, float vy, float vz, double time) { + this.particle_vx = vx; + this.particle_vy = vy; + this.particle_vz = vz; + this.particle_time = time; + } + +} diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 68857eb..a4d45e9 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,7 +19,7 @@ package de.steamwar.lobby.utils; -import org.bukkit.Particle; +import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; @@ -29,71 +29,26 @@ public class LobbyPlayer { private static Map cache = new HashMap<>(); - private PlayerHiderState hiderState; - - private Particle particle; - private boolean customVelocity = false; - private float particle_vx = 0; - private float particle_vy = 0; - private float particle_vz = 0; - private double particle_time = 0.001; + private LobbyParticle lobbyParticle; private boolean enderPearlUsed; + private boolean fly; private LobbyPlayer(UUID uuid) { - this.hiderState = PlayerHiderState.SHOW_ALL; cache.put(uuid, this); + lobbyParticle = new LobbyParticle(); } - public PlayerHiderState getHiderState() { - return hiderState; + public LobbyParticle getLobbyParticle() { + return lobbyParticle; } - public void setHiderState(PlayerHiderState hiderState) { - this.hiderState = hiderState; + public boolean isFly() { + return fly; } - public Particle getParticle() { - return particle; - } - - public boolean isCustomVelocity() { - return customVelocity; - } - - public float getParticle_vx() { - return particle_vx; - } - - public float getParticle_vy() { - return particle_vy; - } - - public float getParticle_vz() { - return particle_vz; - } - - public double getParticle_time() { - return particle_time; - } - - public void setParticle(Particle particle) { - this.particle = particle; - this.customVelocity = false; - setParticle(0, 0, 0, 0.001); - } - - public void setParticle(Particle particle, boolean customVelocity) { - this.particle = particle; - this.customVelocity = customVelocity; - setParticle(0, 0, 0, 0.001); - } - - public void setParticle(float vx, float vy, float vz, double time) { - this.particle_vx = vx; - this.particle_vy = vy; - this.particle_vz = vz; - this.particle_time = time; + public void setFly(boolean fly) { + this.fly = fly; } public boolean isEnderPearlUsed() { @@ -104,35 +59,13 @@ public class LobbyPlayer { this.enderPearlUsed = enderPearlUsed; } - public void nexthHiderState() { - if(this.hiderState == PlayerHiderState.SHOW_ALL) { - this.hiderState = PlayerHiderState.SHOW_TEAM; - } - else if(this.hiderState == PlayerHiderState.SHOW_TEAM) { - this.hiderState = PlayerHiderState.SHOW_NOBODY; - } - else - this.hiderState = PlayerHiderState.SHOW_ALL; - } - - public enum PlayerHiderState { - SHOW_ALL("§aAlle Spieler"), - SHOW_TEAM("§6Nur Teammitglieder"), - SHOW_NOBODY("§cKeine Spieler"); - - private String name; - - private PlayerHiderState(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - public static LobbyPlayer getLobbyPlayer(UUID uuid) { LobbyPlayer lobbyPlayer = cache.get(uuid); return lobbyPlayer == null ? new LobbyPlayer(uuid) : lobbyPlayer; } + + public static LobbyPlayer getLobbyPlayer(Player player) { + return getLobbyPlayer(player.getUniqueId()); + } + } diff --git a/src/plugin.yml b/src/plugin.yml index 488c080..31633be 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -4,4 +4,7 @@ author: Yaruma3341 depend: - SpigotCore main: de.steamwar.lobby.LobbySystem -api-version: "1.13" \ No newline at end of file +api-version: "1.13" + +commands: + fly: \ No newline at end of file -- 2.39.2 From 631436d064cfb63654560531988b8d84d75f14f5 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 16:13:02 +0100 Subject: [PATCH 2/8] Update LobbySystem --- .../lobby/listener/ParticleListener.java | 33 +++++---- .../lobby/particle/CustomParticle.java | 69 +++++++++++++++++++ src/de/steamwar/lobby/utils/ItemBuilder.java | 3 +- src/de/steamwar/lobby/utils/LobbyPlayer.java | 17 +++-- 4 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 src/de/steamwar/lobby/particle/CustomParticle.java diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index e43a1d8..a7d3a12 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -19,12 +19,12 @@ package de.steamwar.lobby.listener; +import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.inventories.ParticleInventory; -import de.steamwar.lobby.utils.LobbyParticle; +import de.steamwar.lobby.particle.CustomParticle; import de.steamwar.lobby.utils.LobbyPlayer; -import org.bukkit.Color; -import org.bukkit.Particle; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -37,6 +37,16 @@ import java.util.Random; public class ParticleListener implements Listener { private static Random random = new Random(); + private static int deg = 0; + + public ParticleListener() { + Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> { + deg++; + if (deg > 360) { + deg = 0; + } + }, 0, 1); + } @EventHandler(priority = EventPriority.NORMAL) public void handlePlayerInteract(PlayerInteractEvent event) { @@ -51,21 +61,10 @@ public class ParticleListener implements Listener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - LobbyParticle lobbyParticle = lobbyPlayer.getLobbyParticle(); - Particle particle = lobbyParticle.getParticle(); + CustomParticle particle = lobbyPlayer.getParticle(); + if (particle == null) return; - - if (particle == Particle.REDSTONE) { - Particle.DustOptions dust = new Particle.DustOptions(Color.fromRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextFloat() / 2 + 1); - player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5, dust); - return; - } - - if (lobbyParticle.isCustomVelocity()) { - player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5, lobbyParticle.getParticle_vx(), lobbyParticle.getParticle_vy(), lobbyParticle.getParticle_vz(), lobbyParticle.getParticle_time()); - } else { - player.getWorld().spawnParticle(particle, player.getLocation().add(0.0D, 0.2D, 0.0D), 5); - } + particle.particle(player.getWorld(), player, deg); } diff --git a/src/de/steamwar/lobby/particle/CustomParticle.java b/src/de/steamwar/lobby/particle/CustomParticle.java new file mode 100644 index 0000000..8cb9b4c --- /dev/null +++ b/src/de/steamwar/lobby/particle/CustomParticle.java @@ -0,0 +1,69 @@ +package de.steamwar.lobby.particle; + +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.lobby.utils.LobbyParticle; +import de.steamwar.lobby.utils.LobbyPlayer; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import sun.awt.image.OffScreenImage; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public abstract class CustomParticle { + + private static final List emptyLore = new ArrayList<>(); + private static Random random = new Random(); + + protected final Color randomColor() { + return Color.fromRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256)); + } + + protected final float randomSize() { + return random.nextFloat() / 2 + 1; + } + + protected final Particle.DustOptions getParticleDust() { + return new Particle.DustOptions(randomColor(), randomSize()); + } + + protected final Particle.DustOptions getParticleDust(float size) { + return new Particle.DustOptions(randomColor(), size); + } + + protected final Particle.DustOptions getParticleDust(int r, int g, int b) { + return new Particle.DustOptions(Color.fromRGB(r, g, b), randomSize()); + } + + protected final Particle.DustOptions getParticleDust(int r, int g, int b, float size) { + return new Particle.DustOptions(Color.fromRGB(r, g, b), size); + } + + private Material material; + private String name; + private List lore; + + public CustomParticle(Material material, String name, List lore) { + if (lore == null) { + lore = emptyLore; + } + this.material = material; + this.name = name; + this.lore = lore; + } + + public final void add(SWInventory swInventory, int pos, LobbyPlayer lobbyPlayer) { + SWItem swItem = new SWItem(material, name, lore, false, clickType -> { + lobbyPlayer.setParticle(this); + }); + swInventory.setItem(pos, swItem); + } + + public abstract void particle(World world, Player player, int deg); + +} diff --git a/src/de/steamwar/lobby/utils/ItemBuilder.java b/src/de/steamwar/lobby/utils/ItemBuilder.java index fd84bf7..6c411f6 100644 --- a/src/de/steamwar/lobby/utils/ItemBuilder.java +++ b/src/de/steamwar/lobby/utils/ItemBuilder.java @@ -20,6 +20,7 @@ package de.steamwar.lobby.utils; import java.util.ArrayList; +import java.util.List; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -62,7 +63,7 @@ public class ItemBuilder { return this; } - public ItemBuilder addLore(ArrayList lore) { + public ItemBuilder addLore(List lore) { meta.setLore(lore); return this; } diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index a4d45e9..64900ef 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,6 +19,7 @@ package de.steamwar.lobby.utils; +import de.steamwar.lobby.particle.CustomParticle; import org.bukkit.entity.Player; import java.util.HashMap; @@ -29,18 +30,14 @@ public class LobbyPlayer { private static Map cache = new HashMap<>(); - private LobbyParticle lobbyParticle; + private CustomParticle customParticle; private boolean enderPearlUsed; private boolean fly; private LobbyPlayer(UUID uuid) { cache.put(uuid, this); - lobbyParticle = new LobbyParticle(); - } - - public LobbyParticle getLobbyParticle() { - return lobbyParticle; + customParticle = null; } public boolean isFly() { @@ -59,6 +56,14 @@ public class LobbyPlayer { this.enderPearlUsed = enderPearlUsed; } + public CustomParticle getParticle() { + return customParticle; + } + + public void setParticle(CustomParticle customParticle) { + this.customParticle = customParticle; + } + public static LobbyPlayer getLobbyPlayer(UUID uuid) { LobbyPlayer lobbyPlayer = cache.get(uuid); return lobbyPlayer == null ? new LobbyPlayer(uuid) : lobbyPlayer; -- 2.39.2 From d41815ff8dde2efae93e95f651f17a05a0177ab5 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 17:46:45 +0100 Subject: [PATCH 3/8] Update ParticleSystem --- .../lobby/inventories/ParticleInventory.java | 87 ++++++++++--------- .../lobby/listener/ParticleListener.java | 5 +- .../lobby/listener/PlayerSeatListener.java | 19 ++++ .../lobby/particle/FunctionalParticle.java | 45 ++++++++++ .../lobby/particle/SimpleParticle.java | 68 +++++++++++++++ ...stomParticle.java => SpecialParticle.java} | 35 ++++++-- .../lobby/particle/WingsParticle.java | 65 ++++++++++++++ .../steamwar/lobby/utils/LobbyParticle.java | 57 ------------ src/de/steamwar/lobby/utils/LobbyPlayer.java | 14 +-- 9 files changed, 278 insertions(+), 117 deletions(-) create mode 100644 src/de/steamwar/lobby/particle/FunctionalParticle.java create mode 100644 src/de/steamwar/lobby/particle/SimpleParticle.java rename src/de/steamwar/lobby/particle/{CustomParticle.java => SpecialParticle.java} (61%) create mode 100644 src/de/steamwar/lobby/particle/WingsParticle.java delete mode 100644 src/de/steamwar/lobby/utils/LobbyParticle.java diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 7ad5c68..182366f 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -20,8 +20,9 @@ package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import de.steamwar.lobby.utils.LobbyParticle; +import de.steamwar.lobby.particle.FunctionalParticle; +import de.steamwar.lobby.particle.SimpleParticle; +import de.steamwar.lobby.particle.SpecialParticle; import de.steamwar.lobby.utils.LobbyPlayer; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; @@ -38,11 +39,38 @@ public class ParticleInventory { private static List lore = Arrays.asList("§aKlicken zum Auswählen"); + private static SpecialParticle SNEEZE = new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01); + private static SpecialParticle SMOKE = new SimpleParticle(Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01); + private static SpecialParticle FLAME = new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA); + private static SpecialParticle WATER = new SimpleParticle(Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER); + private static SpecialParticle HEART = new FunctionalParticle(Material.RED_DYE, "§cHerzen", lore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5)); + private static SpecialParticle NOTES = new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", lore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5)); + private static SpecialParticle NAUTILIS = new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01); + + private static SpecialParticle SNOWBALL = new SimpleParticle(Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01); + private static SpecialParticle EFFECT = new SimpleParticle(Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 0F, 0.2F, 0F, 0.01); + private static SpecialParticle CAMPFIRE = new SimpleParticle(Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01); + private static SpecialParticle MAGIC = new SimpleParticle(Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01); + private static SpecialParticle RAGE = new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01); + private static SpecialParticle SLIME = new SimpleParticle(Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME); + private static SpecialParticle MOB = new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB); + + private static SpecialParticle DAMAGE = new SimpleParticle(Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01); + private static SpecialParticle WITCH = new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH); + private static SpecialParticle ENCHANTING = new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE); + private static SpecialParticle FRIEND = new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01); + private static SpecialParticle FIRE = new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 0F, 0.2F, 0F, 0.01); + private static SpecialParticle TOTEM = new SimpleParticle(Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 0F, 0.2F, 0F, 0.01); + private static SpecialParticle END = new SimpleParticle(Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01); + + private static SpecialParticle[] row_1 = new SpecialParticle[]{SNEEZE, SMOKE, FLAME, WATER, HEART, NOTES, NAUTILIS}; + private static SpecialParticle[] row_2 = new SpecialParticle[]{SNOWBALL, EFFECT, CAMPFIRE, MAGIC, RAGE, SLIME, MOB}; + private static SpecialParticle[] row_3 = new SpecialParticle[]{DAMAGE, WITCH, ENCHANTING, FRIEND, FIRE, TOTEM, END}; + private static SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); - LobbyParticle lobbyParticle = lobbyPlayer.getLobbyParticle(); SWInventory swInventory; if (userGroup == UserGroup.Member) { @@ -51,54 +79,27 @@ public class ParticleInventory { swInventory = new SWInventory(player, 9*6, "§6Partikel"); } - add(swInventory, Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 10, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 11, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA, 12, player, lobbyParticle); - add(swInventory, Material.RED_DYE, "§cHerzen", lore, Particle.HEART, 13, player, lobbyParticle); - add(swInventory, Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER, 14, player, lobbyParticle); - add(swInventory, Material.NOTE_BLOCK, "§eNoten", lore, Particle.NOTE, 15, player, lobbyParticle); - add(swInventory, Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 16, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); - - add(swInventory, Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 19, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 20, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 21, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.01); - add(swInventory, Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 22, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 23, player, lobbyParticle, true, 0.2F, 0.02F, 0.2F, 0.01); - add(swInventory, Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME, 24, player, lobbyParticle); - add(swInventory, Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB, 25, player, lobbyParticle); + add(swInventory, row_1, 10, lobbyPlayer); + add(swInventory, row_2, 19, lobbyPlayer); if (userGroup == UserGroup.Member) { - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 31, player, lobbyParticle); + swInventory.setItem(31, Material.BARRIER, "§8Keine Partikel", lore, false, clickType -> { + lobbyPlayer.setParticle(null); + }); } else { - add(swInventory, Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 28, player, lobbyParticle, true, 0.2F, 0F, 0.2F, 0.01); - add(swInventory, Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH, 29, player, lobbyParticle); - add(swInventory, Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE, 30, player, lobbyParticle); - add(swInventory, Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 31, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - add(swInventory, Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 32, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.01); - add(swInventory, Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 33, player, lobbyParticle, true, 0F, 0.2F, 0F, 0.2); - add(swInventory, Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 34, player, lobbyParticle, true, 0.2F, 0.2F, 0.2F, 0.01); - - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 40, player, lobbyParticle); + add(swInventory, row_3, 28, lobbyPlayer); + swInventory.setItem(40, Material.BARRIER, "§8Keine Partikel", lore, false, clickType -> { + lobbyPlayer.setParticle(null); + }); } return swInventory; } - private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyParticle lobbyParticle, boolean customVelocity, float vx, float vy, float vz, double time) { - SWItem swItem = new SWItem(material, name, lore, false, clickType -> { - lobbyParticle.setParticle(particle, customVelocity); - lobbyParticle.setParticle(vx, vy, vz, time); - player.closeInventory(); - }); - swInventory.setItem(slot, swItem); - } - - private static void add(SWInventory swInventory, Material material, String name, List lore, Particle particle, int slot, Player player, LobbyParticle lobbyParticle) { - SWItem swItem = new SWItem(material, name, lore, false, clickType -> { - lobbyParticle.setParticle(particle); - player.closeInventory(); - }); - swInventory.setItem(slot, swItem); + private static void add(SWInventory swInventory, SpecialParticle[] specialParticles, int index, LobbyPlayer lobbyPlayer) { + for (int i = 0; i < specialParticles.length; i++) { + specialParticles[i].add(swInventory, i + index, lobbyPlayer); + } } public static void openParticleInventory(Player player) { diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index a7d3a12..aed2945 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -22,7 +22,7 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.inventories.LobbyInventory; import de.steamwar.lobby.inventories.ParticleInventory; -import de.steamwar.lobby.particle.CustomParticle; +import de.steamwar.lobby.particle.SpecialParticle; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -36,7 +36,6 @@ import java.util.Random; public class ParticleListener implements Listener { - private static Random random = new Random(); private static int deg = 0; public ParticleListener() { @@ -61,7 +60,7 @@ public class ParticleListener implements Listener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - CustomParticle particle = lobbyPlayer.getParticle(); + SpecialParticle particle = lobbyPlayer.getParticle(); if (particle == null) return; particle.particle(player.getWorld(), player, deg); diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index 75b92ea..89a8cac 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.lobby.listener; import org.bukkit.GameMode; diff --git a/src/de/steamwar/lobby/particle/FunctionalParticle.java b/src/de/steamwar/lobby/particle/FunctionalParticle.java new file mode 100644 index 0000000..2a8090a --- /dev/null +++ b/src/de/steamwar/lobby/particle/FunctionalParticle.java @@ -0,0 +1,45 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.lobby.particle; + +import org.apache.logging.log4j.util.TriConsumer; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.List; + +public class FunctionalParticle extends SpecialParticle { + + private TriConsumer particleSpawn; + + public FunctionalParticle(Material material, String name, List lore, TriConsumer particleSpawn) { + super(material, name, lore); + this.particleSpawn = particleSpawn; + } + + @Override + public void particle(World world, Player player, int deg) { + particleSpawn.accept(world, player, deg); + } + +} diff --git a/src/de/steamwar/lobby/particle/SimpleParticle.java b/src/de/steamwar/lobby/particle/SimpleParticle.java new file mode 100644 index 0000000..14930cb --- /dev/null +++ b/src/de/steamwar/lobby/particle/SimpleParticle.java @@ -0,0 +1,68 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.*; +import org.bukkit.entity.Player; + +import java.util.List; + +public class SimpleParticle extends SpecialParticle { + + private Particle particle; + private boolean customVelocity = false; + private float vx; + private float vy; + private float vz; + private double time; + + public SimpleParticle(Material material, String name, List lore, Particle particle) { + super(material, name, lore); + this.particle = particle; + } + + public SimpleParticle(Material material, String name, List lore, Particle particle, float vx, float vy, float vz, double time) { + super(material, name, lore); + this.particle = particle; + customVelocity = true; + this.vx = vx; + this.vy = vy; + this.vz = vz; + this.time = time; + } + + @Override + public void particle(World world, Player player, int deg) { + Location location = player.getLocation().add(0.0, 0.2, 0.0); + if (particle == Particle.REDSTONE) { + world.spawnParticle(particle, location, 5, getParticleDust()); + return; + } + + if (customVelocity) { + world.spawnParticle(particle, location, 5, vx, vy, vz, time); + } else { + world.spawnParticle(particle, location, 5); + } + } + +} diff --git a/src/de/steamwar/lobby/particle/CustomParticle.java b/src/de/steamwar/lobby/particle/SpecialParticle.java similarity index 61% rename from src/de/steamwar/lobby/particle/CustomParticle.java rename to src/de/steamwar/lobby/particle/SpecialParticle.java index 8cb9b4c..6cc7647 100644 --- a/src/de/steamwar/lobby/particle/CustomParticle.java +++ b/src/de/steamwar/lobby/particle/SpecialParticle.java @@ -1,21 +1,39 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.lobby.particle; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; -import de.steamwar.lobby.utils.LobbyParticle; +import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.entity.Player; -import sun.awt.image.OffScreenImage; import java.util.ArrayList; import java.util.List; import java.util.Random; -public abstract class CustomParticle { +public abstract class SpecialParticle { private static final List emptyLore = new ArrayList<>(); private static Random random = new Random(); @@ -48,7 +66,7 @@ public abstract class CustomParticle { private String name; private List lore; - public CustomParticle(Material material, String name, List lore) { + public SpecialParticle(Material material, String name, List lore) { if (lore == null) { lore = emptyLore; } @@ -57,11 +75,14 @@ public abstract class CustomParticle { this.lore = lore; } - public final void add(SWInventory swInventory, int pos, LobbyPlayer lobbyPlayer) { - SWItem swItem = new SWItem(material, name, lore, false, clickType -> { + public final SWItem getItem(LobbyPlayer lobbyPlayer) { + return new SWItem(material, name, lore, false, clickType -> { lobbyPlayer.setParticle(this); }); - swInventory.setItem(pos, swItem); + } + + public final void add(SWInventory swInventory, int pos, LobbyPlayer lobbyPlayer) { + swInventory.setItem(pos, getItem(lobbyPlayer)); } public abstract void particle(World world, Player player, int deg); diff --git a/src/de/steamwar/lobby/particle/WingsParticle.java b/src/de/steamwar/lobby/particle/WingsParticle.java new file mode 100644 index 0000000..84ec2d0 --- /dev/null +++ b/src/de/steamwar/lobby/particle/WingsParticle.java @@ -0,0 +1,65 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class WingsParticle extends SpecialParticle { + + private static class Relative { + + private double up = 0; + private double side = 0; + + public Relative(double up, double side) { + this.up = up; + this.side = side; + } + + } + + private static final Set particleRelatives = new HashSet<>(); + + private Particle particle; + + public WingsParticle(Material material, String name, List lore, Particle particle) { + super(material, name, lore); + this.particle = particle; + } + + @Override + public void particle(World world, Player player, int deg) { + Location location = player.getLocation().add(0, 1.7, 0); + particleRelatives.forEach(relative -> { + + }); + } + +} diff --git a/src/de/steamwar/lobby/utils/LobbyParticle.java b/src/de/steamwar/lobby/utils/LobbyParticle.java deleted file mode 100644 index b6789ef..0000000 --- a/src/de/steamwar/lobby/utils/LobbyParticle.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.steamwar.lobby.utils; - -import org.bukkit.Particle; - -public class LobbyParticle { - - private Particle particle; - private boolean customVelocity = false; - private float particle_vx = 0; - private float particle_vy = 0; - private float particle_vz = 0; - private double particle_time = 0.001; - - public Particle getParticle() { - return particle; - } - - public boolean isCustomVelocity() { - return customVelocity; - } - - public float getParticle_vx() { - return particle_vx; - } - - public float getParticle_vy() { - return particle_vy; - } - - public float getParticle_vz() { - return particle_vz; - } - - public double getParticle_time() { - return particle_time; - } - - public void setParticle(Particle particle) { - this.particle = particle; - this.customVelocity = false; - setParticle(0, 0, 0, 0.001); - } - - public void setParticle(Particle particle, boolean customVelocity) { - this.particle = particle; - this.customVelocity = customVelocity; - setParticle(0, 0, 0, 0.001); - } - - public void setParticle(float vx, float vy, float vz, double time) { - this.particle_vx = vx; - this.particle_vy = vy; - this.particle_vz = vz; - this.particle_time = time; - } - -} diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 64900ef..8709a0c 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,7 +19,7 @@ package de.steamwar.lobby.utils; -import de.steamwar.lobby.particle.CustomParticle; +import de.steamwar.lobby.particle.SpecialParticle; import org.bukkit.entity.Player; import java.util.HashMap; @@ -30,14 +30,14 @@ public class LobbyPlayer { private static Map cache = new HashMap<>(); - private CustomParticle customParticle; + private SpecialParticle specialParticle; private boolean enderPearlUsed; private boolean fly; private LobbyPlayer(UUID uuid) { cache.put(uuid, this); - customParticle = null; + specialParticle = null; } public boolean isFly() { @@ -56,12 +56,12 @@ public class LobbyPlayer { this.enderPearlUsed = enderPearlUsed; } - public CustomParticle getParticle() { - return customParticle; + public SpecialParticle getParticle() { + return specialParticle; } - public void setParticle(CustomParticle customParticle) { - this.customParticle = customParticle; + public void setParticle(SpecialParticle specialParticle) { + this.specialParticle = specialParticle; } public static LobbyPlayer getLobbyPlayer(UUID uuid) { -- 2.39.2 From b46e34f06be0642b7f9d51dfca37612461ff1a00 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 18:24:50 +0100 Subject: [PATCH 4/8] Update PlayerSeatListener --- .../lobby/listener/PlayerSeatListener.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index 89a8cac..5fa1fe6 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -20,6 +20,7 @@ package de.steamwar.lobby.listener; import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.type.Stairs; @@ -33,8 +34,43 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.spigotmc.event.entity.EntityDismountEvent; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + public class PlayerSeatListener implements Listener { + private class SeatLocation { + + private int x; + private int y; + private int z; + + public SeatLocation(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SeatLocation)) return false; + SeatLocation that = (SeatLocation) o; + return x == that.x && + y == that.y && + z == that.z; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + + } + + private Set seats = new HashSet<>(); + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) @@ -58,7 +94,13 @@ public class PlayerSeatListener implements Listener { if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) return; - Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(event.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.ARROW); + Location location = event.getClickedBlock().getLocation(); + SeatLocation seatLocation = getSeatLocation(location); + if (seats.contains(seatLocation)) + return; + seats.add(seatLocation); + + Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW); arrow.setGravity(false); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.addPassenger(event.getPlayer()); @@ -67,6 +109,8 @@ public class PlayerSeatListener implements Listener { @EventHandler public void onEntityDismount(EntityDismountEvent event) { + seats.remove(getSeatLocation(event.getDismounted().getLocation())); + if (event.getDismounted().getType() != EntityType.ARROW) return; @@ -82,4 +126,8 @@ public class PlayerSeatListener implements Listener { event.getPlayer().getVehicle().remove(); } + public SeatLocation getSeatLocation(Location location) { + return new SeatLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + } -- 2.39.2 From 2aa00b59c42054bcd135d7488de8eb9c51aba5f6 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 19 Nov 2020 19:04:26 +0100 Subject: [PATCH 5/8] Update PlayerSeatListener --- src/de/steamwar/lobby/listener/PlayerSeatListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index 5fa1fe6..dc824a4 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -40,7 +40,7 @@ import java.util.Set; public class PlayerSeatListener implements Listener { - private class SeatLocation { + private static class SeatLocation { private int x; private int y; -- 2.39.2 From 3d55bd5df6a4a2e6e65e4a2bb248cac515586f62 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 20 Nov 2020 10:06:22 +0100 Subject: [PATCH 6/8] Update PlayerMoveListener --- .../steamwar/lobby/commands/FlyCommand.java | 6 +- .../lobby/listener/PlayerMoveListener.java | 8 +-- .../lobby/particle/WingsParticle.java | 65 ------------------- 3 files changed, 7 insertions(+), 72 deletions(-) delete mode 100644 src/de/steamwar/lobby/particle/WingsParticle.java diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index 268593d..7e266a6 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -29,18 +29,18 @@ import org.bukkit.entity.Player; public class FlyCommand implements CommandExecutor { - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) + if(!(sender instanceof Player)) { return false; + } Player player = (Player) sender; SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); if (userGroup == UserGroup.Member) { - player.sendMessage("§cDu verfügst nicht über die benötigten Rechte!"); + player.sendMessage("§cUnbekannter Befehl."); return false; } diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index 2d4b9f0..72fe02b 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -28,13 +28,13 @@ import org.bukkit.util.Vector; public class PlayerMoveListener implements Listener { + private static final Vector borderMinVector = new Vector(Config.BorderMinX, Config.BorderMinY, Config.BorderMinZ); + private static final Vector borderMaxVector = new Vector(Config.BorderMaxX, Config.BorderMaxY, Config.BorderMaxZ); + @EventHandler public void handleWorldBorder(PlayerMoveEvent event) { Location to = event.getTo(); - if (!isInRegion( - new Vector(Config.BorderMinX, Config.BorderMinY, Config.BorderMinZ), - new Vector(Config.BorderMaxX, Config.BorderMaxY, Config.BorderMaxZ), - to.toVector())) { + if (!isInRegion(borderMinVector, borderMaxVector, to.toVector())) { event.getPlayer().teleport(event.getFrom()); } } diff --git a/src/de/steamwar/lobby/particle/WingsParticle.java b/src/de/steamwar/lobby/particle/WingsParticle.java deleted file mode 100644 index 84ec2d0..0000000 --- a/src/de/steamwar/lobby/particle/WingsParticle.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.lobby.particle; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class WingsParticle extends SpecialParticle { - - private static class Relative { - - private double up = 0; - private double side = 0; - - public Relative(double up, double side) { - this.up = up; - this.side = side; - } - - } - - private static final Set particleRelatives = new HashSet<>(); - - private Particle particle; - - public WingsParticle(Material material, String name, List lore, Particle particle) { - super(material, name, lore); - this.particle = particle; - } - - @Override - public void particle(World world, Player player, int deg) { - Location location = player.getLocation().add(0, 1.7, 0); - particleRelatives.forEach(relative -> { - - }); - } - -} -- 2.39.2 From c0a09b8634c940e7bf8ea8814a98d3f60478f93e Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 28 Nov 2020 08:13:55 +0100 Subject: [PATCH 7/8] Rework Particles --- .../steamwar/lobby/commands/FlyCommand.java | 2 +- .../lobby/inventories/ParticleInventory.java | 7 +++-- .../lobby/particle/FunctionalParticle.java | 9 +++--- .../lobby/particle/ParticleFunction.java | 30 +++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 src/de/steamwar/lobby/particle/ParticleFunction.java diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index 7e266a6..deb780c 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -31,7 +31,7 @@ public class FlyCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { + if (!(sender instanceof Player)) { return false; } diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 182366f..7b29c32 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -35,7 +35,8 @@ import java.util.List; public class ParticleInventory { - private ParticleInventory() {} + private ParticleInventory() { + } private static List lore = Arrays.asList("§aKlicken zum Auswählen"); @@ -74,9 +75,9 @@ public class ParticleInventory { SWInventory swInventory; if (userGroup == UserGroup.Member) { - swInventory = new SWInventory(player, 9*5, "§6Partikel"); + swInventory = new SWInventory(player, 9 * 5, "§6Partikel"); } else { - swInventory = new SWInventory(player, 9*6, "§6Partikel"); + swInventory = new SWInventory(player, 9 * 6, "§6Partikel"); } add(swInventory, row_1, 10, lobbyPlayer); diff --git a/src/de/steamwar/lobby/particle/FunctionalParticle.java b/src/de/steamwar/lobby/particle/FunctionalParticle.java index 2a8090a..c8bc297 100644 --- a/src/de/steamwar/lobby/particle/FunctionalParticle.java +++ b/src/de/steamwar/lobby/particle/FunctionalParticle.java @@ -21,7 +21,6 @@ package de.steamwar.lobby.particle; -import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; @@ -30,16 +29,16 @@ import java.util.List; public class FunctionalParticle extends SpecialParticle { - private TriConsumer particleSpawn; + private ParticleFunction particleFunction; - public FunctionalParticle(Material material, String name, List lore, TriConsumer particleSpawn) { + public FunctionalParticle(Material material, String name, List lore, ParticleFunction particleFunction) { super(material, name, lore); - this.particleSpawn = particleSpawn; + this.particleFunction = particleFunction; } @Override public void particle(World world, Player player, int deg) { - particleSpawn.accept(world, player, deg); + particleFunction.accept(world, player, deg); } } diff --git a/src/de/steamwar/lobby/particle/ParticleFunction.java b/src/de/steamwar/lobby/particle/ParticleFunction.java new file mode 100644 index 0000000..13f475a --- /dev/null +++ b/src/de/steamwar/lobby/particle/ParticleFunction.java @@ -0,0 +1,30 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * / + */ + +package de.steamwar.lobby.particle; + +import org.bukkit.World; +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface ParticleFunction { + void accept(World world, Player player, Integer time); +} -- 2.39.2 From 4d991e3089507ed997aceb6902b63df7b622c4a1 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Dec 2020 10:52:35 +0100 Subject: [PATCH 8/8] Improve Code Style --- .../steamwar/lobby/commands/FlyCommand.java | 4 +- .../lobby/inventories/ParticleInventory.java | 57 +++++++++---------- .../lobby/listener/DoubleJumpListener.java | 8 +-- .../lobby/listener/ParticleListener.java | 5 +- .../lobby/listener/PlayerMoveListener.java | 19 +------ .../lobby/listener/PlayerSeatListener.java | 3 - .../lobby/particle/SpecialParticle.java | 19 +------ src/de/steamwar/lobby/utils/ItemBuilder.java | 5 +- 8 files changed, 36 insertions(+), 84 deletions(-) diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index deb780c..0557f74 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -31,9 +31,7 @@ public class FlyCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - return false; - } + if (!(sender instanceof Player)) return false; Player player = (Player) sender; SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index 7b29c32..6291c16 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -38,47 +38,42 @@ public class ParticleInventory { private ParticleInventory() { } - private static List lore = Arrays.asList("§aKlicken zum Auswählen"); + private static final List lore = Arrays.asList("§aKlicken zum Auswählen"); - private static SpecialParticle SNEEZE = new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01); - private static SpecialParticle SMOKE = new SimpleParticle(Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01); - private static SpecialParticle FLAME = new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA); - private static SpecialParticle WATER = new SimpleParticle(Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER); - private static SpecialParticle HEART = new FunctionalParticle(Material.RED_DYE, "§cHerzen", lore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5)); - private static SpecialParticle NOTES = new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", lore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5)); - private static SpecialParticle NAUTILIS = new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01); + private static final SpecialParticle SNEEZE = new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01); + private static final SpecialParticle SMOKE = new SimpleParticle(Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01); + private static final SpecialParticle FLAME = new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA); + private static final SpecialParticle WATER = new SimpleParticle(Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER); + private static final SpecialParticle HEART = new FunctionalParticle(Material.RED_DYE, "§cHerzen", lore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5)); + private static final SpecialParticle NOTES = new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", lore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5)); + private static final SpecialParticle NAUTILIS = new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01); - private static SpecialParticle SNOWBALL = new SimpleParticle(Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01); - private static SpecialParticle EFFECT = new SimpleParticle(Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 0F, 0.2F, 0F, 0.01); - private static SpecialParticle CAMPFIRE = new SimpleParticle(Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01); - private static SpecialParticle MAGIC = new SimpleParticle(Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01); - private static SpecialParticle RAGE = new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01); - private static SpecialParticle SLIME = new SimpleParticle(Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME); - private static SpecialParticle MOB = new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB); + private static final SpecialParticle SNOWBALL = new SimpleParticle(Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01); + private static final SpecialParticle EFFECT = new SimpleParticle(Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 0F, 0.2F, 0F, 0.01); + private static final SpecialParticle CAMPFIRE = new SimpleParticle(Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01); + private static final SpecialParticle MAGIC = new SimpleParticle(Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01); + private static final SpecialParticle RAGE = new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01); + private static final SpecialParticle SLIME = new SimpleParticle(Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME); + private static final SpecialParticle MOB = new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB); - private static SpecialParticle DAMAGE = new SimpleParticle(Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01); - private static SpecialParticle WITCH = new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH); - private static SpecialParticle ENCHANTING = new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE); - private static SpecialParticle FRIEND = new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01); - private static SpecialParticle FIRE = new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 0F, 0.2F, 0F, 0.01); - private static SpecialParticle TOTEM = new SimpleParticle(Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 0F, 0.2F, 0F, 0.01); - private static SpecialParticle END = new SimpleParticle(Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01); + private static final SpecialParticle DAMAGE = new SimpleParticle(Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01); + private static final SpecialParticle WITCH = new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH); + private static final SpecialParticle ENCHANTING = new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE); + private static final SpecialParticle FRIEND = new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01); + private static final SpecialParticle FIRE = new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 0F, 0.2F, 0F, 0.01); + private static final SpecialParticle TOTEM = new SimpleParticle(Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 0F, 0.2F, 0F, 0.01); + private static final SpecialParticle END = new SimpleParticle(Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01); - private static SpecialParticle[] row_1 = new SpecialParticle[]{SNEEZE, SMOKE, FLAME, WATER, HEART, NOTES, NAUTILIS}; - private static SpecialParticle[] row_2 = new SpecialParticle[]{SNOWBALL, EFFECT, CAMPFIRE, MAGIC, RAGE, SLIME, MOB}; - private static SpecialParticle[] row_3 = new SpecialParticle[]{DAMAGE, WITCH, ENCHANTING, FRIEND, FIRE, TOTEM, END}; + private static final SpecialParticle[] row_1 = new SpecialParticle[]{SNEEZE, SMOKE, FLAME, WATER, HEART, NOTES, NAUTILIS}; + private static final SpecialParticle[] row_2 = new SpecialParticle[]{SNOWBALL, EFFECT, CAMPFIRE, MAGIC, RAGE, SLIME, MOB}; + private static final SpecialParticle[] row_3 = new SpecialParticle[]{DAMAGE, WITCH, ENCHANTING, FRIEND, FIRE, TOTEM, END}; private static SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); - SWInventory swInventory; - if (userGroup == UserGroup.Member) { - swInventory = new SWInventory(player, 9 * 5, "§6Partikel"); - } else { - swInventory = new SWInventory(player, 9 * 6, "§6Partikel"); - } + SWInventory swInventory = new SWInventory(player, 9 * (userGroup == UserGroup.Member ? 5 : 6), "§6Partikel"); add(swInventory, row_1, 10, lobbyPlayer); add(swInventory, row_2, 19, lobbyPlayer); diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index 05c65f2..9a80051 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -69,12 +69,8 @@ public class DoubleJumpListener implements Listener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) { - return; - } - if (LobbyPlayer.getLobbyPlayer(player).isFly()) { - return; - } + if (player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) return; + if (LobbyPlayer.getLobbyPlayer(player).isFly()) return; player.setAllowFlight(true); if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index aed2945..42c4cc0 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -32,8 +32,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; -import java.util.Random; - public class ParticleListener implements Listener { private static int deg = 0; @@ -50,8 +48,7 @@ public class ParticleListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if(event.getMaterial() != LobbyInventory.PARTICLE) - return; + if (event.getMaterial() != LobbyInventory.PARTICLE) return; ParticleInventory.openParticleInventory(player); } diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index 72fe02b..e7d284d 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -34,27 +34,10 @@ public class PlayerMoveListener implements Listener { @EventHandler public void handleWorldBorder(PlayerMoveEvent event) { Location to = event.getTo(); - if (!isInRegion(borderMinVector, borderMaxVector, to.toVector())) { + if (!to.toVector().isInAABB(borderMinVector, borderMaxVector)) { event.getPlayer().teleport(event.getFrom()); } } - private boolean isInRegion(Vector minPoint, Vector maxPoint, Vector location) { - int x = location.getBlockX(); - int y = location.getBlockY(); - int z = location.getBlockZ(); - - if (x >= minPoint.getBlockX() - && x <= maxPoint.getBlockX() - && y >= minPoint.getBlockY() - && y <= maxPoint.getBlockY() - && z >= minPoint.getBlockZ() - && z <= maxPoint.getBlockZ()) { - return true; - } else { - return false; - } - } - } diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index dc824a4..a0ac093 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -111,9 +111,6 @@ public class PlayerSeatListener implements Listener { public void onEntityDismount(EntityDismountEvent event) { seats.remove(getSeatLocation(event.getDismounted().getLocation())); - if (event.getDismounted().getType() != EntityType.ARROW) - return; - if (event.getEntityType() != EntityType.PLAYER) return; diff --git a/src/de/steamwar/lobby/particle/SpecialParticle.java b/src/de/steamwar/lobby/particle/SpecialParticle.java index 6cc7647..f8ffa2d 100644 --- a/src/de/steamwar/lobby/particle/SpecialParticle.java +++ b/src/de/steamwar/lobby/particle/SpecialParticle.java @@ -21,7 +21,6 @@ package de.steamwar.lobby.particle; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; -import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Color; import org.bukkit.Material; @@ -38,30 +37,18 @@ public abstract class SpecialParticle { private static final List emptyLore = new ArrayList<>(); private static Random random = new Random(); - protected final Color randomColor() { + protected static Color randomColor() { return Color.fromRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256)); } - protected final float randomSize() { + protected static float randomSize() { return random.nextFloat() / 2 + 1; } - protected final Particle.DustOptions getParticleDust() { + protected static Particle.DustOptions getParticleDust() { return new Particle.DustOptions(randomColor(), randomSize()); } - protected final Particle.DustOptions getParticleDust(float size) { - return new Particle.DustOptions(randomColor(), size); - } - - protected final Particle.DustOptions getParticleDust(int r, int g, int b) { - return new Particle.DustOptions(Color.fromRGB(r, g, b), randomSize()); - } - - protected final Particle.DustOptions getParticleDust(int r, int g, int b, float size) { - return new Particle.DustOptions(Color.fromRGB(r, g, b), size); - } - private Material material; private String name; private List lore; diff --git a/src/de/steamwar/lobby/utils/ItemBuilder.java b/src/de/steamwar/lobby/utils/ItemBuilder.java index 6c411f6..c78e28e 100644 --- a/src/de/steamwar/lobby/utils/ItemBuilder.java +++ b/src/de/steamwar/lobby/utils/ItemBuilder.java @@ -19,15 +19,14 @@ package de.steamwar.lobby.utils; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.List; + public class ItemBuilder { private ItemStack item; -- 2.39.2