mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 01:27:33 +01:00
Try to aggressively stub out AdvancementDataPlayer
This commit is contained in:
parent
40e80c074d
commit
0e25c352a0
@ -1,6 +1,7 @@
|
||||
package net.citizensnpcs.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -83,6 +84,20 @@ public class NMS {
|
||||
return f;
|
||||
}
|
||||
|
||||
public static Field getFinalField(Class<?> clazz, String field) {
|
||||
Field f = getField(clazz, field);
|
||||
if (f == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
MODIFIERS_FIELD.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
||||
} catch (Exception e) {
|
||||
Messaging.logTr(Messages.ERROR_GETTING_FIELD, field, e.getLocalizedMessage());
|
||||
return null;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public static GameProfileRepository getGameProfileRepository() {
|
||||
return BRIDGE.getGameProfileRepository();
|
||||
}
|
||||
@ -221,6 +236,10 @@ public class NMS {
|
||||
BRIDGE.setDestination(entity, x, y, z, speed);
|
||||
}
|
||||
|
||||
public static void setDummyAdvancement(Player entity) {
|
||||
BRIDGE.setDummyAdvancement(entity);
|
||||
}
|
||||
|
||||
public static void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
BRIDGE.setHeadYaw(entity, yaw);
|
||||
}
|
||||
@ -287,4 +306,6 @@ public class NMS {
|
||||
}
|
||||
|
||||
private static NMSBridge BRIDGE;
|
||||
|
||||
private static Field MODIFIERS_FIELD = NMS.getField(Field.class, "modifiers");
|
||||
}
|
||||
|
@ -113,6 +113,8 @@ public interface NMSBridge {
|
||||
|
||||
public void setDestination(Entity entity, double x, double y, double z, float speed);
|
||||
|
||||
public void setDummyAdvancement(Player entity);
|
||||
|
||||
public void setHeadYaw(Entity entity, float yaw);
|
||||
|
||||
public void setKnockbackResistance(LivingEntity entity, double d);
|
||||
|
@ -820,6 +820,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDummyAdvancement(Player entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
if (!(entity instanceof LivingEntity))
|
||||
|
@ -880,6 +880,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDummyAdvancement(Player entity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
if (!(entity instanceof LivingEntity))
|
||||
@ -1482,6 +1486,7 @@ public class NMSImpl implements NMSBridge {
|
||||
public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "f");
|
||||
private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bw");
|
||||
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
|
@ -325,8 +325,8 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
controllerMove = new PlayerControllerMove(this);
|
||||
navigation = new PlayerNavigation(this, world);
|
||||
NMS.setStepHeight(getBukkitEntity(), 1); // the default (0) breaks step climbing
|
||||
|
||||
setSkinFlags((byte) 0xFF);
|
||||
NMS.setDummyAdvancement(getBukkitEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,57 @@
|
||||
package net.citizensnpcs.nms.v1_12_R1.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.minecraft.server.v1_12_R1.Advancement;
|
||||
import net.minecraft.server.v1_12_R1.AdvancementDataPlayer;
|
||||
import net.minecraft.server.v1_12_R1.AdvancementProgress;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
|
||||
public class DummyPlayerAdvancementData extends AdvancementDataPlayer {
|
||||
private DummyPlayerAdvancementData() {
|
||||
super(((CraftServer) Bukkit.getServer()).getServer(), CitizensAPI.getDataFolder(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(Advancement adv) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void a(EntityPlayer p) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(EntityPlayer p) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void c() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementProgress getProgress(Advancement adv) {
|
||||
return new AdvancementProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grantCriteria(Advancement adv, String str) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeCritera(Advancement adv, String str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final DummyPlayerAdvancementData INSTANCE = new DummyPlayerAdvancementData();
|
||||
}
|
@ -888,6 +888,17 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDummyAdvancement(Player entity) {
|
||||
try {
|
||||
ADVANCEMENT_PLAYER_FIELD.set(getHandle(entity), DummyPlayerAdvancementData.INSTANCE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeadYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
if (!(entity instanceof LivingEntity))
|
||||
@ -1473,6 +1484,7 @@ public class NMSImpl implements NMSBridge {
|
||||
navigation.d();
|
||||
}
|
||||
|
||||
private static Field ADVANCEMENT_PLAYER_FIELD = NMS.getFinalField(EntityPlayer.class, "bY");;
|
||||
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
|
||||
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
|
||||
EntityType.HORSE, EntityType.GHAST);
|
||||
@ -1493,13 +1505,12 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
private static Field SKULL_PROFILE_FIELD;
|
||||
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
|
||||
|
||||
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG");
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = NMS.getField(EntityTypes.class, "b");
|
||||
Field modifiersField = NMS.getField(Field.class, "modifiers");
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
Field field = NMS.getFinalField(EntityTypes.class, "b");
|
||||
ENTITY_REGISTRY = new CustomEntityRegistry(
|
||||
(RegistryMaterials<MinecraftKey, Class<? extends Entity>>) field.get(null));
|
||||
field.set(null, ENTITY_REGISTRY);
|
||||
|
Loading…
Reference in New Issue
Block a user