mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 11:36:51 +01:00
Add a getMinecraftVersion() method to the ProtocolManager.
This can be useful if you want to implement different read/write methods for each version of Minecraft.
This commit is contained in:
parent
458a92c34a
commit
0b56df20d5
@ -32,6 +32,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.PacketConstructor;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
@ -169,6 +170,12 @@ public interface ProtocolManager extends PacketStream {
|
||||
*/
|
||||
public Set<Integer> getReceivingFilters();
|
||||
|
||||
/**
|
||||
* Retrieve the current Minecraft version.
|
||||
* @return The current version.
|
||||
*/
|
||||
public MinecraftVersion getMinecraftVersion();
|
||||
|
||||
/**
|
||||
* Determines whether or not this protocol mananger has been disabled.
|
||||
* @return TRUE if it has, FALSE otherwise.
|
||||
|
@ -24,6 +24,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager.PlayerInjectHooks;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -123,10 +124,14 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
||||
private PluginManager queuedManager;
|
||||
private Plugin queuedPlugin;
|
||||
|
||||
public DelayedPacketManager(@Nonnull ErrorReporter reporter) {
|
||||
private MinecraftVersion version;
|
||||
|
||||
public DelayedPacketManager(@Nonnull ErrorReporter reporter, @Nonnull MinecraftVersion version) {
|
||||
Preconditions.checkNotNull(reporter, "reporter cannot be NULL.");
|
||||
Preconditions.checkNotNull(version, "version cannot be NULL.");
|
||||
|
||||
this.reporter = reporter;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,6 +141,14 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
|
||||
public InternalManager getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getMinecraftVersion() {
|
||||
if (delegate != null)
|
||||
return delegate.getMinecraftVersion();
|
||||
else
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the delegate to the underlying manager.
|
||||
|
@ -190,7 +190,7 @@ public class PacketFilterBuilder {
|
||||
// If the server hasn't loaded yet - wait
|
||||
if (InjectedServerConnection.getServerConnection(reporter, server) == null) {
|
||||
// We need to delay this until we know if Netty is enabled
|
||||
final DelayedPacketManager delayed = new DelayedPacketManager(reporter);
|
||||
final DelayedPacketManager delayed = new DelayedPacketManager(reporter, mcVersion);
|
||||
|
||||
// They must reference each other
|
||||
delayed.setAsynchronousManager(asyncManager);
|
||||
|
@ -66,6 +66,7 @@ import com.comphenix.protocol.injector.spigot.SpigotPacketInjector;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -179,6 +180,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
// Plugin verifier
|
||||
private PluginVerifier pluginVerifier;
|
||||
|
||||
// The current Minecraft version
|
||||
private MinecraftVersion minecraftVersion;
|
||||
|
||||
/**
|
||||
* Only create instances of this class if protocol lib is disabled.
|
||||
*/
|
||||
@ -210,9 +214,10 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
|
||||
// The plugin verifier
|
||||
this.pluginVerifier = new PluginVerifier(builder.getLibrary());
|
||||
this.minecraftVersion = builder.getMinecraftVersion();
|
||||
|
||||
// The write packet interceptor
|
||||
interceptWritePacket = new InterceptWritePacket(classLoader, reporter);
|
||||
this.interceptWritePacket = new InterceptWritePacket(classLoader, reporter);
|
||||
|
||||
// Use the correct injection type
|
||||
if (builder.isNettyEnabled()) {
|
||||
@ -267,6 +272,11 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
return new PacketFilterBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getMinecraftVersion() {
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsynchronousManager getAsynchronousManager() {
|
||||
return asyncFilterManager;
|
||||
|
@ -40,7 +40,7 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
private final int major;
|
||||
private final int minor;
|
||||
private final int build;
|
||||
|
||||
|
||||
// The development stage
|
||||
private final String development;
|
||||
|
||||
@ -141,10 +141,10 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
* @return A normal version string.
|
||||
*/
|
||||
public String getVersion() {
|
||||
if (development == null)
|
||||
return String.format("%s.%s.%s", major, minor, build);
|
||||
if (getDevelopmentStage() == null)
|
||||
return String.format("%s.%s.%s", getMajor(), getMinor(), getBuild());
|
||||
else
|
||||
return String.format("%s.%s.%s-%s", major, minor, build, development);
|
||||
return String.format("%s.%s.%s-%s", getMajor(), getMinor(), getBuild(), getDevelopmentStage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,11 +153,11 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
return 1;
|
||||
|
||||
return ComparisonChain.start().
|
||||
compare(major, o.major).
|
||||
compare(minor, o.minor).
|
||||
compare(build, o.build).
|
||||
compare(getMajor(), o.getMajor()).
|
||||
compare(getMinor(), o.getMinor()).
|
||||
compare(getBuild(), o.getBuild()).
|
||||
// No development String means it's a release
|
||||
compare(development, o.development, Ordering.natural().nullsLast()).
|
||||
compare(getDevelopmentStage(), o.getDevelopmentStage(), Ordering.natural().nullsLast()).
|
||||
result();
|
||||
}
|
||||
|
||||
@ -171,10 +171,10 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
if (obj instanceof MinecraftVersion) {
|
||||
MinecraftVersion other = (MinecraftVersion) obj;
|
||||
|
||||
return major == other.major &&
|
||||
minor == other.minor &&
|
||||
build == other.build &&
|
||||
Objects.equal(development, other.development);
|
||||
return getMajor() == other.getMajor() &&
|
||||
getMinor() == other.getMinor() &&
|
||||
getBuild() == other.getBuild() &&
|
||||
Objects.equal(getDevelopmentStage(), other.getDevelopmentStage());
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -182,7 +182,7 @@ public class MinecraftVersion implements Comparable<MinecraftVersion> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(major, minor, build);
|
||||
return Objects.hashCode(getMajor(), getMinor(), getBuild());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user