diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 197b62e..1bdab28 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,14 +34,16 @@ 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); pm.registerEvents(new PlayerWorldInteractionListener(), instance); pm.registerEvents(new DoubleJumpListener(), instance); pm.registerEvents(new ParticleListener(), instance); + pm.registerEvents(new PlayerSeatListener(), 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..4d1fb69 --- /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.isFlying(); + + 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/listener/DoubleJumpListener.java b/src/de/steamwar/lobby/listener/DoubleJumpListener.java index d094c5a..612b5e9 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).isFlying()) { + 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).isFlying()) return; player.setAllowFlight(true); if (player.getGameMode() == GameMode.ADVENTURE || player.getGameMode() == GameMode.SURVIVAL) { diff --git a/src/de/steamwar/lobby/listener/PlayerMoveListener.java b/src/de/steamwar/lobby/listener/PlayerMoveListener.java index ebe2e92..2ef7dcb 100644 --- a/src/de/steamwar/lobby/listener/PlayerMoveListener.java +++ b/src/de/steamwar/lobby/listener/PlayerMoveListener.java @@ -20,6 +20,7 @@ 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; @@ -28,12 +29,22 @@ import org.bukkit.util.Vector; public class PlayerMoveListener implements Listener { + private static final Location spawnLocation = new Location(Bukkit.getWorlds().get(0), Config.SpawnX, Config.SpawnY, Config.SpawnZ, Config.Yaw, Config.Pitch); + 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 (to.getY() <= Config.BorderMinY || to.getY() >= Config.BorderMaxY) { + event.getPlayer().teleport(spawnLocation); + return; + } + if (!event.getFrom().toVector().isInAABB(borderMinVector, borderMaxVector)) { + event.getPlayer().teleport(spawnLocation); + return; + } 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/utils/LobbyPlayer.java b/src/de/steamwar/lobby/utils/LobbyPlayer.java index 380daf5..ba7f197 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 de.steamwar.lobby.particle.SpecialParticle; +import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; @@ -32,12 +33,21 @@ public class LobbyPlayer { private SpecialParticle specialParticle; private boolean enderPearlUsed; + private boolean fly; private LobbyPlayer(UUID uuid) { cache.put(uuid, this); specialParticle = null; } + public boolean isFlying() { + return fly; + } + + public void setFly(boolean fly) { + this.fly = fly; + } + public SpecialParticle getParticle() { return specialParticle; } @@ -58,4 +68,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