From 1a309753699f73f3412cb3a58ab402633232cb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20G=2E=20J=C3=B8rgensen?= Date: Thu, 26 May 2016 21:47:06 +0200 Subject: [PATCH] Update to 1.9 --- pom.xml | 26 +- .../packetwrapper/AbstractPacket.java | 71 ++-- .../WrapperPlayClientUseEntity.java | 165 +++++--- .../WrapperPlayServerEntityDestroy.java | 99 +++-- .../WrapperPlayServerEntityEffect.java | 243 ++++++----- .../WrapperPlayServerNamedEntitySpawn.java | 387 +++++++++--------- .../WrapperPlayServerPlayerInfo.java | 73 ++-- .../java/tk/maciekmm/antiaura/AntiAura.java | 18 +- .../java/tk/maciekmm/antiaura/AuraCheck.java | 28 +- .../tk/maciekmm/antiaura/NameGenerator.java | 3 +- 10 files changed, 639 insertions(+), 474 deletions(-) diff --git a/pom.xml b/pom.xml index b38af32..fe37cf3 100644 --- a/pom.xml +++ b/pom.xml @@ -2,39 +2,39 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 antiaura - 0.3-SNAPSHOT + 0.4-SNAPSHOT tk.maciekmm AntiAura Simple aura hack checker. http://maciekmm.net jar - tk.maciekmm.antiaura.AntiAura + UTF-8 + 1.8 + 1.8 - spigot-repo - https://hub.spigotmc.org/nexus/content/groups/public/ + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - shadowvolt-repo - http://ci.shadowvolt.com/plugin/repository/everything/ + dmulloy2-repo + http://repo.dmulloy2.net/content/groups/public/ - - org.bukkit - bukkit - 1.8-R0.1-SNAPSHOT + org.spigotmc + spigot-api + 1.9-R0.1-SNAPSHOT com.comphenix.protocol - ProtocolLib - 3.6.3-SNAPSHOT - + ProtocolLib-API + 4.0 + diff --git a/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java b/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java index 2e0a0da..55579c9 100644 --- a/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java +++ b/src/main/java/com/comphenix/packetwrapper/AbstractPacket.java @@ -1,30 +1,29 @@ -/* - * PacketWrapper - Contains wrappers for each packet in Minecraft. - * Copyright (C) 2012 Kristian S. Stangeland +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ - package com.comphenix.packetwrapper; -import java.lang.reflect.InvocationTargetException; - -import org.bukkit.entity.Player; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.google.common.base.Objects; +import java.lang.reflect.InvocationTargetException; +import org.bukkit.entity.Player; public abstract class AbstractPacket { // The packet we will be modifying @@ -32,6 +31,7 @@ public abstract class AbstractPacket { /** * Constructs a new strongly typed wrapper for the given packet. + * * @param handle - handle to the raw packet data. * @param type - the packet type. */ @@ -40,41 +40,64 @@ protected AbstractPacket(PacketContainer handle, PacketType type) { if (handle == null) throw new IllegalArgumentException("Packet handle cannot be NULL."); if (!Objects.equal(handle.getType(), type)) - throw new IllegalArgumentException( - handle.getHandle() + " is not a packet of type " + type); - + throw new IllegalArgumentException(handle.getHandle() + + " is not a packet of type " + type); + this.handle = handle; } /** * Retrieve a handle to the raw packet data. + * * @return Raw packet data. */ public PacketContainer getHandle() { return handle; } - + /** * Send the current packet to the given receiver. + * * @param receiver - the receiver. * @throws RuntimeException If the packet cannot be sent. */ public void sendPacket(Player receiver) { try { - ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, getHandle()); + ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, + getHandle()); } catch (InvocationTargetException e) { throw new RuntimeException("Cannot send packet.", e); } } - + /** * Simulate receiving the current packet from the given sender. + * * @param sender - the sender. * @throws RuntimeException If the packet cannot be received. + * @deprecated Misspelled. recieve -> receive + * @see #receivePacket(Player) */ + @Deprecated public void recievePacket(Player sender) { try { - ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, getHandle()); + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); + } catch (Exception e) { + throw new RuntimeException("Cannot recieve packet.", e); + } + } + + /** + * Simulate receiving the current packet from the given sender. + * + * @param sender - the sender. + * @throws RuntimeException if the packet cannot be received. + */ + public void receivePacket(Player sender) { + try { + ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, + getHandle()); } catch (Exception e) { throw new RuntimeException("Cannot recieve packet.", e); } diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayClientUseEntity.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayClientUseEntity.java index 524f551..b7a3cf4 100644 --- a/src/main/java/com/comphenix/packetwrapper/WrapperPlayClientUseEntity.java +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayClientUseEntity.java @@ -1,63 +1,116 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.comphenix.packetwrapper; -import org.bukkit.util.Vector; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; public class WrapperPlayClientUseEntity extends AbstractPacket { - public static final PacketType TYPE = PacketType.Play.Client.USE_ENTITY; - - public WrapperPlayClientUseEntity() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayClientUseEntity(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve Target. - * @return The current Target - */ - public int getTarget() { - return handle.getIntegers().read(0); - } - - /** - * Set Target. - * @param value - new value. - */ - public void setTarget(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve Type. - *

