Skip to content

Commit f99b977

Browse files
committed
Restore backwards compatibility, restructure poms
1 parent b00ae2f commit f99b977

File tree

10 files changed

+104
-127
lines changed

10 files changed

+104
-127
lines changed

modules/API/pom.xml

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<artifactId>ProtocolLib-API</artifactId>
55
<name>ProtocolLib-API</name>
6-
<version>4.3.0-SNAPSHOT</version>
6+
<version>${minorVersion}</version>
77

88
<description>Provides read/write access to the Minecraft protocol.</description>
99
<url>http://www.spigotmc.org/resources/protocollib.1997/</url>
@@ -20,6 +20,7 @@
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121
<project.build.number></project.build.number>
2222
<project.fullVersion>${project.version}</project.fullVersion>
23+
<spigotVersion>1.12-pre2-SNAPSHOT</spigotVersion>
2324
</properties>
2425

2526
<build>
@@ -191,62 +192,4 @@
191192
<timezone>1</timezone>
192193
</developer>
193194
</developers>
194-
195-
<dependencies>
196-
<!-- Included with Minecraft
197-
<dependency>
198-
<groupId>io.netty</groupId>
199-
<artifactId>netty-all</artifactId>
200-
<version>4.0.23.Final</version>
201-
</dependency>
202-
-->
203-
<dependency>
204-
<groupId>org.spigotmc</groupId>
205-
<artifactId>spigot-api</artifactId>
206-
<version>${spigotVersion}</version>
207-
<scope>provided</scope>
208-
</dependency>
209-
<dependency>
210-
<groupId>org.spigotmc</groupId>
211-
<artifactId>spigot</artifactId>
212-
<version>${spigotVersion}</version>
213-
<scope>provided</scope>
214-
</dependency>
215-
<dependency>
216-
<groupId>cglib</groupId>
217-
<artifactId>cglib-nodep</artifactId>
218-
<version>2.2.2</version>
219-
<scope>compile</scope>
220-
</dependency>
221-
<dependency>
222-
<groupId>com.comphenix.executors</groupId>
223-
<artifactId>BukkitExecutors</artifactId>
224-
<version>1.1-SNAPSHOT</version>
225-
<scope>compile</scope>
226-
</dependency>
227-
<dependency>
228-
<groupId>junit</groupId>
229-
<artifactId>junit</artifactId>
230-
<version>4.10</version>
231-
<scope>test</scope>
232-
</dependency>
233-
<dependency>
234-
<groupId>org.mockito</groupId>
235-
<artifactId>mockito-all</artifactId>
236-
<version>1.8.4</version>
237-
<scope>test</scope>
238-
</dependency>
239-
<dependency>
240-
<groupId>org.powermock</groupId>
241-
<artifactId>powermock-module-junit4</artifactId>
242-
<version>1.5</version>
243-
<scope>test</scope>
244-
</dependency>
245-
<dependency>
246-
<groupId>org.powermock</groupId>
247-
<artifactId>powermock-api-mockito</artifactId>
248-
<version>1.5</version>
249-
<scope>test</scope>
250-
</dependency>
251-
</dependencies>
252195
</project>

