Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Test-Account666/PlugManX
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: firestarter/plugman
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on May 1, 2024

  1. fix: 1.20.6 support

    nkomarn committed May 1, 2024
    Copy the full SHA
    43bb118 View commit details
26 changes: 7 additions & 19 deletions src/main/java/com/rylinaux/plugman/util/BukkitCommandWrap.java
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
public class BukkitCommandWrap {
private Field bField;
private Method removeCommandMethod;
private String nmsVersion;
private Class minecraftServerClass;
private Method aMethod;
private Method getServerMethod;
@@ -24,19 +23,9 @@ public class BukkitCommandWrap {
private Method syncCommandsMethod;
private Constructor bukkitcommandWrapperConstructor;

public BukkitCommandWrap() {
try {
this.nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
this.nmsVersion = null;
}
}

public void wrap(Command command, String alias) {
if (this.nmsVersion == null) return;
if (this.minecraftServerClass == null) try {
this.minecraftServerClass = Class.forName("net.minecraft.server." + this.nmsVersion + ".MinecraftServer");
this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
} catch (ClassNotFoundException e) {
try {
this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
@@ -80,7 +69,7 @@ public void wrap(Command command, String alias) {
}

if (this.bField == null) try {
this.bField = Class.forName("net.minecraft.server." + this.nmsVersion + ".CommandDispatcher").getDeclaredField("b");
this.bField = Class.forName("net.minecraft.server.CommandDispatcher").getDeclaredField("b");
this.bField.setAccessible(true);
} catch (NoSuchFieldException | ClassNotFoundException e) {
if (this.bField == null) try {
@@ -115,7 +104,7 @@ public void wrap(Command command, String alias) {
}

if (this.bukkitcommandWrapperConstructor == null) try {
this.bukkitcommandWrapperConstructor = Class.forName("org.bukkit.craftbukkit." + this.nmsVersion + ".command.BukkitCommandWrapper").getDeclaredConstructor(Class.forName("org.bukkit.craftbukkit." + this.nmsVersion + ".CraftServer"), Command.class);
this.bukkitcommandWrapperConstructor = Class.forName("org.bukkit.craftbukkit.command.BukkitCommandWrapper").getDeclaredConstructor(Class.forName("org.bukkit.craftbukkit.CraftServer"), Command.class);
this.bukkitcommandWrapperConstructor.setAccessible(true);
} catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace();
@@ -141,7 +130,7 @@ public void wrap(Command command, String alias) {
}

if (this.registerMethod == null) try {
this.registerMethod = Class.forName("org.bukkit.craftbukkit." + this.nmsVersion + ".command.BukkitCommandWrapper").getMethod("register", com.mojang.brigadier.CommandDispatcher.class, String.class);
this.registerMethod = Class.forName("org.bukkit.craftbukkit.command.BukkitCommandWrapper").getMethod("register", com.mojang.brigadier.CommandDispatcher.class, String.class);
this.registerMethod.setAccessible(true);
} catch (NoSuchMethodException | ClassNotFoundException e) {
e.printStackTrace();
@@ -157,7 +146,7 @@ public void wrap(Command command, String alias) {

public void sync() {
if (this.syncCommandsMethod == null) try {
this.syncCommandsMethod = Class.forName("org.bukkit.craftbukkit." + this.nmsVersion + ".CraftServer").getDeclaredMethod("syncCommands");
this.syncCommandsMethod = Class.forName("org.bukkit.craftbukkit.CraftServer").getDeclaredMethod("syncCommands");
this.syncCommandsMethod.setAccessible(true);

if (Bukkit.getOnlinePlayers().size() >= 1)
@@ -176,9 +165,8 @@ public void sync() {
}

public void unwrap(String command) {
if (this.nmsVersion == null) return;
if (this.minecraftServerClass == null) try {
this.minecraftServerClass = Class.forName("net.minecraft.server." + this.nmsVersion + ".MinecraftServer");
this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
} catch (ClassNotFoundException e) {
try {
this.minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
@@ -222,7 +210,7 @@ public void unwrap(String command) {
}

if (this.bField == null) try {
this.bField = Class.forName("net.minecraft.server." + this.nmsVersion + ".CommandDispatcher").getDeclaredField("b");
this.bField = Class.forName("net.minecraft.server.CommandDispatcher").getDeclaredField("b");
this.bField.setAccessible(true);
} catch (NoSuchFieldException | ClassNotFoundException e) {
if (this.bField == null) try {
14 changes: 1 addition & 13 deletions src/main/java/com/rylinaux/plugman/util/BukkitPluginUtil.java
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ public class BukkitPluginUtil implements PluginUtil {
private final Field pluginClassLoaderPlugin;
private Field commandMapField;
private Field knownCommandsField;
private String nmsVersion = null;

{
try {
@@ -443,7 +442,7 @@ public String load(String name) {
@Override
public Map<String, Command> getKnownCommands() {
if (this.commandMapField == null) try {
this.commandMapField = Class.forName("org.bukkit.craftbukkit." + this.getNmsVersion() + ".CraftServer").getDeclaredField("commandMap");
this.commandMapField = Class.forName("org.bukkit.craftbukkit.CraftServer").getDeclaredField("commandMap");
this.commandMapField.setAccessible(true);
} catch (NoSuchFieldException | ClassNotFoundException e) {
e.printStackTrace();
@@ -477,17 +476,6 @@ public Map<String, Command> getKnownCommands() {
return knownCommands;
}

private String getNmsVersion() {
if (this.nmsVersion == null) try {
this.nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
this.nmsVersion = null;
}
return this.nmsVersion;
}


/**
* Reload a plugin.
*
14 changes: 1 addition & 13 deletions src/main/java/com/rylinaux/plugman/util/PaperPluginUtil.java
Original file line number Diff line number Diff line change
@@ -67,7 +67,6 @@ public class PaperPluginUtil implements PluginUtil {
private final BukkitPluginUtil bukkitPluginUtil;
private Field commandMapField;
private Field knownCommandsField;
private String nmsVersion = null;

{
try {
@@ -469,7 +468,7 @@ private void unloadCommands(Plugin target) {
@Override
public Map<String, Command> getKnownCommands() {
if (this.commandMapField == null) try {
this.commandMapField = Class.forName("org.bukkit.craftbukkit." + this.getNmsVersion() + ".CraftServer").getDeclaredField("commandMap");
this.commandMapField = Class.forName("org.bukkit.craftbukkit.CraftServer").getDeclaredField("commandMap");
this.commandMapField.setAccessible(true);
} catch (NoSuchFieldException | ClassNotFoundException e) {
e.printStackTrace();
@@ -503,17 +502,6 @@ public Map<String, Command> getKnownCommands() {
return knownCommands;
}

private String getNmsVersion() {
if (this.nmsVersion == null) try {
this.nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
this.nmsVersion = null;
}
return this.nmsVersion;
}


/**
* Reload a plugin.
*