Add support for retrieving WorldType in MCPC
Dieser Commit ist enthalten in:
Ursprung
47134b43cc
Commit
c416877f35
@ -33,6 +33,7 @@ import com.comphenix.protocol.ProtocolLibrary;
|
|||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
|
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||||
@ -308,12 +309,17 @@ public class BukkitConverters {
|
|||||||
if (!hasWorldType)
|
if (!hasWorldType)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
final Class<?> worldType = MinecraftReflection.getWorldTypeClass();
|
||||||
|
|
||||||
return new IgnoreNullConverter<WorldType>() {
|
return new IgnoreNullConverter<WorldType>() {
|
||||||
@Override
|
@Override
|
||||||
protected Object getGenericValue(Class<?> genericType, WorldType specific) {
|
protected Object getGenericValue(Class<?> genericType, WorldType specific) {
|
||||||
try {
|
try {
|
||||||
if (worldTypeGetType == null)
|
// Deduce getType method by parameters alone
|
||||||
worldTypeGetType = MinecraftReflection.getWorldTypeClass().getMethod("getType", String.class);
|
if (worldTypeGetType == null) {
|
||||||
|
worldTypeGetType = FuzzyReflection.fromClass(worldType).
|
||||||
|
getMethodByParameters("getType", worldType, new Class<?>[] { String.class });
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to the Bukkit world type
|
// Convert to the Bukkit world type
|
||||||
return worldTypeGetType.invoke(this, specific.getName());
|
return worldTypeGetType.invoke(this, specific.getName());
|
||||||
@ -326,8 +332,15 @@ public class BukkitConverters {
|
|||||||
@Override
|
@Override
|
||||||
protected WorldType getSpecificValue(Object generic) {
|
protected WorldType getSpecificValue(Object generic) {
|
||||||
try {
|
try {
|
||||||
if (worldTypeName == null)
|
if (worldTypeName == null) {
|
||||||
worldTypeName = MinecraftReflection.getWorldTypeClass().getMethod("name");
|
try {
|
||||||
|
worldTypeName = worldType.getMethod("name");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Assume the first method is the one
|
||||||
|
worldTypeName = FuzzyReflection.fromClass(worldType).
|
||||||
|
getMethodByParameters("name", String.class, new Class<?>[] {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamically call the namne method
|
// Dynamically call the namne method
|
||||||
String name = (String) worldTypeName.invoke(generic);
|
String name = (String) worldTypeName.invoke(generic);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren