Created
December 6, 2012 18:50
-
-
Save aadnk/4227029 to your computer and use it in GitHub Desktop.
Attacking hidden players. Version for 1.7.2: https://gist.github.com/aadnk/d4f5d49fe079cb13da9c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.comphenix.example; | |
/* | |
* Attack hidden players | |
* | |
* Copyright 2012 Kristian S. Stangeland (Comphenix) | |
* | |
* This library 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.1 of the License, or (at your option) any later version. | |
* | |
* This library 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 | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
import org.bukkit.Location; | |
import org.bukkit.util.Vector; | |
public class Vector3D { | |
/** | |
* Represents the null (0, 0, 0) origin. | |
*/ | |
public static final Vector3D ORIGIN = new Vector3D(0, 0, 0); | |
// Use protected members, like Bukkit | |
public final double x; | |
public final double y; | |
public final double z; | |
/** | |
* Construct an immutable 3D vector. | |
*/ | |
public Vector3D(double x, double y, double z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
/** | |
* Construct an immutable floating point 3D vector from a location object. | |
* @param location - the location to copy. | |
*/ | |
public Vector3D(Location location) { | |
this(location.toVector()); | |
} | |
/** | |
* Construct an immutable floating point 3D vector from a mutable Bukkit vector. | |
* @param vector - the mutable real Bukkit vector to copy. | |
*/ | |
public Vector3D(Vector vector) { | |
if (vector == null) | |
throw new IllegalArgumentException("Vector cannot be NULL."); | |
this.x = vector.getX(); | |
this.y = vector.getY(); | |
this.z = vector.getZ(); | |
} | |
/** | |
* Convert this instance to an equivalent real 3D vector. | |
* @return Real 3D vector. | |
*/ | |
public Vector toVector() { | |
return new Vector(x, y, z); | |
} | |
/** | |
* Adds the current vector and a given position vector, producing a result vector. | |
* @param other - the other vector. | |
* @return The new result vector. | |
*/ | |
public Vector3D add(Vector3D other) { | |
if (other == null) | |
throw new IllegalArgumentException("other cannot be NULL"); | |
return new Vector3D(x + other.x, y + other.y, z + other.z); | |
} | |
/** | |
* Adds the current vector and a given vector together, producing a result vector. | |
* @param other - the other vector. | |
* @return The new result vector. | |
*/ | |
public Vector3D add(double x, double y, double z) { | |
return new Vector3D(this.x + x, this.y + y, this.z + z); | |
} | |
/** | |
* Substracts the current vector and a given vector, producing a result position. | |
* @param other - the other position. | |
* @return The new result position. | |
*/ | |
public Vector3D subtract(Vector3D other) { | |
if (other == null) | |
throw new IllegalArgumentException("other cannot be NULL"); | |
return new Vector3D(x - other.x, y - other.y, z - other.z); | |
} | |
/** | |
* Substracts the current vector and a given vector together, producing a result vector. | |
* @param other - the other vector. | |
* @return The new result vector. | |
*/ | |
public Vector3D subtract(double x, double y, double z) { | |
return new Vector3D(this.x - x, this.y - y, this.z - z); | |
} | |
/** | |
* Multiply each dimension in the current vector by the given factor. | |
* @param factor - multiplier. | |
* @return The new result. | |
*/ | |
public Vector3D multiply(int factor) { | |
return new Vector3D(x * factor, y * factor, z * factor); | |
} | |
/** | |
* Multiply each dimension in the current vector by the given factor. | |
* @param factor - multiplier. | |
* @return The new result. | |
*/ | |
public Vector3D multiply(double factor) { | |
return new Vector3D(x * factor, y * factor, z * factor); | |
} | |
/** | |
* Divide each dimension in the current vector by the given divisor. | |
* @param divisor - the divisor. | |
* @return The new result. | |
*/ | |
public Vector3D divide(int divisor) { | |
if (divisor == 0) | |
throw new IllegalArgumentException("Cannot divide by null."); | |
return new Vector3D(x / divisor, y / divisor, z / divisor); | |
} | |
/** | |
* Divide each dimension in the current vector by the given divisor. | |
* @param divisor - the divisor. | |
* @return The new result. | |
*/ | |
public Vector3D divide(double divisor) { | |
if (divisor == 0) | |
throw new IllegalArgumentException("Cannot divide by null."); | |
return new Vector3D(x / divisor, y / divisor, z / divisor); | |
} | |
/** | |
* Retrieve the absolute value of this vector. | |
* @return The new result. | |
*/ | |
public Vector3D abs() { | |
return new Vector3D(Math.abs(x), Math.abs(y), Math.abs(z)); | |
} | |
@Override | |
public String toString() { | |
return String.format("[x: %s, y: %s, z: %s]", x, y, z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code in lines 54 and 89 is deprecated, is this possible now?
Line 54: "new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {"
Line 89: "PacketContainer useEntity = protocolManager.createPacket(PacketType.Play.Client.USE_ENTITY, false);"
And I'm getting following errors when hitting an hidden player: http://pastebin.com/TH1XgrjC
This error points to "useEntity.getIntegers()." in my code, here it is line 90. What have I to do now to fix this error?