-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
MapObject.java
91 lines (76 loc) · 3.24 KB
/
MapObject.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
package com.denizenscript.denizen.utilities.maps;
import com.denizenscript.denizen.objects.dPlayer;
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizencore.objects.aH;
import com.denizenscript.denizencore.tags.TagManager;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapView;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public abstract class MapObject {
protected String xTag;
protected String yTag;
protected String visibilityTag = "true";
protected Map<UUID, Integer> currentX = new HashMap<>();
protected Map<UUID, Integer> currentY = new HashMap<>();
protected Map<UUID, Boolean> currentVisibility = new HashMap<>();
protected boolean debug;
public MapView lastMap;
public boolean worldCoordinates = false;
public MapObject(String xTag, String yTag, String visibilityTag, boolean debug) {
this.xTag = xTag;
this.yTag = yTag;
this.visibilityTag = visibilityTag;
this.debug = debug;
}
public void update(dPlayer player, UUID uuid) {
currentX.put(uuid, getX(player, uuid));
currentY.put(uuid, getY(player, uuid));
currentVisibility.put(uuid, aH.getBooleanFrom(tag(visibilityTag, player)));
}
public int getX(dPlayer player, UUID uuid) {
//if (!currentX.containsKey(uuid)) {
int x = (int) aH.getDoubleFrom(tag(xTag, player));
currentX.put(uuid, x);
//}
if (worldCoordinates && lastMap != null) {
float f = (float) (x - lastMap.getCenterX()) / (1 << (lastMap.getScale().getValue()));
int bx = ((int) ((f * 2.0F) + 0.5D));
return (bx < -127 ? -127 : (bx > 127 ? 127 : bx));
}
return x;
}
public int getY(dPlayer player, UUID uuid) {
//if (!currentY.containsKey(uuid)) {
int y = (int) aH.getDoubleFrom(tag(yTag, player));
currentY.put(uuid, y);
//}
if (worldCoordinates && lastMap != null) {
float f1 = (float) (y - lastMap.getCenterZ()) / (1 << (lastMap.getScale().getValue()));
int by = ((int) ((f1 * 2.0F) + 0.5D));
return (by < -127 ? -127 : (by > 127 ? 127 : by));
}
return y;
}
public boolean isVisibleTo(dPlayer player, UUID uuid) {
if (!currentVisibility.containsKey(uuid)) {
currentVisibility.put(uuid, tag(visibilityTag, player).equalsIgnoreCase("true"));
}
return currentVisibility.get(uuid);
}
protected String tag(String arg, dPlayer player) {
// Short, reusable TagManager call
return TagManager.tag(arg, new BukkitTagContext(player, player.getSelectedNPC(), false, null, debug, null));
}
public Map<String, Object> getSaveData() {
Map<String, Object> data = new HashMap<>();
data.put("x", xTag);
data.put("y", yTag);
data.put("visibility", visibilityTag);
data.put("debug", debug ? "true" : "false");
data.put("world_coordinates", worldCoordinates ? "true" : "false");
return data;
}
public abstract void render(MapView mapView, MapCanvas mapCanvas, dPlayer player, UUID uuid);
}