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