Compare commits

..
20 Commits
Author SHA1 Message Date
purplexdev dc4dc80bdc Merge remote-tracking branch 'origin/master' 2020-06-05 20:17:47 +02:00
purplexdev 808a7b69d8 1.2.7 release,
Optimizations & bug fixes

* WrappedPacketInUseEntity getHand() null bug, so for now I just removed the getHand() method.

* WrappedPacketInEntityAction added as a couple of you suggested

* Optimization to getting entities by their id(used in use entity and entity action packet)

* After optimizing getEntity, file size has reduced by about 10%
2020-06-05 20:17:00 +02:00
retrooper 5b3b6ff509 jitpack version updated to 1.2.6 and link updated 2020-06-03 16:43:39 +02:00
purplexdev b923e86a91 Merge remote-tracking branch 'origin/master' 2020-06-03 13:43:54 +02:00
purplexdev 2c078dd1d4 Packages moved
io.github.explored.packetevents -> io.github.retrooper.packetevents
2020-06-03 13:43:41 +02:00
retrooper feb80c38b8 username changed 2020-06-03 13:29:16 +02:00
purplexdev b525407ad5 Keep alive packet added 2020-06-03 13:26:13 +02:00
purplexdev b660673743 * Get player ping
PacketEvents.getPing(Player);
2020-06-03 12:17:14 +02:00
purplexdev ba6e7c03fb 1.2.6 Bug fixes!
* Fixed listener not calling events outside of the "onPacket" function in the new
optimized event system!

* pom.xml updated to use new group id

* Registered listener example updated, more documented

This will be the 1.2.6 release build!
2020-06-02 10:22:08 +02:00
purplexdev 50e4b46018 Merge remote-tracking branch 'origin/master' 2020-06-02 09:57:12 +02:00
purplexdev a837bf38b1 Version 1.2.6 out,
* Packages moved from me.purplex.packetevents -> io.github.explored.packetevents
* The event calling has been massively optimized!
* Some unneeded imports have been removed.
2020-06-02 09:56:48 +02:00
explored 6fb102edf9 if link doesnt work 2020-06-01 17:58:31 +02:00
explored e45ed75e91 proper spacing 2020-06-01 17:56:32 +02:00
explored ef6b6b9466 readme details changed
* Changed my username (purplexdev -> explored)

* check out the details on the link specified
2020-06-01 17:55:35 +02:00
explored f6df333304 name changed 2020-05-31 20:33:49 +02:00
purplexdev 83aee85f48 Random debugs removed 2020-05-31 17:45:36 +02:00
purplexdev 73c5a0dfad Random debugs removed,
Now injecting players in PlayerLoginEvent
2020-05-29 13:06:29 +02:00
purplexdev 555c2b86c7 Merge remote-tracking branch 'origin/master' 2020-05-29 12:44:37 +02:00
purplexdev b5fd4b68bf LoginHandshake wrappers removed, BlockPlace added, WrappedPacketInUseEntity getEntity() optimized, to use worldServer.getEntity(ID); (faster) 2020-05-29 12:44:08 +02:00
purplex 3baaa64754 release version updated to 1.2.5 2020-05-28 20:34:22 +02:00
76 changed files with 1099 additions and 1016 deletions

No files matched your search

