WIP: no async world access #496
+57
-65
@@ -19,12 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.smartplace;
|
package de.steamwar.bausystem.features.smartplace;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.configplayer.Config;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@@ -34,104 +32,98 @@ import org.bukkit.block.data.*;
|
|||||||
import org.bukkit.block.data.type.*;
|
import org.bukkit.block.data.type.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.RayTraceResult;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class SmartPlaceListener implements Listener {
|
public class SmartPlaceListener implements Listener {
|
||||||
|
|
||||||
private static final Set<Material> CONTAINERS = new HashSet<>();
|
private static final Set<Material> IGNORED = Set.of(Material.TNT, Material.REDSTONE_ORE, Material.BEEHIVE, Material.SEA_PICKLE);
|
||||||
private static final Set<Material> IGNORED = new HashSet<>();
|
|
||||||
|
|
||||||
static {
|
private static final Set<UUID> FAKED_SNEAK = new HashSet<>();
|
||||||
World world = Bukkit.getWorlds().get(0);
|
|
||||||
Block block = world.getBlockAt(0, 0, 0);
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
BlockState state = block.getState();
|
|
||||||
for (Material material : Material.values()) {
|
|
||||||
if (material.isLegacy()) continue;
|
|
||||||
if (!material.isInteractable() && !material.isBlock()) continue;
|
|
||||||
BlockData blockData = material.createBlockData();
|
|
||||||
block.setBlockData(blockData);
|
|
||||||
if (block.getState() instanceof TileState) {
|
|
||||||
CONTAINERS.add(material);
|
|
||||||
} else if (blockData instanceof Stairs) {
|
|
||||||
CONTAINERS.add(material);
|
|
||||||
}
|
|
||||||
state.update(true, false);
|
|
||||||
}
|
|
||||||
CONTAINERS.add(Material.GRINDSTONE);
|
|
||||||
CONTAINERS.remove(Material.COMPARATOR);
|
|
||||||
state.update(true, false);
|
|
||||||
|
|
||||||
IGNORED.add(Material.TNT);
|
private static boolean isContainer(Block block) {
|
||||||
IGNORED.add(Material.REDSTONE_ORE);
|
if (block.getType() == Material.COMPARATOR) return false;
|
||||||
IGNORED.add(Material.BEEHIVE);
|
if (block.getType() == Material.GRINDSTONE) return true;
|
||||||
IGNORED.add(Material.SEA_PICKLE);
|
return block.getState() instanceof TileState || block.getBlockData() instanceof Stairs;
|
||||||
IGNORED.remove(Material.STONE);
|
|
||||||
IGNORED.remove(Material.BARRIER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Set<Player> SMART_PLACING = new HashSet<>();
|
private static boolean isReallySneaking(Player player) {
|
||||||
private static final Set<Player> WAS_EXECUTED = new HashSet<>();
|
return player.isSneaking() && !FAKED_SNEAK.contains(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
public SmartPlaceListener() {
|
private static boolean shouldSmartPlace(Block block, BlockFace blockFace, Material heldType) {
|
||||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
boolean smartPlace = false;
|
||||||
if (!Permission.BUILD.hasPermission(player)) return packet;
|
|
||||||
if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet;
|
|
||||||
RayTraceResult rayTraceResult = player.rayTraceBlocks(6);
|
|
||||||
Block block = rayTraceResult != null ? rayTraceResult.getHitBlock() : null;
|
|
||||||
BlockFace blockFace = rayTraceResult != null ? rayTraceResult.getHitBlockFace() : null;
|
|
||||||
boolean shouldSneak = false;
|
|
||||||
if (block != null) {
|
|
||||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
|
||||||
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
|
if (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) {
|
||||||
shouldSneak = true;
|
smartPlace = true;
|
||||||
}
|
}
|
||||||
if (CONTAINERS.contains(block.getType())) {
|
if (isContainer(block)) {
|
||||||
if (itemStack.getType() == Material.TNT) {
|
if (heldType == Material.TNT) {
|
||||||
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL || block.getType().name().endsWith("SHULKER_BOX")) {
|
||||||
shouldSneak = false;
|
smartPlace = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shouldSneak = false;
|
smartPlace = false;
|
||||||
}
|
}
|
||||||
if (IGNORED.contains(block.getType())) {
|
if (IGNORED.contains(block.getType())) {
|
||||||
shouldSneak = false;
|
smartPlace = false;
|
||||||
}
|
}
|
||||||
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && itemStack.getType().isSolid()) {
|
if (blockFace == BlockFace.DOWN && (block.getType() == Material.REPEATER || block.getType() == Material.COMPARATOR) && heldType.isSolid()) {
|
||||||
shouldSneak = true;
|
smartPlace = true;
|
||||||
}
|
}
|
||||||
|
return smartPlace;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean smartPlaceEnabled(Player player) {
|
||||||
|
return Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onSmartPlace(PlayerInteractEvent event) {
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.getGameMode() == GameMode.SPECTATOR) return;
|
||||||
|
if (!Permission.BUILD.hasPermission(player)) return;
|
||||||
|
if (!smartPlaceEnabled(player)) return;
|
||||||
|
if (player.isSneaking()) return;
|
||||||
|
|
||||||
|
ItemStack itemStack = event.getItem();
|
||||||
|
if (itemStack == null || itemStack.getType().isAir()) return;
|
||||||
|
if (!shouldSmartPlace(event.getClickedBlock(), event.getBlockFace(), itemStack.getType())) return;
|
||||||
|
|
||||||
|
player.setSneaking(true);
|
||||||
|
FAKED_SNEAK.add(player.getUniqueId());
|
||||||
|
Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> {
|
||||||
|
if (FAKED_SNEAK.remove(player.getUniqueId())) {
|
||||||
|
player.setSneaking(false);
|
||||||
}
|
}
|
||||||
boolean sneaking = player.isSneaking();
|
|
||||||
if (sneaking) SMART_PLACING.add(player);
|
|
||||||
player.setSneaking(shouldSneak || sneaking);
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
|
||||||
SMART_PLACING.remove(player);
|
|
||||||
player.setSneaking(sneaking);
|
|
||||||
}, 0);
|
|
||||||
return packet;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
|
FAKED_SNEAK.remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
if (!smartPlaceEnabled(event.getPlayer())) return;
|
||||||
WAS_EXECUTED.add(event.getPlayer());
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
|
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
|
||||||
if (!event.getPlayer().isSneaking()) return;
|
if (!isReallySneaking(event.getPlayer())) return;
|
||||||
if (event.getClickedBlock().getType() != Material.REPEATER) return;
|
if (event.getClickedBlock().getType() != Material.REPEATER) return;
|
||||||
if ((event.getItem() == null || event.getItem().getType() == Material.REPEATER)) {
|
if ((event.getItem() == null || event.getItem().getType() == Material.REPEATER)) {
|
||||||
Repeater repeater = (Repeater) event.getClickedBlock().getBlockData();
|
Repeater repeater = (Repeater) event.getClickedBlock().getBlockData();
|
||||||
@@ -146,9 +138,9 @@ public class SmartPlaceListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
|
if (!smartPlaceEnabled(event.getPlayer())) return;
|
||||||
if (!SMART_PLACING.contains(event.getPlayer())) {
|
if (!isReallySneaking(event.getPlayer())) {
|
||||||
if (CONTAINERS.contains(event.getBlockAgainst().getType())) {
|
if (isContainer(event.getBlockAgainst())) {
|
||||||
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
|
SoundGroup soundGroup = event.getBlockPlaced().getBlockData().getSoundGroup();
|
||||||
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
event.getPlayer().playSound(event.getBlockPlaced().getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-89
@@ -22,123 +22,71 @@ package de.steamwar.bausystem.features.util;
|
|||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
|
|
||||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.core.ProtocolWrapper;
|
import de.steamwar.core.ProtocolWrapper;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import io.papermc.paper.event.player.PlayerFailMoveEvent;
|
||||||
import net.minecraft.world.entity.player.Abilities;
|
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
||||||
import net.minecraft.world.level.GameType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class NoClipCommand extends SWCommand implements Listener {
|
public class NoClipCommand extends SWCommand implements Listener {
|
||||||
|
|
||||||
public static class NoClipData implements SWPlayer.Component {
|
public static class NoClipData implements SWPlayer.Component {
|
||||||
private long lastTick = -1;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUnmount(SWPlayer player) {
|
public void onUnmount(SWPlayer swPlayer) {
|
||||||
player.getPlayer().setGameMode(GameMode.CREATIVE);
|
Player player = swPlayer.getPlayer();
|
||||||
|
showClientGameMode(player, GameMode.CREATIVE, GameMode.CREATIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NoClipCommand() {
|
public NoClipCommand() {
|
||||||
super("noclip", "nc");
|
super("noclip", "nc");
|
||||||
|
|
||||||
BiFunction<Player, ServerboundMovePlayerPacket, Object> first = (player, o) -> {
|
|
||||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
|
||||||
if (noClipData == null) return o;
|
|
||||||
if (noClipData.lastTick == TPSUtils.currentTick.get()) return o;
|
|
||||||
setInternalGameMode(player, GameMode.SPECTATOR);
|
|
||||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
|
||||||
return o;
|
|
||||||
};
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, first);
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, first);
|
|
||||||
|
|
||||||
BiFunction<Player, Object, Object> second = (player, o) -> {
|
|
||||||
NoClipData noClipData = SWPlayer.of(player).getComponent(NoClipData.class).orElse(null);
|
|
||||||
if (noClipData == null) return o;
|
|
||||||
setInternalGameMode(player, GameMode.CREATIVE);
|
|
||||||
noClipData.lastTick = TPSUtils.currentTick.get();
|
|
||||||
return o;
|
|
||||||
};
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, second);
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, second);
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundContainerClickPacket.class, second);
|
|
||||||
|
|
||||||
BiFunction<Player, ServerboundSetCreativeModeSlotPacket, Object> third = (player, o) -> {
|
|
||||||
if (SWPlayer.of(player).hasComponent(NoClipData.class)) {
|
|
||||||
int index = o.slotNum();
|
|
||||||
if (index >= 36 && index <= 44) {
|
|
||||||
index -= 36;
|
|
||||||
} else if (index > 44) {
|
|
||||||
index -= 5;
|
|
||||||
} else if (index <= 8) {
|
|
||||||
index = index - 8 + 36;
|
|
||||||
}
|
|
||||||
player.getInventory().setItem(index, CraftItemStack.asBukkitCopy(o.itemStack()));
|
|
||||||
if (index < 9) player.getInventory().setHeldItemSlot(index);
|
|
||||||
player.updateInventory();
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
};
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundSetCreativeModeSlotPacket.class, third);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInternalGameMode(Player player, GameMode gameMode) {
|
@Register
|
||||||
((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(help = true)
|
|
||||||
public void genericCommand(@Validator Player player) {
|
public void genericCommand(@Validator Player player) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
if (swPlayer.hasComponent(NoClipData.class)) {
|
if (swPlayer.hasComponent(NoClipData.class)) {
|
||||||
swPlayer.removeComponent(NoClipData.class);
|
swPlayer.removeComponent(NoClipData.class);
|
||||||
} else {
|
} else {
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
Abilities abilities = (((CraftPlayer) player).getHandle()).getAbilities();
|
player.setAllowFlight(true);
|
||||||
abilities.mayBuild = true;
|
player.setFlying(true);
|
||||||
abilities.mayfly = true;
|
|
||||||
abilities.instabuild = true;
|
|
||||||
|
|
||||||
swPlayer.setComponent(new NoClipData());
|
swPlayer.setComponent(new NoClipData());
|
||||||
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
|
||||||
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, 1F));
|
showClientGameMode(player, GameMode.CREATIVE, GameMode.SPECTATOR);
|
||||||
pseudoGameMode(player, GameMode.SPECTATOR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
public void onPlayerFailMove(PlayerFailMoveEvent event) {
|
||||||
event.getNewSpectator().forEach(player -> {
|
if (event.getFailReason() != PlayerFailMoveEvent.FailReason.CLIPPED_INTO_BLOCK) return;
|
||||||
SWPlayer.of(player).removeComponent(NoClipData.class);
|
if (!SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) return;
|
||||||
});
|
event.setAllowed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler
|
||||||
|
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||||
|
event.getNewSpectator().forEach(player -> SWPlayer.of(player).removeComponent(NoClipData.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler
|
||||||
public void onBlock(BlockCanBuildEvent event) {
|
public void onBlock(BlockCanBuildEvent event) {
|
||||||
if (event.getPlayer() == null) return;
|
if (event.getPlayer() == null) return;
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
@@ -146,7 +94,7 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler
|
||||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -154,20 +102,13 @@ public class NoClipCommand extends SWCommand implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
/**
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
* @param player player
|
||||||
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
|
* @param localMode GameMode for breaking and placing
|
||||||
return;
|
* @param listedMode GameMode for noPhysics
|
||||||
}
|
*/
|
||||||
if (SWPlayer.of(event.getPlayer()).hasComponent(NoClipData.class)) {
|
private static void showClientGameMode(Player player, GameMode localMode, GameMode listedMode) {
|
||||||
event.setCancelled(true);
|
TinyProtocol.instance.sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, localMode.getValue()));
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), listedMode));
|
||||||
event.getPlayer().setSpectatorTarget(null);
|
|
||||||
}, 1L);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void pseudoGameMode(Player player, GameMode gameMode) {
|
|
||||||
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), gameMode));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2025 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.core.events;
|
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import de.steamwar.linkage.Linked;
|
|
||||||
import de.steamwar.sql.SWException;
|
|
||||||
import de.steamwar.techhider.ProtocolUtils;
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
@Linked
|
|
||||||
public class AntiNocom implements Listener {
|
|
||||||
|
|
||||||
private final Map<Player, Integer> flags = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public AntiNocom() {
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::onDig);
|
|
||||||
registerUseItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onQuit(PlayerQuitEvent e) {
|
|
||||||
flags.remove(e.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerUseItem() {
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, (player, packet) -> {
|
|
||||||
BlockPos pos = packet.getHitResult().getBlockPos();
|
|
||||||
return isValid(player, "UseItem", pos.getX(), pos.getZ()) ? packet : null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServerboundPlayerActionPacket onDig(Player player, ServerboundPlayerActionPacket packet) {
|
|
||||||
BlockPos pos = packet.getPos();
|
|
||||||
return isValid(player, "Dig", pos.getX(), pos.getZ()) ? packet : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValid(Player player, String type, int x, int z) {
|
|
||||||
if ((x == 0 && z == 0) || player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int amount = flags.compute(player, (p, a) -> a == null ? 1 : a + 1);
|
|
||||||
if (amount % 8 == 0) { // Only after 8 and every 8 to reduce false flags and spam
|
|
||||||
if (amount == 8) {
|
|
||||||
// Schedule player kick only once
|
|
||||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
SWException.log(player.getName() + " kicked for potential NoCom-DOS attack", x + " " + z + " " + type + " " + amount);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,14 @@
|
|||||||
package de.steamwar.cursor;
|
package de.steamwar.cursor;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.SWPlayer;
|
import de.steamwar.core.SWPlayer;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class CursorListener implements Listener {
|
public class CursorListener implements Listener {
|
||||||
@@ -26,10 +20,6 @@ public class CursorListener implements Listener {
|
|||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::updateCursorFromPacket);
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::updateCursorFromPacket);
|
|
||||||
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::updateCursorFromPacket);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||||
SWPlayer.allWithSingleComponent(Cursor.class)
|
SWPlayer.allWithSingleComponent(Cursor.class)
|
||||||
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
.map(SWPlayer.SWPlayerWithComponent::getComponent)
|
||||||
@@ -37,15 +27,6 @@ public class CursorListener implements Listener {
|
|||||||
}, 1, 1);
|
}, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Packet<?> updateCursorFromPacket(Player player, Packet<?> packet) {
|
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
|
||||||
Optional<Cursor> activeCursor = swPlayer.getComponent(Cursor.class);
|
|
||||||
|
|
||||||
activeCursor.ifPresent(Cursor::renderDeduplicated);
|
|
||||||
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
SWPlayer.of(event.getPlayer()).getComponent(Cursor.class).ifPresent(cursor -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user