feat: figuring out bungee support
This commit is contained in:
parent
3f86c3c405
commit
ba778db81a
8 changed files with 55 additions and 47 deletions
|
@ -1,5 +1,7 @@
|
|||
package net.artelnatif.nicko.bungee;
|
||||
|
||||
import net.artelnatif.nicko.bungee.event.PluginMessageListener;
|
||||
import net.artelnatif.nicko.bungee.event.ServerSwitchListener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class NickoBungee extends Plugin {
|
||||
|
@ -17,6 +19,10 @@ public class NickoBungee extends Plugin {
|
|||
getProxy().registerChannel(NICKO_PLUGIN_CHANNEL_FETCH);
|
||||
getProxy().registerChannel(NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
|
||||
getLogger().info("Registering listeners...");
|
||||
getProxy().getPluginManager().registerListener(this, new ServerSwitchListener());
|
||||
getProxy().getPluginManager().registerListener(this, new PluginMessageListener());
|
||||
|
||||
getLogger().info("Nicko (Bungee) has been enabled.");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package net.artelnatif.nicko.bungee.event;
|
||||
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PluginMessageListener implements Listener {
|
||||
@EventHandler
|
||||
public void onSwitch(PluginMessageEvent event) {
|
||||
final String message = Arrays.toString(event.getData());
|
||||
System.out.println("message = " + message);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package net.artelnatif.nicko.bungee.event;
|
||||
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.bungee.pluginchannel.PluginChannelHelper;
|
||||
import net.artelnatif.nicko.bungee.pluginchannel.PluginMessageUtils;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
@ -10,23 +10,12 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class ServerSwitchListener implements Listener {
|
||||
|
||||
/*
|
||||
* Nicko Message Format
|
||||
* FETCH: nicko:skin/fetch
|
||||
* - UUID
|
||||
*
|
||||
* UPDATE: nicko:skin/update
|
||||
* - UUID
|
||||
* - Skin
|
||||
* - Name
|
||||
*/
|
||||
|
||||
@EventHandler
|
||||
public void onSwitch(ServerSwitchEvent event) {
|
||||
final ServerInfo from = event.getFrom();
|
||||
final ProxiedPlayer player = event.getPlayer();
|
||||
final Server to = player.getServer();
|
||||
PluginChannelHelper.sendMessage(from, NickoBungee.NICKO_PLUGIN_CHANNEL_FETCH, player.getUniqueId().toString());
|
||||
System.out.println("NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE = " + NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
PluginMessageUtils.sendMessage(from, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, player.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,16 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
public class PluginChannelHelper {
|
||||
public static boolean sendMessage(final ServerInfo info, final String channel, final String... data) {
|
||||
public class PluginMessageUtils {
|
||||
public static void sendMessage(final ServerInfo info, final String channel, final String... data) {
|
||||
if (info == null) { return; }
|
||||
|
||||
final ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
output.writeUTF(channel);
|
||||
for (String elt : data) {
|
||||
output.writeUTF(elt);
|
||||
}
|
||||
System.out.printf("(%s) PluginMessage <-> %s", info.getSocketAddress().toString(), output);
|
||||
return info.sendData(channel, output.toByteArray(), false);
|
||||
info.sendData(channel, output.toByteArray(), true);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.apache.commons.lang.LocaleUtils;
|
||||
import org.apache.commons.lang3.LocaleUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
|
|
@ -9,6 +9,7 @@ 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;
|
||||
}
|
||||
|
@ -16,7 +17,8 @@ public class UpdateMessageHandler implements PluginMessageListener {
|
|||
final ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
final String subchannel = in.readUTF();
|
||||
if(subchannel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
// TODO: 10/20/22 update player
|
||||
System.out.println("subchannel = " + subchannel);
|
||||
System.out.println("Received " + NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE + " msg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue