From d72e31b8117f8e098ef1cb138dd0a5d7247121ab Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 1 Nov 2020 21:29:09 +0100 Subject: [PATCH] Add Seats --- .../spectatesystem/SpectateSystem.java | 2 + .../listener/PlayerSeatListener.java | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java diff --git a/src/de/steamwar/spectatesystem/SpectateSystem.java b/src/de/steamwar/spectatesystem/SpectateSystem.java index 644b029..91331db 100644 --- a/src/de/steamwar/spectatesystem/SpectateSystem.java +++ b/src/de/steamwar/spectatesystem/SpectateSystem.java @@ -24,6 +24,7 @@ import de.steamwar.spectatesystem.elements.RScoreboard; import de.steamwar.spectatesystem.listener.PlayerListener; import de.steamwar.spectatesystem.listener.CancelListener; import de.steamwar.spectatesystem.listener.JoinListener; +import de.steamwar.spectatesystem.listener.PlayerSeatListener; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -43,6 +44,7 @@ public class SpectateSystem extends JavaPlugin { new JoinListener(); new PlayerListener(); new CancelListener(); + new PlayerSeatListener(); try { acceptor = new ConnectionAcceptor(); } catch (IOException e) { diff --git a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java new file mode 100644 index 0000000..65f67c8 --- /dev/null +++ b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java @@ -0,0 +1,64 @@ +/* + 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.spectatesystem.listener; + +import org.bukkit.GameMode; +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.spigotmc.event.entity.EntityDismountEvent; + +public class PlayerSeatListener extends BasicListener { + + @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) + return; + + Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(event.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.ARROW); + arrow.setGravity(false); + arrow.addScoreboardTag(event.getPlayer().getUniqueId().toString()); + arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); + arrow.setPassenger(event.getPlayer()); + } + + @EventHandler + public void onEntityDismount(EntityDismountEvent event) { + if(event.getEntity().getType() != EntityType.ARROW) + return; + + if(event.getEntityType() != EntityType.PLAYER) + return; + + event.getEntity().getWorld().getEntitiesByClasses(Arrow.class).forEach(entity -> { + if(entity.getScoreboardTags().contains(event.getEntity().getUniqueId().toString())) + entity.remove(); + }); + } +} -- 2.39.5