feat: bungeecord support on proxy and some optimizations
This commit is contained in:
parent
b3c624eaa4
commit
a4999a28a1
8 changed files with 122 additions and 26 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -43,4 +43,7 @@ v1_19_R1/target
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
# Build folder
|
# Build folder
|
||||||
target
|
target
|
||||||
|
|
||||||
|
# Maven Dependency Reduced Pom
|
||||||
|
core/dependency-reduced-pom.xml
|
|
@ -160,8 +160,21 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.cache2k</groupId>
|
||||||
|
<artifactId>cache2k-api</artifactId>
|
||||||
|
<version>2.6.1.Final</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.cache2k</groupId>
|
||||||
|
<artifactId>cache2k-core</artifactId>
|
||||||
|
<version>2.6.1.Final</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
|
<cache2k-version>2.6.1.Final</cache2k-version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
12
core/pom.xml
12
core/pom.xml
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<cache2k-version>2.6.1.Final</cache2k-version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -114,6 +115,17 @@
|
||||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||||
<version>2.14.0-rc1</version>
|
<version>2.14.0-rc1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.cache2k</groupId>
|
||||||
|
<artifactId>cache2k-api</artifactId>
|
||||||
|
<version>${cache2k-version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.cache2k</groupId>
|
||||||
|
<artifactId>cache2k-core</artifactId>
|
||||||
|
<version>${cache2k-version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -12,6 +12,10 @@ import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Nicko {
|
public class Nicko {
|
||||||
|
public static final String CHANNEL = "nicko:";
|
||||||
|
public static final String MESSAGE_UPDATE = CHANNEL + "update";
|
||||||
|
public static final String MESSAGE_FETCH = CHANNEL + "fetch";
|
||||||
|
|
||||||
private ConfigurationManager configManager;
|
private ConfigurationManager configManager;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private File dataFolder;
|
private File dataFolder;
|
||||||
|
|
|
@ -11,8 +11,6 @@ import net.artelnatif.nicko.bukkit.gui.items.main.ExitGUI;
|
||||||
import net.artelnatif.nicko.bukkit.i18n.Locale;
|
import net.artelnatif.nicko.bukkit.i18n.Locale;
|
||||||
import net.artelnatif.nicko.bukkit.i18n.LocaleFileManager;
|
import net.artelnatif.nicko.bukkit.i18n.LocaleFileManager;
|
||||||
import net.artelnatif.nicko.bukkit.placeholder.PlaceHolderHook;
|
import net.artelnatif.nicko.bukkit.placeholder.PlaceHolderHook;
|
||||||
import net.artelnatif.nicko.bukkit.messaging.PluginMessageEvent;
|
|
||||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
|
||||||
import net.artelnatif.nicko.config.Configuration;
|
import net.artelnatif.nicko.config.Configuration;
|
||||||
import net.artelnatif.nicko.impl.Internals;
|
import net.artelnatif.nicko.impl.Internals;
|
||||||
import net.artelnatif.nicko.impl.InternalsProvider;
|
import net.artelnatif.nicko.impl.InternalsProvider;
|
||||||
|
@ -50,31 +48,22 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
nicko.initBukkit(this);
|
nicko.initBukkit(this);
|
||||||
|
|
||||||
if (unitTesting) onUnitTestingStartup();
|
if (!nicko.getDataStore().getStorage().isError()) {
|
||||||
else onPluginStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnitTestingStartup() {
|
|
||||||
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
|
||||||
nicko.getDataStore().getStorage().setError(true);
|
|
||||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPluginStartup() {
|
|
||||||
getLogger().info("Loading internals...");
|
|
||||||
if (getInternals() == null) {
|
|
||||||
getLogger().severe("Nicko could not find a valid implementation for this server version. Is your server supported?");
|
|
||||||
nicko.getDataStore().getStorage().setError(true);
|
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getServer().getPluginManager().isPluginEnabled(this) && !nicko.getDataStore().getStorage().isError()) {
|
|
||||||
getLogger().info("Loading persistence...");
|
getLogger().info("Loading persistence...");
|
||||||
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
||||||
nicko.getDataStore().getStorage().setError(true);
|
nicko.getDataStore().getStorage().setError(true);
|
||||||
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unitTesting) {
|
||||||
|
getLogger().info("Loading internals...");
|
||||||
|
if (getInternals() == null) {
|
||||||
|
getLogger().severe("Nicko could not find a valid implementation for this server version. Is your server supported?");
|
||||||
|
nicko.getDataStore().getStorage().setError(true);
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
localeFileManager = new LocaleFileManager();
|
localeFileManager = new LocaleFileManager();
|
||||||
if (nicko.getConfig().isCustomLocale()) {
|
if (nicko.getConfig().isCustomLocale()) {
|
||||||
|
@ -104,7 +93,7 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
if (nicko.getConfig().isBungeecord()) {
|
if (nicko.getConfig().isBungeecord()) {
|
||||||
if (support.stopIfBungeeCordIsNotEnabled()) {
|
if (support.stopIfBungeeCordIsNotEnabled()) {
|
||||||
getLogger().info("Enabling BungeeCord support...");
|
getLogger().info("Enabling BungeeCord support...");
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.PROXY_UPDATE, new PluginMessageEvent());
|
//TODO: Enable BungeeCord
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +101,13 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onUnitTestingStartup() {
|
||||||
|
if (!nicko.getDataStore().getStorage().getProvider().init()) {
|
||||||
|
nicko.getDataStore().getStorage().setError(true);
|
||||||
|
getLogger().severe("Failed to open persistence, data will NOT be saved!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (!nicko.getDataStore().getStorage().isError()) {
|
if (!nicko.getDataStore().getStorage().isError()) {
|
||||||
|
|
|
@ -3,12 +3,13 @@ package net.artelnatif.nicko.bungee;
|
||||||
import net.artelnatif.nicko.Nicko;
|
import net.artelnatif.nicko.Nicko;
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import org.cache2k.Cache;
|
||||||
|
import org.cache2k.Cache2kBuilder;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class NickoBungee extends Plugin {
|
public class NickoBungee extends Plugin {
|
||||||
private final HashMap<UUID, NickoProfile> profiles = new HashMap<>();
|
private final Cache<UUID, NickoProfile> profileCache = Cache2kBuilder.of(UUID.class, NickoProfile.class).build();
|
||||||
private final Nicko nicko = new Nicko();
|
private final Nicko nicko = new Nicko();
|
||||||
|
|
||||||
private static NickoBungee plugin;
|
private static NickoBungee plugin;
|
||||||
|
@ -29,6 +30,8 @@ public class NickoBungee extends Plugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getProxy().registerChannel(Nicko.MESSAGE_FETCH);
|
||||||
|
getProxy().registerChannel(Nicko.MESSAGE_UPDATE);
|
||||||
getLogger().info("Nicko (Bungee) has been enabled.");
|
getLogger().info("Nicko (Bungee) has been enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,10 +39,14 @@ public class NickoBungee extends Plugin {
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (!nicko.getDataStore().getStorage().isError()) {
|
if (!nicko.getDataStore().getStorage().isError()) {
|
||||||
|
getProxy().unregisterChannel(Nicko.MESSAGE_FETCH);
|
||||||
|
getProxy().unregisterChannel(Nicko.MESSAGE_UPDATE);
|
||||||
getLogger().info("Nicko (Bungee) has been disabled.");
|
getLogger().info("Nicko (Bungee) has been disabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Cache<UUID, NickoProfile> getProfileCache() { return profileCache; }
|
||||||
|
|
||||||
public Nicko getNicko() {
|
public Nicko getNicko() {
|
||||||
return nicko;
|
return nicko;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class PluginMessageSender {
|
public class PluginMessageSender {
|
||||||
|
@ -17,4 +20,18 @@ public class PluginMessageSender {
|
||||||
}
|
}
|
||||||
info.sendData(channel, output.toByteArray(), true);
|
info.sendData(channel, output.toByteArray(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendObject(final ServerInfo info, final String channel, final Object payload) {
|
||||||
|
if (info == null) { return; }
|
||||||
|
|
||||||
|
try {
|
||||||
|
final ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream os = new ObjectOutputStream(out);
|
||||||
|
os.writeObject(payload);
|
||||||
|
info.sendData(channel, output.toByteArray(), true);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
System.out.println("massive f");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
package net.artelnatif.nicko.bungee.in;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import net.artelnatif.nicko.Nicko;
|
||||||
|
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||||
|
import net.artelnatif.nicko.bungee.PluginMessageSender;
|
||||||
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import org.cache2k.Cache;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MessageHandler implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onMessage(PluginMessageEvent event) {
|
||||||
|
final Cache<UUID, NickoProfile> cache = NickoBungee.getInstance().getProfileCache();
|
||||||
|
if (event.getTag().equalsIgnoreCase(Nicko.MESSAGE_UPDATE)) {
|
||||||
|
try {
|
||||||
|
final ByteArrayInputStream inputStream = new ByteArrayInputStream(event.getData());
|
||||||
|
final ObjectInputStream objectStream = new ObjectInputStream(inputStream);
|
||||||
|
|
||||||
|
final String uuid = objectStream.readUTF();
|
||||||
|
final NickoProfile profile = (NickoProfile) objectStream.readObject();
|
||||||
|
cache.put(UUID.fromString(uuid), profile);
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else if (event.getTag().equalsIgnoreCase(Nicko.MESSAGE_FETCH)) {
|
||||||
|
final ByteArrayDataInput input = ByteStreams.newDataInput(event.getData());
|
||||||
|
final String stringUuid = input.readUTF();
|
||||||
|
final UUID uuid = UUID.fromString(stringUuid);
|
||||||
|
final ServerInfo info = NickoBungee.getInstance().getProxy().getPlayer(uuid).getServer().getInfo();
|
||||||
|
final NickoProfile profile = cache.peekAndRemove(uuid);
|
||||||
|
PluginMessageSender.sendObject(info, Nicko.MESSAGE_FETCH, profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue