Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed Sep 18, 2024
1 parent 8d5df00 commit 9c6db52
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
27 changes: 23 additions & 4 deletions patches/api/0003-Add-fakeplayer-api.patch
Original file line number Diff line number Diff line change
Expand Up @@ -588,22 +588,25 @@ index 0000000000000000000000000000000000000000..f1123d55712cc90a1d0bb79b7832c90a
+}
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotActionStopEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotActionStopEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..acac3d3ff0a985e461edf2ee3a1c32a9b9b296c9
index 0000000000000000000000000000000000000000..56822a944a13394f635a7640d76c66b4cc98698a
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/event/bot/BotActionStopEvent.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,56 @@
+package org.leavesmc.leaves.event.bot;
+
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.leavesmc.leaves.entity.Bot;
+
+import java.util.UUID;
+
+public class BotActionStopEvent extends BotActionEvent {
+
+public class BotActionStopEvent extends BotActionEvent implements Cancellable{
+ private static final HandlerList handlers = new HandlerList();
+ private boolean cancel = false;
+ private final CommandSender sender;
+
+ public enum Reason {
+ DONE, COMMAND, PLUGIN, INTERNAL
Expand All @@ -614,6 +617,7 @@ index 0000000000000000000000000000000000000000..acac3d3ff0a985e461edf2ee3a1c32a9
+ public BotActionStopEvent(@NotNull Bot who, String actionName, UUID actionUUID, Reason stopReason, CommandSender sender) {
+ super(who, actionName, actionUUID);
+ this.reason = stopReason;
+ this.sender = sender;
+ }
+
+ public Reason getReason() {
Expand All @@ -628,6 +632,21 @@ index 0000000000000000000000000000000000000000..acac3d3ff0a985e461edf2ee3a1c32a9
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancel;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancel = cancel;
+ }
+
+ @Nullable
+ public CommandSender getSender() {
+ return sender;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotConfigModifyEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotConfigModifyEvent.java
new file mode 100644
Expand Down
37 changes: 25 additions & 12 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ index 4632eb883e9f5efde520ee543bcad25827c0da2c..d710803137a325f34e0628405d5ddfd0
return event;
diff --git a/src/main/java/org/leavesmc/leaves/bot/BotCommand.java b/src/main/java/org/leavesmc/leaves/bot/BotCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..ee4255c82786c83428373caf2d6d8530e164c671
index 0000000000000000000000000000000000000000..5a1054414f5313b59d38d89fb84987cad397ff12
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/BotCommand.java
@@ -0,0 +1,530 @@
@@ -0,0 +1,543 @@
+package org.leavesmc.leaves.bot;
+
+import io.papermc.paper.command.CommandUtil;
Expand Down Expand Up @@ -958,10 +958,18 @@ index 0000000000000000000000000000000000000000..ee4255c82786c83428373caf2d6d8530
+
+ String index = args[3];
+ if (index.equals("all")) {
+ bot.getBotActions().forEach(action -> new BotActionStopEvent(
+ bot.getBukkitEntity(), action.getName(), action.getUUID(), BotActionStopEvent.Reason.COMMAND, sender
+ ).callEvent());
+ bot.getBotActions().clear();
+ Set<BotAction<?>> forRemoval = new HashSet<>();
+ for (int i = 0; i < bot.getBotActions().size(); i++) {
+ BotAction<?> action = bot.getBotActions().get(i);
+ BotActionStopEvent event = new BotActionStopEvent(
+ bot.getBukkitEntity(), action.getName(), action.getUUID(), BotActionStopEvent.Reason.COMMAND, sender
+ );
+ event.callEvent();
+ if (!event.isCancelled()) {
+ forRemoval.add(action);
+ }
+ }
+ bot.getBotActions().removeAll(forRemoval);
+ sender.sendMessage(bot.getScoreboardName() + "'s action list cleared.");
+ } else {
+ try {
Expand All @@ -972,11 +980,15 @@ index 0000000000000000000000000000000000000000..ee4255c82786c83428373caf2d6d8530
+ }
+
+ BotAction<?> action = bot.getBotActions().get(i);
+ new BotActionStopEvent(
+ BotActionStopEvent event = new BotActionStopEvent(
+ bot.getBukkitEntity(), action.getName(), action.getUUID(), BotActionStopEvent.Reason.COMMAND, sender
+ ).callEvent();
+ bot.getBotActions().remove(i);
+ sender.sendMessage(bot.getScoreboardName() + "'s " + action.getName() + " stopped.");
+ );
+ event.callEvent();
+ if (!event.isCancelled()) {
+ bot.getBotActions().remove(i);
+ sender.sendMessage(bot.getScoreboardName() + "'s " + action.getName() + " stopped.");
+
+ }
+ } catch (NumberFormatException e) {
+ sender.sendMessage(text("Invalid index", NamedTextColor.RED));
+ }
Expand Down Expand Up @@ -1088,8 +1100,9 @@ index 0000000000000000000000000000000000000000..ee4255c82786c83428373caf2d6d8530
+ return;
+ }
+
+ if (!botList.removeBot(bot, BotRemoveEvent.RemoveReason.COMMAND, sender, true)) return;
+ sender.sendMessage(bot.getScoreboardName() + " saved to " + bot.createState.realName());
+ if (botList.removeBot(bot, BotRemoveEvent.RemoveReason.COMMAND, sender, true)) {
+ sender.sendMessage(bot.getScoreboardName() + " saved to " + bot.createState.realName());
+ }
+ }
+
+ private void onLoad(CommandSender sender, String @NotNull [] args) {
Expand Down

0 comments on commit 9c6db52

Please sign in to comment.