/
ImprovedOfflinePlayer_v1_12_R1.java
144 lines (129 loc) · 5.63 KB
/
ImprovedOfflinePlayer_v1_12_R1.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package net.aufdemrand.denizen.nms.impl;
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_12_R1;
import net.minecraft.server.v1_12_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
import org.bukkit.craftbukkit.v1_12_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_12_R1 extends ImprovedOfflinePlayer {
public ImprovedOfflinePlayer_v1_12_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_12_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_12_R1) compound).toNMSTag();
nbtTagCompound.set("Inventory", inv.getInventory().a(new NBTTagList()));
this.compound = CompoundTag_v1_12_R1.fromNMSTag(nbtTagCompound);
if (this.autosave) {
savePlayerData();
}
}
@Override
public Inventory getEnderChest() {
if (offlineEnderChests.containsKey(getUniqueId())) {
return offlineEnderChests.get(getUniqueId());
}
InventoryEnderChest endchest = new InventoryEnderChest(null);
endchest.a(((CompoundTag_v1_12_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_12_R1) compound).toNMSTag();
nbtTagCompound.set("EnderItems", ((InventoryEnderChest) ((CraftInventory) inventory).getInventory()).i());
this.compound = CompoundTag_v1_12_R1.fromNMSTag(nbtTagCompound);
if (this.autosave) {
savePlayerData();
}
}
@Override
public double getMaxHealth() {
AttributeInstance maxHealth = getAttributes().a(GenericAttributes.maxHealth);
return maxHealth == null ? GenericAttributes.maxHealth.getDefault() : maxHealth.getValue();
}
@Override
public void setMaxHealth(double input) {
AttributeMapBase attributes = getAttributes();
AttributeInstance maxHealth = attributes.a(GenericAttributes.maxHealth);
if (maxHealth == null) {
maxHealth = attributes.b(GenericAttributes.maxHealth);
}
maxHealth.setValue(input);
setAttributes(attributes);
}
private AttributeMapBase getAttributes() {
AttributeMapBase amb = new AttributeMapServer();
initAttributes(amb);
GenericAttributes.a(amb, ((CompoundTag_v1_12_R1) this.compound).toNMSTag().getList("Attributes", 10));
return amb;
}
private void initAttributes(AttributeMapBase amb) {
// ===== from EntityHuman superclass (EntityLiving) =====
amb.b(GenericAttributes.maxHealth);
amb.b(GenericAttributes.c);
//this.getAttributeMap().b(GenericAttributes.MOVEMENT_SPEED); -- merged below to simplify code
amb.b(GenericAttributes.h);
amb.b(GenericAttributes.i);
// ===== from EntityHuman =====
amb.b(GenericAttributes.ATTACK_DAMAGE).setValue(1.0D);
//this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.10000000149011612D); -- merged below
amb.b(GenericAttributes.MOVEMENT_SPEED).setValue(0.10000000149011612D);
amb.b(GenericAttributes.g);
amb.b(GenericAttributes.j);
}
public void setAttributes(AttributeMapBase attributes) {
NBTTagCompound nbtTagCompound = ((CompoundTag_v1_12_R1) compound).toNMSTag();
nbtTagCompound.set("Attributes", GenericAttributes.a(attributes));
this.compound = CompoundTag_v1_12_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_12_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_12_R1) this.compound).toNMSTag(), new FileOutputStream(this.file));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}