Merge branch 'feature/phantom-classes' into dev/modules
This commit is contained in:
@@ -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',
|
||||
|
||||
3
phantom-classes/build.gradle
Normal file
3
phantom-classes/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly libs.bukkit
|
||||
}
|
||||
2
phantom-classes/gradle.properties
Normal file
2
phantom-classes/gradle.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
moduleName=phantom-classes
|
||||
moduleVersion=1.0-SNAPSHOT
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mojang.authlib;
|
||||
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameProfile {
|
||||
|
||||
public GameProfile(UUID id, String name) {
|
||||
|
||||
}
|
||||
|
||||
public PropertyMap getProperties() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.mojang.authlib.properties;
|
||||
|
||||
public class Property {
|
||||
|
||||
public Property(String value, String name) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.mojang.authlib.properties;
|
||||
|
||||
import com.google.common.collect.ForwardingMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
public class PropertyMap extends ForwardingMultimap<String, Property> {
|
||||
|
||||
@Override
|
||||
protected Multimap<String, Property> delegate() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class BlockPosition {
|
||||
|
||||
public BlockPosition(double x, double y, double z) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class TileEntity {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public class TileEntitySkull extends TileEntity {
|
||||
|
||||
public void setGameProfile(GameProfile gameprofile) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.minecraft.server.v1_12_R1;
|
||||
|
||||
public class WorldServer {
|
||||
|
||||
public TileEntity getTileEntity(BlockPosition pos) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.bukkit.craftbukkit.v1_12_R1;
|
||||
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
|
||||
public class CraftServer {
|
||||
|
||||
public SimpleCommandMap getCommandMap() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.bukkit.craftbukkit.v1_12_R1;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
|
||||
public class CraftWorld {
|
||||
|
||||
public WorldServer getHandle() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
include 'phantom-classes'
|
||||
include 'tools'
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':phantom-classes')
|
||||
compileOnly libs.bukkit
|
||||
implementation libs.commons_text
|
||||
implementation libs.refobj
|
||||
|
||||
testImplementation libs.bukkit
|
||||
testImplementation libs.test.h2db
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package ghast;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.TileEntitySkull;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
@@ -8,8 +12,7 @@ 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.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
@@ -19,9 +22,6 @@ import java.util.UUID;
|
||||
@SuppressWarnings("unused")
|
||||
public class BuildHelper {
|
||||
|
||||
private final Class<?> CLASS_BLOCKPOSITION = getClassForName("net.minecraft.server.v1_12_R1.BlockPosition");
|
||||
private final Class<?> CLASS_GAMEPROFILE = getClassForName("com.mojang.authlib.GameProfile");
|
||||
|
||||
/**
|
||||
* Установка черепа.
|
||||
* <p>
|
||||
@@ -95,17 +95,10 @@ public class BuildHelper {
|
||||
* @param skinUrl URL на текстуру
|
||||
*/
|
||||
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());
|
||||
|
||||
new ReflectionObject(skull.getWorld())
|
||||
.method("getHandle").invoke()
|
||||
.method("getTileEntity", CLASS_BLOCKPOSITION)
|
||||
.invoke(refobjBlockPosition.getOriginalObject())
|
||||
.method("setGameProfile", CLASS_GAMEPROFILE)
|
||||
.invoke(getRefObjPlayerProfile(skinUrl).getOriginalObject());
|
||||
((TileEntitySkull) (((CraftWorld) skull.getWorld())
|
||||
.getHandle()
|
||||
.getTileEntity(new BlockPosition(skull.getX(), skull.getY(), skull.getZ()))))
|
||||
.setGameProfile(generateTexturedPlayerProfile(skinUrl));
|
||||
}
|
||||
|
||||
public Sign placeSignWall(Location location, BlockFace face) {
|
||||
@@ -119,29 +112,12 @@ 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()
|
||||
.encodeToString(("{textures:{SKIN:{url:\"" + url + "\"}}}").getBytes(StandardCharsets.UTF_8)));
|
||||
private GameProfile generateTexturedPlayerProfile(String skinUrl) {
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
|
||||
|
||||
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());
|
||||
|
||||
return refobjGameProfile;
|
||||
}
|
||||
|
||||
private Class<?> getClassForName(String className) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
gameProfile.getProperties().put("textures",
|
||||
new Property("textures", Base64.getEncoder().encodeToString(
|
||||
("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes(StandardCharsets.UTF_8))));
|
||||
return gameProfile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user