Added testing/debug stuff
This commit is contained in:
parent
a88fbe139e
commit
01456bfc9f
|
|
@ -16,6 +16,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.junit.jupiter:junit-jupiter:5.9.0'
|
||||
compileOnly 'com.velocitypowered:velocity-api:3.1.0'
|
||||
annotationProcessor 'com.velocitypowered:velocity-api:3.1.0'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,23 +13,25 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
|||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EventListener {
|
||||
|
||||
private final HashMap<ChannelIdentifier, HashSet<Lock>> queuedLocks = new HashMap<>();
|
||||
private final HashMap<ChannelIdentifier, HashSet<Lock>> channelLockMap = new HashMap<>();
|
||||
private final static List<ChannelIdentifier> channelIdentifierList = new ArrayList<>();
|
||||
private final List<ChannelIdentifier> channelIdentifierList = new ArrayList<>();
|
||||
private static EventListener instance = null;
|
||||
|
||||
public static EventListener getInstance() {
|
||||
if (instance == null)
|
||||
return new EventListener();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void reload()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = new EventListener();
|
||||
EventListener.channelIdentifierList.clear();
|
||||
instance = getInstance();
|
||||
instance.channelIdentifierList.clear();
|
||||
ChannelRegistrar channelRegistrar = DataLock.getServer().getChannelRegistrar();
|
||||
for (String s : Config.PLUGIN_MESSAGE_CHANNELS) {
|
||||
String[] split = s.split(":");
|
||||
|
|
@ -38,13 +40,13 @@ public class EventListener {
|
|||
continue;
|
||||
}
|
||||
MinecraftChannelIdentifier minecraftChannelIdentifier = MinecraftChannelIdentifier.create(split[0], split[1]);
|
||||
if (EventListener.channelIdentifierList.contains(minecraftChannelIdentifier)) {
|
||||
if (instance.channelIdentifierList.contains(minecraftChannelIdentifier)) {
|
||||
Logger.warn("Duplicate message channel [%] in config.", s);
|
||||
continue;
|
||||
}
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Loaded entry [%] as [%].", s, minecraftChannelIdentifier.asKey().asString());
|
||||
EventListener.channelIdentifierList.add(minecraftChannelIdentifier);
|
||||
instance.channelIdentifierList.add(minecraftChannelIdentifier);
|
||||
channelRegistrar.register(minecraftChannelIdentifier);
|
||||
}
|
||||
}
|
||||
|
|
@ -65,14 +67,33 @@ public class EventListener {
|
|||
});
|
||||
}
|
||||
|
||||
private String formatLockMap(HashMap<ChannelIdentifier, HashSet<Lock>> map) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (ChannelIdentifier plugin : map.keySet()) {
|
||||
stringBuilder
|
||||
.append(plugin)
|
||||
.append("\n")
|
||||
.append(
|
||||
map.get(plugin)
|
||||
.stream()
|
||||
.map(lock -> lock.getData() + " : " + lock.getServerHash())
|
||||
.collect(Collectors.joining(", ")))
|
||||
.append("\n---\n");
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessageEvent(PluginMessageEvent event) {
|
||||
ChannelIdentifier identifier = event.getIdentifier();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Received message on [%].", identifier.getId());
|
||||
if (!EventListener.channelIdentifierList.contains(identifier))
|
||||
if (!channelIdentifierList.contains(identifier))
|
||||
return;
|
||||
|
||||
if (Config.DEBUG)
|
||||
Logger.info("\nCurrent locks:\n%\nQueued locks:\n%", formatLockMap(channelLockMap), formatLockMap(queuedLocks));
|
||||
|
||||
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||
|
||||
if(event.getSource() instanceof Player) {
|
||||
|
|
|
|||
27
src/test/java/com/alttd/datalock/LockTest.java
Normal file
27
src/test/java/com/alttd/datalock/LockTest.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package com.alttd.datalock;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LockTest {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
void testEquals() {
|
||||
assertEquals(new Lock(123, "test"), new Lock(123, "test"));
|
||||
assertNotEquals(new Lock(123, "test1"), new Lock(123, "test2"));
|
||||
assertEquals(new Lock(123, "test"), new Lock(-123, "test"));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
void testHashCode() {
|
||||
assertEquals(new Lock(123, "test").hashCode(), new Lock(123, "test").hashCode());
|
||||
assertNotEquals(new Lock(123, "test1").hashCode(), new Lock(123, "test2").hashCode());
|
||||
assertEquals(new Lock(123, "test").hashCode(), new Lock(-123, "test").hashCode());
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
void compareTo() {
|
||||
assertEquals(0, new Lock(123, "test").compareTo(new Lock(123, "test")));
|
||||
assertNotEquals(0, new Lock(123, "test1").compareTo(new Lock(123, "test")));
|
||||
assertNotEquals(0, new Lock(123, "test").compareTo(new Lock(-123, "test")));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user