Compare commits

..

No commits in common. "c60fb613d4b52fe953e9c93dbcf8935b1ff35b32" and "e02ccc2b60bfb03e2ae27d9af407b77bf93288b6" have entirely different histories.

4 changed files with 8 additions and 42 deletions

View File

@ -155,11 +155,10 @@ 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, or null if the file does not exists. * @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 CompoundTag getPlayerData(boolean convertTag) throws IOException { default CompoundTag getPlayerData(boolean convertTag) {
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)
@ -167,13 +166,13 @@ public interface PaperOffPlayer extends AbstractOffPlayer {
.getPlayerList() .getPlayerList()
.playerIo() .playerIo()
.getPlayerData(getUniqueId().toString()); .getPlayerData(getUniqueId().toString());
if (data != null && convertTag) { if (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 IOException("Unable to upgrade data format of player " + getName() + " (" + getUniqueId() + ") from version " + destVersion + " to " + destVersion); throw new RuntimeException("Unable to upgrade data format of player " + getName() + " (" + getUniqueId() + ") from version " + destVersion + " to " + destVersion);
} }
} }
return data; return data;
@ -184,9 +183,8 @@ 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() throws IOException { default PlayerDataWrapper getPlayerDataWrapper() {
return new PlayerDataWrapper(getPlayerData(true)); return new PlayerDataWrapper(getPlayerData(true));
} }
@ -220,18 +218,16 @@ 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() throws IOException { default PlayerInventory getInventory() {
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() throws IOException { default Inventory getEnderChest() {
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.isEmpty()) { if (!htmlTitle.equals("")) {
typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>"; typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>";
} }
else { else {

View File

@ -3,7 +3,6 @@ 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;
@ -112,7 +111,6 @@ 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

@ -1,28 +0,0 @@
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);
}
}