Skip to content

Commit

Permalink
use modern java instanceof in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 11, 2023
1 parent 3962553 commit 3be9462
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 57 deletions.
Expand Up @@ -57,8 +57,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String val = ((ElementTag) determinationObj).asString();
if (determinationObj instanceof ElementTag element) {
String val = element.asString();
if (val.startsWith("fuel_power:")) {
event.setFuelPower(Integer.parseInt(val.substring("fuel_power:".length())));
return true;
Expand Down
Expand Up @@ -71,8 +71,8 @@ else if (!changeType.equals("changes")) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setNewLevel(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setNewLevel(element.asInt());
}
return super.applyDetermination(path, determinationObj);
}
Expand Down
Expand Up @@ -54,8 +54,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setBurnTime(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setBurnTime(element.asInt());
return true;
}
else if (determinationObj.canBeType(DurationTag.class)) {
Expand Down
Expand Up @@ -50,8 +50,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setNewCurrent(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setNewCurrent(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -62,8 +62,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setAmount(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setAmount(element.asInt());
return true;
}
else if (DurationTag.matches(determinationObj.toString())) {
Expand Down
Expand Up @@ -63,8 +63,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
experience = ((ElementTag) determinationObj).asInt();
if (determinationObj instanceof ElementTag element && element.isInt()) {
experience = element.asInt();
event.setExperience(experience);
return true;
}
Expand Down
Expand Up @@ -64,8 +64,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setDuration(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setDuration(element.asInt());
return true;
}
else if (DurationTag.matches(determinationObj.toString())) {
Expand Down
Expand Up @@ -114,20 +114,20 @@ else if (lower.equals("no_xp")) {
event.setDroppedExp(0);
return true;
}
else if (lower.equals("keep_inv") && event instanceof PlayerDeathEvent) {
((PlayerDeathEvent) event).setKeepInventory(true);
else if (lower.equals("keep_inv") && event instanceof PlayerDeathEvent playerEvent) {
playerEvent.setKeepInventory(true);
return true;
}
else if (lower.equals("keep_level") && event instanceof PlayerDeathEvent) {
((PlayerDeathEvent) event).setKeepLevel(true);
else if (lower.equals("keep_level") && event instanceof PlayerDeathEvent playerEvent) {
playerEvent.setKeepLevel(true);
return true;
}
else if (lower.equals("no_message") && event instanceof PlayerDeathEvent) {
((PlayerDeathEvent) event).setDeathMessage(null);
else if (lower.equals("no_message") && event instanceof PlayerDeathEvent playerEvent) {
playerEvent.setDeathMessage(null);
return true;
}
else if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setDroppedExp(((ElementTag) determinationObj).asInt());
else if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setDroppedExp(element.asInt());
return true;
}
else if (Argument.valueOf(lower).matchesArgumentList(ItemTag.class)) {
Expand All @@ -140,8 +140,8 @@ else if (Argument.valueOf(lower).matchesArgumentList(ItemTag.class)) {
}
return true;
}
else if (event instanceof PlayerDeathEvent) {
PaperAPITools.instance.setDeathMessage((PlayerDeathEvent) event, determination);
else if (event instanceof PlayerDeathEvent playerEvent) {
PaperAPITools.instance.setDeathMessage(playerEvent, determination);
return true;
}
else {
Expand All @@ -160,10 +160,10 @@ public ObjectTag getContext(String name) {
case "entity": return entity.getDenizenObject();
case "projectile": return projectile == null ? null : projectile.getDenizenObject();
case "damager": return damager == null ? null : damager.getDenizenObject();
case "message": return event instanceof PlayerDeathEvent ? new ElementTag(PaperAPITools.instance.getDeathMessage((PlayerDeathEvent) event)) : null;
case "message": return event instanceof PlayerDeathEvent playerEvent ? new ElementTag(PaperAPITools.instance.getDeathMessage(playerEvent)) : null;
case "cause": return cause;
case "xp": return new ElementTag(event.getDroppedExp());
case "keep_inventory": return event instanceof PlayerDeathEvent ? new ElementTag(((PlayerDeathEvent) event).getKeepInventory()) : null;
case "keep_inventory": return event instanceof PlayerDeathEvent playerEvent ? new ElementTag(playerEvent.getKeepInventory()) : null;
case "drops":
ListTag list = new ListTag();
for (ItemStack stack : event.getDrops()) {
Expand All @@ -176,8 +176,8 @@ public ObjectTag getContext(String name) {

@Override
public void cancellationChanged() {
if (cancelled && event instanceof PlayerDeathEvent) {
((PlayerDeathEvent) event).setDeathMessage(null); // Historical no_message was by cancelling.
if (cancelled && event instanceof PlayerDeathEvent playerEvent) {
playerEvent.setDeathMessage(null); // Historical no_message was by cancelling.
}
super.cancellationChanged();
}
Expand All @@ -193,8 +193,8 @@ public void onEntityDeath(EntityDeathEvent event) {
EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
if (lastDamage != null) {
cause = new ElementTag(event.getEntity().getLastDamageCause().getCause().toString());
if (lastDamage instanceof EntityDamageByEntityEvent) {
damager = new EntityTag(((EntityDamageByEntityEvent) lastDamage).getDamager());
if (lastDamage instanceof EntityDamageByEntityEvent byEntEvent) {
damager = new EntityTag(byEntEvent.getDamager());
EntityTag shooter = damager.getShooter();
if (damager instanceof Projectile) {
projectile = damager;
Expand Down
Expand Up @@ -69,8 +69,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && determinationObj.asElement().isInt()) {
event.setFoodLevel(determinationObj.asElement().asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setFoodLevel(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -62,8 +62,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isDouble()) {
event.setAmount(((ElementTag) determinationObj).asDouble());
if (determinationObj instanceof ElementTag element && element.isDouble()) {
event.setAmount(element.asDouble());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -95,8 +95,8 @@ else if (!runGenericCheck(attacker, event.getCause().name())) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isDouble()) {
event.setDamage(((ElementTag) determinationObj).asDouble());
if (determinationObj instanceof ElementTag element && element.isDouble()) {
event.setDamage(element.asDouble());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -78,8 +78,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isFloat()) {
event.setPower(((ElementTag) determinationObj).asFloat());
if (determinationObj instanceof ElementTag element && element.isFloat()) {
event.setPower(element.asFloat());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -62,8 +62,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setCount(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setCount(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -55,8 +55,8 @@ public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
event.setRecipe(determinationObj.asType(TradeTag.class, getTagContext(path)).getRecipe());
return true;
}
else if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setBonus(((ElementTag) determinationObj).asInt());
else if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setBonus(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -89,9 +89,9 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
if (((ElementTag) determinationObj).isInt()) {
cost = ((ElementTag) determinationObj).asInt();
if (determinationObj instanceof ElementTag element) {
if (element.isInt()) {
cost = element.asInt();
event.setExpLevelCost(cost);
return true;
}
Expand Down
Expand Up @@ -59,8 +59,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setAmount(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setAmount(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -76,8 +76,8 @@ public ObjectTag getContext(String name) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setDamage(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setDamage(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -73,8 +73,8 @@ public ObjectTag getContext(String name) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.setRepairAmount(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.setRepairAmount(element.asInt());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down
Expand Up @@ -71,8 +71,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
event.getInventory().setRepairCost(((ElementTag) determinationObj).asInt());
if (determinationObj instanceof ElementTag element && element.isInt()) {
event.getInventory().setRepairCost(element.asInt());
return true;
}
String determination = determinationObj.toString();
Expand Down
Expand Up @@ -68,8 +68,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
int xp = ((ElementTag) determinationObj).asInt();
if (determinationObj instanceof ElementTag element && element.isInt()) {
int xp = element.asInt();
event.setExpToDrop(xp);
return true;
}
Expand Down
Expand Up @@ -96,8 +96,8 @@ public boolean matches(ScriptPath path) {

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isDouble()) {
event.setDamage(((ElementTag) determinationObj).asDouble());
if (determinationObj instanceof ElementTag element && element.isDouble()) {
event.setDamage(element.asDouble());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand Down

0 comments on commit 3be9462

Please sign in to comment.