diff --git a/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java b/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java index cc5cf9be..f5338e95 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java @@ -55,6 +55,7 @@ import net.momirealms.customfishing.version.VersionManagerImpl; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -120,29 +121,29 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin { @Override public void onDisable() { - ((AdventureManagerImpl) this.adventure).close(); - ((BagManagerImpl) this.bagManager).disable(); - ((BlockManagerImpl) this.blockManager).disable(); - ((EffectManagerImpl) this.effectManager).disable(); - ((FishingManagerImpl) this.fishingManager).disable(); - ((GameManagerImpl) this.gameManager).disable(); - ((ItemManagerImpl) this.itemManager).disable(); - ((LootManagerImpl) this.lootManager).disable(); - ((MarketManagerImpl) this.marketManager).disable(); - ((EntityManagerImpl) this.entityManager).disable(); - ((RequirementManagerImpl) this.requirementManager).disable(); - ((SchedulerImpl) this.scheduler).shutdown(); - ((IntegrationManagerImpl) this.integrationManager).disable(); - ((CompetitionManagerImpl) this.competitionManager).disable(); - ((StorageManagerImpl) this.storageManager).disable(); - ((PlaceholderManagerImpl) this.placeholderManager).disable(); - ((StatisticsManagerImpl) this.statisticsManager).disable(); - ((ActionManagerImpl) this.actionManager).disable(); - ((TotemManagerImpl) this.totemManager).disable(); - ((HookManagerImpl) this.hookManager).disable(); - this.coolDownManager.disable(); - this.chatCatcherManager.disable(); - this.commandManager.unload(); + if (this.adventure != null) ((AdventureManagerImpl) this.adventure).close(); + if (this.bagManager != null) ((BagManagerImpl) this.bagManager).disable(); + if (this.blockManager != null) ((BlockManagerImpl) this.blockManager).disable(); + if (this.effectManager != null) ((EffectManagerImpl) this.effectManager).disable(); + if (this.fishingManager != null) ((FishingManagerImpl) this.fishingManager).disable(); + if (this.gameManager != null) ((GameManagerImpl) this.gameManager).disable(); + if (this.itemManager != null) ((ItemManagerImpl) this.itemManager).disable(); + if (this.lootManager != null) ((LootManagerImpl) this.lootManager).disable(); + if (this.marketManager != null) ((MarketManagerImpl) this.marketManager).disable(); + if (this.entityManager != null) ((EntityManagerImpl) this.entityManager).disable(); + if (this.requirementManager != null) ((RequirementManagerImpl) this.requirementManager).disable(); + if (this.scheduler != null) ((SchedulerImpl) this.scheduler).shutdown(); + if (this.integrationManager != null) ((IntegrationManagerImpl) this.integrationManager).disable(); + if (this.competitionManager != null) ((CompetitionManagerImpl) this.competitionManager).disable(); + if (this.storageManager != null) ((StorageManagerImpl) this.storageManager).disable(); + if (this.placeholderManager != null) ((PlaceholderManagerImpl) this.placeholderManager).disable(); + if (this.statisticsManager != null) ((StatisticsManagerImpl) this.statisticsManager).disable(); + if (this.actionManager != null) ((ActionManagerImpl) this.actionManager).disable(); + if (this.totemManager != null) ((TotemManagerImpl) this.totemManager).disable(); + if (this.hookManager != null) ((HookManagerImpl) this.hookManager).disable(); + if (this.coolDownManager != null) this.coolDownManager.disable(); + if (this.chatCatcherManager != null) this.chatCatcherManager.disable(); + if (this.commandManager != null) this.commandManager.unload(); HandlerList.unregisterAll(this); } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java index 1da461b1..cd4da07d 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java @@ -93,7 +93,7 @@ public class Competition implements FishingCompetition { Action[] actions = config.getStartActions(); if (actions != null) { - Condition condition = new Condition(null, null, new HashMap<>()); + Condition condition = new Condition(null, null, this.publicPlaceholders); for (Action action : actions) { action.trigger(condition); } @@ -186,14 +186,14 @@ public class Competition implements FishingCompetition { Player player = Bukkit.getPlayer(competitionPlayer.left()); if (player != null) for (Action action : rewardsMap.get(String.valueOf(i))) - action.trigger(new Condition(player)); + action.trigger(new Condition(player, this.publicPlaceholders)); } else { Action[] actions = rewardsMap.get("participation"); if (actions != null) { Player player = Bukkit.getPlayer(competitionPlayer.left()); { if (player != null) for (Action action : actions) - action.trigger(new Condition(player)); + action.trigger(new Condition(player, this.publicPlaceholders)); } } } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java index cc19fb60..480dd131 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java @@ -44,6 +44,8 @@ import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -199,6 +201,7 @@ public class RequirementManagerImpl implements RequirementManager { this.registerCompetitionRequirement(); this.registerListRequirement(); this.registerEnvironmentRequirement(); + this.registerPotionEffectRequirement(); } public HashMap getLootWithWeight(Condition condition) { @@ -1139,11 +1142,59 @@ public class RequirementManagerImpl implements RequirementManager { }; } else { LogUtils.warn("Wrong value format found at plugin-level requirement."); - return null; + return EmptyRequirement.instance; } }); } + + private void registerPotionEffectRequirement() { + registerRequirement("potion-effect", (args, actions, advanced) -> { + String potions = (String) args; + String[] split = potions.split("(<=|>=|<|>|==)", 2); + PotionEffectType type = PotionEffectType.getByName(split[0]); + if (type == null) { + LogUtils.warn("Potion effect doesn't exist: " + split[0]); + return EmptyRequirement.instance; + } + int required = Integer.parseInt(split[1]); + String operator = potions.substring(split[0].length(), potions.length() - split[1].length()); + return condition -> { + int level = -1; + PotionEffect potionEffect = condition.getPlayer().getPotionEffect(type); + if (potionEffect != null) { + level = potionEffect.getAmplifier(); + } + boolean result = false; + switch (operator) { + case ">=" -> { + if (level >= required) result = true; + } + case ">" -> { + if (level > required) result = true; + } + case "==" -> { + if (level == required) result = true; + } + case "!=" -> { + if (level != required) result = true; + } + case "<=" -> { + if (level <= required) result = true; + } + case "<" -> { + if (level < required) result = true; + } + } + if (result) { + return true; + } + if (advanced) triggerActions(actions, condition); + return false; + }; + }); + } + /** * Triggers a list of actions with the given condition. * If the list of actions is not null, each action in the list is triggered.