feat: revert bad idea

This commit is contained in:
aro 2023-02-08 19:39:09 +01:00
parent cb8cf571b8
commit bce3578fe8
7 changed files with 8 additions and 150 deletions

View file

@ -11,7 +11,7 @@ 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.pluginchannel.PluginMessageHandler; import net.artelnatif.nicko.bukkit.messaging.PluginMessageEvent;
import net.artelnatif.nicko.bungee.NickoBungee; 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;
@ -104,7 +104,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 PluginMessageHandler()); getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.PROXY_UPDATE, new PluginMessageEvent());
} }
} }

View file

@ -1,35 +0,0 @@
package net.artelnatif.nicko.bukkit.pluginchannel;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import net.artelnatif.nicko.bukkit.NickoBukkit;
import net.artelnatif.nicko.bungee.NickoBungee;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.util.ArrayList;
public class PluginMessageHandler implements PluginMessageListener {
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
if (!channel.equals(NickoBungee.SERVER_DATA)) {
return;
}
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 + "!");
NickoBukkit.getInstance().getLogger().severe("This should not have happened, open an issue at https://atnrch.xyz/git/aro/Nicko !");
return;
}
final ArrayList<String> decodedPayload = new ArrayList<>(payloadSize);
for (int i = 0; i < payloadSize; i++) {
decodedPayload.add(in.readUTF());
}
System.out.println("decodedPayload = " + decodedPayload);
}
}

View file

@ -1,15 +1,14 @@
package net.artelnatif.nicko.bungee; package net.artelnatif.nicko.bungee;
import net.artelnatif.nicko.Nicko; import net.artelnatif.nicko.Nicko;
import net.artelnatif.nicko.bungee.event.UpdateMessageListener; import net.artelnatif.nicko.disguise.NickoProfile;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
public class NickoBungee extends Plugin { import java.util.HashMap;
public static final String NICKO_PLUGIN_CHANNEL_BASE = "nicko:"; import java.util.UUID;
public static final String PROXY_UPDATE = NICKO_PLUGIN_CHANNEL_BASE + "update";
public static final String PROXY_FETCH = NICKO_PLUGIN_CHANNEL_BASE + "fetch";
public static final String SERVER_DATA = NICKO_PLUGIN_CHANNEL_BASE + "data";
public class NickoBungee extends Plugin {
private final HashMap<UUID, NickoProfile> profiles = new HashMap<>();
private final Nicko nicko = new Nicko(); private final Nicko nicko = new Nicko();
private static NickoBungee plugin; private static NickoBungee plugin;
@ -30,12 +29,6 @@ public class NickoBungee extends Plugin {
return; return;
} }
getLogger().info("Registering channel...");
getProxy().registerChannel(SERVER_DATA);
getLogger().info("Registering listener...");
getProxy().getPluginManager().registerListener(this, new UpdateMessageListener());
getLogger().info("Nicko (Bungee) has been enabled."); getLogger().info("Nicko (Bungee) has been enabled.");
} }
} }
@ -43,9 +36,6 @@ public class NickoBungee extends Plugin {
@Override @Override
public void onDisable() { public void onDisable() {
if (!nicko.getDataStore().getStorage().isError()) { if (!nicko.getDataStore().getStorage().isError()) {
getLogger().info("Unregistering channels...");
getProxy().unregisterChannel(PROXY_UPDATE);
getLogger().info("Nicko (Bungee) has been disabled."); getLogger().info("Nicko (Bungee) has been disabled.");
} }
} }

View file

@ -1,4 +1,4 @@
package net.artelnatif.nicko.bungee.message; package net.artelnatif.nicko.bungee;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;

View file

@ -1,53 +0,0 @@
package net.artelnatif.nicko.bungee.event;
import net.artelnatif.nicko.bungee.NickoBungee;
import net.artelnatif.nicko.bungee.message.PluginMessageSender;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
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.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Optional;
import java.util.UUID;
public class FetchMessageListener implements Listener {
@EventHandler
public void onMessage(PluginMessageEvent event) {
if (!event.getTag().equals(NickoBungee.PROXY_FETCH)) { return; }
try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(event.getData()))) {
final NickoBungee instance = NickoBungee.getInstance();
final ProxyServer proxy = instance.getProxy();
final String stringUuid = input.readUTF();
final UUID uuid = UUID.fromString(stringUuid);
final ProxiedPlayer player = proxy.getPlayer(uuid);
final ServerInfo serverInfo = player.getServer().getInfo();
final Optional<NickoProfile> optionalProfile = instance.getNicko().getDataStore().getData(uuid);
if (optionalProfile.isPresent()) {
final NickoProfile profile = optionalProfile.get();
final ArrayList<String> payload = new ArrayList<>();
payload.add(player.getUniqueId().toString());
payload.add(profile.getName());
payload.add(profile.getSkin());
payload.add(String.valueOf(profile.isBungeecordTransfer()));
payload.add(profile.getLocale().getCode());
PluginMessageSender.send(serverInfo, NickoBungee.SERVER_DATA, payload);
return;
}
instance.getNicko().getLogger().warning("Unable to send profile to distant server!");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,27 +0,0 @@
package net.artelnatif.nicko.bungee.event;
import net.artelnatif.nicko.bungee.NickoBungee;
import net.artelnatif.nicko.bungee.message.MessageDecoder;
import net.artelnatif.nicko.disguise.NickoProfile;
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.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
public class UpdateMessageListener implements Listener {
@EventHandler
public void onMessage(PluginMessageEvent event) {
if (!event.getTag().equals(NickoBungee.PROXY_UPDATE)) { return; }
try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(event.getData()))) {
final NickoProfile profile = MessageDecoder.decode(input);
// TODO: 1/28/23 STORE PROFILE
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,17 +0,0 @@
package net.artelnatif.nicko.bungee.message;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.bukkit.i18n.Locale;
import java.io.DataInputStream;
import java.io.IOException;
public class MessageDecoder {
public static final int STRING_SIZE = 3;
public static NickoProfile decode(DataInputStream input) throws IOException {
final String[] stringValues = new String[3];
for (int i = 1; i < STRING_SIZE; i++) { stringValues[i] = input.readUTF(); }
return new NickoProfile(stringValues[0], stringValues[1], Locale.valueOf(stringValues[2]), true);
}
}