SteamWar/BauSystem2.0
Archiviert
12
0

Fix SmartPlaceListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-10-16 14:12:33 +02:00
Ursprung f0741dbc19
Commit 05c01e25e2

Datei anzeigen

@ -85,29 +85,39 @@ public class SmartPlaceListener implements Plain, Listener {
private static final Reflection.MethodInvoker packetExecutor = Reflection.getMethod(playerConnectionClazz, null, useItem);
private static final Set<Player> SMART_PLACING = new HashSet<>();
private static final Set<Player> WAS_EXECUTED = new HashSet<>();
public SmartPlaceListener() {
TinyProtocol.instance.addFilter(useItem, (player, object) -> {
if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return object;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
Block block = player.getTargetBlockExact(6);
boolean shouldSneak = !(block != null && (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) && !CONTAINERS.contains(block.getType()) && !IGNORED.contains(block.getType()));
boolean sneaking = player.isSneaking();
if (sneaking) SMART_PLACING.add(player);
player.setSneaking(shouldSneak || sneaking);
packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), object);
SMART_PLACING.remove(player);
player.setSneaking(sneaking);
}, 0);
TinyProtocol.instance.addFilter(useItem, (player, packet) -> {
if (!Config.getInstance().get(player).getPlainValueOrDefault("smartPlace", false)) return packet;
Block block = player.getTargetBlockExact(6);
boolean shouldSneak = !(block != null && (block.getType().isInteractable() || block.getType() == Material.NOTE_BLOCK) && !CONTAINERS.contains(block.getType()) && !IGNORED.contains(block.getType()));
boolean sneaking = player.isSneaking();
run(player, packet, true, sneaking, shouldSneak);
return null;
});
}
private void run(Player player, Object packet, boolean first, boolean sneaking, boolean shouldSneak) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (sneaking) SMART_PLACING.add(player);
player.setSneaking(shouldSneak || sneaking);
packetExecutor.invoke(playerConnection.get(getHandle.invoke(player)), packet);
SMART_PLACING.remove(player);
player.setSneaking(sneaking);
if (!WAS_EXECUTED.contains(player) && first) {
run(player, packet, false, sneaking, shouldSneak);
}
WAS_EXECUTED.remove(player);
}, first ? 0 : 1);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
WAS_EXECUTED.add(event.getPlayer());
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
if (!event.getPlayer().isSneaking()) return;