избавляемся от рефлексии: скины для голов
This commit is contained in:
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 net.minecraft.server.v1_12_R1.WorldServer;
|
||||||
|
|
||||||
|
public class CraftWorld {
|
||||||
|
|
||||||
|
public WorldServer getHandle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
|
include 'phantom-classes'
|
||||||
include 'tools'
|
include 'tools'
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly project(':phantom-classes')
|
||||||
compileOnly libs.bukkit
|
compileOnly libs.bukkit
|
||||||
implementation libs.commons_text
|
implementation libs.commons_text
|
||||||
implementation libs.refobj
|
implementation libs.refobj
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package ghast;
|
package ghast;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
import lombok.experimental.UtilityClass;
|
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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.SkullType;
|
import org.bukkit.SkullType;
|
||||||
@@ -8,8 +12,7 @@ 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.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||||
import ru.dmitriymx.reflection.ReflectionObject;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@@ -19,9 +22,6 @@ import java.util.UUID;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class BuildHelper {
|
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>
|
* <p>
|
||||||
@@ -95,17 +95,10 @@ public class BuildHelper {
|
|||||||
* @param skinUrl URL на текстуру
|
* @param skinUrl URL на текстуру
|
||||||
*/
|
*/
|
||||||
public static void setPlayerHeadSkin(Skull skull, String skinUrl) {
|
public static void setPlayerHeadSkin(Skull skull, String skinUrl) {
|
||||||
//TODO заменить рефлексию на "фантомные" классы
|
((TileEntitySkull) (((CraftWorld) skull.getWorld())
|
||||||
ReflectionObject refobjBlockPosition = new ReflectionClass(CLASS_BLOCKPOSITION)
|
.getHandle()
|
||||||
.constructor(double.class, double.class, double.class)
|
.getTileEntity(new BlockPosition(skull.getX(), skull.getY(), skull.getZ()))))
|
||||||
.newInstance(skull.getX(), skull.getY(), skull.getZ());
|
.setGameProfile(generateTexturedPlayerProfile(skinUrl));
|
||||||
|
|
||||||
new ReflectionObject(skull.getWorld())
|
|
||||||
.method("getHandle").invoke()
|
|
||||||
.method("getTileEntity", CLASS_BLOCKPOSITION)
|
|
||||||
.invoke(refobjBlockPosition.getOriginalObject())
|
|
||||||
.method("setGameProfile", CLASS_GAMEPROFILE)
|
|
||||||
.invoke(getRefObjPlayerProfile(skinUrl).getOriginalObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sign placeSignWall(Location location, BlockFace face) {
|
public Sign placeSignWall(Location location, BlockFace face) {
|
||||||
@@ -119,29 +112,12 @@ public class BuildHelper {
|
|||||||
return sign;
|
return sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReflectionObject getRefObjPlayerProfile(String url){
|
private GameProfile generateTexturedPlayerProfile(String skinUrl) {
|
||||||
ReflectionObject refobjProperty = new ReflectionClass(
|
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
|
||||||
getClassForName("com.mojang.authlib.properties.Property"))
|
|
||||||
.constructor(String.class, String.class)
|
|
||||||
.newInstance("textures", Base64.getEncoder()
|
|
||||||
.encodeToString(("{textures:{SKIN:{url:\"" + url + "\"}}}").getBytes(StandardCharsets.UTF_8)));
|
|
||||||
|
|
||||||
ReflectionObject refobjGameProfile = new ReflectionClass(CLASS_GAMEPROFILE)
|
gameProfile.getProperties().put("textures",
|
||||||
.constructor(UUID.class, String.class)
|
new Property("textures", Base64.getEncoder().encodeToString(
|
||||||
.newInstance(UUID.randomUUID(), null);
|
("{textures:{SKIN:{url:\"" + skinUrl + "\"}}}").getBytes(StandardCharsets.UTF_8))));
|
||||||
refobjGameProfile
|
return gameProfile;
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user