Access offline players inventory and enderchest.
Also added various reflection wrapper API
This commit is contained in:
parent
a36b8ec1f2
commit
1557de2bdf
@ -1,12 +1,18 @@
|
|||||||
package fr.pandacube.lib.paper.players;
|
package fr.pandacube.lib.paper.players;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftItemStack;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.ListTag;
|
||||||
|
import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
|
|
||||||
import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
|
|
||||||
|
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,4 +135,68 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
|||||||
PaperPlayerConfigStorage.unset(getUniqueId(), key);
|
PaperPlayerConfigStorage.unset(getUniqueId(), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Player data
|
||||||
|
*/
|
||||||
|
|
||||||
|
default CompoundTag getPlayerData() {
|
||||||
|
return ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
|
||||||
|
.getServer()
|
||||||
|
.getPlayerList()
|
||||||
|
.playerIo()
|
||||||
|
.getPlayerData(getUniqueId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
default ItemStack[] getInventoryContent() {
|
||||||
|
ItemStack[] content = new ItemStack[InventoryType.PLAYER.getDefaultSize()];
|
||||||
|
CompoundTag playerData = getPlayerData();
|
||||||
|
if (playerData == null)
|
||||||
|
return content;
|
||||||
|
ListTag nbttaglist = playerData.getList("Inventory", 10); // type of list element 10 is CompoundTag
|
||||||
|
if (nbttaglist == null)
|
||||||
|
return content;
|
||||||
|
// cat nbEl NBTslot bukkitSlot NBT->Bukkit
|
||||||
|
// items 36el 0-35 ==
|
||||||
|
// armor 4el start 100 36-39 -100 + 36
|
||||||
|
// offhnd 1el start 150 40 -150 + 40
|
||||||
|
for (int i = 0; i < nbttaglist.size(); i++) {
|
||||||
|
CompoundTag itemTag = nbttaglist.getCompound(i);
|
||||||
|
ItemStack is = CraftItemStack.asCraftMirror(itemTag);
|
||||||
|
if (is != null && !is.getType().isAir()) {
|
||||||
|
int nbtSlot = itemTag.getByte("Slot") & 255;
|
||||||
|
int bukkitSlot = nbtSlot < 36 ? nbtSlot
|
||||||
|
: (nbtSlot >= 100 && nbtSlot < 104) ? nbtSlot - 100 + 36
|
||||||
|
: nbtSlot == 150 ? 40
|
||||||
|
: -1;
|
||||||
|
if (bukkitSlot >= 0)
|
||||||
|
content[bukkitSlot] = is;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
default ItemStack[] getEnderchestContent() {
|
||||||
|
ItemStack[] content = new ItemStack[InventoryType.ENDER_CHEST.getDefaultSize()];
|
||||||
|
CompoundTag playerData = getPlayerData();
|
||||||
|
if (playerData == null || !playerData.contains("EnderItems", 9)) // type 9 is list
|
||||||
|
return content;
|
||||||
|
ListTag nbtList = playerData.getList("EnderItems", 10); // type of list element 10 is CompoundTag
|
||||||
|
if (nbtList == null)
|
||||||
|
return content;
|
||||||
|
for (int i = 0; i < nbtList.size(); i++) {
|
||||||
|
CompoundTag itemTag = nbtList.getCompound(i);
|
||||||
|
int nbtSlot = itemTag.getByte("Slot") & 255;
|
||||||
|
ItemStack is = CraftItemStack.asCraftMirror(itemTag);
|
||||||
|
if (nbtSlot < content.length && is != null && !is.getType().isAir()) {
|
||||||
|
content[nbtSlot] = CraftItemStack.asCraftMirror(itemTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,10 @@ import com.destroystokyo.paper.ClientOption;
|
|||||||
import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
||||||
import com.destroystokyo.paper.SkinParts;
|
import com.destroystokyo.paper.SkinParts;
|
||||||
import fr.pandacube.lib.paper.players.PlayerNonPersistentConfig.Expiration;
|
import fr.pandacube.lib.paper.players.PlayerNonPersistentConfig.Expiration;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
import net.kyori.adventure.audience.MessageType;
|
import net.kyori.adventure.audience.MessageType;
|
||||||
import net.kyori.adventure.identity.Identified;
|
import net.kyori.adventure.identity.Identified;
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
@ -17,6 +20,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MainHand;
|
import org.bukkit.inventory.MainHand;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -53,6 +57,14 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, AbstractOnlinePlayer
|
|||||||
return getBukkitPlayer();
|
return getBukkitPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the OBC.CraftPlayer instance wrapped into the {@link CraftPlayer} reflection wrapper.
|
||||||
|
* @return the OBC.CraftPlayer instance wrapped into the {@link CraftPlayer} reflection wrapper.
|
||||||
|
*/
|
||||||
|
default CraftPlayer getWrappedCraftPlayer() {
|
||||||
|
return ReflectWrapper.wrapTyped(getBukkitPlayer(), CraftPlayer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -305,4 +317,28 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, AbstractOnlinePlayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Player data
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default CompoundTag getPlayerData() {
|
||||||
|
CompoundTag tag = new CompoundTag();
|
||||||
|
getWrappedCraftPlayer().getHandle().serializeEntity(tag);
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default ItemStack[] getInventoryContent() {
|
||||||
|
return getBukkitPlayer().getInventory().getContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default ItemStack[] getEnderchestContent() {
|
||||||
|
return getBukkitPlayer().getEnderChest().getContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.pandacube.lib.paper.reflect;
|
package fr.pandacube.lib.paper.reflect;
|
||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode;
|
import fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftItemStack;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMapView;
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMapView;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey;
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer;
|
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer;
|
||||||
@ -24,7 +25,9 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.ResourceLocatio
|
|||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Vec3Argument;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Vec3Argument;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.BlockPos;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.Vec3i;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.core.Vec3i;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CollectionTag;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.ListTag;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.NbtIo;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.NbtIo;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.StringTag;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.StringTag;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.Tag;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.Tag;
|
||||||
@ -39,6 +42,7 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedPlayerLi
|
|||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServer;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServer;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServerProperties;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.DedicatedServerProperties;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.MinecraftServer;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.MinecraftServer;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.PlayerList;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerChunkCache;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerChunkCache;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerGamePacketListenerImpl;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerGamePacketListenerImpl;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerLevel;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.server.ServerLevel;
|
||||||
@ -50,8 +54,10 @@ import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkPos;
|
|||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkStorage;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ChunkStorage;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.DamageSource;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Entity;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Level;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.PlayerDataStorage;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.SavedData;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.SavedData;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.Vec3;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.VoxelShape;
|
||||||
@ -91,6 +97,7 @@ public class PandalibPaperReflect {
|
|||||||
initWrapper(CommandNode.class, CommandNode.REFLECT.get());
|
initWrapper(CommandNode.class, CommandNode.REFLECT.get());
|
||||||
|
|
||||||
// craftbukkit
|
// craftbukkit
|
||||||
|
initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get());
|
||||||
initWrapper(CraftMapView.class, CraftMapView.REFLECT.get());
|
initWrapper(CraftMapView.class, CraftMapView.REFLECT.get());
|
||||||
initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get());
|
initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get());
|
||||||
initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get());
|
initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get());
|
||||||
@ -115,7 +122,9 @@ public class PandalibPaperReflect {
|
|||||||
initWrapper(BlockPos.class, BlockPos.MAPPING.runtimeClass());
|
initWrapper(BlockPos.class, BlockPos.MAPPING.runtimeClass());
|
||||||
initWrapper(Vec3i.class, Vec3i.MAPPING.runtimeClass());
|
initWrapper(Vec3i.class, Vec3i.MAPPING.runtimeClass());
|
||||||
// minecraft.nbt
|
// minecraft.nbt
|
||||||
|
initWrapper(CollectionTag.class, CollectionTag.MAPPING.runtimeClass());
|
||||||
initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass());
|
initWrapper(CompoundTag.class, CompoundTag.MAPPING.runtimeClass());
|
||||||
|
initWrapper(ListTag.class, ListTag.MAPPING.runtimeClass());
|
||||||
initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass());
|
initWrapper(NbtIo.class, NbtIo.MAPPING.runtimeClass());
|
||||||
initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass());
|
initWrapper(StringTag.class, StringTag.MAPPING.runtimeClass());
|
||||||
initWrapper(Tag.class, Tag.MAPPING.runtimeClass());
|
initWrapper(Tag.class, Tag.MAPPING.runtimeClass());
|
||||||
@ -136,6 +145,7 @@ public class PandalibPaperReflect {
|
|||||||
initWrapper(DedicatedServer.class, DedicatedServer.MAPPING.runtimeClass());
|
initWrapper(DedicatedServer.class, DedicatedServer.MAPPING.runtimeClass());
|
||||||
initWrapper(DedicatedServerProperties.class, DedicatedServerProperties.MAPPING.runtimeClass());
|
initWrapper(DedicatedServerProperties.class, DedicatedServerProperties.MAPPING.runtimeClass());
|
||||||
initWrapper(MinecraftServer.class, MinecraftServer.MAPPING.runtimeClass());
|
initWrapper(MinecraftServer.class, MinecraftServer.MAPPING.runtimeClass());
|
||||||
|
initWrapper(PlayerList.class, PlayerList.MAPPING.runtimeClass());
|
||||||
initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass());
|
initWrapper(ServerChunkCache.class, ServerChunkCache.MAPPING.runtimeClass());
|
||||||
initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass());
|
initWrapper(ServerGamePacketListenerImpl.class, ServerGamePacketListenerImpl.MAPPING.runtimeClass());
|
||||||
initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass());
|
initWrapper(ServerLevel.class, ServerLevel.MAPPING.runtimeClass());
|
||||||
@ -151,8 +161,10 @@ public class PandalibPaperReflect {
|
|||||||
initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass());
|
initWrapper(ChunkStorage.class, ChunkStorage.MAPPING.runtimeClass());
|
||||||
initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass());
|
initWrapper(DamageSource.class, DamageSource.MAPPING.runtimeClass());
|
||||||
initWrapper(Entity.class, Entity.MAPPING.runtimeClass());
|
initWrapper(Entity.class, Entity.MAPPING.runtimeClass());
|
||||||
|
initWrapper(ItemStack.class, ItemStack.MAPPING.runtimeClass());
|
||||||
initWrapper(Level.class, Level.MAPPING.runtimeClass());
|
initWrapper(Level.class, Level.MAPPING.runtimeClass());
|
||||||
initWrapper(MapItemSavedData.class, MapItemSavedData.MAPPING.runtimeClass());
|
initWrapper(MapItemSavedData.class, MapItemSavedData.MAPPING.runtimeClass());
|
||||||
|
initWrapper(PlayerDataStorage.class, PlayerDataStorage.MAPPING.runtimeClass());
|
||||||
initWrapper(SavedData.class, SavedData.MAPPING.runtimeClass());
|
initWrapper(SavedData.class, SavedData.MAPPING.runtimeClass());
|
||||||
initWrapper(Vec3.class, Vec3.MAPPING.runtimeClass());
|
initWrapper(Vec3.class, Vec3.MAPPING.runtimeClass());
|
||||||
initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass());
|
initWrapper(VoxelShape.class, VoxelShape.MAPPING.runtimeClass());
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.OBCReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.MapItemSavedData;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectClass;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectField;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperTyped;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.map.MapView;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
public class CraftItemStack extends ReflectWrapperTyped<ItemStack> {
|
||||||
|
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("inventory.CraftItemStack"));
|
||||||
|
public static final ReflectMethod<?> asCraftMirror = wrapEx(() -> REFLECT.method("asCraftMirror", fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack.MAPPING.runtimeClass()));
|
||||||
|
|
||||||
|
public static ItemStack asCraftMirror(fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack original) {
|
||||||
|
return (ItemStack) wrapReflectEx(() -> asCraftMirror.invokeStatic(unwrap(original)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ItemStack asCraftMirror(CompoundTag nbt) {
|
||||||
|
return asCraftMirror(fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.ItemStack.of(nbt));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected CraftItemStack(Object obj) {
|
||||||
|
super(obj);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperTyped;
|
||||||
|
|
||||||
|
import java.util.AbstractList;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
|
||||||
|
public class CollectionTag extends ReflectWrapperTyped<AbstractList<?>> implements Tag {
|
||||||
|
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.CollectionTag"));
|
||||||
|
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return __getRuntimeInstance().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CollectionTag(Object nms) {
|
||||||
|
super(nms);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.reflect.ReflectConstructor;
|
||||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||||
@ -15,6 +16,7 @@ import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
|||||||
|
|
||||||
public class CompoundTag extends ReflectWrapper implements Tag {
|
public class CompoundTag extends ReflectWrapper implements Tag {
|
||||||
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.CompoundTag"));
|
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.CompoundTag"));
|
||||||
|
public static final ReflectConstructor<?> CONSTRUCTOR = wrapEx(() -> MAPPING.runtimeReflect().constructor());
|
||||||
private static final ReflectMethod<?> putBoolean = wrapEx(() -> MAPPING.mojMethod("putBoolean", String.class, boolean.class));
|
private static final ReflectMethod<?> putBoolean = wrapEx(() -> MAPPING.mojMethod("putBoolean", String.class, boolean.class));
|
||||||
private static final ReflectMethod<?> putByte = wrapEx(() -> MAPPING.mojMethod("putByte", String.class, byte.class));
|
private static final ReflectMethod<?> putByte = wrapEx(() -> MAPPING.mojMethod("putByte", String.class, byte.class));
|
||||||
private static final ReflectMethod<?> putByteArray = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, byte[].class));
|
private static final ReflectMethod<?> putByteArray = wrapEx(() -> MAPPING.mojMethod("putByteArray", String.class, byte[].class));
|
||||||
@ -45,14 +47,20 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
private static final ReflectMethod<?> getLongArray = wrapEx(() -> MAPPING.mojMethod("getLongArray", String.class));
|
private static final ReflectMethod<?> getLongArray = wrapEx(() -> MAPPING.mojMethod("getLongArray", String.class));
|
||||||
private static final ReflectMethod<?> getCompound = wrapEx(() -> MAPPING.mojMethod("getCompound", String.class));
|
private static final ReflectMethod<?> getCompound = wrapEx(() -> MAPPING.mojMethod("getCompound", String.class));
|
||||||
private static final ReflectMethod<?> getBoolean = wrapEx(() -> MAPPING.mojMethod("getBoolean", String.class));
|
private static final ReflectMethod<?> getBoolean = wrapEx(() -> MAPPING.mojMethod("getBoolean", String.class));
|
||||||
|
private static final ReflectMethod<?> getList = wrapEx(() -> MAPPING.mojMethod("getList", String.class, int.class));
|
||||||
|
|
||||||
private static final ReflectMethod<?> get = wrapEx(() -> MAPPING.mojMethod("get", String.class));
|
private static final ReflectMethod<?> get = wrapEx(() -> MAPPING.mojMethod("get", String.class));
|
||||||
private static final ReflectMethod<?> getAllKeys = wrapEx(() -> MAPPING.mojMethod("getAllKeys"));
|
private static final ReflectMethod<?> getAllKeys = wrapEx(() -> MAPPING.mojMethod("getAllKeys"));
|
||||||
private static final ReflectMethod<?> entries = wrapEx(() -> MAPPING.mojMethod("entries"));
|
private static final ReflectMethod<?> entries = wrapEx(() -> MAPPING.mojMethod("entries"));
|
||||||
private static final ReflectMethod<?> size = wrapEx(() -> MAPPING.mojMethod("size"));
|
private static final ReflectMethod<?> size = wrapEx(() -> MAPPING.mojMethod("size"));
|
||||||
private static final ReflectMethod<?> contains = wrapEx(() -> MAPPING.mojMethod("contains", String.class));
|
private static final ReflectMethod<?> contains = wrapEx(() -> MAPPING.mojMethod("contains", String.class));
|
||||||
|
private static final ReflectMethod<?> containsStringInt = wrapEx(() -> MAPPING.mojMethod("contains", String.class, int.class));
|
||||||
|
|
||||||
public CompoundTag(Object nms) {
|
public CompoundTag() {
|
||||||
|
this(wrapReflectEx(() -> CONSTRUCTOR.instanciate()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CompoundTag(Object nms) {
|
||||||
super(nms);
|
super(nms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +151,9 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
public boolean getBoolean(String key) {
|
public boolean getBoolean(String key) {
|
||||||
return (boolean) wrapReflectEx(() -> getBoolean.invoke(__getRuntimeInstance(), key));
|
return (boolean) wrapReflectEx(() -> getBoolean.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
|
public ListTag getList(String key, int type) {
|
||||||
|
return wrap(wrapReflectEx(() -> getList.invoke(__getRuntimeInstance(), key, type)), ListTag.class);
|
||||||
|
}
|
||||||
public Tag get(String key) {
|
public Tag get(String key) {
|
||||||
return wrap(wrapReflectEx(() -> get.invoke(__getRuntimeInstance(), key)), Tag.class);
|
return wrap(wrapReflectEx(() -> get.invoke(__getRuntimeInstance(), key)), Tag.class);
|
||||||
}
|
}
|
||||||
@ -165,5 +176,8 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
public boolean contains(String key) {
|
public boolean contains(String key) {
|
||||||
return (boolean) wrapReflectEx(() -> contains.invoke(__getRuntimeInstance(), key));
|
return (boolean) wrapReflectEx(() -> contains.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
|
public boolean contains(String key, int type) {
|
||||||
|
return (boolean) wrapReflectEx(() -> containsStringInt.invoke(__getRuntimeInstance(), key, type));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
public class ListTag extends CollectionTag {
|
||||||
|
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.ListTag"));
|
||||||
|
private static final ReflectMethod<?> getCompound = wrapEx(() -> MAPPING.mojMethod("getCompound", int.class));
|
||||||
|
|
||||||
|
public CompoundTag getCompound(int index) {
|
||||||
|
return wrap(wrapReflectEx(() -> getCompound.invoke(__getRuntimeInstance(), index)), CompoundTag.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ListTag(Object nms) {
|
||||||
|
super(nms);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,8 +21,9 @@ public class NbtIo extends ReflectWrapper {
|
|||||||
|
|
||||||
|
|
||||||
public static CompoundTag readCompressed(File f) {
|
public static CompoundTag readCompressed(File f) {
|
||||||
return new CompoundTag(wrapEx(() -> readCompressed.invokeStatic(f)));
|
return wrap(wrapEx(() -> readCompressed.invokeStatic(f)), CompoundTag.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeCompressed(CompoundTag tag, File f) {
|
public static void writeCompressed(CompoundTag tag, File f) {
|
||||||
Object nmsTag = ReflectWrapper.unwrap(tag);
|
Object nmsTag = ReflectWrapper.unwrap(tag);
|
||||||
wrapEx(() -> writeCompressed.invokeStatic(nmsTag, f));
|
wrapEx(() -> writeCompressed.invokeStatic(nmsTag, f));
|
||||||
|
@ -10,7 +10,7 @@ public class StringTag extends ReflectWrapper implements Tag {
|
|||||||
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.StringTag"));
|
public static final ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.nbt.StringTag"));
|
||||||
|
|
||||||
|
|
||||||
public StringTag(Object nms) {
|
protected StringTag(Object nms) {
|
||||||
super(nms);
|
super(nms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
|||||||
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
|
||||||
public class DedicatedPlayerList extends ReflectWrapper {
|
public class DedicatedPlayerList extends PlayerList {
|
||||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedPlayerList"));
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.dedicated.DedicatedPlayerList"));
|
||||||
|
|
||||||
protected DedicatedPlayerList(Object obj) {
|
protected DedicatedPlayerList(Object obj) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
|
||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Commands;
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.commands.Commands;
|
||||||
import fr.pandacube.lib.reflect.ReflectField;
|
import fr.pandacube.lib.reflect.ReflectField;
|
||||||
@ -11,11 +12,16 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
|||||||
public class MinecraftServer extends ReflectWrapper {
|
public class MinecraftServer extends ReflectWrapper {
|
||||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.MinecraftServer"));
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.MinecraftServer"));
|
||||||
private static final ReflectField<?> vanillaCommandDispatcher = wrapEx(() -> MAPPING.runtimeReflect().field("vanillaCommandDispatcher"));
|
private static final ReflectField<?> vanillaCommandDispatcher = wrapEx(() -> MAPPING.runtimeReflect().field("vanillaCommandDispatcher"));
|
||||||
|
private static final ReflectMethod<?> getPlayerList = wrapEx(() -> MAPPING.mojMethod("getPlayerList"));
|
||||||
|
|
||||||
public Commands vanillaCommandDispatcher() {
|
public Commands vanillaCommandDispatcher() {
|
||||||
return wrap(wrapReflectEx(() -> vanillaCommandDispatcher.getValue(__getRuntimeInstance())), Commands.class);
|
return wrap(wrapReflectEx(() -> vanillaCommandDispatcher.getValue(__getRuntimeInstance())), Commands.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerList getPlayerList() {
|
||||||
|
return wrap(wrapReflectEx(() -> getPlayerList.invoke(__getRuntimeInstance())), PlayerList.class);
|
||||||
|
}
|
||||||
|
|
||||||
protected MinecraftServer(Object obj) {
|
protected MinecraftServer(Object obj) {
|
||||||
super(obj);
|
super(obj);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.server;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.PlayerDataStorage;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectField;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
public class PlayerList extends ReflectWrapper {
|
||||||
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.server.players.PlayerList"));
|
||||||
|
private static final ReflectField<?> playerIo = wrapEx(() -> MAPPING.mojField("playerIo"));
|
||||||
|
|
||||||
|
public PlayerDataStorage playerIo() {
|
||||||
|
return wrap(wrapReflectEx(() -> playerIo.getValue(__getRuntimeInstance())), PlayerDataStorage.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PlayerList(Object obj) {
|
||||||
|
super(obj);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||||
|
|
||||||
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
import fr.pandacube.lib.reflect.ReflectMethod;
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
|
||||||
@ -9,12 +10,17 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
|||||||
|
|
||||||
public class Entity extends ReflectWrapper {
|
public class Entity extends ReflectWrapper {
|
||||||
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.entity.Entity"));
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.entity.Entity"));
|
||||||
public static final ReflectMethod<?> getBukkitEntity = wrapEx(() -> MAPPING.runtimeReflect().method("getBukkitEntity")); // spigot field
|
public static final ReflectMethod<?> getBukkitEntity = wrapEx(() -> MAPPING.runtimeReflect().method("getBukkitEntity")); // spigot method
|
||||||
|
public static final ReflectMethod<?> serializeEntity = wrapEx(() -> MAPPING.runtimeReflect().method("serializeEntity", CompoundTag.MAPPING.runtimeClass())); // paper method
|
||||||
|
|
||||||
public org.bukkit.entity.Entity getBukkitEntity() {
|
public org.bukkit.entity.Entity getBukkitEntity() {
|
||||||
return (org.bukkit.entity.Entity) wrapReflectEx(() -> getBukkitEntity.invoke(__getRuntimeInstance()));
|
return (org.bukkit.entity.Entity) wrapReflectEx(() -> getBukkitEntity.invoke(__getRuntimeInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean serializeEntity(CompoundTag nbt) {
|
||||||
|
return wrapReflectEx(() -> (Boolean) serializeEntity.invoke(__getRuntimeInstance(), unwrap(nbt)));
|
||||||
|
}
|
||||||
|
|
||||||
protected Entity(Object obj) {
|
protected Entity(Object obj) {
|
||||||
super(obj);
|
super(obj);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectConstructor;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
public class ItemStack extends ReflectWrapper {
|
||||||
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.item.ItemStack"));
|
||||||
|
private static final ReflectMethod<?> of = wrapEx(() -> MAPPING.mojMethod("of", CompoundTag.class));
|
||||||
|
|
||||||
|
public static ItemStack of(CompoundTag nbt) {
|
||||||
|
return wrap(wrapReflectEx(() -> of.invokeStatic(unwrap(nbt))), ItemStack.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ItemStack(Object obj) {
|
||||||
|
super(obj);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package fr.pandacube.lib.paper.reflect.wrapper.minecraft.world;
|
||||||
|
|
||||||
|
import fr.pandacube.lib.paper.reflect.NMSReflect;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.nbt.CompoundTag;
|
||||||
|
import fr.pandacube.lib.paper.reflect.wrapper.paper.configuration.WorldConfiguration;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectField;
|
||||||
|
import fr.pandacube.lib.reflect.ReflectMethod;
|
||||||
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
|
|
||||||
|
public class PlayerDataStorage extends ReflectWrapper {
|
||||||
|
public static final NMSReflect.ClassMapping MAPPING = wrapEx(() -> NMSReflect.mojClass("net.minecraft.world.level.storage.PlayerDataStorage"));
|
||||||
|
public static final ReflectMethod<?> getPlayerData = wrapEx(() -> MAPPING.runtimeReflect().method("getPlayerData", String.class)); // Craftbukkit method
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param playerId UUID of a player as it is used to name the player data file (UUID.toString())
|
||||||
|
*/
|
||||||
|
public CompoundTag getPlayerData(String playerId) {
|
||||||
|
return wrap(wrapReflectEx(() -> getPlayerData.invoke(__getRuntimeInstance(), playerId)), CompoundTag.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected PlayerDataStorage(Object obj) {
|
||||||
|
super(obj);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user