9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-21 16:09:21 +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) { 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 ActionDelay<>(plugin, this, args, chance), "delay");
registerAction((args, chance) -> new ActionTimer<>(plugin, this, args, chance), "timer"); registerAction((args, chance) -> new ActionTimer<>(plugin, this, args, chance), "timer");
registerAction((args, chance) -> { 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.BukkitCustomCropsPlugin;
import net.momirealms.customcrops.api.action.Action; import net.momirealms.customcrops.api.action.Action;
import net.momirealms.customcrops.api.context.Context;
public abstract class AbstractBuiltInAction<T> implements Action<T> { public abstract class AbstractBuiltInAction<T> implements Action<T> {
protected final BukkitCustomCropsPlugin plugin; protected final BukkitCustomCropsPlugin plugin;
protected final double chance; protected final double chance;
protected AbstractBuiltInAction(BukkitCustomCropsPlugin plugin, double chance) { protected AbstractBuiltInAction(BukkitCustomCropsPlugin plugin, double chance) {
this.plugin = plugin; this.plugin = plugin;
this.chance = chance; this.chance = chance;
} }
public BukkitCustomCropsPlugin getPlugin() { public BukkitCustomCropsPlugin plugin() {
return plugin; return plugin;
} }
public double getChance() { public double chance() {
return chance; return chance;
} }
public boolean checkChance() { @Override
return !(Math.random() > chance); 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; import static java.util.Objects.requireNonNull;
public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> { 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( public ActionActionbarNearby(
BukkitCustomCropsPlugin plugin, BukkitCustomCropsPlugin plugin,
Section section, Section section,
@@ -43,10 +45,10 @@ public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
this.actionbar = section.getString("actionbar"); this.actionbar = section.getString("actionbar");
this.range = MathValue.auto(section.get("range")); this.range = MathValue.auto(section.get("range"));
} }
@Override @Override
public void trigger(Context<T> context) { protected void triggerAction(Context<T> context) {
if (context.argOrDefault(ContextKeys.OFFLINE, false)) return; if (context.argOrDefault(ContextKeys.OFFLINE, false)) return;
if (Math.random() > chance) return;
OfflinePlayer owner = null; OfflinePlayer owner = null;
if (context.holder() instanceof Player player) { if (context.holder() instanceof Player player) {
owner = player; owner = player;
@@ -63,11 +65,11 @@ public class ActionActionbarNearby<T> extends AbstractBuiltInAction<T> {
} }
} }
public String getActionbar() { public String actionbar() {
return actionbar; return actionbar;
} }
public MathValue<T> getRange() { public MathValue<T> range() {
return range; return range;
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -44,10 +44,12 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> { public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
final MathValue<T> min;
final MathValue<T> max; private final MathValue<T> min;
final boolean toInv; private final MathValue<T> max;
final String[] qualityLoots; private final boolean toInv;
private final String[] qualityLoots;
public ActionQualityCrops( public ActionQualityCrops(
BukkitCustomCropsPlugin plugin, BukkitCustomCropsPlugin plugin,
Section section, Section section,
@@ -66,9 +68,9 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
} }
} }
} }
@Override @Override
public void trigger(Context<T> context) { protected void triggerAction(Context<T> context) {
if (!checkChance()) return;
Location location = requireNonNull(context.arg(ContextKeys.LOCATION)); Location location = requireNonNull(context.arg(ContextKeys.LOCATION));
int random = RandomUtils.generateRandomInt((int) min.evaluate(context), (int) max.evaluate(context)); int random = RandomUtils.generateRandomInt((int) min.evaluate(context), (int) max.evaluate(context));
Player player = null; Player player = null;
@@ -130,19 +132,19 @@ public class ActionQualityCrops<T> extends AbstractBuiltInAction<T> {
return null; return null;
} }
public MathValue<T> getMin() { public MathValue<T> min() {
return min; return min;
} }
public MathValue<T> getMax() { public MathValue<T> max() {
return max; return max;
} }
public boolean isToInv() { public boolean toInventory() {
return toInv; return toInv;
} }
public String[] getQualityLoots() { public String[] qualityLoots() {
return qualityLoots; return qualityLoots;
} }
} }

View File

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

View File

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

View File

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