SteamWar/BauSystem2.0
Archiviert
12
0

Fix NoClipCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-05 21:27:33 +02:00
Ursprung c6b6ce3abd
Commit 868de95898
3 geänderte Dateien mit 17 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.other;
import lombok.experimental.UtilityClass;
import net.minecraft.server.v1_15_R1.EnumGamemode;
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
import org.bukkit.GameMode;
@ -27,11 +28,12 @@ import org.bukkit.entity.Player;
import java.lang.reflect.Field;
@UtilityClass
public class NoClipCommand_15 {
private static Field gameModeField;
private Field gameModeField;
public static void setGameModeInternal(Player player, GameMode gameMode) {
public void setGameModeInternal(Player player, GameMode gameMode) {
CraftPlayer craftPlayer = (CraftPlayer) player;
EnumGamemode enumGamemode = EnumGamemode.getById(gameMode.getValue());
try {
@ -42,7 +44,7 @@ public class NoClipCommand_15 {
}
}
private static void checkCache() throws NoSuchFieldException {
private void checkCache() throws NoSuchFieldException {
if (gameModeField == null) {
gameModeField = PlayerInteractManager.class.getDeclaredField("gamemode");
gameModeField.setAccessible(true);

Datei anzeigen

@ -30,10 +30,8 @@ import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.command.SWCommand;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@Linked(LinkageType.COMMAND)

Datei anzeigen

@ -42,6 +42,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import java.lang.reflect.InvocationTargetException;
@ -79,14 +80,6 @@ public class NoClipCommand extends SWCommand implements Listener {
}
}
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.SPECTATE) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (NOCLIPS.contains(event.getPlayer())) {
event.setCancelled(true);
}
}
});
}
@Register(help = true)
@ -138,4 +131,15 @@ public class NoClipCommand extends SWCommand implements Listener {
event.getPlayer().setFlying(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
return;
}
if (NOCLIPS.contains(event.getPlayer())) {
event.getPlayer().setSpectatorTarget(null);
event.setCancelled(true);
}
}
}