diff --git a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java index d7ebaec21..21e1f2019 100644 --- a/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/CommandTrait.java @@ -206,8 +206,9 @@ public class CommandTrait extends Trait { public boolean canUse(Player player, NPCCommand command) { for (String perm : command.perms) { - if (!player.hasPermission(perm)) + if (!player.hasPermission(perm)) { return false; + } } long currentTimeSec = System.currentTimeMillis() / 1000; if (lastUsed.containsKey(command.command)) { diff --git a/main/src/main/java/net/citizensnpcs/trait/ScoreboardTrait.java b/main/src/main/java/net/citizensnpcs/trait/ScoreboardTrait.java index 590e01507..3cd611b13 100644 --- a/main/src/main/java/net/citizensnpcs/trait/ScoreboardTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/ScoreboardTrait.java @@ -13,6 +13,7 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.persistence.Persist; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.TraitName; +import net.citizensnpcs.util.NMS; @TraitName("scoreboardtrait") public class ScoreboardTrait extends Trait { @@ -57,6 +58,9 @@ public class ScoreboardTrait extends Trait { SUPPORT_TEAM_SETOPTION = false; } } + if (!SUPPORT_TEAM_SETOPTION) { + NMS.setTeamNameTagVisible(team, nameVisibility); + } if (npc.data().has(NPC.GLOWING_COLOR_METADATA)) { color = ChatColor.valueOf(npc.data().get(NPC.GLOWING_COLOR_METADATA)); diff --git a/main/src/main/java/net/citizensnpcs/util/NMS.java b/main/src/main/java/net/citizensnpcs/util/NMS.java index f3d90be81..1dcfca703 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMS.java +++ b/main/src/main/java/net/citizensnpcs/util/NMS.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Tameable; import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.mojang.authlib.GameProfile; @@ -417,6 +418,10 @@ public class NMS { BRIDGE.setStepHeight(entity, height); } + public static void setTeamNameTagVisible(Team team, boolean visible) { + BRIDGE.setTeamNameTagVisible(team, visible); + } + public static void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { BRIDGE.setVerticalMovement(bukkitEntity, d); } diff --git a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java index c63cfa79a..19ce31d44 100644 --- a/main/src/main/java/net/citizensnpcs/util/NMSBridge.java +++ b/main/src/main/java/net/citizensnpcs/util/NMSBridge.java @@ -15,6 +15,7 @@ import org.bukkit.entity.Tameable; import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.mojang.authlib.GameProfile; @@ -142,6 +143,8 @@ public interface NMSBridge { public void setStepHeight(Entity entity, float height); + public void setTeamNameTagVisible(Team team, boolean visible); + public void setVerticalMovement(Entity bukkitEntity, double d); public void setWitherCharged(Wither wither, boolean charged); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index 68ce53a9f..4736a55af 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -1,5 +1,6 @@ package net.citizensnpcs.nms.v1_10_R1.util; +import java.lang.invoke.MethodHandle; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.SocketAddress; @@ -40,6 +41,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -193,6 +195,8 @@ import net.minecraft.server.v1_10_R1.PathEntity; import net.minecraft.server.v1_10_R1.PathPoint; import net.minecraft.server.v1_10_R1.PathfinderGoalSelector; import net.minecraft.server.v1_10_R1.ReportedException; +import net.minecraft.server.v1_10_R1.ScoreboardTeam; +import net.minecraft.server.v1_10_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_10_R1.SoundEffect; import net.minecraft.server.v1_10_R1.Vec3D; import net.minecraft.server.v1_10_R1.WorldServer; @@ -940,6 +944,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).P = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1456,6 +1474,7 @@ public class NMSImpl implements NMSBridge { private static final Set 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); + private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle"); private static final float DEFAULT_SPEED = 1F; private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c"); @@ -1473,6 +1492,7 @@ public class NMSImpl implements NMSBridge { private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bx"); private static final Random RANDOM = Util.getFastRandom(); private static Field SKULL_PROFILE_FIELD; + private static MethodHandle TEAM_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"); diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index 76162bbe1..5c1da614c 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -40,6 +40,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -213,6 +214,8 @@ import net.minecraft.server.v1_11_R1.PathPoint; import net.minecraft.server.v1_11_R1.PathfinderGoalSelector; import net.minecraft.server.v1_11_R1.RegistryMaterials; import net.minecraft.server.v1_11_R1.ReportedException; +import net.minecraft.server.v1_11_R1.ScoreboardTeam; +import net.minecraft.server.v1_11_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_11_R1.SoundEffect; import net.minecraft.server.v1_11_R1.Vec3D; import net.minecraft.server.v1_11_R1.WorldServer; @@ -998,6 +1001,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).P = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1520,6 +1537,7 @@ public class NMSImpl implements NMSBridge { private static final Set 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); + private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle"); private static final float DEFAULT_SPEED = 1F; private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c"); @@ -1535,9 +1553,10 @@ public class NMSImpl implements NMSBridge { 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; + private static MethodHandle TEAM_FIELD; + private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bF"); diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index f7cb93238..171afe0d7 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -40,6 +40,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -217,6 +218,8 @@ import net.minecraft.server.v1_12_R1.PathPoint; import net.minecraft.server.v1_12_R1.PathfinderGoalSelector; import net.minecraft.server.v1_12_R1.RegistryMaterials; import net.minecraft.server.v1_12_R1.ReportedException; +import net.minecraft.server.v1_12_R1.ScoreboardTeam; +import net.minecraft.server.v1_12_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_12_R1.SoundEffect; import net.minecraft.server.v1_12_R1.SoundEffects; import net.minecraft.server.v1_12_R1.Vec3D; @@ -1011,6 +1014,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).P = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1507,11 +1524,11 @@ public class NMSImpl implements NMSBridge { if ((entity.width > f2) && (!justCreated) && (!entity.world.isClientSide)) entity.move(EnumMoveType.SELF, (f2 - entity.width) / 2, 0.0D, (f2 - entity.width) / 2); } - }; + } public static void stopNavigation(NavigationAbstract navigation) { navigation.p(); - } + }; public static void updateAI(EntityLiving entity) { if (entity instanceof EntityInsentient) { @@ -1531,6 +1548,7 @@ public class NMSImpl implements NMSBridge { } private static MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class, "bY"); + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST); @@ -1549,9 +1567,10 @@ public class NMSImpl implements NMSBridge { private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "i"); private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bx"); private static final Random RANDOM = Util.getFastRandom(); - private static Field SKULL_PROFILE_FIELD; + private static MethodHandle TEAM_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"); diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index f1c5f5502..d54155114 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -41,6 +41,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -232,6 +233,8 @@ import net.minecraft.server.v1_13_R2.PathPoint; import net.minecraft.server.v1_13_R2.PathfinderGoalSelector; import net.minecraft.server.v1_13_R2.RegistryMaterials; import net.minecraft.server.v1_13_R2.ReportedException; +import net.minecraft.server.v1_13_R2.ScoreboardTeam; +import net.minecraft.server.v1_13_R2.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_13_R2.SoundEffect; import net.minecraft.server.v1_13_R2.SoundEffects; import net.minecraft.server.v1_13_R2.Vec3D; @@ -1046,6 +1049,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).Q = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1639,6 +1656,7 @@ public class NMSImpl implements NMSBridge { } private static MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class, "cf"); + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST, EntityType.SHULKER, @@ -1663,6 +1681,7 @@ public class NMSImpl implements NMSBridge { private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bC"); private static final Random RANDOM = Util.getFastRandom(); private static Field SKULL_PROFILE_FIELD; + private static MethodHandle TEAM_FIELD; private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bL", false); diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index 898748cec..e31841e43 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -43,6 +43,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -254,6 +255,8 @@ import net.minecraft.server.v1_14_R1.PlayerChunkMap; import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker; import net.minecraft.server.v1_14_R1.RegistryBlocks; import net.minecraft.server.v1_14_R1.ReportedException; +import net.minecraft.server.v1_14_R1.ScoreboardTeam; +import net.minecraft.server.v1_14_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_14_R1.SoundEffect; import net.minecraft.server.v1_14_R1.Vec3D; import net.minecraft.server.v1_14_R1.WorldServer; @@ -1093,6 +1096,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).K = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1722,6 +1739,7 @@ public class NMSImpl implements NMSBridge { private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class, "advancementDataPlayer"); + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST, EntityType.SHULKER, @@ -1764,6 +1782,7 @@ public class NMSImpl implements NMSBridge { private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size"); private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size"); private static Field SKULL_PROFILE_FIELD; + private static MethodHandle TEAM_FIELD; static { try { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/trait/Commands.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/trait/Commands.java index d883358d3..d2548f2d2 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/trait/Commands.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/trait/Commands.java @@ -76,7 +76,7 @@ public class Commands { } if (args.hasFlag('n')) { trait.setNectar(!trait.hasNectar()); - output += ' ' + (trait.hasNectar() ? Messaging.tr(Messages.BEE_HAS_NECTAR, npc.getName()) + output += ' ' + (trait.hasStung() ? Messaging.tr(Messages.BEE_HAS_NECTAR, npc.getName()) : Messaging.tr(Messages.BEE_NO_NECTAR, npc.getName())); } if (!output.isEmpty()) { diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 54149a45c..87bc1893d 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -43,6 +43,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -255,6 +256,8 @@ import net.minecraft.server.v1_15_R1.PlayerChunkMap; import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker; import net.minecraft.server.v1_15_R1.RegistryBlocks; import net.minecraft.server.v1_15_R1.ReportedException; +import net.minecraft.server.v1_15_R1.ScoreboardTeam; +import net.minecraft.server.v1_15_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_15_R1.SoundEffect; import net.minecraft.server.v1_15_R1.Vec3D; import net.minecraft.server.v1_15_R1.WorldServer; @@ -1097,6 +1100,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).H = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1712,6 +1729,7 @@ public class NMSImpl implements NMSBridge { private static final MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class, "advancementDataPlayer"); + private static final Set BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.BEE, EntityType.SILVERFISH, EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.DOLPHIN, EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST, @@ -1752,6 +1770,7 @@ public class NMSImpl implements NMSBridge { private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size"); private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size"); private static Field SKULL_PROFILE_FIELD; + private static MethodHandle TEAM_FIELD; static { try { diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java index ffe975fe0..0534e12f3 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/NMSImpl.java @@ -36,6 +36,7 @@ import org.bukkit.entity.Wither; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.PluginLoadOrder; +import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; import com.google.common.base.Function; @@ -167,6 +168,8 @@ import net.minecraft.server.v1_8_R3.PathEntity; import net.minecraft.server.v1_8_R3.PathPoint; import net.minecraft.server.v1_8_R3.PathfinderGoalSelector; import net.minecraft.server.v1_8_R3.ReportedException; +import net.minecraft.server.v1_8_R3.ScoreboardTeam; +import net.minecraft.server.v1_8_R3.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_8_R3.WorldServer; @SuppressWarnings("unchecked") @@ -883,6 +886,20 @@ public class NMSImpl implements NMSBridge { NMSImpl.getHandle(entity).S = height; } + @Override + public void setTeamNameTagVisible(Team team, boolean visible) { + if (TEAM_FIELD == null) { + TEAM_FIELD = NMS.getField(team.getClass(), "team"); + } + ScoreboardTeam nmsTeam; + try { + nmsTeam = (ScoreboardTeam) TEAM_FIELD.get(team); + nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); + } catch (Throwable e) { + e.printStackTrace(); + } + } + @Override public void setVerticalMovement(org.bukkit.entity.Entity bukkitEntity, double d) { if (!bukkitEntity.getType().isAlive()) @@ -1340,6 +1357,7 @@ public class NMSImpl implements NMSBridge { private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "a"); private static final Random RANDOM = Util.getFastRandom(); private static Field SKULL_PROFILE_FIELD; + private static Field TEAM_FIELD; private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c"); static { @@ -1360,4 +1378,5 @@ public class NMSImpl implements NMSBridge { ex.printStackTrace(); } } + }