modules/API/src/main/java/com/comphenix/protocol/injector/netty/NettyByteBufAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* all indexing in the byte buffer.
4646
* @author Kristian
4747
*/
48+
@SuppressWarnings("unused")
4849
public class NettyByteBufAdapter extends AbstractByteBuf {
4950
private DataInputStream input;
5051
private DataOutputStream output;

modules/ProtocolLib/pom.xml

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<artifactId>ProtocolLib</artifactId>
55
<name>ProtocolLib</name>
6-
<version>4.3.0-SNAPSHOT</version>
6+
<version>${minorVersion}</version>
77

88
<description>Provides read/write access to the Minecraft protocol.</description>
99
<url>http://www.spigotmc.org/resources/protocollib.1997/</url>
@@ -63,6 +63,7 @@
6363
<exclude>org.spigotmc:spigot</exclude>
6464
<exclude>org.spigotmc:spigot-api</exclude>
6565
<exclude>junit:junit</exclude>
66+
<exclude>io.netty:*</exclude>
6667
</excludes>
6768
</artifactSet>
6869
</configuration>
@@ -230,38 +231,10 @@
230231
<groupId>com.comphenix.protocol</groupId>
231232
<artifactId>ProtocolLib-API</artifactId>
232233
<version>${project.version}</version>
233-
</dependency>
234-
<!-- Included with Minecraft
235-
<dependency>
236-
<groupId>io.netty</groupId>
237-
<artifactId>netty-all</artifactId>
238-
<version>4.0.23.Final</version>
239-
</dependency>
240-
-->
241-
<dependency>
242-
<groupId>org.spigotmc</groupId>
243-
<artifactId>spigot-api</artifactId>
244-
<version>${spigotVersion}</version>
245-
<scope>provided</scope>
246-
</dependency>
247-
<dependency>
248-
<groupId>org.spigotmc</groupId>
249-
<artifactId>spigot</artifactId>
250-
<version>${spigotVersion}</version>
251-
<scope>provided</scope>
252-
</dependency>
253-
<dependency>
254-
<groupId>cglib</groupId>
255-
<artifactId>cglib-nodep</artifactId>
256-
<version>2.2.2</version>
257-
<scope>compile</scope>
258-
</dependency>
259-
<dependency>
260-
<groupId>com.comphenix.executors</groupId>
261-
<artifactId>BukkitExecutors</artifactId>
262-
<version>1.1-SNAPSHOT</version>
263234
<scope>compile</scope>
264235
</dependency>
236+
237+
<!-- Testing dependencies -->
265238
<dependency>
266239
<groupId>junit</groupId>
267240
<artifactId>junit</artifactId>

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelInjector.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import io.netty.channel.socket.SocketChannel;
6767
import io.netty.handler.codec.ByteToMessageDecoder;
6868
import io.netty.handler.codec.MessageToByteEncoder;
69+
import io.netty.util.AttributeKey;
6970
import io.netty.util.concurrent.GenericFutureListener;
7071
import io.netty.util.internal.TypeParameterMatcher;
7172

@@ -89,6 +90,10 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
8990
private static Class<?> PACKET_LOGIN_CLIENT = null;
9091
private static FieldAccessor LOGIN_GAME_PROFILE = null;
9192

93+
// Versioning
94+
private static Class<?> PACKET_SET_PROTOCOL = null;
95+
private static AttributeKey<Integer> PROTOCOL_KEY = AttributeKey.valueOf("PROTOCOL");
96+
9297
// Saved accessors
9398
private static MethodAccessor DECODE_BUFFER;
9499
private static MethodAccessor ENCODE_BUFFER;
@@ -97,9 +102,6 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
97102
// For retrieving the protocol
98103
private static FieldAccessor PROTOCOL_ACCESSOR;
99104

100-
// For retrieving the protocol version
101-
private static MethodAccessor PROTOCOL_VERSION;
102-
103105
// The factory that created this injector
104106
private InjectionFactory factory;
105107

@@ -184,19 +186,8 @@ public ChannelInjector(Player player, Object networkManager, Channel channel, Ch
184186
*/
185187
@Override
186188
public int getProtocolVersion() {
187-
MethodAccessor accessor = PROTOCOL_VERSION;
188-
if (accessor == null) {
189-
try {
190-
accessor = Accessors.getMethodAccessor(networkManager.getClass(), "getVersion");
191-
} catch (Throwable ex) {
192-
}
193-
}
194-
195-
if (accessor != null) {
196-
return (Integer) accessor.invoke(networkManager);
197-
} else {
198-
return MinecraftProtocolVersion.getCurrentVersion();
199-
}
189+
Integer value = originalChannel.attr(PROTOCOL_KEY).get();
190+
return value != null ? value : MinecraftProtocolVersion.getCurrentVersion();
200191
}
201192

202193
@Override
@@ -279,6 +270,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
279270
originalChannel.pipeline().addBefore("protocol_lib_decoder", "protocol_lib_finish", finishHandler);
280271
originalChannel.pipeline().addAfter("encoder", "protocol_lib_encoder", protocolEncoder);
281272

273+
try {
282274
// Intercept all write methods
283275
channelField.setValue(new ChannelProxy(originalChannel, MinecraftReflection.getPacketClass()) {
284276
// Compatibility with Spigot 1.8
@@ -370,6 +362,9 @@ protected PacketEvent handleScheduled(Object instance, FieldAccessor accessor) {
370362
return event != null ? event : BYPASSED_PACKET;
371363
}
372364
});
365+
} catch (Throwable ex) {
366+
throw new RuntimeException("Failed to overwrite channel field", ex);
367+
}
373368

374369
injected = true;
375370
return true;
@@ -602,6 +597,26 @@ protected void handleLogin(Class<?> packetClass, Object packet) {
602597
// Save the channel injector
603598
factory.cacheInjector(profile.getName(), this);
604599
}
600+
601+
if (PACKET_SET_PROTOCOL == null) {
602+
try {
603+
PACKET_SET_PROTOCOL = PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass();
604+
} catch (Throwable ex) {
605+
ex.printStackTrace(); // TODO debug
606+
PACKET_SET_PROTOCOL = getClass(); // If we can't find it don't worry about it
607+
}
608+
}
609+
610+
if (PACKET_SET_PROTOCOL.equals(packetClass)) {
611+
FuzzyReflection fuzzy = FuzzyReflection.fromObject(packet);
612+
try {
613+
int protocol = (int) fuzzy.invokeMethod(packet, "getProtocol", int.class);
614+
System.out.println("Determined protocol " + protocol);
615+
originalChannel.attr(PROTOCOL_KEY).set(protocol);
616+
} catch (Throwable ex) {
617+
ex.printStackTrace(); // TODO debug
618+
}
619+
}
605620
}
606621

607622
@Override

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ChannelProxy.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@
1616
*/
1717
package com.comphenix.protocol.injector.netty;
1818

19+
import java.lang.reflect.Field;
20+
import java.net.SocketAddress;
21+
import java.util.Map;
22+
import java.util.concurrent.Callable;
23+
24+
import com.comphenix.protocol.reflect.accessors.Accessors;
25+
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
26+
import com.google.common.collect.Maps;
27+
1928
import io.netty.buffer.ByteBufAllocator;
2029
import io.netty.channel.Channel;
2130
import io.netty.channel.ChannelConfig;
2231
import io.netty.channel.ChannelFuture;
23-
import io.netty.channel.ChannelId;
2432
import io.netty.channel.ChannelMetadata;
2533
import io.netty.channel.ChannelPipeline;
2634
import io.netty.channel.ChannelProgressivePromise;
@@ -29,15 +37,6 @@
2937
import io.netty.util.Attribute;
3038
import io.netty.util.AttributeKey;
3139

32-
import java.lang.reflect.Field;
33-
import java.net.SocketAddress;
34-
import java.util.Map;
35-
import java.util.concurrent.Callable;
36-
37-
import com.comphenix.protocol.reflect.accessors.Accessors;
38-
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
39-
import com.google.common.collect.Maps;
40-
4140
public abstract class ChannelProxy implements Channel {
4241
// Mark that a certain object does not contain a message field
4342
private static final FieldAccessor MARK_NO_MESSAGE = new FieldAccessor() {
@@ -333,6 +332,7 @@ public int compareTo(Channel o) {
333332
return delegate.compareTo(o);
334333
}
335334

335+
/* Added in Netty 4.1, seem to be unused
336336
public long bytesBeforeUnwritable() {
337337
return delegate.bytesBeforeUnwritable();
338338
}
@@ -348,4 +348,5 @@ public ChannelId id() {
348348
public <T> boolean hasAttr(AttributeKey<T> key) {
349349
return delegate.hasAttr(key);
350350
}
351+
*/
351352
}

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/EventLoopProxy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ public List<Runnable> shutdownNow() {
257257
return getDelegate().shutdownNow();
258258
}
259259

260+
/*
260261
public ChannelFuture register(ChannelPromise promise) {
261262
return getDelegate().register(promise);
262263
}
264+
*/
263265
}

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/PipelineProxy.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
*/
1717
package com.comphenix.protocol.injector.netty;
1818

19+
import java.net.SocketAddress;
20+
import java.util.Iterator;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Map.Entry;
24+
1925
import io.netty.channel.Channel;
2026
import io.netty.channel.ChannelFuture;
2127
import io.netty.channel.ChannelHandler;
2228
import io.netty.channel.ChannelHandlerContext;
2329
import io.netty.channel.ChannelPipeline;
24-
import io.netty.channel.ChannelProgressivePromise;
2530
import io.netty.channel.ChannelPromise;
2631
import io.netty.util.concurrent.EventExecutorGroup;
2732

28-
import java.net.SocketAddress;
29-
import java.util.Iterator;
30-
import java.util.List;
31-
import java.util.Map;
32-
import java.util.Map.Entry;
33-
3433
/**
3534
* A pipeline proxy.
3635
* @author Kristian
@@ -370,6 +369,7 @@ public ChannelFuture writeAndFlush(Object arg0) {
370369
return pipeline.writeAndFlush(arg0);
371370
}
372371

372+
/* Added in Netty 4.1, seem to be unused
373373
public ChannelFuture newFailedFuture(Throwable ex) {
374374
return pipeline.newFailedFuture(ex);
375375
}
@@ -389,4 +389,5 @@ public ChannelFuture newSucceededFuture() {
389389
public ChannelPromise voidPromise() {
390390
return pipeline.voidPromise();
391391
}
392+
*/
392393
}

