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