/
MapText.java
65 lines (55 loc) · 2.2 KB
/
MapText.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
package com.denizenscript.denizen.utilities.maps;
import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import org.bukkit.Color;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapPalette;
import org.bukkit.map.MapView;
import org.bukkit.map.MinecraftFont;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class MapText extends MapObject {
protected String textTag, colorTag;
protected Map<UUID, String> playerTexts = new HashMap<>();
public MapText(String xTag, String yTag, String visibilityTag, boolean debug, String textTag, String colorTag) {
super(xTag, yTag, visibilityTag, debug);
this.textTag = textTag;
this.colorTag = colorTag;
}
@Override
public void update(PlayerTag player, UUID uuid) {
super.update(player, uuid);
playerTexts.put(uuid, tag(textTag, player));
}
public String getText(PlayerTag player) {
return playerTexts.get(player.getPlayerEntity().getUniqueId());
}
public void setText(String textTag) {
this.textTag = textTag;
}
@Override
public Map<String, Object> getSaveData() {
Map<String, Object> data = super.getSaveData();
data.put("type", "TEXT");
data.put("text", textTag);
data.put("color", colorTag);
return data;
}
@Override
public void render(MapView mapView, MapCanvas mapCanvas, PlayerTag player, UUID uuid) {
try {
if (!playerTexts.containsKey(uuid)) {
playerTexts.put(uuid, tag(textTag, player));
}
Color color = ColorTag.valueOf(colorTag == null ? "black" : tag(colorTag, player), getTagContext(player)).getColor();
byte b = MapPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue());
String text = ((char) 167) + Byte.toString(b) + ((char) 59) + getText(player);
mapCanvas.drawText(getX(player), getY(player), MinecraftFont.Font, text);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
}