Compare commits
7 Commits
1.20.2-768
...
1.20.2-772
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
909b208b67 | ||
|
|
b159640ebe | ||
|
|
76aa79aa3c | ||
|
|
f2d8696e94 | ||
|
|
31e86623e1 | ||
|
|
a290a8d6a0 | ||
|
|
31a559f1d9 |
2
.github/workflows/build_1_20_2.yml
vendored
2
.github/workflows/build_1_20_2.yml
vendored
@@ -60,4 +60,4 @@ jobs:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
file: "build/libs/luminol-1.20.2-paperclip.jar"
|
||||
file_glob: true
|
||||
prerelease: false
|
||||
prerelease: true
|
||||
|
||||
506
patches/api/0002-Leaves-fakeplayer-API.patch
Normal file
506
patches/api/0002-Leaves-fakeplayer-API.patch
Normal file
@@ -0,0 +1,506 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrHua269 <novau233@163.com>
|
||||
Date: Tue, 30 Jan 2024 09:03:08 +0000
|
||||
Subject: [PATCH] Leaves fakeplayer API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||
index b7e1c8bd8dd38e1a9e74925740b22dad61a75f49..5ee1ba3847599ac67b5cd8ca26e61b1231c45dcd 100644
|
||||
--- a/src/main/java/org/bukkit/Bukkit.java
|
||||
+++ b/src/main/java/org/bukkit/Bukkit.java
|
||||
@@ -58,6 +58,7 @@ import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import io.papermc.paper.util.JarManifests; // Paper
|
||||
+import top.leavesmc.leaves.entity.BotManager;
|
||||
|
||||
/**
|
||||
* Represents the Bukkit core, for version and Server singleton handling
|
||||
@@ -2836,6 +2837,17 @@ public final class Bukkit {
|
||||
}
|
||||
// Folia end - region threading API
|
||||
|
||||
+ // Leaves start - Bot API
|
||||
+ /**
|
||||
+ * Returns a bot manager.
|
||||
+ *
|
||||
+ * @return Bot Manager
|
||||
+ */
|
||||
+ public static @NotNull BotManager getBotManager() {
|
||||
+ return server.getBotManager();
|
||||
+ }
|
||||
+ // Leaves end - Bot API
|
||||
+
|
||||
@NotNull
|
||||
public static Server.Spigot spigot() {
|
||||
return server.spigot();
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 85b169c04f44431363d4e14d4857140f160ceace..9e12552aca127892d122a2616d303d3cdfc67416 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -58,6 +58,7 @@ import org.bukkit.util.CachedServerIcon;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.BotManager;
|
||||
|
||||
/**
|
||||
* Represents a server implementation.
|
||||
@@ -2479,4 +2480,14 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
*/
|
||||
public boolean isGlobalTickThread();
|
||||
// Folia end - region threading API
|
||||
+
|
||||
+
|
||||
+ // Leaves start - Bot API
|
||||
+ /**
|
||||
+ * Returns a bot manager.
|
||||
+ *
|
||||
+ * @return Bot Manager
|
||||
+ */
|
||||
+ @NotNull BotManager getBotManager();
|
||||
+ // Leaves end - Bot 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..8816683c795f9be6a4f112203cfac3f59d8faba5
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/Bot.java
|
||||
@@ -0,0 +1,46 @@
|
||||
+package top.leavesmc.leaves.entity;
|
||||
+
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.botaction.LeavesBotAction;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a fakeplayer
|
||||
+ */
|
||||
+public interface Bot extends Player {
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the fakeplayer skin
|
||||
+ *
|
||||
+ * @return fakeplayer skin name
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public String getSkinName();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the fakeplayer name without prefix and suffix
|
||||
+ *
|
||||
+ * @return fakeplayer real name
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getRealName();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the fakeplayer action with args.
|
||||
+ *
|
||||
+ * @param action action name
|
||||
+ * @param player player who create this action
|
||||
+ * @param args passed action arguments
|
||||
+ */
|
||||
+ public boolean setBotAction(@NotNull String action, @NotNull Player player, @NotNull String[] args);
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the fakeplayer action with args.
|
||||
+ *
|
||||
+ * @param action leaves bot action
|
||||
+ * @param player player who create this action
|
||||
+ * @param args passed action arguments
|
||||
+ */
|
||||
+ public boolean setBotAction(@NotNull LeavesBotAction action, @NotNull Player player, @NotNull String[] args);
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/entity/BotManager.java b/src/main/java/top/leavesmc/leaves/entity/BotManager.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..f2258027b2ed4bfcf7feda2e9075b1a1a05a85b6
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/BotManager.java
|
||||
@@ -0,0 +1,107 @@
|
||||
+package top.leavesmc.leaves.entity;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.util.Consumer;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.botaction.CustomBotAction;
|
||||
+
|
||||
+import java.util.Collection;
|
||||
+import java.util.UUID;
|
||||
+
|
||||
+/**
|
||||
+ * Simple fakeplayer manager
|
||||
+ */
|
||||
+public interface BotManager {
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a fakeplayer object by the given uuid.
|
||||
+ *
|
||||
+ * @param uuid the uuid to look up
|
||||
+ * @return a fakeplayer if one was found, null otherwise
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Bot getBot(@NotNull UUID uuid);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a fakeplayer object by the given name.
|
||||
+ *
|
||||
+ * @param name the name to look up
|
||||
+ * @return a fakeplayer if one was found, null otherwise
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Bot getBot(@NotNull String name);
|
||||
+
|
||||
+ /**
|
||||
+ * Creates a fakeplayer with given param.
|
||||
+ * <p>
|
||||
+ * prefix and suffix will not be added.
|
||||
+ *
|
||||
+ * @param name fakeplayer name
|
||||
+ * @param realName fakeplayer real name
|
||||
+ * @param skin fakeplayer skin arr
|
||||
+ * @param skinName fakeplayer skin name
|
||||
+ * @param location a location will create fakeplayer
|
||||
+ * @return a fakeplayer if success, null otherwise
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Bot createBot(@NotNull String name, @NotNull String realName, @Nullable String[] skin, @Nullable String skinName, @NotNull Location location);
|
||||
+
|
||||
+ /**
|
||||
+ * Creates a fakeplayer with given param.
|
||||
+ *
|
||||
+ * @param name fakeplayer name
|
||||
+ * @param skinName fakeplayer skin name
|
||||
+ * @param location a location will create fakeplayer
|
||||
+ * @param consumer a consumer after create fakeplayer success
|
||||
+ */
|
||||
+ public void createBot(@NotNull String name, @Nullable String skinName, @NotNull Location location, @Nullable Consumer<Bot> consumer);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes a fakeplayer object by the given name.
|
||||
+ *
|
||||
+ * @param name the name to look up
|
||||
+ */
|
||||
+ public void removeBot(@NotNull String name);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes a fakeplayer object by the given uuid.
|
||||
+ *
|
||||
+ * @param uuid the uuid to look up
|
||||
+ */
|
||||
+ public void removeBot(@NotNull UUID uuid);
|
||||
+
|
||||
+ /**
|
||||
+ * Removes all fakeplayers.
|
||||
+ */
|
||||
+ public void removeAllBots();
|
||||
+
|
||||
+ /**
|
||||
+ * Save fakeplayers data if resident-fakeplayer is true, or remove all fakeplayer.
|
||||
+ */
|
||||
+ public void saveOrRemoveAllBots();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a view of all currently logged in fakeplayers. This view is a reused object, making some operations like Collection.size() zero-allocation.
|
||||
+ *
|
||||
+ * @return a view of fakeplayers.
|
||||
+ */
|
||||
+ public Collection<Bot> getBots();
|
||||
+
|
||||
+ /**
|
||||
+ * Register a custom bot action.
|
||||
+ *
|
||||
+ * @param name action name
|
||||
+ * @param action action executor
|
||||
+ * @return true if success, or false
|
||||
+ */
|
||||
+ public boolean registerCustomBotAction(String name, CustomBotAction action);
|
||||
+
|
||||
+ /**
|
||||
+ * Unregister a custom bot action.
|
||||
+ *
|
||||
+ * @param name action name
|
||||
+ * @return true if success, or false
|
||||
+ */
|
||||
+ public boolean unregisterCustomBotAction(String name);
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java b/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..7abf4eef22e40468929e724ebc07a97b0b2a05f3
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java
|
||||
@@ -0,0 +1,52 @@
|
||||
+package top.leavesmc.leaves.entity.botaction;
|
||||
+
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.Bot;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a class which contains methods for a custom bot action
|
||||
+ */
|
||||
+public interface CustomBotAction {
|
||||
+
|
||||
+ /**
|
||||
+ * Executes the action, returning its success.
|
||||
+ *
|
||||
+ * @param bot bot of the action
|
||||
+ * @return true if once action finish, otherwise false
|
||||
+ */
|
||||
+ public boolean doTick(Bot bot);
|
||||
+
|
||||
+ /**
|
||||
+ * Created a new action instance.
|
||||
+ *
|
||||
+ * @param player player who create this action
|
||||
+ * @param args passed action arguments
|
||||
+ * @return a new action instance with given args
|
||||
+ */
|
||||
+ public @Nullable CustomBotAction getNew(Player player, String[] args);
|
||||
+
|
||||
+ /**
|
||||
+ * Requests a list of possible completions for a action argument.
|
||||
+ *
|
||||
+ * @return A List of a List of possible completions for the argument.
|
||||
+ */
|
||||
+ public @NotNull List<List<String>> getTabComplete();
|
||||
+
|
||||
+ /**
|
||||
+ * Return a ticks to wait between {@link CustomBotAction#doTick(Bot)}
|
||||
+ *
|
||||
+ * @return the ticks to wait between runs
|
||||
+ */
|
||||
+ public int getTickDelay();
|
||||
+
|
||||
+ /**
|
||||
+ * Return a number of times {@link CustomBotAction#doTick(Bot)} can return true
|
||||
+ *
|
||||
+ * @return the number of times an action can be executed
|
||||
+ */
|
||||
+ public int getNumber();
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java b/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e298722319ff0cfd52e531693ea3767e5f9a3d52
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java
|
||||
@@ -0,0 +1,32 @@
|
||||
+package top.leavesmc.leaves.entity.botaction;
|
||||
+
|
||||
+/**
|
||||
+ * A Leaves bot action enum
|
||||
+ */
|
||||
+public enum LeavesBotAction {
|
||||
+ ATTACK("attack"),
|
||||
+ ATTACK_SELF("attack_self"),
|
||||
+ BREAK("break"),
|
||||
+ DROP("drop"),
|
||||
+ FISH("fish"),
|
||||
+ JUMP("jump"),
|
||||
+ LAY("lay"),
|
||||
+ LOOK("look"),
|
||||
+ ROTATE("rotate"),
|
||||
+ SNEAK("sneak"),
|
||||
+ STOP("stop"),
|
||||
+ SWIM("swim"),
|
||||
+ USE("use"),
|
||||
+ USE_ON("use_on"),
|
||||
+ USE_TO("use_to");
|
||||
+
|
||||
+ private final String name;
|
||||
+
|
||||
+ private LeavesBotAction(String name) {
|
||||
+ this.name = name;
|
||||
+ }
|
||||
+
|
||||
+ public String getName() {
|
||||
+ return name;
|
||||
+ }
|
||||
+}
|
||||
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;
|
||||
+ }
|
||||
+}
|
||||
@@ -46,7 +46,7 @@ index 11c1a367fbc25cb63738a00ad93fb0b0b3500e7d..4f6af1fa55047e7be9e57c1dd1c60e9d
|
||||
}
|
||||
|
||||
+ private static void initDAB(){
|
||||
+ dearEnabled = get("optimizations.dab.enabled", false);
|
||||
+ dearEnabled = get("optimizations.dab.enabled", true);
|
||||
+ startDistance = get("optimizations.dab.start-distance", 12,
|
||||
+ "This value determines how far away an entity has to be\n"+
|
||||
+ "from the player to start being effected by DEAR.");
|
||||
|
||||
166
patches/server/0060-Leaves-Command-Utilities.patch
Normal file
166
patches/server/0060-Leaves-Command-Utilities.patch
Normal file
@@ -0,0 +1,166 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrHua269 <novau233@163.com>
|
||||
Date: Mon, 29 Jan 2024 12:47:41 +0000
|
||||
Subject: [PATCH] Leaves Command Utilities
|
||||
|
||||
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/command/CommandArgument.java b/src/main/java/top/leavesmc/leaves/command/CommandArgument.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..eadc6d168fb13299348b0c275ae352ee2f1e1ea2
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/command/CommandArgument.java
|
||||
@@ -0,0 +1,43 @@
|
||||
+package top.leavesmc.leaves.command;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class CommandArgument {
|
||||
+
|
||||
+ private final List<CommandArgumentType<?>> argumentTypes;
|
||||
+ private final List<List<String>> tabComplete;
|
||||
+
|
||||
+ public CommandArgument(CommandArgumentType<?>... argumentTypes) {
|
||||
+ this.argumentTypes = List.of(argumentTypes);
|
||||
+ this.tabComplete = new ArrayList<>();
|
||||
+ for (int i = 0; i < argumentTypes.length; i++) {
|
||||
+ tabComplete.add(new ArrayList<>());
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public List<String> tabComplete(int n) {
|
||||
+ if (tabComplete.size() > n) {
|
||||
+ return tabComplete.get(n);
|
||||
+ } else {
|
||||
+ return List.of();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public CommandArgument setTabComplete(int index, List<String> list) {
|
||||
+ tabComplete.set(index, list);
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ public CommandArgumentResult parse(int index, String @NotNull [] args) {
|
||||
+ Object[] result = new Object[argumentTypes.size()];
|
||||
+ Arrays.fill(result, null);
|
||||
+ for (int i = index, j = 0; i < args.length && j < result.length; i++, j++) {
|
||||
+ result[j] = argumentTypes.get(j).pasre(args[i]);
|
||||
+ }
|
||||
+ return new CommandArgumentResult(new ArrayList<>(Arrays.asList(result)));
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/command/CommandArgumentResult.java b/src/main/java/top/leavesmc/leaves/command/CommandArgumentResult.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..340eaca64c96180b895a075ce9e44402cd104eed
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/command/CommandArgumentResult.java
|
||||
@@ -0,0 +1,62 @@
|
||||
+package top.leavesmc.leaves.command;
|
||||
+
|
||||
+import net.minecraft.core.BlockPos;
|
||||
+import org.bukkit.util.Vector;
|
||||
+
|
||||
+import java.util.List;
|
||||
+import java.util.Objects;
|
||||
+
|
||||
+public class CommandArgumentResult {
|
||||
+
|
||||
+ private final List<Object> result;
|
||||
+
|
||||
+ public CommandArgumentResult(List<Object> result) {
|
||||
+ this.result = result;
|
||||
+ }
|
||||
+
|
||||
+ public Integer readInt(int def) {
|
||||
+ return Objects.requireNonNullElse(read(Integer.class), def);
|
||||
+ }
|
||||
+
|
||||
+ public Double readDouble(double def) {
|
||||
+ return Objects.requireNonNullElse(read(Double.class), def);
|
||||
+ }
|
||||
+
|
||||
+ public String readString(String def) {
|
||||
+ return Objects.requireNonNullElse(read(String.class), def);
|
||||
+ }
|
||||
+
|
||||
+ public BlockPos readPos() {
|
||||
+ Integer[] pos = {read(Integer.class), read(Integer.class), read(Integer.class)};
|
||||
+ for (Integer po : pos) {
|
||||
+ if (po == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ return new BlockPos(pos[0], pos[1], pos[2]);
|
||||
+ }
|
||||
+
|
||||
+ public Vector readVector() {
|
||||
+ Double[] pos = {read(Double.class), read(Double.class), read(Double.class)};
|
||||
+ for (Double po : pos) {
|
||||
+ if (po == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ return new Vector(pos[0], pos[1], pos[2]);
|
||||
+ }
|
||||
+
|
||||
+ public <T> T read(Class<T> tClass) {
|
||||
+ if (result.isEmpty()) {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ Object obj = result.remove(0);
|
||||
+ if (tClass.isInstance(obj)) {
|
||||
+ return tClass.cast(obj);
|
||||
+ } else {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/command/CommandArgumentType.java b/src/main/java/top/leavesmc/leaves/command/CommandArgumentType.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..edf12195c7224ca2fb5d3c2ac3fcf485d3049d07
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/command/CommandArgumentType.java
|
||||
@@ -0,0 +1,37 @@
|
||||
+package top.leavesmc.leaves.command;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public abstract class CommandArgumentType<E> {
|
||||
+
|
||||
+ public static final CommandArgumentType<Integer> INTEGER = new CommandArgumentType<>() {
|
||||
+ @Override
|
||||
+ public Integer pasre(@NotNull String arg) {
|
||||
+ try {
|
||||
+ return Integer.parseInt(arg);
|
||||
+ } catch (NumberFormatException e) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
+ public static final CommandArgumentType<Double> DOUBLE = new CommandArgumentType<>() {
|
||||
+ @Override
|
||||
+ public Double pasre(@NotNull String arg) {
|
||||
+ try {
|
||||
+ return Double.parseDouble(arg);
|
||||
+ } catch (NumberFormatException e) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
+ public static final CommandArgumentType<String> STRING = new CommandArgumentType<>() {
|
||||
+ @Override
|
||||
+ public String pasre(@NotNull String arg) {
|
||||
+ return arg;
|
||||
+ }
|
||||
+ };
|
||||
+
|
||||
+ public abstract E pasre(@NotNull String arg);
|
||||
+}
|
||||
3226
patches/server/0061-Leaves-fakeplayer-support.patch
Normal file
3226
patches/server/0061-Leaves-fakeplayer-support.patch
Normal file
File diff suppressed because it is too large
Load Diff
102
patches/server/0062-Io_uring-channel-type-support.patch
Normal file
102
patches/server/0062-Io_uring-channel-type-support.patch
Normal file
@@ -0,0 +1,102 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrHua269 <novau233@163.com>
|
||||
Date: Tue, 30 Jan 2024 13:08:25 +0000
|
||||
Subject: [PATCH] Io_uring channel type support
|
||||
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 8a926993088d33983f75071b3320dd67c3e857c3..aa1033e0de7d59c32acd2afa58c0b916588b97ed 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -39,6 +39,7 @@ dependencies {
|
||||
log4jPlugins.annotationProcessorConfigurationName("org.apache.logging.log4j:log4j-core:2.19.0") // Paper - Needed to generate meta for our Log4j plugins
|
||||
runtimeOnly(log4jPlugins.output)
|
||||
alsoShade(log4jPlugins.output)
|
||||
+ implementation("io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.21.Final:linux-x86_64") //Luminol - io_uring Libraries
|
||||
implementation("io.netty:netty-codec-haproxy:4.1.97.Final") // Paper - Add support for proxy protocol
|
||||
// Paper end
|
||||
implementation("org.apache.logging.log4j:log4j-iostreams:2.19.0") // Paper - remove exclusion
|
||||
diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java
|
||||
index 610642b0a0c3f17c66ec27ed812b97c68cee1be6..87f5c0fc3f92feecb167c3e28d86a67ba848cb61 100644
|
||||
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
|
||||
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
|
||||
@@ -37,6 +37,7 @@ public class LuminolConfig {
|
||||
public static boolean fixSpectorTeleportFolia = false;
|
||||
public static boolean disableRootUserWarning = false;
|
||||
public static boolean fixDoubleEntitySchedulerRetring = false;
|
||||
+ public static boolean enableIoUring = false;
|
||||
|
||||
public static boolean safeTeleportation = true;
|
||||
public static boolean enableSandDuping = false;
|
||||
@@ -185,6 +186,7 @@ public class LuminolConfig {
|
||||
disableOfflineModeWarning = get("misc.disable_offline_mode_warning",disableOfflineModeWarning);
|
||||
disableRootUserWarning = get("misc.disable_root_user_warning",disableRootUserWarning);
|
||||
fixDoubleEntitySchedulerRetring = get("misc.fix_folia_double_entity_scheduler_retring",fixDoubleEntitySchedulerRetring,"Fix https://github.com/PaperMC/Folia/pull/181 on Folia");
|
||||
+ enableIoUring = get("misc.enable_io_uring_support",enableIoUring);
|
||||
|
||||
if (tpsbarEnabled){
|
||||
initTpsbar();
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
||||
index 81090d1b5d67506268a41c6387a1d45302e88a5c..637d321b75dc7b5653ff9aa6134f900c634a19d8 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
||||
@@ -20,9 +20,11 @@ import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.local.LocalAddress;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
-import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||
+import io.netty.incubator.channel.uring.IOUring;
|
||||
+import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
|
||||
+import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
|
||||
import io.netty.util.HashedWheelTimer;
|
||||
import io.netty.util.Timeout;
|
||||
import io.netty.util.Timer;
|
||||
@@ -35,6 +37,8 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
+
|
||||
+import me.earthme.luminol.LuminolConfig;
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.ReportedException;
|
||||
import net.minecraft.network.BandwidthDebugMonitor;
|
||||
@@ -73,6 +77,10 @@ public class ServerConnectionListener {
|
||||
}
|
||||
// Paper end
|
||||
|
||||
+ //Luminol start - io_uring support
|
||||
+ public static final Supplier<IOUringEventLoopGroup> SERVER_IO_URING_WORKER_GROUP = Suppliers.memoize(() -> new IOUringEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty IO_URING Server IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()));
|
||||
+ //Luminol end
|
||||
+
|
||||
public ServerConnectionListener(MinecraftServer server) {
|
||||
this.server = server;
|
||||
this.running = true;
|
||||
@@ -89,8 +97,14 @@ public class ServerConnectionListener {
|
||||
synchronized (this.channels) {
|
||||
Class oclass;
|
||||
EventLoopGroup eventloopgroup;
|
||||
-
|
||||
- if (Epoll.isAvailable() && this.server.isEpollEnabled()) {
|
||||
+ //Luminol start - io_uring support
|
||||
+ if (IOUring.isAvailable() && LuminolConfig.enableIoUring){
|
||||
+ eventloopgroup = SERVER_IO_URING_WORKER_GROUP.get();
|
||||
+ oclass = IOUringServerSocketChannel.class;
|
||||
+ ServerConnectionListener.LOGGER.info("Using io_uring channel type");
|
||||
+ }
|
||||
+ else if (Epoll.isAvailable() && this.server.isEpollEnabled()) {
|
||||
+ //Luminol end
|
||||
// Paper start
|
||||
if (address instanceof io.netty.channel.unix.DomainSocketAddress) {
|
||||
oclass = io.netty.channel.epoll.EpollServerDomainSocketChannel.class;
|
||||
@@ -100,7 +114,8 @@ public class ServerConnectionListener {
|
||||
// Paper end
|
||||
eventloopgroup = (EventLoopGroup) ServerConnectionListener.SERVER_EPOLL_EVENT_GROUP.get();
|
||||
ServerConnectionListener.LOGGER.info("Using epoll channel type");
|
||||
- } else {
|
||||
+ }
|
||||
+ else {
|
||||
oclass = NioServerSocketChannel.class;
|
||||
eventloopgroup = (EventLoopGroup) ServerConnectionListener.SERVER_EVENT_GROUP.get();
|
||||
ServerConnectionListener.LOGGER.info("Using default channel type");
|
||||
Reference in New Issue
Block a user