modules/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/ProtocolInjector.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.comphenix.protocol.reflect.FuzzyReflection;
4949
import com.comphenix.protocol.reflect.VolatileField;
5050
import com.comphenix.protocol.utility.MinecraftReflection;
51+
import com.comphenix.protocol.utility.MinecraftVersion;
5152
import com.google.common.collect.Lists;
5253

5354
import io.netty.channel.Channel;
@@ -142,10 +143,15 @@ public synchronized void inject() {
142143
@Override
143144
protected void initChannel(final Channel channel) throws Exception {
144145
try {
145-
// TODO I don't like this
146146
synchronized (networkManagers) {
147-
channel.eventLoop().submit(() ->
148-
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
147+
// For some reason it needs to be delayed on 1.12, but the delay breaks 1.11 and below
148+
// TODO I see this more as a temporary hotfix than a permanent solution
149+
if (MinecraftVersion.getCurrentVersion().getMinor() >= 12) {
150+
channel.eventLoop().submit(() ->
151+
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject());
152+
} else {
153+
injectionFactory.fromChannel(channel, ProtocolInjector.this, playerFactory).inject();
154+
}
149155
}
150156
} catch (Exception e) {
151157
reporter.reportDetailed(ProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).messageParam(channel).error(e));

modules/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static void initializePackage() {
6363
packaged = true;
6464

6565
MinecraftReflection.setMinecraftPackage(Constants.NMS, Constants.OBC);
66-
MinecraftVersion.setCurrentVersion(MinecraftVersion.FROSTBURN_UPDATE);
66+
MinecraftVersion.setCurrentVersion(MinecraftVersion.COLOR_UPDATE);
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)