Added debug messages
Added a way to clear all locks on a server when it was empty when a user joins
This commit is contained in:
parent
780249933c
commit
a88fbe139e
|
|
@ -30,7 +30,7 @@ public final class Config {
|
||||||
public static File CONFIG_PATH;
|
public static File CONFIG_PATH;
|
||||||
|
|
||||||
public static void init() { // todo setup share for the config
|
public static void init() { // todo setup share for the config
|
||||||
CONFIG_PATH = new File(DataLock.getDataDirectory().toAbsolutePath() + File.separator + "DataLock");
|
CONFIG_PATH = new File(DataLock.getDataDirectory().toAbsolutePath().toString());
|
||||||
File configFile = new File(CONFIG_PATH, "config.yml");
|
File configFile = new File(CONFIG_PATH, "config.yml");
|
||||||
|
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
|
|
@ -152,8 +152,12 @@ public final class Config {
|
||||||
* ONLY EDIT ANYTHING BELOW THIS LINE
|
* ONLY EDIT ANYTHING BELOW THIS LINE
|
||||||
**/
|
**/
|
||||||
public static List<String> PLUGIN_MESSAGE_CHANNELS = new ArrayList<>(List.of("example_plugin:table_1"));
|
public static List<String> PLUGIN_MESSAGE_CHANNELS = new ArrayList<>(List.of("example_plugin:table_1"));
|
||||||
|
public static boolean DEBUG = false;
|
||||||
|
|
||||||
private static void loadGroups() {
|
private static void loadSettings() {
|
||||||
PLUGIN_MESSAGE_CHANNELS = getList("settings.channels", new ArrayList<>(List.of("example_plugin:table_1")));
|
PLUGIN_MESSAGE_CHANNELS = getList("settings.channels", new ArrayList<>(List.of("example_plugin:table_1")));
|
||||||
|
DEBUG = getBoolean("settings.debug", DEBUG);
|
||||||
|
if (DEBUG)
|
||||||
|
Logger.info("DEBUG: on");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ public class DataLock {
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
server.getEventManager().register(this, EventListener.getInstance());
|
server.getEventManager().register(this, EventListener.getInstance());
|
||||||
|
server.getEventManager().register(this, new PlayerListener());
|
||||||
new Reload(server);
|
new Reload(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ public class EventListener {
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
instance = new EventListener();
|
instance = new EventListener();
|
||||||
EventListener.channelIdentifierList.clear();
|
EventListener.channelIdentifierList.clear();
|
||||||
|
ChannelRegistrar channelRegistrar = DataLock.getServer().getChannelRegistrar();
|
||||||
for (String s : Config.PLUGIN_MESSAGE_CHANNELS) {
|
for (String s : Config.PLUGIN_MESSAGE_CHANNELS) {
|
||||||
String[] split = s.split(":");
|
String[] split = s.split(":");
|
||||||
if (split.length != 2) {
|
if (split.length != 2) {
|
||||||
|
|
@ -40,13 +42,34 @@ public class EventListener {
|
||||||
Logger.warn("Duplicate message channel [%] in config.", s);
|
Logger.warn("Duplicate message channel [%] in config.", s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Loaded entry [%] as [%].", s, minecraftChannelIdentifier.asKey().asString());
|
||||||
EventListener.channelIdentifierList.add(minecraftChannelIdentifier);
|
EventListener.channelIdentifierList.add(minecraftChannelIdentifier);
|
||||||
|
channelRegistrar.register(minecraftChannelIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearServer(int hashCode) {
|
||||||
|
channelLockMap.forEach((identifier, value) -> {
|
||||||
|
HashSet<Lock> temp = new HashSet<>();
|
||||||
|
for (Lock lock : value) {
|
||||||
|
if (lock.getServerHash() == hashCode)
|
||||||
|
temp.add(lock);
|
||||||
|
}
|
||||||
|
for (Lock lock : temp) {
|
||||||
|
value.remove(lock);
|
||||||
|
queueNextLock(value, lock, identifier);
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Clearing % from % due to clear server being called for the server that lock is on", lock.getData(), identifier.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPluginMessageEvent(PluginMessageEvent event) {
|
public void onPluginMessageEvent(PluginMessageEvent event) {
|
||||||
ChannelIdentifier identifier = event.getIdentifier();
|
ChannelIdentifier identifier = event.getIdentifier();
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Received message on [%].", identifier.getId());
|
||||||
if (!EventListener.channelIdentifierList.contains(identifier))
|
if (!EventListener.channelIdentifierList.contains(identifier))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -81,6 +104,9 @@ public class EventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Config.DEBUG)
|
||||||
|
Logger.info("Plugin message channel: [%]", channel.toLowerCase());
|
||||||
|
|
||||||
switch (channel.toLowerCase()) {
|
switch (channel.toLowerCase()) {
|
||||||
case "try-lock" -> tryLock(identifier, hashLock, data, serverConnection);
|
case "try-lock" -> tryLock(identifier, hashLock, data, serverConnection);
|
||||||
case "check-lock" -> checkLock(identifier, hashLock, data, serverConnection);
|
case "check-lock" -> checkLock(identifier, hashLock, data, serverConnection);
|
||||||
|
|
|
||||||
28
src/main/java/com/alttd/datalock/PlayerListener.java
Normal file
28
src/main/java/com/alttd/datalock/PlayerListener.java
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.alttd.datalock;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class PlayerListener {
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
void onPlayerConnect(ServerConnectedEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ServerInfo serverInfo = event.getServer().getServerInfo();
|
||||||
|
if (event.getServer().getPlayersConnected().stream().filter(p -> p.equals(player)).findAny().isEmpty())
|
||||||
|
EventListener.getInstance().clearServer(serverInfo.hashCode());
|
||||||
|
|
||||||
|
Optional<RegisteredServer> previousServer = event.getPreviousServer();
|
||||||
|
if (previousServer.isEmpty())
|
||||||
|
return;
|
||||||
|
serverInfo = previousServer.get().getServerInfo();
|
||||||
|
if (event.getServer().getPlayersConnected().stream().filter(p -> p.equals(player)).findAny().isEmpty())
|
||||||
|
EventListener.getInstance().clearServer(serverInfo.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user