13
0

Merge pull request 'Add Seats' (#1) from seat into master

Dieser Commit ist enthalten in:
Lixfel 2020-11-02 10:42:40 +01:00
Commit 3f65da5775
2 geänderte Dateien mit 66 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
});
}
}