From 7d7bf356de8eca88a83aa30be8b90e225eec470e Mon Sep 17 00:00:00 2001 From: mariaum Date: Thu, 7 Mar 2019 13:12:29 -0300 Subject: [PATCH 1/4] Improve 1.8 performance by not just catching exceptions. (#1697) --- .../net/citizensnpcs/npc/CitizensNPC.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index d92f162c0..e47ebc6a6 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -287,9 +287,12 @@ public class CitizensNPC extends AbstractNPC { NMS.trySwim(getEntity()); } navigator.run(); - try { - getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false)); - } catch (NoSuchMethodError e) { + if (SUPPORT_GLOWING) { + try { + getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false)); + } catch (NoSuchMethodError e) { + SUPPORT_GLOWING = false; + } } if (!getNavigator().isNavigating() && updateCounter++ > Setting.PACKET_UPDATE_DELAY.asInt()) { updateCounter = 0; @@ -310,11 +313,15 @@ public class CitizensNPC extends AbstractNPC { team.unregister(); data().remove(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA); } else { - try { - team.setOption(Option.NAME_TAG_VISIBILITY, - nameVisibility ? OptionStatus.ALWAYS : OptionStatus.NEVER); - } catch (NoSuchMethodError e) { - } catch (NoClassDefFoundError e) { + if (SUPPORT_TEAM_SETOPTION) { + try { + team.setOption(Option.NAME_TAG_VISIBILITY, + nameVisibility ? OptionStatus.ALWAYS : OptionStatus.NEVER); + } catch (NoSuchMethodError e) { + SUPPORT_TEAM_SETOPTION = false; + } catch (NoClassDefFoundError e) { + SUPPORT_TEAM_SETOPTION = false; + } } if (data().has(NPC.GLOWING_COLOR_METADATA)) { if (team.getPrefix() == null || team.getPrefix().length() == 0 @@ -346,10 +353,11 @@ public class CitizensNPC extends AbstractNPC { } } - if (data().has(NPC.SILENT_METADATA)) { + if (SUPPORT_SILENT && data().has(NPC.SILENT_METADATA)) { try { getEntity().setSilent(Boolean.parseBoolean(data().get(NPC.SILENT_METADATA).toString())); } catch (NoSuchMethodError e) { + SUPPORT_SILENT = false; } } } catch (Exception ex) { @@ -369,4 +377,7 @@ public class CitizensNPC extends AbstractNPC { } private static final String NPC_METADATA_MARKER = "NPC"; + private static boolean SUPPORT_SILENT = true; + private static boolean SUPPORT_GLOWING = true; + private static boolean SUPPORT_TEAM_SETOPTION = true; } From 7c348bff1319df50b6cf828ca1ceb2befd6a39a8 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Fri, 8 Mar 2019 22:19:31 -0800 Subject: [PATCH 2/4] Update quick-select and talk items to material names (#1710) also add back-support for if the original IDs are used (there's no good generic legacy ID upverter, but recognizing the old default numbers should suffice for 99% of servers). Should be cross-compatible with all supported minecraft versions, but is *required* in particular for 1.13 --- main/src/main/java/net/citizensnpcs/Settings.java | 4 ++-- main/src/main/java/net/citizensnpcs/util/Util.java | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/Settings.java b/main/src/main/java/net/citizensnpcs/Settings.java index 62c6073cd..b9df04af1 100644 --- a/main/src/main/java/net/citizensnpcs/Settings.java +++ b/main/src/main/java/net/citizensnpcs/Settings.java @@ -114,7 +114,7 @@ public class Settings { QUICK_SELECT("npc.selection.quick-select", false), REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true), SAVE_TASK_DELAY("storage.save-task.delay", 20 * 60 * 60), - SELECTION_ITEM("npc.selection.item", "280"), + SELECTION_ITEM("npc.selection.item", "stick"), SELECTION_MESSAGE("npc.selection.message", "You selected !"), SERVER_OWNS_NPCS("npc.server-ownership", false), STORAGE_FILE("storage.file", "saves.yml"), @@ -122,7 +122,7 @@ public class Settings { SUBPLUGIN_FOLDER("subplugins.folder", "plugins"), TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 5), TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 10), - TALK_ITEM("npc.text.talk-item", "340"), + TALK_ITEM("npc.text.talk-item", "book"), TELEPORT_DELAY("npc.teleport-delay", -1), USE_BOAT_CONTROLS("npc.controllable.use-boat-controls", true), USE_NEW_PATHFINDER("npc.pathfinding.use-new-finder", false), diff --git a/main/src/main/java/net/citizensnpcs/util/Util.java b/main/src/main/java/net/citizensnpcs/util/Util.java index 2286c5bf2..b3859737d 100644 --- a/main/src/main/java/net/citizensnpcs/util/Util.java +++ b/main/src/main/java/net/citizensnpcs/util/Util.java @@ -237,8 +237,17 @@ public class Util { if (parts.contains("*")) return true; for (String part : Splitter.on(',').split(parts)) { - if ((SpigotUtil.isUsing1_13API() ? Material.matchMaterial(part, true) - : Material.matchMaterial(part)) == player.getInventory().getItemInHand().getType()) { + Material matchMaterial = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(part, true) + : Material.matchMaterial(part); + if (matchMaterial == null) { + if (part.equals("280")) { + matchMaterial = Material.STICK; + } + else if (part.equals("340")) { + matchMaterial = Material.BOOK; + } + } + if (matchMaterial == player.getInventory().getItemInHand().getType()) { return true; } } From 2d0370a55e80aeb64cbd82c916aa13f648ba2ce6 Mon Sep 17 00:00:00 2001 From: mcmonkey Date: Sat, 9 Mar 2019 10:36:48 -0800 Subject: [PATCH 3/4] patch NPE in followTrait#toggle --- main/src/main/java/net/citizensnpcs/trait/FollowTrait.java | 1 + 1 file changed, 1 insertion(+) diff --git a/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java b/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java index 4468d7e15..462091c30 100644 --- a/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/FollowTrait.java @@ -62,6 +62,7 @@ public class FollowTrait extends Trait { } this.followingUUID = player.getUniqueId(); if (npc.getNavigator().isNavigating() && this.player != null + && npc.getNavigator().getEntityTarget() != null && this.player == npc.getNavigator().getEntityTarget().getTarget()) { npc.getNavigator().cancelNavigation(); } From fe69d6c0b88408d4750e33a1ee23f176d2d7b18c Mon Sep 17 00:00:00 2001 From: mcmonkey Date: Sat, 16 Mar 2019 20:36:45 -0700 Subject: [PATCH 4/4] (BREAKING) initial patch for 1.13 NMS repatch --- .../java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java | 8 ++++---- .../nms/v1_13_R2/util/PlayerPathfinderNormal.java | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) 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 fb55a4d49..a88be6562 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 @@ -1320,7 +1320,7 @@ public class NMSImpl implements NMSBridge { } else { float f9 = 0.91F; BoundingBox bb = NMSBoundingBox.wrap(entity.getBoundingBox()); - BlockPosition.b blockposition_b = BlockPosition.b.d(entity.locX, bb.minY - 1.0D, entity.locZ); + BlockPosition.PooledBlockPosition blockposition_b = BlockPosition.PooledBlockPosition.d(entity.locX, bb.minY - 1.0D, entity.locZ); Throwable throwable = null; float f4; float f3; @@ -1407,12 +1407,12 @@ public class NMSImpl implements NMSBridge { entity.aK += entity.aJ; } - private static BlockPosition.b getBlockPositionBE(BlockPosition.b blockPos, double x, double y, double z) { + private static BlockPosition.PooledBlockPosition getBlockPositionBE(BlockPosition.PooledBlockPosition blockPos, double x, double y, double z) { try { return blockPos.c(x, y, z); } catch (NoSuchMethodError ex) { try { - return (BlockPosition.b) BLOCK_POSITION_B_D.invoke(blockPos, x, y, z); + return (BlockPosition.PooledBlockPosition) BLOCK_POSITION_B_D.invoke(blockPos, x, y, z); } catch (Throwable ex2) { ex2.printStackTrace(); return null; @@ -1619,7 +1619,7 @@ public class NMSImpl implements NMSBridge { 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); - private static final Method BLOCK_POSITION_B_D = NMS.getMethod(BlockPosition.b.class, "e", false, double.class, + private static final Method BLOCK_POSITION_B_D = NMS.getMethod(BlockPosition.PooledBlockPosition.class, "e", false, double.class, double.class, double.class); private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle"); private static final float DEFAULT_SPEED = 1F; diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerPathfinderNormal.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerPathfinderNormal.java index f34f78dd3..5a9e0e87b 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerPathfinderNormal.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/PlayerPathfinderNormal.java @@ -185,11 +185,11 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { return var11; } - private static final Method BLOCK_POSITION_B_C = NMS.getMethod(BlockPosition.b.class, "f", false, int.class, int.class, int.class); + private static final Method BLOCK_POSITION_B_C = NMS.getMethod(BlockPosition.PooledBlockPosition.class, "f", false, int.class, int.class, int.class); public PathType a(IBlockAccess var1, int var2, int var3, int var4, PathType var5) { if (var5 == PathType.WALKABLE) { - BlockPosition.b var6 = BlockPosition.b.r(); + BlockPosition.PooledBlockPosition var6 = BlockPosition.PooledBlockPosition.r(); Throwable var7 = null; try { @@ -202,7 +202,7 @@ public class PlayerPathfinderNormal extends PlayerPathfinderAbstract { } catch (NoSuchMethodError ex) { try { - blockPos = (BlockPosition.b) BLOCK_POSITION_B_C.invoke(var6, var8 + var2, var3, var9 + var4); + blockPos = (BlockPosition.PooledBlockPosition) BLOCK_POSITION_B_C.invoke(var6, var8 + var2, var3, var9 + var4); } catch (Throwable ex2) { ex2.printStackTrace();