- * Notes: 0 = INTERACT, 1 = ATTACK, 2 = INTERACT_AT - * @return The current Type - */ - public EntityUseAction getType() { - return handle.getEntityUseActions().read(0); - } - - /** - * Set Type. - * @param value - new value. - */ - public void setType(EntityUseAction value) { - handle.getEntityUseActions().write(0, value); - } - - public Vector getTargetVector() { - return handle.getVectors().read(0); - } - - public void setTargetVector(Vector value) { - handle.getVectors().write(0, value); - } - -} \ No newline at end of file + public static final PacketType TYPE = PacketType.Play.Client.USE_ENTITY; + + public WrapperPlayClientUseEntity() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayClientUseEntity(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve entity ID of the target. + * + * @return The current entity ID + */ + public int getTargetID() { + return handle.getIntegers().read(0); + } + + /** + * Retrieve the entity that was targeted. + * + * @param world - the current world of the entity. + * @return The targeted entity. + */ + public Entity getTarget(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity that was targeted. + * + * @param event - the packet event. + * @return The targeted entity. + */ + public Entity getTarget(PacketEvent event) { + return getTarget(event.getPlayer().getWorld()); + } + + /** + * Set entity ID of the target. + * + * @param value - new value. + */ + public void setTargetID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve Type. + * + * @return The current Type + */ + public EntityUseAction getType() { + return handle.getEntityUseActions().read(0); + } + + /** + * Set Type. + * + * @param value - new value. + */ + public void setType(EntityUseAction value) { + handle.getEntityUseActions().write(0, value); + } + + /** + * Retrieve the target vector. + *

+ * Notes: Only if {@link #getType()} is {@link EntityUseAction#INTERACT_AT}. + * + * @return The target vector or null + */ + public Vector getTargetVector() { + return handle.getVectors().read(0); + } + + /** + * Set the target vector. + * + * @param value - new value. + */ + public void setTargetVector(Vector value) { + handle.getVectors().write(0, value); + } +} diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java index 0eb4458..97f88ce 100644 --- a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityDestroy.java @@ -1,46 +1,67 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.comphenix.packetwrapper; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; public class WrapperPlayServerEntityDestroy extends AbstractPacket { - public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY; - - public WrapperPlayServerEntityDestroy() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerEntityDestroy(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve Count. - *

- * Notes: length of following array - * @return The current Count - */ - public int getCount() { - return handle.getIntegerArrays().read(0).length; - } - - /** - * Retrieve Entity IDs. - *

- * Notes: the list of entities of destroy - * @return The current Entity IDs - */ - public int[] getEntityIds() { - return handle.getIntegerArrays().read(0); - } - - /** - * Set Entity IDs. - * @param value - new value. - */ - public void setEntityIds(int[] value) { - handle.getIntegerArrays().write(0, value); - } - + public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY; + + public WrapperPlayServerEntityDestroy() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityDestroy(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Count. + *

+ * Notes: length of following array + * + * @return The current Count + */ + public int getCount() { + return handle.getIntegerArrays().read(0).length; + } + + /** + * Retrieve Entity IDs. + *

+ * Notes: the list of entities of destroy + * + * @return The current Entity IDs + */ + public int[] getEntityIDs() { + return handle.getIntegerArrays().read(0); + } + + /** + * Set Entity IDs. + * + * @param value - new value. + */ + public void setEntityIds(int[] value) { + handle.getIntegerArrays().write(0, value); + } + } diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityEffect.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityEffect.java index d2bd526..43fc1a6 100644 --- a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityEffect.java +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerEntityEffect.java @@ -1,102 +1,153 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.comphenix.packetwrapper; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; +import org.bukkit.World; +import org.bukkit.entity.Entity; public class WrapperPlayServerEntityEffect extends AbstractPacket { - public static final PacketType TYPE = PacketType.Play.Server.ENTITY_EFFECT; - - public WrapperPlayServerEntityEffect() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerEntityEffect(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve Entity ID. - *

- * Notes: entity's ID - * @return The current Entity ID - */ - public int getEntityId() { - return handle.getIntegers().read(0); - } - - /** - * Set Entity ID. - * @param value - new value. - */ - public void setEntityId(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve Effect ID. - *

- * Notes: see [[1]] - * @return The current Effect ID - */ - public byte getEffectId() { - return handle.getBytes().read(0); - } - - /** - * Set Effect ID. - * @param value - new value. - */ - public void setEffectId(byte value) { - handle.getBytes().write(0, value); - } - - /** - * Retrieve Amplifier. - * @return The current Amplifier - */ - public byte getAmplifier() { - return handle.getBytes().read(1); - } - - /** - * Set Amplifier. - * @param value - new value. - */ - public void setAmplifier(byte value) { - handle.getBytes().write(1, value); - } - - /** - * Retrieve Duration. - * @return The current Duration - */ - public int getDuration() { - return handle.getIntegers().read(1); - } - - /** - * Set Duration. - * @param value - new value. - */ - public void setDuration(int value) { - handle.getIntegers().write(1, value); - } - - /** - * Retrieve Hide Particles. - * @return The current Hide Particles - */ - public boolean getHideParticles() { - return handle.getBooleans().read(0); - } - - /** - * Set Hide Particles. - * @param value - new value. - */ - public void setHideParticles(boolean value) { - handle.getBooleans().write(0, value); - } - -} \ No newline at end of file + public static final PacketType TYPE = PacketType.Play.Server.ENTITY_EFFECT; + + public WrapperPlayServerEntityEffect() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerEntityEffect(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Retrieve Effect ID. + *

+ * Notes: see [[1]] + * + * @return The current Effect ID + */ + public byte getEffectID() { + return handle.getBytes().read(0); + } + + /** + * Set Effect ID. + * + * @param value - new value. + */ + public void setEffectID(byte value) { + handle.getBytes().write(0, (byte) (value & 255)); + } + + /** + * Retrieve Amplifier. + * + * @return The current Amplifier + */ + public byte getAmplifier() { + return handle.getBytes().read(1); + } + + /** + * Set Amplifier. + * + * @param value - new value. + */ + public void setAmplifier(byte value) { + handle.getBytes().write(1, (byte) (value & 255)); + } + + /** + * Retrieve Duration. + * + * @return The current Duration + */ + public int getDuration() { + return handle.getIntegers().read(1); + } + + /** + * Set Duration. + * + * @param value - new value. + */ + public void setDuration(int value) { + handle.getIntegers().write(1, value); + } + + /** + * Retrieve Hide Particles. + * + * @return The current Hide Particles + */ + public boolean getHideParticles() { + return handle.getBytes().read(2) == 0; + } + + /** + * Set Hide Particles. + * + * @param value - new value. + */ + public void setHideParticles(boolean value) { + handle.getBytes().write(2, (byte) (value ? 0 : 1)); + } + +} diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java index b92a820..8cdab01 100644 --- a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerNamedEntitySpawn.java @@ -1,199 +1,202 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.comphenix.packetwrapper; -import java.util.UUID; - -import org.bukkit.util.Vector; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import java.util.UUID; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket { - public static final PacketType TYPE = PacketType.Play.Server.NAMED_ENTITY_SPAWN; - - public WrapperPlayServerNamedEntitySpawn() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) { - super(packet, TYPE); - } - - /** - * Retrieve Entity ID. - *

- * Notes: player's Entity ID - * @return The current Entity ID - */ - public int getEntityId() { - return handle.getIntegers().read(0); - } - - /** - * Set Entity ID. - * @param value - new value. - */ - public void setEntityId(int value) { - handle.getIntegers().write(0, value); - } - - /** - * Retrieve Player UUID. - *

- * Notes: player's UUID - * @return The current Player UUID - */ - public UUID getPlayerUuid() { - return handle.getSpecificModifier(UUID.class).read(0); - } - - /** - * Set Player UUID. - * @param value - new value. - */ - public void setPlayerUuid(UUID value) { - handle.getSpecificModifier(UUID.class).write(0, value); - } - - /** - * Retrieve the position of the spawned entity as a vector. - * @return The position as a vector. - */ - public Vector getPosition() { - return new Vector(getX(), getY(), getZ()); - } - - /** - * Set the position of the spawned entity using a vector. - * @param position - the new position. - */ - public void setPosition(Vector position) { - setX(position.getX()); - setY(position.getY()); - setZ(position.getZ()); - } - - /** - * Retrieve the x axis of the position. - *

- * Note that the coordinate is rounded off to the nearest 1/32 of a meter. - * @return The current X - */ - public double getX() { - return handle.getIntegers().read(1) / 32.0D; - } - - /** - * Set the x axis of the position. - * @param value - new value. - */ - public void setX(double value) { - handle.getIntegers().write(1, (int) Math.floor(value * 32.0D)); - } - - /** - * Retrieve the y axis of the position. - *

- * Note that the coordinate is rounded off to the nearest 1/32 of a meter. - * @return The current y - */ - public double getY() { - return handle.getIntegers().read(2) / 32.0D; - } - - /** - * Set the y axis of the position. - * @param value - new value. - */ - public void setY(double value) { - handle.getIntegers().write(2, (int) Math.floor(value * 32.0D)); - } - - /** - * Retrieve the z axis of the new position. - *

- * Note that the coordinate is rounded off to the nearest 1/32 of a meter. - * @return The current z - */ - public double getZ() { - return handle.getIntegers().read(3) / 32.0D; - } - - /** - * Set the z axis of the new position. - * @param value - new value. - */ - public void setZ(double value) { - handle.getIntegers().write(3, (int) Math.floor(value * 32.0D)); - } - - /** - * Retrieve the yaw of the spawned entity. - * @return The current Yaw - */ - public float getYaw() { - return (handle.getBytes().read(0) * 360.F) / 256.0F; - } - - /** - * Set the yaw of the spawned entity. - * @param value - new yaw. - */ - public void setYaw(float value) { - handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); - } - - /** - * Retrieve the pitch of the spawned entity. - * @return The current pitch - */ - public float getPitch() { - return (handle.getBytes().read(1) * 360.F) / 256.0F; - } - - /** - * Set the pitch of the spawned entity. - * @param value - new pitch. - */ - public void setPitch(float value) { - handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); - } - - /** - * Retrieve Current Item. - *

- * Notes: the item the player is currently holding. Note that this should be 0 for "no item", unlike -1 used in other packets. A negative value crashes clients. - * @return The current Current Item - */ - public int getCurrentItem() { - return handle.getIntegers().read(4); - } - - /** - * Set Current Item. - * @param value - new value. - */ - public void setCurrentItem(int value) { - handle.getIntegers().write(4, value); - } - - /** - * Retrieve Metadata. - *

- * Notes: the client will crash if no metadata is sent - * @return The current Metadata - */ - public WrappedDataWatcher getMetadata() { - return handle.getDataWatcherModifier().read(0); - } - - /** - * Set Metadata. - * @param value - new value. - */ - public void setMetadata(WrappedDataWatcher value) { - handle.getDataWatcherModifier().write(0, value); - } - -} \ No newline at end of file + public static final PacketType TYPE = + PacketType.Play.Server.NAMED_ENTITY_SPAWN; + + public WrapperPlayServerNamedEntitySpawn() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) { + super(packet, TYPE); + } + + /** + * Retrieve Entity ID. + *

+ * Notes: entity's ID + * + * @return The current Entity ID + */ + public int getEntityID() { + return handle.getIntegers().read(0); + } + + /** + * Set Entity ID. + * + * @param value - new value. + */ + public void setEntityID(int value) { + handle.getIntegers().write(0, value); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param world - the current world of the entity. + * @return The spawned entity. + */ + public Entity getEntity(World world) { + return handle.getEntityModifier(world).read(0); + } + + /** + * Retrieve the entity of the painting that will be spawned. + * + * @param event - the packet event. + * @return The spawned entity. + */ + public Entity getEntity(PacketEvent event) { + return getEntity(event.getPlayer().getWorld()); + } + + /** + * Retrieve Player UUID. + *

+ * Notes: player's UUID + * + * @return The current Player UUID + */ + public UUID getPlayerUUID() { + return handle.getSpecificModifier(UUID.class).read(0); + } + + /** + * Set Player UUID. + * + * @param value - new value. + */ + public void setPlayerUUID(UUID value) { + handle.getSpecificModifier(UUID.class).write(0, value); + } + + /** + * Retrieve the position of the spawned entity as a vector. + * + * @return The position as a vector. + */ + public Vector getPosition() { + return new Vector(getX(), getY(), getZ()); + } + + /** + * Set the position of the spawned entity using a vector. + * + * @param position - the new position. + */ + public void setPosition(Vector position) { + setX(position.getX()); + setY(position.getY()); + setZ(position.getZ()); + } + + public double getX() { + return handle.getDoubles().read(0); + } + + public void setX(double value) { + handle.getDoubles().write(0, value); + } + + public double getY() { + return handle.getDoubles().read(1); + } + + public void setY(double value) { + handle.getDoubles().write(1, value); + } + + public double getZ() { + return handle.getDoubles().read(2); + } + + public void setZ(double value) { + handle.getDoubles().write(2, value); + } + + /** + * Retrieve the yaw of the spawned entity. + * + * @return The current Yaw + */ + public float getYaw() { + return (handle.getBytes().read(0) * 360.F) / 256.0F; + } + + /** + * Set the yaw of the spawned entity. + * + * @param value - new yaw. + */ + public void setYaw(float value) { + handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve the pitch of the spawned entity. + * + * @return The current pitch + */ + public float getPitch() { + return (handle.getBytes().read(1) * 360.F) / 256.0F; + } + + /** + * Set the pitch of the spawned entity. + * + * @param value - new pitch. + */ + public void setPitch(float value) { + handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F)); + } + + /** + * Retrieve Metadata. + *

+ * Notes: the client will crash if no metadata is sent + * + * @return The current Metadata + */ + public WrappedDataWatcher getMetadata() { + return handle.getDataWatcherModifier().read(0); + } + + /** + * Set Metadata. + * + * @param value - new value. + */ + public void setMetadata(WrappedDataWatcher value) { + handle.getDataWatcherModifier().write(0, value); + } +} diff --git a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java index 5121667..074680d 100644 --- a/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java +++ b/src/main/java/com/comphenix/packetwrapper/WrapperPlayServerPlayerInfo.java @@ -1,37 +1,54 @@ +/** + * PacketWrapper - ProtocolLib wrappers for Minecraft packets + * Copyright (C) dmulloy2 + * Copyright (C) Kristian S. Strangeland + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.comphenix.packetwrapper; -import java.util.List; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.PlayerInfoData; +import java.util.List; public class WrapperPlayServerPlayerInfo extends AbstractPacket { - public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO; - - public WrapperPlayServerPlayerInfo() { - super(new PacketContainer(TYPE), TYPE); - handle.getModifier().writeDefaults(); - } - - public WrapperPlayServerPlayerInfo(PacketContainer packet) { - super(packet, TYPE); - } - - public PlayerInfoAction getAction() { - return handle.getPlayerInfoAction().read(0); - } - - public void setAction(PlayerInfoAction value) { - handle.getPlayerInfoAction().write(0, value); - } - - public List getData() { - return handle.getPlayerInfoDataLists().read(0); - } - - public void setData(List value) { - handle.getPlayerInfoDataLists().write(0, value); - } + public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO; + + public WrapperPlayServerPlayerInfo() { + super(new PacketContainer(TYPE), TYPE); + handle.getModifier().writeDefaults(); + } + + public WrapperPlayServerPlayerInfo(PacketContainer packet) { + super(packet, TYPE); + } + + public PlayerInfoAction getAction() { + return handle.getPlayerInfoAction().read(0); + } + + public void setAction(PlayerInfoAction value) { + handle.getPlayerInfoAction().write(0, value); + } + + public List getData() { + return handle.getPlayerInfoDataLists().read(0); + } + + public void setData(List value) { + handle.getPlayerInfoDataLists().write(0, value); + } } diff --git a/src/main/java/tk/maciekmm/antiaura/AntiAura.java b/src/main/java/tk/maciekmm/antiaura/AntiAura.java index 7dd6e2d..72ae981 100644 --- a/src/main/java/tk/maciekmm/antiaura/AntiAura.java +++ b/src/main/java/tk/maciekmm/antiaura/AntiAura.java @@ -26,7 +26,13 @@ import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; import com.comphenix.protocol.wrappers.WrappedChatComponent; - +import java.lang.reflect.InvocationTargetException; +import java.text.NumberFormat; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.List; +import java.util.Random; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -37,14 +43,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import java.lang.reflect.InvocationTargetException; -import java.text.NumberFormat; -import java.util.AbstractMap; -import java.util.HashMap; -import java.util.List; -import java.util.Random; -import java.util.UUID; - public class AntiAura extends JavaPlugin implements Listener { @@ -75,7 +73,7 @@ public void register() { public void onPacketReceiving(PacketEvent event) { if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) { WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket()); - int entID = packet.getTarget(); + int entID = packet.getTargetID(); if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType() == EntityUseAction.ATTACK) { running.get(event.getPlayer().getUniqueId()).markAsKilled(entID); } diff --git a/src/main/java/tk/maciekmm/antiaura/AuraCheck.java b/src/main/java/tk/maciekmm/antiaura/AuraCheck.java index f253c4a..90a40ba 100644 --- a/src/main/java/tk/maciekmm/antiaura/AuraCheck.java +++ b/src/main/java/tk/maciekmm/antiaura/AuraCheck.java @@ -25,19 +25,19 @@ import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; +import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import com.comphenix.protocol.wrappers.WrappedGameProfile; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class AuraCheck { @@ -68,11 +68,11 @@ public void invoke(CommandSender player, final Callback callback) { } else { spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(2 * Math.cos(radians), 0.2, 2 * Math.sin(radians)).toVector(), plugin); } - WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.ADD_PLAYER); + WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUUID(), PlayerInfoAction.ADD_PLAYER); infoWrapper.sendPacket(this.checked); spawnWrapper.sendPacket(this.checked); - entitiesSpawned.put(spawnWrapper.getEntityId(), false); - WrapperPlayServerPlayerInfo RemoveinfoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.REMOVE_PLAYER); + entitiesSpawned.put(spawnWrapper.getEntityID(), false); + WrapperPlayServerPlayerInfo RemoveinfoWrapper = getInfoWrapper(spawnWrapper.getPlayerUUID(), PlayerInfoAction.REMOVE_PLAYER); RemoveinfoWrapper.sendPacket(this.checked); } @@ -116,15 +116,15 @@ public AbstractMap.SimpleEntry end() { public static WrapperPlayServerNamedEntitySpawn getSpawnWrapper(Vector loc, AntiAura plugin) { WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn(); - wrapper.setEntityId(AntiAura.RANDOM.nextInt(20000)); + wrapper.setEntityID(AntiAura.RANDOM.nextInt(20000)); wrapper.setPosition(loc); - wrapper.setPlayerUuid(UUID.randomUUID()); + wrapper.setPlayerUUID(UUID.randomUUID()); wrapper.setYaw(0.0F); wrapper.setPitch(-45.0F); WrappedDataWatcher watcher = new WrappedDataWatcher(); - watcher.setObject(0, plugin.getConfig().getBoolean("invisibility", false) ? (byte) 0x20 : (byte) 0); - watcher.setObject(6, 0.5F); - watcher.setObject(11, (byte) 1); + watcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), plugin.getConfig().getBoolean("invisibility", false) ? (byte) 0x20 : (byte) 0); + watcher.setObject(new WrappedDataWatcherObject(6, Registry.get(Float.class)), 0.5F); + watcher.setObject(new WrappedDataWatcherObject(11, Registry.get(Byte.class)), (byte) 1); wrapper.setMetadata(watcher); return wrapper; } diff --git a/src/main/java/tk/maciekmm/antiaura/NameGenerator.java b/src/main/java/tk/maciekmm/antiaura/NameGenerator.java index 26404fd..28de745 100644 --- a/src/main/java/tk/maciekmm/antiaura/NameGenerator.java +++ b/src/main/java/tk/maciekmm/antiaura/NameGenerator.java @@ -1,8 +1,7 @@ package tk.maciekmm.antiaura; -import org.apache.commons.lang.RandomStringUtils; - import java.util.Random; +import org.apache.commons.lang.RandomStringUtils; public class NameGenerator { private static Random random = new Random();