9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
XiaoMoMi
2024-08-30 23:42:49 +08:00
parent 6f54585538
commit b149e08ba1
17 changed files with 541 additions and 262 deletions

View File

@@ -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.loot.LootManager;
import net.momirealms.customfishing.api.mechanic.market.MarketManager; import net.momirealms.customfishing.api.mechanic.market.MarketManager;
import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; 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.misc.placeholder.PlaceholderManager;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager; import net.momirealms.customfishing.api.mechanic.statistic.StatisticsManager;
@@ -84,6 +85,7 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin {
protected TotemManager totemManager; protected TotemManager totemManager;
protected FishingManager fishingManager; protected FishingManager fishingManager;
protected GameManager gameManager; protected GameManager gameManager;
protected HologramManager hologramManager;
/** /**
* Constructs a new BukkitCustomFishingPlugin instance. * Constructs a new BukkitCustomFishingPlugin instance.
@@ -358,6 +360,15 @@ public abstract class BukkitCustomFishingPlugin implements CustomFishingPlugin {
return translationManager; return translationManager;
} }
/**
* Retrieves the HologramManager.
*
* @return the {@link HologramManager}
*/
public HologramManager getHologramManager() {
return hologramManager;
}
/** /**
* Logs a debug message. * Logs a debug message.
* *

View File

@@ -35,11 +35,11 @@ public interface ActionManager<T> extends Reloadable {
/** /**
* Registers a custom action type with its corresponding factory. * 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. * @return True if registration was successful, false if the type is already registered.
*/ */
boolean registerAction(String type, ActionFactory<T> actionFactory); boolean registerAction(ActionFactory<T> actionFactory, String... type);
/** /**
* Unregisters a custom action type. * Unregisters a custom action type.

View File

@@ -31,5 +31,6 @@ public enum ActionTrigger {
TIMER, TIMER,
INTERACT, INTERACT,
REEL, REEL,
NEW_SIZE_RECORD NEW_SIZE_RECORD,
END
} }

View File

@@ -207,6 +207,7 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
* Ends the game for the gaming player. * Ends the game for the gaming player.
*/ */
protected void endGame() { protected void endGame() {
if (!isValid()) return;
destroy(); destroy();
boolean success = isSuccessful(); boolean success = isSuccessful();
BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> { BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> {

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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<Player> 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<Player> set2) {
Set<Player> intersectionSet = new HashSet<>(set1);
intersectionSet.retainAll(set2);
Set<Player> uniqueToSet1 = new HashSet<>(set1);
uniqueToSet1.removeAll(set2);
Set<Player> 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;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) <2024> <XiaoMoMi>
*
* 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 <https://www.gnu.org/licenses/>.
*/
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<Location, Hologram> holograms = new ConcurrentHashMap<>();
private SchedulerTask task;
public HologramManager(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
}
@Override
public void load() {
this.task = plugin.getScheduler().sync().runRepeating(() -> {
ArrayList<Location> toRemove = new ArrayList<>();
for (Map.Entry<Location, Hologram> 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<Player> 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);
}
}
}

View File

@@ -35,11 +35,11 @@ public interface RequirementManager<T> extends Reloadable {
/** /**
* Registers a custom requirement type with its corresponding factory. * 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 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. * @return True if registration was successful, false if the type is already registered.
*/ */
boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory<T> requirementFactory); boolean registerRequirement(@NotNull RequirementFactory<T> requirementFactory, @NotNull String... type);
/** /**
* Unregisters a custom requirement type. * Unregisters a custom requirement type.

View File

@@ -39,7 +39,7 @@ import java.util.stream.Collectors;
public class WorldGuardRegion { public class WorldGuardRegion {
public static void register() { public static void register() {
BukkitCustomFishingPlugin.getInstance().getRequirementManager().registerRequirement("region", (args, notSatisfiedActions, runActions) -> { BukkitCustomFishingPlugin.getInstance().getRequirementManager().registerRequirement((args, notSatisfiedActions, runActions) -> {
HashSet<String> regions = new HashSet<>(); HashSet<String> regions = new HashSet<>();
boolean other; boolean other;
int mode = 1; int mode = 1;
@@ -92,6 +92,6 @@ public class WorldGuardRegion {
if (runActions) ActionManager.trigger(context, notSatisfiedActions); if (runActions) ActionManager.trigger(context, notSatisfiedActions);
return false; return false;
}; };
}); }, "region");
} }
} }

View File

@@ -22,6 +22,7 @@ import net.momirealms.customfishing.api.event.CustomFishingReloadEvent;
import net.momirealms.customfishing.api.mechanic.MechanicType; import net.momirealms.customfishing.api.mechanic.MechanicType;
import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.misc.cooldown.CoolDownManager; 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.mechanic.misc.placeholder.BukkitPlaceholderManager;
import net.momirealms.customfishing.api.util.EventUtils; import net.momirealms.customfishing.api.util.EventUtils;
import net.momirealms.customfishing.bukkit.action.BukkitActionManager; import net.momirealms.customfishing.bukkit.action.BukkitActionManager;
@@ -137,6 +138,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
this.translationManager = new TranslationManager(this); this.translationManager = new TranslationManager(this);
this.integrationManager = new BukkitIntegrationManager(this); this.integrationManager = new BukkitIntegrationManager(this);
this.gameManager = new BukkitGameManager(this); this.gameManager = new BukkitGameManager(this);
this.hologramManager = new HologramManager(this);
this.commandManager = new BukkitCommandManager(this); this.commandManager = new BukkitCommandManager(this);
this.commandManager.registerDefaultFeatures(); this.commandManager.registerDefaultFeatures();
@@ -196,6 +198,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
this.bagManager.reload(); this.bagManager.reload();
this.storageManager.reload(); this.storageManager.reload();
this.fishingManager.reload(); this.fishingManager.reload();
this.hologramManager.reload();
this.itemManager.load(); this.itemManager.load();
this.eventManager.load(); this.eventManager.load();
@@ -230,6 +233,7 @@ public class BukkitCustomFishingPluginImpl extends BukkitCustomFishingPlugin {
this.bagManager.disable(); this.bagManager.disable();
this.integrationManager.disable(); this.integrationManager.disable();
this.storageManager.disable(); this.storageManager.disable();
this.hologramManager.disable();
this.commandManager.unregisterFeatures(); this.commandManager.unregisterFeatures();
} }

View File

@@ -37,6 +37,7 @@ import net.momirealms.customfishing.api.util.PlayerUtils;
import net.momirealms.customfishing.bukkit.integration.VaultHook; import net.momirealms.customfishing.bukkit.integration.VaultHook;
import net.momirealms.customfishing.bukkit.util.LocationUtils; import net.momirealms.customfishing.bukkit.util.LocationUtils;
import net.momirealms.customfishing.common.helper.AdventureHelper; 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.MessageConstants;
import net.momirealms.customfishing.common.locale.TranslationManager; import net.momirealms.customfishing.common.locale.TranslationManager;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; 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.Pair;
import net.momirealms.customfishing.common.util.RandomUtils; import net.momirealms.customfishing.common.util.RandomUtils;
import net.momirealms.sparrow.heart.SparrowHeart; 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.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@@ -89,9 +92,13 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
@Override @Override
public boolean registerAction(String type, ActionFactory<Player> actionFactory) { public boolean registerAction(ActionFactory<Player> actionFactory, String... types) {
if (this.actionFactoryMap.containsKey(type)) return false; for (String type : types) {
this.actionFactoryMap.put(type, actionFactory); if (this.actionFactoryMap.containsKey(type)) return false;
}
for (String type : types) {
this.actionFactoryMap.put(type, actionFactory);
}
return true; return true;
} }
@@ -155,7 +162,7 @@ public class BukkitActionManager implements ActionManager<Player> {
this.registerCloseInvAction(); this.registerCloseInvAction();
this.registerExpAction(); this.registerExpAction();
this.registerFoodAction(); this.registerFoodAction();
this.registerChainAction(); this.registerBuildAction();
this.registerMoneyAction(); this.registerMoneyAction();
this.registerItemAction(); this.registerItemAction();
this.registerPotionAction(); this.registerPotionAction();
@@ -168,7 +175,7 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
private void registerMessageAction() { private void registerMessageAction() {
registerAction("message", (args, chance) -> { registerAction((args, chance) -> {
List<String> messages = ListUtils.toList(args); List<String> messages = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -178,8 +185,8 @@ public class BukkitActionManager implements ActionManager<Player> {
audience.sendMessage(AdventureHelper.miniMessage(text)); audience.sendMessage(AdventureHelper.miniMessage(text));
} }
}; };
}); }, "message");
registerAction("random-message", (args, chance) -> { registerAction((args, chance) -> {
List<String> messages = ListUtils.toList(args); List<String> messages = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -188,8 +195,8 @@ public class BukkitActionManager implements ActionManager<Player> {
Audience audience = plugin.getSenderFactory().getAudience(context.holder()); Audience audience = plugin.getSenderFactory().getAudience(context.holder());
audience.sendMessage(AdventureHelper.miniMessage(random)); audience.sendMessage(AdventureHelper.miniMessage(random));
}; };
}); }, "random-message");
registerAction("broadcast", (args, chance) -> { registerAction((args, chance) -> {
List<String> messages = ListUtils.toList(args); List<String> messages = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -201,8 +208,8 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
} }
}; };
}); }, "broadcast");
registerAction("message-nearby", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
List<String> messages = ListUtils.toList(section.get("message")); List<String> messages = ListUtils.toList(section.get("message"));
MathValue<Player> range = MathValue.auto(section.get("range")); MathValue<Player> range = MathValue.auto(section.get("range"));
@@ -230,11 +237,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at message-nearby action which should be Section"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at message-nearby action which should be Section");
return Action.empty(); return Action.empty();
} }
}); }, "message-nearby");
} }
private void registerCommandAction() { private void registerCommandAction() {
registerAction("command", (args, chance) -> { registerAction((args, chance) -> {
List<String> commands = ListUtils.toList(args); List<String> commands = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -245,8 +252,8 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
}, null); }, null);
}; };
}); }, "command");
registerAction("player-command", (args, chance) -> { registerAction((args, chance) -> {
List<String> commands = ListUtils.toList(args); List<String> commands = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -257,8 +264,8 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
}, context.holder().getLocation()); }, context.holder().getLocation());
}; };
}); }, "player-command");
registerAction("random-command", (args, chance) -> { registerAction((args, chance) -> {
List<String> commands = ListUtils.toList(args); List<String> commands = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -269,8 +276,8 @@ public class BukkitActionManager implements ActionManager<Player> {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalRandom);
}, null); }, null);
}; };
}); }, "random-command");
registerAction("command-nearby", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
List<String> cmd = ListUtils.toList(section.get("command")); List<String> cmd = ListUtils.toList(section.get("command"));
MathValue<Player> range = MathValue.auto(section.get("range")); MathValue<Player> range = MathValue.auto(section.get("range"));
@@ -293,18 +300,18 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at command-nearby action which should be Section"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at command-nearby action which should be Section");
return Action.empty(); return Action.empty();
} }
}); }, "command-nearby");
} }
private void registerCloseInvAction() { private void registerCloseInvAction() {
registerAction("close-inv", (args, chance) -> condition -> { registerAction((args, chance) -> condition -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
condition.holder().closeInventory(); condition.holder().closeInventory();
}); }, "close-inv");
} }
private void registerActionBarAction() { private void registerActionBarAction() {
registerAction("actionbar", (args, chance) -> { registerAction((args, chance) -> {
String text = (String) args; String text = (String) args;
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -312,8 +319,8 @@ public class BukkitActionManager implements ActionManager<Player> {
Component component = AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(context.holder(), text, context.placeholderMap())); Component component = AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(context.holder(), text, context.placeholderMap()));
audience.sendActionBar(component); audience.sendActionBar(component);
}; };
}); }, "actionbar");
registerAction("random-actionbar", (args, chance) -> { registerAction((args, chance) -> {
List<String> texts = ListUtils.toList(args); List<String> texts = ListUtils.toList(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -322,8 +329,8 @@ public class BukkitActionManager implements ActionManager<Player> {
Audience audience = plugin.getSenderFactory().getAudience(context.holder()); Audience audience = plugin.getSenderFactory().getAudience(context.holder());
audience.sendActionBar(AdventureHelper.miniMessage(random)); audience.sendActionBar(AdventureHelper.miniMessage(random));
}; };
}); }, "random-actionbar");
registerAction("actionbar-nearby", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String actionbar = section.getString("actionbar"); String actionbar = section.getString("actionbar");
MathValue<Player> range = MathValue.auto(section.get("range")); MathValue<Player> range = MathValue.auto(section.get("range"));
@@ -345,11 +352,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at actionbar-nearby action which should be Section"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at actionbar-nearby action which should be Section");
return Action.empty(); return Action.empty();
} }
}); }, "actionbar-nearby");
} }
private void registerExpAction() { private void registerExpAction() {
registerAction("mending", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -357,8 +364,8 @@ public class BukkitActionManager implements ActionManager<Player> {
ExperienceOrb entity = player.getLocation().getWorld().spawn(player.getLocation().clone().add(0,0.5,0), ExperienceOrb.class); ExperienceOrb entity = player.getLocation().getWorld().spawn(player.getLocation().clone().add(0,0.5,0), ExperienceOrb.class);
entity.setExperience((int) value.evaluate(context)); entity.setExperience((int) value.evaluate(context));
}; };
}); }, "mending");
registerAction("exp", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
@@ -367,38 +374,38 @@ public class BukkitActionManager implements ActionManager<Player> {
Audience audience = plugin.getSenderFactory().getAudience(player); Audience audience = plugin.getSenderFactory().getAudience(player);
AdventureHelper.playSound(audience, Sound.sound(Key.key("minecraft:entity.experience_orb.pickup"), Sound.Source.PLAYER, 1, 1)); AdventureHelper.playSound(audience, Sound.sound(Key.key("minecraft:entity.experience_orb.pickup"), Sound.Source.PLAYER, 1, 1));
}; };
}); }, "exp");
registerAction("level", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
Player player = context.holder(); Player player = context.holder();
player.setLevel((int) Math.max(0, player.getLevel() + value.evaluate(context))); player.setLevel((int) Math.max(0, player.getLevel() + value.evaluate(context)));
}; };
}); }, "level");
} }
private void registerFoodAction() { private void registerFoodAction() {
registerAction("food", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
Player player = context.holder(); Player player = context.holder();
player.setFoodLevel((int) (player.getFoodLevel() + value.evaluate(context))); player.setFoodLevel((int) (player.getFoodLevel() + value.evaluate(context)));
}; };
}); }, "food");
registerAction("saturation", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
Player player = context.holder(); Player player = context.holder();
player.setSaturation((float) (player.getSaturation() + value.evaluate(context))); player.setSaturation((float) (player.getSaturation() + value.evaluate(context)));
}; };
}); }, "saturation");
} }
private void registerItemAction() { private void registerItemAction() {
registerAction("item-amount", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
boolean mainOrOff = section.getString("hand", "main").equalsIgnoreCase("main"); boolean mainOrOff = section.getString("hand", "main").equalsIgnoreCase("main");
int amount = section.getInt("amount", 1); int amount = section.getInt("amount", 1);
@@ -417,8 +424,8 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "item-amount");
registerAction("durability", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
EquipmentSlot slot = Optional.ofNullable(section.getString("slot")) EquipmentSlot slot = Optional.ofNullable(section.getString("slot"))
.map(hand -> EquipmentSlot.valueOf(hand.toUpperCase(Locale.ENGLISH))) .map(hand -> EquipmentSlot.valueOf(hand.toUpperCase(Locale.ENGLISH)))
@@ -450,8 +457,8 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at durability action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at durability action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "durability");
registerAction("give-item", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String id = section.getString("item"); String id = section.getString("item");
int amount = section.getInt("amount", 1); int amount = section.getInt("amount", 1);
@@ -480,11 +487,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at give-item action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at give-item action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "give-item");
} }
private void registerChainAction() { private void registerBuildAction() {
registerAction("chain", (args, chance) -> { registerAction((args, chance) -> {
List<Action<Player>> actions = new ArrayList<>(); List<Action<Player>> actions = new ArrayList<>();
if (args instanceof Section section) { if (args instanceof Section section) {
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) { for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
@@ -499,8 +506,8 @@ public class BukkitActionManager implements ActionManager<Player> {
action.trigger(context); action.trigger(context);
} }
}; };
}); }, "chain");
registerAction("delay", (args, chance) -> { registerAction((args, chance) -> {
List<Action<Player>> actions = new ArrayList<>(); List<Action<Player>> actions = new ArrayList<>();
int delay; int delay;
boolean async; boolean async;
@@ -531,8 +538,8 @@ public class BukkitActionManager implements ActionManager<Player> {
}, delay, location); }, delay, location);
} }
}; };
}); }, "delay");
registerAction("timer", (args, chance) -> { registerAction((args, chance) -> {
List<Action<Player>> actions = new ArrayList<>(); List<Action<Player>> actions = new ArrayList<>();
int delay, duration, period; int delay, duration, period;
boolean async; boolean async;
@@ -571,8 +578,8 @@ public class BukkitActionManager implements ActionManager<Player> {
} }
plugin.getScheduler().asyncLater(task::cancel, duration * 50L, TimeUnit.MILLISECONDS); plugin.getScheduler().asyncLater(task::cancel, duration * 50L, TimeUnit.MILLISECONDS);
}; };
}); }, "timer");
registerAction("conditional", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
Action<Player>[] actions = parseActions(section.getSection("actions")); Action<Player>[] actions = parseActions(section.getSection("actions"));
Requirement<Player>[] requirements = plugin.getRequirementManager().parseRequirements(section.getSection("conditions"), true); Requirement<Player>[] requirements = plugin.getRequirementManager().parseRequirements(section.getSection("conditions"), true);
@@ -591,8 +598,8 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at conditional action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at conditional action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "conditional");
registerAction("priority", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
List<Pair<Requirement<Player>[], Action<Player>[]>> conditionActionPairList = new ArrayList<>(); List<Pair<Requirement<Player>[], Action<Player>[]>> conditionActionPairList = new ArrayList<>();
for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) { for (Map.Entry<String, Object> entry : section.getStringRouteMappedValues(false).entrySet()) {
@@ -623,32 +630,32 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at priority action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at priority action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "priority");
} }
private void registerMoneyAction() { private void registerMoneyAction() {
registerAction("give-money", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
if (!VaultHook.isHooked()) return; if (!VaultHook.isHooked()) return;
VaultHook.deposit(context.holder(), value.evaluate(context)); VaultHook.deposit(context.holder(), value.evaluate(context));
}; };
}); }, "give-money");
registerAction("take-money", (args, chance) -> { registerAction((args, chance) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
if (!VaultHook.isHooked()) return; if (!VaultHook.isHooked()) return;
VaultHook.withdraw(context.holder(), value.evaluate(context)); VaultHook.withdraw(context.holder(), value.evaluate(context));
}; };
}); }, "take-money");
} }
// The registry name changes a lot // The registry name changes a lot
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void registerPotionAction() { private void registerPotionAction() {
registerAction("potion-effect", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
PotionEffect potionEffect = new PotionEffect( PotionEffect potionEffect = new PotionEffect(
Objects.requireNonNull(PotionEffectType.getByName(section.getString("type", "BLINDNESS").toUpperCase(Locale.ENGLISH))), Objects.requireNonNull(PotionEffectType.getByName(section.getString("type", "BLINDNESS").toUpperCase(Locale.ENGLISH))),
@@ -663,11 +670,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at potion-effect action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at potion-effect action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "potion-effect");
} }
private void registerSoundAction() { private void registerSoundAction() {
registerAction("sound", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
Sound sound = Sound.sound( Sound sound = Sound.sound(
Key.key(section.getString("key")), Key.key(section.getString("key")),
@@ -684,12 +691,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at sound action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at sound action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "sound");
} }
private void registerPluginExpAction() { private void registerPluginExpAction() {
registerAction("plugin-exp", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String pluginName = section.getString("plugin"); String pluginName = section.getString("plugin");
MathValue<Player> value = MathValue.auto(section.get("exp")); MathValue<Player> value = MathValue.auto(section.get("exp"));
@@ -704,11 +710,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-exp action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-exp action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "plugin-exp");
} }
private void registerTitleAction() { private void registerTitleAction() {
registerAction("title", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> title = TextValue.auto(section.getString("title", "")); TextValue<Player> title = TextValue.auto(section.getString("title", ""));
TextValue<Player> subtitle = TextValue.auto(section.getString("subtitle", "")); TextValue<Player> subtitle = TextValue.auto(section.getString("subtitle", ""));
@@ -729,8 +735,8 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "title");
registerAction("random-title", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
List<String> titles = section.getStringList("titles"); List<String> titles = section.getStringList("titles");
if (titles.isEmpty()) titles.add(""); if (titles.isEmpty()) titles.add("");
@@ -755,8 +761,8 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at random-title action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at random-title action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "random-title");
registerAction("title-nearby", (args, chance) -> { registerAction((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> title = TextValue.auto(section.getString("title")); TextValue<Player> title = TextValue.auto(section.getString("title"));
TextValue<Player> subtitle = TextValue.auto(section.getString("subtitle")); TextValue<Player> subtitle = TextValue.auto(section.getString("subtitle"));
@@ -783,11 +789,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title-nearby action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title-nearby action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
}); }, "title-nearby");
} }
private void registerFakeItemAction() { private void registerFakeItemAction() {
registerAction("fake-item", ((args, chance) -> { registerAction(((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String itemID = section.getString("item", ""); String itemID = section.getString("item", "");
String[] split = itemID.split(":"); String[] split = itemID.split(":");
@@ -800,17 +806,28 @@ public class BukkitActionManager implements ActionManager<Player> {
MathValue<Player> yaw = MathValue.auto(section.get("yaw", 0)); MathValue<Player> yaw = MathValue.auto(section.get("yaw", 0));
int range = section.getInt("range", 0); int range = section.getInt("range", 0);
boolean opposite = section.getBoolean("opposite-yaw", false); boolean opposite = section.getBoolean("opposite-yaw", false);
boolean useItemDisplay = section.getBoolean("use-item-display", false);
String finalItemID = itemID; String finalItemID = itemID;
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
Player owner = context.holder(); Player owner = context.holder();
Location location = position ? requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)).clone() : owner.getLocation().clone(); 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.add(x.evaluate(context), y.evaluate(context) - 1, z.evaluate(context));
location.setPitch(0);
if (opposite) location.setYaw(-owner.getLocation().getYaw()); if (opposite) location.setYaw(-owner.getLocation().getYaw());
else location.setYaw((float) yaw.evaluate(context)); else location.setYaw((float) yaw.evaluate(context));
FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); FakeEntity fakeEntity;
armorStand.invisible(true); if (useItemDisplay && VersionHelper.isVersionNewerThan1_19_4()) {
armorStand.equipment(EquipmentSlot.HEAD, plugin.getItemManager().buildInternal(context, finalItemID)); 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<Player> viewers = new ArrayList<>(); ArrayList<Player> viewers = new ArrayList<>();
if (range > 0) { if (range > 0) {
for (Player player : location.getWorld().getPlayers()) { for (Player player : location.getWorld().getPlayers()) {
@@ -822,12 +839,12 @@ public class BukkitActionManager implements ActionManager<Player> {
viewers.add(owner); viewers.add(owner);
} }
for (Player player : viewers) { for (Player player : viewers) {
armorStand.spawn(player); fakeEntity.spawn(player);
} }
plugin.getScheduler().asyncLater(() -> { plugin.getScheduler().asyncLater(() -> {
for (Player player : viewers) { for (Player player : viewers) {
if (player.isOnline() && player.isValid()) { if (player.isOnline() && player.isValid()) {
armorStand.destroy(player); fakeEntity.destroy(player);
} }
} }
}, (long) (duration.evaluate(context) * 50), TimeUnit.MILLISECONDS); }, (long) (duration.evaluate(context) * 50), TimeUnit.MILLISECONDS);
@@ -836,11 +853,11 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at fake-item action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at fake-item action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
})); }), "fake-item");
} }
private void registerHologramAction() { private void registerHologramAction() {
registerAction("hologram", ((args, chance) -> { registerAction(((args, chance) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> text = TextValue.auto(section.getString("text", "")); TextValue<Player> text = TextValue.auto(section.getString("text", ""));
MathValue<Player> duration = MathValue.auto(section.get("duration", 20)); MathValue<Player> duration = MathValue.auto(section.get("duration", 20));
@@ -848,17 +865,20 @@ public class BukkitActionManager implements ActionManager<Player> {
MathValue<Player> x = MathValue.auto(section.get("x", 0)); MathValue<Player> x = MathValue.auto(section.get("x", 0));
MathValue<Player> y = MathValue.auto(section.get("y", 0)); MathValue<Player> y = MathValue.auto(section.get("y", 0));
MathValue<Player> z = MathValue.auto(section.get("z", 0)); MathValue<Player> 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); int range = section.getInt("range", 16);
boolean useTextDisplay = section.getBoolean("use-text-display", false);
return context -> { return context -> {
if (Math.random() > chance) return; if (Math.random() > chance) return;
Player owner = context.holder(); Player owner = context.holder();
Location location = position ? requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)).clone() : owner.getLocation().clone(); Location location = position ? requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)).clone() : owner.getLocation().clone();
location.add(x.evaluate(context), y.evaluate(context), z.evaluate(context)); location.add(x.evaluate(context), y.evaluate(context), z.evaluate(context));
FakeArmorStand armorStand = SparrowHeart.getInstance().createFakeArmorStand(location); HashSet<Player> viewers = new HashSet<>();
armorStand.invisible(true);
armorStand.small(true);
armorStand.name(AdventureHelper.miniMessageToJson(text.render(context)));
ArrayList<Player> viewers = new ArrayList<>();
if (range > 0) { if (range > 0) {
for (Player player : location.getWorld().getPlayers()) { for (Player player : location.getWorld().getPlayers()) {
if (LocationUtils.getDistance(player.getLocation(), location) <= range) { if (LocationUtils.getDistance(player.getLocation(), location) <= range) {
@@ -868,26 +888,17 @@ public class BukkitActionManager implements ActionManager<Player> {
} else { } else {
viewers.add(owner); viewers.add(owner);
} }
for (Player player : viewers) { plugin.getHologramManager().createHologram(location, AdventureHelper.miniMessageToJson(text.render(context)), (int) duration.evaluate(context), useTextDisplay, rgba, 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);
}; };
} else { } else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at hologram action which is expected to be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at hologram action which is expected to be `Section`");
return Action.empty(); return Action.empty();
} }
})); }), "hologram");
} }
private void registerFishFindAction() { private void registerFishFindAction() {
registerAction("fish-finder", (args, chance) -> { registerAction((args, chance) -> {
String surrounding; String surrounding;
if (args instanceof Boolean b) { if (args instanceof Boolean b) {
surrounding = b ? "lava" : "water"; surrounding = b ? "lava" : "water";
@@ -920,7 +931,7 @@ public class BukkitActionManager implements ActionManager<Player> {
plugin.getSenderFactory().wrap(context.holder()).sendMessage(TranslationManager.render(MessageConstants.COMMAND_FISH_FINDER_POSSIBLE_LOOTS.arguments(AdventureHelper.miniMessage(stringJoiner.toString())).build())); 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<Player> {
for (Class<? extends ActionExpansion<Player>> expansionClass : classes) { for (Class<? extends ActionExpansion<Player>> expansionClass : classes) {
ActionExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance(); ActionExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance();
unregisterAction(expansion.getActionType()); 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() ); plugin.getPluginLogger().info("Loaded action expansion: " + expansion.getActionType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor() );
} }
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {

View File

@@ -45,6 +45,7 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@@ -80,9 +81,13 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
} }
@Override @Override
public boolean registerRequirement(@NotNull String type, @NotNull RequirementFactory<Player> requirementFactory) { public boolean registerRequirement(@NotNull RequirementFactory<Player> requirementFactory, @NotNull String... types) {
if (this.requirementFactoryMap.containsKey(type)) return false; for (String type : types) {
this.requirementFactoryMap.put(type, requirementFactory); if (this.requirementFactoryMap.containsKey(type)) return false;
}
for (String type : types) {
this.requirementFactoryMap.put(type, requirementFactory);
}
return true; return true;
} }
@@ -188,17 +193,20 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
this.registerItemInHandRequirement(); this.registerItemInHandRequirement();
this.registerImpossibleRequirement(); this.registerImpossibleRequirement();
this.registerPotionEffectRequirement(); this.registerPotionEffectRequirement();
this.registerSneakRequirement();
this.registerGameModeRequirement();
this.registerEquipmentRequirement();
} }
private void registerImpossibleRequirement() { private void registerImpossibleRequirement() {
registerRequirement("impossible", ((args, actions, runActions) -> context -> { registerRequirement(((args, actions, runActions) -> context -> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
})); }), "impossible");
} }
private void registerCompetitionRequirement() { private void registerCompetitionRequirement() {
registerRequirement("competition", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
boolean onCompetition = section.getBoolean("ongoing", true); boolean onCompetition = section.getBoolean("ongoing", true);
List<String> ids = section.contains("id") ? ListUtils.toList(section.get("id")) : List.of(); List<String> ids = section.contains("id") ? ListUtils.toList(section.get("id")) : List.of();
@@ -225,11 +233,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at competition requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at competition requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "competition");
} }
private void registerInBagRequirement() { private void registerInBagRequirement() {
registerRequirement("in-fishingbag", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean arg = (boolean) args; boolean arg = (boolean) args;
return context -> { return context -> {
boolean inBag = Optional.ofNullable(context.arg(ContextKeys.IN_BAG)).orElse(false); boolean inBag = Optional.ofNullable(context.arg(ContextKeys.IN_BAG)).orElse(false);
@@ -237,11 +245,30 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; 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<String> 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() { private void registerItemInHandRequirement() {
registerRequirement("item-in-hand", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main"); boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main");
int amount = section.getInt("amount", 1); int amount = section.getInt("amount", 1);
@@ -259,11 +286,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-in-hand requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-in-hand requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "item-in-hand");
} }
private void registerPluginLevelRequirement() { private void registerPluginLevelRequirement() {
registerRequirement("plugin-level", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String pluginName = section.getString("plugin"); String pluginName = section.getString("plugin");
int level = section.getInt("level"); int level = section.getInt("level");
@@ -283,11 +310,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-level requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-level requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "plugin-level");
} }
private void registerTimeRequirement() { private void registerTimeRequirement() {
registerRequirement("time", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> list = ListUtils.toList(args); List<String> list = ListUtils.toList(args);
List<Pair<Integer, Integer>> timePairs = list.stream().map(line -> { List<Pair<Integer, Integer>> timePairs = list.stream().map(line -> {
String[] split = line.split("~"); String[] split = line.split("~");
@@ -302,11 +329,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "time");
} }
private void registerYRequirement() { private void registerYRequirement() {
registerRequirement("ypos", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> list = ListUtils.toList(args); List<String> list = ListUtils.toList(args);
List<Pair<Double, Double>> posPairs = list.stream().map(line -> { List<Pair<Double, Double>> posPairs = list.stream().map(line -> {
String[] split = line.split("~"); String[] split = line.split("~");
@@ -321,11 +348,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "ypos");
} }
private void registerOrRequirement() { private void registerOrRequirement() {
registerRequirement("||", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
Requirement<Player>[] requirements = parseRequirements(section, runActions); Requirement<Player>[] requirements = parseRequirements(section, runActions);
return context -> { return context -> {
@@ -339,11 +366,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at || requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at || requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "||");
} }
private void registerAndRequirement() { private void registerAndRequirement() {
registerRequirement("&&", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
Requirement<Player>[] requirements = parseRequirements(section, runActions); Requirement<Player>[] requirements = parseRequirements(section, runActions);
return context -> { return context -> {
@@ -360,11 +387,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at && requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at && requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "&&");
} }
private void registerInWaterRequirement() { private void registerInWaterRequirement() {
registerRequirement("in-water", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean inWater = (boolean) args; boolean inWater = (boolean) args;
return context -> { return context -> {
boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key()); boolean in_water = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.WATER_FISHING.key());
@@ -372,11 +399,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "in-water");
} }
private void registerInVoidRequirement() { private void registerInVoidRequirement() {
registerRequirement("in-void", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean inVoid = (boolean) args; boolean inVoid = (boolean) args;
return context -> { return context -> {
boolean in_void = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.VOID_FISHING.key()); boolean in_void = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.VOID_FISHING.key());
@@ -384,12 +411,12 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "in-void");
} }
private void registerInLavaRequirement() { private void registerInLavaRequirement() {
// Deprecated requirement type // Deprecated requirement type
registerRequirement("lava-fishing", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean inLava = (boolean) args; boolean inLava = (boolean) args;
if (!inLava) { if (!inLava) {
// in water // in water
@@ -407,8 +434,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "lava-fishing");
registerRequirement("in-lava", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean inLava = (boolean) args; boolean inLava = (boolean) args;
return context -> { return context -> {
boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key()); boolean in_lava = Optional.ofNullable(context.arg(ContextKeys.SURROUNDING)).orElse("").equals(EffectProperties.LAVA_FISHING.key());
@@ -416,11 +443,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "in-lava");
} }
private void registerRodRequirement() { private void registerRodRequirement() {
registerRequirement("rod", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> rods = new HashSet<>(ListUtils.toList(args)); HashSet<String> rods = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.ROD); String id = context.arg(ContextKeys.ROD);
@@ -428,8 +455,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "rod");
registerRequirement("!rod", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> rods = new HashSet<>(ListUtils.toList(args)); HashSet<String> rods = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.ROD); String id = context.arg(ContextKeys.ROD);
@@ -437,11 +464,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!rod");
} }
private void registerGroupRequirement() { private void registerGroupRequirement() {
registerRequirement("group", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> groups = new HashSet<>(ListUtils.toList(args)); HashSet<String> groups = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String lootID = context.arg(ContextKeys.ID); String lootID = context.arg(ContextKeys.ID);
@@ -455,8 +482,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "group");
registerRequirement("!group", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> groups = new HashSet<>(ListUtils.toList(args)); HashSet<String> groups = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String lootID = context.arg(ContextKeys.ID); String lootID = context.arg(ContextKeys.ID);
@@ -474,11 +501,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!group");
} }
private void registerLootRequirement() { private void registerLootRequirement() {
registerRequirement("loot", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> arg = new HashSet<>(ListUtils.toList(args)); HashSet<String> arg = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String lootID = context.arg(ContextKeys.ID); String lootID = context.arg(ContextKeys.ID);
@@ -486,8 +513,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "loot");
registerRequirement("!loot", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> arg = new HashSet<>(ListUtils.toList(args)); HashSet<String> arg = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String lootID = context.arg(ContextKeys.ID); String lootID = context.arg(ContextKeys.ID);
@@ -495,11 +522,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!loot");
} }
private void registerHookRequirement() { private void registerHookRequirement() {
registerRequirement("hook", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> hooks = new HashSet<>(ListUtils.toList(args)); HashSet<String> hooks = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.HOOK); String id = context.arg(ContextKeys.HOOK);
@@ -507,8 +534,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "hook");
registerRequirement("!hook", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> hooks = new HashSet<>(ListUtils.toList(args)); HashSet<String> hooks = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.HOOK); String id = context.arg(ContextKeys.HOOK);
@@ -516,8 +543,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!hook");
registerRequirement("has-hook", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean has = (boolean) args; boolean has = (boolean) args;
return context -> { return context -> {
String id = context.arg(ContextKeys.HOOK); String id = context.arg(ContextKeys.HOOK);
@@ -526,11 +553,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "has-hook");
} }
private void registerBaitRequirement() { private void registerBaitRequirement() {
registerRequirement("bait", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> arg = new HashSet<>(ListUtils.toList(args)); HashSet<String> arg = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.BAIT); String id = context.arg(ContextKeys.BAIT);
@@ -538,8 +565,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "bait");
registerRequirement("!bait", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> arg = new HashSet<>(ListUtils.toList(args)); HashSet<String> arg = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String id = context.arg(ContextKeys.BAIT); String id = context.arg(ContextKeys.BAIT);
@@ -547,8 +574,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!bait");
registerRequirement("has-bait", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean has = (boolean) args; boolean has = (boolean) args;
return context -> { return context -> {
String id = context.arg(ContextKeys.BAIT); String id = context.arg(ContextKeys.BAIT);
@@ -557,11 +584,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "has-bait");
} }
private void registerSizeRequirement() { private void registerSizeRequirement() {
registerRequirement("has-size", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean has = (boolean) args; boolean has = (boolean) args;
return context -> { return context -> {
float size = Optional.ofNullable(context.arg(ContextKeys.SIZE)).orElse(-1f); float size = Optional.ofNullable(context.arg(ContextKeys.SIZE)).orElse(-1f);
@@ -570,11 +597,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "has-size");
} }
private void registerOpenWaterRequirement() { private void registerOpenWaterRequirement() {
registerRequirement("open-water", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean openWater = (boolean) args; boolean openWater = (boolean) args;
return context -> { return context -> {
boolean current = Optional.ofNullable(context.arg(ContextKeys.OPEN_WATER)).orElse(false); boolean current = Optional.ofNullable(context.arg(ContextKeys.OPEN_WATER)).orElse(false);
@@ -583,11 +610,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "open-water");
} }
private void registerHasStatsRequirement() { private void registerHasStatsRequirement() {
registerRequirement("has-stats", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean has = (boolean) args; boolean has = (boolean) args;
return context -> { return context -> {
String loot = context.arg(ContextKeys.ID); String loot = context.arg(ContextKeys.ID);
@@ -599,11 +626,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "has-stats");
} }
private void registerLootTypeRequirement() { private void registerLootTypeRequirement() {
registerRequirement("loot-type", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> types = ListUtils.toList(args); List<String> types = ListUtils.toList(args);
return context -> { return context -> {
String loot = context.arg(ContextKeys.ID); String loot = context.arg(ContextKeys.ID);
@@ -615,8 +642,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "loot-type");
registerRequirement("!loot-type", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> types = ListUtils.toList(args); List<String> types = ListUtils.toList(args);
return context -> { return context -> {
String loot = context.arg(ContextKeys.ID); String loot = context.arg(ContextKeys.ID);
@@ -628,22 +655,22 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!loot-type");
} }
private void registerListRequirement() { 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().severe("It seems that you made a mistake where you put \"list\" into \"conditions\" section.");
plugin.getPluginLogger().warn("list:"); plugin.getPluginLogger().warn("list:");
for (String e : ListUtils.toList(args)) { for (String e : ListUtils.toList(args)) {
plugin.getPluginLogger().warn(" - " + e); plugin.getPluginLogger().warn(" - " + e);
} }
return Requirement.empty(); return Requirement.empty();
}); }, "list");
} }
private void registerEnvironmentRequirement() { private void registerEnvironmentRequirement() {
registerRequirement("environment", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> environments = ListUtils.toList(args); List<String> environments = ListUtils.toList(args);
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -652,8 +679,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "environment");
registerRequirement("!environment", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> environments = ListUtils.toList(args); List<String> environments = ListUtils.toList(args);
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -662,11 +689,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!environment");
} }
private void registerIceFishingRequirement() { private void registerIceFishingRequirement() {
registerRequirement("ice-fishing", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
boolean iceFishing = (boolean) args; boolean iceFishing = (boolean) args;
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.OTHER_LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.OTHER_LOCATION));
@@ -686,11 +713,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "ice-fishing");
} }
private void registerLevelRequirement() { private void registerLevelRequirement() {
registerRequirement("level", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
int current = context.holder().getLevel(); int current = context.holder().getLevel();
@@ -699,11 +726,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "level");
} }
private void registerMoneyRequirement() { private void registerMoneyRequirement() {
registerRequirement("money", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
double current = VaultHook.getBalance(context.holder()); double current = VaultHook.getBalance(context.holder());
@@ -712,11 +739,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "money");
} }
private void registerRandomRequirement() { private void registerRandomRequirement() {
registerRequirement("random", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
MathValue<Player> value = MathValue.auto(args); MathValue<Player> value = MathValue.auto(args);
return context -> { return context -> {
if (Math.random() < value.evaluate(context, true)) if (Math.random() < value.evaluate(context, true))
@@ -724,11 +751,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "random");
} }
private void registerBiomeRequirement() { private void registerBiomeRequirement() {
registerRequirement("biome", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> biomes = new HashSet<>(ListUtils.toList(args)); HashSet<String> biomes = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION)));
@@ -738,8 +765,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "biome");
registerRequirement("!biome", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> biomes = new HashSet<>(ListUtils.toList(args)); HashSet<String> biomes = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION))); Location location = requireNonNull(Optional.ofNullable(context.arg(ContextKeys.OTHER_LOCATION)).orElse(context.arg(ContextKeys.LOCATION)));
@@ -749,11 +776,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!biome");
} }
private void registerMoonPhaseRequirement() { private void registerMoonPhaseRequirement() {
registerRequirement("moon-phase", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> moonPhases = new HashSet<>(ListUtils.toList(args)); HashSet<String> moonPhases = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -763,8 +790,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "moon-phase");
registerRequirement("!moon-phase", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> moonPhases = new HashSet<>(ListUtils.toList(args)); HashSet<String> moonPhases = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -774,11 +801,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!moon-phase");
} }
private void registerWorldRequirement() { private void registerWorldRequirement() {
registerRequirement("world", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> worlds = new HashSet<>(ListUtils.toList(args)); HashSet<String> worlds = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -787,8 +814,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "world");
registerRequirement("!world", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> worlds = new HashSet<>(ListUtils.toList(args)); HashSet<String> worlds = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
@@ -797,11 +824,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "!world");
} }
private void registerWeatherRequirement() { private void registerWeatherRequirement() {
registerRequirement("weather", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> weathers = new HashSet<>(ListUtils.toList(args)); HashSet<String> weathers = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
String currentWeather; String currentWeather;
@@ -814,11 +841,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "weather");
} }
private void registerCoolDownRequirement() { private void registerCoolDownRequirement() {
registerRequirement("cooldown", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
String key = section.getString("key"); String key = section.getString("key");
int time = section.getInt("time"); int time = section.getInt("time");
@@ -832,11 +859,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at cooldown requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at cooldown requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "cooldown");
} }
private void registerDateRequirement() { private void registerDateRequirement() {
registerRequirement("date", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
HashSet<String> dates = new HashSet<>(ListUtils.toList(args)); HashSet<String> dates = new HashSet<>(ListUtils.toList(args));
return context -> { return context -> {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@@ -846,11 +873,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "date");
} }
private void registerPermissionRequirement() { private void registerPermissionRequirement() {
registerRequirement("permission", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> perms = ListUtils.toList(args); List<String> perms = ListUtils.toList(args);
return context -> { return context -> {
for (String perm : perms) for (String perm : perms)
@@ -859,8 +886,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "permission");
registerRequirement("!permission", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> perms = ListUtils.toList(args); List<String> perms = ListUtils.toList(args);
return context -> { return context -> {
for (String perm : perms) for (String perm : perms)
@@ -870,11 +897,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
} }
return true; return true;
}; };
}); }, "!permission");
} }
private void registerSeasonRequirement() { private void registerSeasonRequirement() {
registerRequirement("season", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
List<String> seasons = ListUtils.toList(args); List<String> seasons = ListUtils.toList(args);
return context -> { return context -> {
SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonProvider(); SeasonProvider seasonProvider = plugin.getIntegrationManager().getSeasonProvider();
@@ -886,11 +913,11 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; return false;
}; };
}); }, "season");
} }
private void registerPAPIRequirement() { private void registerPAPIRequirement() {
registerRequirement("<", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -903,8 +930,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at < requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at < requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "<");
registerRequirement("<=", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -917,8 +944,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at <= requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at <= requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "<=");
registerRequirement("!=", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -931,8 +958,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at != requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at != requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!=");
registerRequirement("==", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -945,8 +972,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at == requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at == requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "==");
registerRequirement(">=", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -959,8 +986,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at >= requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at >= requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, ">=");
registerRequirement(">", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
MathValue<Player> v1 = MathValue.auto(section.get("value1")); MathValue<Player> v1 = MathValue.auto(section.get("value1"));
MathValue<Player> v2 = MathValue.auto(section.get("value2")); MathValue<Player> v2 = MathValue.auto(section.get("value2"));
@@ -973,8 +1000,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at > requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at > requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, ">");
registerRequirement("regex", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("papi", "")); TextValue<Player> v1 = TextValue.auto(section.getString("papi", ""));
String v2 = section.getString("regex", ""); String v2 = section.getString("regex", "");
@@ -987,8 +1014,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at regex requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at regex requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "regex");
registerRequirement("startsWith", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1001,8 +1028,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at startsWith requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at startsWith requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "startsWith");
registerRequirement("!startsWith", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1015,8 +1042,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !startsWith requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !startsWith requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!startsWith");
registerRequirement("endsWith", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1029,8 +1056,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at endsWith requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at endsWith requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "endsWith");
registerRequirement("!endsWith", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1043,8 +1070,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !endsWith requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !endsWith requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!endsWith");
registerRequirement("contains", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1057,8 +1084,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at contains requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at contains requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "contains");
registerRequirement("!contains", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1071,8 +1098,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !contains requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !contains requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!contains");
registerRequirement("in-list", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> papi = TextValue.auto(section.getString("papi", "")); TextValue<Player> papi = TextValue.auto(section.getString("papi", ""));
List<String> values = ListUtils.toList(section.get("values")); List<String> values = ListUtils.toList(section.get("values"));
@@ -1085,8 +1112,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at in-list requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at in-list requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "in-list");
registerRequirement("!in-list", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> papi = TextValue.auto(section.getString("papi", "")); TextValue<Player> papi = TextValue.auto(section.getString("papi", ""));
List<String> values = ListUtils.toList(section.get("values")); List<String> values = ListUtils.toList(section.get("values"));
@@ -1099,8 +1126,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !in-list requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !in-list requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!in-list");
registerRequirement("equals", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1114,8 +1141,8 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equals requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equals requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "equals");
registerRequirement("!equals", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
if (args instanceof Section section) { if (args instanceof Section section) {
TextValue<Player> v1 = TextValue.auto(section.getString("value1", "")); TextValue<Player> v1 = TextValue.auto(section.getString("value1", ""));
TextValue<Player> v2 = TextValue.auto(section.getString("value2", "")); TextValue<Player> v2 = TextValue.auto(section.getString("value2", ""));
@@ -1128,12 +1155,12 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !equals requirement which is expected be `Section`"); plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !equals requirement which is expected be `Section`");
return Requirement.empty(); return Requirement.empty();
} }
}); }, "!equals");
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void registerPotionEffectRequirement() { private void registerPotionEffectRequirement() {
registerRequirement("potion-effect", (args, actions, runActions) -> { registerRequirement((args, actions, runActions) -> {
String potions = (String) args; String potions = (String) args;
String[] split = potions.split("(<=|>=|<|>|==)", 2); String[] split = potions.split("(<=|>=|<|>|==)", 2);
PotionEffectType type = PotionEffectType.getByName(split[0]); PotionEffectType type = PotionEffectType.getByName(split[0]);
@@ -1176,7 +1203,40 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
if (runActions) ActionManager.trigger(context, actions); if (runActions) ActionManager.trigger(context, actions);
return false; 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<String> 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<Player> {
for (Class<? extends RequirementExpansion<Player>> expansionClass : classes) { for (Class<? extends RequirementExpansion<Player>> expansionClass : classes) {
RequirementExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance(); RequirementExpansion<Player> expansion = expansionClass.getDeclaredConstructor().newInstance();
unregisterRequirement(expansion.getRequirementType()); 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()); plugin.getPluginLogger().info("Loaded requirement expansion: " + expansion.getRequirementType() + "[" + expansion.getVersion() + "]" + " by " + expansion.getAuthor());
} }
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {

View File

@@ -41,6 +41,10 @@ public class BukkitExecutor implements RegionExecutor<Location> {
@Override @Override
public void run(Runnable r, Location l) { public void run(Runnable r, Location l) {
if (Bukkit.isPrimaryThread()) {
r.run();
return;
}
Bukkit.getScheduler().runTask(plugin, r); Bukkit.getScheduler().runTask(plugin, r);
} }

View File

@@ -71,6 +71,7 @@ public class ActivatedTotem {
task.cancel(); task.cancel();
} }
this.subTasks.clear(); this.subTasks.clear();
this.doEndAction();
} }
public long getExpireTime() { public long getExpireTime() {
@@ -86,4 +87,9 @@ public class ActivatedTotem {
BukkitCustomFishingPlugin.getInstance().getEventManager().getEventCarrier(totemConfig.id(), MechanicType.TOTEM) BukkitCustomFishingPlugin.getInstance().getEventManager().getEventCarrier(totemConfig.id(), MechanicType.TOTEM)
.ifPresent(carrier -> carrier.trigger(context, ActionTrigger.TIMER)); .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));
}
} }

View File

@@ -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.action.ActionTrigger;
import net.momirealms.customfishing.api.mechanic.config.ConfigManager; import net.momirealms.customfishing.api.mechanic.config.ConfigManager;
import net.momirealms.customfishing.api.mechanic.context.Context; 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.effect.EffectModifier;
import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager; import net.momirealms.customfishing.api.mechanic.requirement.RequirementManager;
import net.momirealms.customfishing.api.mechanic.totem.TotemConfig; import net.momirealms.customfishing.api.mechanic.totem.TotemConfig;
import net.momirealms.customfishing.api.mechanic.totem.TotemManager; import net.momirealms.customfishing.api.mechanic.totem.TotemManager;
import net.momirealms.customfishing.api.mechanic.totem.block.TotemBlock; 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.api.util.SimpleLocation;
import net.momirealms.customfishing.bukkit.util.LocationUtils; import net.momirealms.customfishing.bukkit.util.LocationUtils;
import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask;
@@ -91,6 +93,7 @@ public class BukkitTotemManager implements TotemManager, Listener {
if (this.timerCheckTask != null) if (this.timerCheckTask != null)
this.timerCheckTask.cancel(); this.timerCheckTask.cancel();
this.block2Totem.clear(); this.block2Totem.clear();
this.id2Totem.clear();
} }
@Override @Override
@@ -162,9 +165,17 @@ public class BukkitTotemManager implements TotemManager, Listener {
if (config == null) if (config == null)
return; return;
Location location = block.getLocation();
SimpleLocation simpleLocation = SimpleLocation.of(location);
ActivatedTotem previous = this.activatedTotems.get(simpleLocation);
if (previous != null) {
return;
}
String totemID = config.id(); String totemID = config.id();
final Player player = event.getPlayer();; final Player player = event.getPlayer();;
Context<Player> context = Context.player(player); Context<Player> context = Context.player(player);
context.arg(ContextKeys.SLOT, event.getHand());
Optional<EffectModifier> optionalEffectModifier = plugin.getEffectManager().getEffectModifier(totemID, MechanicType.TOTEM); Optional<EffectModifier> optionalEffectModifier = plugin.getEffectManager().getEffectModifier(totemID, MechanicType.TOTEM);
if (optionalEffectModifier.isPresent()) { if (optionalEffectModifier.isPresent()) {
if (!RequirementManager.isSatisfied(context, optionalEffectModifier.get().requirements())) { 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); if (EventUtils.fireAndCheckCancel(new TotemActivateEvent(player, block.getLocation(), config))) {
Bukkit.getPluginManager().callEvent(totemActivateEvent);
if (totemActivateEvent.isCancelled()) {
return; return;
} }
plugin.getEventManager().trigger(context, totemID, MechanicType.TOTEM, ActionTrigger.ACTIVATE); plugin.getEventManager().trigger(context, totemID, MechanicType.TOTEM, ActionTrigger.ACTIVATE);
Location location = block.getLocation();
ActivatedTotem activatedTotem = new ActivatedTotem(player, location, config); ActivatedTotem activatedTotem = new ActivatedTotem(player, location, config);
SimpleLocation simpleLocation = SimpleLocation.of(location); this.activatedTotems.put(simpleLocation, activatedTotem);
ActivatedTotem previous = this.activatedTotems.put(simpleLocation, activatedTotem);
if (previous != null) {
previous.cancel();
}
} }
@Override @Override

View File

@@ -131,6 +131,7 @@ mechanics:
duration: 35 duration: 35
position: other position: other
item: lava_effect item: lava_effect
use-item-display: true
priority_2: priority_2:
conditions: conditions:
in-water: true in-water: true
@@ -141,6 +142,7 @@ mechanics:
duration: 35 duration: 35
position: other position: other
item: water_effect item: water_effect
use-item-display: true
# Global properties which would help you reduce duplicated lines # Global properties which would help you reduce duplicated lines
global-loot-property: global-loot-property:
show-in-fishfinder: true show-in-fishfinder: true

View File

@@ -26,7 +26,6 @@ double_loot_totem:
requirement_1: requirement_1:
type: item-in-hand type: item-in-hand
value: value:
hand: main
item: NAUTILUS_SHELL item: NAUTILUS_SHELL
amount: 1 amount: 1
not-met-actions: not-met-actions:
@@ -48,6 +47,8 @@ double_loot_totem:
text: '<#BA55D3>[Double Loot Totem]</#BA55D3>' text: '<#BA55D3>[Double Loot Totem]</#BA55D3>'
position: other position: other
range: 16 range: 16
use-text-display: true
rgba: 147,112,219,50
y: 3.3 y: 3.3
x: 0 x: 0
z: 0 z: 0
@@ -58,6 +59,7 @@ double_loot_totem:
text: 'Time Left: {time_left} seconds' text: 'Time Left: {time_left} seconds'
position: other position: other
range: 16 range: 16
use-text-display: true
y: 2.8 y: 2.8
x: 0 x: 0
z: 0 z: 0
@@ -65,7 +67,6 @@ double_loot_totem:
remove_item_action: remove_item_action:
type: item-amount type: item-amount
value: value:
hand: main
amount: -1 amount: -1
broadcast_action: broadcast_action:
type: message-nearby type: message-nearby
@@ -256,7 +257,6 @@ golden_star_totem:
requirement_1: requirement_1:
type: item-in-hand type: item-in-hand
value: value:
hand: main
item: GOLD_INGOT item: GOLD_INGOT
amount: 1 amount: 1
not-met-actions: not-met-actions:
@@ -278,6 +278,8 @@ golden_star_totem:
text: '<#FFFF00>[Golden Star Totem]</#FFFF00>' text: '<#FFFF00>[Golden Star Totem]</#FFFF00>'
position: other position: other
range: 16 range: 16
use-text-display: true
rgba: 255,215,0,50
y: 1 y: 1
x: 0 x: 0
z: 0 z: 0
@@ -287,6 +289,7 @@ golden_star_totem:
duration: 20 duration: 20
text: 'Time Left: {time_left} seconds' text: 'Time Left: {time_left} seconds'
position: other position: other
use-text-display: true
range: 16 range: 16
y: 0.5 y: 0.5
x: 0 x: 0
@@ -295,7 +298,6 @@ golden_star_totem:
remove_item_action: remove_item_action:
type: item-amount type: item-amount
value: value:
hand: main
amount: -1 amount: -1
broadcast_action: broadcast_action:
type: message-nearby type: message-nearby

View File

@@ -1,6 +1,6 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=2.2.20 project_version=2.2.21
config_version=36 config_version=36
project_group=net.momirealms project_group=net.momirealms
@@ -17,7 +17,7 @@ h2_driver_version=2.2.224
sqlite_driver_version=3.46.0.1 sqlite_driver_version=3.46.0.1
adventure_bundle_version=4.17.0 adventure_bundle_version=4.17.0
adventure_platform_version=4.3.3 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_core_version=2.0.0-rc.2
cloud_services_version=2.0.0-rc.2 cloud_services_version=2.0.0-rc.2
cloud_brigadier_version=2.0.0-beta.9 cloud_brigadier_version=2.0.0-beta.9