Skip to content

Commit

Permalink
Merge branch 'master' of github.com:CitizensDev/Citizens2
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 28, 2019
2 parents 068b85a + fe69d6c commit aea3cd3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions main/src/main/java/net/citizensnpcs/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public void loadFromKey(DataKey root) {
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", "<b>You selected <a><npc><b>!"),
SERVER_OWNS_NPCS("npc.server-ownership", false),
STORAGE_FILE("storage.file", "saves.yml"),
STORAGE_TYPE("storage.type", "yaml"),
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),
Expand Down
29 changes: 20 additions & 9 deletions main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ public void update() {
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;
Expand All @@ -310,11 +313,15 @@ public void update() {
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
Expand Down Expand Up @@ -346,10 +353,11 @@ public void update() {
}
}

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) {
Expand All @@ -369,4 +377,7 @@ private void updateFlyableState() {
}

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;
}
1 change: 1 addition & 0 deletions main/src/main/java/net/citizensnpcs/trait/FollowTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public boolean toggle(OfflinePlayer player, boolean protect) {
}
this.followingUUID = player.getUniqueId();
if (npc.getNavigator().isNavigating() && this.player != null
&& npc.getNavigator().getEntityTarget() != null
&& this.player == npc.getNavigator().getEntityTarget().getTarget()) {
npc.getNavigator().cancelNavigation();
}
Expand Down
13 changes: 11 additions & 2 deletions main/src/main/java/net/citizensnpcs/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,17 @@ public static boolean matchesItemInHand(Player player, String setting) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float
} 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;
Expand Down Expand Up @@ -1407,12 +1407,12 @@ public static void flyingMoveLogic(EntityLiving entity, float f, float f1, float
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;
Expand Down Expand Up @@ -1619,7 +1619,7 @@ public static void updateNavigation(NavigationAbstract navigation) {
private static final Set<EntityType> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ public PathType a(IBlockAccess var1, int var2, int var3, int var4, int var5, int
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 {
Expand All @@ -202,7 +202,7 @@ public PathType a(IBlockAccess var1, int var2, int var3, int var4, PathType var5
}
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();
Expand Down

0 comments on commit aea3cd3

Please sign in to comment.