Compare commits

..

2 Commits

4 changed files with 42 additions and 8 deletions

View File

@ -155,10 +155,11 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
* Gets the NBT data from the player-data file. * 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. * 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 * @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 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()) if (isOnline())
throw new IllegalStateException("Cannot access data file of " + getName() + " because theyre online."); throw new IllegalStateException("Cannot access data file of " + getName() + " because theyre online.");
CompoundTag data = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class) CompoundTag data = ReflectWrapper.wrapTyped(Bukkit.getServer(), CraftServer.class)
@ -166,13 +167,13 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
.getPlayerList() .getPlayerList()
.playerIo() .playerIo()
.getPlayerData(getUniqueId().toString()); .getPlayerData(getUniqueId().toString());
if (convertTag) { if (data != null && convertTag) {
int srcVersion = data.contains("DataVersion", Tag.TAG_ANY_NUMERIC()) ? data.getInt("DataVersion") : -1; int srcVersion = data.contains("DataVersion", Tag.TAG_ANY_NUMERIC()) ? data.getInt("DataVersion") : -1;
int destVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion(); int destVersion = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
try { try {
data = MCDataConverter.convertTag(MCTypeRegistry.PLAYER(), data, srcVersion, destVersion); data = MCDataConverter.convertTag(MCTypeRegistry.PLAYER(), data, srcVersion, destVersion);
} catch (Exception e) { } 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; 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. * 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. * @return the NBT data from the player-data file.
* @throws IllegalStateException if the player is online. * @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)); return new PlayerDataWrapper(getPlayerData(true));
} }
@ -218,16 +220,18 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
/** /**
* Gets the players inventory. * Gets the players inventory.
* @return the players inventory. * @return the players inventory.
* @throws IOException if an error occurs reading the data.
*/ */
default PlayerInventory getInventory() { default PlayerInventory getInventory() throws IOException {
return getPlayerDataWrapper().getInventory(); return getPlayerDataWrapper().getInventory();
} }
/** /**
* Gets the players enderchest. * Gets the players enderchest.
* @return the players enderchest. * @return the players enderchest.
* @throws IOException if an error occurs reading the data.
*/ */
default Inventory getEnderChest() { default Inventory getEnderChest() throws IOException {
return getPlayerDataWrapper().getEnderChest(); return getPlayerDataWrapper().getEnderChest();
} }

View File

@ -107,7 +107,7 @@ import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
String classToPrint = type; String classToPrint = type;
String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1); String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1);
String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'"); String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'");
if (!htmlTitle.equals("")) { if (!htmlTitle.isEmpty()) {
typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>"; typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>";
} }
else { else {

View File

@ -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.brigadier.CommandNode;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftItemStack; 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.CraftMetaItem;
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;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
@ -111,6 +112,7 @@ public class PandalibPaperReflect {
// craftbukkit // craftbukkit
thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftMapView.class, CraftMapView.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(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get()));

View File

@ -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);
}
}