Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa70848c0e | ||
|
|
0274014768 | ||
|
|
44ebf50956 | ||
|
|
009fe731a3 |
No files matched your search
Generated
-166
@@ -1,166 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ArtifactsWorkspaceSettings">
|
||||
<artifacts-to-build>
|
||||
<artifact name="PacketEvents:jar" />
|
||||
</artifacts-to-build>
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="56671312-5d48-415e-89e3-6da52f639a93" name="Default Changelist" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="Enum" />
|
||||
<option value="Interface" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="MavenImportPreferences">
|
||||
<option name="importingSettings">
|
||||
<MavenImportingSettings>
|
||||
<option name="downloadDocsAutomatically" value="true" />
|
||||
<option name="downloadSourcesAutomatically" value="true" />
|
||||
</MavenImportingSettings>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectId" id="1aLTtv1mzTFDpQDYHmrwgIboWkQ" />
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||
<property name="project.structure.last.edited" value="Modules" />
|
||||
<property name="project.structure.proportion" value="0.15" />
|
||||
<property name="project.structure.side.proportion" value="0.2" />
|
||||
<property name="run.code.analysis.last.selected.profile" value="pProject Default" />
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="JetRunConfigurationType">
|
||||
<module name="JSLoader" />
|
||||
<option name="VM_PARAMETERS" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="PASS_PARENT_ENVS" value="true" />
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="WORKING_DIRECTORY" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="KotlinStandaloneScriptRunConfigurationType">
|
||||
<module name="JSLoader" />
|
||||
<option name="filePath" />
|
||||
<option name="vmParameters" />
|
||||
<option name="alternativeJrePath" />
|
||||
<option name="programParameters" />
|
||||
<option name="passParentEnvs" value="true" />
|
||||
<option name="workingDirectory" />
|
||||
<option name="isAlternativeJrePathEnabled" value="false" />
|
||||
<option name="VM_PARAMETERS" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="PASS_PARENT_ENVS" value="true" />
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="WORKING_DIRECTORY" />
|
||||
<option name="filePath" />
|
||||
<option name="vmParameters" />
|
||||
<option name="alternativeJrePath" />
|
||||
<option name="programParameters" />
|
||||
<option name="passParentEnvs" value="true" />
|
||||
<option name="workingDirectory" />
|
||||
<option name="isAlternativeJrePathEnabled" value="false" />
|
||||
<option name="VM_PARAMETERS" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||
<option name="ALTERNATIVE_JRE_PATH" />
|
||||
<option name="PASS_PARENT_ENVS" value="true" />
|
||||
<option name="MAIN_CLASS_NAME" />
|
||||
<option name="WORKING_DIRECTORY" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="JSLoader build" type="MavenRunConfiguration" factoryName="Maven">
|
||||
<MavenSettings>
|
||||
<option name="myGeneralSettings" />
|
||||
<option name="myRunnerSettings" />
|
||||
<option name="myRunnerParameters">
|
||||
<MavenRunnerParameters>
|
||||
<option name="profiles">
|
||||
<set />
|
||||
</option>
|
||||
<option name="goals">
|
||||
<list>
|
||||
<option value="clean" />
|
||||
<option value="package" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="pomFileName" />
|
||||
<option name="profilesMap">
|
||||
<map />
|
||||
</option>
|
||||
<option name="resolveToWorkspace" value="false" />
|
||||
<option name="workingDirPath" value="$PROJECT_DIR$" />
|
||||
</MavenRunnerParameters>
|
||||
</option>
|
||||
</MavenSettings>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="56671312-5d48-415e-89e3-6da52f639a93" name="Default Changelist" comment="" />
|
||||
<created>1586514092402</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1586514092402</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="WindowStateProjectService">
|
||||
<state x="280" y="4" key="#Project_Structure" timestamp="1586868472617">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="280" y="4" key="#Project_Structure/0.0.1600.860@0.0.1600.860" timestamp="1586868472617" />
|
||||
<state x="558" y="300" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1586868346065">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="558" y="300" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1600.860@0.0.1600.860" timestamp="1586868346065" />
|
||||
<state x="580" y="171" key="FileChooserDialogImpl" timestamp="1586868828893">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="580" y="171" key="FileChooserDialogImpl/0.0.1600.860@0.0.1600.860" timestamp="1586868828893" />
|
||||
<state x="280" y="4" key="SettingsEditor" timestamp="1586515368359">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="280" y="4" key="SettingsEditor/0.0.1600.860@0.0.1600.860" timestamp="1586515368359" />
|
||||
<state x="182" y="91" key="new project wizard" timestamp="1587127371863">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="182" y="91" key="new project wizard/0.0.1600.860@0.0.1600.860" timestamp="1587127371863" />
|
||||
<state x="456" y="195" key="run.anything.popup" timestamp="1586766899144">
|
||||
<screen x="0" y="0" width="1600" height="860" />
|
||||
</state>
|
||||
<state x="456" y="195" key="run.anything.popup/0.0.1600.860@0.0.1600.860" timestamp="1586766899144" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.retrooper</groupId>
|
||||
<artifactId>packetevents</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PacketEvents</name>
|
||||
@@ -54,10 +54,6 @@
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
@@ -75,7 +71,6 @@
|
||||
<version>1.5.21</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
|
||||
@@ -2,7 +2,10 @@ package me.purplex.packetevents;
|
||||
|
||||
import com.comphenix.tinyprotocol.*;
|
||||
import io.netty.channel.Channel;
|
||||
import me.purplex.packetevents.events.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.events.packetevent.PacketSendEvent;
|
||||
import me.purplex.packetevents.events.packetevent.ServerTickEvent;
|
||||
import me.purplex.packetevents.events.packetevent.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.example.TestExample;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.*;
|
||||
@@ -22,7 +25,11 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if(p == null) return super.onPacketInAsync(null, channel, packet);
|
||||
if(channel == null) return super.onPacketInAsync(p, null, packet);
|
||||
String packetName = packet.getClass().getSimpleName();
|
||||
PacketEvents.getPacketManager().callPacketReceiveEvent(new PacketReceiveEvent(p, packetName, packet));
|
||||
PacketReceiveEvent e = new PacketReceiveEvent(p, packetName, packet);
|
||||
PacketEvents.getPacketManager().callPacketReceiveEvent(e);
|
||||
if(e.isCancelled()) {
|
||||
return super.onPacketInAsync(null, null, null);
|
||||
}
|
||||
return super.onPacketInAsync(p, channel, packet);
|
||||
}
|
||||
|
||||
@@ -32,11 +39,23 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if(p == null) return super.onPacketInAsync(null, channel, packet);
|
||||
if(channel == null) return super.onPacketInAsync(p, null, packet);
|
||||
String packetName = packet.getClass().getSimpleName();
|
||||
PacketEvents.getPacketManager().callPacketReceiveEvent(new PacketReceiveEvent(p, packetName, packet));
|
||||
PacketSendEvent e = new PacketSendEvent(p, packetName, packet);
|
||||
PacketEvents.getPacketManager().callPacketSendEvent(e);
|
||||
if(e.isCancelled()) {
|
||||
return super.onPacketOutAsync(null, null, null);
|
||||
}
|
||||
return super.onPacketOutAsync(p, channel, packet);
|
||||
}
|
||||
};
|
||||
|
||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long now = System.currentTimeMillis();
|
||||
PacketEvents.getPacketManager().callServerTickEvent(new ServerTickEvent(now));
|
||||
}
|
||||
}, 0L, 1L);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.purplex.packetevents;
|
||||
|
||||
import me.purplex.packetevents.events.PacketManager;
|
||||
import me.purplex.packetevents.events.manager.PacketManager;
|
||||
|
||||
public class PacketEvents {
|
||||
private static PacketManager packetManager;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.purplex.packetevents.enums;
|
||||
|
||||
public enum EntityUseAction {
|
||||
INTERACT, INTERACT_AT, ATTACK, INVALID, WRONG_PACKET;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.purplex.packetevents.enums;
|
||||
|
||||
public enum PlayerAction {
|
||||
START_SNEAKING,
|
||||
|
||||
STOP_SNEAKING,
|
||||
|
||||
STOP_SLEEPING,
|
||||
|
||||
START_SPRINTING,
|
||||
|
||||
STOP_SPRINTING,
|
||||
|
||||
START_RIDING_JUMP,
|
||||
|
||||
STOP_RIDING_JUMP,
|
||||
|
||||
OPEN_INVENTORY,
|
||||
|
||||
START_FALL_FLYING, WRONG_PACKET;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package me.purplex.packetevents.enums;
|
||||
|
||||
public enum PlayerDigType {
|
||||
|
||||
START_DESTROY_BLOCK,
|
||||
|
||||
ABORT_DESTROY_BLOCK,
|
||||
|
||||
STOP_DESTROY_BLOCK,
|
||||
|
||||
DROP_ALL_ITEMS,
|
||||
|
||||
DROP_ITEM,
|
||||
|
||||
RELEASE_USE_ITEM,
|
||||
|
||||
SWAP_HELD_ITEMS,
|
||||
|
||||
WRONG_PACKET;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.purplex.packetevents.events;
|
||||
|
||||
public interface PacketListener {
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package me.purplex.packetevents.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketReceiveEvent extends PacketEvent {
|
||||
|
||||
private Player player;
|
||||
private String name;
|
||||
private Object packet;
|
||||
private long timestamp;
|
||||
public PacketReceiveEvent(Player player, String packetName, Object packet) {
|
||||
this.player = player;
|
||||
this.name = packetName;
|
||||
this.packet = packet;
|
||||
this.timestamp = (System.nanoTime() / 1000000);
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public String getPacketName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Object getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package me.purplex.packetevents.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketSendEvent extends PacketEvent {
|
||||
|
||||
private Player player;
|
||||
private String name;
|
||||
private Object packet;
|
||||
private long timestamp;
|
||||
public PacketSendEvent(Player player, String packetName, Object packet) {
|
||||
this.player = player;
|
||||
this.name = packetName;
|
||||
this.packet = packet;
|
||||
this.timestamp = (System.nanoTime() / 1000000);
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public String getPacketName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Object getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -1,4 +1,9 @@
|
||||
package me.purplex.packetevents.events;
|
||||
package me.purplex.packetevents.events.eventmanager;
|
||||
|
||||
import me.purplex.packetevents.events.packetevent.ServerTickEvent;
|
||||
import me.purplex.packetevents.events.listener.PacketListener;
|
||||
import me.purplex.packetevents.events.packetevent.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.events.packetevent.PacketSendEvent;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -10,4 +15,6 @@ public interface PacketEventManager {
|
||||
|
||||
public void registerPacketListener(PacketListener e);
|
||||
|
||||
public void callServerTickEvent(ServerTickEvent e);
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.purplex.packetevents.events;
|
||||
package me.purplex.packetevents.events.handler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.purplex.packetevents.events.listener;
|
||||
|
||||
public interface PacketListener {
|
||||
}
|
||||
+26
-1
@@ -1,4 +1,11 @@
|
||||
package me.purplex.packetevents.events;
|
||||
package me.purplex.packetevents.events.manager;
|
||||
|
||||
import me.purplex.packetevents.events.packetevent.ServerTickEvent;
|
||||
import me.purplex.packetevents.events.eventmanager.PacketEventManager;
|
||||
import me.purplex.packetevents.events.handler.PacketHandler;
|
||||
import me.purplex.packetevents.events.listener.PacketListener;
|
||||
import me.purplex.packetevents.events.packetevent.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.events.packetevent.PacketSendEvent;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -44,4 +51,22 @@ public class PacketManager implements PacketEventManager {
|
||||
public void registerPacketListener(PacketListener e) {
|
||||
this.packetListeners.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callServerTickEvent(ServerTickEvent e) {
|
||||
for (PacketListener listener : this.packetListeners) {
|
||||
Method[] methods = listener.getClass().getMethods();
|
||||
for (Method m : methods) {
|
||||
if (m.isAnnotationPresent(PacketHandler.class)) {
|
||||
if (m.getParameterTypes()[0].getSimpleName().equals(e.getClass().getSimpleName())) {
|
||||
try {
|
||||
m.invoke(listener, e);
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package me.purplex.packetevents.events.packetevent;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.Reflection.*;
|
||||
import me.purplex.packetevents.enums.EntityUseAction;
|
||||
import me.purplex.packetevents.enums.PlayerAction;
|
||||
import me.purplex.packetevents.enums.PlayerDigType;
|
||||
import me.purplex.packetevents.events.PacketEvent;
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
public class PacketReceiveEvent extends PacketEvent {
|
||||
|
||||
private Player player;
|
||||
private String name;
|
||||
private Object packet;
|
||||
private long timestamp;
|
||||
private boolean cancelled;
|
||||
|
||||
public PacketReceiveEvent(Player player, String packetName, Object packet) {
|
||||
this.player = player;
|
||||
this.name = packetName;
|
||||
this.packet = packet;
|
||||
this.timestamp = (System.nanoTime() / 1000000);
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public String getPacketName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Object getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of dig
|
||||
* PacketPlayInBlockDig
|
||||
* @return
|
||||
*/
|
||||
public PlayerDigType getPlayerDigType() {
|
||||
String c = String.valueOf(Reflection.getMethod(packet.getClass(), "c").invoke(packet));
|
||||
PlayerDigType type;
|
||||
try {
|
||||
type = PlayerDigType.valueOf(c);
|
||||
} catch (IllegalArgumentException e) {
|
||||
type = PlayerDigType.WRONG_PACKET;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity interact action
|
||||
* PacketPlayInUseEntity
|
||||
* @return
|
||||
*/
|
||||
public EntityUseAction getEntityUseAction() {
|
||||
Object action = null;
|
||||
try {
|
||||
action = FieldUtils.readDeclaredField(packet, "action", true);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (EntityUseAction a : EntityUseAction.values()) {
|
||||
if (a.toString().equalsIgnoreCase(action.toString())) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return EntityUseAction.WRONG_PACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PlayerAction
|
||||
* PacketPlayInEntityAction
|
||||
* @return
|
||||
*/
|
||||
public PlayerAction getPlayerAction() {
|
||||
Object animation = null;
|
||||
try {
|
||||
animation = FieldUtils.readDeclaredField(packet, "animation", true);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (PlayerAction a : PlayerAction.values()) {
|
||||
if (a.toString().equalsIgnoreCase(animation.toString())) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return PlayerAction.WRONG_PACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity you interacted with
|
||||
* PacketPlayInUseEntity
|
||||
* @return
|
||||
*/
|
||||
public Entity getInteractedEntity() {
|
||||
try {
|
||||
FieldAccessor<Integer> field = Reflection.getField(packet.getClass(), int.class, 0);
|
||||
int id = field.get(packet);
|
||||
for (Entity e : player.getWorld().getEntities()) {
|
||||
if (e.getEntityId() == id) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
for(World w : Bukkit.getWorlds()) {
|
||||
for(Entity e : w.getEntities()) {
|
||||
if(e.getEntityId() == id) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string message
|
||||
* PacketPlayInChat
|
||||
* @return
|
||||
*/
|
||||
public String getChatPacketMessage() {
|
||||
FieldAccessor<String> field = Reflection.getField(packet.getClass(), String.class, 0);
|
||||
String message = field.get(packet);
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package me.purplex.packetevents.events.packetevent;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.Reflection.*;
|
||||
import me.purplex.packetevents.events.PacketEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketSendEvent extends PacketEvent {
|
||||
|
||||
private Player player;
|
||||
private String name;
|
||||
private Object packet;
|
||||
private long timestamp;
|
||||
private boolean cancelled;
|
||||
public PacketSendEvent(Player player, String packetName, Object packet) {
|
||||
this.player = player;
|
||||
this.name = packetName;
|
||||
this.packet = packet;
|
||||
this.timestamp = (System.nanoTime() / 1000000);
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public String getPacketName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Object getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Velocity entity
|
||||
* PacketPlayOutEntityVelocity
|
||||
* @return
|
||||
*/
|
||||
public Entity getVelocityEntity() {
|
||||
//WorldServer s;
|
||||
FieldAccessor<Integer> field = Reflection.getField(packet.getClass(), int.class, 0);
|
||||
int id = field.get(packet);
|
||||
for(World w : Bukkit.getWorlds()) {
|
||||
for(Entity e : w.getEntities()) {
|
||||
if(e.getEntityId() == id) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get X velocity
|
||||
* PacketPlayOutEntityVelocity
|
||||
* @return x
|
||||
*/
|
||||
public double getVelocityX() {
|
||||
FieldAccessor<Integer> field = Reflection.getField(packet.getClass(), int.class, 1);
|
||||
int i = field.get(packet);
|
||||
double x = i / 8000.0;
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Y velocity
|
||||
* PacketPlayOutEntityVelocity
|
||||
* @return y
|
||||
*/
|
||||
public double getVelocityY() {
|
||||
FieldAccessor<Integer> field = Reflection.getField(packet.getClass(), int.class, 2);
|
||||
int i = field.get(packet);
|
||||
double y = i / 8000.0;
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Z velocity
|
||||
* PacketPlayOutEntityVelocity
|
||||
* @return z
|
||||
*/
|
||||
public double getVelocityZ() {
|
||||
FieldAccessor<Integer> field = Reflection.getField(packet.getClass(), int.class, 3);
|
||||
int i = field.get(packet);
|
||||
double z = i / 8000.0;
|
||||
return z;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.purplex.packetevents.events.packetevent;
|
||||
|
||||
import me.purplex.packetevents.events.PacketEvent;
|
||||
|
||||
|
||||
public class ServerTickEvent extends PacketEvent {
|
||||
|
||||
private long timestamp;
|
||||
public ServerTickEvent(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +1,64 @@
|
||||
package me.purplex.packetevents.example;
|
||||
|
||||
import me.purplex.packetevents.events.PacketHandler;
|
||||
import me.purplex.packetevents.events.PacketListener;
|
||||
import me.purplex.packetevents.events.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.events.PacketSendEvent;
|
||||
import me.purplex.packetevents.enums.EntityUseAction;
|
||||
import me.purplex.packetevents.enums.PlayerAction;
|
||||
import me.purplex.packetevents.enums.PlayerDigType;
|
||||
import me.purplex.packetevents.events.packetevent.ServerTickEvent;
|
||||
import me.purplex.packetevents.events.handler.PacketHandler;
|
||||
import me.purplex.packetevents.events.listener.PacketListener;
|
||||
import me.purplex.packetevents.events.packetevent.PacketReceiveEvent;
|
||||
import me.purplex.packetevents.events.packetevent.PacketSendEvent;
|
||||
import me.purplex.packetevents.packets.Packet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class TestExample implements PacketListener {
|
||||
/**
|
||||
* How to register a packet listener?
|
||||
*
|
||||
* PacketEvents.getPacketManager().registerPacketListener(new TestExample());
|
||||
* <p>
|
||||
* PacketEvents.getPacketManager().registerPacketListener(new TestExample());
|
||||
*/
|
||||
|
||||
private int tick;
|
||||
|
||||
|
||||
@PacketHandler
|
||||
public void onPacketReceive(PacketReceiveEvent e) {
|
||||
//ONLY CLIENT PACKETS ALLOWED HERE!
|
||||
if(e.getPacketName().equals(Packet.Client.USE_ENTITY)) {
|
||||
e.getPlayer().sendMessage("You have attacked an entity!");
|
||||
}
|
||||
else if(e.getPacketName().equals(Packet.Client.ARM_ANIMATION)) {
|
||||
if (e.getPacketName().equals(Packet.Client.USE_ENTITY)) {
|
||||
Entity entity = e.getInteractedEntity();
|
||||
EntityUseAction entityUseAction = e.getEntityUseAction();
|
||||
e.getPlayer().sendMessage("Dist: " + entity.getLocation().distanceSquared(e.getPlayer().getLocation()));
|
||||
} else if (e.getPacketName().equals(Packet.Client.ARM_ANIMATION)) {
|
||||
e.getPlayer().sendMessage("You swung your arm.");
|
||||
}
|
||||
else if(e.getPacketName().equals(Packet.Client.POSITION)) {
|
||||
e.getPlayer().sendMessage("You updated your position!");
|
||||
} else if (e.getPacketName().equals(Packet.Client.BLOCK_DIG)) {
|
||||
PlayerDigType type = e.getPlayerDigType();
|
||||
} else if (e.getPacketName().equals(Packet.Client.CHAT)) {
|
||||
String message = e.getChatPacketMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@PacketHandler
|
||||
public void onPacketSend(PacketSendEvent e) {
|
||||
//ONLY SERVER PACKETS ALLOWED HERE!
|
||||
if(e.getPacketName().equals(Packet.Server.ENTITY_VELOCITY)) {
|
||||
e.getPlayer().sendMessage("You took velocity!");
|
||||
if (e.getPacketName().equals(Packet.Server.ENTITY_VELOCITY)) {
|
||||
System.out.println("preee");
|
||||
Entity entity = e.getVelocityEntity();
|
||||
System.out.println(entity.getName());
|
||||
System.out.println(e.getVelocityX());
|
||||
}
|
||||
}
|
||||
|
||||
@PacketHandler
|
||||
public void onServerTick(ServerTickEvent e) {
|
||||
//CALLED EVERY TICK
|
||||
tick++;
|
||||
if (tick % 20 == 0) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.sendMessage("One second has passed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ 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";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: PacketEvents
|
||||
version: ${project.version}
|
||||
main: me.retrooper.packetevents.Main
|
||||
main: me.purplex.packetevents.Main
|
||||
authors: [purplex]
|
||||
Reference in new issue
Block a user