0

избавляемся от рефлексии: CommnadManager: register

This commit is contained in:
2021-01-08 20:00:20 +03:00
parent d686f56b0c
commit f2ab5521d1
4 changed files with 15 additions and 11 deletions

View File

@@ -5,7 +5,6 @@ class LibsExtention {
final def commons_text = 'org.apache.commons:commons-text:1.9'
final def lombok = 'org.projectlombok:lombok:1.18.12'
final def refobj = 'ru.dmitriymx:reflection-object:1.2'
final def bukkit = filter([
lib : 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT',

View File

@@ -0,0 +1,10 @@
package org.bukkit.craftbukkit.v1_12_R1;
import org.bukkit.command.SimpleCommandMap;
public class CraftServer {
public SimpleCommandMap getCommandMap() {
return null;
}
}

View File

@@ -7,7 +7,6 @@ dependencies {
compileOnly project(':phantom-classes')
compileOnly libs.bukkit
implementation libs.commons_text
implementation libs.refobj
testImplementation libs.bukkit
testImplementation libs.test.h2db

View File

@@ -4,8 +4,7 @@ import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import ru.dmitriymx.reflection.ReflectionObject;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
@UtilityClass
@SuppressWarnings("unused")
@@ -59,13 +58,10 @@ public class CommandManager {
}
public void register() {
//TODO для Paper такие "извращения" не требуются. Нужно продумать.
new ReflectionObject(Bukkit.getServer())
.method("getCommandMap").invoke()
.method("register", String.class, Command.class).invoke(
name, new CommandWrapper(name, this.onlyPlayer, this.deniedMessage,
this.executer, this.errorConsumer)
);
((CraftServer) Bukkit.getServer()).getCommandMap().register(
name,
new CommandWrapper(name, this.onlyPlayer, this.deniedMessage, this.executer, this.errorConsumer)
);
}
}
}