/
Entity.java
144 lines (116 loc) · 3.48 KB
/
Entity.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.utilities.arguments;
import net.aufdemrand.denizen.interfaces.dScriptArgument;
import net.aufdemrand.denizen.tags.Attribute;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import org.bukkit.entity.LivingEntity;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Entity implements dScriptArgument {
public static Map<String, Entity> entities = new HashMap<String, Entity>();
/**
* Gets a saved location based on an Id.
*
* @param id the Id key of the location
* @return the Location associated
*/
public static Entity getSavedEntity(String id) {
if (entities.containsKey(id.toUpperCase()))
return entities.get(id.toUpperCase());
else return null;
}
public static void saveEntity(Entity entity) {
if (entity.id == null) return;
entities.put(entity.id.toUpperCase(), entity);
}
/**
* Checks if there is a saved item with this Id.
*
* @param id the Id to check
* @return true if it exists, false if not
*/
public static boolean isSavedEntity(String id) {
return entities.containsKey(id.toUpperCase());
}
/**
* Called on server startup or /denizen reload locations. Should probably not be called manually.
*/
public static void _recallEntities() {
List<Map<?, ?>> entitylist = DenizenAPI.getCurrentInstance().getSaves().getMapList("dScript.Entities");
entities.clear();
// TODO: Figure out de-serialization of this.
}
/**
* Called by Denizen internally on a server shutdown or /denizen save. Should probably
* not be called manually.
*/
public static void _saveEntities() {
// TODO: Figure out serialization
}
/**
* Gets a Item Object from a string form.
*
* @param string the string or dScript argument String
* @return an Item, or null if incorrectly formatted
*
*/
public static Entity valueOf(String string) {
// Create entity!
return null;
}
private String id = null;
private String prefix = "Entity";
LivingEntity entity;
public Entity(LivingEntity entity) {
this.entity = entity;
}
public Entity(String id, LivingEntity entity) {
this.entity = entity;
this.id = id;
saveEntity(this);
}
public void identifyAs(String id) {
if (this.id == null) {
this.id = id;
saveEntity(this);
}
}
public LivingEntity getBukkitEntity() {
return entity;
}
public boolean isAlive() {
return entity != null;
}
public Entity setId(String id) {
this.id = id.toUpperCase();
return this;
}
@Override
public String getDefaultPrefix() {
return prefix;
}
@Override
public String debug() {
return null;
}
@Override
public String as_dScriptArg() {
return null;
}
public String dScriptArgValue() {
return getDefaultPrefix().toLowerCase() + ":" + as_dScriptArg();
}
@Override
public String toString() {
return entity.getUniqueId().toString();
}
@Override
public dScriptArgument setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public String getAttribute(Attribute attribute) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}