From b149e08ba1fdc5517b23b88170f96d59b94e468b Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:42:49 +0800 Subject: [PATCH] 2.2.21 --- .../api/BukkitCustomFishingPlugin.java | 11 + .../api/mechanic/action/ActionManager.java | 6 +- .../api/mechanic/action/ActionTrigger.java | 3 +- .../mechanic/game/AbstractGamingPlayer.java | 1 + .../api/mechanic/misc/hologram/Hologram.java | 74 ++++ .../misc/hologram/HologramManager.java | 100 ++++++ .../requirement/RequirementManager.java | 4 +- .../integration/region/WorldGuardRegion.java | 4 +- .../bukkit/BukkitCustomFishingPluginImpl.java | 4 + .../bukkit/action/BukkitActionManager.java | 211 +++++------ .../requirement/BukkitRequirementManager.java | 336 +++++++++++------- .../bukkit/scheduler/impl/BukkitExecutor.java | 4 + .../bukkit/totem/ActivatedTotem.java | 6 + .../bukkit/totem/BukkitTotemManager.java | 23 +- core/src/main/resources/config.yml | 2 + .../main/resources/contents/totem/default.yml | 10 +- gradle.properties | 4 +- 17 files changed, 541 insertions(+), 262 deletions(-) create mode 100644 api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/Hologram.java create mode 100644 api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/HologramManager.java diff --git a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java index 4ec18c7b..493283cb 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java +++ b/api/src/main/java/net/momirealms/customfishing/api/BukkitCustomFishingPlugin.java @@ -33,6 +33,7 @@ import net.momirealms.customfishing.api.mechanic.item.ItemManager; import net.momirealms.customfishing.api.mechanic.loot.LootManager; import net.momirealms.customfishing.api.mechanic.market.MarketManager; import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; +import net.momirealms.customfishing.api.mechanic.misc.hologram.HologramManager; import net.momirealms.customfishing.api.mechanic.misc.placeholder.PlaceholderManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager; @@ -84,6 +85,7 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin { protected TotemManager totemManager; protected FishingManager fishingManager; protected GameManager gameManager; + protected HologramManager hologramManager; /** * Constructs a new BukkitCustomFishingPlugin instance. @@ -358,6 +360,15 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin { return translationManager; } + /** + * Retrieves the HologramManager. + * + * @return the {@link HologramManager} + */ + public HologramManager getHologramManager() { + return hologramManager; + } + /** * Logs a debug message. * diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java index 5c87f2b0..3b3b0872 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionManager.java @@ -35,11 +35,11 @@ public interface ActionManager extends Reloadable { /** * Registers a custom action type with its corresponding factory. * - * @param type The type identifier of the action. - * @param actionFactory The factory responsible for creating instances of the action. + * @param actionFactory The factory responsible for creating instances of the action. + * @param type The type identifier of the action. * @return True if registration was successful, false if the type is already registered. */ - boolean registerAction(String type, ActionFactory actionFactory); + boolean registerAction(ActionFactory actionFactory, String... type); /** * Unregisters a custom action type. diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java index 05c3f65a..90bda7fa 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/action/ActionTrigger.java @@ -31,5 +31,6 @@ public enum ActionTrigger { TIMER, INTERACT, REEL, - NEW_SIZE_RECORD + NEW_SIZE_RECORD, + END } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java index 5a3c8530..47ec5fcc 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/game/AbstractGamingPlayer.java @@ -207,6 +207,7 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable { * Ends the game for the gaming player. */ protected void endGame() { + if (!isValid()) return; destroy(); boolean success = isSuccessful(); BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> { diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/Hologram.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/Hologram.java new file mode 100644 index 00000000..14ad8294 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/Hologram.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.mechanic.misc.hologram; + +import net.momirealms.sparrow.heart.feature.entity.FakeNamedEntity; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.Set; + +public class Hologram { + + private final FakeNamedEntity entity; + private Set set1 = new HashSet<>(); + private int ticksRemaining = 0; + + public Hologram(FakeNamedEntity entity) { + this.entity = entity; + } + + public void name(String json) { + entity.name(json); + } + + public void destroy() { + for (Player player : set1) { + entity.destroy(player); + } + set1.clear(); + } + + public void setTicksRemaining(int ticks) { + ticksRemaining = ticks; + } + + public boolean reduceTicks() { + ticksRemaining--; + return ticksRemaining < 0; + } + + public void updateNearbyPlayers(Set set2) { + Set intersectionSet = new HashSet<>(set1); + intersectionSet.retainAll(set2); + Set uniqueToSet1 = new HashSet<>(set1); + uniqueToSet1.removeAll(set2); + Set uniqueToSet2 = new HashSet<>(set2); + uniqueToSet2.removeAll(set1); + for (Player p : uniqueToSet1) { + entity.destroy(p); + } + for (Player p : uniqueToSet2) { + entity.spawn(p); + } + for (Player p : intersectionSet) { + entity.updateMetaData(p); + } + set1 = set2; + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/HologramManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/HologramManager.java new file mode 100644 index 00000000..764e568d --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/misc/hologram/HologramManager.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.mechanic.misc.hologram; + +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.common.helper.VersionHelper; +import net.momirealms.customfishing.common.plugin.feature.Reloadable; +import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; +import net.momirealms.sparrow.heart.SparrowHeart; +import net.momirealms.sparrow.heart.feature.entity.FakeNamedEntity; +import net.momirealms.sparrow.heart.feature.entity.armorstand.FakeArmorStand; +import net.momirealms.sparrow.heart.feature.entity.display.FakeTextDisplay; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +public class HologramManager implements Reloadable { + + private final BukkitCustomFishingPlugin plugin; + private final ConcurrentHashMap holograms = new ConcurrentHashMap<>(); + private SchedulerTask task; + + public HologramManager(BukkitCustomFishingPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void load() { + this.task = plugin.getScheduler().sync().runRepeating(() -> { + ArrayList toRemove = new ArrayList<>(); + for (Map.Entry entry : holograms.entrySet()) { + if (entry.getValue().reduceTicks()) { + toRemove.add(entry.getKey()); + entry.getValue().destroy(); + } + } + for (Location location : toRemove) { + holograms.remove(location); + } + }, 1,1, null); + } + + @Override + public void unload() { + if (this.task != null) { + this.task.cancel(); + } + for (Hologram hologram : holograms.values()) { + hologram.destroy(); + } + holograms.clear(); + } + + public void createHologram(Location location, String json, int ticks, boolean displayEntity, int[] rgba, Set viewers) { + Hologram hologram = holograms.get(location); + if (hologram == null) { + FakeNamedEntity fakeNamedEntity; + if (displayEntity && VersionHelper.isVersionNewerThan1_19_4()) { + FakeTextDisplay textDisplay = SparrowHeart.getInstance().createFakeTextDisplay(location); + textDisplay.rgba(rgba[0], rgba[1], rgba[2], rgba[3]); + fakeNamedEntity = textDisplay; + } else { + FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); + armorStand.small(true); + armorStand.invisible(true); + fakeNamedEntity = armorStand; + } + hologram = new Hologram(fakeNamedEntity); + hologram.name(json); + hologram.updateNearbyPlayers(viewers); + hologram.setTicksRemaining(ticks); + holograms.put(location, hologram); + } else { + hologram.name(json); + hologram.updateNearbyPlayers(viewers); + hologram.setTicksRemaining(ticks); + } + } + + +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java index 43573c64..d5602d7c 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/requirement/RequirementManager.java @@ -35,11 +35,11 @@ public interface RequirementManager extends Reloadable { /** * Registers a custom requirement type with its corresponding factory. * - * @param type The type identifier of the requirement. * @param requirementFactory The factory responsible for creating instances of the requirement. + * @param type The type identifier of the requirement. * @return True if registration was successful, false if the type is already registered. */ - boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory requirementFactory); + boolean registerRequirement(@NotNull RequirementFactory requirementFactory, @NotNull String... type); /** * Unregisters a custom requirement type. diff --git a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/region/WorldGuardRegion.java b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/region/WorldGuardRegion.java index 55d28adf..ff22ac4d 100644 --- a/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/region/WorldGuardRegion.java +++ b/compatibility/src/main/java/net/momirealms/customfishing/bukkit/integration/region/WorldGuardRegion.java @@ -39,7 +39,7 @@ import java.util.stream.Collectors; public class WorldGuardRegion { public static void register() { - BukkitCustomFishingPlugin.getInstance().getRequirementManager().registerRequirement("region", (args, notSatisfiedActions, runActions) -> { + BukkitCustomFishingPlugin.getInstance().getRequirementManager().registerRequirement((args, notSatisfiedActions, runActions) -> { HashSet regions = new HashSet<>(); boolean other; int mode = 1; @@ -92,6 +92,6 @@ public class WorldGuardRegion { if (runActions) ActionManager.trigger(context, notSatisfiedActions); return false; }; - }); + }, "region"); } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java index 8d4aa48c..7a4540c1 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/BukkitCustomFishingPluginImpl.java @@ -22,6 +22,7 @@ import net.momirealms.customfishing.api.event.CustomFishingReloadEvent; import net.momirealms.customfishing.api.mechanic.MechanicType; import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; +import net.momirealms.customfishing.api.mechanic.misc.hologram.HologramManager; import net.momirealms.customfishing.api.mechanic.misc.placeholder.BukkitPlaceholderManager; import net.momirealms.customfishing.api.util.EventUtils; import net.momirealms.customfishing.bukkit.action.BukkitActionManager; @@ -137,6 +138,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { this.translationManager = new TranslationManager(this); this.integrationManager = new BukkitIntegrationManager(this); this.gameManager = new BukkitGameManager(this); + this.hologramManager = new HologramManager(this); this.commandManager = new BukkitCommandManager(this); this.commandManager.registerDefaultFeatures(); @@ -196,6 +198,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { this.bagManager.reload(); this.storageManager.reload(); this.fishingManager.reload(); + this.hologramManager.reload(); this.itemManager.load(); this.eventManager.load(); @@ -230,6 +233,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin { this.bagManager.disable(); this.integrationManager.disable(); this.storageManager.disable(); + this.hologramManager.disable(); this.commandManager.unregisterFeatures(); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java index 534c6389..85f54de8 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/action/BukkitActionManager.java @@ -37,6 +37,7 @@ import net.momirealms.customfishing.api.util.PlayerUtils; import net.momirealms.customfishing.bukkit.integration.VaultHook; import net.momirealms.customfishing.bukkit.util.LocationUtils; import net.momirealms.customfishing.common.helper.AdventureHelper; +import net.momirealms.customfishing.common.helper.VersionHelper; import net.momirealms.customfishing.common.locale.MessageConstants; import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; @@ -45,7 +46,9 @@ import net.momirealms.customfishing.common.util.ListUtils; import net.momirealms.customfishing.common.util.Pair; import net.momirealms.customfishing.common.util.RandomUtils; import net.momirealms.sparrow.heart.SparrowHeart; -import net.momirealms.sparrow.heart.feature.armorstand.FakeArmorStand; +import net.momirealms.sparrow.heart.feature.entity.FakeEntity; +import net.momirealms.sparrow.heart.feature.entity.armorstand.FakeArmorStand; +import net.momirealms.sparrow.heart.feature.entity.display.FakeItemDisplay; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -89,9 +92,13 @@ public class BukkitActionManager implements ActionManager { } @Override - public boolean registerAction(String type, ActionFactory actionFactory) { - if (this.actionFactoryMap.containsKey(type)) return false; - this.actionFactoryMap.put(type, actionFactory); + public boolean registerAction(ActionFactory actionFactory, String... types) { + for (String type : types) { + if (this.actionFactoryMap.containsKey(type)) return false; + } + for (String type : types) { + this.actionFactoryMap.put(type, actionFactory); + } return true; } @@ -155,7 +162,7 @@ public class BukkitActionManager implements ActionManager { this.registerCloseInvAction(); this.registerExpAction(); this.registerFoodAction(); - this.registerChainAction(); + this.registerBuildAction(); this.registerMoneyAction(); this.registerItemAction(); this.registerPotionAction(); @@ -168,7 +175,7 @@ public class BukkitActionManager implements ActionManager { } private void registerMessageAction() { - registerAction("message", (args, chance) -> { + registerAction((args, chance) -> { List messages = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -178,8 +185,8 @@ public class BukkitActionManager implements ActionManager { audience.sendMessage(AdventureHelper.miniMessage(text)); } }; - }); - registerAction("random-message", (args, chance) -> { + }, "message"); + registerAction((args, chance) -> { List messages = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -188,8 +195,8 @@ public class BukkitActionManager implements ActionManager { Audience audience = plugin.getSenderFactory().getAudience(context.holder()); audience.sendMessage(AdventureHelper.miniMessage(random)); }; - }); - registerAction("broadcast", (args, chance) -> { + }, "random-message"); + registerAction((args, chance) -> { List messages = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -201,8 +208,8 @@ public class BukkitActionManager implements ActionManager { } } }; - }); - registerAction("message-nearby", (args, chance) -> { + }, "broadcast"); + registerAction((args, chance) -> { if (args instanceof Section section) { List messages = ListUtils.toList(section.get("message")); MathValue range = MathValue.auto(section.get("range")); @@ -230,11 +237,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at message-nearby action which should be Section"); return Action.empty(); } - }); + }, "message-nearby"); } private void registerCommandAction() { - registerAction("command", (args, chance) -> { + registerAction((args, chance) -> { List commands = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -245,8 +252,8 @@ public class BukkitActionManager implements ActionManager { } }, null); }; - }); - registerAction("player-command", (args, chance) -> { + }, "command"); + registerAction((args, chance) -> { List commands = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -257,8 +264,8 @@ public class BukkitActionManager implements ActionManager { } }, context.holder().getLocation()); }; - }); - registerAction("random-command", (args, chance) -> { + }, "player-command"); + registerAction((args, chance) -> { List commands = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -269,8 +276,8 @@ public class BukkitActionManager implements ActionManager { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom); }, null); }; - }); - registerAction("command-nearby", (args, chance) -> { + }, "random-command"); + registerAction((args, chance) -> { if (args instanceof Section section) { List cmd = ListUtils.toList(section.get("command")); MathValue range = MathValue.auto(section.get("range")); @@ -293,18 +300,18 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at command-nearby action which should be Section"); return Action.empty(); } - }); + }, "command-nearby"); } private void registerCloseInvAction() { - registerAction("close-inv", (args, chance) -> condition -> { + registerAction((args, chance) -> condition -> { if (Math.random() > chance) return; condition.holder().closeInventory(); - }); + }, "close-inv"); } private void registerActionBarAction() { - registerAction("actionbar", (args, chance) -> { + registerAction((args, chance) -> { String text = (String) args; return context -> { if (Math.random() > chance) return; @@ -312,8 +319,8 @@ public class BukkitActionManager implements ActionManager { Component component = AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(context.holder(), text, context.placeholderMap())); audience.sendActionBar(component); }; - }); - registerAction("random-actionbar", (args, chance) -> { + }, "actionbar"); + registerAction((args, chance) -> { List texts = ListUtils.toList(args); return context -> { if (Math.random() > chance) return; @@ -322,8 +329,8 @@ public class BukkitActionManager implements ActionManager { Audience audience = plugin.getSenderFactory().getAudience(context.holder()); audience.sendActionBar(AdventureHelper.miniMessage(random)); }; - }); - registerAction("actionbar-nearby", (args, chance) -> { + }, "random-actionbar"); + registerAction((args, chance) -> { if (args instanceof Section section) { String actionbar = section.getString("actionbar"); MathValue range = MathValue.auto(section.get("range")); @@ -345,11 +352,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at actionbar-nearby action which should be Section"); return Action.empty(); } - }); + }, "actionbar-nearby"); } private void registerExpAction() { - registerAction("mending", (args, chance) -> { + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; @@ -357,8 +364,8 @@ public class BukkitActionManager implements ActionManager { ExperienceOrb entity = player.getLocation().getWorld().spawn(player.getLocation().clone().add(0,0.5,0), ExperienceOrb.class); entity.setExperience((int) value.evaluate(context)); }; - }); - registerAction("exp", (args, chance) -> { + }, "mending"); + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; @@ -367,38 +374,38 @@ public class BukkitActionManager implements ActionManager { Audience audience = plugin.getSenderFactory().getAudience(player); AdventureHelper.playSound(audience, Sound.sound(Key.key("minecraft:entity.experience_orb.pickup"), Sound.Source.PLAYER, 1, 1)); }; - }); - registerAction("level", (args, chance) -> { + }, "exp"); + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; Player player = context.holder(); player.setLevel((int) Math.max(0, player.getLevel() + value.evaluate(context))); }; - }); + }, "level"); } private void registerFoodAction() { - registerAction("food", (args, chance) -> { + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; Player player = context.holder(); player.setFoodLevel((int) (player.getFoodLevel() + value.evaluate(context))); }; - }); - registerAction("saturation", (args, chance) -> { + }, "food"); + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; Player player = context.holder(); player.setSaturation((float) (player.getSaturation() + value.evaluate(context))); }; - }); + }, "saturation"); } private void registerItemAction() { - registerAction("item-amount", (args, chance) -> { + registerAction((args, chance) -> { if (args instanceof Section section) { boolean mainOrOff = section.getString("hand", "main").equalsIgnoreCase("main"); int amount = section.getInt("amount", 1); @@ -417,8 +424,8 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`"); return Action.empty(); } - }); - registerAction("durability", (args, chance) -> { + }, "item-amount"); + registerAction((args, chance) -> { if (args instanceof Section section) { EquipmentSlot slot = Optional.ofNullable(section.getString("slot")) .map(hand -> EquipmentSlot.valueOf(hand.toUpperCase(Locale.ENGLISH))) @@ -450,8 +457,8 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at durability action which is expected to be `Section`"); return Action.empty(); } - }); - registerAction("give-item", (args, chance) -> { + }, "durability"); + registerAction((args, chance) -> { if (args instanceof Section section) { String id = section.getString("item"); int amount = section.getInt("amount", 1); @@ -480,11 +487,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at give-item action which is expected to be `Section`"); return Action.empty(); } - }); + }, "give-item"); } - private void registerChainAction() { - registerAction("chain", (args, chance) -> { + private void registerBuildAction() { + registerAction((args, chance) -> { List> actions = new ArrayList<>(); if (args instanceof Section section) { for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { @@ -499,8 +506,8 @@ public class BukkitActionManager implements ActionManager { action.trigger(context); } }; - }); - registerAction("delay", (args, chance) -> { + }, "chain"); + registerAction((args, chance) -> { List> actions = new ArrayList<>(); int delay; boolean async; @@ -531,8 +538,8 @@ public class BukkitActionManager implements ActionManager { }, delay, location); } }; - }); - registerAction("timer", (args, chance) -> { + }, "delay"); + registerAction((args, chance) -> { List> actions = new ArrayList<>(); int delay, duration, period; boolean async; @@ -571,8 +578,8 @@ public class BukkitActionManager implements ActionManager { } plugin.getScheduler().asyncLater(task::cancel, duration * 50L, TimeUnit.MILLISECONDS); }; - }); - registerAction("conditional", (args, chance) -> { + }, "timer"); + registerAction((args, chance) -> { if (args instanceof Section section) { Action[] actions = parseActions(section.getSection("actions")); Requirement[] requirements = plugin.getRequirementManager().parseRequirements(section.getSection("conditions"), true); @@ -591,8 +598,8 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at conditional action which is expected to be `Section`"); return Action.empty(); } - }); - registerAction("priority", (args, chance) -> { + }, "conditional"); + registerAction((args, chance) -> { if (args instanceof Section section) { List[], Action[]>> conditionActionPairList = new ArrayList<>(); for (Map.Entry entry : section.getStringRouteMappedValues(false).entrySet()) { @@ -623,32 +630,32 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at priority action which is expected to be `Section`"); return Action.empty(); } - }); + }, "priority"); } private void registerMoneyAction() { - registerAction("give-money", (args, chance) -> { + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; if (!VaultHook.isHooked()) return; VaultHook.deposit(context.holder(), value.evaluate(context)); }; - }); - registerAction("take-money", (args, chance) -> { + }, "give-money"); + registerAction((args, chance) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() > chance) return; if (!VaultHook.isHooked()) return; VaultHook.withdraw(context.holder(), value.evaluate(context)); }; - }); + }, "take-money"); } // The registry name changes a lot @SuppressWarnings("deprecation") private void registerPotionAction() { - registerAction("potion-effect", (args, chance) -> { + registerAction((args, chance) -> { if (args instanceof Section section) { PotionEffect potionEffect = new PotionEffect( Objects.requireNonNull(PotionEffectType.getByName(section.getString("type", "BLINDNESS").toUpperCase(Locale.ENGLISH))), @@ -663,11 +670,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at potion-effect action which is expected to be `Section`"); return Action.empty(); } - }); + }, "potion-effect"); } private void registerSoundAction() { - registerAction("sound", (args, chance) -> { + registerAction((args, chance) -> { if (args instanceof Section section) { Sound sound = Sound.sound( Key.key(section.getString("key")), @@ -684,12 +691,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at sound action which is expected to be `Section`"); return Action.empty(); } - }); + }, "sound"); } - private void registerPluginExpAction() { - registerAction("plugin-exp", (args, chance) -> { + registerAction((args, chance) -> { if (args instanceof Section section) { String pluginName = section.getString("plugin"); MathValue value = MathValue.auto(section.get("exp")); @@ -704,11 +710,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-exp action which is expected to be `Section`"); return Action.empty(); } - }); + }, "plugin-exp"); } private void registerTitleAction() { - registerAction("title", (args, chance) -> { + registerAction((args, chance) -> { if (args instanceof Section section) { TextValue title = TextValue.auto(section.getString("title", "")); TextValue subtitle = TextValue.auto(section.getString("subtitle", "")); @@ -729,8 +735,8 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title action which is expected to be `Section`"); return Action.empty(); } - }); - registerAction("random-title", (args, chance) -> { + }, "title"); + registerAction((args, chance) -> { if (args instanceof Section section) { List titles = section.getStringList("titles"); if (titles.isEmpty()) titles.add(""); @@ -755,8 +761,8 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at random-title action which is expected to be `Section`"); return Action.empty(); } - }); - registerAction("title-nearby", (args, chance) -> { + }, "random-title"); + registerAction((args, chance) -> { if (args instanceof Section section) { TextValue title = TextValue.auto(section.getString("title")); TextValue subtitle = TextValue.auto(section.getString("subtitle")); @@ -783,11 +789,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title-nearby action which is expected to be `Section`"); return Action.empty(); } - }); + }, "title-nearby"); } private void registerFakeItemAction() { - registerAction("fake-item", ((args, chance) -> { + registerAction(((args, chance) -> { if (args instanceof Section section) { String itemID = section.getString("item", ""); String[] split = itemID.split(":"); @@ -800,17 +806,28 @@ public class BukkitActionManager implements ActionManager { MathValue yaw = MathValue.auto(section.get("yaw", 0)); int range = section.getInt("range", 0); boolean opposite = section.getBoolean("opposite-yaw", false); + boolean useItemDisplay = section.getBoolean("use-item-display", false); String finalItemID = itemID; return context -> { if (Math.random() > chance) return; Player owner = context.holder(); Location location = position ? requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)).clone() : owner.getLocation().clone(); location.add(x.evaluate(context), y.evaluate(context) - 1, z.evaluate(context)); + location.setPitch(0); if (opposite) location.setYaw(-owner.getLocation().getYaw()); else location.setYaw((float) yaw.evaluate(context)); - FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); - armorStand.invisible(true); - armorStand.equipment(EquipmentSlot.HEAD, plugin.getItemManager().buildInternal(context, finalItemID)); + FakeEntity fakeEntity; + if (useItemDisplay && VersionHelper.isVersionNewerThan1_19_4()) { + location.add(0,1.5,0); + FakeItemDisplay itemDisplay = SparrowHeart.getInstance().createFakeItemDisplay(location); + itemDisplay.item(plugin.getItemManager().buildInternal(context, finalItemID)); + fakeEntity = itemDisplay; + } else { + FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); + armorStand.invisible(true); + armorStand.equipment(EquipmentSlot.HEAD, plugin.getItemManager().buildInternal(context, finalItemID)); + fakeEntity = armorStand; + } ArrayList viewers = new ArrayList<>(); if (range > 0) { for (Player player : location.getWorld().getPlayers()) { @@ -822,12 +839,12 @@ public class BukkitActionManager implements ActionManager { viewers.add(owner); } for (Player player : viewers) { - armorStand.spawn(player); + fakeEntity.spawn(player); } plugin.getScheduler().asyncLater(() -> { for (Player player : viewers) { if (player.isOnline() && player.isValid()) { - armorStand.destroy(player); + fakeEntity.destroy(player); } } }, (long) (duration.evaluate(context) * 50), TimeUnit.MILLISECONDS); @@ -836,11 +853,11 @@ public class BukkitActionManager implements ActionManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at fake-item action which is expected to be `Section`"); return Action.empty(); } - })); + }), "fake-item"); } private void registerHologramAction() { - registerAction("hologram", ((args, chance) -> { + registerAction(((args, chance) -> { if (args instanceof Section section) { TextValue text = TextValue.auto(section.getString("text", "")); MathValue duration = MathValue.auto(section.get("duration", 20)); @@ -848,17 +865,20 @@ public class BukkitActionManager implements ActionManager { MathValue x = MathValue.auto(section.get("x", 0)); MathValue y = MathValue.auto(section.get("y", 0)); MathValue z = MathValue.auto(section.get("z", 0)); + String rgbaStr = section.getString("rgba", "0,0,0,0"); + int[] rgba = new int[4]; + String[] split = rgbaStr.split(","); + for (int i = 0; i < split.length; i++) { + rgba[i] = Integer.parseInt(split[i]); + } int range = section.getInt("range", 16); + boolean useTextDisplay = section.getBoolean("use-text-display", false); return context -> { if (Math.random() > chance) return; Player owner = context.holder(); Location location = position ? requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)).clone() : owner.getLocation().clone(); location.add(x.evaluate(context), y.evaluate(context), z.evaluate(context)); - FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); - armorStand.invisible(true); - armorStand.small(true); - armorStand.name(AdventureHelper.miniMessageToJson(text.render(context))); - ArrayList viewers = new ArrayList<>(); + HashSet viewers = new HashSet<>(); if (range > 0) { for (Player player : location.getWorld().getPlayers()) { if (LocationUtils.getDistance(player.getLocation(), location) <= range) { @@ -868,26 +888,17 @@ public class BukkitActionManager implements ActionManager { } else { viewers.add(owner); } - for (Player player : viewers) { - armorStand.spawn(player); - } - plugin.getScheduler().asyncLater(() -> { - for (Player player : viewers) { - if (player.isOnline() && player.isValid()) { - armorStand.destroy(player); - } - } - }, (long) (duration.evaluate(context) * 50), TimeUnit.MILLISECONDS); + plugin.getHologramManager().createHologram(location, AdventureHelper.miniMessageToJson(text.render(context)), (int) duration.evaluate(context), useTextDisplay, rgba, viewers); }; } else { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at hologram action which is expected to be `Section`"); return Action.empty(); } - })); + }), "hologram"); } private void registerFishFindAction() { - registerAction("fish-finder", (args, chance) -> { + registerAction((args, chance) -> { String surrounding; if (args instanceof Boolean b) { surrounding = b ? "lava" : "water"; @@ -920,7 +931,7 @@ public class BukkitActionManager implements ActionManager { plugin.getSenderFactory().wrap(context.holder()).sendMessage(TranslationManager.render(MessageConstants.COMMAND_FISH_FINDER_POSSIBLE_LOOTS.arguments(AdventureHelper.miniMessage(stringJoiner.toString())).build())); } }; - }); + }, "fish-finder"); } /** @@ -951,7 +962,7 @@ public class BukkitActionManager implements ActionManager { for (Class> expansionClass : classes) { ActionExpansion expansion = expansionClass.getDeclaredConstructor().newInstance(); unregisterAction(expansion.getActionType()); - registerAction(expansion.getActionType(), expansion.getActionFactory()); + registerAction(expansion.getActionFactory(), expansion.getActionType()); plugin.getPluginLogger().info("Loaded action expansion: " + expansion.getActionType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor() ); } } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java index 9e408b09..969a7650 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/requirement/BukkitRequirementManager.java @@ -45,6 +45,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -80,9 +81,13 @@ public class BukkitRequirementManager implements RequirementManager { } @Override - public boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory requirementFactory) { - if (this.requirementFactoryMap.containsKey(type)) return false; - this.requirementFactoryMap.put(type, requirementFactory); + public boolean registerRequirement(@NotNull RequirementFactory requirementFactory, @NotNull String... types) { + for (String type : types) { + if (this.requirementFactoryMap.containsKey(type)) return false; + } + for (String type : types) { + this.requirementFactoryMap.put(type, requirementFactory); + } return true; } @@ -188,17 +193,20 @@ public class BukkitRequirementManager implements RequirementManager { this.registerItemInHandRequirement(); this.registerImpossibleRequirement(); this.registerPotionEffectRequirement(); + this.registerSneakRequirement(); + this.registerGameModeRequirement(); + this.registerEquipmentRequirement(); } private void registerImpossibleRequirement() { - registerRequirement("impossible", ((args, actions, runActions) -> context -> { + registerRequirement(((args, actions, runActions) -> context -> { if (runActions) ActionManager.trigger(context, actions); return false; - })); + }), "impossible"); } private void registerCompetitionRequirement() { - registerRequirement("competition", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { boolean onCompetition = section.getBoolean("ongoing", true); List ids = section.contains("id") ? ListUtils.toList(section.get("id")) : List.of(); @@ -225,11 +233,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at competition requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "competition"); } private void registerInBagRequirement() { - registerRequirement("in-fishingbag", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean arg = (boolean) args; return context -> { boolean inBag = Optional.ofNullable(context.arg(ContextKeys.IN_BAG)).orElse(false); @@ -237,11 +245,30 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "in-fishingbag"); + } + + private void registerEquipmentRequirement() { + registerRequirement((args, actions, runActions) -> { + if (args instanceof Section section) { + EquipmentSlot slot = EquipmentSlot.valueOf(section.getString("slot","HEAD").toUpperCase(Locale.ENGLISH)); + List items = ListUtils.toList(section.get("item")); + return context -> { + ItemStack itemStack = context.holder().getInventory().getItem(slot); + String id = plugin.getItemManager().getItemID(itemStack); + if (items.contains(id)) return true; + if (runActions) ActionManager.trigger(context, actions); + return false; + }; + } else { + plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equipment requirement which is expected be `Section`"); + return Requirement.empty(); + } + }, "equipment"); } private void registerItemInHandRequirement() { - registerRequirement("item-in-hand", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main"); int amount = section.getInt("amount", 1); @@ -259,11 +286,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-in-hand requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "item-in-hand"); } private void registerPluginLevelRequirement() { - registerRequirement("plugin-level", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { String pluginName = section.getString("plugin"); int level = section.getInt("level"); @@ -283,11 +310,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-level requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "plugin-level"); } private void registerTimeRequirement() { - registerRequirement("time", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List list = ListUtils.toList(args); List> timePairs = list.stream().map(line -> { String[] split = line.split("~"); @@ -302,11 +329,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "time"); } private void registerYRequirement() { - registerRequirement("ypos", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List list = ListUtils.toList(args); List> posPairs = list.stream().map(line -> { String[] split = line.split("~"); @@ -321,11 +348,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "ypos"); } private void registerOrRequirement() { - registerRequirement("||", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { Requirement[] requirements = parseRequirements(section, runActions); return context -> { @@ -339,11 +366,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at || requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "||"); } private void registerAndRequirement() { - registerRequirement("&&", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { Requirement[] requirements = parseRequirements(section, runActions); return context -> { @@ -360,11 +387,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at && requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "&&"); } private void registerInWaterRequirement() { - registerRequirement("in-water", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean inWater = (boolean) args; return context -> { boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key()); @@ -372,11 +399,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "in-water"); } private void registerInVoidRequirement() { - registerRequirement("in-void", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean inVoid = (boolean) args; return context -> { boolean in_void = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.VOID_FISHING.key()); @@ -384,12 +411,12 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "in-void"); } private void registerInLavaRequirement() { // Deprecated requirement type - registerRequirement("lava-fishing", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean inLava = (boolean) args; if (!inLava) { // in water @@ -407,8 +434,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("in-lava", (args, actions, runActions) -> { + }, "lava-fishing"); + registerRequirement((args, actions, runActions) -> { boolean inLava = (boolean) args; return context -> { boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key()); @@ -416,11 +443,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "in-lava"); } private void registerRodRequirement() { - registerRequirement("rod", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet rods = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.ROD); @@ -428,8 +455,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!rod", (args, actions, runActions) -> { + }, "rod"); + registerRequirement((args, actions, runActions) -> { HashSet rods = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.ROD); @@ -437,11 +464,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!rod"); } private void registerGroupRequirement() { - registerRequirement("group", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet groups = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -455,8 +482,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!group", (args, actions, runActions) -> { + }, "group"); + registerRequirement((args, actions, runActions) -> { HashSet groups = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -474,11 +501,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!group"); } private void registerLootRequirement() { - registerRequirement("loot", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -486,8 +513,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!loot", (args, actions, runActions) -> { + }, "loot"); + registerRequirement((args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String lootID = context.arg(ContextKeys.ID); @@ -495,11 +522,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!loot"); } private void registerHookRequirement() { - registerRequirement("hook", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet hooks = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.HOOK); @@ -507,8 +534,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!hook", (args, actions, runActions) -> { + }, "hook"); + registerRequirement((args, actions, runActions) -> { HashSet hooks = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.HOOK); @@ -516,8 +543,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("has-hook", (args, actions, runActions) -> { + }, "!hook"); + registerRequirement((args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String id = context.arg(ContextKeys.HOOK); @@ -526,11 +553,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "has-hook"); } private void registerBaitRequirement() { - registerRequirement("bait", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.BAIT); @@ -538,8 +565,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!bait", (args, actions, runActions) -> { + }, "bait"); + registerRequirement((args, actions, runActions) -> { HashSet arg = new HashSet<>(ListUtils.toList(args)); return context -> { String id = context.arg(ContextKeys.BAIT); @@ -547,8 +574,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("has-bait", (args, actions, runActions) -> { + }, "!bait"); + registerRequirement((args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String id = context.arg(ContextKeys.BAIT); @@ -557,11 +584,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "has-bait"); } private void registerSizeRequirement() { - registerRequirement("has-size", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean has = (boolean) args; return context -> { float size = Optional.ofNullable(context.arg(ContextKeys.SIZE)).orElse(-1f); @@ -570,11 +597,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "has-size"); } private void registerOpenWaterRequirement() { - registerRequirement("open-water", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean openWater = (boolean) args; return context -> { boolean current = Optional.ofNullable(context.arg(ContextKeys.OPEN_WATER)).orElse(false); @@ -583,11 +610,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "open-water"); } private void registerHasStatsRequirement() { - registerRequirement("has-stats", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean has = (boolean) args; return context -> { String loot = context.arg(ContextKeys.ID); @@ -599,11 +626,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "has-stats"); } private void registerLootTypeRequirement() { - registerRequirement("loot-type", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List types = ListUtils.toList(args); return context -> { String loot = context.arg(ContextKeys.ID); @@ -615,8 +642,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!loot-type", (args, actions, runActions) -> { + }, "loot-type"); + registerRequirement((args, actions, runActions) -> { List types = ListUtils.toList(args); return context -> { String loot = context.arg(ContextKeys.ID); @@ -628,22 +655,22 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!loot-type"); } private void registerListRequirement() { - registerRequirement("list", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { plugin.getPluginLogger().severe("It seems that you made a mistake where you put \"list\" into \"conditions\" section."); plugin.getPluginLogger().warn("list:"); for (String e : ListUtils.toList(args)) { plugin.getPluginLogger().warn(" - " + e); } return Requirement.empty(); - }); + }, "list"); } private void registerEnvironmentRequirement() { - registerRequirement("environment", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List environments = ListUtils.toList(args); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -652,8 +679,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!environment", (args, actions, runActions) -> { + }, "environment"); + registerRequirement((args, actions, runActions) -> { List environments = ListUtils.toList(args); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -662,11 +689,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!environment"); } private void registerIceFishingRequirement() { - registerRequirement("ice-fishing", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { boolean iceFishing = (boolean) args; return context -> { Location location = requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)); @@ -686,11 +713,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "ice-fishing"); } private void registerLevelRequirement() { - registerRequirement("level", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { int current = context.holder().getLevel(); @@ -699,11 +726,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "level"); } private void registerMoneyRequirement() { - registerRequirement("money", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { double current = VaultHook.getBalance(context.holder()); @@ -712,11 +739,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "money"); } private void registerRandomRequirement() { - registerRequirement("random", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { MathValue value = MathValue.auto(args); return context -> { if (Math.random() < value.evaluate(context, true)) @@ -724,11 +751,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "random"); } private void registerBiomeRequirement() { - registerRequirement("biome", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet biomes = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); @@ -738,8 +765,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!biome", (args, actions, runActions) -> { + }, "biome"); + registerRequirement((args, actions, runActions) -> { HashSet biomes = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); @@ -749,11 +776,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!biome"); } private void registerMoonPhaseRequirement() { - registerRequirement("moon-phase", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet moonPhases = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -763,8 +790,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!moon-phase", (args, actions, runActions) -> { + }, "moon-phase"); + registerRequirement((args, actions, runActions) -> { HashSet moonPhases = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -774,11 +801,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!moon-phase"); } private void registerWorldRequirement() { - registerRequirement("world", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet worlds = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -787,8 +814,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!world", (args, actions, runActions) -> { + }, "world"); + registerRequirement((args, actions, runActions) -> { HashSet worlds = new HashSet<>(ListUtils.toList(args)); return context -> { Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); @@ -797,11 +824,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "!world"); } private void registerWeatherRequirement() { - registerRequirement("weather", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet weathers = new HashSet<>(ListUtils.toList(args)); return context -> { String currentWeather; @@ -814,11 +841,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "weather"); } private void registerCoolDownRequirement() { - registerRequirement("cooldown", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { String key = section.getString("key"); int time = section.getInt("time"); @@ -832,11 +859,11 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at cooldown requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "cooldown"); } private void registerDateRequirement() { - registerRequirement("date", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { HashSet dates = new HashSet<>(ListUtils.toList(args)); return context -> { Calendar calendar = Calendar.getInstance(); @@ -846,11 +873,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "date"); } private void registerPermissionRequirement() { - registerRequirement("permission", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List perms = ListUtils.toList(args); return context -> { for (String perm : perms) @@ -859,8 +886,8 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); - registerRequirement("!permission", (args, actions, runActions) -> { + }, "permission"); + registerRequirement((args, actions, runActions) -> { List perms = ListUtils.toList(args); return context -> { for (String perm : perms) @@ -870,11 +897,11 @@ public class BukkitRequirementManager implements RequirementManager { } return true; }; - }); + }, "!permission"); } private void registerSeasonRequirement() { - registerRequirement("season", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { List seasons = ListUtils.toList(args); return context -> { SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonProvider(); @@ -886,11 +913,11 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "season"); } private void registerPAPIRequirement() { - registerRequirement("<", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -903,8 +930,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at < requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("<=", (args, actions, runActions) -> { + }, "<"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -917,8 +944,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at <= requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!=", (args, actions, runActions) -> { + }, "<="); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -931,8 +958,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at != requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("==", (args, actions, runActions) -> { + }, "!="); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -945,8 +972,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at == requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement(">=", (args, actions, runActions) -> { + }, "=="); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -959,8 +986,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at >= requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement(">", (args, actions, runActions) -> { + }, ">="); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { MathValue v1 = MathValue.auto(section.get("value1")); MathValue v2 = MathValue.auto(section.get("value2")); @@ -973,8 +1000,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at > requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("regex", (args, actions, runActions) -> { + }, ">"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("papi", "")); String v2 = section.getString("regex", ""); @@ -987,8 +1014,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at regex requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("startsWith", (args, actions, runActions) -> { + }, "regex"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1001,8 +1028,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at startsWith requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!startsWith", (args, actions, runActions) -> { + }, "startsWith"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1015,8 +1042,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !startsWith requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("endsWith", (args, actions, runActions) -> { + }, "!startsWith"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1029,8 +1056,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at endsWith requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!endsWith", (args, actions, runActions) -> { + }, "endsWith"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1043,8 +1070,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !endsWith requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("contains", (args, actions, runActions) -> { + }, "!endsWith"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1057,8 +1084,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at contains requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!contains", (args, actions, runActions) -> { + }, "contains"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1071,8 +1098,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !contains requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("in-list", (args, actions, runActions) -> { + }, "!contains"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue papi = TextValue.auto(section.getString("papi", "")); List values = ListUtils.toList(section.get("values")); @@ -1085,8 +1112,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at in-list requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!in-list", (args, actions, runActions) -> { + }, "in-list"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue papi = TextValue.auto(section.getString("papi", "")); List values = ListUtils.toList(section.get("values")); @@ -1099,8 +1126,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !in-list requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("equals", (args, actions, runActions) -> { + }, "!in-list"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1114,8 +1141,8 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equals requirement which is expected be `Section`"); return Requirement.empty(); } - }); - registerRequirement("!equals", (args, actions, runActions) -> { + }, "equals"); + registerRequirement((args, actions, runActions) -> { if (args instanceof Section section) { TextValue v1 = TextValue.auto(section.getString("value1", "")); TextValue v2 = TextValue.auto(section.getString("value2", "")); @@ -1128,12 +1155,12 @@ public class BukkitRequirementManager implements RequirementManager { plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !equals requirement which is expected be `Section`"); return Requirement.empty(); } - }); + }, "!equals"); } @SuppressWarnings("deprecation") private void registerPotionEffectRequirement() { - registerRequirement("potion-effect", (args, actions, runActions) -> { + registerRequirement((args, actions, runActions) -> { String potions = (String) args; String[] split = potions.split("(<=|>=|<|>|==)", 2); PotionEffectType type = PotionEffectType.getByName(split[0]); @@ -1176,7 +1203,40 @@ public class BukkitRequirementManager implements RequirementManager { if (runActions) ActionManager.trigger(context, actions); return false; }; - }); + }, "potion-effect"); + } + + private void registerSneakRequirement() { + registerRequirement((args, actions, advanced) -> { + boolean sneak = (boolean) args; + return context -> { + if (context.holder() == null) return false; + if (sneak) { + if (context.holder().isSneaking()) + return true; + } else { + if (!context.holder().isSneaking()) + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }, "sneak"); + } + + protected void registerGameModeRequirement() { + registerRequirement((args, actions, advanced) -> { + List modes = ListUtils.toList(args); + return context -> { + if (context.holder() == null) return false; + var name = context.holder().getGameMode().name().toLowerCase(Locale.ENGLISH); + if (modes.contains(name)) { + return true; + } + if (advanced) ActionManager.trigger(context, actions); + return false; + }; + }, "gamemode"); } /** @@ -1206,7 +1266,7 @@ public class BukkitRequirementManager implements RequirementManager { for (Class> expansionClass : classes) { RequirementExpansion expansion = expansionClass.getDeclaredConstructor().newInstance(); unregisterRequirement(expansion.getRequirementType()); - registerRequirement(expansion.getRequirementType(), expansion.getRequirementFactory()); + registerRequirement(expansion.getRequirementFactory(), expansion.getRequirementType()); plugin.getPluginLogger().info("Loaded requirement expansion: " + expansion.getRequirementType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor()); } } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java index af583f14..18e2ad6a 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/scheduler/impl/BukkitExecutor.java @@ -41,6 +41,10 @@ public class BukkitExecutor implements RegionExecutor { @Override public void run(Runnable r, Location l) { + if (Bukkit.isPrimaryThread()) { + r.run(); + return; + } Bukkit.getScheduler().runTask(plugin, r); } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java index 8860f56b..5bfafbe1 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/ActivatedTotem.java @@ -71,6 +71,7 @@ public class ActivatedTotem { task.cancel(); } this.subTasks.clear(); + this.doEndAction(); } public long getExpireTime() { @@ -86,4 +87,9 @@ public class ActivatedTotem { BukkitCustomFishingPlugin.getInstance().getEventManager().getEventCarrier(totemConfig.id(), MechanicType.TOTEM) .ifPresent(carrier -> carrier.trigger(context, ActionTrigger.TIMER)); } + + public void doEndAction() { + BukkitCustomFishingPlugin.getInstance().getEventManager().getEventCarrier(totemConfig.id(), MechanicType.TOTEM) + .ifPresent(carrier -> carrier.trigger(context, ActionTrigger.END)); + } } diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java index 7ea7a923..c3842119 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/totem/BukkitTotemManager.java @@ -23,11 +23,13 @@ import net.momirealms.customfishing.api.mechanic.MechanicType; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.context.Context; +import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.api.mechanic.totem.TotemConfig; import net.momirealms.customfishing.api.mechanic.totem.TotemManager; import net.momirealms.customfishing.api.mechanic.totem.block.TotemBlock; +import net.momirealms.customfishing.api.util.EventUtils; import net.momirealms.customfishing.api.util.SimpleLocation; import net.momirealms.customfishing.bukkit.util.LocationUtils; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; @@ -91,6 +93,7 @@ public class BukkitTotemManager implements TotemManager, Listener { if (this.timerCheckTask != null) this.timerCheckTask.cancel(); this.block2Totem.clear(); + this.id2Totem.clear(); } @Override @@ -162,9 +165,17 @@ public class BukkitTotemManager implements TotemManager, Listener { if (config == null) return; + Location location = block.getLocation(); + SimpleLocation simpleLocation = SimpleLocation.of(location); + ActivatedTotem previous = this.activatedTotems.get(simpleLocation); + if (previous != null) { + return; + } + String totemID = config.id(); final Player player = event.getPlayer();; Context context = Context.player(player); + context.arg(ContextKeys.SLOT, event.getHand()); Optional optionalEffectModifier = plugin.getEffectManager().getEffectModifier(totemID, MechanicType.TOTEM); if (optionalEffectModifier.isPresent()) { if (!RequirementManager.isSatisfied(context, optionalEffectModifier.get().requirements())) { @@ -172,21 +183,13 @@ public class BukkitTotemManager implements TotemManager, Listener { } } - TotemActivateEvent totemActivateEvent = new TotemActivateEvent(player, block.getLocation(), config); - Bukkit.getPluginManager().callEvent(totemActivateEvent); - if (totemActivateEvent.isCancelled()) { + if (EventUtils.fireAndCheckCancel(new TotemActivateEvent(player, block.getLocation(), config))) { return; } plugin.getEventManager().trigger(context, totemID, MechanicType.TOTEM, ActionTrigger.ACTIVATE); - - Location location = block.getLocation(); ActivatedTotem activatedTotem = new ActivatedTotem(player, location, config); - SimpleLocation simpleLocation = SimpleLocation.of(location); - ActivatedTotem previous = this.activatedTotems.put(simpleLocation, activatedTotem); - if (previous != null) { - previous.cancel(); - } + this.activatedTotems.put(simpleLocation, activatedTotem); } @Override diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 726de550..c3527879 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -131,6 +131,7 @@ mechanics: duration: 35 position: other item: lava_effect + use-item-display: true priority_2: conditions: in-water: true @@ -141,6 +142,7 @@ mechanics: duration: 35 position: other item: water_effect + use-item-display: true # Global properties which would help you reduce duplicated lines global-loot-property: show-in-fishfinder: true diff --git a/core/src/main/resources/contents/totem/default.yml b/core/src/main/resources/contents/totem/default.yml index 8d1a2d86..b4226c26 100644 --- a/core/src/main/resources/contents/totem/default.yml +++ b/core/src/main/resources/contents/totem/default.yml @@ -26,7 +26,6 @@ double_loot_totem: requirement_1: type: item-in-hand value: - hand: main item: NAUTILUS_SHELL amount: 1 not-met-actions: @@ -48,6 +47,8 @@ double_loot_totem: text: '<#BA55D3>[Double Loot Totem]' position: other range: 16 + use-text-display: true + rgba: 147,112,219,50 y: 3.3 x: 0 z: 0 @@ -58,6 +59,7 @@ double_loot_totem: text: 'Time Left: {time_left} seconds' position: other range: 16 + use-text-display: true y: 2.8 x: 0 z: 0 @@ -65,7 +67,6 @@ double_loot_totem: remove_item_action: type: item-amount value: - hand: main amount: -1 broadcast_action: type: message-nearby @@ -256,7 +257,6 @@ golden_star_totem: requirement_1: type: item-in-hand value: - hand: main item: GOLD_INGOT amount: 1 not-met-actions: @@ -278,6 +278,8 @@ golden_star_totem: text: '<#FFFF00>[Golden Star Totem]' position: other range: 16 + use-text-display: true + rgba: 255,215,0,50 y: 1 x: 0 z: 0 @@ -287,6 +289,7 @@ golden_star_totem: duration: 20 text: 'Time Left: {time_left} seconds' position: other + use-text-display: true range: 16 y: 0.5 x: 0 @@ -295,7 +298,6 @@ golden_star_totem: remove_item_action: type: item-amount value: - hand: main amount: -1 broadcast_action: type: message-nearby diff --git a/gradle.properties b/gradle.properties index d5a189f0..b9aba67b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.2.20 +project_version=2.2.21 config_version=36 project_group=net.momirealms @@ -17,7 +17,7 @@ h2_driver_version=2.2.224 sqlite_driver_version=3.46.0.1 adventure_bundle_version=4.17.0 adventure_platform_version=4.3.3 -sparrow_heart_version=0.36 +sparrow_heart_version=0.39 cloud_core_version=2.0.0-rc.2 cloud_services_version=2.0.0-rc.2 cloud_brigadier_version=2.0.0-beta.9