Merge branch 'dev/joor' into rc/1.13
This commit is contained in:
@@ -32,7 +32,7 @@ dependencies {
|
||||
exclude(module: 'snakeyaml')
|
||||
}
|
||||
implementation('org.apache.commons:commons-text:1.9')
|
||||
implementation('ru.dmitriymx:reflection-object:1.2')
|
||||
implementation('org.jooq:joor-java-8:0.9.13')
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
|
||||
|
||||
@@ -8,13 +8,15 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.Skull;
|
||||
import ru.dmitriymx.reflection.ReflectionClass;
|
||||
import ru.dmitriymx.reflection.ReflectionObject;
|
||||
import org.joor.Reflect;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.joor.Reflect.on;
|
||||
import static org.joor.Reflect.onClass;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("unused")
|
||||
public class BuildHelper {
|
||||
@@ -96,16 +98,13 @@ public class BuildHelper {
|
||||
*/
|
||||
public static void setPlayerHeadSkin(Skull skull, String skinUrl) {
|
||||
//TODO заменить рефлексию на "фантомные" классы
|
||||
ReflectionObject refobjBlockPosition = new ReflectionClass(CLASS_BLOCKPOSITION)
|
||||
.constructor(double.class, double.class, double.class)
|
||||
.newInstance(skull.getX(), skull.getY(), skull.getZ());
|
||||
Reflect reflectBlockPosition = onClass(CLASS_BLOCKPOSITION)
|
||||
.create(skull.getX(), skull.getY(), skull.getZ());
|
||||
|
||||
new ReflectionObject(skull.getWorld())
|
||||
.method("getHandle").invoke()
|
||||
.method("getTileEntity", CLASS_BLOCKPOSITION)
|
||||
.invoke(refobjBlockPosition.getOriginalObject())
|
||||
.method("setGameProfile", CLASS_GAMEPROFILE)
|
||||
.invoke(getRefObjPlayerProfile(skinUrl).getOriginalObject());
|
||||
on(skull.getWorld())
|
||||
.call("getHandle")
|
||||
.call("getTileEntity", reflectBlockPosition.get())
|
||||
.call("setGameProfile", getReflectPlayerProfile(skinUrl).get());
|
||||
}
|
||||
|
||||
public Sign placeSignWall(Location location, BlockFace face) {
|
||||
@@ -119,22 +118,18 @@ public class BuildHelper {
|
||||
return sign;
|
||||
}
|
||||
|
||||
private ReflectionObject getRefObjPlayerProfile(String url){
|
||||
ReflectionObject refobjProperty = new ReflectionClass(
|
||||
getClassForName("com.mojang.authlib.properties.Property"))
|
||||
.constructor(String.class, String.class)
|
||||
.newInstance("textures", Base64.getEncoder()
|
||||
private Reflect getReflectPlayerProfile(String url) {
|
||||
Reflect reflectProperty = onClass("com.mojang.authlib.properties.Property")
|
||||
.create("textures", Base64.getEncoder()
|
||||
.encodeToString(("{textures:{SKIN:{url:\"" + url + "\"}}}").getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
ReflectionObject refobjGameProfile = new ReflectionClass(CLASS_GAMEPROFILE)
|
||||
.constructor(UUID.class, String.class)
|
||||
.newInstance(UUID.randomUUID(), null);
|
||||
refobjGameProfile
|
||||
.method("getProperties").invoke()
|
||||
.method("put", Object.class, Object.class)
|
||||
.invoke("textures", refobjProperty.getOriginalObject());
|
||||
Reflect reflectGameProfile = onClass(CLASS_GAMEPROFILE)
|
||||
.create(UUID.randomUUID(), null);
|
||||
|
||||
return refobjGameProfile;
|
||||
reflectGameProfile.call("getProperties")
|
||||
.call("put", "textures", reflectProperty.get());
|
||||
|
||||
return reflectGameProfile;
|
||||
}
|
||||
|
||||
private Class<?> getClassForName(String className) {
|
||||
|
||||
@@ -4,8 +4,8 @@ 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 static org.joor.Reflect.on;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("unused")
|
||||
@@ -60,12 +60,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)
|
||||
);
|
||||
on(Bukkit.getServer())
|
||||
.call("getCommandMap")
|
||||
.call("register", name, new CommandWrapper(name, this.onlyPlayer, this.deniedMessage,
|
||||
this.executer, this.errorConsumer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user