Close web editor sockets on plugin disable (#3326)

This commit is contained in:
Luck 2022-03-20 10:45:59 +00:00
parent fb56189f0a
commit eece15d415
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 18 additions and 2 deletions

View File

@ -58,6 +58,7 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
import me.lucko.luckperms.common.tasks.SyncTask;
import me.lucko.luckperms.common.treeview.PermissionRegistry;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.common.webeditor.socket.WebEditorSocket;
import me.lucko.luckperms.common.webeditor.store.WebEditorStore;
import net.luckperms.api.LuckPerms;
@ -234,6 +235,13 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// cancel delayed/repeating tasks
getBootstrap().getScheduler().shutdownScheduler();
// close web editor sockets
for (WebEditorSocket socket : this.webEditorStore.sockets().getSockets()) {
if (!socket.isClosed()) {
socket.close();
}
}
// shutdown permission vault and verbose handler tasks
this.permissionRegistry.close();
this.verboseHandler.close();

View File

@ -217,6 +217,7 @@ public class WebEditorSocket {
private void closeSocket() {
this.socket.socket().close(1000, "Normal");
this.plugin.getWebEditorStore().sockets().removeSocket(this);
this.closed = true;
}

View File

@ -31,13 +31,12 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.CaffeineFactory;
import me.lucko.luckperms.common.webeditor.socket.WebEditorSocket;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public final class WebEditorSocketMap {
private final Cache<UUID, WebEditorSocket> sockets = CaffeineFactory.newBuilder()
.weakValues()
.expireAfterWrite(5, TimeUnit.MINUTES)
.build();
public WebEditorSocket getSocket(Sender sender) {
@ -47,4 +46,12 @@ public final class WebEditorSocketMap {
public void putSocket(Sender sender, WebEditorSocket socket) {
this.sockets.put(sender.getUniqueId(), socket);
}
public void removeSocket(WebEditorSocket socket) {
this.sockets.asMap().values().remove(socket);
}
public Collection<WebEditorSocket> getSockets() {
return this.sockets.asMap().values();
}
}