Compare commits
2 Commits
e02ccc2b60
...
c60fb613d4
Author | SHA1 | Date | |
---|---|---|---|
c60fb613d4 | |||
33e4e053cf |
@ -155,10 +155,11 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
* Gets the NBT data from the player-data file.
|
||||
* It will not work if the player is online, because the data on the file are not synchronized with real-time values.
|
||||
* @param convertTag true to convert the data to the current MC version, false to keep the saved version
|
||||
* @return the NBT data from the player-data file.
|
||||
* @return the NBT data from the player-data file, or null if the file does not exists.
|
||||
* @throws IllegalStateException if the player is online.
|
||||
* @throws IOException if an error occurs reading the data.
|
||||
*/
|
||||
default CompoundTag getPlayerData(boolean convertTag) {
|
||||
default CompoundTag getPlayerData(boolean convertTag) throws IOException {
|
||||
if (isOnline())
|
||||
throw new IllegalStateException("Cannot access data file of " + getName() + " because they’re online.");
|
||||
CompoundTag data = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
|
||||
@ -166,13 +167,13 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
.getPlayerList()
|
||||
.playerIo()
|
||||
.getPlayerData(getUniqueId().toString());
|
||||
if (convertTag) {
|
||||
if (data != null && convertTag) {
|
||||
int srcVersion = data.contains("DataVersion", Tag.TAG_ANY_NUMERIC()) ? data.getInt("DataVersion") : -1;
|
||||
int destVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
||||
try {
|
||||
data = MCDataConverter.convertTag(MCTypeRegistry.PLAYER(), data, srcVersion, destVersion);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to upgrade data format of player " + getName() + " (" + getUniqueId() + ") from version " + destVersion + " to " + destVersion);
|
||||
throw new IOException("Unable to upgrade data format of player " + getName() + " (" + getUniqueId() + ") from version " + destVersion + " to " + destVersion);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
@ -183,8 +184,9 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
* It will not work if the player is online, because the data on the file are not synchronized with real-time values.
|
||||
* @return the NBT data from the player-data file.
|
||||
* @throws IllegalStateException if the player is online.
|
||||
* @throws IOException if an error occurs reading the data.
|
||||
*/
|
||||
default PlayerDataWrapper getPlayerDataWrapper() {
|
||||
default PlayerDataWrapper getPlayerDataWrapper() throws IOException {
|
||||
return new PlayerDataWrapper(getPlayerData(true));
|
||||
}
|
||||
|
||||
@ -218,16 +220,18 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
|
||||
/**
|
||||
* Gets the player’s inventory.
|
||||
* @return the player’s inventory.
|
||||
* @throws IOException if an error occurs reading the data.
|
||||
*/
|
||||
default PlayerInventory getInventory() {
|
||||
default PlayerInventory getInventory() throws IOException {
|
||||
return getPlayerDataWrapper().getInventory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player’s enderchest.
|
||||
* @return the player’s enderchest.
|
||||
* @throws IOException if an error occurs reading the data.
|
||||
*/
|
||||
default Inventory getEnderChest() {
|
||||
default Inventory getEnderChest() throws IOException {
|
||||
return getPlayerDataWrapper().getEnderChest();
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
|
||||
String classToPrint = type;
|
||||
String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1);
|
||||
String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'");
|
||||
if (!htmlTitle.equals("")) {
|
||||
if (!htmlTitle.isEmpty()) {
|
||||
typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>";
|
||||
}
|
||||
else {
|
||||
|
@ -3,6 +3,7 @@ package fr.pandacube.lib.paper.reflect;
|
||||
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.CraftMetaItem;
|
||||
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.CraftServer;
|
||||
@ -111,6 +112,7 @@ public class PandalibPaperReflect {
|
||||
// craftbukkit
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftMapView.class, CraftMapView.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftMetaItem.class, CraftMetaItem.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get()));
|
||||
thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get()));
|
||||
|
@ -0,0 +1,28 @@
|
||||
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
|
||||
|
||||
import fr.pandacube.lib.paper.reflect.OBCReflect;
|
||||
import fr.pandacube.lib.reflect.ReflectClass;
|
||||
import fr.pandacube.lib.reflect.ReflectField;
|
||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperTyped;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||
|
||||
public class CraftMetaItem extends ReflectWrapperTyped<ItemMeta> {
|
||||
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("inventory.CraftMetaItem"));
|
||||
public static final ReflectField<?> displayName = wrapEx(() -> REFLECT.field("displayName"));
|
||||
|
||||
public String getRawDisplayName() {
|
||||
return (String) wrapReflectEx(() -> displayName.getValue(__getRuntimeInstance()));
|
||||
}
|
||||
|
||||
public void setRawDisplayName(String rawDisplayName) {
|
||||
wrapReflectEx(() -> displayName.setValue(__getRuntimeInstance(), rawDisplayName));
|
||||
}
|
||||
|
||||
|
||||
protected CraftMetaItem(Object obj) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user