9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-20 23:39:34 +00:00
Files
LeavesMC/patches/api/0003-Add-fakeplayer-api.patch
2023-03-12 16:48:32 +08:00

213 lines
5.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Wed, 27 Jul 2022 15:30:34 +0800
Subject: [PATCH] Add fakeplayer api
diff --git a/src/main/java/top/leavesmc/leaves/entity/Bot.java b/src/main/java/top/leavesmc/leaves/entity/Bot.java
new file mode 100644
index 0000000000000000000000000000000000000000..a59fd3495f5a51159d0c84300874b6d988e558c3
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/Bot.java
@@ -0,0 +1,18 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents a fakeplayer
+ */
+public interface Bot extends Player {
+
+ /**
+ * Gets the fakeplayer skin
+ *
+ * @return fakeplayer skin name
+ */
+ @Nullable
+ public String getSkinName();
+}
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotCreateEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotCreateEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..7cf1eb4eb3d2fe9310f9272ec53208632b87b49b
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/event/bot/BotCreateEvent.java
@@ -0,0 +1,106 @@
+package top.leavesmc.leaves.event.bot;
+
+import org.bukkit.Location;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Call when a fakeplayer creates a server
+ */
+public class BotCreateEvent extends Event implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+
+ private final String bot;
+ private final String skin;
+ private String joinMessage;
+ private Location createLocation;
+ private boolean cancel = false;
+
+ public BotCreateEvent(@NotNull final String who, @NotNull final String skin, @NotNull final Location createLocation, @Nullable final String joinMessage) {
+ this.bot = who;
+ this.skin = skin;
+ this.joinMessage = joinMessage;
+ this.createLocation = createLocation;
+ }
+
+ /**
+ * Gets the fakeplayer name
+ *
+ * @return fakeplayer name
+ */
+ public String getBot() {
+ return bot;
+ }
+
+ /**
+ * Gets the join message to send to all online players
+ *
+ * @return string join message. Can be null
+ */
+ @Nullable
+ public String getJoinMessage() {
+ return joinMessage;
+ }
+
+ /**
+ * Sets the join message to send to all online players
+ *
+ * @param joinMessage join message. If null, no message will be sent
+ */
+ public void setJoinMessage(@Nullable String joinMessage) {
+ this.joinMessage = joinMessage;
+ }
+
+ /**
+ * Gets the location to create the fakeplayer
+ *
+ * @return Location to create the fakeplayer
+ */
+ @NotNull
+ public Location getCreateLocation() {
+ return createLocation;
+ }
+
+ /**
+ * Sets the location to create the fakeplayer
+ *
+ * @param createLocation location to create the fakeplayer
+ */
+ public void setCreateLocation(@NotNull Location createLocation) {
+ this.createLocation = createLocation;
+ }
+
+ /**
+ * Gets the fakeplayer skin
+ *
+ * @return fakeplayer skin name
+ */
+ @Nullable
+ public String getSkin() {
+ return skin;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancel;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancel = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..4a4fe07ce965d4a97e0d8105a91310dac7d1343c
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/event/bot/BotEvent.java
@@ -0,0 +1,31 @@
+package top.leavesmc.leaves.event.bot;
+
+import org.bukkit.event.Event;
+import org.jetbrains.annotations.NotNull;
+import top.leavesmc.leaves.entity.Bot;
+
+/**
+ * Represents a fakeplayer related event
+ */
+public abstract class BotEvent extends Event {
+ protected Bot bot;
+
+ public BotEvent(@NotNull final Bot who) {
+ bot = who;
+ }
+
+ public BotEvent(@NotNull final Bot who, boolean async) { // Paper - public
+ super(async);
+ bot = who;
+ }
+
+ /**
+ * Returns the fakeplayer involved in this event
+ *
+ * @return Fakeplayer who is involved in this event
+ */
+ @NotNull
+ public final Bot getBot() {
+ return bot;
+ }
+}
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotJoinEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotJoinEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..10afa5c7fd4ee8a4e72d64f8ca9bf8731ec2ad61
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/event/bot/BotJoinEvent.java
@@ -0,0 +1,27 @@
+package top.leavesmc.leaves.event.bot;
+
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import top.leavesmc.leaves.entity.Bot;
+
+/**
+ * Called when a fakeplayer joins a server
+ */
+public class BotJoinEvent extends BotEvent {
+ private static final HandlerList handlers = new HandlerList();
+
+ public BotJoinEvent(@NotNull Bot who) {
+ super(who);
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}