Force packets to be handled sync

This commit is contained in:
libraryaddict 2020-03-25 16:37:18 +13:00
parent e3d4659545
commit d2b078be85
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4

View File

@ -14,6 +14,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
public class PacketsManager { public class PacketsManager {
private static PacketListener clientInteractEntityListener; private static PacketListener clientInteractEntityListener;
@ -66,22 +67,6 @@ public class PacketsManager {
return inventoryModifierEnabled; return inventoryModifierEnabled;
} }
public static boolean isViewDisguisesListenerEnabled() {
return viewDisguisesListenerEnabled;
}
public static void setHearDisguisesListener(boolean enabled) {
if (soundsListenerEnabled != enabled) {
soundsListenerEnabled = enabled;
if (soundsListenerEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener);
}
}
}
public static void setInventoryListenerEnabled(boolean enabled) { public static void setInventoryListenerEnabled(boolean enabled) {
if (inventoryModifierEnabled != enabled) { if (inventoryModifierEnabled != enabled) {
inventoryModifierEnabled = enabled; inventoryModifierEnabled = enabled;
@ -105,10 +90,27 @@ public class PacketsManager {
} }
} }
public static boolean isViewDisguisesListenerEnabled() {
return viewDisguisesListenerEnabled;
}
public static void setHearDisguisesListener(boolean enabled) {
if (soundsListenerEnabled != enabled) {
soundsListenerEnabled = enabled;
if (soundsListenerEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener);
}
}
}
public static void setupMainPacketsListener() { public static void setupMainPacketsListener() {
if (clientInteractEntityListener != null) { if (clientInteractEntityListener != null) {
if (mainListener != null) { if (mainListener != null) {
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener); // ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
ProtocolLibrary.getProtocolManager().getAsynchronousManager().unregisterAsyncHandler(mainListener);
} }
ArrayList<PacketType> packetsToListen = new ArrayList<>(); ArrayList<PacketType> packetsToListen = new ArrayList<>();
@ -161,7 +163,9 @@ public class PacketsManager {
mainListener = new PacketListenerMain(LibsDisguises.getInstance(), packetsToListen); mainListener = new PacketListenerMain(LibsDisguises.getInstance(), packetsToListen);
ProtocolLibrary.getProtocolManager().addPacketListener(mainListener); // ProtocolLibrary.getProtocolManager().addPacketListener(mainListener);
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(mainListener)
.syncStart(10, TimeUnit.SECONDS);
} }
} }
@ -170,9 +174,13 @@ public class PacketsManager {
viewDisguisesListenerEnabled = enabled; viewDisguisesListenerEnabled = enabled;
if (viewDisguisesListenerEnabled) { if (viewDisguisesListenerEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener); //ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
ProtocolLibrary.getProtocolManager().getAsynchronousManager()
.registerAsyncHandler(viewDisguisesListener).syncStart(10, TimeUnit.SECONDS);
} else { } else {
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener); ProtocolLibrary.getProtocolManager().getAsynchronousManager()
.unregisterAsyncHandler(viewDisguisesListener);
// ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
} }
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {