From 38bea9af636211986d47893be67645fefc229038 Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 24 Mar 2022 14:13:14 +0100 Subject: [PATCH 1/5] Player Seat Listener --- src/de/steamwar/lobby/LobbySystem.java | 1 + .../lobby/listener/PlayerSeatListener.java | 110 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/de/steamwar/lobby/listener/PlayerSeatListener.java diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 977188a..9e19805 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -56,6 +56,7 @@ public class LobbySystem extends JavaPlugin { new ParticleListener(); new InventoryInteraction(); new WorldInteraction(); + new PlayerSeatListener(); new AlphaWall(l -> l.getX() > 1199, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X); diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java new file mode 100644 index 0000000..863ce71 --- /dev/null +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -0,0 +1,110 @@ +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.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 extends BasicListener{ + + 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()); + } + +} From a93fe5797d196a2da6e8a224a5a50c1799e3fd5f Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Thu, 24 Mar 2022 14:57:03 +0100 Subject: [PATCH 2/5] Player Seat Listener --- .../lobby/listener/PlayerSeatListener.java | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index 863ce71..4dda9fa 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -1,8 +1,26 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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 de.steamwar.lobby.LobbySystem; +import org.bukkit.*; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.type.Stairs; import org.bukkit.entity.AbstractArrow; @@ -12,45 +30,29 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scheduler.BukkitRunnable; import org.spigotmc.event.entity.EntityDismountEvent; import java.util.HashSet; -import java.util.Objects; import java.util.Set; public class PlayerSeatListener extends BasicListener{ - private static class SeatLocation { + public static final World world = Bukkit.getWorlds().get(0); - 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<>(); + static { + new BukkitRunnable() { + @Override + public void run() { + for(Arrow arrow : world.getEntitiesByClass(Arrow.class)) { + arrow.setTicksLived(1); + } + } + }.runTaskTimer(LobbySystem.getPlugin(), 20*60,20*60); } - private Set seats = new HashSet<>(); - @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) @@ -75,7 +77,7 @@ public class PlayerSeatListener extends BasicListener{ return; Location location = event.getClickedBlock().getLocation(); - SeatLocation seatLocation = getSeatLocation(location); + Location seatLocation = getSeatLocation(location); if (seats.contains(seatLocation)) return; seats.add(seatLocation); @@ -91,7 +93,7 @@ public class PlayerSeatListener extends BasicListener{ public void onEntityDismount(EntityDismountEvent event) { seats.remove(getSeatLocation(event.getDismounted().getLocation())); - if (event.getEntityType() != EntityType.PLAYER) + if (event.getEntityType() != EntityType.PLAYER && event.getDismounted().getType() != EntityType.ARROW) return; event.getDismounted().remove(); @@ -99,12 +101,12 @@ public class PlayerSeatListener extends BasicListener{ @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer().isInsideVehicle()) + if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW) event.getPlayer().getVehicle().remove(); } - public SeatLocation getSeatLocation(Location location) { - return new SeatLocation(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + public Location getSeatLocation(Location location) { + return new Location(world,location.getBlockX(), location.getBlockY(), location.getBlockZ()); } } From 9922f0b59584c86f8318efe9ccbe1032278bb639 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Mar 2022 11:17:56 +0100 Subject: [PATCH 3/5] Fix PlayerSeatListener --- src/de/steamwar/lobby/listener/PlayerSeatListener.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/lobby/listener/PlayerSeatListener.java b/src/de/steamwar/lobby/listener/PlayerSeatListener.java index 4dda9fa..10d8528 100644 --- a/src/de/steamwar/lobby/listener/PlayerSeatListener.java +++ b/src/de/steamwar/lobby/listener/PlayerSeatListener.java @@ -25,6 +25,7 @@ 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.Entity; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -70,7 +71,7 @@ public class PlayerSeatListener extends BasicListener{ if (((Stairs) event.getClickedBlock().getBlockData()).getShape() != Stairs.Shape.STRAIGHT) return; - if (event.getPlayer().isInsideVehicle()) + if (event.getPlayer().isInsideVehicle() && isArrow(event.getPlayer().getVehicle())) event.getPlayer().getVehicle().remove(); if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) @@ -93,7 +94,7 @@ public class PlayerSeatListener extends BasicListener{ public void onEntityDismount(EntityDismountEvent event) { seats.remove(getSeatLocation(event.getDismounted().getLocation())); - if (event.getEntityType() != EntityType.PLAYER && event.getDismounted().getType() != EntityType.ARROW) + if (event.getEntityType() != EntityType.PLAYER && !isArrow(event.getDismounted())) return; event.getDismounted().remove(); @@ -101,7 +102,7 @@ public class PlayerSeatListener extends BasicListener{ @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer().isInsideVehicle() && event.getPlayer().getVehicle().getType() == EntityType.ARROW) + if (event.getPlayer().isInsideVehicle() && isArrow(event.getPlayer().getVehicle())) event.getPlayer().getVehicle().remove(); } @@ -109,4 +110,7 @@ public class PlayerSeatListener extends BasicListener{ return new Location(world,location.getBlockX(), location.getBlockY(), location.getBlockZ()); } + private boolean isArrow(Entity entity) { + return entity.getType() == EntityType.ARROW; + } } From a15aa5c37375c7047a49d3ebd749736ad2d77b9c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 26 Mar 2022 11:42:49 +0100 Subject: [PATCH 4/5] Fix modifying --- src/de/steamwar/lobby/portal/CommandPortal.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/lobby/portal/CommandPortal.java b/src/de/steamwar/lobby/portal/CommandPortal.java index 53e66f3..3dfe6ed 100644 --- a/src/de/steamwar/lobby/portal/CommandPortal.java +++ b/src/de/steamwar/lobby/portal/CommandPortal.java @@ -21,6 +21,7 @@ package de.steamwar.lobby.portal; import de.steamwar.comms.packets.ExecuteCommandPacket; import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.listener.Portals; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -79,7 +80,8 @@ public class CommandPortal implements PortalHandler { cmd.append(pieces[i]).append(parts[i+1].substring(1)); } - player.sendMessage("/" + cmd); + if(ModifyCommand.modifying(player)) + player.sendMessage("/" + cmd); new ExecuteCommandPacket(player, cmd.toString()).send(player); } From 88fbfa0f44b53af91f55deac1c094fe6e280310c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Mar 2022 11:55:22 +0100 Subject: [PATCH 5/5] Add MapsRotateListener --- src/de/steamwar/lobby/LobbySystem.java | 1 + .../lobby/listener/MapsRotateListener.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/de/steamwar/lobby/listener/MapsRotateListener.java diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index 9e19805..96cb5f5 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -57,6 +57,7 @@ public class LobbySystem extends JavaPlugin { new InventoryInteraction(); new WorldInteraction(); new PlayerSeatListener(); + new MapsRotateListener(); new AlphaWall(l -> l.getX() > 1199, AlphaWall.REFLECT_X); new AlphaWall(l -> l.getX() < 2977, AlphaWall.REFLECT_X); diff --git a/src/de/steamwar/lobby/listener/MapsRotateListener.java b/src/de/steamwar/lobby/listener/MapsRotateListener.java new file mode 100644 index 0000000..e098da0 --- /dev/null +++ b/src/de/steamwar/lobby/listener/MapsRotateListener.java @@ -0,0 +1,38 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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.command.ModifyCommand; +import org.bukkit.entity.ItemFrame; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +public class MapsRotateListener extends BasicListener { + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (ModifyCommand.modifying(event.getPlayer())) { + return; + } + if (event.getRightClicked() instanceof ItemFrame) { + event.setCancelled(true); + } + } +}