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..0557f74 --- /dev/null +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -0,0 +1,54 @@ +/* + 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("§cUnbekannter Befehl."); + 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..6291c16 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -20,7 +20,9 @@ package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; +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; @@ -33,70 +35,67 @@ import java.util.List; public class ParticleInventory { - private 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 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 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 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 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.getUniqueId()); + 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, 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.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, row_1, 10, lobbyPlayer); + add(swInventory, row_2, 19, lobbyPlayer); if (userGroup == UserGroup.Member) { - add(swInventory, Material.BARRIER, "§8Keine Partikel", lore, null, 31, player, lobbyPlayer); + 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, 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.BARRIER, "§8Keine Partikel", lore, null, 40, player, lobbyPlayer); + 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, LobbyPlayer lobbyPlayer, 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); - 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) { - SWItem swItem = new SWItem(material, name, lore, false, clickType -> { - lobbyPlayer.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/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index d094c5a..9a80051 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,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 (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..42c4cc0 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -19,11 +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.particle.SpecialParticle; 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; @@ -31,17 +32,23 @@ 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 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) { Player player = event.getPlayer(); - if(event.getMaterial() != LobbyInventory.PARTICLE) - return; + if (event.getMaterial() != LobbyInventory.PARTICLE) return; ParticleInventory.openParticleInventory(player); } @@ -49,21 +56,11 @@ 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); + SpecialParticle 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 (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()); - } 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/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..e7d284d 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; @@ -29,36 +28,15 @@ 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())) - event.getPlayer().teleport(new Location( - Bukkit.getWorlds().get(0), - Config.SpawnX, - Config.SpawnY, - Config.SpawnZ, - Config.Yaw, - Config.Pitch)); - } - - 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; + if (!to.toVector().isInAABB(borderMinVector, borderMaxVector)) { + event.getPlayer().teleport(event.getFrom()); + } } diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java new file mode 100644 index 0000000..a0ac093 --- /dev/null +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -0,0 +1,130 @@ +/* + 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; +import org.bukkit.Location; +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; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +public class PlayerSeatListener implements Listener { + + private static 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) + 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; + + 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()); + arrow.setPersistent(true); + } + + @EventHandler + public void onEntityDismount(EntityDismountEvent event) { + seats.remove(getSeatLocation(event.getDismounted().getLocation())); + + if (event.getEntityType() != EntityType.PLAYER) + return; + + event.getDismounted().remove(); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer().isInsideVehicle()) + event.getPlayer().getVehicle().remove(); + } + + public SeatLocation getSeatLocation(Location location) { + return new SeatLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + +} 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/particle/FunctionalParticle.java b/src/de/steamwar/lobby/particle/FunctionalParticle.java new file mode 100644 index 0000000..c8bc297 --- /dev/null +++ b/src/de/steamwar/lobby/particle/FunctionalParticle.java @@ -0,0 +1,44 @@ +/* + * + * 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.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.List; + +public class FunctionalParticle extends SpecialParticle { + + private ParticleFunction particleFunction; + + public FunctionalParticle(Material material, String name, List lore, ParticleFunction particleFunction) { + super(material, name, lore); + this.particleFunction = particleFunction; + } + + @Override + public void particle(World world, Player player, int 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); +} 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/SpecialParticle.java b/src/de/steamwar/lobby/particle/SpecialParticle.java new file mode 100644 index 0000000..f8ffa2d --- /dev/null +++ b/src/de/steamwar/lobby/particle/SpecialParticle.java @@ -0,0 +1,77 @@ +/* + 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.LobbyPlayer; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public abstract class SpecialParticle { + + private static final List emptyLore = new ArrayList<>(); + private static Random random = new Random(); + + protected static Color randomColor() { + return Color.fromRGB(random.nextInt(256), random.nextInt(256), random.nextInt(256)); + } + + protected static float randomSize() { + return random.nextFloat() / 2 + 1; + } + + protected static Particle.DustOptions getParticleDust() { + return new Particle.DustOptions(randomColor(), randomSize()); + } + + private Material material; + private String name; + private List lore; + + public SpecialParticle(Material material, String name, List lore) { + if (lore == null) { + lore = emptyLore; + } + this.material = material; + this.name = name; + this.lore = lore; + } + + public final SWItem getItem(LobbyPlayer lobbyPlayer) { + return new SWItem(material, name, lore, false, clickType -> { + lobbyPlayer.setParticle(this); + }); + } + + 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/utils/ItemBuilder.java b/src/de/steamwar/lobby/utils/ItemBuilder.java index 686ffb8..c78e28e 100644 --- a/src/de/steamwar/lobby/utils/ItemBuilder.java +++ b/src/de/steamwar/lobby/utils/ItemBuilder.java @@ -19,14 +19,14 @@ package de.steamwar.lobby.utils; -import java.util.ArrayList; - 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; @@ -62,7 +62,7 @@ public class ItemBuilder { return this; } - public ItemBuilder addLore(ArrayList lore) { + public ItemBuilder addLore(List lore) { meta.setLore(lore); return this; } @@ -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/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 68857eb..8709a0c 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -19,7 +19,8 @@ package de.steamwar.lobby.utils; -import org.bukkit.Particle; +import de.steamwar.lobby.particle.SpecialParticle; +import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; @@ -29,71 +30,22 @@ 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 SpecialParticle specialParticle; private boolean enderPearlUsed; + private boolean fly; private LobbyPlayer(UUID uuid) { - this.hiderState = PlayerHiderState.SHOW_ALL; cache.put(uuid, this); + specialParticle = null; } - public PlayerHiderState getHiderState() { - return hiderState; + public boolean isFly() { + return fly; } - public void setHiderState(PlayerHiderState hiderState) { - this.hiderState = hiderState; - } - - 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 +56,21 @@ 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 SpecialParticle getParticle() { + return specialParticle; } - 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 void setParticle(SpecialParticle specialParticle) { + this.specialParticle = specialParticle; } 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