Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9d58e08c9 | ||
|
|
24eda2b3a5 | ||
|
|
38c4f3234d | ||
|
|
e94b6f24dc |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.7.6</version>
|
||||
<version>1.7.8</version>
|
||||
|
||||
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
|
||||
<build>
|
||||
@@ -122,6 +122,20 @@
|
||||
<version>4.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ProtocolSupport</groupId>
|
||||
<artifactId>ProtocolSupport</artifactId>
|
||||
<version>3d24efeda6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
|
||||
@@ -37,7 +37,8 @@ import io.github.retrooper.packetevents.utils.nms.NMSUtils;
|
||||
import io.github.retrooper.packetevents.utils.player.ClientVersion;
|
||||
import io.github.retrooper.packetevents.utils.server.PEVersion;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import io.github.retrooper.packetevents.utils.v_1_7_10.ProtocolVersionAccessor_v_1_7;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.v_1_7_10.ProtocolVersionAccessor_v_1_7;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -57,9 +58,8 @@ public final class PacketEvents implements Listener {
|
||||
private static final PacketEventsAPI packetEventsAPI = new PacketEventsAPI();
|
||||
private static final PacketEvents instance = new PacketEvents();
|
||||
private static final ArrayList<Plugin> plugins = new ArrayList<>(1);
|
||||
private static boolean loaded, initialized;
|
||||
private static final PEVersion version = new PEVersion(1, 7, 6);
|
||||
|
||||
private static boolean loading, loaded, initialized, initializing, uninitializing;
|
||||
private static final PEVersion version = new PEVersion(1, 7, 8);
|
||||
private static PacketEventsSettings settings = new PacketEventsSettings();
|
||||
/**
|
||||
* General executor service, basically for anything that the packet executor service doesn't do.
|
||||
@@ -88,7 +88,8 @@ public final class PacketEvents implements Listener {
|
||||
* All PacketEvents' wrappers are setup and do all loading they need to do.
|
||||
*/
|
||||
public static void load() {
|
||||
if (!loaded) {
|
||||
if (!loaded && !loading) {
|
||||
loading = true;
|
||||
ServerVersion version = ServerVersion.getVersion();
|
||||
WrappedPacket.version = version;
|
||||
PacketEvent.version = version;
|
||||
@@ -107,9 +108,11 @@ public final class PacketEvents implements Listener {
|
||||
|
||||
WrappedPacket.loadAllWrappers();
|
||||
} catch (Exception ex) {
|
||||
loading = false;
|
||||
throw new PacketEventsLoadFailureException();
|
||||
}
|
||||
loaded = true;
|
||||
loading = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -135,14 +138,14 @@ public final class PacketEvents implements Listener {
|
||||
*/
|
||||
public static void init(final Plugin pl, PacketEventsSettings packetEventsSettings) {
|
||||
load();
|
||||
if (!initialized) {
|
||||
if (!initialized && !initializing) {
|
||||
initializing = true;
|
||||
settings = packetEventsSettings;
|
||||
int packetHandlingThreadCount = settings.getPacketHandlingThreadCount();
|
||||
//if the count is 1 or is invalid
|
||||
if(packetHandlingThreadCount == 1 || packetHandlingThreadCount < 0) {
|
||||
if (packetHandlingThreadCount == 1 || packetHandlingThreadCount < 0) {
|
||||
packetHandlingExecutorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
packetHandlingExecutorService = Executors.newFixedThreadPool(packetHandlingThreadCount);
|
||||
}
|
||||
plugins.add(pl);
|
||||
@@ -152,11 +155,17 @@ public final class PacketEvents implements Listener {
|
||||
PacketEvents.getAPI().packetManager = new PacketManager(plugins.get(0), settings.shouldInjectEarly());
|
||||
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
getAPI().getPlayerUtils().injectPlayer(p);
|
||||
try {
|
||||
getAPI().getPlayerUtils().injectPlayer(p);
|
||||
} catch (Exception ex) {
|
||||
p.kickPlayer("Failed to inject you, please rejoin the server!");
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.shouldCheckForUpdates()) {
|
||||
PacketEvents.generalExecutorService.execute(() -> new UpdateChecker().handleUpdate());
|
||||
Future<?> future =
|
||||
PacketEvents.generalExecutorService
|
||||
.submit(() -> new UpdateChecker().handleUpdate());
|
||||
}
|
||||
|
||||
if (getAPI().getServerUtils().isBungeeCordEnabled()) {
|
||||
@@ -165,6 +174,7 @@ public final class PacketEvents implements Listener {
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
initializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +182,8 @@ public final class PacketEvents implements Listener {
|
||||
*
|
||||
*/
|
||||
public static void stop() {
|
||||
if (initialized) {
|
||||
if (initialized && !uninitializing) {
|
||||
uninitializing = true;
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
PacketEvents.getAPI().packetManager.ejectPlayer(player);
|
||||
}
|
||||
@@ -184,6 +195,7 @@ public final class PacketEvents implements Listener {
|
||||
PacketEvents.generalExecutorService.shutdownNow();
|
||||
PacketEvents.packetHandlingExecutorService.shutdownNow();
|
||||
initialized = false;
|
||||
uninitializing = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,9 +233,7 @@ public final class PacketEvents implements Listener {
|
||||
if (PacketEvents.getSettings().shouldInjectEarly()) {
|
||||
assert getAPI().packetManager.tinyProtocol != null;
|
||||
try {
|
||||
if (getAPI().packetManager.canInject(e.getPlayer())) {
|
||||
getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
}
|
||||
getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
} catch (Exception ex) {
|
||||
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, "We are unable to inject you. Please try again!");
|
||||
}
|
||||
@@ -232,15 +242,21 @@ public final class PacketEvents implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
if(PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10) {
|
||||
Object channel = NMSUtils.getChannel(e.getPlayer());
|
||||
Object channel = NMSUtils.getChannel(e.getPlayer());
|
||||
if (PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10) {
|
||||
ClientVersion version = ClientVersion.getClientVersion(ProtocolVersionAccessor_v_1_7.getProtocolVersion(e.getPlayer()));
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(channel, version);
|
||||
} else if (VersionLookupUtils.isDependencyAvailable()) {
|
||||
int protocolVersion = VersionLookupUtils.getProtocolVersion(e.getPlayer());
|
||||
ClientVersion version = ClientVersion.getClientVersion(protocolVersion);
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(channel, version);
|
||||
}
|
||||
//Waiting for the BungeeCord server to send their plugin message with your version,
|
||||
if (!PacketEvents.getSettings().shouldInjectEarly()) {
|
||||
if (getAPI().packetManager.canInject(e.getPlayer())) {
|
||||
try {
|
||||
PacketEvents.getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
} catch (Exception ex) {
|
||||
e.getPlayer().kickPlayer("There was an issue injecting you. Please try again!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,6 +264,7 @@ public final class PacketEvents implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onQuit(final PlayerQuitEvent e) {
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(e.getPlayer().getUniqueId());
|
||||
Object channel = NMSUtils.getChannelNoCache(e.getPlayer());
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,12 @@
|
||||
package io.github.retrooper.packetevents.example;
|
||||
|
||||
import io.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.retrooper.packetevents.event.PacketListenerDynamic;
|
||||
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
|
||||
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.in.chat.WrappedPacketInChat;
|
||||
import io.github.retrooper.packetevents.utils.player.ClientVersion;
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
+1
-1
@@ -30,6 +30,6 @@ public class PacketEventsNMSCachedEntityNotFoundException extends RuntimeExcepti
|
||||
}
|
||||
|
||||
public PacketEventsNMSCachedEntityNotFoundException(int entityID) {
|
||||
this("PacketEvents failed to find an entity with ID " + entityID + " in NMS' entity cache map!");
|
||||
this("PacketEvents failed to find an entity with ID " + entityID + "!");
|
||||
}
|
||||
}
|
||||
@@ -41,9 +41,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private static final AtomicInteger handlerID = new AtomicInteger();
|
||||
private final int handlerNumber = handlerID.getAndIncrement();
|
||||
private final Plugin plugin;
|
||||
private final boolean tinyProtocolMode;
|
||||
public final TinyProtocol tinyProtocol;
|
||||
@@ -57,8 +54,8 @@ public class PacketManager {
|
||||
tinyProtocol = new TinyProtocol(plugin);
|
||||
nettyProtocol = null;
|
||||
} else {
|
||||
tinyProtocol = null;
|
||||
nettyProtocol = new NettyPacketManager(plugin);
|
||||
tinyProtocol = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +92,10 @@ public class PacketManager {
|
||||
PacketEvents.getAPI().getEventManager().callEvent(injectEvent);
|
||||
if (!injectEvent.isCancelled()) {
|
||||
if (tinyProtocolMode) {
|
||||
assert tinyProtocol != null;
|
||||
tinyProtocol.injectPlayerAsync(player);
|
||||
} else {
|
||||
assert nettyProtocol != null;
|
||||
nettyProtocol.injectPlayerAsync(player);
|
||||
}
|
||||
}
|
||||
@@ -160,12 +159,8 @@ public class PacketManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInject(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getNettyHandlerName() {
|
||||
return "pe-" + plugin.getName() + "-" + handlerNumber;
|
||||
return "pe-" + plugin.getName();
|
||||
}
|
||||
|
||||
public Object read(Player player, Object channel, Object packet) {
|
||||
@@ -280,12 +275,13 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
private void interceptLogin(PacketLoginEvent event) {
|
||||
if (event.getPacketId() == PacketType.Login.HANDSHAKE &&
|
||||
PacketEvents.getAPI().getServerUtils().getVersion() != ServerVersion.v_1_7_10) {
|
||||
WrappedPacketLoginHandshake handshake = new WrappedPacketLoginHandshake(event.getNMSPacket());
|
||||
int protocolVersion = handshake.getProtocolVersion();
|
||||
ClientVersion version = ClientVersion.getClientVersion(protocolVersion);
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(event.getChannel(), version);
|
||||
if (event.getPacketId() == PacketType.Login.HANDSHAKE
|
||||
&& PacketEvents.getAPI().getServerUtils().getVersion() != ServerVersion.v_1_7_10
|
||||
&& !PacketEvents.getAPI().getServerUtils().isBungeeCordEnabled()) {
|
||||
WrappedPacketLoginHandshake handshake = new WrappedPacketLoginHandshake(event.getNMSPacket());
|
||||
int protocolVersion = handshake.getProtocolVersion();
|
||||
ClientVersion version = ClientVersion.getClientVersion(protocolVersion);
|
||||
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(event.getChannel(), version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-4
@@ -38,11 +38,7 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
//System.out.println("USE ENTITY HAS BEEN LOADED BROOOIOII");
|
||||
Class<?> useEntityClass = NMSUtils.getNMSClassWithoutException("PacketPlayInUseEntity");
|
||||
/*if(useEntityClass == null) {
|
||||
System.out.println("failed to init use entity wtfffff");
|
||||
}*/
|
||||
try {
|
||||
enumEntityUseActionClass = NMSUtils.getNMSClass("EnumEntityUseAction");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
|
||||
|
||||
public WrappedPacketOutChat(String message, ChatPosition chatPosition, UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.message = message;
|
||||
this.message = fromStringToJSON(message);
|
||||
this.chatPosition = chatPosition;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
package io.github.retrooper.packetevents.settings;
|
||||
|
||||
import io.github.retrooper.packetevents.utils.server.ServerVersion;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
|
||||
public class PacketEventsSettings {
|
||||
private ServerVersion backupServerVersion = ServerVersion.v_1_7_10;
|
||||
|
||||
+26
-41
@@ -40,10 +40,8 @@ public final class EntityFinderUtils {
|
||||
public static ServerVersion version;
|
||||
private static Class<?> worldServerClass;
|
||||
private static Class<?> craftWorldClass;
|
||||
private static Class<?> entityClass;
|
||||
private static Method getEntityByIdMethod;
|
||||
private static Method craftWorldGetHandle;
|
||||
private static Method getBukkitEntity;
|
||||
|
||||
private static boolean isServerVersion_v_1_8_x;
|
||||
|
||||
@@ -52,15 +50,13 @@ public final class EntityFinderUtils {
|
||||
try {
|
||||
worldServerClass = NMSUtils.getNMSClass("WorldServer");
|
||||
craftWorldClass = NMSUtils.getOBCClass("CraftWorld");
|
||||
entityClass = NMSUtils.getNMSClass("Entity");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
getEntityByIdMethod = worldServerClass.getMethod(getEntityByIDMethodName(), int.class);
|
||||
getEntityByIdMethod = worldServerClass.getMethod(isServerVersion_v_1_8_x ? "a" : "getEntity", int.class);
|
||||
craftWorldGetHandle = craftWorldClass.getMethod("getHandle");
|
||||
getBukkitEntity = entityClass.getMethod("getBukkitEntity");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -73,6 +69,14 @@ public final class EntityFinderUtils {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
//Entity has not been found in the NMS entity cache map...
|
||||
for(World world : Bukkit.getWorlds()) {
|
||||
for(Entity entity : world.getEntities()) {
|
||||
if(entity.getEntityId() == id) {
|
||||
return NMSUtils.getNMSEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new PacketEventsNMSCachedEntityNotFoundException(id);
|
||||
}
|
||||
|
||||
@@ -83,11 +87,19 @@ public final class EntityFinderUtils {
|
||||
* @return Entity
|
||||
*/
|
||||
public static Entity getEntityById(final int id) {
|
||||
Object nmsEntity = getNMSEntityById(id);
|
||||
try {
|
||||
return (Entity) getBukkitEntity.invoke(nmsEntity);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (final World world : Bukkit.getWorlds()) {
|
||||
final Object entity = getNMSEntityByIdWithWorld(world, id);
|
||||
if (entity != null) {
|
||||
return NMSUtils.getBukkitEntity(entity);
|
||||
}
|
||||
}
|
||||
//Entity has not been found in the NMS entity cache map...
|
||||
for(World world : Bukkit.getWorlds()) {
|
||||
for(Entity entity : world.getEntities()) {
|
||||
if(entity.getEntityId() == id) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new PacketEventsNMSCachedEntityNotFoundException(id);
|
||||
}
|
||||
@@ -98,25 +110,19 @@ public final class EntityFinderUtils {
|
||||
} else if (craftWorldClass == null) {
|
||||
throw new IllegalStateException("PacketEvents failed to locate the CraftWorld class.");
|
||||
}
|
||||
Object craftWorld = craftWorldClass.cast(world);
|
||||
|
||||
Object worldServer = null;
|
||||
try {
|
||||
worldServer = craftWorldGetHandle.invoke(craftWorld);
|
||||
worldServer = craftWorldGetHandle.invoke(world);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Object nmsEntity = null;
|
||||
try {
|
||||
nmsEntity = getEntityByIdMethod.invoke(worldServer, id);
|
||||
return getEntityByIdMethod.invoke(worldServer, id);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(nmsEntity == null) {
|
||||
throw new PacketEventsNMSCachedEntityNotFoundException(id);
|
||||
}
|
||||
return nmsEntity;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,27 +135,6 @@ public final class EntityFinderUtils {
|
||||
@Nullable
|
||||
public static Entity getEntityByIdWithWorld(final World world, final int id) {
|
||||
Object nmsEntity = getNMSEntityByIdWithWorld(world, id);
|
||||
if (nmsEntity == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (Entity) getBukkitEntity.invoke(nmsEntity);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new PacketEventsNMSCachedEntityNotFoundException(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the name of the method that returns the NMS entity when you pass in its ID.
|
||||
* On 1.8-1.8.8 the function name is called 'a', on 1.7.10 and 1.9 and above the name is called 'getEntity'.
|
||||
*
|
||||
* @return entity by ID method name
|
||||
*/
|
||||
public static String getEntityByIDMethodName() {
|
||||
if (isServerVersion_v_1_8_x) {
|
||||
return "a";
|
||||
}
|
||||
return "getEntity";
|
||||
return NMSUtils.getBukkitEntity(nmsEntity);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ public final class NMSUtils {
|
||||
private static Method getCraftPlayerHandle;
|
||||
private static Method getCraftEntityHandle;
|
||||
private static Method asBukkitCopy;
|
||||
private static Method getBukkitEntity;
|
||||
private static Field entityPlayerPingField, playerConnectionField;
|
||||
|
||||
public static final HashMap<UUID, Object> channelCache = new HashMap<>();
|
||||
@@ -102,6 +103,7 @@ public final class NMSUtils {
|
||||
getCraftEntityHandle = craftEntityClass.getMethod("getHandle");
|
||||
asBukkitCopy = craftItemStack.getMethod("asBukkitCopy", nmsItemStackClass);
|
||||
craftWorldGetHandle = craftWorldClass.getMethod("getHandle");
|
||||
getBukkitEntity = nmsEntityClass.getMethod("getBukkitEntity");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -196,6 +198,15 @@ public final class NMSUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Entity getBukkitEntity(final Object nmsEntity) {
|
||||
try {
|
||||
return (Entity) getBukkitEntity.invoke(nmsEntity);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getCraftPlayer(final Player player) {
|
||||
return craftPlayerClass.cast(player);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ public enum ClientVersion {
|
||||
v_1_16_1(736),
|
||||
v_1_16_2(751),
|
||||
v_1_16_3(753),
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(754),
|
||||
v_1_16_4(754),
|
||||
HIGHER_THAN_SUPPORTED_VERSIONS(755),
|
||||
/**
|
||||
* Pre releases just aren't supported, we would end up with so many enum constants.
|
||||
*/
|
||||
@@ -65,6 +66,7 @@ public enum ClientVersion {
|
||||
|
||||
private static final int lowestSupportedProtocolVersion = 5;
|
||||
private static final int highestSupportedProtocolVersion = 753;
|
||||
|
||||
ClientVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
}
|
||||
@@ -94,24 +96,21 @@ public enum ClientVersion {
|
||||
}
|
||||
|
||||
public static ClientVersion getClientVersion(int protocolVersion) {
|
||||
if(protocolVersion == -1) {
|
||||
return ClientVersion.UNRESOLVED;
|
||||
if (protocolVersion == -1) {
|
||||
return ClientVersion.UNRESOLVED;
|
||||
}
|
||||
for(ClientVersion version : ClientVersion.values()) {
|
||||
if(version.protocolVersion > protocolVersion) {
|
||||
for (ClientVersion version : ClientVersion.values()) {
|
||||
if (version.protocolVersion > protocolVersion) {
|
||||
break;
|
||||
}
|
||||
else if(version.protocolVersion == protocolVersion) {
|
||||
} else if (version.protocolVersion == protocolVersion) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
if(protocolVersion < lowestSupportedProtocolVersion) {
|
||||
if (protocolVersion < lowestSupportedProtocolVersion) {
|
||||
return LOWER_THAN_SUPPORTED_VERSIONS;
|
||||
}
|
||||
else if(protocolVersion > highestSupportedProtocolVersion) {
|
||||
} else if (protocolVersion > highestSupportedProtocolVersion) {
|
||||
return HIGHER_THAN_SUPPORTED_VERSIONS;
|
||||
}
|
||||
else if(protocolVersion > lowestSupportedProtocolVersion
|
||||
} else if (protocolVersion > lowestSupportedProtocolVersion
|
||||
&& protocolVersion < highestSupportedProtocolVersion) {
|
||||
return ANY_PRE_RELEASE_VERSION;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public enum ServerVersion {
|
||||
v_1_11_2((short) 316), v_1_12((short) 335), v_1_12_1((short) 338), v_1_12_2((short) 340), v_1_13((short) 393),
|
||||
v_1_13_1((short) 401), v_1_13_2((short) 404), v_1_14((short) 477), v_1_14_1((short) 480), v_1_14_2((short) 485),
|
||||
v_1_14_3((short) 490), v_1_14_4((short) 498), v_1_15((short) 573), v_1_15_1((short) 575), v_1_15_2((short) 578),
|
||||
v_1_16((short) 735), v_1_16_1((short) 736), v_1_16_2((short) 751), v_1_16_3((short) 753), ERROR((short) -1), EMPTY((short) -1);
|
||||
v_1_16((short) 735), v_1_16_1((short) 736), v_1_16_2((short) 751), v_1_16_3((short) 753), v_1_16_4((short)754),ERROR((short) -1);
|
||||
|
||||
private static final String nmsVersionSuffix = Bukkit.getServer().getClass().getPackage().getName()
|
||||
.replace(".", ",").split(",")[3];
|
||||
@@ -58,6 +58,9 @@ public enum ServerVersion {
|
||||
if (reversedValues[0] == null) {
|
||||
reversedValues = ServerVersion.reverse(values());
|
||||
}
|
||||
if(reversedValues == null) {
|
||||
throw new IllegalStateException("Failed to reverse the ServerVersion enum constant values.");
|
||||
}
|
||||
for (final ServerVersion val : reversedValues) {
|
||||
String valName = val.name().substring(2).replace("_", ".");
|
||||
if (Bukkit.getBukkitVersion().contains(valName)) {
|
||||
@@ -125,7 +128,7 @@ public enum ServerVersion {
|
||||
* @return True if the supplied version is lower or equal, false if it is higher
|
||||
* than the server's version.
|
||||
*/
|
||||
public boolean isAtLeast(final ServerVersion version) {
|
||||
public boolean isHigherThanOrEquals(final ServerVersion version) {
|
||||
return protocolId >= version.protocolId;
|
||||
}
|
||||
|
||||
@@ -149,7 +152,7 @@ public enum ServerVersion {
|
||||
* @return True if the supplied version is higher or equal, false if it is lower
|
||||
* than the server's version.
|
||||
*/
|
||||
public boolean isAtMost(final ServerVersion version) {
|
||||
public boolean isLowerThanOrEquals(final ServerVersion version) {
|
||||
return version.protocolId >= protocolId;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 retrooper
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup;
|
||||
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.protocollib.ProtocolLibVersionLookupUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.protocolsupport.ProtocolSupportVersionLookupUtils;
|
||||
import io.github.retrooper.packetevents.utils.versionlookup.viaversion.ViaVersionLookupUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class VersionLookupUtils {
|
||||
public static boolean isDependencyAvailable() {
|
||||
return ViaVersionLookupUtils.isAvailable() || ProtocolSupportVersionLookupUtils.isAvailable()
|
||||
|| ProtocolLibVersionLookupUtils.isAvailable();
|
||||
}
|
||||
|
||||
public static int getProtocolVersion(Player player) {
|
||||
if (ViaVersionLookupUtils.isAvailable()) {
|
||||
return ViaVersionLookupUtils.getProtocolVersion(player);
|
||||
} else if (ProtocolSupportVersionLookupUtils.isAvailable()) {
|
||||
return ProtocolSupportVersionLookupUtils.getProtocolVersion(player);
|
||||
} else if (ProtocolLibVersionLookupUtils.isAvailable()) {
|
||||
return ProtocolLibVersionLookupUtils.getProtocolVersion(player);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+9
-23
@@ -22,32 +22,18 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.packetwrappers.out.blockchange;
|
||||
package io.github.retrooper.packetevents.utils.versionlookup.protocollib;
|
||||
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
class WrappedPacketOutBlockChange extends WrappedPacket {
|
||||
public WrappedPacketOutBlockChange(Object packet) {
|
||||
super(packet);
|
||||
public class ProtocolLibVersionLookupUtils {
|
||||
public static boolean isAvailable() {
|
||||
return Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
|
||||
}
|
||||
//to-do load
|
||||
@Override
|
||||
protected void setup() {
|
||||
//1.7 - int, int, int, Block, int data
|
||||
//1.8+ - BlockPosition, IBlockData
|
||||
|
||||
//Constructors
|
||||
//1.7 - int, int, int, World
|
||||
|
||||
//1.8->~1.12.2(World, BlockPosition)
|
||||
|
||||
//~1.13->~1.14(IBlockAccess, BlockPosition)
|
||||
//1.16+(BlockPosition, IBlockData)
|
||||
net.minecraft.server.v1_7_R4.PacketPlayOutBlockChange bc;
|
||||
net.minecraft.server.v1_8_R3.PacketPlayOutBlockChange bc1;
|
||||
net.minecraft.server.v1_9_R1.PacketPlayOutBlockChange bc2;
|
||||
net.minecraft.server.v1_12_R1.PacketPlayOutBlockChange bc3;
|
||||
net.minecraft.server.v1_13_R2.PacketPlayOutBlockChange bc4;
|
||||
net.minecraft.server.v1_16_R2.PacketPlayOutBlockChange bc5;
|
||||
public static int getProtocolVersion(Player player) {
|
||||
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 retrooper
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup.protocolsupport;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
|
||||
public class ProtocolSupportVersionLookupUtils {
|
||||
public static boolean isAvailable() {
|
||||
return Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
|
||||
}
|
||||
|
||||
public static int getProtocolVersion(Player player) {
|
||||
return ProtocolSupportAPI.getProtocolVersion(player).getId();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.v_1_7_10;
|
||||
package io.github.retrooper.packetevents.utils.versionlookup.v_1_7_10;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020 retrooper
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.versionlookup.viaversion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
public class ViaVersionLookupUtils {
|
||||
public static boolean isAvailable() {
|
||||
return Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
|
||||
}
|
||||
|
||||
public static int getProtocolVersion(Player player) {
|
||||
return Via.getAPI().getPlayerVersion(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user