mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 02:25:57 +01:00
Use new metadata
This commit is contained in:
parent
194198a9ce
commit
efd3ec54f5
@ -2,9 +2,11 @@ package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Bed;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
@ -36,30 +38,22 @@ public class SleepTrait extends Trait {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (SUPPORT_BLOCKDATA == null) {
|
||||
try {
|
||||
SUPPORT_BLOCKDATA = true;
|
||||
at.getBlock().getBlockData();
|
||||
} catch (NoSuchMethodError e) {
|
||||
SUPPORT_BLOCKDATA = false;
|
||||
}
|
||||
}
|
||||
if (npc.getEntity() instanceof Player) {
|
||||
Player player = (Player) npc.getEntity();
|
||||
if (!SUPPORT_BLOCKSTATE) {
|
||||
NMS.sleep(player, true);
|
||||
} else {
|
||||
npc.data().set(NPC.Metadata.ENTITY_POSE, "SLEEPING");
|
||||
if (SUPPORT_BLOCKDATA) {
|
||||
try {
|
||||
if (SUPPORT_BLOCKDATA && at.getBlock().getBlockData() instanceof Bed
|
||||
|| at.getBlock().getState() instanceof Bed) {
|
||||
if (at.getBlock().getBlockData() instanceof Bed || at.getBlock().getState() instanceof Bed) {
|
||||
player.sleep(at, true);
|
||||
} else {
|
||||
NMS.sleep(player, true);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
SUPPORT_BLOCKSTATE = false;
|
||||
SUPPORT_BLOCKDATA = false;
|
||||
NMS.sleep(player, true);
|
||||
}
|
||||
} else {
|
||||
NMS.sleep(player, true);
|
||||
}
|
||||
sleeping = true;
|
||||
} else if (npc.getEntity() instanceof Villager) {
|
||||
@ -73,6 +67,7 @@ public class SleepTrait extends Trait {
|
||||
}
|
||||
|
||||
private void wakeup() {
|
||||
npc.data().remove(NPC.Metadata.ENTITY_POSE);
|
||||
if (npc.getEntity() instanceof Player) {
|
||||
NMS.sleep((Player) npc.getEntity(), false);
|
||||
} else if (npc.getEntity() instanceof Villager) {
|
||||
@ -82,5 +77,12 @@ public class SleepTrait extends Trait {
|
||||
}
|
||||
|
||||
private static Boolean SUPPORT_BLOCKDATA = null;
|
||||
private static boolean SUPPORT_BLOCKSTATE = true;
|
||||
static {
|
||||
try {
|
||||
Block.class.getMethod("getBlockData");
|
||||
SUPPORT_BLOCKDATA = true;
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
SUPPORT_BLOCKDATA = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,9 @@ import net.citizensnpcs.api.util.BoundingBox;
|
||||
import net.citizensnpcs.api.util.EntityDim;
|
||||
import net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator;
|
||||
import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
import net.citizensnpcs.trait.MirrorTrait;
|
||||
import net.citizensnpcs.trait.SneakTrait;
|
||||
import net.citizensnpcs.trait.versioned.ArmadilloTrait.ArmadilloState;
|
||||
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
|
||||
import net.citizensnpcs.trait.versioned.SnifferTrait.SnifferState;
|
||||
@ -262,7 +264,9 @@ public interface NMSBridge {
|
||||
public void setSitting(Tameable tameable, boolean sitting);
|
||||
|
||||
public default void setSneaking(Entity entity, boolean sneaking) {
|
||||
if (entity instanceof Player) {
|
||||
if (entity instanceof NPCHolder) {
|
||||
((NPCHolder) entity).getNPC().getOrAddTrait(SneakTrait.class).setSneaking(sneaking);
|
||||
} else if (entity instanceof Player) {
|
||||
((Player) entity).setSneaking(sneaking);
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import net.minecraft.server.v1_14_R1.DamageSource;
|
||||
import net.minecraft.server.v1_14_R1.Entity;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.EntityPose;
|
||||
import net.minecraft.server.v1_14_R1.EnumGamemode;
|
||||
import net.minecraft.server.v1_14_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_14_R1.EnumProtocolDirection;
|
||||
@ -357,7 +358,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
}
|
||||
dB();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(EntityPose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
dB();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMoveDestination(double x, double y, double z, double speed) {
|
||||
|
@ -1500,9 +1500,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(Player player, boolean sleep) {
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
EntityPose pose = sleep ? EntityPose.SLEEPING : EntityPose.STANDING;
|
||||
try {
|
||||
ENTITY_SETPOSE_METHOD.invoke(getHandle(player), sleep ? EntityPose.SLEEPING : EntityPose.STANDING);
|
||||
ENTITY_SETPOSE.invoke(getHandle(entity), pose);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import net.minecraft.server.v1_15_R1.DamageSource;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.EntityPose;
|
||||
import net.minecraft.server.v1_15_R1.EnumGamemode;
|
||||
import net.minecraft.server.v1_15_R1.EnumItemSlot;
|
||||
import net.minecraft.server.v1_15_R1.EnumProtocolDirection;
|
||||
@ -403,7 +404,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
}
|
||||
dX();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(EntityPose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
dX();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAI() {
|
||||
|
@ -1549,9 +1549,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(Player player, boolean sleep) {
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
EntityPose pose = sleep ? EntityPose.SLEEPING : EntityPose.STANDING;
|
||||
try {
|
||||
ENTITY_SETPOSE_METHOD.invoke(getHandle(player), sleep ? EntityPose.SLEEPING : EntityPose.STANDING);
|
||||
ENTITY_SETPOSE.invoke(getHandle(entity), pose);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import net.minecraft.server.v1_16_R3.DamageSource;
|
||||
import net.minecraft.server.v1_16_R3.Entity;
|
||||
import net.minecraft.server.v1_16_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R3.EntityPose;
|
||||
import net.minecraft.server.v1_16_R3.EnumGamemode;
|
||||
import net.minecraft.server.v1_16_R3.EnumItemSlot;
|
||||
import net.minecraft.server.v1_16_R3.EnumProtocolDirection;
|
||||
@ -368,7 +369,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
}
|
||||
eu();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(EntityPose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
eu();
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePackets(boolean navigating) {
|
||||
|
@ -1573,9 +1573,10 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(Player player, boolean sleep) {
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
EntityPose pose = sleep ? EntityPose.SLEEPING : EntityPose.STANDING;
|
||||
try {
|
||||
ENTITY_SETPOSE_METHOD.invoke(getHandle(player), sleep ? EntityPose.SLEEPING : EntityPose.STANDING);
|
||||
ENTITY_SETPOSE_METHOD.invoke(getHandle(entity), pose);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
@ -161,7 +162,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
entity.playerTouch(this);
|
||||
}
|
||||
}
|
||||
updatePlayerPose();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(Pose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
updatePlayerPose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1567,8 +1567,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(org.bukkit.entity.Player player, boolean sleeping) {
|
||||
getHandle(player).setPose(sleeping ? Pose.SLEEPING : Pose.STANDING);
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
getHandle(entity).setPose(sleep ? Pose.SLEEPING : Pose.STANDING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +49,7 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
@ -162,7 +163,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
entity.playerTouch(this);
|
||||
}
|
||||
}
|
||||
updatePlayerPose();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(Pose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
updatePlayerPose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1575,8 +1575,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(org.bukkit.entity.Player player, boolean sleeping) {
|
||||
getHandle(player).setPose(sleeping ? Pose.SLEEPING : Pose.STANDING);
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
getHandle(entity).setPose(sleep ? Pose.SLEEPING : Pose.STANDING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +49,7 @@ import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
@ -155,7 +156,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
entity.playerTouch(this);
|
||||
}
|
||||
}
|
||||
updatePlayerPose();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(Pose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
updatePlayerPose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1774,8 +1774,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(org.bukkit.entity.Player player, boolean sleeping) {
|
||||
getHandle(player).setPose(sleeping ? Pose.SLEEPING : Pose.STANDING);
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
getHandle(entity).setPose(sleep ? Pose.SLEEPING : Pose.STANDING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +49,7 @@ import net.minecraft.stats.ServerStatsCounter;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
@ -157,7 +158,11 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
entity.playerTouch(this);
|
||||
}
|
||||
}
|
||||
updatePlayerPose();
|
||||
if (npc.data().has(NPC.Metadata.ENTITY_POSE)) {
|
||||
setPose(Pose.valueOf(npc.data().get(NPC.Metadata.ENTITY_POSE)));
|
||||
} else {
|
||||
updatePlayerPose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1770,8 +1770,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(org.bukkit.entity.Player player, boolean sleeping) {
|
||||
getHandle(player).setPose(sleeping ? Pose.SLEEPING : Pose.STANDING);
|
||||
public void sleep(org.bukkit.entity.Player entity, boolean sleep) {
|
||||
getHandle(entity).setPose(sleep ? Pose.SLEEPING : Pose.STANDING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user