No need to suppress any warnings - we can use wildcards.
Dieser Commit ist enthalten in:
Ursprung
5d06b9e84c
Commit
d328111b38
@ -4,7 +4,7 @@
|
|||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<name>ProtocolLib</name>
|
<name>ProtocolLib</name>
|
||||||
<version>1.8.3-SNAPSHOT</version>
|
<version>1.8.4-SNAPSHOT</version>
|
||||||
<description>Provides read/write access to the Minecraft protocol.</description>
|
<description>Provides read/write access to the Minecraft protocol.</description>
|
||||||
<url>http://dev.bukkit.org/server-mods/protocollib/</url>
|
<url>http://dev.bukkit.org/server-mods/protocollib/</url>
|
||||||
<developers>
|
<developers>
|
||||||
|
@ -23,8 +23,7 @@ class CachedPackage {
|
|||||||
* @param className - class name.
|
* @param className - class name.
|
||||||
* @param clazz - type of class.
|
* @param clazz - type of class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public void setPackageClass(String className, Class<?> clazz) {
|
||||||
public void setPackageClass(String className, Class clazz) {
|
|
||||||
cache.put(className, clazz);
|
cache.put(className, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,10 +33,9 @@ class CachedPackage {
|
|||||||
* @return Class object.
|
* @return Class object.
|
||||||
* @throws RuntimeException If we are unable to find the given class.
|
* @throws RuntimeException If we are unable to find the given class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public Class<?> getPackageClass(String className) {
|
||||||
public Class getPackageClass(String className) {
|
|
||||||
try {
|
try {
|
||||||
Class result = cache.get(className);
|
Class<?> result = cache.get(className);
|
||||||
|
|
||||||
// Concurrency is not a problem - we don't care if we look up a class twice
|
// Concurrency is not a problem - we don't care if we look up a class twice
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
@ -162,7 +162,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the object to test.
|
* @param obj - the object to test.
|
||||||
* @return TRUE if it can, FALSE otherwise.
|
* @return TRUE if it can, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isChunkPosition(Object obj) {
|
public static boolean isChunkPosition(Object obj) {
|
||||||
return getChunkPositionClass().isAssignableFrom(obj.getClass());
|
return getChunkPositionClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -172,7 +171,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the object to test.
|
* @param obj - the object to test.
|
||||||
* @return TRUE if it can, FALSE otherwise.
|
* @return TRUE if it can, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isChunkCoordinates(Object obj) {
|
public static boolean isChunkCoordinates(Object obj) {
|
||||||
return getChunkCoordinatesClass().isAssignableFrom(obj.getClass());
|
return getChunkCoordinatesClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -182,7 +180,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isPacketClass(Object obj) {
|
public static boolean isPacketClass(Object obj) {
|
||||||
return getPacketClass().isAssignableFrom(obj.getClass());
|
return getPacketClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -192,7 +189,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isLoginHandler(Object obj) {
|
public static boolean isLoginHandler(Object obj) {
|
||||||
return getNetLoginHandlerClass().isAssignableFrom(obj.getClass());
|
return getNetLoginHandlerClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -202,7 +198,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isMinecraftEntity(Object obj) {
|
public static boolean isMinecraftEntity(Object obj) {
|
||||||
return getEntityClass().isAssignableFrom(obj.getClass());
|
return getEntityClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -212,7 +207,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isItemStack(Object value) {
|
public static boolean isItemStack(Object value) {
|
||||||
return getItemStackClass().isAssignableFrom(value.getClass());
|
return getItemStackClass().isAssignableFrom(value.getClass());
|
||||||
}
|
}
|
||||||
@ -222,7 +216,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isMinecraftPlayer(Object obj) {
|
public static boolean isMinecraftPlayer(Object obj) {
|
||||||
return getEntityPlayerClass().isAssignableFrom(obj.getClass());
|
return getEntityPlayerClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -232,7 +225,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isWatchableObject(Object obj) {
|
public static boolean isWatchableObject(Object obj) {
|
||||||
return getWatchableObjectClass().isAssignableFrom(obj.getClass());
|
return getWatchableObjectClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -242,7 +234,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isDataWatcher(Object obj) {
|
public static boolean isDataWatcher(Object obj) {
|
||||||
return getDataWatcherClass().isAssignableFrom(obj.getClass());
|
return getDataWatcherClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -252,7 +243,6 @@ public class MinecraftReflection {
|
|||||||
* @param obj - the given object.
|
* @param obj - the given object.
|
||||||
* @return TRUE if it is, FALSE otherwise.
|
* @return TRUE if it is, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static boolean isCraftItemStack(Object obj) {
|
public static boolean isCraftItemStack(Object obj) {
|
||||||
return getCraftItemStackClass().isAssignableFrom(obj.getClass());
|
return getCraftItemStackClass().isAssignableFrom(obj.getClass());
|
||||||
}
|
}
|
||||||
@ -261,8 +251,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the EntityPlayer (NMS) class.
|
* Retrieve the EntityPlayer (NMS) class.
|
||||||
* @return The entity class.
|
* @return The entity class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getEntityPlayerClass() {
|
||||||
public static Class getEntityPlayerClass() {
|
|
||||||
return getMinecraftClass("EntityPlayer");
|
return getMinecraftClass("EntityPlayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,8 +259,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the entity (NMS) class.
|
* Retrieve the entity (NMS) class.
|
||||||
* @return The entity class.
|
* @return The entity class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getEntityClass() {
|
||||||
public static Class getEntityClass() {
|
|
||||||
return getMinecraftClass("Entity");
|
return getMinecraftClass("Entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,8 +267,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the packet class.
|
* Retrieve the packet class.
|
||||||
* @return The packet class.
|
* @return The packet class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getPacketClass() {
|
||||||
public static Class getPacketClass() {
|
|
||||||
return getMinecraftClass("Packet");
|
return getMinecraftClass("Packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +275,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the NetLoginHandler class.
|
* Retrieve the NetLoginHandler class.
|
||||||
* @return The NetLoginHandler class.
|
* @return The NetLoginHandler class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getNetLoginHandlerClass() {
|
||||||
public static Class getNetLoginHandlerClass() {
|
|
||||||
return getMinecraftClass("NetLoginHandler", "PendingConnection");
|
return getMinecraftClass("NetLoginHandler", "PendingConnection");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +307,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the NMS ItemStack class.
|
* Retrieve the NMS ItemStack class.
|
||||||
* @return The ItemStack class.
|
* @return The ItemStack class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getItemStackClass() {
|
||||||
public static Class getItemStackClass() {
|
|
||||||
return getMinecraftClass("ItemStack");
|
return getMinecraftClass("ItemStack");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,8 +315,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the WorldType class.
|
* Retrieve the WorldType class.
|
||||||
* @return The WorldType class.
|
* @return The WorldType class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getWorldTypeClass() {
|
||||||
public static Class getWorldTypeClass() {
|
|
||||||
return getMinecraftClass("WorldType");
|
return getMinecraftClass("WorldType");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,8 +331,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the DataWatcher class.
|
* Retrieve the DataWatcher class.
|
||||||
* @return The DataWatcher class.
|
* @return The DataWatcher class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getDataWatcherClass() {
|
||||||
public static Class getDataWatcherClass() {
|
|
||||||
return getMinecraftClass("DataWatcher");
|
return getMinecraftClass("DataWatcher");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,8 +339,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the ChunkPosition class.
|
* Retrieve the ChunkPosition class.
|
||||||
* @return The ChunkPosition class.
|
* @return The ChunkPosition class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getChunkPositionClass() {
|
||||||
public static Class getChunkPositionClass() {
|
|
||||||
return getMinecraftClass("ChunkPosition");
|
return getMinecraftClass("ChunkPosition");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,8 +347,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the ChunkPosition class.
|
* Retrieve the ChunkPosition class.
|
||||||
* @return The ChunkPosition class.
|
* @return The ChunkPosition class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getChunkCoordinatesClass() {
|
||||||
public static Class getChunkCoordinatesClass() {
|
|
||||||
return getMinecraftClass("ChunkCoordinates");
|
return getMinecraftClass("ChunkCoordinates");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,8 +355,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the WatchableObject class.
|
* Retrieve the WatchableObject class.
|
||||||
* @return The WatchableObject class.
|
* @return The WatchableObject class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getWatchableObjectClass() {
|
||||||
public static Class getWatchableObjectClass() {
|
|
||||||
return getMinecraftClass("WatchableObject");
|
return getMinecraftClass("WatchableObject");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,8 +363,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the ItemStack[] class.
|
* Retrieve the ItemStack[] class.
|
||||||
* @return The ItemStack[] class.
|
* @return The ItemStack[] class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getItemStackArrayClass() {
|
||||||
public static Class getItemStackArrayClass() {
|
|
||||||
if (itemStackArrayClass == null)
|
if (itemStackArrayClass == null)
|
||||||
itemStackArrayClass = getArrayClass(getItemStackClass());
|
itemStackArrayClass = getArrayClass(getItemStackClass());
|
||||||
return itemStackArrayClass;
|
return itemStackArrayClass;
|
||||||
@ -395,8 +374,7 @@ public class MinecraftReflection {
|
|||||||
* @param componentType - type of each element in the array.
|
* @param componentType - type of each element in the array.
|
||||||
* @return The class of the array.
|
* @return The class of the array.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getArrayClass(Class<?> componentType) {
|
||||||
public static Class getArrayClass(Class componentType) {
|
|
||||||
// Bit of a hack, but it works
|
// Bit of a hack, but it works
|
||||||
return Array.newInstance(componentType, 0).getClass();
|
return Array.newInstance(componentType, 0).getClass();
|
||||||
}
|
}
|
||||||
@ -405,8 +383,7 @@ public class MinecraftReflection {
|
|||||||
* Retrieve the CraftItemStack class.
|
* Retrieve the CraftItemStack class.
|
||||||
* @return The CraftItemStack class.
|
* @return The CraftItemStack class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getCraftItemStackClass() {
|
||||||
public static Class getCraftItemStackClass() {
|
|
||||||
return getCraftBukkitClass("inventory.CraftItemStack");
|
return getCraftBukkitClass("inventory.CraftItemStack");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +392,6 @@ public class MinecraftReflection {
|
|||||||
* @param bukkitItemStack - the Bukkit ItemStack to convert.
|
* @param bukkitItemStack - the Bukkit ItemStack to convert.
|
||||||
* @return A CraftItemStack as an ItemStack.
|
* @return A CraftItemStack as an ItemStack.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static ItemStack getBukkitItemStack(ItemStack bukkitItemStack) {
|
public static ItemStack getBukkitItemStack(ItemStack bukkitItemStack) {
|
||||||
// Delegate this task to the method that can execute it
|
// Delegate this task to the method that can execute it
|
||||||
if (craftBukkitMethod != null)
|
if (craftBukkitMethod != null)
|
||||||
@ -441,7 +417,6 @@ public class MinecraftReflection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static ItemStack getBukkitItemByMethod(ItemStack bukkitItemStack) {
|
private static ItemStack getBukkitItemByMethod(ItemStack bukkitItemStack) {
|
||||||
if (craftBukkitMethod == null) {
|
if (craftBukkitMethod == null) {
|
||||||
try {
|
try {
|
||||||
@ -465,7 +440,6 @@ public class MinecraftReflection {
|
|||||||
* @param minecraftItemStack - the NMS ItemStack to wrap.
|
* @param minecraftItemStack - the NMS ItemStack to wrap.
|
||||||
* @return The wrapped ItemStack.
|
* @return The wrapped ItemStack.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static ItemStack getBukkitItemStack(Object minecraftItemStack) {
|
public static ItemStack getBukkitItemStack(Object minecraftItemStack) {
|
||||||
// Delegate this task to the method that can execute it
|
// Delegate this task to the method that can execute it
|
||||||
if (craftNMSMethod != null)
|
if (craftNMSMethod != null)
|
||||||
@ -491,7 +465,6 @@ public class MinecraftReflection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static ItemStack getBukkitItemByMethod(Object minecraftItemStack) {
|
private static ItemStack getBukkitItemByMethod(Object minecraftItemStack) {
|
||||||
if (craftNMSMethod == null) {
|
if (craftNMSMethod == null) {
|
||||||
try {
|
try {
|
||||||
@ -543,8 +516,7 @@ public class MinecraftReflection {
|
|||||||
* @return Class object.
|
* @return Class object.
|
||||||
* @throws RuntimeException If we are unable to find the given class.
|
* @throws RuntimeException If we are unable to find the given class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getMinecraftClass(String className) {
|
||||||
public static Class getMinecraftClass(String className) {
|
|
||||||
if (minecraftPackage == null)
|
if (minecraftPackage == null)
|
||||||
minecraftPackage = new CachedPackage(getMinecraftPackage());
|
minecraftPackage = new CachedPackage(getMinecraftPackage());
|
||||||
return minecraftPackage.getPackageClass(className);
|
return minecraftPackage.getPackageClass(className);
|
||||||
@ -556,13 +528,12 @@ public class MinecraftReflection {
|
|||||||
* @return Class object.
|
* @return Class object.
|
||||||
* @throws RuntimeException If we are unable to find any of the given classes.
|
* @throws RuntimeException If we are unable to find any of the given classes.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public static Class<?> getMinecraftClass(String className, String... aliases) {
|
||||||
public static Class getMinecraftClass(String className, String... aliases) {
|
|
||||||
try {
|
try {
|
||||||
// Try the main class first
|
// Try the main class first
|
||||||
return getMinecraftClass(className);
|
return getMinecraftClass(className);
|
||||||
} catch (RuntimeException e1) {
|
} catch (RuntimeException e1) {
|
||||||
Class success = null;
|
Class<?> success = null;
|
||||||
|
|
||||||
// Try every alias too
|
// Try every alias too
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren