-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
MapDot.java
55 lines (48 loc) · 1.88 KB
/
MapDot.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
package com.denizenscript.denizen.utilities.maps;
import com.denizenscript.denizen.objects.ColorTag;
import com.denizenscript.denizen.objects.PlayerTag;
import org.bukkit.Color;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapPalette;
import org.bukkit.map.MapView;
import java.util.Map;
import java.util.UUID;
public class MapDot extends MapObject {
protected String radiusTag;
protected String colorTag;
public MapDot(String xTag, String yTag, String visibilityTag, boolean debug, String radiusTag, String colorTag) {
super(xTag, yTag, visibilityTag, debug);
this.radiusTag = radiusTag;
this.colorTag = colorTag;
}
@Override
public Map<String, Object> getSaveData() {
Map<String, Object> data = super.getSaveData();
data.put("type", "DOT");
data.put("radius", radiusTag);
data.put("color", colorTag);
return data;
}
@Override
public void render(MapView mapView, MapCanvas mapCanvas, PlayerTag player, UUID uuid) {
int baseX = getX(player, uuid);
int baseY = getY(player, uuid);
int radius = (int) Double.parseDouble(tag(radiusTag, player));
Color color = ColorTag.valueOf(tag(colorTag, player)).getColor();
for (int x = -radius; x < radius; x++) {
int finalX = baseX + x;
if (finalX >= 128) {
continue;
}
for (int y = -radius; y < radius; y++) {
int finalY = baseY + y;
if (finalY >= 128) {
continue;
}
if (((x + 0.5) * (x + 0.5)) + ((y + 0.5) * (y + 0.5)) <= (radius * radius)) {
mapCanvas.setPixel(finalX, finalY, MapPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue()));
}
}
}
}
}