From 4b6276f40af223361e43876b9873678302790694 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 21:50:44 +0100 Subject: [PATCH 1/6] Add Fly Command --- src/de/steamwar/lobby/LobbySystem.java | 4 +- .../steamwar/lobby/commands/FlyCommand.java | 55 +++++++++++++++++++ src/de/steamwar/lobby/utils/LobbyPlayer.java | 14 +++++ src/plugin.yml | 5 +- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/lobby/commands/FlyCommand.java diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index f171e66..f3a301a 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; @@ -33,7 +34,6 @@ public class LobbySystem extends JavaPlugin { instance = this; PluginManager pm = Bukkit.getPluginManager(); - pm.registerEvents(new PlayerMoveListener(), instance); pm.registerEvents(new PlayerConnectionListener(), instance); pm.registerEvents(new PlayerInventoryListener(), instance); @@ -42,6 +42,8 @@ public class LobbySystem extends JavaPlugin { pm.registerEvents(new ParticleListener(), instance); pm.registerEvents(new PlayerHiderListener(), instance); pm.registerEvents(new EnderPearlListener(), instance); + + getCommand("fly").setExecutor(new FlyCommand()); } diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java new file mode 100644 index 0000000..7885739 --- /dev/null +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -0,0 +1,55 @@ +/* + 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; + } + +} \ No newline at end of file diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 68857eb..aabd3b5 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -20,6 +20,7 @@ package de.steamwar.lobby.utils; import org.bukkit.Particle; +import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; @@ -39,12 +40,21 @@ public class LobbyPlayer { private double particle_time = 0.001; private boolean enderPearlUsed; + private boolean fly; private LobbyPlayer(UUID uuid) { this.hiderState = PlayerHiderState.SHOW_ALL; cache.put(uuid, this); } + public boolean isFly() { + return fly; + } + + public void setFly(boolean fly) { + this.fly = fly; + } + public PlayerHiderState getHiderState() { return hiderState; } @@ -135,4 +145,8 @@ public class LobbyPlayer { 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.5 From 0263c2eebe3e649a0ec1c2eb4275b4a8281c2687 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 21:54:07 +0100 Subject: [PATCH 2/6] Add cancel to fly kick Detection --- src/de/steamwar/lobby/listener/PlayerConnectionListener.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java index ab66243..78c5c68 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -58,6 +58,8 @@ public class PlayerConnectionListener implements Listener { @EventHandler public void handlePlayerKick(PlayerKickEvent event) { + if (LobbyPlayer.getLobbyPlayer(event.getPlayer()).isFly()) + event.setCancelled(true); if(event.getReason().equals("Flying is not enabled on this server") && event.getPlayer().getVehicle() instanceof EnderPearl) event.setCancelled(true); } -- 2.39.5 From d9217984dbb61ea640d37dda83deb0e5d4f0a01d Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 21:55:21 +0100 Subject: [PATCH 3/6] Add DoubleJumpListener fly detection --- src/de/steamwar/lobby/listener/DoubleJumpListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index d094c5a..0769b48 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); -- 2.39.5 From c9f1e3be294ed89c393adbf0c78fbf87e064f92a Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 21:55:46 +0100 Subject: [PATCH 4/6] Add DoubleJumpListener fly detection --- src/de/steamwar/lobby/listener/DoubleJumpListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index 0769b48..2954924 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -69,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) { -- 2.39.5 From e493f3cfe6e8fdd8ca6d965e4fa46e5abdeb177b Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 30 Dec 2020 10:07:07 +0100 Subject: [PATCH 5/6] Update PlayerConnectionListener Update LobbyPlayer.isFly() --- src/de/steamwar/lobby/commands/FlyCommand.java | 2 +- src/de/steamwar/lobby/listener/DoubleJumpListener.java | 4 ++-- src/de/steamwar/lobby/listener/PlayerConnectionListener.java | 2 -- src/de/steamwar/lobby/utils/LobbyPlayer.java | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index 7885739..cbb829e 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -43,7 +43,7 @@ public class FlyCommand implements CommandExecutor { } LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - boolean newFlightState = !lobbyPlayer.isFly(); + boolean newFlightState = !lobbyPlayer.hasFly(); lobbyPlayer.setFly(newFlightState); player.setAllowFlight(newFlightState); diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index 2954924..c8902ff 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -48,7 +48,7 @@ public class DoubleJumpListener implements Listener { if (player.getGameMode() != GameMode.ADVENTURE && player.getGameMode() != GameMode.SURVIVAL) { return; } - if (LobbyPlayer.getLobbyPlayer(player).isFly()) { + if (LobbyPlayer.getLobbyPlayer(player).hasFly()) { return; } @@ -70,7 +70,7 @@ public class DoubleJumpListener implements Listener { Player player = event.getPlayer(); if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) return; - if (LobbyPlayer.getLobbyPlayer(player).isFly()) return; + if (LobbyPlayer.getLobbyPlayer(player).hasFly()) return; player.setAllowFlight(true); if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { diff --git a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java index 78c5c68..ab66243 100644 --- a/src/de/steamwar/lobby/listener/PlayerConnectionListener.java +++ b/src/de/steamwar/lobby/listener/PlayerConnectionListener.java @@ -58,8 +58,6 @@ public class PlayerConnectionListener implements Listener { @EventHandler public void handlePlayerKick(PlayerKickEvent event) { - if (LobbyPlayer.getLobbyPlayer(event.getPlayer()).isFly()) - event.setCancelled(true); if(event.getReason().equals("Flying is not enabled on this server") && event.getPlayer().getVehicle() instanceof EnderPearl) event.setCancelled(true); } diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 1cce12b..1c797e5 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -44,7 +44,7 @@ public class LobbyPlayer { cache.put(uuid, this); } - public boolean isFly() { + public boolean hasFly() { return fly; } -- 2.39.5 From 8d1297dec5538e66644cf833e4aad87249497f08 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 30 Dec 2020 16:00:49 +0100 Subject: [PATCH 6/6] Rename LobbyPlayer.hasFly() -> isFlying() --- src/de/steamwar/lobby/commands/FlyCommand.java | 2 +- src/de/steamwar/lobby/listener/DoubleJumpListener.java | 4 ++-- src/de/steamwar/lobby/utils/LobbyPlayer.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/lobby/commands/FlyCommand.java b/src/de/steamwar/lobby/commands/FlyCommand.java index cbb829e..4d1fb69 100644 --- a/src/de/steamwar/lobby/commands/FlyCommand.java +++ b/src/de/steamwar/lobby/commands/FlyCommand.java @@ -43,7 +43,7 @@ public class FlyCommand implements CommandExecutor { } LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player); - boolean newFlightState = !lobbyPlayer.hasFly(); + boolean newFlightState = !lobbyPlayer.isFlying(); lobbyPlayer.setFly(newFlightState); player.setAllowFlight(newFlightState); diff --git a/src/de/steamwar/lobby/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index c8902ff..612b5e9 100644 --- a/src/de/steamwar/lobby/listener/DoubleJumpListener.java +++ b/src/de/steamwar/lobby/listener/DoubleJumpListener.java @@ -48,7 +48,7 @@ public class DoubleJumpListener implements Listener { if (player.getGameMode() != GameMode.ADVENTURE && player.getGameMode() != GameMode.SURVIVAL) { return; } - if (LobbyPlayer.getLobbyPlayer(player).hasFly()) { + if (LobbyPlayer.getLobbyPlayer(player).isFlying()) { return; } @@ -70,7 +70,7 @@ public class DoubleJumpListener implements Listener { Player player = event.getPlayer(); if(player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR) return; - if (LobbyPlayer.getLobbyPlayer(player).hasFly()) return; + if (LobbyPlayer.getLobbyPlayer(player).isFlying()) return; player.setAllowFlight(true); if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { diff --git a/src/de/steamwar/lobby/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 1c797e5..70f7b48 100644 --- a/src/de/steamwar/lobby/utils/LobbyPlayer.java +++ b/src/de/steamwar/lobby/utils/LobbyPlayer.java @@ -44,7 +44,7 @@ public class LobbyPlayer { cache.put(uuid, this); } - public boolean hasFly() { + public boolean isFlying() { return fly; } -- 2.39.5