From d1dbff05187f974ba3ab1a73812ee81ef254f03c Mon Sep 17 00:00:00 2001 From: Heliosares Date: Mon, 3 Jul 2023 17:36:50 -0400 Subject: [PATCH] Potential fix for playblack blocking --- pom.xml | 3 +- .../auxprotect/utils/FakePlayer.java | 2 +- .../auxprotect/utils/PlaybackSolver.java | 136 +++++++++--------- 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index 9ff72e5..636358b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 AuxProtect AuxProtect - 1.2.6 + 1.2.7-pre1 AuxProtect ${project.artifactId}-${project.version} @@ -22,6 +22,7 @@ src/main/java + org.apache.maven.plugins maven-compiler-plugin 3.8.1 diff --git a/src/main/java/dev/heliosares/auxprotect/utils/FakePlayer.java b/src/main/java/dev/heliosares/auxprotect/utils/FakePlayer.java index 09814b2..2219ff7 100644 --- a/src/main/java/dev/heliosares/auxprotect/utils/FakePlayer.java +++ b/src/main/java/dev/heliosares/auxprotect/utils/FakePlayer.java @@ -76,7 +76,7 @@ public class FakePlayer { if (skin != null) profile.getProperties().put("textures", skin.wrap()); // TODO fake player still being added to list packet.getPlayerInfoDataLists().write(1, List.of( - new PlayerInfoData(uuid, 0, false, EnumWrappers.NativeGameMode.SURVIVAL, profile, WrappedChatComponent.fromLegacyText(name), null) + new PlayerInfoData(uuid, 0, false, EnumWrappers.NativeGameMode.SURVIVAL, profile, WrappedChatComponent.fromLegacyText(name), (WrappedRemoteChatSessionData) null) )); protocol.sendServerPacket(audience, packet); diff --git a/src/main/java/dev/heliosares/auxprotect/utils/PlaybackSolver.java b/src/main/java/dev/heliosares/auxprotect/utils/PlaybackSolver.java index 4a95207..d74d03d 100644 --- a/src/main/java/dev/heliosares/auxprotect/utils/PlaybackSolver.java +++ b/src/main/java/dev/heliosares/auxprotect/utils/PlaybackSolver.java @@ -174,79 +174,79 @@ public class PlaybackSolver extends BukkitRunnable { @Override public void run() { - synchronized (this) { - if (closed || isCancelled() || !audience.isOnline()) { - close(); - cancel(); - return; - } - final long timeNow = System.currentTimeMillis() - realReferenceTime + startTime; - - audience.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(TimeUtil.format(timeNow, TimeUtil.entryTimeFormat) + " " + ChatColor.COLOR_CHAR + "7- " + TimeUtil.millisToString(System.currentTimeMillis() - timeNow) + " ago")); - - - for (Iterator it = points.iterator(); it.hasNext(); ) { - PosPoint point = it.next(); - if (timeNow > point.time()) { - FakePlayer actor = actors.get(point.name()); - Location loc = point.location.clone(); - assert loc.getWorld() != null; - - if (actor == null) { - String name = "~" + point.name; - if (name.length() > 16) name = name.substring(0, 16); - actor = new FakePlayer(name, protocol, audience); - actor.spawn(point.location(), skins.get(point.uuid)); - } - actors.put(point.name(), actor); - actor.setLocation(loc, false); - if (point.posture != null) actor.setPosture(point.posture); - - it.remove(); - } else break; - } - - Set swing = new HashSet<>(); - for (Iterator it = blockActions.iterator(); it.hasNext(); ) { - BlockAction action = it.next(); - if (timeNow > action.time()) { - it.remove(); - FakePlayer actor = actors.get(action.name()); - if (actor != null) { - swing.add(actor); - action.sendChange(audience, false); - } - } - } - swing.forEach(FakePlayer::swingArm); - - for (Iterator it = actors.values().iterator(); it.hasNext(); ) { - FakePlayer pl = it.next(); - if (System.currentTimeMillis() - pl.getLastMoved() > 1000) { - pl.remove(); - it.remove(); - } - } - if (points.isEmpty()) close(); + if (closed) return; + if (!audience.isOnline()) { + close(); + return; } + final long timeNow = System.currentTimeMillis() - realReferenceTime + startTime; + + audience.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(TimeUtil.format(timeNow, TimeUtil.entryTimeFormat) + " " + ChatColor.COLOR_CHAR + "7- " + TimeUtil.millisToString(System.currentTimeMillis() - timeNow) + " ago")); + + + for (Iterator it = points.iterator(); it.hasNext(); ) { + if (closed) return; + PosPoint point = it.next(); + if (timeNow > point.time()) { + FakePlayer actor = actors.get(point.name()); + Location loc = point.location.clone(); + assert loc.getWorld() != null; + + if (actor == null) { + String name = "~" + point.name; + if (name.length() > 16) name = name.substring(0, 16); + actor = new FakePlayer(name, protocol, audience); + actor.spawn(point.location(), skins.get(point.uuid)); + } + actors.put(point.name(), actor); + actor.setLocation(loc, false); + if (point.posture != null) actor.setPosture(point.posture); + + it.remove(); + } else break; + } + + Set swing = new HashSet<>(); + for (Iterator it = blockActions.iterator(); it.hasNext(); ) { + if (closed) return; + BlockAction action = it.next(); + if (timeNow > action.time()) { + it.remove(); + FakePlayer actor = actors.get(action.name()); + if (actor != null) { + swing.add(actor); + action.sendChange(audience, false); + } + } + } + swing.forEach(FakePlayer::swingArm); + + for (Iterator it = actors.values().iterator(); it.hasNext(); ) { + if (closed) return; + FakePlayer pl = it.next(); + if (System.currentTimeMillis() - pl.getLastMoved() > 1000) { + pl.remove(); + it.remove(); + } + } + if (points.isEmpty()) close(); } public void close() { - synchronized (this) { - if (closed) return; - closed = true; - if (audience.isOnline()) { - audience.sendMessage(Language.translate(Language.L.COMMAND__LOOKUP__PLAYBACK__STOPPED)); - audience.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Language.translate(Language.L.COMMAND__LOOKUP__PLAYBACK__STOPPED))); - actors.values().forEach(FakePlayer::remove); - actors.clear(); - int countBlocks = 0; - for (Location location : modified) { - if (audience.getWorld().equals(location.getWorld()) && location.distance(audience.getLocation()) < 250) { - audience.sendBlockChange(location, location.getBlock().getBlockData()); - } - if (++countBlocks > 10000) break; + if (closed) return; + cancel(); + closed = true; + if (audience.isOnline()) { + audience.sendMessage(Language.translate(Language.L.COMMAND__LOOKUP__PLAYBACK__STOPPED)); + audience.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Language.translate(Language.L.COMMAND__LOOKUP__PLAYBACK__STOPPED))); + actors.values().forEach(FakePlayer::remove); + actors.clear(); + int countBlocks = 0; + for (Location location : modified) { + if (audience.getWorld().equals(location.getWorld()) && location.distance(audience.getLocation()) < 250) { + audience.sendBlockChange(location, location.getBlock().getBlockData()); } + if (++countBlocks > 10000) break; } } cleanup();