mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 17:09:21 +00:00
Added expression support for chance
This commit is contained in:
@@ -20,6 +20,7 @@ package net.momirealms.customcrops.api.action;
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.builtin.*;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.common.util.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -96,7 +97,7 @@ public abstract class AbstractActionManager<T> implements ActionManager<T> {
|
||||
plugin.getPluginLogger().warn("Action type: " + section.getString("type") + " doesn't exist.");
|
||||
return Action.empty();
|
||||
}
|
||||
return factory.process(section.get("value"), section.getDouble("chance", 1d));
|
||||
return factory.process(section.get("value"), section.contains("chance") ? MathValue.auto(section.get("chance")) : MathValue.plain(1d));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -122,7 +123,7 @@ public abstract class AbstractActionManager<T> implements ActionManager<T> {
|
||||
plugin.getPluginLogger().warn("Action type: " + type + " doesn't exist.");
|
||||
return Action.empty();
|
||||
}
|
||||
return factory.process(args, 1);
|
||||
return factory.process(args, MathValue.plain(1));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"ResultOfMethodCallIgnored", "unchecked"})
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package net.momirealms.customcrops.api.action;
|
||||
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
|
||||
/**
|
||||
* Interface representing a factory for creating actions.
|
||||
*
|
||||
@@ -30,5 +32,5 @@ public interface ActionFactory<T> {
|
||||
* @param args the args containing the arguments needed to build the action
|
||||
* @return the constructed action
|
||||
*/
|
||||
Action<T> process(Object args, double chance);
|
||||
Action<T> process(Object args, MathValue<T> chance);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,15 @@ package net.momirealms.customcrops.api.action.builtin;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractBuiltInAction<T> implements Action<T> {
|
||||
|
||||
protected final BukkitCustomCropsPlugin plugin;
|
||||
protected final double chance;
|
||||
protected final MathValue<T> chance;
|
||||
|
||||
protected AbstractBuiltInAction(BukkitCustomCropsPlugin plugin, double chance) {
|
||||
protected AbstractBuiltInAction(BukkitCustomCropsPlugin plugin, MathValue<T> chance) {
|
||||
this.plugin = plugin;
|
||||
this.chance = chance;
|
||||
}
|
||||
@@ -35,13 +37,13 @@ public abstract class AbstractBuiltInAction<T> implements Action<T> {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public double chance() {
|
||||
public MathValue<T> chance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Context<T> context) {
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
triggerAction(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionActionbarNearby(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actionbar = section.getString("actionbar");
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
||||
import net.momirealms.customcrops.api.core.world.Pos3;
|
||||
import net.momirealms.customcrops.api.core.wrapper.WrappedBreakEvent;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.util.DummyCancellable;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -46,7 +47,7 @@ public class ActionBreak<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionBreak(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.triggerEvent = Optional.ofNullable(args).map(it -> (boolean) it).orElse(true);
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.common.helper.AdventureHelper;
|
||||
import net.momirealms.customcrops.common.util.ListUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -36,7 +37,7 @@ public class ActionBroadcast<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionBroadcast(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.messages = ListUtils.toList(args);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.AbstractActionManager;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -35,7 +36,7 @@ public class ActionChain<T> extends AbstractBuiltInAction<T> {
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
AbstractActionManager<T> manager,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actions = new ArrayList<>();
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.common.util.ListUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -35,7 +36,7 @@ public class ActionCommand<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionCommand(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.commands = ListUtils.toList(args);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ActionCommandNearby<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionCommandNearby(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.cmd = ListUtils.toList(section.get("command"));
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.AbstractActionManager;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.requirement.Requirement;
|
||||
|
||||
public class ActionConditional<T> extends AbstractBuiltInAction<T> {
|
||||
@@ -34,7 +35,7 @@ public class ActionConditional<T> extends AbstractBuiltInAction<T> {
|
||||
AbstractActionManager<T> manager,
|
||||
Class<T> tClass,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actions = manager.parseActions(section.getSection("actions"));
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.momirealms.customcrops.api.action.AbstractActionManager;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -40,7 +41,7 @@ public class ActionDelay<T> extends AbstractBuiltInAction<T> {
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
AbstractActionManager<T> manager,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actions = new ArrayList<>();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ActionDropItem<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionDropItem(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.ignoreFertilizer = section.getBoolean("ignore-fertilizer", true);
|
||||
@@ -75,6 +75,7 @@ public class ActionDropItem<T> extends AbstractBuiltInAction<T> {
|
||||
player = null;
|
||||
}
|
||||
int random = RandomUtils.generateRandomInt((int) min.evaluate(context), (int) max.evaluate(context));
|
||||
if (random <= 0) return;
|
||||
ItemStack itemStack = generateItem(location, player, random);
|
||||
plugin.getScheduler().sync().run(() -> {
|
||||
DropItemActionEvent actionEvent = new DropItemActionEvent(context, location, item, itemStack);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.action.ActionManager;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -37,7 +38,7 @@ public class ActionDropItemLegacy<T> extends AbstractBuiltInAction<T> {
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
ActionManager<T> manager,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actions = new ArrayList<>();
|
||||
@@ -45,13 +46,13 @@ public class ActionDropItemLegacy<T> extends AbstractBuiltInAction<T> {
|
||||
if (otherItemSection != null) {
|
||||
for (Map.Entry<String, Object> entry : otherItemSection.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section inner) {
|
||||
actions.add(requireNonNull(manager.getActionFactory("drop-item")).process(inner, inner.getDouble("chance", 1D)));
|
||||
actions.add(requireNonNull(manager.getActionFactory("drop-item")).process(inner, section.contains("chance") ? MathValue.auto(section.get("chance")) : MathValue.plain(1d)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Section qualitySection = section.getSection("quality-crops");
|
||||
if (qualitySection != null) {
|
||||
actions.add(requireNonNull(manager.getActionFactory("quality-crops")).process(qualitySection, 1));
|
||||
actions.add(requireNonNull(manager.getActionFactory("quality-crops")).process(qualitySection, MathValue.plain(1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ActionFakeItem<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionFakeItem(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
String itemID = section.getString("item", "");
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ActionHologram<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionHologram(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.text = TextValue.auto(section.getString("text", ""));
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ActionMessageNearby<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionMessageNearby(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.messages = ListUtils.toList(section.get("message"));
|
||||
|
||||
@@ -21,6 +21,7 @@ import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.util.ParticleUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
@@ -51,7 +52,7 @@ public class ActionParticle<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionParticle(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.particleType = ParticleUtils.getParticle(section.getString("particle", "ASH").toUpperCase(Locale.ENGLISH));
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
||||
import net.momirealms.customcrops.api.core.world.Pos3;
|
||||
import net.momirealms.customcrops.api.event.CropPlantEvent;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.util.EventUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -54,7 +55,7 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionPlant(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.point = section.getInt("point", 0);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.action.AbstractActionManager;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.requirement.Requirement;
|
||||
import net.momirealms.customcrops.common.util.Pair;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class ActionPriority<T> extends AbstractBuiltInAction<T> {
|
||||
AbstractActionManager<T> manager,
|
||||
Class<T> tClass,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.conditionActionPairList = new ArrayList<>();
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionQualityCrops(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.min = MathValue.auto(section.get("min"));
|
||||
@@ -76,6 +76,7 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
|
||||
protected void triggerAction(Context<T> context) {
|
||||
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
|
||||
int random = RandomUtils.generateRandomInt((int) min.evaluate(context), (int) max.evaluate(context));
|
||||
if (random <= 0) return;
|
||||
Player player;
|
||||
if (context.holder() instanceof Player p) {
|
||||
player = p;
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.placeholder.BukkitPlaceholderManager;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.common.util.ListUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -36,7 +37,7 @@ public class ActionRandomCommand<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionRandomCommand(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.commands = ListUtils.toList(args);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.integration.EntityProvider;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -37,7 +38,7 @@ public class ActionSpawnEntity<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionSpawnEntity(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.id = section.getString("id");
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.momirealms.customcrops.api.action.AbstractActionManager;
|
||||
import net.momirealms.customcrops.api.action.Action;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.common.plugin.scheduler.SchedulerTask;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class ActionTimer<T> extends AbstractBuiltInAction<T> {
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
AbstractActionManager<T> manager,
|
||||
Object args,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.actions = new ArrayList<>();
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.context.Context;
|
||||
import net.momirealms.customcrops.api.context.ContextKeys;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import net.momirealms.customcrops.api.misc.value.TextValue;
|
||||
import net.momirealms.customcrops.api.util.LocationUtils;
|
||||
import net.momirealms.customcrops.common.helper.AdventureHelper;
|
||||
@@ -42,7 +43,7 @@ public class ActionTitleNearby<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionTitleNearby(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
this.title = TextValue.auto(section.getString("title"));
|
||||
|
||||
@@ -33,6 +33,7 @@ import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerConfig;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
||||
import net.momirealms.customcrops.api.core.world.Pos3;
|
||||
import net.momirealms.customcrops.api.misc.value.MathValue;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.*;
|
||||
@@ -47,7 +48,7 @@ public class ActionVariation<T> extends AbstractBuiltInAction<T> {
|
||||
public ActionVariation(
|
||||
BukkitCustomCropsPlugin plugin,
|
||||
Section section,
|
||||
double chance
|
||||
MathValue<T> chance
|
||||
) {
|
||||
super(plugin, chance);
|
||||
ignore = section.getBoolean("ignore-fertilizer", false);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.6.20.1
|
||||
project_version=3.6.21
|
||||
config_version=42
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
List<String> messages = ListUtils.toList(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
List<String> replaced = plugin.getPlaceholderManager().parse(context.holder(), messages, context.placeholderMap());
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.holder());
|
||||
for (String text : replaced) {
|
||||
@@ -105,7 +105,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
List<String> messages = ListUtils.toList(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
String random = messages.get(RandomUtils.generateRandomInt(0, messages.size() - 1));
|
||||
random = BukkitPlaceholderManager.getInstance().parse(context.holder(), random, context.placeholderMap());
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.holder());
|
||||
@@ -119,7 +119,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
List<String> commands = ListUtils.toList(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
List<String> replaced = BukkitPlaceholderManager.getInstance().parse(context.holder(), commands, context.placeholderMap());
|
||||
plugin.getScheduler().sync().run(() -> {
|
||||
for (String text : replaced) {
|
||||
@@ -133,7 +133,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
private void registerCloseInvAction() {
|
||||
registerAction((args, chance) -> context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
context.holder().closeInventory();
|
||||
}, "close-inv");
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
String text = (String) args;
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.holder());
|
||||
Component component = AdventureHelper.miniMessage(plugin.getPlaceholderManager().parse(context.holder(), text, context.placeholderMap()));
|
||||
audience.sendActionBar(component);
|
||||
@@ -153,7 +153,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
List<String> texts = ListUtils.toList(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
String random = texts.get(RandomUtils.generateRandomInt(0, texts.size() - 1));
|
||||
random = plugin.getPlaceholderManager().parse(context.holder(), random, context.placeholderMap());
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.holder());
|
||||
@@ -167,7 +167,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
final Player player = context.holder();
|
||||
ExperienceOrb entity = player.getLocation().getWorld().spawn(player.getLocation().clone().add(0,0.5,0), ExperienceOrb.class);
|
||||
entity.setExperience((int) value.evaluate(context));
|
||||
@@ -177,7 +177,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
final Player player = context.holder();
|
||||
player.giveExp((int) Math.round(value.evaluate(context)));
|
||||
Audience audience = plugin.getSenderFactory().getAudience(player);
|
||||
@@ -188,7 +188,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
player.setLevel((int) Math.max(0, player.getLevel() + value.evaluate(context)));
|
||||
};
|
||||
@@ -200,7 +200,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
player.setFoodLevel((int) (player.getFoodLevel() + value.evaluate(context)));
|
||||
};
|
||||
@@ -209,7 +209,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
player.setSaturation((float) (player.getSaturation() + value.evaluate(context)));
|
||||
};
|
||||
@@ -233,7 +233,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
}
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
EquipmentSlot hand = context.arg(ContextKeys.SLOT);
|
||||
if (mainOrOff == null && hand == null) {
|
||||
@@ -264,7 +264,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
return Action.empty();
|
||||
}
|
||||
return context -> {
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
if (player == null) return;
|
||||
EquipmentSlot tempSlot = slot;
|
||||
@@ -297,7 +297,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
int amount = section.getInt("amount", 1);
|
||||
boolean toInventory = section.getBoolean("to-inventory", false);
|
||||
return context -> {
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Player player = context.holder();
|
||||
if (player == null) return;
|
||||
ItemStack itemStack = plugin.getItemManager().build(context.holder(), finalID);
|
||||
@@ -329,7 +329,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
if (!VaultHook.isHooked()) return;
|
||||
VaultHook.deposit(context.holder(), value.evaluate(context));
|
||||
};
|
||||
@@ -338,7 +338,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
MathValue<Player> value = MathValue.auto(args);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
if (!VaultHook.isHooked()) return;
|
||||
VaultHook.withdraw(context.holder(), value.evaluate(context));
|
||||
};
|
||||
@@ -355,7 +355,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
context.holder().addPotionEffect(potionEffect);
|
||||
};
|
||||
} else {
|
||||
@@ -376,7 +376,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Audience audience = plugin.getSenderFactory().getAudience(context.holder());
|
||||
AdventureHelper.playSound(audience, sound);
|
||||
};
|
||||
@@ -395,7 +395,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
String target = section.getString("target");
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Optional.ofNullable(plugin.getIntegrationManager().getLevelerProvider(pluginName)).ifPresentOrElse(it -> {
|
||||
it.addXp(context.holder(), target, value.evaluate(context));
|
||||
}, () -> plugin.getPluginLogger().warn("Plugin (" + pluginName + "'s) level is not compatible. Please double check if it's a problem caused by pronunciation."));
|
||||
@@ -416,7 +416,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
int stay = section.getInt("stay", 30);
|
||||
int fadeOut = section.getInt("fade-out", 10);
|
||||
return context -> {
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
final Player player = context.holder();
|
||||
if (player == null) return;
|
||||
Audience audience = plugin.getSenderFactory().getAudience(player);
|
||||
@@ -442,7 +442,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
int fadeOut = section.getInt("fade-out", 10);
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
TextValue<Player> title = TextValue.auto(titles.get(RandomUtils.generateRandomInt(0, titles.size() - 1)));
|
||||
TextValue<Player> subtitle = TextValue.auto(subtitles.get(RandomUtils.generateRandomInt(0, subtitles.size() - 1)));
|
||||
final Player player = context.holder();
|
||||
@@ -465,7 +465,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
boolean arg = (boolean) args;
|
||||
return context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
EquipmentSlot slot = context.arg(ContextKeys.SLOT);
|
||||
if (slot == null) {
|
||||
SparrowHeart.getInstance().swingHand(context.holder(), arg ? HandSlot.MAIN : HandSlot.OFF);
|
||||
@@ -480,7 +480,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
private void registerForceTickAction() {
|
||||
registerAction((args, chance) -> context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
|
||||
Pos3 pos3 = Pos3.from(location);
|
||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(location.getWorld());
|
||||
@@ -500,7 +500,7 @@ public class PlayerActionManager extends AbstractActionManager<Player> {
|
||||
}, "force-tick");
|
||||
registerAction((args, chance) -> context -> {
|
||||
if (context.holder() == null) return;
|
||||
if (Math.random() > chance) return;
|
||||
if (Math.random() > chance.evaluate(context)) return;
|
||||
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
|
||||
Pos3 pos3 = Pos3.from(location);
|
||||
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(location.getWorld());
|
||||
|
||||
Reference in New Issue
Block a user