Skip to content

Commit

Permalink
Add support for latest waterfall
Browse files Browse the repository at this point in the history
  • Loading branch information
Exceptionflug committed Sep 6, 2019
1 parent e632eff commit 61a0820
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.lang.reflect.*;
import java.util.Map;
import java.util.function.Supplier;
import java.util.logging.Level;

/**
Expand Down Expand Up @@ -84,7 +85,11 @@ public void registerPacket(final Protocol protocol, final Direction direction, f
try {
final TIntObjectMap<Object> protocols = (TIntObjectMap<Object>) protocolsField.get(getDirectionData(protocol, direction));
for(final Integer protocolVersion : protocolIdMapping.keySet()) {
registerPacket(protocols, protocolVersion, protocolIdMapping.get(protocolVersion), clazz);
if(isWaterfall()) {
registerPacketWaterfall(protocols, protocolVersion, protocolIdMapping.get(protocolVersion), clazz);
} else {
registerPacketBungeeCord(protocols, protocolVersion, protocolIdMapping.get(protocolVersion), clazz);
}
}
ProxyServer.getInstance().getLogger().info("[Protocolize] Injected custom packet: "+clazz.getName());
} catch (final Exception e) {
Expand Down Expand Up @@ -133,10 +138,27 @@ private Object getDirectionData(final Protocol protocol, final Direction directi
return null;
}

private void registerPacket(final TIntObjectMap<Object> protocols, final int protocolVersion, final int packetId, final Class<?> clazz) throws IllegalAccessException, NoSuchMethodException {
public boolean isWaterfall() {
return protocolDataConstructorsField.getType().equals(Supplier[].class);
}

private void registerPacketBungeeCord(final TIntObjectMap<Object> protocols, final int protocolVersion, final int packetId, final Class<?> clazz) throws IllegalAccessException, NoSuchMethodException {
final Object protocolData = protocols.get(protocolVersion);
((TObjectIntMap<Class<?>>)protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Constructor[])protocolDataConstructorsField.get(protocolData))[packetId] = clazz.getDeclaredConstructor();
}

private void registerPacketWaterfall(final TIntObjectMap<Object> protocols, final int protocolVersion, final int packetId, final Class<?> clazz) throws IllegalAccessException, NoSuchMethodException {
final Object protocolData = protocols.get(protocolVersion);
((TObjectIntMap<Class<?>>)protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Supplier[])protocolDataConstructorsField.get(protocolData))[packetId] = () -> {
try {
return clazz.getDeclaredConstructor().newInstance();
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
return null;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class ProtocolizePlugin extends Plugin {
public void onEnable() {
ProxyServer.getInstance().getLogger().info("======= PROTOCOLIZE =======");
ProxyServer.getInstance().getLogger().info("Version " + getDescription().getVersion() + " by " + getDescription().getAuthor());
if(ProtocolAPI.getPacketRegistration().isWaterfall()) {
ProxyServer.getInstance().getLogger().info("[Protocolize] Running on Waterfall. Please report bugs regarding protocolize under https://github.com/Exceptionflug/protocolize/issues");
}
ProxyServer.getInstance().getPluginManager().registerListener(this, new PlayerListener(this));

try {
Expand Down

0 comments on commit 61a0820

Please sign in to comment.