Skip to content

Commit

Permalink
let CommandAPI internal plugin create more safe
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei authored Jul 23, 2024
1 parent 5636060 commit 1754df3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 3 additions & 8 deletions patches/api/0002-Command-API-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Command API support


diff --git a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
index d5a3c3dce76c4ed0f1184ab5ba21db9c5f1c01ec..789f500201bf0ad6597645f7799959fb8a378082 100644
index d5a3c3dce76c4ed0f1184ab5ba21db9c5f1c01ec..13b2341f6d3b3caf3d7a79f936b19c6805197427 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPlugin.java
@@ -15,6 +15,8 @@ import java.util.List;
Expand All @@ -17,17 +17,12 @@ index d5a3c3dce76c4ed0f1184ab5ba21db9c5f1c01ec..789f500201bf0ad6597645f7799959fb
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -64,6 +66,21 @@ public abstract class JavaPlugin extends PluginBase {
@@ -64,6 +66,16 @@ public abstract class JavaPlugin extends PluginBase {
// Paper end
}

+ // Lumina start - CommandAPI support
+ /**
+ * It should only be used internally on the server side.
+ * Never use it in a plugin!
+ *
+ */
+ public JavaPlugin(@Nullable Object onlyForCommandApi) {
+ protected JavaPlugin(@Nullable Object ignored) {
+ server = Bukkit.getServer();
+ isEnabled = true;
+ description = new PluginDescriptionFile("CommandAPI", "", "");
Expand Down
18 changes: 16 additions & 2 deletions patches/server/0002-Command-API-Support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ index d78ad5eccd18d89050a486a0c40090a09683bd16..8302e4bedc03795c4cda526466fa4dc2
public EntitySelector(int count, boolean includesNonPlayers, boolean localWorldOnly, Predicate<Entity> basePredicate, MinMaxBounds.Doubles distance, Function<Vec3, Vec3> positionOffset, @Nullable AABB box, BiConsumer<Vec3, List<? extends Entity>> sorter, boolean senderOnly, @Nullable String playerName, @Nullable UUID uuid, @Nullable EntityType<?> type, boolean usesAt) {
this.maxResults = count;
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index cc40d3e69a3635ca7895876159f2821091c14a9a..ad189a69f8466324d5c33416d0fbaeefa017341f 100644
index cc40d3e69a3635ca7895876159f2821091c14a9a..f16e1ee682415cf1b49aeba2fb3f879b07be3226 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -91,6 +91,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
Expand All @@ -1800,7 +1800,7 @@ index cc40d3e69a3635ca7895876159f2821091c14a9a..ad189a69f8466324d5c33416d0fbaeef
}

+ // Lumina start - enable CommandAPI
+ commandAPIPlugin = new org.bukkit.plugin.java.JavaPlugin(null){};
+ commandAPIPlugin = org.bukkit.plugin.java.CommandAPIPluginFactory.create();
+ dev.jorel.commandapi.CommandAPI.onLoad(new dev.jorel.commandapi.CommandAPIBukkitConfig(commandAPIPlugin)
+ .shouldHookPaperReload(false)
+ .skipReloadDatapacks(true)
Expand All @@ -1811,3 +1811,17 @@ index cc40d3e69a3635ca7895876159f2821091c14a9a..ad189a69f8466324d5c33416d0fbaeef
// CraftBukkit start
// this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
this.server.loadPlugins();
diff --git a/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java b/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..8afd999c0e4453df6b3b0c52cd6521758cd786b0
--- /dev/null
+++ b/src/main/java/org/bukkit/plugin/java/CommandAPIPluginFactory.java
@@ -0,0 +1,7 @@
+package org.bukkit.plugin.java;
+
+public class CommandAPIPluginFactory {
+ public static JavaPlugin create() {
+ return new JavaPlugin(null) {};
+ }
+}
\ No newline at end of file

0 comments on commit 1754df3

Please sign in to comment.