Removing usage of Pair class
Dieser Commit ist enthalten in:
Ursprung
708bfb29ac
Commit
3284a77508
@ -5,7 +5,6 @@ import de.steamwar.bungeecore.listeners.BasicListener;
|
||||
import de.steamwar.bungeecore.sql.Mod;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||
import javafx.util.Pair;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.Connection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -74,11 +73,11 @@ public class Forge extends BasicListener {
|
||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
||||
|
||||
if (data[0] == 2) {
|
||||
Pair<Integer, Integer> numMods = Utils.readVarInt(data, 1);
|
||||
Utils.VarInt numMods = Utils.readVarInt(data, 1);
|
||||
List<Mod> mods = new LinkedList<>();
|
||||
|
||||
int bytePos = 1 + numMods.getKey();
|
||||
for (int i = 0; i < numMods.getValue(); i++) {
|
||||
int bytePos = 1 + numMods.length;
|
||||
for (int i = 0; i < numMods.value; i++) {
|
||||
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
|
||||
bytePos += 1 + data[bytePos];
|
||||
//Version information is unused
|
||||
|
@ -5,23 +5,22 @@ import com.google.gson.stream.JsonReader;
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||
import de.steamwar.bungeecore.sql.Mod;
|
||||
import javafx.util.Pair;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.Connection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LabyMod extends BasicListener {
|
||||
|
||||
private static Set<ProxiedPlayer> labyModUsers = new HashSet<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPluginMessageEvent(PluginMessageEvent event){
|
||||
if(!event.getTag().equals("LMC"))
|
||||
@ -32,7 +31,6 @@ public class LabyMod extends BasicListener {
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
labyModUsers.add((ProxiedPlayer) sender);
|
||||
updateGameInfo((ProxiedPlayer) sender);
|
||||
byte[] data = event.getData();
|
||||
|
||||
@ -40,15 +38,15 @@ public class LabyMod extends BasicListener {
|
||||
}
|
||||
|
||||
private void runAsync(byte[] data, ProxiedPlayer player) {
|
||||
Pair<Integer, String> purpose = readString(data, 0);
|
||||
if(!"INFO".equals(purpose.getValue()))
|
||||
VarString purpose = readString(data, 0);
|
||||
if(!"INFO".equals(purpose.value))
|
||||
return;
|
||||
|
||||
Pair<Integer, String> value = readString(data, purpose.getKey());
|
||||
VarString value = readString(data, purpose.length);
|
||||
List<Mod> mods = new LinkedList<>();
|
||||
|
||||
try{
|
||||
InfoPacket info = new InfoPacket(value.getValue());
|
||||
InfoPacket info = new InfoPacket(value.value);
|
||||
for(InfoPacket.Addon addon : info.addons) {
|
||||
mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD));
|
||||
}
|
||||
@ -59,10 +57,10 @@ public class LabyMod extends BasicListener {
|
||||
Utils.handleMods(player, mods);
|
||||
}
|
||||
|
||||
private Pair<Integer, String> readString(byte[] array, int startPos){
|
||||
Pair<Integer, Integer> varInt = Utils.readVarInt(array, startPos);
|
||||
startPos += varInt.getKey();
|
||||
return new Pair<>(varInt.getValue()+varInt.getKey(), new String(Arrays.copyOfRange(array, startPos, startPos + varInt.getValue()), StandardCharsets.UTF_8));
|
||||
private VarString readString(byte[] array, int startPos){
|
||||
Utils.VarInt varInt = Utils.readVarInt(array, startPos);
|
||||
startPos += varInt.length;
|
||||
return new VarString(varInt.value+varInt.length, new String(Arrays.copyOfRange(array, startPos, startPos + varInt.value), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private void updateGameInfo(ProxiedPlayer proxiedPlayer) {
|
||||
@ -76,6 +74,16 @@ public class LabyMod extends BasicListener {
|
||||
proxiedPlayer.sendData("LMC", output.getBytes());
|
||||
}
|
||||
|
||||
private static class VarString{
|
||||
private final int length;
|
||||
private final String value;
|
||||
|
||||
private VarString(int length, String value) {
|
||||
this.length = length;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InfoPacket{
|
||||
String version = null;
|
||||
Feature ccp = null;
|
||||
@ -154,11 +162,4 @@ public class LabyMod extends BasicListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerDisconnectEvent event){
|
||||
labyModUsers.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
//TODO: PlayerHandshakeEvent
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.sql.Mod;
|
||||
import de.steamwar.bungeecore.sql.Mod.ModType;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import javafx.util.Pair;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@ -16,7 +15,7 @@ import java.util.List;
|
||||
class Utils {
|
||||
private Utils(){}
|
||||
|
||||
static Pair<Integer, Integer> readVarInt(byte[] array, int startPos) {
|
||||
static VarInt readVarInt(byte[] array, int startPos) {
|
||||
int numRead = 0;
|
||||
int result = 0;
|
||||
byte read;
|
||||
@ -31,7 +30,7 @@ class Utils {
|
||||
}
|
||||
} while ((read & 0b10000000) != 0);
|
||||
|
||||
return new Pair<>(numRead, result);
|
||||
return new VarInt(numRead, result);
|
||||
}
|
||||
|
||||
static boolean handleMods(ProxiedPlayer player, List<Mod> mods){
|
||||
@ -68,4 +67,14 @@ class Utils {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static class VarInt{
|
||||
final int length;
|
||||
final int value;
|
||||
|
||||
VarInt(int length, int value){
|
||||
this.length = length;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren