/
ImprovedOfflinePlayer_v1_8_R3.java
123 lines (109 loc) · 4.52 KB
/
ImprovedOfflinePlayer_v1_8_R3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package net.aufdemrand.denizen.nms.impl;
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3;
import net.minecraft.server.v1_8_R3.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_8_R3.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_8_R3 extends ImprovedOfflinePlayer {
public ImprovedOfflinePlayer_v1_8_R3(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_8_R3) 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_8_R3) compound).toNMSTag();
nbtTagCompound.set("Inventory", inv.getInventory().a(new NBTTagList()));
this.compound = CompoundTag_v1_8_R3.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_8_R3) this.compound).toNMSTag().getList("EnderItems", 10));
Inventory inv = new CraftInventory(endchest);
offlineEnderChests.put(getUniqueId(), inv);
return inv;
}
@Override
public void setEnderChest(Inventory inventory) {
NBTTagCompound nbtTagCompound = ((CompoundTag_v1_8_R3) compound).toNMSTag();
nbtTagCompound.set("EnderItems", ((InventoryEnderChest) ((CraftInventory) inventory).getInventory()).h());
this.compound = CompoundTag_v1_8_R3.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_8_R3) this.compound).toNMSTag().getList("Attributes", 0));
return amb;
}
public void setAttributes(AttributeMapBase attributes) {
NBTTagCompound nbtTagCompound = ((CompoundTag_v1_8_R3) compound).toNMSTag();
nbtTagCompound.set("Attributes", GenericAttributes.a(attributes));
this.compound = CompoundTag_v1_8_R3.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_8_R3.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_8_R3) this.compound).toNMSTag(), new FileOutputStream(this.file));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}