Skip to content

Commit bb2b457

Browse files
committed
New Fakeplayer start
1 parent 9338453 commit bb2b457

19 files changed

+1326
-837
lines changed

patches/api/0003-Add-fakeplayer-api.patch

Lines changed: 108 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ index 0000000000000000000000000000000000000000..922ca5b27bc0dd443d635646f37f8795
120120
+}
121121
diff --git a/src/main/java/org/leavesmc/leaves/entity/BotManager.java b/src/main/java/org/leavesmc/leaves/entity/BotManager.java
122122
new file mode 100644
123-
index 0000000000000000000000000000000000000000..ee6848b8990c516aa5c5490546dd16ae5c909740
123+
index 0000000000000000000000000000000000000000..457395381d1d78eb53f307d4465ea520c1aa57fd
124124
--- /dev/null
125125
+++ b/src/main/java/org/leavesmc/leaves/entity/BotManager.java
126-
@@ -0,0 +1,124 @@
126+
@@ -0,0 +1,58 @@
127127
+package org.leavesmc.leaves.entity;
128128
+
129129
+import org.bukkit.Location;
@@ -159,72 +159,6 @@ index 0000000000000000000000000000000000000000..ee6848b8990c516aa5c5490546dd16ae
159159
+ public Bot getBot(@NotNull String name);
160160
+
161161
+ /**
162-
+ * Creates a fakeplayer with given param.
163-
+ * <p>
164-
+ * prefix and suffix will not be added.
165-
+ *
166-
+ * @param name fakeplayer name
167-
+ * @param realName fakeplayer real name
168-
+ * @param skin fakeplayer skin arr
169-
+ * @param skinName fakeplayer skin name
170-
+ * @param location a location will create fakeplayer
171-
+ * @return a fakeplayer if success, null otherwise
172-
+ */
173-
+ @Deprecated(since = "1.21")
174-
+ @Nullable
175-
+ public Bot createBot(@NotNull String name, @NotNull String realName, @Nullable String[] skin, @Nullable String skinName, @NotNull Location location);
176-
+
177-
+ /**
178-
+ * Creates a fakeplayer with given param.
179-
+ * <p>
180-
+ * prefix and suffix will not be added.
181-
+ *
182-
+ * @param name fakeplayer name
183-
+ * @param realName fakeplayer real name
184-
+ * @param skin fakeplayer skin arr
185-
+ * @param skinName fakeplayer skin name
186-
+ * @param location a location will create fakeplayer
187-
+ * @param consumer a consumer after create fakeplayer success
188-
+ * @return a fakeplayer if you support skin arr and the creation is success, null otherwise
189-
+ */
190-
+ @Nullable
191-
+ public Bot createBot(@NotNull String name, @NotNull String realName, @NotNull String[] skin, @Nullable String skinName, @NotNull Location location, @Nullable Consumer<Bot> consumer);
192-
+
193-
+ /**
194-
+ * Creates a fakeplayer with given param.
195-
+ *
196-
+ * @param name fakeplayer name
197-
+ * @param skinName fakeplayer skin name
198-
+ * @param location a location will create fakeplayer
199-
+ * @param consumer a consumer after create fakeplayer success
200-
+ */
201-
+ public void createBot(@NotNull String name, @Nullable String skinName, @NotNull Location location, @Nullable Consumer<Bot> consumer);
202-
+
203-
+ /**
204-
+ * Removes a fakeplayer object by the given name.
205-
+ *
206-
+ * @param name the name to look up
207-
+ */
208-
+ public void removeBot(@NotNull String name);
209-
+
210-
+ /**
211-
+ * Removes a fakeplayer object by the given uuid.
212-
+ *
213-
+ * @param uuid the uuid to look up
214-
+ */
215-
+ public void removeBot(@NotNull UUID uuid);
216-
+
217-
+ /**
218-
+ * Removes all fakeplayers.
219-
+ */
220-
+ public void removeAllBots();
221-
+
222-
+ /**
223-
+ * Save fakeplayers data if resident-fakeplayer is true, or remove all fakeplayer.
224-
+ */
225-
+ public void saveOrRemoveAllBots();
226-
+
227-
+ /**
228162
+ * Gets a view of all currently logged in fakeplayers. This view is a reused object, making some operations like Collection.size() zero-allocation.
229163
+ *
230164
+ * @return a view of fakeplayers.
@@ -405,7 +339,7 @@ index 0000000000000000000000000000000000000000..91ea5540387b7d7e1be5b6368a2f02b3
405339
+}
406340
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotConfigModifyEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotConfigModifyEvent.java
407341
new file mode 100644
408-
index 0000000000000000000000000000000000000000..5e55759fd3d7891e8e1d5d6a306dc8144d366469
342+
index 0000000000000000000000000000000000000000..1ebdd3657e615a825918d455691cc1d6df78cfba
409343
--- /dev/null
410344
+++ b/src/main/java/org/leavesmc/leaves/event/bot/BotConfigModifyEvent.java
411345
@@ -0,0 +1,49 @@
@@ -420,10 +354,10 @@ index 0000000000000000000000000000000000000000..5e55759fd3d7891e8e1d5d6a306dc814
420354
+ private static final HandlerList handlers = new HandlerList();
421355
+
422356
+ private final String configName;
423-
+ private final String configValue;
357+
+ private final String[] configValue;
424358
+ private boolean cancel;
425359
+
426-
+ public BotConfigModifyEvent(@NotNull Bot who, String configName, String configValue) {
360+
+ public BotConfigModifyEvent(@NotNull Bot who, String configName, String[] configValue) {
427361
+ super(who);
428362
+ this.configName = configName;
429363
+ this.configValue = configValue;
@@ -435,7 +369,7 @@ index 0000000000000000000000000000000000000000..5e55759fd3d7891e8e1d5d6a306dc814
435369
+ }
436370
+
437371
+ @NotNull
438-
+ public String getConfigValue() {
372+
+ public String[] getConfigValue() {
439373
+ return configValue;
440374
+ }
441375
+
@@ -460,10 +394,10 @@ index 0000000000000000000000000000000000000000..5e55759fd3d7891e8e1d5d6a306dc814
460394
+}
461395
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotCreateEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotCreateEvent.java
462396
new file mode 100644
463-
index 0000000000000000000000000000000000000000..be510d565c5942efea3423190b06c01873a7abd2
397+
index 0000000000000000000000000000000000000000..ec0ed853a6d6dec263784da284ee521c81aebbc8
464398
--- /dev/null
465399
+++ b/src/main/java/org/leavesmc/leaves/event/bot/BotCreateEvent.java
466-
@@ -0,0 +1,118 @@
400+
@@ -0,0 +1,119 @@
467401
+package org.leavesmc.leaves.event.bot;
468402
+
469403
+import org.bukkit.Location;
@@ -483,14 +417,15 @@ index 0000000000000000000000000000000000000000..be510d565c5942efea3423190b06c018
483417
+ public enum CreateReason {
484418
+ COMMAND,
485419
+ PLUGIN,
486-
+ INTERNAL
420+
+ INTERNAL,
421+
+ UNKNOWN,
487422
+ }
488423
+ private static final HandlerList handlers = new HandlerList();
489424
+
490425
+ private final String bot;
491426
+ private final String skin;
492427
+ private final CreateReason reason;
493-
+ private final Optional<CommandSender> creator;
428+
+ private final CommandSender creator;
494429
+ private Location createLocation;
495430
+ private boolean cancel = false;
496431
+
@@ -499,7 +434,7 @@ index 0000000000000000000000000000000000000000..be510d565c5942efea3423190b06c018
499434
+ this.skin = skin;
500435
+ this.createLocation = createLocation;
501436
+ this.reason = reason;
502-
+ this.creator = Optional.ofNullable(creator);
437+
+ this.creator = creator;
503438
+ }
504439
+
505440
+ /**
@@ -552,12 +487,12 @@ index 0000000000000000000000000000000000000000..be510d565c5942efea3423190b06c018
552487
+
553488
+ /**
554489
+ * Gets the creator of the bot
555-
+ * if the create reason is not COMMAND, the creator might be Optional.empty()
490+
+ * if the create reason is not COMMAND, the creator might be null
556491
+ *
557492
+ * @return An optional of creator
558493
+ */
559-
+ @NotNull
560-
+ public Optional<CommandSender> getCreator() {
494+
+ @Nullable
495+
+ public CommandSender getCreator() {
561496
+ return creator;
562497
+ }
563498
+
@@ -582,6 +517,81 @@ index 0000000000000000000000000000000000000000..be510d565c5942efea3423190b06c018
582517
+ return handlers;
583518
+ }
584519
+}
520+
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotDeathEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotDeathEvent.java
521+
new file mode 100644
522+
index 0000000000000000000000000000000000000000..3366b50cf1835129a027b5342e4d8cf070cecf4a
523+
--- /dev/null
524+
+++ b/src/main/java/org/leavesmc/leaves/event/bot/BotDeathEvent.java
525+
@@ -0,0 +1,69 @@
526+
+package org.leavesmc.leaves.event.bot;
527+
+
528+
+import net.kyori.adventure.text.Component;
529+
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
530+
+import org.bukkit.event.Cancellable;
531+
+import org.bukkit.event.HandlerList;
532+
+import org.jetbrains.annotations.NotNull;
533+
+import org.jetbrains.annotations.Nullable;
534+
+import org.leavesmc.leaves.entity.Bot;
535+
+
536+
+public class BotDeathEvent extends BotEvent implements Cancellable {
537+
+
538+
+ private static final HandlerList handlers = new HandlerList();
539+
+
540+
+ private boolean cancel = false;
541+
+ private boolean sendDeathMessage;
542+
+ private Component deathMessage;
543+
+
544+
+ public BotDeathEvent(@NotNull Bot who, @Nullable Component deathMessage, boolean sendDeathMessage) {
545+
+ super(who);
546+
+ this.deathMessage = deathMessage;
547+
+ this.sendDeathMessage = sendDeathMessage;
548+
+ }
549+
+
550+
+ @Override
551+
+ public @NotNull HandlerList getHandlers() {
552+
+ return handlers;
553+
+ }
554+
+
555+
+ @NotNull
556+
+ public static HandlerList getHandlerList() {
557+
+ return handlers;
558+
+ }
559+
+
560+
+ public Component deathMessage() {
561+
+ return deathMessage;
562+
+ }
563+
+
564+
+ public void deathMessage(Component deathMessage) {
565+
+ this.deathMessage = deathMessage;
566+
+ }
567+
+
568+
+ @Nullable
569+
+ public String getDeathMessage() {
570+
+ return this.deathMessage == null ? null : LegacyComponentSerializer.legacySection().serialize(this.deathMessage);
571+
+ }
572+
+
573+
+ public void setDeathMessage(@Nullable String deathMessage) {
574+
+ this.deathMessage = deathMessage != null ? LegacyComponentSerializer.legacySection().deserialize(deathMessage) : null;
575+
+ }
576+
+
577+
+ public boolean isSendDeathMessage() {
578+
+ return sendDeathMessage;
579+
+ }
580+
+
581+
+ public void setSendDeathMessage(boolean sendDeathMessage) {
582+
+ this.sendDeathMessage = sendDeathMessage;
583+
+ }
584+
+
585+
+ @Override
586+
+ public boolean isCancelled() {
587+
+ return cancel;
588+
+ }
589+
+
590+
+ @Override
591+
+ public void setCancelled(boolean cancel) {
592+
+ this.cancel = cancel;
593+
+ }
594+
+}
585595
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotEvent.java
586596
new file mode 100644
587597
index 0000000000000000000000000000000000000000..ad358081f1e1da4075243d7ca0a01c1f7b00631b
@@ -745,10 +755,10 @@ index 0000000000000000000000000000000000000000..07f6d81c4cd897230bbd6712dac09b89
745755
+}
746756
diff --git a/src/main/java/org/leavesmc/leaves/event/bot/BotRemoveEvent.java b/src/main/java/org/leavesmc/leaves/event/bot/BotRemoveEvent.java
747757
new file mode 100644
748-
index 0000000000000000000000000000000000000000..7af990a5ee020dfdbec2efc6aecf6393a4223730
758+
index 0000000000000000000000000000000000000000..e950643e4b4da99b067d7392034a651361094853
749759
--- /dev/null
750760
+++ b/src/main/java/org/leavesmc/leaves/event/bot/BotRemoveEvent.java
751-
@@ -0,0 +1,105 @@
761+
@@ -0,0 +1,107 @@
752762
+package org.leavesmc.leaves.event.bot;
753763
+
754764
+import net.kyori.adventure.text.Component;
@@ -776,23 +786,17 @@ index 0000000000000000000000000000000000000000..7af990a5ee020dfdbec2efc6aecf6393
776786
+ private static final HandlerList handlers = new HandlerList();
777787
+
778788
+ private final RemoveReason reason;
779-
+ private final Optional<CommandSender> remover;
789+
+ private final CommandSender remover;
780790
+ private Component removeMessage;
791+
+ private boolean saved;
781792
+ private boolean cancel = false;
782793
+
783-
+ public BotRemoveEvent(@NotNull final Bot who, @NotNull RemoveReason reason) {
784-
+ this(who, reason, null);
785-
+ }
786-
+
787-
+ public BotRemoveEvent(@NotNull final Bot who, @NotNull RemoveReason reason, @Nullable CommandSender remover) {
788-
+ this(who, reason, remover, null);
789-
+ }
790-
+
791-
+ public BotRemoveEvent(@NotNull final Bot who, @NotNull RemoveReason reason, @Nullable CommandSender remover, @Nullable Component removeMessage) {
794+
+ public BotRemoveEvent(@NotNull final Bot who, @NotNull RemoveReason reason, @Nullable CommandSender remover, @Nullable Component removeMessage, boolean saved) {
792795
+ super(who);
793796
+ this.reason = reason;
794-
+ this.remover = Optional.ofNullable(remover);
797+
+ this.remover = remover;
795798
+ this.removeMessage = removeMessage;
799+
+ this.saved = saved;
796800
+ }
797801
+
798802
+ /**
@@ -807,12 +811,12 @@ index 0000000000000000000000000000000000000000..7af990a5ee020dfdbec2efc6aecf6393
807811
+
808812
+ /**
809813
+ * Gets the remover of the bot
810-
+ * if the remove reason is not COMMAND, the creator might be Optional.empty()
814+
+ * if the remove reason is not COMMAND, the creator might be null
811815
+ *
812816
+ * @return An optional of remover
813817
+ */
814-
+ @NotNull
815-
+ public Optional<CommandSender> getRemover() {
818+
+ @Nullable
819+
+ public CommandSender getRemover() {
816820
+ return remover;
817821
+ }
818822
+
@@ -843,6 +847,14 @@ index 0000000000000000000000000000000000000000..7af990a5ee020dfdbec2efc6aecf6393
843847
+ this.cancel = cancel;
844848
+ }
845849
+
850+
+ public boolean isSaved() {
851+
+ return saved;
852+
+ }
853+
+
854+
+ public void setSaved(boolean saved) {
855+
+ this.saved = saved;
856+
+ }
857+
+
846858
+ @Override
847859
+ @NotNull
848860
+ public HandlerList getHandlers() {

0 commit comments

Comments
 (0)