Update scoreboard team class

Addresses #1232
This commit is contained in:
Dan Mulloy 2021-06-20 12:35:03 -04:00
parent 638e81b9ce
commit 583ed4b58a
No known key found for this signature in database
GPG Key ID: BFACD592A5F0DFD6
3 changed files with 26 additions and 19 deletions

View File

@ -187,7 +187,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x52, "UpdateHealth", "SPacketUpdateHealth");
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x53, "ScoreboardObjective", "SPacketScoreboardObjective");
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x54, "Mount", "SPacketSetPassengers");
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam", "SPacketTeams");
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam$b", "ScoreboardTeam", "SPacketTeams");
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x56, "ScoreboardScore", "SPacketUpdateScore");
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x57, "SetSubtitleText");
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x58, "UpdateTime", "SPacketTimeUpdate");

View File

@ -111,15 +111,10 @@ public abstract class ProtocolRegistry {
protected abstract void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender);
/**
* Retrieve the number of mapping in all the maps.
* @param maps - iterable of maps.
* @return The sum of all the entries.
* @deprecated Not a public API
*/
protected final int sum(Iterable<? extends Map<Integer, Class<?>>> maps) {
int count = 0;
for (Map<Integer, Class<?>> map : maps)
count += map.size();
return count;
@Deprecated
public void _associate(PacketType type, Class<?> clazz) {
register.typeToClass.put(type, clazz);
}
}

View File

@ -17,6 +17,8 @@
package com.comphenix.protocol.injector.packet;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -62,7 +64,7 @@ public class PacketRegistry {
*/
public static boolean isSupported(PacketType type) {
initialize();
return NETTY.getPacketTypeLookup().containsKey(type);
return NETTY.getPacketTypeLookup().get(type) != null;
}
/**
@ -136,7 +138,21 @@ public class PacketRegistry {
public static Class getPacketClassFromType(PacketType type) {
return getPacketClassFromType(type, false);
}
private static Class<?> searchForPacket(List<String> classNames) {
for (String name : classNames) {
try {
Class<?> clazz = MinecraftReflection.getMinecraftClass(name);
if (MinecraftReflection.getPacketClass().isAssignableFrom(clazz)
&& !Modifier.isAbstract(clazz.getModifiers())) {
return clazz;
}
} catch (Exception ignored) {}
}
return null;
}
/**
* Retrieves the correct packet class from a given type.
* <p>
@ -155,14 +171,10 @@ public class PacketRegistry {
}
// Then try looking up the class names
for (String name : type.getClassNames()) {
try {
clazz = MinecraftReflection.getMinecraftClass(name);
break;
} catch (Exception ignored) { }
}
clazz = searchForPacket(type.getClassNames());
// TODO Cache the result?
// cache it for next time
NETTY._associate(type, clazz);
return clazz;
}