Skip to content

Commit 583ed4b

Browse files
committed
Update scoreboard team class
Addresses #1232
1 parent 638e81b commit 583ed4b

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/main/java/com/comphenix/protocol/PacketType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static class Server extends PacketTypeEnum {
187187
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x52, "UpdateHealth", "SPacketUpdateHealth");
188188
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x53, "ScoreboardObjective", "SPacketScoreboardObjective");
189189
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x54, "Mount", "SPacketSetPassengers");
190-
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam", "SPacketTeams");
190+
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam$b", "ScoreboardTeam", "SPacketTeams");
191191
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x56, "ScoreboardScore", "SPacketUpdateScore");
192192
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x57, "SetSubtitleText");
193193
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x58, "UpdateTime", "SPacketTimeUpdate");

src/main/java/com/comphenix/protocol/injector/netty/ProtocolRegistry.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,10 @@ public synchronized void synchronize() {
111111
protected abstract void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender);
112112

113113
/**
114-
* Retrieve the number of mapping in all the maps.
115-
* @param maps - iterable of maps.
116-
* @return The sum of all the entries.
114+
* @deprecated Not a public API
117115
*/
118-
protected final int sum(Iterable<? extends Map<Integer, Class<?>>> maps) {
119-
int count = 0;
120-
121-
for (Map<Integer, Class<?>> map : maps)
122-
count += map.size();
123-
return count;
116+
@Deprecated
117+
public void _associate(PacketType type, Class<?> clazz) {
118+
register.typeToClass.put(type, clazz);
124119
}
125120
}

src/main/java/com/comphenix/protocol/injector/packet/PacketRegistry.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package com.comphenix.protocol.injector.packet;
1919

20+
import java.lang.reflect.Modifier;
21+
import java.util.List;
2022
import java.util.Map;
2123
import java.util.Set;
2224

@@ -62,7 +64,7 @@ private static void initialize() {
6264
*/
6365
public static boolean isSupported(PacketType type) {
6466
initialize();
65-
return NETTY.getPacketTypeLookup().containsKey(type);
67+
return NETTY.getPacketTypeLookup().get(type) != null;
6668
}
6769

6870
/**
@@ -136,7 +138,21 @@ public static Class getPacketClassFromID(int packetID) {
136138
public static Class getPacketClassFromType(PacketType type) {
137139
return getPacketClassFromType(type, false);
138140
}
139-
141+
142+
private static Class<?> searchForPacket(List<String> classNames) {
143+
for (String name : classNames) {
144+
try {
145+
Class<?> clazz = MinecraftReflection.getMinecraftClass(name);
146+
if (MinecraftReflection.getPacketClass().isAssignableFrom(clazz)
147+
&& !Modifier.isAbstract(clazz.getModifiers())) {
148+
return clazz;
149+
}
150+
} catch (Exception ignored) {}
151+
}
152+
153+
return null;
154+
}
155+
140156
/**
141157
* Retrieves the correct packet class from a given type.
142158
* <p>
@@ -155,14 +171,10 @@ public static Class getPacketClassFromType(PacketType type, boolean forceVanilla
155171
}
156172

157173
// Then try looking up the class names
158-
for (String name : type.getClassNames()) {
159-
try {
160-
clazz = MinecraftReflection.getMinecraftClass(name);
161-
break;
162-
} catch (Exception ignored) { }
163-
}
174+
clazz = searchForPacket(type.getClassNames());
164175

165-
// TODO Cache the result?
176+
// cache it for next time
177+
NETTY._associate(type, clazz);
166178
return clazz;
167179
}
168180

0 commit comments

Comments
 (0)