feat: check the other way for bungee support
This commit is contained in:
parent
ba778db81a
commit
573463d7f3
4 changed files with 53 additions and 28 deletions
|
@ -15,7 +15,7 @@ import net.artelnatif.nicko.i18n.LocaleManager;
|
|||
import net.artelnatif.nicko.impl.Internals;
|
||||
import net.artelnatif.nicko.impl.InternalsProvider;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.pluginchannel.UpdateMessageHandler;
|
||||
import net.artelnatif.nicko.pluginchannel.PluginMessageHandler;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import net.artelnatif.nicko.utils.ServerUtils;
|
||||
import org.bukkit.Material;
|
||||
|
@ -73,10 +73,11 @@ public class NickoBukkit extends JavaPlugin {
|
|||
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
|
||||
ServerUtils.checkSpigotBungeeCordHook();
|
||||
if (nickoConfiguration.isBungeecordEnabled()) {
|
||||
getLogger().info("Enabling Bungeecord support...");
|
||||
if (ServerUtils.checkBungeeCordHook()) {
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, new UpdateMessageHandler());
|
||||
getLogger().info("Enabling BungeeCord support...");
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, new PluginMessageHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package net.artelnatif.nicko.pluginchannel;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UpdateMessageHandler implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if (!channel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Received " + NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE + " msg");
|
||||
final ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
|
||||
final int payloadSize = in.readInt();
|
||||
if (payloadSize == 0 || payloadSize > 4) {
|
||||
NickoBukkit.getInstance().getLogger().severe("Prevented error by skipping malformed payload of size " + payloadSize + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
final ArrayList<String> decodedPayload = new ArrayList<>(payloadSize);
|
||||
for (int i = 0; i < payloadSize; i++) {
|
||||
decodedPayload.add(in.readUTF());
|
||||
}
|
||||
|
||||
System.out.println("decodedPayload = " + decodedPayload);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package net.artelnatif.nicko.pluginchannel;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class UpdateMessageHandler implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
System.out.println("channel = " + channel);
|
||||
if(!channel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
final String subchannel = in.readUTF();
|
||||
if(subchannel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
System.out.println("subchannel = " + subchannel);
|
||||
System.out.println("Received " + NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE + " msg");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,18 @@ import org.bukkit.Server;
|
|||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class ServerUtils {
|
||||
public static void checkSpigotBungeeCordHook() {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
final Server server = instance.getServer();
|
||||
final YamlConfiguration config = server.spigot().getConfig();
|
||||
if (config.getConfigurationSection("settings").getBoolean("bungeecord") && instance.getNickoConfig().isBungeecordEnabled()) {
|
||||
instance.getLogger().severe("Hummm. Your server is hooked to BungeeCord, but it seems");
|
||||
instance.getLogger().severe("that BungeeCord support is not enabled inside Nicko.");
|
||||
instance.getLogger().severe("If this is intentional, you can safely ignore this message.");
|
||||
instance.getLogger().severe("Otherwise, you can enable BungeeCord support inside Nicko's configuration file.");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkBungeeCordHook() {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
final Server server = instance.getServer();
|
||||
|
@ -12,7 +24,7 @@ public class ServerUtils {
|
|||
if (!config.getConfigurationSection("settings").getBoolean("bungeecord")) {
|
||||
instance.getLogger().severe("Hummm. You have enabled BungeeCord support inside Nicko,");
|
||||
instance.getLogger().severe("but it seems that your server is not hooked to your BungeeCord instance.");
|
||||
instance.getLogger().severe("If the server is already hooked to BungeeCord, please enable it into your spigot.yml aswell.");
|
||||
instance.getLogger().severe("Please enable BungeeCord support inside your spigot.yml as well.");
|
||||
instance.getLogger().severe("The plugin will not continue.");
|
||||
instance.getServer().getPluginManager().disablePlugin(instance);
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue