SteamWar/BauSystem2.0
Archiviert
12
0

Add SpectatorListener
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2023-12-16 14:42:01 +01:00
Ursprung 0cec90c55c
Commit 20af36a4a2

Datei anzeigen

@ -0,0 +1,110 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.bausystem.features.world;
import de.steamwar.bausystem.Permission;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockMultiPlaceEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.*;
@Linked
public class SpectatorListener implements Listener {
private boolean anySupervisorOnline(Player player) {
return Bukkit.getOnlinePlayers().stream().filter(p -> p != player).anyMatch(Permission.SUPERVISOR::hasPermission);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (!anySupervisorOnline(null)) {
event.getPlayer().kickPlayer("");
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (!anySupervisorOnline(event.getPlayer())) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.kickPlayer("");
});
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) {
if (!Permission.SUPERVISOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
event.setMessage("/");
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockCanBuild(BlockCanBuildEvent event) {
if (event.getPlayer() == null) return;
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setBuildable(false);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerBucket(PlayerBucketEvent event) {
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
event.setCancelled(true);
}
}
}