Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.30'

// Tests
testImplementation 'com.viaversion:viaversion:5.9.1'
testImplementation 'com.viaversion:viabackwards:5.3.2'
testImplementation 'io.netty:netty-all:4.1.97.Final'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.18:2.85.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.18:2.85.2'
testRuntimeOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
testRuntimeOnly 'io.netty:netty-all:4.1.97.Final'
testRuntimeOnly 'it.unimi.dsi:fastutil:8.5.16'
testRuntimeOnly 'com.viaversion:viaversion:5.9.1'
testRuntimeOnly 'com.viaversion:viabackwards:5.3.2'
}

processResources {
Expand Down Expand Up @@ -96,4 +98,4 @@ test {
events "passed", "skipped", "failed"
exceptionFormat = "full"
}
}
}
Binary file modified builds/TuffXPlus-1.0.1-beta.jar
Binary file not shown.
10 changes: 6 additions & 4 deletions src/main/java/tf/tuff/ServerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;

import tf.tuff.util.SchedulerCompat;

public class ServerRegistry {
private final JavaPlugin p;
private final String wsUrl;
private final String server;
private WebSocketClient client;
private boolean running = true;
private volatile boolean running = true;

public ServerRegistry(JavaPlugin pl, String registryUrl, String serverAddr) {
p = pl;
Expand All @@ -19,7 +21,7 @@ public ServerRegistry(JavaPlugin pl, String registryUrl, String serverAddr) {
}

public void connect() {
p.getServer().getScheduler().runTaskAsynchronously(p, this::doConnect);
SchedulerCompat.runAsync(p, this::doConnect);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

private void doConnect() {
Expand All @@ -40,7 +42,7 @@ public void onMessage(String msg) {
@Override
public void onClose(int code, String reason, boolean remote) {
if (running) {
p.getServer().getScheduler().runTaskLaterAsynchronously(p, () -> doConnect(), 100L);
SchedulerCompat.runAsyncLater(p, ServerRegistry.this::doConnect, 100L);
}
}

Expand All @@ -52,7 +54,7 @@ public void onError(Exception e) {
client.connect();
} catch (Exception e) {
if (running) {
p.getServer().getScheduler().runTaskLaterAsynchronously(p, () -> doConnect(), 100L);
SchedulerCompat.runAsyncLater(p, this::doConnect, 100L);
}
}
}
Expand Down
42 changes: 33 additions & 9 deletions src/main/java/tf/tuff/TuffX.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import tf.tuff.netty.ChunkInjector;
import tf.tuff.tuffactions.TuffActions;
import tf.tuff.util.SchedulerCompat;
import tf.tuff.viablocks.ViaBlocksPlugin;
import tf.tuff.viaentities.ViaEntitiesPlugin;
import tf.tuff.y0.Y0Plugin;
Expand All @@ -39,11 +40,13 @@ public class TuffX extends JavaPlugin implements Listener, PluginMessageListener
public TuffActions tuffActions;
public ViaEntitiesPlugin viaEntitiesPlugin;
private ChunkInjector chunkInjector;
private boolean packetEventsEnabled;

// required by MockBukkit
public TuffX(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
super(loader, description, dataFolder, file);
}
public TuffX() { super(); }

@Override
public void onLoad() {
Expand All @@ -52,18 +55,29 @@ public void onLoad() {
this.tuffActions = new TuffActions(this);
this.viaEntitiesPlugin = new ViaEntitiesPlugin(this);

PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().reEncodeByDefault(false)
.checkForUpdates(false);
PacketEvents.getAPI().load();
if (shouldBootstrapPacketEvents()) {
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().reEncodeByDefault(false)
.checkForUpdates(false);
PacketEvents.getAPI().load();
packetEventsEnabled = true;
}
}

@Override
public void onEnable() {
PacketEvents.getAPI().init();
if (packetEventsEnabled && PacketEvents.getAPI() != null) {
PacketEvents.getAPI().init();
} else {
packetEventsEnabled = false;
}

saveDefaultConfig();

getLogger().info(SchedulerCompat.isFolia()
? "Folia detected. Using region and entity schedulers."
: "Using standard Bukkit-compatible schedulers.");

y0Plugin.onTuffXEnable();
tuffActions.onTuffXEnable();
viaBlocksPlugin.onTuffXEnable();
Expand All @@ -76,9 +90,11 @@ public void onEnable() {
getConfig().options().copyDefaults(true);
saveConfig();

PacketEvents.getAPI().getEventManager().registerListener(
new NetworkListener(this), PacketListenerPriority.NORMAL
);
if (packetEventsEnabled) {
PacketEvents.getAPI().getEventManager().registerListener(
new NetworkListener(this), PacketListenerPriority.NORMAL
);
}

getServer().getPluginManager().registerEvents(this, this);

Expand Down Expand Up @@ -109,12 +125,20 @@ public void onDisable() {
serverRegistry = null;
}

PacketEvents.getAPI().terminate();
if (packetEventsEnabled && PacketEvents.getAPI() != null) {
PacketEvents.getAPI().terminate();
}
packetEventsEnabled = false;

getServer().getMessenger().unregisterIncomingPluginChannel(this);
getServer().getMessenger().unregisterOutgoingPluginChannel(this);
}

private boolean shouldBootstrapPacketEvents() {
return getServer() == null
|| !getServer().getClass().getName().startsWith("be.seeseemelk.mockbukkit");
}

public void reloadTuffX(){
saveDefaultConfig();
reloadConfig();
Expand Down
Loading
Loading