9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-19 15:09:25 +00:00

Reformat actions

This commit is contained in:
XiaoMoMi
2024-09-05 16:53:54 +08:00
parent 4381d8d207
commit 37cef6b3f8
22 changed files with 249 additions and 199 deletions

View File

@@ -191,7 +191,7 @@ public abstract class AbstractActionManager<T> implements ActionManager<T> {
}
protected void registerBundleAction(Class<T> tClass) {
registerAction((args, chance) -> new ActionBundle<>(plugin, this, args, chance), "chain");
registerAction((args, chance) -> new ActionChain<>(plugin, this, args, chance), "chain");
registerAction((args, chance) -> new ActionDelay<>(plugin, this, args, chance), "delay");
registerAction((args, chance) -> new ActionTimer<>(plugin, this, args, chance), "timer");
registerAction((args, chance) -> {

View File

@@ -19,24 +19,31 @@ 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;
public abstract class AbstractBuiltInAction<T> implements Action<T> {
protected final BukkitCustomCropsPlugin plugin;
protected final double chance;
protected AbstractBuiltInAction(BukkitCustomCropsPlugin plugin, double chance) {
this.plugin = plugin;
this.chance = chance;
}
public BukkitCustomCropsPlugin getPlugin() {
public BukkitCustomCropsPlugin plugin() {
return plugin;
}
public double getChance() {
public double chance() {
return chance;
}
public boolean checkChance() {
return !(Math.random() > chance);
@Override
public void trigger(Context<T> context) {
if (Math.random() > chance) return;
triggerAction(context);
}
protected abstract void triggerAction(Context<T> context);
}

View File

@@ -32,8 +32,10 @@ import org.bukkit.entity.Player;
import static java.util.Objects.requireNonNull;
public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
final String actionbar;
final MathValue<T> range;
private final String actionbar;
private final MathValue<T> range;
public ActionActionbarNearby(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -43,10 +45,10 @@ public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
this.actionbar = section.getString("actionbar");
this.range = MathValue.auto(section.get("range"));
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer owner = null;
if (context.holder() instanceof Player player) {
owner = player;
@@ -63,11 +65,11 @@ public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
}
}
public String getActionbar() {
public String actionbar() {
return actionbar;
}
public MathValue<T> getRange() {
public MathValue<T> range() {
return range;
}
}

View File

@@ -40,7 +40,9 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ActionBreak<T> extends AbstractBuiltInAction<T> {
final boolean triggerEvent;
private final boolean triggerEvent;
public ActionBreak(
BukkitCustomCropsPlugin plugin,
Object args,
@@ -49,8 +51,9 @@ public class ActionBreak<T> extends AbstractBuiltInAction<T> {
super(plugin, chance);
this.triggerEvent = (boolean) args;
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
Optional<CustomCropsWorld<?>> optionalWorld = plugin.getWorldManager().getWorld(location.getWorld());
if (optionalWorld.isEmpty()) {
@@ -92,7 +95,7 @@ public class ActionBreak<T> extends AbstractBuiltInAction<T> {
plugin.getItemManager().remove(location, ExistenceForm.ANY);
}
public boolean isTriggerEvent() {
public boolean shouldBreakTriggerEvent() {
return triggerEvent;
}
}

View File

@@ -30,7 +30,9 @@ import org.bukkit.entity.Player;
import java.util.List;
public class ActionBroadcast<T> extends AbstractBuiltInAction<T> {
final List<String> messages;
private final List<String> messages;
public ActionBroadcast(
BukkitCustomCropsPlugin plugin,
Object args,
@@ -39,10 +41,10 @@ public class ActionBroadcast<T> extends AbstractBuiltInAction<T> {
super(plugin, chance);
this.messages = ListUtils.toList(args);
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer offlinePlayer = null;
if (context.holder() instanceof Player player) {
offlinePlayer = player;
@@ -56,7 +58,7 @@ public class ActionBroadcast<T> extends AbstractBuiltInAction<T> {
}
}
public List<String> getMessages() {
public List<String> messages() {
return messages;
}
}

View File

@@ -27,9 +27,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ActionBundle<T> extends AbstractBuiltInAction<T> {
final List<Action<T>> actions;
public ActionBundle(
public class ActionChain<T> extends AbstractBuiltInAction<T> {
private final List<Action<T>> actions;
public ActionChain(
BukkitCustomCropsPlugin plugin,
AbstractActionManager<T> manager,
Object args,
@@ -45,15 +47,15 @@ public class ActionBundle<T> extends AbstractBuiltInAction<T> {
}
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
for (Action<T> action : actions) {
action.trigger(context);
}
}
public List<Action<T>> getActions() {
public List<Action<T>> actions() {
return actions;
}
}

View File

@@ -29,7 +29,9 @@ import org.bukkit.entity.Player;
import java.util.List;
public class ActionCommand<T> extends AbstractBuiltInAction<T> {
final List<String> commands;
private final List<String> commands;
public ActionCommand(
BukkitCustomCropsPlugin plugin,
Object args,
@@ -38,10 +40,10 @@ public class ActionCommand<T> extends AbstractBuiltInAction<T> {
super(plugin, chance);
this.commands = ListUtils.toList(args);
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer owner = null;
if (context.holder() instanceof Player player) {
owner = player;
@@ -54,7 +56,7 @@ public class ActionCommand<T> extends AbstractBuiltInAction<T> {
}, null);
}
public List<String> getCommands() {
public List<String> commands() {
return commands;
}
}

View File

@@ -35,8 +35,10 @@ import java.util.List;
import static java.util.Objects.requireNonNull;
public class ActionCommandNearby<T> extends AbstractBuiltInAction<T> {
final List<String> cmd;
final MathValue<T> range;
private final List<String> cmd;
private final MathValue<T> range;
public ActionCommandNearby(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -46,10 +48,10 @@ public class ActionCommandNearby<T> extends AbstractBuiltInAction<T> {
this.cmd = ListUtils.toList(section.get("command"));
this.range = MathValue.auto(section.get("range"));
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer owner = null;
if (context.holder() instanceof Player player) {
owner = player;
@@ -67,11 +69,11 @@ public class ActionCommandNearby<T> extends AbstractBuiltInAction<T> {
}
}
public List<String> getCmd() {
public List<String> commands() {
return cmd;
}
public MathValue<T> getRange() {
public MathValue<T> range() {
return range;
}
}

View File

@@ -25,8 +25,10 @@ import net.momirealms.customcrops.api.context.Context;
import net.momirealms.customcrops.api.requirement.Requirement;
public class ActionConditional<T> extends AbstractBuiltInAction<T> {
final Action<T>[] actions;
final Requirement<T>[] requirements;
private final Action<T>[] actions;
private final Requirement<T>[] requirements;
public ActionConditional(
BukkitCustomCropsPlugin plugin,
AbstractActionManager<T> manager,
@@ -38,24 +40,24 @@ public class ActionConditional<T> extends AbstractBuiltInAction<T> {
this.actions = manager.parseActions(section.getSection("actions"));
this.requirements = plugin.getRequirementManager(tClass).parseRequirements(section.getSection("conditions"), true);
}
@Override
public void trigger(Context<T> condition) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
for (Requirement<T> requirement : requirements) {
if (!requirement.isSatisfied(condition)) {
if (!requirement.isSatisfied(context)) {
return;
}
}
for (Action<T> action : actions) {
action.trigger(condition);
action.trigger(context);
}
}
public Action<T>[] getActions() {
public Action<T>[] actions() {
return actions;
}
public Requirement<T>[] getRequirements() {
public Requirement<T>[] requirements() {
return requirements;
}
}

View File

@@ -31,9 +31,11 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
public class ActionDelay<T> extends AbstractBuiltInAction<T> {
final List<Action<T>> actions;
final int delay;
final boolean async;
private final List<Action<T>> actions;
private final int delay;
private final boolean async;
public ActionDelay(
BukkitCustomCropsPlugin plugin,
AbstractActionManager<T> manager,
@@ -55,9 +57,9 @@ public class ActionDelay<T> extends AbstractBuiltInAction<T> {
async = false;
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
Location location = context.arg(ContextKeys.LOCATION);
if (async) {
plugin.getScheduler().asyncLater(() -> {
@@ -72,15 +74,15 @@ public class ActionDelay<T> extends AbstractBuiltInAction<T> {
}
}
public List<Action<T>> getActions() {
public List<Action<T>> actions() {
return actions;
}
public int getDelay() {
public int delay() {
return delay;
}
public boolean isAsync() {
public boolean async() {
return async;
}
}

View File

@@ -42,11 +42,13 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ActionDropItem<T> extends AbstractBuiltInAction<T> {
final boolean ignoreFertilizer;
final String item;
final MathValue<T> min;
final MathValue<T> max;
final boolean toInv;
private final boolean ignoreFertilizer;
private final String item;
private final MathValue<T> min;
private final MathValue<T> max;
private final boolean toInv;
public ActionDropItem(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -58,11 +60,10 @@ public class ActionDropItem<T> extends AbstractBuiltInAction<T> {
this.min = MathValue.auto(section.get("min"));
this.max = MathValue.auto(section.get("max"));
this.toInv = section.getBoolean("to-inventory", false);
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
Player player = null;
if (context.holder() instanceof Player p) {
@@ -117,23 +118,23 @@ public class ActionDropItem<T> extends AbstractBuiltInAction<T> {
return itemStack;
}
public boolean isIgnoreFertilizer() {
public boolean ignoreFertilizer() {
return ignoreFertilizer;
}
public String getItem() {
public String itemID() {
return item;
}
public MathValue<T> getMin() {
public MathValue<T> min() {
return min;
}
public MathValue<T> getMax() {
public MathValue<T> max() {
return max;
}
public boolean isToInv() {
public boolean toInventory() {
return toInv;
}
}

View File

@@ -30,7 +30,9 @@ import java.util.Map;
import static java.util.Objects.requireNonNull;
public class ActionDropItemLegacy<T> extends AbstractBuiltInAction<T> {
final List<Action<T>> actions;
private final List<Action<T>> actions;
public ActionDropItemLegacy(
BukkitCustomCropsPlugin plugin,
ActionManager<T> manager,
@@ -52,9 +54,9 @@ public class ActionDropItemLegacy<T> extends AbstractBuiltInAction<T> {
actions.add(requireNonNull(manager.getActionFactory("quality-crops")).process(qualitySection, 1));
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
for (Action<T> action : actions) {
action.trigger(context);
}

View File

@@ -38,16 +38,18 @@ import java.util.concurrent.TimeUnit;
import static java.util.Objects.requireNonNull;
public class ActionFakeItem<T> extends AbstractBuiltInAction<T> {
final String itemID;
final MathValue<T> duration;
final boolean other;
final MathValue<T> x;
final MathValue<T> y;
final MathValue<T> z;
final MathValue<T> yaw;
final int range;
final boolean visibleToAll;
final boolean useItemDisplay;
private final String itemID;
private final MathValue<T> duration;
private final boolean other;
private final MathValue<T> x;
private final MathValue<T> y;
private final MathValue<T> z;
private final MathValue<T> yaw;
private final int range;
private final boolean visibleToAll;
private final boolean useItemDisplay;
public ActionFakeItem(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -68,9 +70,9 @@ public class ActionFakeItem<T> extends AbstractBuiltInAction<T> {
this.visibleToAll = section.getBoolean("visible-to-all", true);
this.useItemDisplay = section.getBoolean("use-item-display", false);
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
Player owner = null;
if (context.holder() instanceof Player p) {
@@ -117,43 +119,43 @@ public class ActionFakeItem<T> extends AbstractBuiltInAction<T> {
}, (long) (duration.evaluate(context) * 50), TimeUnit.MILLISECONDS);
}
public String getItemID() {
public String itemID() {
return itemID;
}
public MathValue<T> getDuration() {
public MathValue<T> duration() {
return duration;
}
public boolean isOther() {
public boolean otherPosition() {
return other;
}
public MathValue<T> getX() {
public MathValue<T> x() {
return x;
}
public MathValue<T> getY() {
public MathValue<T> y() {
return y;
}
public MathValue<T> getZ() {
public MathValue<T> z() {
return z;
}
public MathValue<T> getYaw() {
public MathValue<T> yaw() {
return yaw;
}
public int getRange() {
public int range() {
return range;
}
public boolean isVisibleToAll() {
public boolean visibleToAll() {
return visibleToAll;
}
public boolean isUseItemDisplay() {
public boolean useItemDisplay() {
return useItemDisplay;
}
}

View File

@@ -1,7 +1,6 @@
package net.momirealms.customcrops.api.action.builtin;
import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.kyori.adventure.text.Component;
import net.momirealms.customcrops.api.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.context.Context;
import net.momirealms.customcrops.api.context.ContextKeys;
@@ -38,15 +37,17 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ActionHologram<T> extends AbstractBuiltInAction<T> {
final TextValue<T> text;
final MathValue<T> duration;
final boolean other;
final MathValue<T> x;
final MathValue<T> y;
final MathValue<T> z;
final boolean applyCorrection;
final boolean onlyShowToOne;
final int range;
private final TextValue<T> text;
private final MathValue<T> duration;
private final boolean other;
private final MathValue<T> x;
private final MathValue<T> y;
private final MathValue<T> z;
private final boolean applyCorrection;
private final boolean onlyShowToOne;
private final int range;
public ActionHologram(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -63,11 +64,10 @@ public class ActionHologram<T> extends AbstractBuiltInAction<T> {
this.onlyShowToOne = !section.getBoolean("visible-to-all", false);
this.range = section.getInt("range", 32);
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (context.holder() == null) return;
if (Math.random() > chance) return;
Player owner = null;
if (context.holder() instanceof Player p) {
owner = p;
@@ -95,45 +95,46 @@ public class ActionHologram<T> extends AbstractBuiltInAction<T> {
}
}
if (viewers.isEmpty()) return;
Component component = AdventureHelper.miniMessage(text.render(context));
String json = AdventureHelper.componentToJson(AdventureHelper.miniMessage(text.render(context)));
int durationInMillis = (int) (duration.evaluate(context) * 50);
for (Player viewer : viewers) {
HologramManager.getInstance().showHologram(viewer, location, AdventureHelper.componentToJson(component), (int) (duration.evaluate(context) * 50));
HologramManager.getInstance().showHologram(viewer, location, json, durationInMillis);
}
}
public TextValue<T> getText() {
public TextValue<T> text() {
return text;
}
public MathValue<T> getDuration() {
public MathValue<T> duration() {
return duration;
}
public boolean isOther() {
public boolean otherPosition() {
return other;
}
public MathValue<T> getX() {
public MathValue<T> x() {
return x;
}
public MathValue<T> getY() {
public MathValue<T> y() {
return y;
}
public MathValue<T> getZ() {
public MathValue<T> z() {
return z;
}
public boolean isApplyCorrection() {
public boolean applyHeightCorrection() {
return applyCorrection;
}
public boolean isOnlyShowToOne() {
public boolean showToOne() {
return onlyShowToOne;
}
public int getRange() {
public int range() {
return range;
}
}

View File

@@ -36,8 +36,10 @@ import java.util.List;
import static java.util.Objects.requireNonNull;
public class ActionMessageNearby<T> extends AbstractBuiltInAction<T> {
final List<String> messages;
final MathValue<T> range;
private final List<String> messages;
private final MathValue<T> range;
public ActionMessageNearby(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -47,10 +49,10 @@ public class ActionMessageNearby<T> extends AbstractBuiltInAction<T> {
this.messages = ListUtils.toList(section.get("message"));
this.range = MathValue.auto(section.get("range"));
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
double realRange = range.evaluate(context);
OfflinePlayer owner = null;
if (context.holder() instanceof Player player) {
@@ -73,11 +75,11 @@ public class ActionMessageNearby<T> extends AbstractBuiltInAction<T> {
}
}
public List<String> getMessages() {
public List<String> messages() {
return messages;
}
public MathValue<T> getRange() {
public MathValue<T> range() {
return range;
}
}

View File

@@ -26,25 +26,28 @@ import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
import static java.util.Objects.requireNonNull;
public class ActionParticle<T> extends AbstractBuiltInAction<T> {
final Particle particleType;
final double x;
final double y;
final double z;
final double offSetX;
final double offSetY;
final double offSetZ;
final int count;
final double extra;
final float scale;
final ItemStack itemStack;
final Color color;
final Color toColor;
private final Particle particleType;
private final double x;
private final double y;
private final double z;
private final double offSetX;
private final double offSetY;
private final double offSetZ;
private final int count;
private final double extra;
private final float scale;
private final ItemStack itemStack;
private final Color color;
private final Color toColor;
public ActionParticle(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -83,10 +86,10 @@ public class ActionParticle<T> extends AbstractBuiltInAction<T> {
toColor = null;
}
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
location.getWorld().spawnParticle(
particleType,
@@ -98,55 +101,58 @@ public class ActionParticle<T> extends AbstractBuiltInAction<T> {
);
}
public Particle getParticleType() {
public Particle particleType() {
return particleType;
}
public double getX() {
public double x() {
return x;
}
public double getY() {
public double y() {
return y;
}
public double getZ() {
public double z() {
return z;
}
public double getOffSetX() {
public double offSetX() {
return offSetX;
}
public double getOffSetY() {
public double offSetY() {
return offSetY;
}
public double getOffSetZ() {
public double offSetZ() {
return offSetZ;
}
public int getCount() {
public int count() {
return count;
}
public double getExtra() {
public double extra() {
return extra;
}
public float getScale() {
public float scale() {
return scale;
}
public ItemStack getItemStack() {
@Nullable
public ItemStack itemStack() {
return itemStack;
}
public Color getColor() {
@Nullable
public Color color() {
return color;
}
public Color getToColor() {
@Nullable
public Color toColor() {
return toColor;
}
}

View File

@@ -45,10 +45,12 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ActionPlant<T> extends AbstractBuiltInAction<T> {
final int point;
final String key;
final int y;
final boolean triggerAction;
private final int point;
private final String key;
private final int y;
private final boolean triggerAction;
public ActionPlant(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -60,10 +62,10 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
this.y = section.getInt("y", 0);
this.triggerAction = section.getBoolean("trigger-event", false);
}
@Override
@SuppressWarnings("unchecked")
public void trigger(Context<T> context) {
if (!checkChance()) return;
@Override
protected void triggerAction(Context<T> context) {
CropConfig cropConfig = Registries.CROP.get(key);
if (cropConfig == null) {
plugin.getPluginLogger().warn("`plant` action is not executed due to crop[" + key + "] not exists");
@@ -111,19 +113,19 @@ public class ActionPlant<T> extends AbstractBuiltInAction<T> {
}, cropLocation);
}
public int getPoint() {
public int point() {
return point;
}
public String getKey() {
public String cropID() {
return key;
}
public int getY() {
public int yOffset() {
return y;
}
public boolean isTriggerAction() {
public boolean triggerPlantAction() {
return triggerAction;
}
}

View File

@@ -30,7 +30,9 @@ import java.util.List;
import java.util.Map;
public class ActionPriority<T> extends AbstractBuiltInAction<T> {
final List<Pair<Requirement<T>[], Action<T>[]>> conditionActionPairList;
private final List<Pair<Requirement<T>[], Action<T>[]>> conditionActionPairList;
public ActionPriority(
BukkitCustomCropsPlugin plugin,
AbstractActionManager<T> manager,
@@ -48,9 +50,9 @@ public class ActionPriority<T> extends AbstractBuiltInAction<T> {
}
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
outer:
for (Pair<Requirement<T>[], Action<T>[]> pair : conditionActionPairList) {
if (pair.left() != null)
@@ -67,7 +69,7 @@ public class ActionPriority<T> extends AbstractBuiltInAction<T> {
}
}
public List<Pair<Requirement<T>[], Action<T>[]>> getConditionActionPairList() {
public List<Pair<Requirement<T>[], Action<T>[]>> conditionalActions() {
return conditionActionPairList;
}
}

View File

@@ -44,10 +44,12 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
final MathValue<T> min;
final MathValue<T> max;
final boolean toInv;
final String[] qualityLoots;
private final MathValue<T> min;
private final MathValue<T> max;
private final boolean toInv;
private final String[] qualityLoots;
public ActionQualityCrops(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -66,9 +68,9 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
}
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
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));
Player player = null;
@@ -130,19 +132,19 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
return null;
}
public MathValue<T> getMin() {
public MathValue<T> min() {
return min;
}
public MathValue<T> getMax() {
public MathValue<T> max() {
return max;
}
public boolean isToInv() {
public boolean toInventory() {
return toInv;
}
public String[] getQualityLoots() {
public String[] qualityLoots() {
return qualityLoots;
}
}

View File

@@ -30,7 +30,9 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class ActionRandomCommand<T> extends AbstractBuiltInAction<T> {
final List<String> commands;
private final List<String> commands;
public ActionRandomCommand(
BukkitCustomCropsPlugin plugin,
Object args,
@@ -39,10 +41,10 @@ public class ActionRandomCommand<T> extends AbstractBuiltInAction<T> {
super(plugin, chance);
this.commands = ListUtils.toList(args);
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer owner = null;
if (context.holder() instanceof Player player) {
owner = player;
@@ -55,7 +57,7 @@ public class ActionRandomCommand<T> extends AbstractBuiltInAction<T> {
}, null);
}
public List<String> getCommands() {
public List<String> commands() {
return commands;
}
}

View File

@@ -32,9 +32,11 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
public class ActionTimer<T> extends AbstractBuiltInAction<T> {
final List<Action<T>> actions;
final int delay, duration, period;
final boolean async;
private final List<Action<T>> actions;
private final int delay, duration, period;
private final boolean async;
public ActionTimer(
BukkitCustomCropsPlugin plugin,
AbstractActionManager<T> manager,
@@ -60,9 +62,9 @@ public class ActionTimer<T> extends AbstractBuiltInAction<T> {
duration = 20;
}
}
@Override
public void trigger(Context<T> context) {
if (!checkChance()) return;
protected void triggerAction(Context<T> context) {
Location location = context.arg(ContextKeys.LOCATION);
SchedulerTask task;
if (async) {
@@ -81,23 +83,23 @@ public class ActionTimer<T> extends AbstractBuiltInAction<T> {
plugin.getScheduler().asyncLater(task::cancel, duration * 50L, TimeUnit.MILLISECONDS);
}
public List<Action<T>> getActions() {
public List<Action<T>> actions() {
return actions;
}
public int getDelay() {
public int delay() {
return delay;
}
public int getDuration() {
public int duration() {
return duration;
}
public int getPeriod() {
public int period() {
return period;
}
public boolean isAsync() {
public boolean async() {
return async;
}
}

View File

@@ -31,12 +31,14 @@ import org.bukkit.entity.Player;
import static java.util.Objects.requireNonNull;
public class ActionTitleNearby<T> extends AbstractBuiltInAction<T> {
final TextValue<T> title;
final TextValue<T> subtitle;
final int fadeIn;
final int stay;
final int fadeOut;
final int range;
private final TextValue<T> title;
private final TextValue<T> subtitle;
private final int fadeIn;
private final int stay;
private final int fadeOut;
private final int range;
public ActionTitleNearby(
BukkitCustomCropsPlugin plugin,
Section section,
@@ -50,10 +52,10 @@ public class ActionTitleNearby<T> extends AbstractBuiltInAction<T> {
this.fadeOut = section.getInt("fade-out", 10);
this.range = section.getInt("range", 0);
}
@Override
public void trigger(Context<T> context) {
protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
for (Player player : location.getWorld().getPlayers()) {
if (LocationUtils.getDistance(player.getLocation(), location) <= range) {
@@ -68,27 +70,27 @@ public class ActionTitleNearby<T> extends AbstractBuiltInAction<T> {
}
}
public TextValue<T> getTitle() {
public TextValue<T> title() {
return title;
}
public TextValue<T> getSubtitle() {
public TextValue<T> subtitle() {
return subtitle;
}
public int getFadeIn() {
public int fadeIn() {
return fadeIn;
}
public int getStay() {
public int stay() {
return stay;
}
public int getFadeOut() {
public int fadeOut() {
return fadeOut;
}
public int getRange() {
public int range() {
return range;
}
}