From 9c6db52100487714798ff0417f3f4dc1fca39f7f Mon Sep 17 00:00:00 2001 From: MC_XiaoHei Date: Wed, 18 Sep 2024 14:22:18 +0800 Subject: [PATCH] fixup --- patches/api/0003-Add-fakeplayer-api.patch | 27 +++++++++++--- patches/server/0010-Fakeplayer-support.patch | 37 +++++++++++++------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/patches/api/0003-Add-fakeplayer-api.patch b/patches/api/0003-Add-fakeplayer-api.patch index 3202264f..9e9e1386 100644 --- a/patches/api/0003-Add-fakeplayer-api.patch +++ b/patches/api/0003-Add-fakeplayer-api.patch @@ -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 @@ -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() { @@ -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 diff --git a/patches/server/0010-Fakeplayer-support.patch b/patches/server/0010-Fakeplayer-support.patch index 952e6481..dbbfdf58 100644 --- a/patches/server/0010-Fakeplayer-support.patch +++ b/patches/server/0010-Fakeplayer-support.patch @@ -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; @@ -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> 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 { @@ -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)); + } @@ -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) {