Some conditions only need at least one present

This commit is contained in:
PikaMug 2022-05-09 02:41:08 -04:00
parent 74d071ffe8
commit ea6e50a49f

View File

@ -171,19 +171,21 @@ public class Condition implements ICondition {
final Player player = quester.getPlayer(); final Player player = quester.getPlayer();
boolean failed = false; boolean failed = false;
if (!entitiesWhileRiding.isEmpty()) { if (!entitiesWhileRiding.isEmpty()) {
boolean atLeastOne = false;
for (final String e : entitiesWhileRiding) { for (final String e : entitiesWhileRiding) {
if (player.getVehicle() == null) { if (player.getVehicle() == null) {
return false; return false;
} }
if (!player.getVehicle().getType().equals(MiscUtil.getProperMobType(e))) { if (player.getVehicle().getType().equals(MiscUtil.getProperMobType(e))) {
failed = true; atLeastOne = true;
if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition entity mismatch for " + player.getName() + ": " + e);
}
break; break;
} }
} }
if (!atLeastOne) {
failed = true;
}
} else if (!npcsWhileRiding.isEmpty()) { } else if (!npcsWhileRiding.isEmpty()) {
boolean atLeastOne = false;
for (final UUID n : npcsWhileRiding) { for (final UUID n : npcsWhileRiding) {
if (plugin.getDependencies().getCitizens() == null) { if (plugin.getDependencies().getCitizens() == null) {
plugin.getLogger().warning("Citizens must be installed for condition ride NPC UUID " + n); plugin.getLogger().warning("Citizens must be installed for condition ride NPC UUID " + n);
@ -192,17 +194,17 @@ public class Condition implements ICondition {
if (player.getVehicle() == null) { if (player.getVehicle() == null) {
return false; return false;
} }
if (!player.getVehicle().equals(plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(n) if (player.getVehicle().equals(plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(n)
.getEntity())) { .getEntity())) {
failed = true; atLeastOne = true;
if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition ride NPC mismatch for " + player.getName()
+ ": NPC UUID " + n);
}
break; break;
} }
} }
if (!atLeastOne) {
failed = true;
}
} else if (!permissions.isEmpty()) { } else if (!permissions.isEmpty()) {
// Must have ALL listed permissions
for (final String p : permissions) { for (final String p : permissions) {
if (plugin.getDependencies().isPluginAvailable("Vault")) { if (plugin.getDependencies().isPluginAvailable("Vault")) {
plugin.getLogger().warning("Vault must be installed for condition permission checks: " + p); plugin.getLogger().warning("Vault must be installed for condition permission checks: " + p);
@ -218,43 +220,45 @@ public class Condition implements ICondition {
} }
} }
} else if (!itemsWhileHoldingMainHand.isEmpty()) { } else if (!itemsWhileHoldingMainHand.isEmpty()) {
boolean atLeastOne = false;
for (final ItemStack is : itemsWhileHoldingMainHand) { for (final ItemStack is : itemsWhileHoldingMainHand) {
if (ItemUtil.compareItems(player.getItemInHand(), is, true, true) != 0) { if (ItemUtil.compareItems(player.getItemInHand(), is, true, true) == 0) {
failed = true; atLeastOne = true;
if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition item mismatch for " + player.getName() + ": code "
+ ItemUtil.compareItems(player.getItemInHand(), is, true, true));
}
break; break;
} }
} }
if (!atLeastOne) {
failed = true;
}
} else if (!worldsWhileStayingWithin.isEmpty()) { } else if (!worldsWhileStayingWithin.isEmpty()) {
boolean atLeastOne = false;
for (final String w : worldsWhileStayingWithin) { for (final String w : worldsWhileStayingWithin) {
if (!player.getWorld().getName().equalsIgnoreCase(w)) { if (player.getWorld().getName().equalsIgnoreCase(w)) {
failed = true; atLeastOne = true;
if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition world mismatch for " + player.getName() + ": " + w);
}
break; break;
} }
} }
if (!atLeastOne) {
failed = true;
}
} else if (!biomesWhileStayingWithin.isEmpty()) { } else if (!biomesWhileStayingWithin.isEmpty()) {
boolean atLeastOne = false;
for (final String b : biomesWhileStayingWithin) { for (final String b : biomesWhileStayingWithin) {
if (MiscUtil.getProperBiome(b) == null) { if (MiscUtil.getProperBiome(b) == null) {
plugin.getLogger().warning("Invalid entry for condition biome checks: " + b); plugin.getLogger().warning("Invalid entry for condition biome checks: " + b);
return false; return false;
} }
if (!player.getWorld().getBiome(player.getLocation().getBlockX(), player.getLocation().getBlockZ()) if (player.getWorld().getBiome(player.getLocation().getBlockX(), player.getLocation().getBlockZ())
.name().equalsIgnoreCase(Objects.requireNonNull(MiscUtil.getProperBiome(b)).name())) { .name().equalsIgnoreCase(Objects.requireNonNull(MiscUtil.getProperBiome(b)).name())) {
failed = true; atLeastOne = true;
if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition biome mismatch for " + player.getName() + ": "
+ MiscUtil.getProperBiome(b));
}
break; break;
} }
} }
if (!atLeastOne) {
failed = true;
}
} else if (!regionsWhileStayingWithin.isEmpty()) { } else if (!regionsWhileStayingWithin.isEmpty()) {
// Must be within ALL listed regions
for (final String r : regionsWhileStayingWithin) { for (final String r : regionsWhileStayingWithin) {
if (!quester.isInRegion(r)) { if (!quester.isInRegion(r)) {
failed = true; failed = true;
@ -265,6 +269,7 @@ public class Condition implements ICondition {
} }
} }
} else if (!placeholdersCheckIdentifier.isEmpty()) { } else if (!placeholdersCheckIdentifier.isEmpty()) {
// Must have ALL listed placeholders equal true
int index = 0; int index = 0;
for (final String i : placeholdersCheckIdentifier) { for (final String i : placeholdersCheckIdentifier) {
if (plugin.getDependencies().isPluginAvailable("PlaceholderAPI")) { if (plugin.getDependencies().isPluginAvailable("PlaceholderAPI")) {