Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
552f63a27f | ||
|
|
612608181d | ||
|
|
8e652f0c44 | ||
|
|
4a3e89d713 | ||
|
|
3dd6d1e0b9 | ||
|
|
f42e1ad71d | ||
|
|
b44f36185a | ||
|
|
1621adad02 | ||
|
|
d2682242ae | ||
|
|
0b26fe3266 | ||
|
|
0354ddf765 | ||
|
|
82e0d01c29 | ||
|
|
57b68f185c | ||
|
|
8f9b8c0433 | ||
|
|
27ced0fc36 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>io.github.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.7</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<Plugin>(1);
|
||||
private static final ArrayList<Plugin> plugins = new ArrayList<>(1);
|
||||
private static boolean loaded, initialized;
|
||||
private static final PEVersion version = new PEVersion(1, 7);
|
||||
private static final PEVersion version = new PEVersion(1, 7, 3);
|
||||
|
||||
private static PacketEventsSettings settings = new PacketEventsSettings();
|
||||
|
||||
@@ -164,14 +161,16 @@ 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();
|
||||
|
||||
initialized = false;
|
||||
NettyPacketManager.executorService.shutdownNow();
|
||||
initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,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,8 +207,12 @@ public final class PacketEvents implements Listener {
|
||||
public void onLogin(PlayerLoginEvent e) {
|
||||
if (PacketEvents.getSettings().shouldInjectEarly()) {
|
||||
assert getAPI().packetManager.tinyProtocol != null;
|
||||
if (getAPI().packetManager.tinyProtocol.canInject(e.getPlayer())) {
|
||||
getAPI().packetManager.injectPlayer(e.getPlayer());
|
||||
try {
|
||||
if (getAPI().packetManager.canInject(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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,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);
|
||||
}
|
||||
|
||||
@@ -28,11 +28,9 @@ import io.github.retrooper.packetevents.PacketEvents;
|
||||
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.impl.PlayerInjectEvent;
|
||||
import io.github.retrooper.packetevents.packettype.PacketType;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.animation.WrappedPacketOutAnimation;
|
||||
import io.github.retrooper.packetevents.packetwrappers.out.explosion.WrappedPacketOutExplosion;
|
||||
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;
|
||||
|
||||
@@ -50,11 +48,5 @@ public class MainExample extends JavaPlugin implements PacketListener {
|
||||
useProtocolLibIfAvailable(true).checkForUpdates(true).injectEarly(true);
|
||||
PacketEvents.getAPI().getEventManager().registerListener(this);
|
||||
PacketEvents.init(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PacketEvents.stop();
|
||||
}
|
||||
}
|
||||
@@ -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":
|
||||
@@ -182,6 +228,7 @@ public class PacketManager {
|
||||
}
|
||||
break;
|
||||
case "PacketStatusOutPong":
|
||||
case "PacketStatusOutServerInfo":
|
||||
final PacketStatusEvent packetStatusEvent = new PacketStatusEvent(channel, packet);
|
||||
PacketEvents.getAPI().getEventManager().callEvent(packetStatusEvent);
|
||||
interceptStatus(packetStatusEvent);
|
||||
@@ -223,6 +270,7 @@ public class PacketManager {
|
||||
case "PacketLoginOutSetCompression":
|
||||
case "PacketLoginOutSuccess":
|
||||
case "PacketStatusOutPong":
|
||||
case "PacketStatusOutServerInfo":
|
||||
break;
|
||||
default:
|
||||
PacketEvents.getAPI().getEventManager().callEvent(new PostPacketSendEvent(player, packet));
|
||||
@@ -263,4 +311,5 @@ public class PacketManager {
|
||||
private void interceptStatus(PacketStatusEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+38
-14
@@ -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;
|
||||
@@ -33,17 +32,20 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class NettyPacketManager {
|
||||
public static boolean v1_7_nettyMode = false;
|
||||
public static final boolean v1_7_nettyMode;
|
||||
public static final ExecutorService
|
||||
executorService =
|
||||
Executors.newFixedThreadPool(Math.max(Runtime.getRuntime().availableProcessors(), 64));
|
||||
|
||||
static {
|
||||
boolean v1_7_nettyMode1;
|
||||
try {
|
||||
Class.forName("io.netty.channel.Channel");
|
||||
Class.forName("net.minecraft.util.io.netty.channel.Channel");
|
||||
v1_7_nettyMode1 = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
v1_7_nettyMode = true;
|
||||
v1_7_nettyMode1 = false;
|
||||
}
|
||||
v1_7_nettyMode = v1_7_nettyMode1;
|
||||
}
|
||||
|
||||
private Plugin plugin;
|
||||
@@ -65,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);
|
||||
}
|
||||
}
|
||||
@@ -83,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);
|
||||
}
|
||||
});
|
||||
@@ -99,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);
|
||||
}
|
||||
}
|
||||
@@ -115,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);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -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);
|
||||
|
||||
+8
-3
@@ -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) {
|
||||
|
||||
+22
-16
@@ -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,13 +120,7 @@ public class TinyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInject(Player player) {
|
||||
if (NettyPacketManager.v1_7_nettyMode) {
|
||||
TinyProtocol7 tp7 = (TinyProtocol7) tinyProt;
|
||||
return !tp7.uninjectedChannels.contains(getChannel(player));
|
||||
} else {
|
||||
TinyProtocol8 tp8 = (TinyProtocol8) tinyProt;
|
||||
return !tp8.uninjectedChannels.contains(getChannel(player));
|
||||
}
|
||||
public void unregisterChannelHandler() {
|
||||
|
||||
}
|
||||
}
|
||||
+9
-35
@@ -27,12 +27,8 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.util.io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@@ -75,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;
|
||||
|
||||
@@ -252,7 +245,7 @@ public class TinyProtocol7 {
|
||||
* @return The packet to recieve instead, or NULL to cancel.
|
||||
*/
|
||||
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
||||
return PacketEvents.getAPI().packetManager.read(sender, channel,packet);
|
||||
return PacketEvents.getAPI().packetManager.read(sender, channel, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -361,7 +354,6 @@ public class TinyProtocol7 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -385,7 +377,6 @@ public class TinyProtocol7 {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, pi);
|
||||
}
|
||||
});
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -429,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>
|
||||
@@ -437,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
|
||||
@@ -459,7 +448,6 @@ public class TinyProtocol7 {
|
||||
channel.pipeline().remove(handlerName);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,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.
|
||||
|
||||
+7
-20
@@ -28,12 +28,8 @@ import io.github.retrooper.packetevents.packetmanager.tinyprotocol.Reflection.Me
|
||||
import io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@@ -78,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;
|
||||
|
||||
@@ -367,7 +360,6 @@ public class TinyProtocol8 {
|
||||
if (interceptor == null) {
|
||||
interceptor = new PacketInterceptor();
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, interceptor);
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -391,8 +383,6 @@ public class TinyProtocol8 {
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, pi);
|
||||
}
|
||||
});
|
||||
|
||||
uninjectedChannels.remove(channel);
|
||||
}
|
||||
|
||||
return interceptor;
|
||||
@@ -436,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>
|
||||
@@ -444,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
|
||||
|
||||
@@ -30,11 +30,12 @@ import java.util.Map;
|
||||
public class PacketType {
|
||||
public static class Status {
|
||||
public static final Map<Class<?>, Byte> packetIds = new HashMap<>();
|
||||
public static final byte PING = 0, PONG = 1;
|
||||
public static final byte PING = 0, PONG = 1, SERVER_INFO = 2;
|
||||
|
||||
public static void init() {
|
||||
packetIds.put(PacketTypeClasses.Status.PING, PING);
|
||||
packetIds.put(PacketTypeClasses.Status.PONG, PONG);
|
||||
packetIds.put(PacketTypeClasses.Status.SERVER_INFO, SERVER_INFO);
|
||||
}
|
||||
}
|
||||
public static class Login {
|
||||
|
||||
@@ -29,11 +29,12 @@ import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
|
||||
|
||||
public class PacketTypeClasses {
|
||||
public static class Status {
|
||||
public static Class<?> PING, PONG;
|
||||
public static Class<?> PING, PONG, SERVER_INFO;
|
||||
|
||||
public static void load() {
|
||||
PING = NMSUtils.getNMSClassWithoutException("PacketStatusInPing");
|
||||
PONG = NMSUtils.getNMSClassWithoutException("PacketStatusOutPong");
|
||||
SERVER_INFO = NMSUtils.getNMSClassWithoutException("PacketStatusOutServerInfo");
|
||||
PacketType.Status.init();
|
||||
}
|
||||
}
|
||||
|
||||
+25
-6
@@ -22,13 +22,32 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package io.github.retrooper.packetevents.utils.protocollib;
|
||||
package io.github.retrooper.packetevents.packetwrappers.in.vehiclemove;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import org.bukkit.entity.Player;
|
||||
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
|
||||
|
||||
class ProtocolLibAPIAccessor {
|
||||
public static int getProtocolVersion(final Player player) {
|
||||
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
|
||||
public class WrappedPacketInVehicleMove extends WrappedPacket {
|
||||
public WrappedPacketInVehicleMove(Object packet) {
|
||||
super(packet);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return readDouble(0);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return readDouble(1);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return readDouble(2);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return readFloat(0);
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return readFloat(1);
|
||||
}
|
||||
}
|
||||
+5
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public enum ServerVersion {
|
||||
this.protocolId = protocolId;
|
||||
}
|
||||
|
||||
public short toProtocolVersion() {
|
||||
public short getProtocolVersion() {
|
||||
return protocolId;
|
||||
}
|
||||
|
||||
|
||||
+3
-8
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user