Skip to content

Commit 68ced21

Browse files
committed
Markers are now added whenever BlueMapAPI is enabled.
Even after /bluemap reload
1 parent 5e993ec commit 68ced21

File tree

1 file changed

+27
-40
lines changed

1 file changed

+27
-40
lines changed

src/com/frosthex/timingsystem/bluemap/TimingSystemBlueMapPlugin.java

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,50 +71,37 @@ public void onEnable() {
7171
}
7272
}
7373

74-
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
74+
BlueMapAPI.onEnable(api -> {
75+
// When BlueMap is enabled, run this code. Also works for /bluemap reload.
76+
MarkerSet markerSet = MarkerSet.builder().label("TimingSystem Track Locations").toggleable(true).build();
7577

76-
@Override
77-
public void run() {
78-
Messager.msgConsole("&6Adding track POI markers to BlueMap...");
79-
Optional<BlueMapAPI> possibleApi = BlueMapAPI.getInstance();
80-
if (!possibleApi.isPresent()) {
81-
Messager.msgConsole("&cBlueMapAPI wasn't ready. Cancelling marker addition...");
82-
return;
83-
}
84-
Messager.msgConsole("&6BlueMapAPI was ready...");
85-
BlueMapAPI api = possibleApi.get();
86-
87-
MarkerSet markerSet = MarkerSet.builder().label("TimingSystem Track Locations").toggleable(true).build();
78+
for (Track track : TimingSystemAPI.getTracks()) {
79+
double x = track.getSpawnLocation().getX();
80+
double y = track.getSpawnLocation().getY();
81+
double z = track.getSpawnLocation().getZ();
8882

89-
for (Track track : TimingSystemAPI.getTracks()) {
90-
double x = track.getSpawnLocation().getX();
91-
double y = track.getSpawnLocation().getY();
92-
double z = track.getSpawnLocation().getZ();
93-
94-
POIMarker marker = POIMarker.builder()
95-
.label(track.getCommandName())
96-
.position(x, y, z)
97-
.maxDistance(1000)
98-
.build();
99-
100-
markerSet.getMarkers().put("tt-" + track.getCommandName(), marker);
101-
102-
Optional<BlueMapWorld> possibleWorld = api.getWorld(track.getSpawnLocation().getWorld());
103-
if (!possibleWorld.isPresent()) {
104-
Messager.msgConsole("&cBlueMapWorld wasn't able to be found... Cancelling...");
105-
return;
106-
}
107-
Messager.msgConsole("&6BlueMapWorld loaded... Attempting to add the marker set...");
108-
BlueMapWorld blueWorld = possibleWorld.get();
83+
POIMarker marker = POIMarker.builder()
84+
.label(track.getCommandName())
85+
.detail("Total Finishes: " + track.getTotalFinishes())
86+
.position(x, y, z)
87+
.maxDistance(10000)
88+
.build();
89+
90+
Optional<BlueMapWorld> possibleWorld = api.getWorld(track.getSpawnLocation().getWorld());
91+
if (!possibleWorld.isPresent()) {
92+
Messager.msgConsole("&cBlueMapWorld wasn't able to be found... Skipping adding marker for track " + track.getCommandName());
93+
continue;
94+
}
95+
BlueMapWorld blueWorld = possibleWorld.get();
10996

110-
for (BlueMapMap map : blueWorld.getMaps()) {
111-
map.getMarkerSets().put("timingsystem-bluemap-tracks", markerSet);
112-
}
113-
114-
}
115-
97+
markerSet.getMarkers().put("tt-" + track.getCommandName(), marker);
98+
99+
for (BlueMapMap map : blueWorld.getMaps()) {
100+
map.getMarkerSets().put("timingsystem-bluemap-tracks", markerSet);
101+
}
102+
116103
}
117-
}, 20*60);
104+
});
118105
}
119106

120107
public static TimingSystemBlueMapPlugin getInstance() {

0 commit comments

Comments
 (0)