diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/abstracts/ImprovedOfflinePlayer.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/abstracts/ImprovedOfflinePlayer.java new file mode 100644 index 0000000000..445d07d0a4 --- /dev/null +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/abstracts/ImprovedOfflinePlayer.java @@ -0,0 +1,462 @@ +package net.aufdemrand.denizen.nms.abstracts; + +/* + * ImprovedOfflinePlayer, a library for Bukkit. + * Copyright (C) 2013 one4me@github.com + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * @name ImprovedOfflinePlayer + * @version 1.6.0 + * @author one4me + */ + +import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag; +import net.aufdemrand.denizen.nms.util.jnbt.DoubleTag; +import net.aufdemrand.denizen.nms.util.jnbt.FloatTag; +import net.aufdemrand.denizen.nms.util.jnbt.ListTag; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.util.Vector; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public abstract class ImprovedOfflinePlayer { + + protected UUID player; + protected File file; + protected CompoundTag compound; + protected boolean exists = false; + protected boolean autosave = true; + public static Map offlineInventories = new HashMap(); + public static Map offlineEnderChests = new HashMap(); + + public ImprovedOfflinePlayer(UUID playeruuid) { + this.exists = loadPlayerData(playeruuid); + } + + public abstract PlayerInventory getInventory(); + + public abstract void setInventory(PlayerInventory inventory); + + public abstract Inventory getEnderChest(); + + public abstract void setEnderChest(Inventory inventory); + + public Location getLocation() { + ListTag position = this.compound.getListTag("Pos"); + ListTag rotation = this.compound.getListTag("Rotation"); + return new Location( + Bukkit.getWorld(new UUID(this.compound.getLong("WorldUUIDMost"), + this.compound.getLong("WorldUUIDLeast"))), + position.getDouble(0), + position.getDouble(1), + position.getDouble(2), + rotation.getFloat(0), + rotation.getFloat(1) + ); + } + + public void setLocation(Location location) { + World w = location.getWorld(); + UUID uuid = w.getUID(); + List position = new ArrayList(); + position.add(new DoubleTag(location.getX())); + position.add(new DoubleTag(location.getY())); + position.add(new DoubleTag(location.getZ())); + List rotation = new ArrayList(); + rotation.add(new FloatTag(location.getYaw())); + rotation.add(new FloatTag(location.getPitch())); + this.compound = this.compound.createBuilder() + .putLong("WorldUUIDMost", uuid.getMostSignificantBits()) + .putLong("WorldUUIDLeast", uuid.getLeastSignificantBits()) + .putInt("Dimension", w.getEnvironment().ordinal()) + .put("Pos", new ListTag(DoubleTag.class, position)) + .put("Rotation", new ListTag(FloatTag.class, rotation)).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getHealthFloat() { + return this.compound.getFloat("HealF"); + } + + public void setHealthFloat(float input) { + this.compound = compound.createBuilder().putFloat("HealF", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public abstract double getMaxHealth(); + + public abstract void setMaxHealth(double input); + + protected abstract boolean loadPlayerData(UUID uuid); + + public abstract void savePlayerData(); + + public boolean exists() { + return this.exists; + } + + public boolean getAutoSave() { + return this.autosave; + } + + public void setAutoSave(boolean autosave) { + this.autosave = autosave; + } + + public float getAbsorptionAmount() { + return this.compound.getFloat("AbsorptionAmount"); + } + + public void setAbsorptionAmount(float input) { + this.compound = compound.createBuilder().putFloat("AbsorptionAmount", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public Location getBedSpawnLocation() { + return new Location( + Bukkit.getWorld(this.compound.getString("SpawnWorld")), + this.compound.getInt("SpawnX"), + this.compound.getInt("SpawnY"), + this.compound.getInt("SpawnZ") + ); + } + + public boolean isSpawnForced() { + return this.compound.getBoolean("SpawnForced"); + } + + public void setBedSpawnLocation(Location location, Boolean override) { + this.compound = compound.createBuilder() + .putInt("SpawnX", (int) location.getX()) + .putInt("SpawnY", (int) location.getY()) + .putInt("SpawnZ", (int) location.getZ()) + .putString("SpawnWorld", location.getWorld().getName()) + .putBoolean("SpawnForced", override == null ? false : override).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getExhaustion() { + return this.compound.getFloat("foodExhaustionLevel"); + } + + public void setExhaustion(float input) { + this.compound = compound.createBuilder().putFloat("foodExhaustionLevel", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getExp() { + return this.compound.getFloat("XpP"); + } + + public void setExp(float input) { + this.compound = compound.createBuilder().putFloat("XpP", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getFallDistance() { + return this.compound.getFloat("FallDistance"); + } + + public void setFallDistance(float input) { + this.compound = compound.createBuilder().putFloat("FallDistance", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getFireTicks() { + return this.compound.getShort("Fire"); + } + + public void setFireTicks(int input) { + this.compound = compound.createBuilder().putShort("Fire", (short) input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getFlySpeed() { + return ((CompoundTag) this.compound.getValue().get("abilities")).getFloat("flySpeed"); + } + + public void setFlySpeed(float speed) { + CompoundTag compoundTag = (CompoundTag) this.compound.getValue().get("abilities"); + compoundTag = compoundTag.createBuilder().putFloat("flySpeed", speed).build(); + this.compound = compound.createBuilder().put("abilities", compoundTag).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getFoodLevel() { + return this.compound.getInt("foodLevel"); + } + + public void setFoodLevel(int input) { + this.compound = compound.createBuilder().putInt("foodLevel", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getFoodTickTimer() { + return this.compound.getInt("foodTickTimer"); + } + + public void setFoodTickTimer(int input) { + this.compound = compound.createBuilder().putInt("foodTickTimer", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public GameMode getGameMode() { + return GameMode.values()[this.compound.getInt("playerGameType")]; + } + + @SuppressWarnings("deprecation")//Will most likely break in 1.7 + public void setGameMode(GameMode input) { + this.compound = compound.createBuilder().putInt("playerGameType", input.getValue()).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getHealthInt() { + return this.compound.getShort("Health"); + } + + public void setHealthInt(int input) { + this.compound = compound.createBuilder().putShort("Health", (short) input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public boolean getIsInvulnerable() { + return compound.getBoolean("Invulnerable"); + } + + public void setIsInvulnerable(boolean input) { + this.compound = compound.createBuilder().putBoolean("Invulnerable", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public boolean getIsOnGround() { + return compound.getBoolean("OnGround"); + } + + public void setIsOnGround(boolean input) { + this.compound = compound.createBuilder().putBoolean("OnGround", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public boolean getIsSleeping() { + return this.compound.getBoolean("Sleeping"); + } + + public void setIsSleeping(boolean input) { + this.compound = compound.createBuilder().putBoolean("Sleeping", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getItemInHand() { + return this.compound.getInt("SelectedItemSlot"); + } + + public void setItemInHand(int input) { + this.compound = compound.createBuilder().putInt("SelectedItemSlot", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getLevel() { + return this.compound.getInt("XpLevel"); + } + + public void setLevel(int input) { + this.compound = compound.createBuilder().putInt("XpLevel", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public UUID getUniqueId() { + return this.player; + } + + public int getPortalCooldown() { + return this.compound.getInt("PortalCooldown"); + } + + public void setPortalCooldown(int input) { + this.compound = compound.createBuilder().putInt("PortalCooldown", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getRemainingAir() { + return this.compound.getShort("Air"); + } + + public void setRemainingAir(int input) { + this.compound = compound.createBuilder().putShort("Air", (short) input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getSaturation() { + return this.compound.getFloat("foodSaturationLevel"); + } + + public void setSaturation(float input) { + this.compound = compound.createBuilder().putFloat("foodSaturationLevel", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getScore() { + return this.compound.getFloat("foodSaturationLevel"); + } + + public void setScore(int input) { + this.compound = compound.createBuilder().putInt("Score", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public short getTimeAttack() { + return this.compound.getShort("AttackTime"); + } + + public void setTimeAttack(short input) { + this.compound = compound.createBuilder().putShort("AttackTime", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public short getTimeDeath() { + return this.compound.getShort("DeathTime"); + } + + public void setTimeDeath(short input) { + this.compound = compound.createBuilder().putShort("DeathTime", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public short getTimeHurt() { + return this.compound.getShort("HurtTime"); + } + + public void setTimeHurt(short input) { + this.compound = compound.createBuilder().putShort("HurtTime", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public short getTimeSleep() { + return this.compound.getShort("SleepTimer"); + } + + public void setTimeSleep(short input) { + this.compound = compound.createBuilder().putShort("SleepTimer", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public int getTotalExperience() { + return this.compound.getInt("XpTotal"); + } + + public void setTotalExperience(int input) { + this.compound = compound.createBuilder().putInt("XpTotal", input).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public Vector getVelocity() { + ListTag list = this.compound.getListTag("Motion"); + return new Vector(list.getDouble(0), list.getDouble(1), list.getDouble(2)); + } + + public void setVelocity(Vector vector) { + List motion = new ArrayList(); + motion.add(new DoubleTag(vector.getX())); + motion.add(new DoubleTag(vector.getY())); + motion.add(new DoubleTag(vector.getZ())); + this.compound = compound.createBuilder().put("Motion", new ListTag(DoubleTag.class, motion)).build(); + if (this.autosave) { + savePlayerData(); + } + } + + public float getWalkSpeed() { + return ((CompoundTag) this.compound.getValue().get("abilities")).getFloat("walkSpeed"); + } + + public void setWalkSpeed(float speed) { + CompoundTag compoundTag = (CompoundTag) this.compound.getValue().get("abilities"); + compoundTag = compoundTag.createBuilder().putFloat("walkSpeed", speed).build(); + this.compound = compound.createBuilder().put("abilities", compoundTag).build(); + if (this.autosave) { + savePlayerData(); + } + } +} diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java index e166d98182..33e2fe0b90 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/EntityHelper.java @@ -1,5 +1,6 @@ package net.aufdemrand.denizen.nms.interfaces; +import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Animals; @@ -22,6 +23,10 @@ public interface EntityHelper { void setTarget(Creature entity, LivingEntity target); + CompoundTag getNbtData(Entity entity); + + void setNbtData(Entity entity, CompoundTag compoundTag); + void stopFollowing(Entity follower); void stopWalking(Entity entity); diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/ItemHelper.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/ItemHelper.java index 412e610925..96ea1cb9a5 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/ItemHelper.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/ItemHelper.java @@ -16,4 +16,6 @@ public interface ItemHelper { ItemStack addNbtData(ItemStack itemStack, String key, Tag value); CompoundTag getNbtData(ItemStack itemStack); + + ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag); } diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PlayerHelper.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PlayerHelper.java index 162c2ce4df..87eff21aa9 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PlayerHelper.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PlayerHelper.java @@ -1,8 +1,12 @@ package net.aufdemrand.denizen.nms.interfaces; +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; import org.bukkit.Chunk; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import java.util.UUID; + public interface PlayerHelper { boolean hasChunkLoaded(Player player, Chunk chunk); @@ -12,4 +16,8 @@ public interface PlayerHelper { void setTemporaryOp(Player player, boolean op); void showEndCredits(Player player); + + ImprovedOfflinePlayer getOfflineData(UUID uuid); + + ImprovedOfflinePlayer getOfflineData(OfflinePlayer offlinePlayer); } diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTag.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTag.java index 2635e714bf..e940bf3c45 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTag.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTag.java @@ -115,6 +115,10 @@ public byte getByte(String key) { } } + public boolean getBoolean(String key) { + return getByte(key) != 0; + } + /** * Get a double named with the given key. *

diff --git a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTagBuilder.java b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTagBuilder.java index 545d30d18b..4a100de180 100644 --- a/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTagBuilder.java +++ b/nmshandler/src/main/java/net/aufdemrand/denizen/nms/util/jnbt/CompoundTagBuilder.java @@ -86,6 +86,10 @@ public CompoundTagBuilder putByte(String key, byte value) { return put(key, new ByteTag(value)); } + public CompoundTagBuilder putBoolean(String key, boolean value) { + return putByte(key, (byte) (value ? 1 : 0)); + } + /** * Put the given key and value into the compound tag as a * {@code DoubleTag}. @@ -183,6 +187,11 @@ public CompoundTagBuilder putAll(Map value) { return this; } + public CompoundTagBuilder remove(String key) { + entries.remove(key); + return this; + } + /** * Build an unnamed compound tag with this builder's entries. * diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/dInventory.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/dInventory.java index 21d5a92abf..d87fc29317 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/dInventory.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/dInventory.java @@ -1,6 +1,8 @@ package net.aufdemrand.denizen.objects; import net.aufdemrand.denizen.BukkitScriptEntryData; +import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; import net.aufdemrand.denizen.objects.notable.NotableManager; import net.aufdemrand.denizen.scripts.containers.core.InventoryScriptContainer; import net.aufdemrand.denizen.scripts.containers.core.InventoryScriptHelper; @@ -8,7 +10,6 @@ import net.aufdemrand.denizen.utilities.Utilities; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; -import net.aufdemrand.denizen.utilities.nbt.ImprovedOfflinePlayer; import net.aufdemrand.denizencore.objects.*; import net.aufdemrand.denizencore.objects.aH.Argument; import net.aufdemrand.denizencore.objects.aH.PrimitiveType; @@ -28,7 +29,12 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.*; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.HorseInventory; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.BookMeta; import java.util.ArrayList; @@ -51,15 +57,15 @@ public static dInventory mirrorBukkitInventory(Inventory inventory) { return InventoryScriptHelper.notableInventories.get(inventory.getTitle()); } // Iterate through offline player inventories - for (Map.Entry inv : InventoryScriptHelper.offlineInventories.entrySet()) { + for (Map.Entry inv : ImprovedOfflinePlayer.offlineInventories.entrySet()) { if (inv.getValue().equals(inventory)) { - return new dInventory(new ImprovedOfflinePlayer(inv.getKey())); + return new dInventory(NMSHandler.getInstance().getPlayerHelper().getOfflineData(inv.getKey())); } } // Iterate through offline player enderchests - for (Map.Entry inv : InventoryScriptHelper.offlineEnderChests.entrySet()) { + for (Map.Entry inv : ImprovedOfflinePlayer.offlineEnderChests.entrySet()) { if (inv.getValue().equals(inventory)) { - return new dInventory(new ImprovedOfflinePlayer(inv.getKey()), true); + return new dInventory(NMSHandler.getInstance().getPlayerHelper().getOfflineData(inv.getKey()), true); } } @@ -533,7 +539,7 @@ else if (holder instanceof Entity) { } else if (getIdType().equals("player")) { // Iterate through offline player inventories - for (Map.Entry inv : InventoryScriptHelper.offlineInventories.entrySet()) { + for (Map.Entry inv : ImprovedOfflinePlayer.offlineInventories.entrySet()) { if (inv.getValue().equals(inventory)) { idHolder = new dPlayer(inv.getKey()).identify(); return; @@ -542,7 +548,7 @@ else if (getIdType().equals("player")) { } else if (getIdType().equals("enderchest")) { // Iterate through offline player enderchests - for (Map.Entry inv : InventoryScriptHelper.offlineEnderChests.entrySet()) { + for (Map.Entry inv : ImprovedOfflinePlayer.offlineEnderChests.entrySet()) { if (inv.getValue().equals(inventory)) { idHolder = new dPlayer(inv.getKey()).identify(); return; diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java index 2ae56a01eb..0af12b85e6 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java @@ -2,6 +2,7 @@ import net.aufdemrand.denizen.flags.FlagManager; import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; import net.aufdemrand.denizen.nms.abstracts.Sidebar; import net.aufdemrand.denizen.objects.properties.entity.EntityHealth; import net.aufdemrand.denizen.scripts.commands.core.FailCommand; @@ -12,7 +13,6 @@ import net.aufdemrand.denizen.utilities.DenizenAPI; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; -import net.aufdemrand.denizen.utilities.nbt.ImprovedOfflinePlayer; import net.aufdemrand.denizen.utilities.packets.*; import net.aufdemrand.denizencore.objects.*; import net.aufdemrand.denizencore.objects.properties.Property; @@ -228,7 +228,7 @@ public OfflinePlayer getOfflinePlayer() { } public ImprovedOfflinePlayer getNBTEditor() { - return new ImprovedOfflinePlayer(getOfflinePlayer()); + return NMSHandler.getInstance().getPlayerHelper().getOfflineData(getOfflinePlayer()); } public dEntity getDenizenEntity() { diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityColor.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityColor.java index 6b5452cac6..4a5020f014 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityColor.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityColor.java @@ -70,7 +70,7 @@ else if (type == EntityType.OCELOT) { } else if (type == EntityType.RABBIT) { - return RabbitType.getRabbitType((Rabbit) colored.getBukkitEntity()).name(); + return ((Rabbit) colored.getBukkitEntity()).getRabbitType().name(); } else // Should never happen @@ -211,10 +211,13 @@ else if (type == EntityType.OCELOT .setCatType(Ocelot.Type.valueOf(mechanism.getValue().asString().toUpperCase())); } - else if (type == EntityType.RABBIT - && mechanism.getValue().matchesEnum(RabbitType.values())) { - RabbitType.setRabbitType((Rabbit) colored.getBukkitEntity(), - RabbitType.valueOf(mechanism.getValue().asString().toUpperCase())); + else if (type == EntityType.RABBIT) { + if (mechanism.getValue().matchesEnum(RabbitType.values())) { + ((Rabbit) colored.getBukkitEntity()).setRabbitType(RabbitType.valueOf(mechanism.getValue().asString().toUpperCase()).getType()); + } + else if (mechanism.getValue().matchesEnum(Rabbit.Type.values())) { + ((Rabbit) colored.getBukkitEntity()).setRabbitType(Rabbit.Type.valueOf(mechanism.getValue().asString().toUpperCase())); + } } } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/scripts/containers/core/InventoryScriptHelper.java b/plugin/src/main/java/net/aufdemrand/denizen/scripts/containers/core/InventoryScriptHelper.java index a4135a5f13..0857516e8d 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/scripts/containers/core/InventoryScriptHelper.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/scripts/containers/core/InventoryScriptHelper.java @@ -1,8 +1,10 @@ package net.aufdemrand.denizen.scripts.containers.core; +import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; +import net.aufdemrand.denizen.nms.interfaces.PlayerHelper; import net.aufdemrand.denizen.objects.dInventory; import net.aufdemrand.denizen.utilities.DenizenAPI; -import net.aufdemrand.denizen.utilities.nbt.ImprovedOfflinePlayer; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -18,8 +20,6 @@ public class InventoryScriptHelper implements Listener { public static Map inventory_scripts = new ConcurrentHashMap(8, 0.9f, 1); - public static Map offlineInventories = new HashMap(); - public static Map offlineEnderChests = new HashMap(); public static Map notableInventories = new HashMap(); public static Map tempInventoryScripts = new HashMap(); @@ -29,24 +29,26 @@ public InventoryScriptHelper() { } public static void _savePlayerInventories() { - for (Map.Entry offlineInv : offlineInventories.entrySet()) { - new ImprovedOfflinePlayer(offlineInv.getKey()).setInventory(offlineInv.getValue()); + PlayerHelper playerHelper = NMSHandler.getInstance().getPlayerHelper(); + for (Map.Entry offlineInv : ImprovedOfflinePlayer.offlineInventories.entrySet()) { + playerHelper.getOfflineData(offlineInv.getKey()).setInventory(offlineInv.getValue()); } - for (Map.Entry offlineEnderChest : offlineEnderChests.entrySet()) { - new ImprovedOfflinePlayer(offlineEnderChest.getKey()).setEnderChest(offlineEnderChest.getValue()); + for (Map.Entry offlineEnderChest : ImprovedOfflinePlayer.offlineEnderChests.entrySet()) { + playerHelper.getOfflineData(offlineEnderChest.getKey()).setEnderChest(offlineEnderChest.getValue()); } } @EventHandler public void onPlayerLogin(PlayerLoginEvent event) { UUID uuid = event.getPlayer().getUniqueId(); - if (offlineInventories.containsKey(uuid)) { - new ImprovedOfflinePlayer(uuid).setInventory(offlineInventories.get(uuid)); - offlineInventories.remove(uuid); + PlayerHelper playerHelper = NMSHandler.getInstance().getPlayerHelper(); + if (ImprovedOfflinePlayer.offlineInventories.containsKey(uuid)) { + playerHelper.getOfflineData(uuid).setInventory(ImprovedOfflinePlayer.offlineInventories.get(uuid)); + ImprovedOfflinePlayer.offlineInventories.remove(uuid); } - if (offlineEnderChests.containsKey(uuid)) { - new ImprovedOfflinePlayer(uuid).setEnderChest(offlineEnderChests.get(uuid)); - offlineEnderChests.remove(uuid); + if (ImprovedOfflinePlayer.offlineEnderChests.containsKey(uuid)) { + playerHelper.getOfflineData(uuid).setEnderChest(ImprovedOfflinePlayer.offlineEnderChests.get(uuid)); + ImprovedOfflinePlayer.offlineEnderChests.remove(uuid); } } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/LogInterceptor.java b/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/LogInterceptor.java index 3850dac18b..839d5c3c76 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/LogInterceptor.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/utilities/debugging/LogInterceptor.java @@ -13,8 +13,9 @@ import org.apache.logging.log4j.spi.AbstractLogger; import org.apache.logging.log4j.spi.AbstractLoggerWrapper; import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_10_R1.LoggerOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; import java.util.HashMap; @@ -116,4 +117,27 @@ public void log(Marker marker, String fqcn, Level level, Message data, Throwable super.log(marker, fqcn, level, data, t); } } + + private static class LoggerOutputStream extends ByteArrayOutputStream { + private final String separator = System.getProperty("line.separator"); + private final Logger logger; + private final Level level; + + public LoggerOutputStream(Logger logger, Level level) { + this.logger = logger; + this.level = level; + } + + public void flush() throws IOException { + synchronized(this) { + super.flush(); + String record = this.toString(); + super.reset(); + if(record.length() > 0 && !record.equals(this.separator)) { + this.logger.log(this.level, record); + } + + } + } + } } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/utilities/entity/RabbitType.java b/plugin/src/main/java/net/aufdemrand/denizen/utilities/entity/RabbitType.java index 4695f7d019..36fe36b0c0 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/utilities/entity/RabbitType.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/utilities/entity/RabbitType.java @@ -1,75 +1,23 @@ package net.aufdemrand.denizen.utilities.entity; -import net.minecraft.server.v1_10_R1.EntityRabbit; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftRabbit; import org.bukkit.entity.Rabbit; public enum RabbitType { - BROWN(0, 0), - WHITE(1, 1), - BLACK(2, 2), - WHITE_SPLOTCHED(3, 3), - GOLD(4, 4), - SALT(5, 5), - KILLER(6, 99); + BROWN(Rabbit.Type.BROWN), + WHITE(Rabbit.Type.WHITE), + BLACK(Rabbit.Type.BLACK), + WHITE_SPLOTCHED(Rabbit.Type.BLACK_AND_WHITE), + GOLD(Rabbit.Type.GOLD), + SALT(Rabbit.Type.SALT_AND_PEPPER), + KILLER(Rabbit.Type.THE_KILLER_BUNNY); - public static RabbitType getRabbitType(Rabbit rabbit) { - return RabbitType.getType(getEntityRabbit(rabbit).getRabbitType()); - } - - public static void setRabbitType(Rabbit rabbit, RabbitType type) { - getEntityRabbit(rabbit).setRabbitType(type.getId()); - } - - private static EntityRabbit getEntityRabbit(Rabbit rabbit) { - return (EntityRabbit) ((CraftRabbit) rabbit).getHandle(); - } - - private static final RabbitType[] types = new RabbitType[values().length]; - private final int internalId; - private final int id; - - static { - for (RabbitType type : values()) { - types[type.getInternalId()] = type; - } - } - - private RabbitType(int internalId, int id) { - this.internalId = internalId; - this.id = id; - } - - /** - * Gets the ID of this rabbit type. - * - * @return Type ID. - */ - public int getId() { - return id; - } + private Rabbit.Type type; - /** - * Gets the internal ID of this rabbit type. - * - * @return Internal Type ID. - */ - private int getInternalId() { - return internalId; + RabbitType(Rabbit.Type type) { + this.type = type; } - /** - * Gets a rabbit type by its ID. - * - * @param id ID of the rabbit type to get. - * @return Resulting type, or null if not found. - */ - public static RabbitType getType(int id) { - for (RabbitType type : types) { - if (id == type.getId()) { - return type; - } - } - return null; + public Rabbit.Type getType() { + return type; } } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/CustomNBT.java b/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/CustomNBT.java index 624aa52d1f..5c100b257f 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/CustomNBT.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/CustomNBT.java @@ -1,16 +1,19 @@ package net.aufdemrand.denizen.utilities.nbt; +import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag; +import net.aufdemrand.denizen.nms.util.jnbt.ListTag; +import net.aufdemrand.denizen.nms.util.jnbt.StringTag; +import net.aufdemrand.denizen.nms.util.jnbt.Tag; import net.aufdemrand.denizencore.utilities.CoreUtilities; -import net.minecraft.server.v1_10_R1.*; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; public class CustomNBT { @@ -28,10 +31,6 @@ public static boolean hasCustomNBT(ItemStack item, String key) { if (item == null) { return false; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - if (!cis.hasTag()) { - return false; - } key = CoreUtilities.toLowerCase(key); List keys = listNBT(item, ""); for (String string : keys) { @@ -46,12 +45,7 @@ public static String getCustomNBT(ItemStack item, String key) { if (item == null) { return null; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag; - if (!cis.hasTag()) { - cis.setTag(new NBTTagCompound()); - } - tag = cis.getTag(); + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); key = CoreUtilities.toLowerCase(key); String finalKey = null; List keys = listNBT(item, ""); @@ -68,17 +62,17 @@ public static String getCustomNBT(ItemStack item, String key) { if (subkeys.hasNext()) { while (true) { String subkey = subkeys.next(); - NBTBase base = tag.get(subkey); + Tag base = compoundTag.getValue().get(subkey); if (!subkeys.hasNext()) { - if (base instanceof NBTTagString) { - return ((NBTTagString) base).c_(); + if (base instanceof StringTag) { + return ((StringTag) base).getValue(); } else { return base.toString(); } } - else if (base instanceof NBTTagCompound) { - tag = (NBTTagCompound) base; + else if (base instanceof CompoundTag) { + compoundTag = (CompoundTag) base; } else { return null; @@ -93,12 +87,7 @@ public static ItemStack removeCustomNBT(ItemStack item, String key) { if (item == null) { return null; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag; - if (!cis.hasTag()) { - cis.setTag(new NBTTagCompound()); - } - tag = cis.getTag(); + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); key = CoreUtilities.toLowerCase(key); String finalKey = null; List keys = listNBT(item, ""); @@ -116,34 +105,30 @@ public static ItemStack removeCustomNBT(ItemStack item, String key) { while (true) { String subkey = subkeys.next(); if (!subkeys.hasNext()) { - tag.remove(subkey); - cis = unregisterNBT(cis, key); + compoundTag = compoundTag.createBuilder().remove(subkey).build(); + item = unregisterNBT(NMSHandler.getInstance().getItemHelper().setNbtData(item, compoundTag), key); } - else if (tag.get(subkey).getTypeId() == tag.getTypeId()) { - tag = tag.getCompound(subkey); + else if (compoundTag.getValue().get(subkey) instanceof CompoundTag) { + compoundTag = (CompoundTag) compoundTag.getValue().get(subkey); continue; } break; } } - return CraftItemStack.asCraftMirror(cis); + return item; } public static List listNBT(ItemStack item, String filter) { if (item == null) { return null; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag; - if (!cis.hasTag()) { - cis.setTag(new NBTTagCompound()); - } - tag = cis.getTag(); - return recursiveSearch(tag, "", filter); + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); + return recursiveSearch(compoundTag, "", filter); } - private static List recursiveSearch(NBTTagCompound compound, String base, String filter) { - Set keys = compound.c(); + private static List recursiveSearch(CompoundTag compound, String base, String filter) { + Map value = compound.getValue(); + Set keys = compound.getValue().keySet(); List finalKeys = new ArrayList(); filter = CoreUtilities.toLowerCase(filter); for (String key : keys) { @@ -151,8 +136,8 @@ private static List recursiveSearch(NBTTagCompound compound, String base if (CoreUtilities.toLowerCase(full).startsWith(filter)) { finalKeys.add(full); } - if (compound.get(key).getTypeId() == compound.getTypeId()) { - finalKeys.addAll(recursiveSearch(compound.getCompound(key), full + ".", filter)); + if (value.get(key) instanceof CompoundTag) { + finalKeys.addAll(recursiveSearch((CompoundTag) value.get(key), full + ".", filter)); } } return finalKeys; @@ -162,13 +147,7 @@ public static ItemStack addCustomNBT(ItemStack item, String key, String value) { if (item == null) { return null; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag; - // Do stuff with tag - if (!cis.hasTag()) { - cis.setTag(new NBTTagCompound()); - } - tag = cis.getTag(); + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); List existingKeys = listNBT(item, ""); String existing = ""; String lowerKey = CoreUtilities.toLowerCase(key); @@ -187,9 +166,9 @@ public static ItemStack addCustomNBT(ItemStack item, String key, String value) { String finalKey = null; if (!existing.equals("")) { for (String subkey : CoreUtilities.split(existing, '.')) { - NBTBase base = tag.get(subkey); - if (base instanceof NBTTagCompound) { - tag = (NBTTagCompound) base; + Tag base = compoundTag.getValue().get(subkey); + if (base instanceof CompoundTag) { + compoundTag = (CompoundTag) base; } else { finalKey = subkey; @@ -201,157 +180,117 @@ public static ItemStack addCustomNBT(ItemStack item, String key, String value) { while (true) { String subkey = subkeys.next(); if (!subkeys.hasNext()) { - tag.setString(subkey, value); - cis = registerNBT(cis, key); + compoundTag = compoundTag.createBuilder().putString(subkey, value).build(); + item = registerNBT(item, key); break; } else { - tag.set(subkey, new NBTTagCompound()); - tag = tag.getCompound(subkey); + compoundTag = compoundTag.createBuilder().put(subkey, NMSHandler.getInstance().createCompoundTag(new HashMap())).build(); + compoundTag = (CompoundTag) compoundTag.getValue().get(subkey); } } } else { - tag.setString(finalKey, value); + compoundTag = compoundTag.createBuilder().putString(finalKey, value).build(); } - return CraftItemStack.asCraftMirror(cis); + return NMSHandler.getInstance().getItemHelper().setNbtData(item, compoundTag); } - private static net.minecraft.server.v1_10_R1.ItemStack registerNBT(net.minecraft.server.v1_10_R1.ItemStack item, String key) { + private static ItemStack registerNBT(ItemStack item, String key) { if (item == null) { return null; } - NBTTagCompound tag; - if (!item.hasTag()) { - item.setTag(new NBTTagCompound()); - } - tag = item.getTag(); - NBTTagList list = new NBTTagList(); - if (tag.hasKeyOfType("Denizen-Registered-Keys", list.getTypeId())) { - list = tag.getList("Denizen-Registered-Keys", new NBTTagString().getTypeId()); - } - list.add(new NBTTagString(key)); - tag.set("Denizen-Registered-Keys", list); - return item; + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); + List list = compoundTag.getList("Denizen-Registered-Keys"); + list.add(new StringTag(key)); + compoundTag = compoundTag.createBuilder().put("Denizen-Registered-Keys", new ListTag(StringTag.class, list)).build(); + return NMSHandler.getInstance().getItemHelper().setNbtData(item, compoundTag); } - private static net.minecraft.server.v1_10_R1.ItemStack unregisterNBT(net.minecraft.server.v1_10_R1.ItemStack item, String key) { + private static ItemStack unregisterNBT(ItemStack item, String key) { if (item == null) { return null; } - NBTTagCompound tag; - if (!item.hasTag()) { - return item; - } - tag = item.getTag(); - NBTTagList list = new NBTTagList(); - if (tag.hasKeyOfType("Denizen-Registered-Keys", list.getTypeId())) { - list = tag.getList("Denizen-Registered-Keys", new NBTTagString().getTypeId()); - } - else { + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); + ListTag list = compoundTag.getListTag("Denizen-Registered-Keys"); + if (list.getValue().isEmpty()) { return item; } + List value = list.getValue(); String lowerKey = CoreUtilities.toLowerCase(key); - for (int i = 0; i < list.size(); i++) { + for (int i = 0; i < list.getValue().size(); i++) { if (CoreUtilities.toLowerCase(list.getString(i)).equals(lowerKey)) { - list.remove(i); + value.remove(i); break; } } - tag.set("Denizen-Registered-Keys", list); - return item; + list.setValue(value); + compoundTag = compoundTag.createBuilder().put("Denizen-Registered-Keys", list).build(); + return NMSHandler.getInstance().getItemHelper().setNbtData(item, compoundTag); } public static List getRegisteredNBT(ItemStack item) { if (item == null) { return null; } - net.minecraft.server.v1_10_R1.ItemStack cis = CraftItemStack.asNMSCopy(item); - NBTTagCompound tag; - if (!cis.hasTag()) { - return null; - } - tag = cis.getTag(); - NBTTagList list = new NBTTagList(); - if (tag.hasKeyOfType("Denizen-Registered-Keys", list.getTypeId())) { - list = tag.getList("Denizen-Registered-Keys", new NBTTagString().getTypeId()); - } - else { + CompoundTag compoundTag = NMSHandler.getInstance().getItemHelper().getNbtData(item); + ListTag list = compoundTag.getListTag("Denizen-Registered-Keys"); + if (list.getValue().isEmpty()) { return null; } List ret = new ArrayList(); - for (int i = 0; i < list.size(); i++) { + for (int i = 0; i < list.getValue().size(); i++) { ret.add(list.getString(i)); } return ret; } - public static LivingEntity addCustomNBT(LivingEntity entity, String key, String value) { + public static Entity addCustomNBT(Entity entity, String key, String value) { if (entity == null) { return null; } - Entity bukkitEntity = entity; - net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound tag = new NBTTagCompound(); - - // Writes the entity's NBT data to tag - nmsEntity.c(tag); + CompoundTag compoundTag = NMSHandler.getInstance().getEntityHelper().getNbtData(entity); // Add custom NBT - tag.setString(key, value); + compoundTag = compoundTag.createBuilder().putString(key, value).build(); // Write tag back - ((EntityLiving) nmsEntity).a(tag); + NMSHandler.getInstance().getEntityHelper().setNbtData(entity, compoundTag); return entity; } - public static LivingEntity removeCustomNBT(LivingEntity entity, String key) { + public static Entity removeCustomNBT(Entity entity, String key) { if (entity == null) { return null; } - Entity bukkitEntity = entity; - net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound tag = new NBTTagCompound(); - - // Writes the entity's NBT data to tag - nmsEntity.c(tag); + CompoundTag compoundTag = NMSHandler.getInstance().getEntityHelper().getNbtData(entity); // Remove custom NBT - tag.remove(key); + compoundTag = compoundTag.createBuilder().remove(key).build(); // Write tag back - ((EntityLiving) nmsEntity).a(tag); + NMSHandler.getInstance().getEntityHelper().setNbtData(entity, compoundTag); return entity; } - public static boolean hasCustomNBT(LivingEntity entity, String key) { + public static boolean hasCustomNBT(Entity entity, String key) { if (entity == null) { return false; } - Entity bukkitEntity = entity; - net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound tag = new NBTTagCompound(); - - // Writes the entity's NBT data to tag - nmsEntity.c(tag); + CompoundTag compoundTag = NMSHandler.getInstance().getEntityHelper().getNbtData(entity); // Check for key - return tag.hasKey(key); + return compoundTag.getValue().containsKey(key); } - public static String getCustomNBT(LivingEntity entity, String key) { + public static String getCustomNBT(Entity entity, String key) { if (entity == null) { return null; } - Entity bukkitEntity = entity; - net.minecraft.server.v1_10_R1.Entity nmsEntity = ((CraftEntity) bukkitEntity).getHandle(); - NBTTagCompound tag = new NBTTagCompound(); - - // Writes the entity's NBT data to tag - nmsEntity.c(tag); + CompoundTag compoundTag = NMSHandler.getInstance().getEntityHelper().getNbtData(entity); // Return contents of the tag - return tag.getString(key); + return compoundTag.getString(key); } } diff --git a/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/ImprovedOfflinePlayer.java b/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/ImprovedOfflinePlayer.java deleted file mode 100644 index 64a34f13d6..0000000000 --- a/plugin/src/main/java/net/aufdemrand/denizen/utilities/nbt/ImprovedOfflinePlayer.java +++ /dev/null @@ -1,615 +0,0 @@ -package net.aufdemrand.denizen.utilities.nbt; - -// NMS/CB imports start - -import com.google.common.io.Files; -import net.aufdemrand.denizen.scripts.containers.core.InventoryScriptHelper; -import net.minecraft.server.v1_10_R1.*; -import org.bukkit.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.UUID; - -// NMS/CB imports end - -/* - * ImprovedOfflinePlayer, a library for Bukkit. - * Copyright (C) 2013 one4me@github.com - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * @name ImprovedOfflinePlayer - * @version 1.6.0 - * @author one4me - */ - -public class ImprovedOfflinePlayer { - - private UUID player; - private File file; - private NBTTagCompound compound; - private boolean exists = false; - private boolean autosave = true; - - public ImprovedOfflinePlayer(UUID playeruuid) { - this.exists = loadPlayerData(playeruuid); - } - - public ImprovedOfflinePlayer(OfflinePlayer offlineplayer) { - this.exists = loadPlayerData(offlineplayer.getUniqueId()); - } - - public org.bukkit.inventory.PlayerInventory getInventory() { - if (InventoryScriptHelper.offlineInventories.containsKey(getUniqueId())) { - return InventoryScriptHelper.offlineInventories.get(getUniqueId()); - } - PlayerInventory inventory = new PlayerInventory(null); - inventory.b(this.compound.getList("Inventory", 10)); - org.bukkit.inventory.PlayerInventory inv = new CraftInventoryPlayer(inventory); - InventoryScriptHelper.offlineInventories.put(getUniqueId(), inv); - return inv; - } - - public void setInventory(org.bukkit.inventory.PlayerInventory inventory) { - CraftInventoryPlayer inv = (CraftInventoryPlayer) inventory; - this.compound.set("Inventory", inv.getInventory().a(new NBTTagList())); - if (this.autosave) { - savePlayerData(); - } - } - - public Inventory getEnderChest() { - if (InventoryScriptHelper.offlineEnderChests.containsKey(getUniqueId())) { - return InventoryScriptHelper.offlineEnderChests.get(getUniqueId()); - } - InventoryEnderChest endchest = new InventoryEnderChest(); - endchest.a(this.compound.getList("EnderItems", 10)); - org.bukkit.inventory.Inventory inv = new CraftInventory(endchest); - InventoryScriptHelper.offlineEnderChests.put(getUniqueId(), inv); - return inv; - } - - public void setEnderChest(Inventory inventory) { - this.compound.set("EnderItems", ((InventoryEnderChest) ((CraftInventory) inventory).getInventory()).h()); - if (this.autosave) { - savePlayerData(); - } - } - - public Location getLocation() { - NBTTagList position = this.compound.getList("Pos", 6); - NBTTagList rotation = this.compound.getList("Rotation", 5); - return new Location( - Bukkit.getWorld(new UUID(this.compound.getLong("WorldUUIDMost"), - this.compound.getLong("WorldUUIDLeast"))), - position.e(0), - position.e(1), - position.e(2), - rotation.f(0), - rotation.f(1) - ); - } - - public void setLocation(Location location) { - World w = location.getWorld(); - UUID uuid = w.getUID(); - this.compound.setLong("WorldUUIDMost", uuid.getMostSignificantBits()); - this.compound.setLong("WorldUUIDLeast", uuid.getLeastSignificantBits()); - this.compound.setInt("Dimension", w.getEnvironment().ordinal()); - NBTTagList position = new NBTTagList(); - position.add(new NBTTagDouble(location.getX())); - position.add(new NBTTagDouble(location.getY())); - position.add(new NBTTagDouble(location.getZ())); - this.compound.set("Pos", position); - NBTTagList rotation = new NBTTagList(); - rotation.add(new NBTTagFloat(location.getYaw())); - rotation.add(new NBTTagFloat(location.getPitch())); - this.compound.set("Rotation", rotation); - if (this.autosave) { - savePlayerData(); - } - } - - public float getHealthFloat() { - return this.compound.getFloat("HealF"); - } - - public void setHealthFloat(float input) { - this.compound.setFloat("HealF", input); - if (this.autosave) { - savePlayerData(); - } - } - - public double getMaxHealth() { - return getAttributes().a("generic.maxHealth").getValue(); - } - - public void setMaxHealth(double input) { - AttributeMapBase attributes = getAttributes(); - attributes.a("generic.maxHealth").setValue(input); - setAttributes(attributes); - } - - private boolean loadPlayerData(UUID uuid) { - try { - this.player = uuid; - for (World w : Bukkit.getWorlds()) { - this.file = new File(w.getWorldFolder(), "playerdata" + File.separator + this.player + ".dat"); - if (this.file.exists()) { - this.compound = NBTCompressedStreamTools.a(new FileInputStream(this.file)); - return true; - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public void savePlayerData() { - if (this.exists) { - try { - NBTCompressedStreamTools.a(this.compound, new FileOutputStream(this.file)); - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - public boolean exists() { - return this.exists; - } - - public boolean getAutoSave() { - return this.autosave; - } - - public void setAutoSave(boolean autosave) { - this.autosave = autosave; - } - - public void copyDataTo(UUID playeruuid) { - try { - if (!playeruuid.equals(this.player)) { - Player to = Bukkit.getPlayer(playeruuid); - Player from = Bukkit.getPlayer(playeruuid); - if (from != null) { - from.saveData(); - } - Files.copy(this.file, new File(this.file.getParentFile(), playeruuid + ".dat")); - if (to != null) { - to.teleport(from == null ? getLocation() : from.getLocation()); - to.loadData(); - } - } - else { - Player player = Bukkit.getPlayer(playeruuid); - if (player != null) { - player.saveData(); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public PlayerAbilities getAbilities() { - PlayerAbilities pa = new PlayerAbilities(); - pa.a(this.compound); - return pa; - } - - public void setAbilities(PlayerAbilities abilities) { - abilities.a(this.compound); - if (this.autosave) { - savePlayerData(); - } - } - - public float getAbsorptionAmount() { - return this.compound.getFloat("AbsorptionAmount"); - } - - public void setAbsorptionAmount(float input) { - this.compound.setFloat("AbsorptionAmount", input); - if (this.autosave) { - savePlayerData(); - } - } - - public AttributeMapBase getAttributes() { - AttributeMapBase amb = (AttributeMapBase) new AttributeMapServer(); - GenericAttributes.a(amb, this.compound.getList("Attributes", 0)); - return amb; - } - - public void setAttributes(AttributeMapBase attributes) { - this.compound.set("Attributes", GenericAttributes.a(attributes)); - if (this.autosave) { - savePlayerData(); - } - } - - public Location getBedSpawnLocation() { - return new Location( - Bukkit.getWorld(this.compound.getString("SpawnWorld")), - this.compound.getInt("SpawnX"), - this.compound.getInt("SpawnY"), - this.compound.getInt("SpawnZ") - ); - } - - public boolean isSpawnForced() { - return this.compound.getBoolean("SpawnForced"); - } - - public void setBedSpawnLocation(Location location, Boolean override) { - this.compound.setInt("SpawnX", (int) location.getX()); - this.compound.setInt("SpawnY", (int) location.getY()); - this.compound.setInt("SpawnZ", (int) location.getZ()); - this.compound.setString("SpawnWorld", location.getWorld().getName()); - this.compound.setBoolean("SpawnForced", override == null ? false : override); - if (this.autosave) { - savePlayerData(); - } - } - - public float getExhaustion() { - return this.compound.getFloat("foodExhaustionLevel"); - } - - public void setExhaustion(float input) { - this.compound.setFloat("foodExhaustionLevel", input); - if (this.autosave) { - savePlayerData(); - } - } - - public float getExp() { - return this.compound.getFloat("XpP"); - } - - public void setExp(float input) { - this.compound.setFloat("XpP", input); - if (this.autosave) { - savePlayerData(); - } - } - - public float getFallDistance() { - return this.compound.getFloat("FallDistance"); - } - - public void setFallDistance(float input) { - this.compound.setFloat("FallDistance", input); - if (this.autosave) { - savePlayerData(); - } - } - - public int getFireTicks() { - return this.compound.getShort("Fire"); - } - - public void setFireTicks(int input) { - this.compound.setShort("Fire", (short) input); - if (this.autosave) { - savePlayerData(); - } - } - - public float getFlySpeed() { - return this.compound.getCompound("abilities").getFloat("flySpeed"); - } - - public void setFlySpeed(float speed) { - this.compound.getCompound("abilities").setFloat("flySpeed", speed); - if (this.autosave) { - savePlayerData(); - } - } - - public int getFoodLevel() { - return this.compound.getInt("foodLevel"); - } - - public void setFoodLevel(int input) { - this.compound.setInt("foodLevel", input); - if (this.autosave) { - savePlayerData(); - } - } - - public int getFoodTickTimer() { - return this.compound.getInt("foodTickTimer"); - } - - public void setFoodTickTimer(int input) { - this.compound.setInt("foodTickTimer", input); - if (this.autosave) { - savePlayerData(); - } - } - - public GameMode getGameMode() { - return GameMode.values()[this.compound.getInt("playerGameType")]; - } - - @SuppressWarnings("deprecation")//Will most likely break in 1.7 - public void setGameMode(GameMode input) { - this.compound.setInt("playerGameType", input.getValue()); - if (this.autosave) { - savePlayerData(); - } - } - - public int getHealthInt() { - return this.compound.getShort("Health"); - } - - public void setHealthInt(int input) { - this.compound.setShort("Health", (short) input); - if (this.autosave) { - savePlayerData(); - } - } - - public boolean getIsInvulnerable() { - return compound.getBoolean("Invulnerable"); - } - - public void setIsInvulnerable(boolean input) { - this.compound.setBoolean("Invulnerable", input); - if (this.autosave) { - savePlayerData(); - } - } - - public boolean getIsOnGround() { - return compound.getBoolean("OnGround"); - } - - public void setIsOnGround(boolean input) { - this.compound.setBoolean("OnGround", input); - if (this.autosave) { - savePlayerData(); - } - } - - public boolean getIsSleeping() { - return this.compound.getBoolean("Sleeping"); - } - - public void setIsSleeping(boolean input) { - this.compound.setBoolean("Sleeping", input); - if (this.autosave) { - savePlayerData(); - } - } - - public int getItemInHand() { - return this.compound.getInt("SelectedItemSlot"); - } - - public void setItemInHand(int input) { - this.compound.setInt("SelectedItemSlot", input); - if (this.autosave) { - savePlayerData(); - } - } - - public int getLevel() { - return this.compound.getInt("XpLevel"); - } - - public void setLevel(int input) { - this.compound.setInt("XpLevel", input); - if (this.autosave) { - savePlayerData(); - } - } - - public UUID getUniqueId() { - return this.player; - } - - public int getPortalCooldown() { - return this.compound.getInt("PortalCooldown"); - } - - public void setPortalCooldown(int input) { - this.compound.setInt("PortalCooldown", input); - if (this.autosave) { - savePlayerData(); - } - } - - @SuppressWarnings("deprecation")//Will most likely break in 1.7 - public ArrayList getPotionEffects() { - ArrayList effects = new ArrayList(); - if (this.compound.hasKey("ActiveEffects")) { - NBTTagList list = this.compound.getList("ActiveEffects", 0); - for (int i = 0; i < list.size(); i++) { - NBTTagCompound effect = (NBTTagCompound) list.get(i); - byte amp = effect.getByte("Amplifier"); - byte id = effect.getByte("Id"); - int time = effect.getInt("Duration"); - effects.add(new PotionEffect(PotionEffectType.getById(id), time, amp)); - } - } - return effects; - } - - @SuppressWarnings("deprecation")//Will most likely break in 1.7 - public void setPotionEffects(ArrayList effects) { - if (effects.isEmpty()) { - this.compound.remove("ActiveEffects"); - if (this.autosave) { - savePlayerData(); - } - return; - } - NBTTagList activeEffects = new NBTTagList(); - for (PotionEffect pe : effects) { - NBTTagCompound eCompound = new NBTTagCompound(); - eCompound.setByte("Amplifier", (byte) (pe.getAmplifier())); - eCompound.setByte("Id", (byte) (pe.getType().getId())); - eCompound.setInt("Duration", (int) (pe.getDuration())); - activeEffects.add(eCompound); - } - this.compound.set("ActiveEffects", activeEffects); - if (this.autosave) { - savePlayerData(); - } - } - - public int getRemainingAir() { - return this.compound.getShort("Air"); - } - - public void setRemainingAir(int input) { - this.compound.setShort("Air", (short) input); - if (this.autosave) { - savePlayerData(); - } - } - - public float getSaturation() { - return this.compound.getFloat("foodSaturationLevel"); - } - - public void setSaturation(float input) { - this.compound.setFloat("foodSaturationLevel", input); - if (this.autosave) { - savePlayerData(); - } - } - - public float getScore() { - return this.compound.getFloat("foodSaturationLevel"); - } - - public void setScore(int input) { - this.compound.setInt("Score", input); - if (this.autosave) { - savePlayerData(); - } - } - - public short getTimeAttack() { - return this.compound.getShort("AttackTime"); - } - - public void setTimeAttack(short input) { - this.compound.setShort("AttackTime", input); - if (this.autosave) { - savePlayerData(); - } - } - - public short getTimeDeath() { - return this.compound.getShort("DeathTime"); - } - - public void setTimeDeath(short input) { - this.compound.setShort("DeathTime", input); - if (this.autosave) { - savePlayerData(); - } - } - - public short getTimeHurt() { - return this.compound.getShort("HurtTime"); - } - - public void setTimeHurt(short input) { - this.compound.setShort("HurtTime", input); - if (this.autosave) { - savePlayerData(); - } - } - - public short getTimeSleep() { - return this.compound.getShort("SleepTimer"); - } - - public void setTimeSleep(short input) { - this.compound.setShort("SleepTimer", input); - if (this.autosave) { - savePlayerData(); - } - } - - public int getTotalExperience() { - return this.compound.getInt("XpTotal"); - } - - public void setTotalExperience(int input) { - this.compound.setInt("XpTotal", input); - if (this.autosave) { - savePlayerData(); - } - } - - public Vector getVelocity() { - NBTTagList list = this.compound.getList("Motion", 6); - return new Vector(list.e(0), list.e(1), list.e(2)); - } - - public void setVelocity(Vector vector) { - NBTTagList motion = new NBTTagList(); - motion.add(new NBTTagDouble(vector.getX())); - motion.add(new NBTTagDouble(vector.getY())); - motion.add(new NBTTagDouble(vector.getZ())); - this.compound.set("Motion", motion); - if (this.autosave) { - savePlayerData(); - } - } - - public float getWalkSpeed() { - return this.compound.getCompound("abilities").getFloat("walkSpeed"); - } - - public void setWalkSpeed(float speed) { - this.compound.getCompound("abilities").setFloat("walkSpeed", speed); - if (this.autosave) { - savePlayerData(); - } - } -} -/* - * Copyright (C) 2013 one4me@github.com - */ diff --git a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java index 2aba9c5262..92faf47516 100644 --- a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java +++ b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java @@ -1,8 +1,10 @@ package net.aufdemrand.denizen.nms.helpers; import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1; import net.aufdemrand.denizen.nms.interfaces.EntityHelper; import net.aufdemrand.denizen.nms.util.Utilities; +import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag; import net.minecraft.server.v1_10_R1.*; import org.bukkit.Location; import org.bukkit.World; @@ -72,6 +74,18 @@ public void setTarget(Creature entity, LivingEntity target) { entity.setTarget(target); } + @Override + public CompoundTag getNbtData(Entity entity) { + NBTTagCompound compound = new NBTTagCompound(); + ((CraftEntity) entity).getHandle().c(compound); + return CompoundTag_v1_10_R1.fromNMSTag(compound); + } + + @Override + public void setNbtData(Entity entity, CompoundTag compoundTag) { + ((CraftEntity) entity).getHandle().f(((CompoundTag_v1_10_R1) compoundTag).toNMSTag()); + } + /* Entity Movement */ diff --git a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/ItemHelper_v1_10_R1.java b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/ItemHelper_v1_10_R1.java index b5e74c3bf8..32a2b77f8b 100644 --- a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/ItemHelper_v1_10_R1.java +++ b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/ItemHelper_v1_10_R1.java @@ -72,4 +72,11 @@ public CompoundTag getNbtData(ItemStack itemStack) { } return new CompoundTag_v1_10_R1(new HashMap()); } + + @Override + public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) { + net.minecraft.server.v1_10_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + nmsItemStack.setTag(((CompoundTag_v1_10_R1) compoundTag).toNMSTag()); + return CraftItemStack.asBukkitCopy(nmsItemStack); + } } diff --git a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_10_R1.java b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_10_R1.java index ce9d170c78..da647def9f 100644 --- a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_10_R1.java +++ b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_10_R1.java @@ -1,6 +1,8 @@ package net.aufdemrand.denizen.nms.helpers; import com.mojang.authlib.GameProfile; +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; +import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_10_R1; import net.aufdemrand.denizen.nms.interfaces.PlayerHelper; import net.minecraft.server.v1_10_R1.MinecraftServer; import net.minecraft.server.v1_10_R1.OpList; @@ -8,11 +10,14 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutGameStateChange; import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.OfflinePlayer; import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.UUID; + public class PlayerHelper_v1_10_R1 implements PlayerHelper { @Override @@ -47,4 +52,14 @@ public void showEndCredits(Player player) { ((CraftPlayer) player).getHandle().playerConnection .sendPacket(new PacketPlayOutGameStateChange(4, 0.0F)); } + + @Override + public ImprovedOfflinePlayer getOfflineData(UUID uuid) { + return new ImprovedOfflinePlayer_v1_10_R1(uuid); + } + + @Override + public ImprovedOfflinePlayer getOfflineData(OfflinePlayer offlinePlayer) { + return new ImprovedOfflinePlayer_v1_10_R1(offlinePlayer.getUniqueId()); + } } diff --git a/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/impl/ImprovedOfflinePlayer_v1_10_R1.java b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/impl/ImprovedOfflinePlayer_v1_10_R1.java new file mode 100644 index 0000000000..9290b4cebf --- /dev/null +++ b/v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/impl/ImprovedOfflinePlayer_v1_10_R1.java @@ -0,0 +1,123 @@ +package net.aufdemrand.denizen.nms.impl; + +import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer; +import net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1; +import net.minecraft.server.v1_10_R1.*; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryPlayer; +import org.bukkit.inventory.Inventory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.UUID; + +public class ImprovedOfflinePlayer_v1_10_R1 extends ImprovedOfflinePlayer { + + public ImprovedOfflinePlayer_v1_10_R1(UUID playeruuid) { + super(playeruuid); + } + + @Override + public org.bukkit.inventory.PlayerInventory getInventory() { + if (offlineInventories.containsKey(getUniqueId())) { + return offlineInventories.get(getUniqueId()); + } + PlayerInventory inventory = new PlayerInventory(null); + inventory.b(((CompoundTag_v1_10_R1) this.compound).toNMSTag().getList("Inventory", 10)); + org.bukkit.inventory.PlayerInventory inv = new CraftInventoryPlayer(inventory); + offlineInventories.put(getUniqueId(), inv); + return inv; + } + + @Override + public void setInventory(org.bukkit.inventory.PlayerInventory inventory) { + CraftInventoryPlayer inv = (CraftInventoryPlayer) inventory; + NBTTagCompound nbtTagCompound = ((CompoundTag_v1_10_R1) compound).toNMSTag(); + nbtTagCompound.set("Inventory", inv.getInventory().a(new NBTTagList())); + this.compound = CompoundTag_v1_10_R1.fromNMSTag(nbtTagCompound); + if (this.autosave) { + savePlayerData(); + } + } + + @Override + public Inventory getEnderChest() { + if (offlineEnderChests.containsKey(getUniqueId())) { + return offlineEnderChests.get(getUniqueId()); + } + InventoryEnderChest endchest = new InventoryEnderChest(); + endchest.a(((CompoundTag_v1_10_R1) this.compound).toNMSTag().getList("EnderItems", 10)); + org.bukkit.inventory.Inventory inv = new CraftInventory(endchest); + offlineEnderChests.put(getUniqueId(), inv); + return inv; + } + + @Override + public void setEnderChest(Inventory inventory) { + NBTTagCompound nbtTagCompound = ((CompoundTag_v1_10_R1) compound).toNMSTag(); + nbtTagCompound.set("EnderItems", ((InventoryEnderChest) ((CraftInventory) inventory).getInventory()).h()); + this.compound = CompoundTag_v1_10_R1.fromNMSTag(nbtTagCompound); + if (this.autosave) { + savePlayerData(); + } + } + + @Override + public double getMaxHealth() { + return getAttributes().a("generic.maxHealth").getValue(); + } + + @Override + public void setMaxHealth(double input) { + AttributeMapBase attributes = getAttributes(); + attributes.a("generic.maxHealth").setValue(input); + setAttributes(attributes); + } + + private AttributeMapBase getAttributes() { + AttributeMapBase amb = new AttributeMapServer(); + GenericAttributes.a(amb, ((CompoundTag_v1_10_R1) this.compound).toNMSTag().getList("Attributes", 0)); + return amb; + } + + public void setAttributes(AttributeMapBase attributes) { + NBTTagCompound nbtTagCompound = ((CompoundTag_v1_10_R1) compound).toNMSTag(); + nbtTagCompound.set("Attributes", GenericAttributes.a(attributes)); + this.compound = CompoundTag_v1_10_R1.fromNMSTag(nbtTagCompound); + if (this.autosave) { + savePlayerData(); + } + } + + @Override + protected boolean loadPlayerData(UUID uuid) { + try { + this.player = uuid; + for (org.bukkit.World w : Bukkit.getWorlds()) { + this.file = new File(w.getWorldFolder(), "playerdata" + File.separator + this.player + ".dat"); + if (this.file.exists()) { + this.compound = CompoundTag_v1_10_R1.fromNMSTag(NBTCompressedStreamTools.a(new FileInputStream(this.file))); + return true; + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + return false; + } + + @Override + public void savePlayerData() { + if (this.exists) { + try { + NBTCompressedStreamTools.a(((CompoundTag_v1_10_R1) this.compound).toNMSTag(), new FileOutputStream(this.file)); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } +}