Skip to content

Commit

Permalink
'adjust bungee reconnect'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 2, 2021
1 parent 7ff4da9 commit b2f980b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
@@ -1,6 +1,7 @@
package com.denizenscript.depenizen.bukkit.bungee;

import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.scripts.commands.core.AdjustCommand;
import com.denizenscript.depenizen.bukkit.Depenizen;
import com.denizenscript.depenizen.bukkit.bungee.packets.in.*;
import com.denizenscript.depenizen.bukkit.bungee.packets.out.ControlsProxyCommandPacketOut;
Expand Down Expand Up @@ -120,15 +121,15 @@ public void init(String address, int port) {

public boolean reconnectPending = false;

public void reconnect() {
public void reconnect(boolean delay) {
if (reconnectPending || shuttingDown) {
return;
}
connected = false;
Bukkit.getScheduler().scheduleSyncDelayedTask(Depenizen.instance, () -> {
reconnectPending = false;
connect();
}, 20 * 5);
}, delay ? 20 * 5 : 0);
}

public boolean shuttingDown = false;
Expand Down Expand Up @@ -171,7 +172,7 @@ public void initChannel(SocketChannel ch) {
});
b.connect(address, port).addListener(future -> Bukkit.getScheduler().scheduleSyncDelayedTask(Depenizen.instance, () -> {
if (!connected && !hasConnectionLoading) {
reconnect();
reconnect(true);
}
}, 10));
showedLastError = false;
Expand All @@ -181,7 +182,7 @@ public void initChannel(SocketChannel ch) {
showedLastError = true;
Debug.echoError(ex);
}
reconnect();
reconnect(true);
}
}

Expand Down Expand Up @@ -219,6 +220,36 @@ public void run(ReplaceableTagEvent event) {
ticksTilKeepalive = keepAliveTickRate;
}
}, 1, 1);
// <--[ObjectType]
// @name bungee
// @prefix None
// @base None
// @plugin Depenizen, DepenizenBungee, BungeeCord
// @format
// N/A
//
// @description
// "bungee" is an internal pseudo-ObjectType that is used as a mechanism adjust target for some global mechanisms.
//
// -->
AdjustCommand.specialAdjustables.put("bungee", mechanism -> {

// <--[mechanism]
// @object bungee
// @name reconnect
// @input None
// @plugin Depenizen, DepenizenBungee, BungeeCord
// @description
// Immediately forces Bungee to do a full disconnect and reconnect.
// For example: - adjust bungee reconnect
// -->
if (mechanism.matches("reconnect")) {
if (BungeeBridge.instance.connected) {
BungeeBridge.instance.handler.fail("Reconnect requested");
}
BungeeBridge.instance.reconnect(false);
}
});
}

public void tagEvent(ReplaceableTagEvent event) {
Expand Down
Expand Up @@ -75,7 +75,7 @@ public void handlerRemoved(ChannelHandlerContext ctx) {
packetBuffer.release();
packetBuffer = null;
BungeeBridge.instance.connected = false;
BungeeBridge.instance.reconnect();
BungeeBridge.instance.reconnect(true);
}

@Override
Expand Down

0 comments on commit b2f980b

Please sign in to comment.