나는이 코드를 나중에 Java에서 개인 필드를 읽어 bukkit 용 맵으로 전달하기 위해이 코드를 사용 해왔다.오류가 발생하기 전에 스 니펫 코드를 두 번만 사용할 수 있습니다.
Field FieldF = net.minecraft.server.v1_9_R2.EntityTypes.class.getDeclaredField("F");
FieldF.setAccessible(true);
Object valueF = FieldF.get("valueF");
그러나이 작업을 시도하면 오류가 발생합니다. 내가 첫 번째 코드를 사용할 수있는 방법 NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
:
내가 추가 한
Unhandled exception type NoSuchFieldException
내가 다른 오류가 선언
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
를 던졌습니다 어떤 것도없이 오류? 오류가 발생하기 전에 두 번만 사용할 수 있습니다.
전체 코드 :
package io.github.rookietec9.EnderPlugin.Entities;
import java.lang.reflect.Field;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.World;
import net.minecraft.server.v1_9_R2.Entity;
public enum CustomBase {
// NAME("Entity name", Entity ID, yourcustomclass.class)
CUSTOM_SKELETON("Skeleton", 54, CustomSkeleton.class); // You can add as
// many as you want.
private CustomBase(String name, int id, Class<? extends Entity> custom) {
addToMaps(custom, name, id);
}
public static void spawnEntity(Entity entity, Location loc) {
Location Loc = new Location((World) entity.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(),
loc.getPitch());
spawnEntity(entity, Loc);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void addToMaps(Class clazz, String name, int id) {
// Remove the lines with // in front of them if you want to override
// default entities (You'd have to remove the default entity from the
// map first though).
Field FieldF = net.minecraft.server.v1_9_R2.EntityTypes.class.getDeclaredField("F");
FieldF.setAccessible(true);
Object valueF = FieldF.get("valueF");
Field FieldC = net.minecraft.server.v1_9_R2.EntityTypes.class.getDeclaredField("D");
FieldC.setAccessible(true);
Object valueC = FieldC.get("valueC");
Field FieldD = net.minecraft.server.v1_9_R2.EntityTypes.class.getDeclaredField("C");
FieldD.setAccessible(true);
Object valueD = FieldD.get("valueD");
((Map) valueC).put(name, clazz);
((Map) valueD).put(clazz, name);
((Map) valueF).put(clazz, Integer.valueOf(id));
// ((Map)getPrivateField("e",
// net.minecraft.server.v1_7_R4.EntityTypes.class,
// null)).put(Integer.valueOf(id), clazz);
// ((Map)getPrivateField("g",
// net.minecraft.server.v1_7_R4.EntityTypes.class, null)).put(name,
// Integer.valueOf(id));
}
}