+10 -56
View File
@@ -1,70 +1,24 @@
# packetevents by purplex
# packetevents by retrooper
PacketListener coded by purplex.
An asynchronous spigot packetListener coded by retrooper.
Dependencies? Nah...
* No dependencies
Licensed with the GPL3 license.
* Licensed with the GPL3 license.
[![](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Coding help discord server: https://discord.gg/ZWTkg4v
Join my discord server(to talk to me): https://discord.gg/ZWTkg4v
How to use with **Gradle, Maven, sbt and leiningen**.
The lastest stable version is displayed below.
Click the link below.
[![](https://jitpack.io/v/purplexdev/packetevents.svg)](https://jitpack.io/#purplexdev/packetevents)
Make sure to replace **Tag** with a proper release version.
# Gradle
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.purplexdev:packetevents:1.1.9'
}
```
# Maven
```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.purplexdev</groupId>
<artifactId>packetevents</artifactId>
<version>1.1.9</version>
</dependency>
</dependencies>
```
# sbt
```
resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.purplexdev" % "packetevents" % "1.1.9"
```
# leiningen
```
:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.purplexdev/packetevents "1.1.9"]]
```
I recommend you to use the latest released version!
[![](https://jitpack.io/v/retrooper/packetevents.svg)](https://jitpack.io/#retrooper/packetevents)
If clicking the badge doesn't work paste this link into your browser http://jitpack.io/#explored/packetevents
+2 -2
View File
@@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.purplex</groupId>
<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.2.5</version>
<version>1.2.7</version>
<packaging>jar</packaging>
<name>packetevents</name>
<properties>
@@ -1,18 +1,19 @@
package me.purplex.packetevents;
package io.github.retrooper.packetevents;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.event.impl.ServerTickEvent;
import me.purplex.packetevents.event.manager.EventManager;
import me.purplex.packetevents.injector.PacketInjector; //public packet injector
import me.purplex.packetevents.utils.TPSUtils; //tps utils
import io.github.retrooper.packetevents.event.impl.ServerTickEvent;
import io.github.retrooper.packetevents.event.manager.EventManager;
import io.github.retrooper.packetevents.injector.PacketInjector;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.utils.TPSUtils;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import javax.annotation.Nullable;
import java.util.concurrent.*;
public class PacketEvents implements Listener {
@@ -32,7 +33,6 @@ public class PacketEvents implements Listener {
return eventManager;
}
@Deprecated
public static void setup(final JavaPlugin plugin, final boolean serverTickEventEnabled) {
PacketEvents.plugin = plugin;
Bukkit.getPluginManager().registerEvents(getInstance(), plugin);
@@ -48,7 +48,6 @@ public class PacketEvents implements Listener {
}
}
@Deprecated
public static void cleanup() {
if (serverTickTask != null) {
serverTickTask.cancel();
@@ -72,7 +71,6 @@ public class PacketEvents implements Listener {
}
};
Future<?> future = executor.submit(runnable);
}
@EventHandler
@@ -92,6 +90,7 @@ public class PacketEvents implements Listener {
return serverTickTask != null;
}
@Nullable
public static double[] getRecentServerTPS() {
final double[] tpsArray = TPSUtils.getRecentTPS();
final int size = tpsArray.length;
@@ -107,6 +106,10 @@ public class PacketEvents implements Listener {
return getRecentServerTPS()[0];
}
public static int getPing(final Player player) {
return NMSUtils.getPlayerPing(player);
}
public static long currentTimeMS() {
return System.nanoTime() / 1000000;
}
@@ -0,0 +1,17 @@
package io.github.retrooper.packetevents.enums;
public enum Direction {
DOWN, UP, NORTH, SOUTH, WEST, EAST
,NORTH_EAST,
NORTH_WEST, SOUTH_EAST,
SOUTH_WEST, WEST_NORTH_WEST,
NORTH_NORTH_WEST, NORTH_NORTH_EAST,
EAST_NORTH_EAST, EAST_SOUTH_EAST,
SOUTH_SOUTH_EAST, SOUTH_SOUTH_WEST,
WEST_SOUTH_WEST, SELF, NULL;
public static Direction get(final byte i) {
return values()[i];
}
}
@@ -1,4 +1,4 @@
package me.purplex.packetevents.enums;
package io.github.retrooper.packetevents.enums;
public enum EntityUseAction {
INTERACT, INTERACT_AT, ATTACK, INVALID;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.enums;
package io.github.retrooper.packetevents.enums;
public enum Hand {
MAIN_HAND,
@@ -1,4 +1,4 @@
package me.purplex.packetevents.enums;
package io.github.retrooper.packetevents.enums;
public enum PlayerAction {
START_SNEAKING,
@@ -1,4 +1,4 @@
package me.purplex.packetevents.enums;
package io.github.retrooper.packetevents.enums;
public enum PlayerDigType {
@@ -1,4 +1,4 @@
package me.purplex.packetevents.enums;
package io.github.retrooper.packetevents.enums;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
@@ -1,8 +1,8 @@
package me.purplex.packetevents.event;
package io.github.retrooper.packetevents.event;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.ServerVersion;
/**
* Incoming and sent packets are called asynchronously,
@@ -1,4 +1,4 @@
package me.purplex.packetevents.event.handler;
package io.github.retrooper.packetevents.event;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -0,0 +1,4 @@
package io.github.retrooper.packetevents.event;
public interface PacketListener {
}
@@ -1,8 +1,9 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
//unfinished
public class PacketLoginEvent extends PacketEvent {
private final Player player;
private final String name;
@@ -1,6 +1,6 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public class PacketReceiveEvent extends PacketEvent {
@@ -1,6 +1,6 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public class PacketSendEvent extends PacketEvent {
@@ -1,6 +1,6 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public class PlayerInjectEvent extends PacketEvent {
@@ -1,6 +1,6 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public class PlayerUninjectEvent extends PacketEvent {
@@ -0,0 +1,21 @@
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.event.PacketEvent;
//unfinished
public class ServerReloadEvent extends PacketEvent {
private final long currentTime;
public ServerReloadEvent(final long currentTime){
this.currentTime = currentTime;
}
public ServerReloadEvent() {
this.currentTime = PacketEvents.currentTimeMS();
}
public final long getCurrentTime() {
return currentTime;
}
}
@@ -1,7 +1,7 @@
package me.purplex.packetevents.event.impl;
package io.github.retrooper.packetevents.event.impl;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.event.PacketEvent;
public class ServerTickEvent extends PacketEvent {
private final int tick;
@@ -0,0 +1,57 @@
package io.github.retrooper.packetevents.event.manager;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.PacketHandler;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class EventManager {
private static HashMap<PacketListener, List<Method>> registeredMethods = new HashMap<PacketListener, List<Method>>();
public static void callEvent(final PacketEvent e) {
for (final PacketListener listener : registeredMethods.keySet()) {
//Annotated methods
final List<Method> methods = registeredMethods.get(listener);
for (final Method method : methods) {
if (method.getParameterTypes()[0].equals(PacketEvent.class)
|| method.getParameterTypes()[0].getSimpleName().equals(e.getClass().getSimpleName())) {
try {
method.invoke(listener, e);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
}
}
}
}
public static void registerListener(final PacketListener e) {
final List<Method> methods = new ArrayList<Method>();
for (final Method m : e.getClass().getMethods()) {
if (m.isAnnotationPresent(PacketHandler.class)) {
methods.add(m);
}
}
registeredMethods.put(e, methods);
}
public static void unregisterListener(final PacketListener e) {
registeredMethods.remove(e);
}
public static void unregisterAllListeners() {
registeredMethods.clear();
}
/*@Override
public void sendPacket(Player player, WrappedPacket packet) {
}*/
}
@@ -1,7 +1,6 @@
package me.purplex.packetevents.example;
package io.github.retrooper.packetevents.example;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -20,7 +19,7 @@ public class CustomMoveEvent extends PacketEvent {
this.to = to;
this.from = from;
this.cancelled = false;
//Timestamp is initialized automatically, so you don't need to initiate it, but you may modify it
//Timestamp is initialized automatically, so you don't need to initiate it, but you may modify it if you like
//this.timestamp = PacketEvents.currentTimeMS();
}
@@ -49,11 +48,11 @@ public class CustomMoveEvent extends PacketEvent {
return from;
}
public void setTo(Location loc) {
public void setTo(final Location loc) {
this.to = loc;
}
public void setFrom(Location loc) {
public void setFrom(final Location loc) {
this.from = from;
}
@@ -1,6 +1,6 @@
package me.purplex.packetevents.example;
package io.github.retrooper.packetevents.example;
import me.purplex.packetevents.PacketEvents;
import io.github.retrooper.packetevents.PacketEvents;
import org.bukkit.plugin.java.JavaPlugin;
public class MainExample extends JavaPlugin {
@@ -1,27 +1,28 @@
package me.purplex.packetevents.example;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.enums.Direction;
import me.purplex.packetevents.enums.EntityUseAction;
import me.purplex.packetevents.enums.Hand;
import me.purplex.packetevents.enums.PlayerDigType;
import me.purplex.packetevents.event.PacketEvent;
import me.purplex.packetevents.event.impl.*;
import me.purplex.packetevents.event.handler.PacketHandler;
import me.purplex.packetevents.event.listener.PacketListener;
import me.purplex.packetevents.packet.Packet;
import me.purplex.packetevents.packetwrappers.in.abilities.WrappedPacketInAbilities;
import me.purplex.packetevents.packetwrappers.in.blockdig.WrappedPacketInBlockDig;
import me.purplex.packetevents.packetwrappers.in.chat.WrappedPacketInChat;
import me.purplex.packetevents.packetwrappers.in.flying.WrappedPacketInFlying;
import me.purplex.packetevents.packetwrappers.in.use_entity.WrappedPacketInUseEntity;
import me.purplex.packetevents.packetwrappers.login.handshake.WrappedPacketLoginHandshake;
import me.purplex.packetevents.utils.playerprotocolversion.PlayerVersionManager;
package io.github.retrooper.packetevents.example;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.*;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketHandler;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.packetwrappers.in.abilities.WrappedPacketInAbilities;
import io.github.retrooper.packetevents.packetwrappers.in.blockdig.WrappedPacketInBlockDig;
import io.github.retrooper.packetevents.packetwrappers.in.blockplace.WrappedPacketInBlockPlace;
import io.github.retrooper.packetevents.packetwrappers.in.chat.WrappedPacketInChat;
import io.github.retrooper.packetevents.packetwrappers.in.entityaction.WrappedPacketInEntityAction;
import io.github.retrooper.packetevents.packetwrappers.in.flying.WrappedPacketInFlying;
import io.github.retrooper.packetevents.packetwrappers.in.keepalive.WrappedPacketInKeepAlive;
import io.github.retrooper.packetevents.packetwrappers.in.useentity.WrappedPacketInUseEntity;
import io.github.retrooper.packetevents.packet.Packet;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
import io.github.retrooper.packetevents.event.impl.*;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
/**
* Implementing PacketListener to listen to packets and packetevents' custom events,
@@ -44,9 +45,8 @@ public class RegisteredListener implements PacketListener, Listener {
case Packet.Client.USE_ENTITY:
final WrappedPacketInUseEntity useEntity = new WrappedPacketInUseEntity(e.getPacket());
final Entity entity = useEntity.getEntity();
final double distance = entity.getLocation().distanceSquared(p.getLocation());
final Hand hand = useEntity.getHand();
final EntityUseAction action = useEntity.getAction();
final double distanceSquared = entity.getLocation().distanceSquared(p.getLocation());
final EntityUseAction useAction = useEntity.getAction();
break;
case Packet.Client.ABILITIES:
final WrappedPacketInAbilities abilities = new WrappedPacketInAbilities(e.getPacket());
@@ -63,7 +63,6 @@ public class RegisteredListener implements PacketListener, Listener {
final WrappedPacketInBlockDig blockDig = new WrappedPacketInBlockDig(e.getPacket());
final PlayerDigType type = blockDig.getDigType();
final Direction direction = blockDig.getDirection();
break;
case Packet.Client.FLYING:
final WrappedPacketInFlying flying = new WrappedPacketInFlying(e.getPacket());
@@ -85,32 +84,58 @@ public class RegisteredListener implements PacketListener, Listener {
final String message = chat.getMessage();
//e.getPlayer().sendMessage(message);
break;
case Packet.Client.BLOCK_PLACE:
final WrappedPacketInBlockPlace blockPlace = new WrappedPacketInBlockPlace(e.getPlayer(), e.getPacket());
final Vector3i blockPosition = blockPlace.getBlockPosition();
final Hand h = blockPlace.getHand();
final ItemStack stack = blockPlace.getItemStack();
break;
case Packet.Client.KEEP_ALIVE:
final WrappedPacketInKeepAlive keepAlive = new WrappedPacketInKeepAlive(e.getPacket());
final long responseID = keepAlive.getId();
break;
case Packet.Client.ENTITY_ACTION:
final WrappedPacketInEntityAction entityAction = new WrappedPacketInEntityAction(e.getPacket());
final PlayerAction action = entityAction.getAction();
final int jumpBoost = entityAction.getJumpBoost();
break;
//System.out.println("YOU SAID: " + message);
}
}
@PacketHandler
public void onPacketSend(PacketSendEvent e) {
}
/**
* Example of a custom event
* @param e
*/
@PacketHandler
public void onCustomMove(CustomMoveEvent e) {
double distance = e.getTo().distanceSquared(e.getFrom());
}
/**
* I recommend you use the player inject event
* to register your players instead of any other bukkit event,
* to avoid any issues.
* @param event
*/
@PacketHandler
public void onInject(PlayerInjectEvent event) {
//event.getPlayer().sendMessage("injected");
//event.setCancelled(true) is possible
}
/**
* I recommend you use the player uninject event,
* to unregister your players
*
* You can also call this event to "whitelist" a player,
* our API won't even notice the player exists, so you won't
* be able to listen to any packets from the player
* @param e
*/
@PacketHandler
public void onUninject(PlayerUninjectEvent e) {
//e.setCancelled(true); will
}
/**
@@ -119,7 +144,7 @@ public class RegisteredListener implements PacketListener, Listener {
* @param e PacketEvent
*/
@PacketHandler
public void onPacket(PacketEvent e) {
public void onPacket(final PacketEvent e) {
if (e instanceof PacketSendEvent) {
final PacketSendEvent p = (PacketSendEvent) e;
final Player targetPlayer = p.getPlayer();
@@ -134,19 +159,7 @@ public class RegisteredListener implements PacketListener, Listener {
final ServerTickEvent event = (ServerTickEvent) e;
final int currentTick = event.getCurrentTick();
// System.out.println(PacketEvents.getCurrentServerTPS() + " is tps");
} else if (e instanceof PacketLoginEvent) {
//System.out.println("LLLOOOOOGIN");
final PacketLoginEvent event = (PacketLoginEvent) e;
if (event.getPacketName().equals(Packet.Login.HANDSHAKE)) {
final WrappedPacketLoginHandshake handshake = new WrappedPacketLoginHandshake(event.getPacket());
final String hostname = handshake.hostname;
final int port = handshake.port;
final int protocolVersion = handshake.protocolVersion;
PlayerVersionManager.setPlayerProtocolVersion(event.getPlayer().getUniqueId(), protocolVersion);
// System.out.println("PROTOCOL NUMBER: " + protocolVersion);
}
}
}
@@ -157,7 +170,7 @@ public class RegisteredListener implements PacketListener, Listener {
*/
@EventHandler
public void onMove(PlayerMoveEvent e) {
CustomMoveEvent customMoveEvent = new CustomMoveEvent(e.getPlayer(), e.getTo(), e.getFrom());
final CustomMoveEvent customMoveEvent = new CustomMoveEvent(e.getPlayer(), e.getTo(), e.getFrom());
e.setCancelled(customMoveEvent.isCancelled());
PacketEvents.getEventManager().callEvent(customMoveEvent);
@@ -168,15 +181,4 @@ public class RegisteredListener implements PacketListener, Listener {
e.setFrom(customMoveEvent.getFrom());
}
}
/**
* Only listen to server tick (if enabled)
*
* @param e ServerTickEvent
*/
@PacketHandler
public void onServerTick(ServerTickEvent e) {
}
}
@@ -1,11 +1,7 @@
package me.purplex.packetevents.injector;
package io.github.retrooper.packetevents.injector;
import me.purplex.packetevents.enums.ServerVersion;
import net.minecraft.server.v1_8_R3.NetworkManager;
import net.minecraft.util.io.netty.channel.Channel;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -41,7 +37,7 @@ public class ChannelManager {
throw new IllegalStateException("Failed to find a NMS class! You are probably using an unsupported version of spigot.");
}
//FIELDS & METHODS
try {
channelField = networkManager.getDeclaredField(getChannelFieldName());
} catch (NoSuchFieldException e) {
@@ -53,14 +49,11 @@ public class ChannelManager {
}
try {
handleMethod = craftPlayer.getDeclaredMethod("getHandle");
handleMethod = craftPlayer.getMethod("getHandle");
} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new IllegalStateException("Failed to find the getHandle function in the CraftPlayer class! You are probably using an unsupported version of spigot.");
}
if (!handleMethod.isAccessible()) {
handleMethod.setAccessible(true);
}
try {
playerConnectionField = entityPlayer.getDeclaredField("playerConnection");
@@ -97,11 +90,16 @@ public class ChannelManager {
playerChannels.remove(uuid);
}
public static boolean contains(final Player player) {
return playerChannels.containsKey(player.getUniqueId());
}
public static Object getChannel(final Player player) {
final UUID uuid = player.getUniqueId();
if (playerChannels.containsKey(uuid)) {
if (contains(player)) {
return playerChannels.get(uuid);
}
Object channel = null;
try {
channel = getChannelObject(player);
@@ -112,8 +110,7 @@ public class ChannelManager {
}
if (channel != null) {
playerChannels.put(uuid, channel);
}
else {
} else {
System.out.println("ITS NULL");
}
return channel;
@@ -1,8 +1,8 @@
package me.purplex.packetevents.injector;
package io.github.retrooper.packetevents.injector;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.entity.Player;
@@ -16,7 +16,6 @@ public class PacketInjector {
}
else {
PlayerInject_1_8.injectPlayer(player);
// player.sendMessage("injected");
}
}
@@ -29,5 +28,4 @@ public class PacketInjector {
}
ChannelManager.removeChannel(player.getUniqueId());
}
}
@@ -1,10 +1,10 @@
package me.purplex.packetevents.injector;
package io.github.retrooper.packetevents.injector;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.event.impl.PacketReceiveEvent;
import me.purplex.packetevents.event.impl.PacketSendEvent;
import me.purplex.packetevents.event.impl.PlayerInjectEvent;
import me.purplex.packetevents.event.impl.PlayerUninjectEvent;
import io.github.retrooper.packetevents.PacketEvents;
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.event.impl.PlayerUninjectEvent;
import net.minecraft.util.io.netty.channel.Channel;
import net.minecraft.util.io.netty.channel.ChannelDuplexHandler;
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
@@ -55,6 +55,7 @@ class PlayerInject_1_7_10 {
PacketEvents.getEventManager().callEvent(uninjectEvent);
channel.eventLoop().submit(runnable);
}
public static Channel getChannel(final Player player) {
return (Channel) ChannelManager.getChannel(player);
}
@@ -1,15 +1,15 @@
package me.purplex.packetevents.injector;
package io.github.retrooper.packetevents.injector;
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.event.impl.PlayerUninjectEvent;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.event.impl.PacketReceiveEvent;
import me.purplex.packetevents.event.impl.PacketSendEvent;
import me.purplex.packetevents.event.impl.PlayerInjectEvent;
import me.purplex.packetevents.event.impl.PlayerUninjectEvent;
import io.github.retrooper.packetevents.PacketEvents;
import org.bukkit.entity.Player;
class PlayerInject_1_8 {
@@ -0,0 +1,81 @@
package io.github.retrooper.packetevents.packet;
public abstract class Packet {
public static class Client {
private static final String c = "PacketPlayIn";
@Deprecated
public static final String FLYING = c + "Flying";
public static final String POSITION = c + "Position";
public static final String POSITION_LOOK = c + "PositionLook";
public static final String LOOK = c + "Look";
public static final String CLIENT_COMMAND = c + "ClientCommand";
public static final String TRANSACTION = c + "Transaction";
public static final String BLOCK_DIG = c + "BlockDig";
public static final String ENTITY_ACTION = c + "EntityAction";
public static final String USE_ENTITY = c + "UseEntity";
public static final String WINDOW_CLICK = c + "WindowClick";
public static final String STEER_VEHICLE = c + "SteerVehicle";
public static final String CUSTOM_PAYLOAD = c + "CustomPayload";
public static final String ARM_ANIMATION = c + "ArmAnimation";
public static final String BLOCK_PLACE = c + "BlockPlace";
public static final String ABILITIES = c + "Abilities";
public static final String HELD_ITEM_SLOT = c + "HeldItemSlot";
public static final String CLOSE_WINDOW = c + "CloseWindow";
public static final String TAB_COMPLETE = c + "TabComplete";
public static final String CHAT = c + "Chat";
public static final String SET_CREATIVE_SLOT = c + "SetCreativeSlot";
public static final String KEEP_ALIVE = c + "KeepAlive";
}
public static class Server {
private static final String s = "PacketPlayOut";
public static final String ANIMATION = s + "Animation";
public static final String KEEP_ALIVE = s + "KeepAlive";
public static final String CHAT = s + "Chat";
public static final String POSITION = s + "Position";
public static final String TRANSACTION = s + "Transaction";
public static final String NAMED_ENTITY_SPAWN = s + "NamedEntitySpawn";
public static final String SPAWN_ENTITY_LIVING = s + "SpawnEntityLiving";
public static final String SPAWN_ENTITY = s + "SpawnEntity";
public static final String CUSTOM_PAYLOAD = s + "CustomPayload";
public static final String ABILITIES = s + "Abilities";
public static final String ENTITY_METADATA = s + "EntityMetadata";
public static final String ENTITY_VELOCITY = s + "EntityVelocity";
public static final String ENTITY_DESTROY = s + "EntityDestroy";
public static final String ENTITY_HEAD_ROTATION = s + "EntityHeadRotation";
public static final String BLOCK_CHANGE = s + "BlockChange";
public static final String CLOSE_WINDOW = s + "CloseWindow";
public static final String HELD_ITEM_SLOT = s + "HeldItemSlot";
public static final String TAB_COMPLETE = s + "TabComplete";
public static final String RESPAWN = s + "Respawn";
public static final String WORLD_PARTICLES = s + "WorldParticles";
public static final String COMMANDS = s + "Commands";
public static final String OPEN_WINDOW = s + "OpenWindow";
public static final String LOGIN = s + "Login";
public static final String SERVER_DIFFICULTY = s + "ServerDifficulty";
}
public static class Login {
public static final String HANDSHAKE = "PacketHandshakingInSetProtocol";
public static final String PING = "PacketStatusInPing";
public static final String START = "PacketStatusInStart";
public static final String SUCCESS = "PacketLoginOutSuccess";
}
public static boolean isInstanceOf(String fatherPacket, String childPacket) {
if (fatherPacket.equals(Client.FLYING) && childPacket.equals(Client.POSITION) || childPacket.equals(Client.POSITION_LOOK) || childPacket.equals(Client.LOOK)) {
return true;
}
return fatherPacket.equals(childPacket);
}
}
@@ -0,0 +1,48 @@
package io.github.retrooper.packetevents.packetwrappers.api;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.entity.Player;
public class WrappedPacket {
private final Player player;
protected Object packet;
protected static ServerVersion version = ServerVersion.getVersion();
private static final String err = "Your Version is unsupported, " +
"please contact explored " +
"through his discord server (http://discord.gg/2uZY5A4) " +
"and tell him what version your server is running on! " +
"Make sure you are using spigot!";
public WrappedPacket(final Object packet) {
this.player = null;
this.packet = packet;
try {
setup();
} catch (final Exception e) {
e.printStackTrace();
}
}
public WrappedPacket(final Player player, final Object packet) {
this.player = player;
this.packet = packet;
try {
setup();
} catch (final Exception e) {
e.printStackTrace();
}
}
protected void setup() throws Exception {
}
protected void throwUnsupportedVersion() {
throw new IllegalStateException(err);
}
public Player getPlayer() {
return player;
}
}
@@ -1,7 +1,7 @@
package me.purplex.packetevents.packetwrappers.in.abilities;
package io.github.retrooper.packetevents.packetwrappers.in.abilities;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
import me.purplex.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Field;
@@ -54,15 +54,16 @@ public class WrappedPacketInAbilities extends WrappedPacket {
private static Class<?> abilitiesClass;
private static Field[] fields = new Field[6];
static {
//CLASS
try {
abilitiesClass = NMSUtils.getNMSClass("PacketPlayInAbilities");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//FIELDS
try {
fields[0] = abilitiesClass.getDeclaredField("a");
fields[1] = abilitiesClass.getDeclaredField("b");
@@ -74,8 +75,10 @@ public class WrappedPacketInAbilities extends WrappedPacket {
e.printStackTrace();
}
for(Field f : fields) {
f.setAccessible(true);
for (Field f : fields) {
if (f != null) {
f.setAccessible(true);
}
}
}
}
@@ -1,13 +1,13 @@
package me.purplex.packetevents.packetwrappers.in.blockdig;
package io.github.retrooper.packetevents.packetwrappers.in.blockdig;
import io.github.retrooper.packetevents.enums.PlayerDigType;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.BaseBlockUtils;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
import io.github.retrooper.packetevents.enums.Direction;
import me.purplex.packetevents.enums.Direction;
import me.purplex.packetevents.enums.PlayerDigType;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
import me.purplex.packetevents.utils.BaseBlockUtils;
import me.purplex.packetevents.utils.NMSUtils;
import me.purplex.packetevents.utils.math.*;
import java.lang.reflect.Field;
public class WrappedPacketInBlockDig extends WrappedPacket {
@@ -83,7 +83,7 @@ public class WrappedPacketInBlockDig extends WrappedPacket {
private static Field e;
static {
//CLASSES
try {
blockDigClass = NMSUtils.getNMSClass("PacketPlayInBlockDig");
if (version != ServerVersion.v_1_7_10) {
@@ -93,7 +93,7 @@ public class WrappedPacketInBlockDig extends WrappedPacket {
e.printStackTrace();
}
//FIELDS
try {
//blockpos
fields[0] = blockDigClass.getDeclaredField("a");
@@ -0,0 +1,75 @@
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.enums.Direction;
import io.github.retrooper.packetevents.enums.Hand;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class WrappedPacketInBlockPlace extends WrappedPacket {
private Vector3i blockPosition;
private Hand hand;
private Direction direction;
private ItemStack itemStack;
public WrappedPacketInBlockPlace(final Player player, final Object packet) {
super(player, packet);
}
@Override
protected void setup() throws Exception {
//1.7.10
final Direction direction;
final Vector3i position;
final ItemStack itemStack;
final Hand hand;
if (version.isHigherThan(ServerVersion.v_1_8_8)) {
final WrappedPacketInBlockPlace_1_9 updatedBlockPlace = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
final Block block = updatedBlockPlace.getBlock();
position = new Vector3i(block.getX(), block.getY(), block.getZ());
hand = updatedBlockPlace.getHand();
itemStack = new ItemStack(block.getType());
// init direction
} else {
final WrappedPacketInBlockPlace_Legacy legacyBlockPlace = new WrappedPacketInBlockPlace_Legacy(packet);
position = legacyBlockPlace.getBlockPosition();
hand = legacyBlockPlace.getHand();
itemStack = legacyBlockPlace.getItemStack();
//init direction
}
this.direction = Direction.NULL;
this.blockPosition = position;
this.itemStack = itemStack;
this.hand = hand;
}
public Vector3i getBlockPosition() {
return blockPosition;
}
public Hand getHand() {
return hand;
}
public ItemStack getItemStack() {
return itemStack;
}
@Deprecated
public Direction getDirection() {
return direction;
}
static {
if (version.isHigherThan(ServerVersion.v_1_8_8)) {
WrappedPacketInBlockPlace_1_9.setupStaticVars();
} else {
WrappedPacketInBlockPlace_Legacy.setupStaticVars();
}
}
}
@@ -0,0 +1,61 @@
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.enums.Hand;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.BlockFinder;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
class WrappedPacketInBlockPlace_1_9 extends WrappedPacket {
private Block block;
private Hand hand;
public WrappedPacketInBlockPlace_1_9(final Player player, final Object packet) {
super(player, packet);
}
@Override
protected void setup() throws Exception {
this.block = BlockFinder.getBlocksInDirection(getPlayer(), 10);
final Object enumHandObj = enumHandField.get(packet);
this.hand = Hand.valueOf(enumHandObj.toString());
}
public Hand getHand() {
return hand;
}
public Block getBlock() {
return block;
}
private static Class<?> blockPlaceClass_1_9;
private static Field enumHandField;
protected static void setupStaticVars() {
try {
blockPlaceClass_1_9 = NMSUtils.getNMSClass("PacketPlayInBlockPlace");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
enumHandField = blockPlaceClass_1_9.getDeclaredField("a");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
if(!enumHandField.isAccessible()) {
enumHandField.setAccessible(true);
}
}
}
@@ -0,0 +1,148 @@
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.enums.Hand;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.BaseBlockUtils;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
class WrappedPacketInBlockPlace_Legacy extends WrappedPacket {
private Vector3i blockPosition;
private ItemStack itemStack;
private Hand hand;
WrappedPacketInBlockPlace_Legacy(final Object packet) {
super(packet);
}
@Override
protected void setup() throws Exception {
final Hand hand = Hand.MAIN_HAND;
final ItemStack itemStack;
final int x, y, z;
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
final Object nmsBlockPosObj = fields[0].get(packet);
x = blockPosXYZ[0].getInt(nmsBlockPosObj);
y = blockPosXYZ[1].getInt(nmsBlockPosObj);
z = blockPosXYZ[2].getInt(nmsBlockPosObj);
Object nmsItemStackObj = fields[1].get(packet);
Object craftItemStack = asBukkitCopyMethod.invoke(null, nmsItemStackObj);
itemStack = (ItemStack) craftItemStack;
}
//1.7.10
else {
x = fields_1_7[0].getInt(packet);
y = fields_1_7[1].getInt(packet);
z = fields_1_7[2].getInt(packet);
Object nmsItemStackObj = fields_1_7[3].get(packet);
Object craftItemStack = asBukkitCopyMethod.invoke(null, nmsItemStackObj);
itemStack = (ItemStack) craftItemStack;
}
this.hand = hand;
this.itemStack = itemStack;
this.blockPosition = new Vector3i(x, y, z);
}
public Hand getHand() {
return hand;
}
public ItemStack getItemStack() {
return itemStack;
}
public Vector3i getBlockPosition() {
return blockPosition;
}
private static Class<?> blockPlaceClass;
private static Class<?> itemStackClass;
private static Class<?> craftItemStackClass;
private static Class<?> blockPositionClass;
private static Field[] fields = new Field[2];
private static Field[] fields_1_7 = new Field[4];
private static Field[] blockPosXYZ = new Field[3];
private static Method asBukkitCopyMethod;
protected static void setupStaticVars() {
try {
blockPlaceClass = NMSUtils.getNMSClass("PacketPlayInBlockPlace");
itemStackClass = NMSUtils.getNMSClass("ItemStack");
craftItemStackClass = NMSUtils.getOBCClass("inventory.CraftItemStack");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
blockPositionClass = NMSUtils.getNMSClass("BlockPosition");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
asBukkitCopyMethod = craftItemStackClass.getMethod("asBukkitCopy", itemStackClass);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
try {
if (version.isLowerThan(ServerVersion.v_1_8)) {
//x
fields_1_7[0] = blockPlaceClass.getDeclaredField("a");
//y
fields_1_7[1] = blockPlaceClass.getDeclaredField("b");
//z
fields_1_7[2] = blockPlaceClass.getDeclaredField("c");
//itemstack
fields_1_7[3] = blockPlaceClass.getDeclaredField("e");
} else {
//block pos
fields[0] = blockPlaceClass.getDeclaredField("b");
//itemstack
fields[1] = blockPlaceClass.getDeclaredField("d");
blockPosXYZ[0] = blockPositionClass.getSuperclass().getDeclaredField(BaseBlockUtils.getPosXFieldName());
blockPosXYZ[1] = blockPositionClass.getSuperclass().getDeclaredField(BaseBlockUtils.getPosYFieldName());
blockPosXYZ[2] = blockPositionClass.getSuperclass().getDeclaredField(BaseBlockUtils.getPosZFieldName());
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
for (Field f : fields) {
if (f != null) {
f.setAccessible(true);
}
}
for (Field f : fields_1_7) {
if (f != null) {
f.setAccessible(true);
}
}
for (Field f : blockPosXYZ) {
if (f != null) {
f.setAccessible(true);
}
}
}
}
@@ -1,8 +1,8 @@
package me.purplex.packetevents.packetwrappers.in.chat;
package io.github.retrooper.packetevents.packetwrappers.in.chat;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
import me.purplex.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Field;
@@ -28,7 +28,7 @@ public class WrappedPacketInChat extends WrappedPacket {
private static Field field;
static {
//CLASSES
try {
chatPacketClass = NMSUtils.getNMSClass("PacketPlayInChat");
} catch (ClassNotFoundException e) {
@@ -41,9 +41,7 @@ public class WrappedPacketInChat extends WrappedPacket {
e.printStackTrace();
}
if (!field.isAccessible()) {
field.setAccessible(true);
}
field.setAccessible(true);
}
private static String getChatFieldName() {
@@ -0,0 +1,108 @@
package io.github.retrooper.packetevents.packetwrappers.in.entityaction;
import io.github.retrooper.packetevents.enums.PlayerAction;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
public class WrappedPacketInEntityAction extends WrappedPacket {
private Entity entity;
private int entityId;
private PlayerAction action;
private int jumpBoost;
public WrappedPacketInEntityAction(final Object packet) {
super(packet);
}
@Override
protected void setup() throws Exception {
final int entityId = fields[0].getInt(packet);
final int jumpBoost = fields[2].getInt(packet);
int animationIndex = -1;
//1.7.10
if (version.isLowerThan(ServerVersion.v_1_8)) {
animationIndex = fields[1].getInt(packet);
} else {
final Object enumObj = fields[1].get(packet);
final Object[] enumValues = enumPlayerActionConstants;
final int len = enumValues.length;
for (int i = 0; i < len; i++) {
final Object val = enumValues[i];
if (val.toString().equals(enumObj.toString())) {
animationIndex = i;
break;
}
}
}
this.entityId = entityId;
this.action = action;
this.jumpBoost = jumpBoost;
this.action = PlayerAction.get((byte) animationIndex);
this.entity = NMSUtils.getEntityById(this.entityId);
}
public Entity getEntity() {
return entity;
}
public int getEntityId() {
return entityId;
}
public PlayerAction getAction() {
return action;
}
public int getJumpBoost() {
return jumpBoost;
}
private static Class<?> entityActionClass;
@Nullable
private static Class<?> enumPlayerActionClass;
private static Field[] fields = new Field[3];
@Nullable
private static Object[] enumPlayerActionConstants;
static {
try {
entityActionClass = NMSUtils.getNMSClass("PacketPlayInEntityAction");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
enumPlayerActionClass = NMSUtils.getNMSClass("PacketPlayInEntityAction$EnumPlayerAction");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
//ints in 1.7.10, EnumPlayerAction in 1.8+
fields[0] = entityActionClass.getDeclaredField("a");
fields[1] = entityActionClass.getDeclaredField("animation");
fields[2] = entityActionClass.getDeclaredField("c");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
enumPlayerActionConstants = enumPlayerActionClass.getEnumConstants();
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
for (final Field f : fields) {
f.setAccessible(true);
}
}
}
@@ -1,9 +1,10 @@
package me.purplex.packetevents.packetwrappers.in.flying;
package io.github.retrooper.packetevents.packetwrappers.in.flying;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
import me.purplex.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Field;
@@ -106,14 +107,14 @@ public class WrappedPacketInFlying extends WrappedPacket {
private static Field[] fields = new Field[8]; //x, y, z, yaw pitch, onGround, isPositionPacket, isLookPacket
static {
//CLASS
try {
flyingClass = NMSUtils.getNMSClass("PacketPlayInFlying");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//FIELDS
try {
fields[0] = flyingClass.getDeclaredField("x");
fields[1] = flyingClass.getDeclaredField("y");
@@ -128,7 +129,7 @@ public class WrappedPacketInFlying extends WrappedPacket {
}
for (Field f : fields) {
if (!f.isAccessible()) {
if (f != null) {
f.setAccessible(true);
}
}
@@ -0,0 +1,54 @@
package io.github.retrooper.packetevents.packetwrappers.in.keepalive;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Field;
public class WrappedPacketInKeepAlive extends WrappedPacket {
public WrappedPacketInKeepAlive(final Object packet) {
super(packet);
}
private long id;
@Override
protected void setup() throws Exception {
if(version.isHigherThan(ServerVersion.v_1_12)) {
this.id = idField.getLong(packet);
}
else {
this.id = idField.getInt(packet);
}
}
/**
* Cast this long to an integer if you are using 1.7.10->1.12.2!
* In 1.13.2->1.15.2 a long is sent
* @return
*/
public long getId() {
return id;
}
private static Class<?> keepAliveClass;
//1.7.10->1.12.2 has int field "a", rest as long field "a"
private static Field idField;
static {
try {
keepAliveClass = NMSUtils.getNMSClass("PacketPlayInKeepAlive");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
idField = keepAliveClass.getDeclaredField("a");
idField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,73 @@
package io.github.retrooper.packetevents.packetwrappers.in.useentity;
import io.github.retrooper.packetevents.enums.EntityUseAction;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
import java.lang.reflect.Field;
public class WrappedPacketInUseEntity extends WrappedPacket {
private int entityId;
private Entity entity;
private EntityUseAction action;
public WrappedPacketInUseEntity(final Object packet) {
super(packet);
}
@Override
protected void setup() throws IllegalAccessException {
this.entityId = fields[0].getInt(packet);
this.entity = NMSUtils.getEntityById(this.entityId);
final Object useActionEnum = fields[1].get(packet);
this.action = EntityUseAction.valueOf(useActionEnum.toString());
}
public Entity getEntity() {
return entity;
}
public int getEntityId() {
return entityId;
}
public EntityUseAction getAction() {
return action;
}
private static Class<?> useEntityClass;
private static Class<?> entityClass;
private static Field[] fields = new Field[2];
static {
try {
useEntityClass = NMSUtils.getNMSClass("PacketPlayInUseEntity");
entityClass = NMSUtils.getNMSClass("Entity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
fields[0] = useEntityClass.getDeclaredField("a");
fields[1] = useEntityClass.getDeclaredField("action");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
for (Field f : fields) {
if (f != null) {
f.setAccessible(true);
}
}
}
}
@@ -1,7 +1,7 @@
package me.purplex.packetevents.utils;
package io.github.retrooper.packetevents.utils;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.ServerVersion;
public class BaseBlockUtils {
private static final ServerVersion version = PacketEvents.getServerVersion();
@@ -0,0 +1,16 @@
package io.github.retrooper.packetevents.utils;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.BlockIterator;
public class BlockFinder {
public static Block getBlocksInDirection(final Player player, final int blockDistance) {
final BlockIterator it = new BlockIterator(player, blockDistance);
Block cur = null;
while(it.hasNext()) {
cur = it.next();
}
return cur;
}
}
@@ -1,22 +1,22 @@
package me.purplex.packetevents.utils;
package io.github.retrooper.packetevents.utils;
import me.purplex.packetevents.enums.ServerVersion;
import net.minecraft.server.v1_7_R4.WorldServer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
public class NMSUtils {
private static final ServerVersion version = ServerVersion.getVersion();
private static final String nettyPrefix = version == ServerVersion.v_1_7_10 ? "net.minecraft.util.io.netty" : "io.netty";
private static final String nmsDir = ServerVersion.getNMSDirectory();
private static final String obcDir = ServerVersion.getOBCDirectory();
@@ -25,18 +25,24 @@ public class NMSUtils {
private static Method getServerMethod;
private static Field recentTPSField;
private static Class<?> worldServerClass;
private static Method getCraftWorldHandleMethod;
private static Method entityMethod;
private static Class<?> craftPlayerClass;
private static Class<?> entityPlayerClass;
private static Method getCraftPlayerHandle;
private static Field entityPlayerPingField;
static {
//CLASSES
try {
minecraftServerClass = getNMSClass("MinecraftServer");
worldServerClass = getNMSClass("WorldServer");
craftWorldsClass = getOBCClass("CraftWorld");
craftPlayerClass = getOBCClass("entity.CraftPlayer");
entityPlayerClass = getNMSClass("EntityPlayer");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
@@ -45,14 +51,15 @@ public class NMSUtils {
try {
getServerMethod = minecraftServerClass.getMethod("getServer");
getCraftWorldHandleMethod = craftWorldsClass.getMethod("getHandle");
// entityMethod = worldServerClass.getMethod(is_1_8() ? "a" : "getEntity");
getCraftPlayerHandle = craftPlayerClass.getMethod("getHandle");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
//FIELDS
try {
recentTPSField = minecraftServerClass.getField("recentTps");
entityPlayerPingField = entityPlayerClass.getField("ping");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
@@ -76,30 +83,44 @@ public class NMSUtils {
return Class.forName(obcDir + "." + name);
}
public static Object getEntityById(final int id) throws InvocationTargetException, IllegalAccessException {
//1.13.2 worlds field -> getWorlds()
//1.8->1.8.8, world.a(ID); rest is getEntity(ID);
final List<World> worlds = Bukkit.getWorlds();
for (World w : worlds) {
/* Object craftWorld = craftWorldsClass.cast(w);
public static Class<?> getNettyClass(String name) throws ClassNotFoundException {
return Class.forName(nettyPrefix + "." + name);
}
Object worldServer = getCraftWorldHandleMethod.invoke(craftWorld);
try {
return entityMethod.invoke(worldServer, id);
} catch (NullPointerException e) {
continue;
}*/
for(Entity e : w.getEntities()) {
if(e.getEntityId() == id) {
return e;
}
}
@Nullable
public static Entity getEntityById(final int id) {
return EntityFinderUtils.getEntityById(id);
}
@Nullable
public static Entity getEntityByIdWithWorld(final World world, final int id) {
return EntityFinderUtils.getEntityByIdWithWorld(world, id);
}
public static int getPlayerPing(final Player player) {
final Object craftPlayer = craftPlayerClass.cast(player);
Object entityPlayer = null;
try {
entityPlayer = getCraftPlayerHandle.invoke(craftPlayer);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
try {
return entityPlayerPingField.getInt(entityPlayer);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return -1;
}
public static boolean is_1_8() {
return version.isHigherThan(ServerVersion.v_1_7_10)
&& version.isLowerThan(ServerVersion.v_1_9);
}
public static String getServerConnectionFieldName() {
return "p";
}
}
@@ -1,7 +1,9 @@
package me.purplex.packetevents.utils;
package io.github.retrooper.packetevents.utils;
import javax.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
public class TPSUtils {
@Nullable
public static double[] getRecentTPS() {
try {
return NMSUtils.recentTPS();
@@ -0,0 +1,94 @@
package io.github.retrooper.packetevents.utils.nms_entityfinder;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class EntityFinderUtils {
@Nullable
private static ServerVersion version = PacketEvents.getServerVersion();
public static Entity getEntityById(final int id) {
for (final World world : Bukkit.getWorlds()) {
final Entity entity = getEntityByIdWithWorld(world, id);
if (entity != null) {
return entity;
}
}
return null;
}
@Nullable
public static Entity getEntityByIdWithWorld(final World world, final int id) {
Object craftWorld = craftWorldClass.cast(world);
Object worldServer = null;
try {
worldServer = craftWorldGetHandle.invoke(craftWorld);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Object nmsEntity = null;
try {
nmsEntity = getEntityByIdMethod.invoke(worldServer, id);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
try {
return (Entity) getBukkitEntity.invoke(nmsEntity);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
private static Class<?> worldServerClass;
private static Class<?> craftWorldClass;
private static Class<?> entityClass;
private static Method getEntityByIdMethod;
private static Method craftWorldGetHandle;
private static Method getBukkitEntity;
static {
try {
worldServerClass = NMSUtils.getNMSClass("WorldServer");
craftWorldClass = NMSUtils.getOBCClass("CraftWorld");
entityClass = NMSUtils.getNMSClass("Entity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
getEntityByIdMethod = worldServerClass.getMethod(getEntityByNameMethodName(), int.class);
craftWorldGetHandle = craftWorldClass.getMethod("getHandle");
getBukkitEntity = entityClass.getMethod("getBukkitEntity");
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public static String getEntityByNameMethodName() {
if (version.isHigherThan(ServerVersion.v_1_7_10) && version.isLowerThan(ServerVersion.v_1_9)) {
return "a";
}
return "getEntity";
}
}
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector2d {
public double x, y;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector2f {
public float x, y;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector2i {
public int x, y;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector3d {
public double x, y, z;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector3f {
public float x, y, z;
@@ -1,4 +1,4 @@
package me.purplex.packetevents.utils.math;
package io.github.retrooper.packetevents.utils.vector;
public class Vector3i {
public int x, y, z;
@@ -1,9 +0,0 @@
package me.purplex.packetevents.enums;
public enum Direction {
DOWN, UP, NORTH, SOUTH, WEST, EAST;
public static Direction get(final byte i) {
return values()[i];
}
}
@@ -1,5 +0,0 @@
package me.purplex.packetevents.event.impl;
//unfinished
public class ServerReloadEvent {
}
@@ -1,4 +0,0 @@
package me.purplex.packetevents.event.listener;
public interface PacketListener {
}
@@ -1,68 +0,0 @@
package me.purplex.packetevents.event.manager;
import me.purplex.packetevents.event.PacketEvent;
import me.purplex.packetevents.event.handler.PacketHandler;
import me.purplex.packetevents.event.listener.PacketListener;
import java.lang.reflect.*;
public class EventManager implements PacketEventManager {
@Override
public void callEvent(final PacketEvent e) {
for (final PacketListener listener : this.packetListeners) {
boolean calledOnPacket = false;
//Annotated methods
final Method[] methods = listener.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
final Method m = methods[i];
if (m.isAnnotationPresent(PacketHandler.class)) {
if (!calledOnPacket && m.getParameterTypes()[0].equals(PacketEvent.class)) {
try {
m.invoke(listener, e);
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
calledOnPacket = true;
} else if (m.getParameterTypes()[0].getSimpleName().equals(e.getClass().getSimpleName())) {
try {
m.invoke(listener, e);
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InvocationTargetException ex) {
ex.printStackTrace();
}
}
}
}
}
}
@Override
public void registerListener(final PacketListener e) {
this.packetListeners.add(e);
}
@Override
public boolean unregisterListener(final PacketListener e) {
return this.packetListeners.remove(e);
}
@Override
public boolean unregisterAllListeners() {
if (this.packetListeners.size() != 0) {
this.packetListeners.clear();
return true;
}
return false;
}
/*@Override
public void sendPacket(Player player, WrappedPacket packet) {
}*/
}
@@ -1,20 +0,0 @@
package me.purplex.packetevents.event.manager;
import me.purplex.packetevents.event.PacketEvent;
import me.purplex.packetevents.event.listener.PacketListener;
import java.util.ArrayList;
import java.util.LinkedList;
public interface PacketEventManager {
public ArrayList<PacketListener> packetListeners = new ArrayList<>();
public void callEvent(PacketEvent e);
public void registerListener(PacketListener e);
public boolean unregisterListener(PacketListener e);
public boolean unregisterAllListeners();
//public void sendPacket(Player player, WrappedPacket packet);
}
@@ -1,82 +0,0 @@
package me.purplex.packetevents.packet;
public abstract class Packet {
public static class Client {
private static final String CLIENT = "PacketPlayIn";
public static final String KEEP_ALIVE = CLIENT + "KeepAlive";
@Deprecated
public static final String FLYING = CLIENT + "Flying";
public static final String POSITION = CLIENT + "Position";
public static final String POSITION_LOOK = CLIENT + "PositionLook";
public static final String LOOK = CLIENT + "Look";
@Deprecated
public static final String LEGACY_POSITION = FLYING + "$" + CLIENT + "Position";
@Deprecated
public static final String LEGACY_POSITION_LOOK = FLYING + "$" + CLIENT + "PositionLook";
@Deprecated
public static final String LEGACY_LOOK = FLYING + "$" + CLIENT + "Look";
public static final String TRANSACTION = CLIENT + "Transaction";
public static final String BLOCK_DIG = CLIENT + "BlockDig";
public static final String ENTITY_ACTION = CLIENT + "EntityAction";
public static final String USE_ENTITY = CLIENT + "UseEntity";
public static final String WINDOW_CLICK = CLIENT + "WindowClick";
public static final String STEER_VEHICLE = CLIENT + "SteerVehicle";
public static final String CUSTOM_PAYLOAD = CLIENT + "CustomPayload";
public static final String ARM_ANIMATION = CLIENT + "ArmAnimation";
public static final String BLOCK_PLACE_1_9 = CLIENT + "BlockPlace1_9";
public static final String BLOCK_PLACE = CLIENT + "BlockPlace";
public static final String ABILITIES = CLIENT + "Abilities";
public static final String HELD_ITEM_SLOT = CLIENT + "HeldItemSlot";
public static final String CLOSE_WINDOW = CLIENT + "CloseWindow";
public static final String TAB_COMPLETE = CLIENT + "TabComplete";
public static final String CHAT = CLIENT + "Chat";
public static final String CREATIVE_SLOT = CLIENT + "SetCreativeSlot";
public static final String CLIENT_COMMAND = CLIENT + "ClientCommand";
}
public static class Server {
private static final String SERVER = "PacketPlayOut";
public static final String ANIMATION = SERVER + "Animation";
public static final String KEEP_ALIVE = SERVER + "KeepAlive";
public static final String CHAT = SERVER + "Chat";
public static final String POSITION = SERVER + "Position";
public static final String TRANSACTION = SERVER + "Transaction";
public static final String NAMED_ENTITY_SPAWN = SERVER + "NamedEntitySpawn";
public static final String SPAWN_ENTITY_LIVING = SERVER + "SpawnEntityLiving";
public static final String SPAWN_ENTITY = SERVER + "SpawnEntity";
public static final String CUSTOM_PAYLOAD = SERVER + "CustomPayload";
public static final String ABILITIES = SERVER + "Abilities";
public static final String ENTITY_METADATA = SERVER + "EntityMetadata";
public static final String ENTITY_VELOCITY = SERVER + "EntityVelocity";
public static final String ENTITY_DESTROY = SERVER + "EntityDestroy";
public static final String ENTITY_HEAD_ROTATION = SERVER + "EntityHeadRotation";
public static final String BLOCK_CHANGE = SERVER + "BlockChange";
public static final String CLOSE_WINDOW = SERVER + "CloseWindow";
public static final String HELD_ITEM = SERVER + "HeldItemSlot";
public static final String TAB_COMPLETE = SERVER + "TabComplete";
public static final String RESPAWN = SERVER + "Respawn";
public static final String WORLD_PARTICLE = SERVER + "WorldParticles";
public static final String COMMANDS = SERVER + "Commands";
public static final String OPEN_WINDOW = SERVER + "OpenWindow";
public static final String LOGIN = SERVER + "Login";
public static final String SERVER_DIFFICULTY = SERVER + "ServerDifficulty";
}
public static class Login {
public static final String HANDSHAKE = "PacketHandshakingInSetProtocol";
public static final String PING = "PacketStatusInPing";
public static final String START = "PacketStatusInStart";
public static final String SUCCESS = "PacketLoginOutSuccess";
}
public static boolean isInstanceOf(String fatherPacket, String childPacket) {
if (fatherPacket.equals(Client.FLYING) && childPacket.equals(Client.POSITION) || childPacket.equals(Client.POSITION_LOOK)) {
return true;
}
return fatherPacket.equals(childPacket);
}
}
@@ -1,29 +0,0 @@
package me.purplex.packetevents.packetwrappers.api;
import me.purplex.packetevents.enums.ServerVersion;
public class WrappedPacket {
protected Object packet;
protected static ServerVersion version = ServerVersion.getVersion();
private static final String err = "Your Version is unsupported, " +
"please contact purplex(creator) " +
"through his discord server (http://discord.gg/2uZY5A4) " +
"and tell him what version your server is running on! " +
"Make sure you are using spigot!";
public WrappedPacket(Object packet) {
this.packet = packet;
try {
setup();
} catch (Exception e) {
e.printStackTrace();
}
}
protected void setup() throws Exception {
}
protected void throwUnsupportedVersion() {
throw new IllegalStateException(err);
}
}
@@ -1,12 +0,0 @@
package me.purplex.packetevents.packetwrappers.api.sendable;
import org.bukkit.entity.Player;
/**
* Unfinished
*/
public class WrappedServerPacket {
public WrappedServerPacket(Player target) {
}
}
@@ -1,15 +0,0 @@
package me.purplex.packetevents.packetwrappers.api.version;
import me.purplex.packetevents.PacketEvents;
import me.purplex.packetevents.enums.ServerVersion;
public abstract class WrappedVersionPacket {
protected final Object packet;
protected static ServerVersion version = PacketEvents.getServerVersion();
public WrappedVersionPacket(Object packet) {
this.packet = packet;
setup();
}
protected abstract void setup();
}
@@ -1,105 +0,0 @@
package me.purplex.packetevents.packetwrappers.in.use_entity;
import me.purplex.packetevents.enums.EntityUseAction;
import me.purplex.packetevents.enums.Hand;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
import me.purplex.packetevents.utils.NMSUtils;
import me.purplex.packetevents.utils.math.Vector3d;
import org.bukkit.entity.Entity;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
public class WrappedPacketInUseEntity extends WrappedPacket {
private int entityId;
private Entity entity;
private EntityUseAction action;
private Hand hand;
public WrappedPacketInUseEntity(Object packet) {
super(packet);
}
@Override
protected void setup() throws IllegalAccessException, InvocationTargetException {
entityId = fields[0].getInt(packet);
// Object nmsEntity = NMSUtils.getEntityById(entityId);
//this.entity = (Entity) getBukkitEntityFromNMS.invoke(nmsEntity);
this.entity = (Entity) NMSUtils.getEntityById(entityId);
Object useActionEnum = fields[1].get(packet);
action = EntityUseAction.valueOf(useActionEnum.toString());
Object handObj;
if (fields[2] == null) {
handObj = Hand.MAIN_HAND.name();
} else {
handObj = fields[2].get(packet);
}
hand = Hand.valueOf(handObj.toString());
}
/**
* Getting entity will be optimized
* @return
*/
@Deprecated
public Entity getEntity() {
return entity;
}
public int getEntityId() {
return entityId;
}
public EntityUseAction getAction() {
return action;
}
public Hand getHand() {
return hand;
}
private static Class<?> useEntityClass;
private static Class<?> entityClass;
private static Field[] fields = new Field[3];
static {
//CLASSES
try {
useEntityClass = NMSUtils.getNMSClass("PacketPlayInUseEntity");
entityClass = NMSUtils.getNMSClass("Entity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
//FIELDS
try {
fields[0] = useEntityClass.getDeclaredField("a");
fields[1] = useEntityClass.getDeclaredField("action");
if (version.isHigherThan(ServerVersion.v_1_8_8)) {
fields[2] = useEntityClass.getDeclaredField("d");
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
for (Field f : fields) {
if (f != null) {
if (!f.isAccessible()) {
f.setAccessible(true);
}
}
}
}
}
@@ -1,98 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.enums.ServerVersion;
import me.purplex.packetevents.packetwrappers.api.WrappedPacket;
public class WrappedPacketLoginHandshake extends WrappedPacket {
public String hostname;
public int port;
public int protocolVersion;
public WrappedPacketLoginHandshake(Object packet) {
super(packet);
}
@Override
protected void setup() {
if(version == ServerVersion.v_1_7_10) {
WrappedPacketLoginHandshake_1_7_10 p = new WrappedPacketLoginHandshake_1_7_10(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_8) {
WrappedPacketLoginHandshake_1_8 p = new WrappedPacketLoginHandshake_1_8(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_8_3) {
WrappedPacketLoginHandshake_1_8_3 p = new WrappedPacketLoginHandshake_1_8_3(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_8_8) {
WrappedPacketLoginHandshake_1_8_8 p = new WrappedPacketLoginHandshake_1_8_8(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_9) {
WrappedPacketLoginHandshake_1_9 p = new WrappedPacketLoginHandshake_1_9(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version==ServerVersion.v_1_9_4) {
WrappedPacketLoginHandshake_1_9_4 p = new WrappedPacketLoginHandshake_1_9_4(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version==ServerVersion.v_1_10) {
WrappedPacketLoginHandshake_1_10 p = new WrappedPacketLoginHandshake_1_10(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_11) {
WrappedPacketLoginHandshake_1_11 p = new WrappedPacketLoginHandshake_1_11(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_12) {
WrappedPacketLoginHandshake_1_12 p = new WrappedPacketLoginHandshake_1_12(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_13) {
WrappedPacketLoginHandshake_1_13 p = new WrappedPacketLoginHandshake_1_13(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_13_2) {
WrappedPacketLoginHandshake_1_13_2 p = new WrappedPacketLoginHandshake_1_13_2(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_14) {
WrappedPacketLoginHandshake_1_14 p = new WrappedPacketLoginHandshake_1_14(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else if(version == ServerVersion.v_1_15) {
WrappedPacketLoginHandshake_1_15 p = new WrappedPacketLoginHandshake_1_15(packet);
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.protocolVersion;
}
else {
throwUnsupportedVersion();
}
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_10_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_10 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_10(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_11_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_11 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_11(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_12_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_12 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_12(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_13_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_13 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_13(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.c();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_13_R2.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_13_2 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_13_2(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.c();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_14_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_14 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_14(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.c();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_15_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_15 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
protected WrappedPacketLoginHandshake_1_15(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.c();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_7_R4.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_7_10 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_7_10(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.b;
this.port = p.c;
this.protocolVersion = p.d();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_8_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_8 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_8(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.b;
this.port = p.c;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_8_R2.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_8_3 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_8_3(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.b;
this.port = p.c;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_8_R3.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_8_8 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_8_8(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_9_R1.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_9 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_9(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,21 +0,0 @@
package me.purplex.packetevents.packetwrappers.login.handshake;
import me.purplex.packetevents.packetwrappers.api.version.WrappedVersionPacket;
import net.minecraft.server.v1_9_R2.PacketHandshakingInSetProtocol;
class WrappedPacketLoginHandshake_1_9_4 extends WrappedVersionPacket {
public String hostname;
public int port;
public int protocolVersion;
WrappedPacketLoginHandshake_1_9_4(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketHandshakingInSetProtocol p = (PacketHandshakingInSetProtocol)packet;
this.hostname = p.hostname;
this.port = p.port;
this.protocolVersion = p.b();
}
}
@@ -1,34 +0,0 @@
package me.purplex.packetevents.utils.playerprotocolversion;
import org.bukkit.entity.Player;
import java.util.*;
public class PlayerVersionManager {
private static HashMap<UUID, Integer> protocolVersion = new HashMap<UUID, Integer>();
public static int getPlayerProtocolVersion(final Player player) {
return protocolVersion.get(player.getUniqueId());
}
public static void setPlayerProtocolVersion(final Player player, final int version) {
protocolVersion.put(player.getUniqueId(), version);
}
public static void clearPlayer(final Player player) {
protocolVersion.remove(player.getUniqueId());
}
public static int getPlayerProtocolVersion(final UUID uuid) {
return protocolVersion.get(uuid);
}
public static void setPlayerProtocolVersion(final UUID uuid, final int version) {
protocolVersion.put(uuid, version);
}
public static void clearPlayer(final UUID uuid) {
protocolVersion.remove(uuid);
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
name: packetevents
version: 1.2.4
main: me.purplex.packetevents.example.MainExample
author: purplex
version: 1.2.6
main: io.github.retrooper.packetevents.example.MainExample
author: retrooper