Skip to content

Commit

Permalink
Improve 1.8 performance by not just catching exceptions. (#1697)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariaum authored and fullwall committed Mar 7, 2019
1 parent 1c9991c commit 7d7bf35
Showing 1 changed file with 20 additions and 9 deletions.
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;
}

0 comments on commit 7d7bf35

Please sign in to comment.