Compare commits

..
2 Commits
Author SHA1 Message Date
retrooper 552f63a27f Merge pull request #59 from retrooper/dev
1.7.3 release
2020-11-03 09:54:11 +01:00
retrooper 612608181d 1.7.3 release
* We no longer eject players when they exit
* Fixed error when you leave the server
* No reload support with inject early setting enabled
2020-11-03 09:51:57 +01:00
15 changed files with 167 additions and 176 deletions

No files matched your search

+8 -1
View File
@@ -6,7 +6,7 @@
<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.7.2</version>
<version>1.7.3</version>
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
<build>
@@ -95,6 +95,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.9</artifactId>
<version>1.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.8.8</artifactId>
@@ -48,17 +48,14 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.Future;
public final class PacketEvents implements Listener {
private static final String nettyHandlerIdentifier = generateRandomNettyIdentifier();
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, 2);
private static final PEVersion version = new PEVersion(1, 7, 3);
private static PacketEventsSettings settings = new PacketEventsSettings();
@@ -164,10 +161,13 @@ public final class PacketEvents implements Listener {
*/
public static void stop() {
if (initialized) {
for (final Player p : Bukkit.getOnlinePlayers()) {
getAPI().getPlayerUtils().ejectPlayer(p);
for (Player player : Bukkit.getOnlinePlayers()) {
PacketEvents.getAPI().packetManager.ejectPlayer(player);
}
if (PacketEvents.getAPI().packetManager.tinyProtocol != null) {
PacketEvents.getAPI().packetManager.tinyProtocol.unregisterChannelHandler();
}
getAPI().getEventManager().unregisterAllListeners();
NettyPacketManager.executorService.shutdownNow();
initialized = false;
@@ -190,10 +190,6 @@ public final class PacketEvents implements Listener {
return plugins;
}
public static String getHandlerName(final String name) {
return "pe-" + nettyHandlerIdentifier + "-" + name;
}
/**
* Get the PacketEvents settings.
*
@@ -212,7 +208,7 @@ public final class PacketEvents implements Listener {
if (PacketEvents.getSettings().shouldInjectEarly()) {
assert getAPI().packetManager.tinyProtocol != null;
try {
if (getAPI().packetManager.tinyProtocol.canInject(e.getPlayer())) {
if (getAPI().packetManager.canInject(e.getPlayer())) {
getAPI().packetManager.injectPlayer(e.getPlayer());
}
} catch (Exception ex) {
@@ -236,26 +232,15 @@ public final class PacketEvents implements Listener {
}
}
if (!PacketEvents.getSettings().shouldInjectEarly()) {
PacketEvents.getAPI().packetManager.injectPlayer(e.getPlayer());
if (getAPI().packetManager.canInject(e.getPlayer())) {
PacketEvents.getAPI().packetManager.injectPlayer(e.getPlayer());
}
}
}
@EventHandler
public void onQuit(final PlayerQuitEvent e) {
PacketEvents.getAPI().getPlayerUtils().ejectPlayer(e.getPlayer());
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(e.getPlayer().getUniqueId());
}
private static String generateRandomNettyIdentifier() {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
StringBuilder sb = new StringBuilder();
Random random = new Random();
while (sb.length() < 13) {
int index = (int) (random.nextFloat() * alphabet.length());
sb.append(alphabet.charAt(index));
}
return sb.toString();
}
}
@@ -25,12 +25,12 @@
package io.github.retrooper.packetevents.event.manager;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
import io.github.retrooper.packetevents.event.eventtypes.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
import io.github.retrooper.packetevents.event.eventtypes.CancellableEvent;
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibListener;
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibAPIListener;
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
import java.lang.reflect.InvocationTargetException;
@@ -76,7 +76,7 @@ public final class EventManager {
public void registerListener(final PacketListener listener) {
final ConcurrentLinkedQueue<Method> methods = new ConcurrentLinkedQueue<>();
for (final Method m : listener.getClass().getDeclaredMethods()) {
if(!m.isAccessible()) {
if (!m.isAccessible()) {
m.setAccessible(true);
}
if (m.isAnnotationPresent(PacketHandler.class)
@@ -88,7 +88,7 @@ public final class EventManager {
if (!methods.isEmpty()) {
if (ProtocolLibUtils.isAvailable()
&& PacketEvents.getSettings().shouldUseProtocolLibIfAvailable()) {
ProtocolLibListener.registerProtocolLibListener(listener, methods);
ProtocolLibAPIListener.registerProtocolLibListener(listener, methods);
} else {
registeredMethods.put(listener, methods);
}
@@ -30,6 +30,7 @@ import io.github.retrooper.packetevents.event.annotation.PacketHandler;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
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;
@@ -39,13 +39,18 @@ import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class PacketManager {
private static AtomicInteger handlerID = new AtomicInteger(0);
private int handlerNumber = handlerID.getAndIncrement();
private final Plugin plugin;
private final boolean tinyProtocolMode;
public final TinyProtocol tinyProtocol;
public final NettyPacketManager nettyProtocol;
private final HashMap<UUID, Long> keepAliveMap = new HashMap<>();
public final ConcurrentLinkedQueue<Object> queuedEjectionChannels = new ConcurrentLinkedQueue<>();
public PacketManager(Plugin plugin, boolean tinyProtocolMode) {
this.plugin = plugin;
@@ -67,6 +72,10 @@ public class PacketManager {
}
}
public void schedulePlayerEjection(Player player) {
queuedEjectionChannels.add(NMSUtils.getChannel(player));
}
public void ejectPlayer(Player player) {
if (PacketEvents.getSettings().shouldEjectAsync()) {
ejectPlayerAsync(player);
@@ -104,7 +113,6 @@ public class PacketManager {
PacketEvents.getAPI().getEventManager().callEvent(ejectEvent);
if (!ejectEvent.isCancelled()) {
keepAliveMap.remove(player.getUniqueId());
NMSUtils.channelCache.remove(player.getUniqueId());
if (tinyProtocolMode) {
tinyProtocol.ejectPlayer(player);
} else {
@@ -118,7 +126,6 @@ public class PacketManager {
PacketEvents.getAPI().getEventManager().callEvent(ejectEvent);
if (!ejectEvent.isCancelled()) {
keepAliveMap.remove(player.getUniqueId());
NMSUtils.channelCache.remove(player.getUniqueId());
if (tinyProtocolMode) {
tinyProtocol.ejectPlayerAsync(player);
} else {
@@ -127,6 +134,33 @@ public class PacketManager {
}
}
public void ejectChannel(Object channel) {
if(!PacketEvents.getSettings().shouldEjectAsync()) {
ejectChannelSync(channel);
}
else {
ejectChannelAsync(channel);
}
}
public void ejectChannelSync(Object channel) {
if(tinyProtocolMode) {
tinyProtocol.ejectChannelSync(channel);
}
else {
nettyProtocol.ejectChannelSync(channel);
}
}
public void ejectChannelAsync(Object channel) {
if(tinyProtocolMode) {
tinyProtocol.ejectChannelAsync(channel);
}
else {
nettyProtocol.ejectChannelAsync(channel);
}
}
public void sendPacket(Object channel, Object packet) {
if (tinyProtocolMode) {
tinyProtocol.sendPacket(channel, packet);
@@ -135,6 +169,18 @@ public class PacketManager {
}
}
public boolean canInject(Player player) {
Object channel = NMSUtils.getChannel(player);
if(channel == null) {
return true;
}
return !queuedEjectionChannels.contains(channel);
}
public String getNettyHandlerName() {
return "pe-" + plugin.getName() + "-" + handlerNumber;
}
public Object read(Player player, Object channel, Object packet) {
switch (ClassUtil.getClassSimpleName(packet.getClass())) {
case "PacketHandshakingInSetProtocol":
@@ -265,4 +311,5 @@ public class PacketManager {
private void interceptStatus(PacketStatusEvent event) {
}
}
@@ -24,7 +24,6 @@
package io.github.retrooper.packetevents.packetmanager.netty;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.utils.nms.NMSUtils;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -68,10 +67,10 @@ public class NettyPacketManager {
*/
public void injectPlayer(final Player player) {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.injectPlayer(player);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.injectPlayer(player);
}
}
@@ -86,10 +85,10 @@ public class NettyPacketManager {
Object channel = NMSUtils.getChannel(player);
executorService.execute(() -> {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.injectPlayer(player);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.injectPlayer(player);
}
});
@@ -102,10 +101,10 @@ public class NettyPacketManager {
*/
public void ejectPlayer(final Player player) {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.ejectPlayer(player);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.ejectPlayer(player);
}
}
@@ -118,21 +117,43 @@ public class NettyPacketManager {
public void ejectPlayerAsync(final Player player) {
executorService.execute(() -> {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.ejectPlayer(player);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.ejectPlayer(player);
}
});
}
public void ejectChannelSync(Object channel) {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.ejectChannel(channel);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.ejectChannel(channel);
}
}
public void ejectChannelAsync(Object channel) {
executorService.execute(() -> {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.ejectChannel(channel);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.ejectChannel(channel);
}
});
}
public void sendPacket(Object channel, Object packet) {
if (v1_7_nettyMode) {
NettyPacketManager_7 npm_7 = (NettyPacketManager_7)npm;
NettyPacketManager_7 npm_7 = (NettyPacketManager_7) npm;
npm_7.sendPacket(channel, packet);
} else {
NettyPacketManager_8 npm_8 = (NettyPacketManager_8)npm;
NettyPacketManager_8 npm_8 = (NettyPacketManager_8) npm;
npm_8.sendPacket(channel, packet);
}
}
@@ -64,19 +64,20 @@ final class NettyPacketManager_7 {
}
};
final ChannelPipeline pipeline = ((Channel) NMSUtils.getChannel(player)).pipeline();
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
pipeline.addBefore("packet_handler", PacketEvents.getAPI().packetManager.getNettyHandlerName(), channelDuplexHandler);
}
/**
* Eject a player using 1.7.10 netty import location.
* @param player Target Player
*/
public void ejectPlayer(final Player player) {
Channel channel = (Channel) NMSUtils.getChannelNoCache(player);
public void ejectPlayer(Player player) {
Channel channel = (Channel)NMSUtils.getChannel(player);
assert channel != null;
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
ejectChannel(channel);
}
public void ejectChannel(Object ch) {
Channel channel = (Channel)ch;
channel.pipeline().remove(PacketEvents.getAPI().packetManager.getNettyHandlerName());
}
public void sendPacket(Object rawChannel, Object packet) {
Channel channel = (Channel)rawChannel;
channel.pipeline().writeAndFlush(packet);
@@ -64,7 +64,7 @@ final class NettyPacketManager_8 {
}
};
final ChannelPipeline pipeline = ((Channel) NMSUtils.getChannel(player)).pipeline();
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
pipeline.addBefore("packet_handler", PacketEvents.getAPI().packetManager.getNettyHandlerName(), channelDuplexHandler);
}
/**
@@ -72,9 +72,14 @@ final class NettyPacketManager_8 {
* @param player
*/
public void ejectPlayer(final Player player) {
final Channel channel = (Channel) NMSUtils.getChannelNoCache(player);
final Channel channel = (Channel) NMSUtils.getChannel(player);
assert channel != null;
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
ejectChannel(channel);
}
public void ejectChannel(Object channel) {
Channel ch = (Channel)channel;
ch.pipeline().remove(PacketEvents.getAPI().packetManager.getNettyHandlerName());
}
public void sendPacket(Object rawChannel, Object packet) {
@@ -80,6 +80,26 @@ public class TinyProtocol {
}
}
public void ejectChannelSync(Object channel) {
if (!NettyPacketManager.v1_7_nettyMode) {
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
tp8.ejectChannelSync(channel);
} else {
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
tp7.ejectChannelSync(channel);
}
}
public void ejectChannelAsync(Object channel) {
if (!NettyPacketManager.v1_7_nettyMode) {
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
tp8.ejectChannelAsync(channel);
} else {
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
tp7.ejectChannelAsync(channel);
}
}
public void sendPacket(Object channel, Object packet) {
if (!NettyPacketManager.v1_7_nettyMode) {
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
@@ -90,14 +110,6 @@ public class TinyProtocol {
}
}
public Object read(Player player, Object channel, Object packet) {
return PacketEvents.getAPI().packetManager.read(player, channel, packet);
}
public Object write(Player player, Object channel, Object packet) {
return PacketEvents.getAPI().packetManager.write(player, channel, packet);
}
public Object getChannel(Player player) {
if (NettyPacketManager.v1_7_nettyMode) {
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
@@ -108,17 +120,7 @@ public class TinyProtocol {
}
}
public boolean canInject(Player player) {
Object channel = getChannel(player);
if(channel == null) {
return false;
}
if (NettyPacketManager.v1_7_nettyMode) {
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
return !tp7.uninjectedChannels.contains(channel);
} else {
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
return !tp8.uninjectedChannels.contains(channel);
}
public void unregisterChannelHandler() {
}
}
@@ -71,9 +71,6 @@ public class TinyProtocol7 {
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
private Listener listener;
// Channels that have already been removed
public Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
// List of network markers
private List<Object> networkManagers;
@@ -357,7 +354,6 @@ public class TinyProtocol7 {
if (interceptor == null) {
interceptor = new PacketInterceptor();
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
uninjectedChannels.remove(channel);
}
return interceptor;
@@ -381,7 +377,6 @@ public class TinyProtocol7 {
channel.pipeline().addBefore("packet_handler", handlerName, pi);
}
});
uninjectedChannels.remove(channel);
}
return interceptor;
@@ -425,6 +420,14 @@ public class TinyProtocol7 {
uninjectChannelAsync(channel);
}
public void ejectChannelSync(Object ch) {
uninjectChannel((Channel)ch);
}
public void ejectChannelAsync(Object ch) {
uninjectChannelAsync((Channel)ch);
}
/**
* Uninject a specific channel.
* <p>
@@ -433,21 +436,11 @@ public class TinyProtocol7 {
* @param channel - the injected channel.
*/
public void uninjectChannel(final Channel channel) {
// No need to guard against this if we're closing
if (!closed) {
uninjectedChannels.add(channel);
}
// See ChannelInjector in ProtocolLib, line 590
channel.pipeline().remove(handlerName);
}
public void uninjectChannelAsync(Channel channel) {
// No need to guard against this if we're closing
if (!closed) {
uninjectedChannels.add(channel);
}
// See ChannelInjector in ProtocolLib, line 590
NettyPacketManager.executorService.execute(new Runnable() {
@Override
@@ -455,7 +448,6 @@ public class TinyProtocol7 {
channel.pipeline().remove(handlerName);
}
});
}
/**
@@ -481,20 +473,6 @@ public class TinyProtocol7 {
/**
* Cease listening for packets. This is called automatically when your plugin is disabled.
*/
public final void close() {
if (!closed) {
closed = true;
// Remove our handlers
for (Player player : plugin.getServer().getOnlinePlayers()) {
uninjectPlayer(player);
}
// Clean up Bukkit
HandlerList.unregisterAll(listener);
unregisterChannelHandler();
}
}
/**
* Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets.
@@ -74,9 +74,6 @@ public class TinyProtocol8 {
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
private Listener listener;
// Channels that have already been removed
public Set<Channel> uninjectedChannels = Collections.newSetFromMap(new MapMaker().weakKeys().<Channel, Boolean>makeMap());
// List of network markers
private List<Object> networkManagers;
@@ -363,7 +360,6 @@ public class TinyProtocol8 {
if (interceptor == null) {
interceptor = new PacketInterceptor();
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
uninjectedChannels.remove(channel);
}
return interceptor;
@@ -387,8 +383,6 @@ public class TinyProtocol8 {
channel.pipeline().addBefore("packet_handler", handlerName, pi);
}
});
uninjectedChannels.remove(channel);
}
return interceptor;
@@ -432,6 +426,13 @@ public class TinyProtocol8 {
uninjectChannelAsync(channel);
}
public void ejectChannelSync(Object ch) {
uninjectChannel((Channel)ch);
}
public void ejectChannelAsync(Object ch) {
uninjectChannelAsync((Channel)ch);
}
/**
* Uninject a specific channel.
* <p>
@@ -440,21 +441,11 @@ public class TinyProtocol8 {
* @param channel - the injected channel.
*/
public void uninjectChannel(final Channel channel) {
// No need to guard against this if we're closing
if (!closed) {
uninjectedChannels.add(channel);
}
// See ChannelInjector in ProtocolLib, line 590
channel.pipeline().remove(handlerName);
}
public void uninjectChannelAsync(Channel channel) {
// No need to guard against this if we're closing
if (!closed) {
uninjectedChannels.add(channel);
}
// See ChannelInjector in ProtocolLib, line 590
NettyPacketManager.executorService.execute(new Runnable() {
@Override
@@ -1,34 +0,0 @@
/*
* 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.protocollib;
import com.comphenix.protocol.ProtocolLibrary;
import org.bukkit.entity.Player;
class ProtocolLibAPIAccessor {
public static int getProtocolVersion(final Player player) {
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
}
}
@@ -30,11 +30,11 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.annotation.PacketHandler;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
import io.github.retrooper.packetevents.event.priority.PacketEventPriority;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -42,8 +42,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
public class ProtocolLibListener {
public class ProtocolLibAPIListener {
public static void registerProtocolLibListener(PacketListener listener, ConcurrentLinkedQueue<Method> methods) {
if (ProtocolLibUtils.isAvailable()) {
for (Method m : methods) {
@@ -62,7 +61,7 @@ public class ProtocolLibListener {
break;
case PacketEventPriority.HIGHEST:
priority = ListenerPriority.HIGHEST;
break;
break;
case PacketEventPriority.MONITOR:
priority = ListenerPriority.MONITOR;
break;
@@ -141,6 +140,4 @@ public class ProtocolLibListener {
}
}
}
}
}
@@ -25,14 +25,9 @@
package io.github.retrooper.packetevents.utils.protocollib;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ProtocolLibUtils {
public static boolean isAvailable() {
return Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
}
public static int getProtocolVersion(final Player player) {
return ProtocolLibAPIAccessor.getProtocolVersion(player);
}
}
@@ -25,7 +25,6 @@
package io.github.retrooper.packetevents.utils.versionlookup;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibUtils;
import io.github.retrooper.packetevents.utils.protocolsupport.ProtocolSupportUtils;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
import io.github.retrooper.packetevents.utils.v_1_7_10.ProtocolVersionAccessor_v_1_7;
@@ -39,9 +38,8 @@ public class VersionLookupUtils {
public static void handleLoadedDependencies() {
protocolAccessMode = (byte) (ViaUtils.isAvailable() ?
0 : ProtocolSupportUtils.isAvailable() ?
1 : ProtocolLibUtils.isAvailable() ?
2 : PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10 ?
3 : -1);
1 : PacketEvents.getAPI().getServerUtils().getVersion() == ServerVersion.v_1_7_10 ?
2 : -1);
}
public static boolean hasHandledLoadedDependencies() {
@@ -50,8 +48,7 @@ public class VersionLookupUtils {
public static boolean isDependencyAvailable() {
return ViaUtils.isAvailable()
|| ProtocolSupportUtils.isAvailable()
|| ProtocolLibUtils.isAvailable();
|| ProtocolSupportUtils.isAvailable();
}
@@ -71,8 +68,6 @@ public class VersionLookupUtils {
case 1:
return ProtocolSupportUtils.getProtocolVersion(player);
case 2:
return ProtocolLibUtils.getProtocolVersion(player);
case 3:
return ProtocolVersionAccessor_v_1_7.getProtocolVersion(player);
default:
return -1;