|
15 | 15 | import org.bukkit.block.BlockFace; |
16 | 16 | import org.bukkit.entity.Player; |
17 | 17 | import org.bukkit.inventory.ItemStack; |
| 18 | +import org.bukkit.potion.PotionEffect; |
18 | 19 | import org.bukkit.potion.PotionEffectType; |
19 | 20 | import org.jetbrains.annotations.NotNull; |
20 | 21 | import org.jetbrains.annotations.Nullable; |
@@ -72,13 +73,6 @@ public Map<String, Object> getDefaults() { |
72 | 73 |
|
73 | 74 | @Override |
74 | 75 | public boolean canRegister() { |
75 | | - /*pingFormatter = new PingFormatter( |
76 | | - getInt("ping_value.medium", 50), |
77 | | - getInt("ping_value.high", 100), |
78 | | - getString("ping_color.low", "&a"), |
79 | | - getString("ping_color.medium", "&e"), |
80 | | - getString("ping_color.high", "&c") |
81 | | - );*/ |
82 | 76 | pingFormatter = new PingFormatter(getConfigSection("ping.formatting")); |
83 | 77 | directionNames = Optional.ofNullable(getConfigSection("direction")) |
84 | 78 | .map(section -> section.getValues(false)) |
@@ -457,10 +451,31 @@ public boolean canRegister() { |
457 | 451 | // has_potioneffect_<effect> |
458 | 452 | if (params.startsWith("has_potioneffect_")) { |
459 | 453 | final String effectName = params.substring("has_potioneffect_".length()); |
460 | | - return Optional.ofNullable(PotionEffectType.getByName(effectName)) |
461 | | - .map(player::hasPotionEffect) |
| 454 | + final Optional<PotionEffectType> effectType = Optional.ofNullable(PotionEffectType.getByName(effectName)); |
| 455 | + |
| 456 | + if (effectType.isEmpty()) { |
| 457 | + return "Unknown potion effect " + effectName; |
| 458 | + } |
| 459 | + |
| 460 | + return effectType.map(player::hasPotionEffect) |
462 | 461 | .map(this::bool) |
463 | | - .orElse("Unknown potion effect " + effectName); |
| 462 | + .get(); |
| 463 | + } |
| 464 | + |
| 465 | + // potion_effect_level_<effect> |
| 466 | + if (params.startsWith("potion_effect_level_")) { |
| 467 | + final String effectName = params.substring("potion_effect_level_".length()); |
| 468 | + final Optional<PotionEffectType> effectType = Optional.ofNullable(PotionEffectType.getByName(effectName)); |
| 469 | + |
| 470 | + if (effectType.isEmpty()) { |
| 471 | + return "Unknown potion effect " + effectName; |
| 472 | + } |
| 473 | + |
| 474 | + return effectType.filter(player::hasPotionEffect) |
| 475 | + .map(player::getPotionEffect) |
| 476 | + .map(PotionEffect::getAmplifier) |
| 477 | + .map(String::valueOf) |
| 478 | + .orElse("0"); |
464 | 479 | } |
465 | 480 |
|
466 | 481 | // item_in_hand_level_<enchantment name or key> |
|
0 commit comments