Skip to content

Commit

Permalink
Catch NullPointerException.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed May 9, 2018
1 parent bd24e12 commit d0235e2
Showing 1 changed file with 18 additions and 12 deletions.
Expand Up @@ -107,19 +107,18 @@ public UseEntityAdapter(Plugin plugin) {
"checks", Arrays.asList(AttackFrequency.class.getSimpleName()));
}
attackFrequency = new AttackFrequency();
NCPAPIProvider.getNoCheatPlusAPI().addComponent(attackFrequency);
this.legacySet = getLegacyReflectionSet();
}

LegacyReflectionSet set = null;
private LegacyReflectionSet getLegacyReflectionSet() {
for (String versionDetail : new String[] {"v1_7_R4", "v1_7_R1"}) {
try {
set = new LegacyReflectionSet(versionDetail);
if (set != null) {
break;
}
return new LegacyReflectionSet(versionDetail);
}
catch (RuntimeException e) {} // +-
}
this.legacySet = set;
NCPAPIProvider.getNoCheatPlusAPI().addComponent(attackFrequency);
return null;
}

@Override
Expand Down Expand Up @@ -158,11 +157,18 @@ public void onPacketReceiving(final PacketEvent event) {
}
if (!packetInterpreted) {
// Handle as if latest.
final StructureModifier<EntityUseAction> actions;
actions = packet.getEntityUseActions();
if (actions.size() == 1 && actions.read(0) == EntityUseAction.ATTACK) {
isAttack = true;
packetInterpreted = true;
try {
final StructureModifier<EntityUseAction> actions = packet.getEntityUseActions();
if (actions.size() == 1 && actions.read(0) == EntityUseAction.ATTACK) {
isAttack = true;
packetInterpreted = true;
}
}
catch (NullPointerException e) {
/*
* TODO: Observed somewhere on 1_7_R4, probably a custom build -
* why doesn't the LegacyReflectionSet work here?
*/
}
}
if (!packetInterpreted) {
Expand Down

0 comments on commit d0235e2

Please sign in to comment.