mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-25 03:35:18 +01:00
Add support for showing spawn points as map markers
This commit is contained in:
parent
89f63a9db2
commit
5adbe6bd5e
@ -50,6 +50,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.ChunkPopulateEvent;
|
import org.bukkit.event.world.ChunkPopulateEvent;
|
||||||
|
import org.bukkit.event.world.SpawnChangeEvent;
|
||||||
import org.bukkit.event.world.WorldListener;
|
import org.bukkit.event.world.WorldListener;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -1098,6 +1099,16 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void onSpawnChange(SpawnChangeEvent event) {
|
||||||
|
/* Call listeners */
|
||||||
|
List<Listener> ll = event_handlers.get(event.getType());
|
||||||
|
if(ll != null) {
|
||||||
|
for(Listener l : ll) {
|
||||||
|
((WorldListener)l).onSpawnChange(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private CustomEventListener ourCustomEventHandler = new CustomEventListener() {
|
private CustomEventListener ourCustomEventHandler = new CustomEventListener() {
|
||||||
@ -1158,6 +1169,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
case WORLD_LOAD:
|
case WORLD_LOAD:
|
||||||
case CHUNK_LOAD:
|
case CHUNK_LOAD:
|
||||||
case CHUNK_POPULATED:
|
case CHUNK_POPULATED:
|
||||||
|
case SPAWN_CHANGE:
|
||||||
pm.registerEvent(type, ourWorldEventHandler, Event.Priority.Monitor, this);
|
pm.registerEvent(type, ourWorldEventHandler, Event.Priority.Monitor, this);
|
||||||
break;
|
break;
|
||||||
case CUSTOM_EVENT:
|
case CUSTOM_EVENT:
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package org.dynmap;
|
package org.dynmap;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.world.SpawnChangeEvent;
|
||||||
|
import org.bukkit.event.world.WorldListener;
|
||||||
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
import org.dynmap.markers.Marker;
|
||||||
|
import org.dynmap.markers.MarkerIcon;
|
||||||
|
import org.dynmap.markers.MarkerSet;
|
||||||
import org.dynmap.markers.impl.MarkerAPIImpl;
|
import org.dynmap.markers.impl.MarkerAPIImpl;
|
||||||
import org.dynmap.markers.impl.MarkerSignManager;
|
import org.dynmap.markers.impl.MarkerSignManager;
|
||||||
|
|
||||||
@ -9,6 +17,9 @@ import org.dynmap.markers.impl.MarkerSignManager;
|
|||||||
public class MarkersComponent extends ClientComponent {
|
public class MarkersComponent extends ClientComponent {
|
||||||
private MarkerAPIImpl api;
|
private MarkerAPIImpl api;
|
||||||
private MarkerSignManager signmgr;
|
private MarkerSignManager signmgr;
|
||||||
|
private MarkerIcon spawnicon;
|
||||||
|
private String spawnlbl;
|
||||||
|
|
||||||
public MarkersComponent(DynmapPlugin plugin, ConfigurationNode configuration) {
|
public MarkersComponent(DynmapPlugin plugin, ConfigurationNode configuration) {
|
||||||
super(plugin, configuration);
|
super(plugin, configuration);
|
||||||
/* Register API with plugin */
|
/* Register API with plugin */
|
||||||
@ -18,7 +29,55 @@ public class MarkersComponent extends ClientComponent {
|
|||||||
if(configuration.getBoolean("enablesigns", false)) {
|
if(configuration.getBoolean("enablesigns", false)) {
|
||||||
signmgr = MarkerSignManager.initializeSignManager(plugin);
|
signmgr = MarkerSignManager.initializeSignManager(plugin);
|
||||||
}
|
}
|
||||||
|
/* If we're posting spawn point markers, initialize and add world listener */
|
||||||
|
if(configuration.getBoolean("showspawn", false)) {
|
||||||
|
String ico = configuration.getString("spawnicon", MarkerIcon.WORLD);
|
||||||
|
spawnlbl = configuration.getString("spawnlabel", "Spawn");
|
||||||
|
spawnicon = api.getMarkerIcon(ico); /* Load it */
|
||||||
|
if(spawnicon == null) {
|
||||||
|
spawnicon = api.getMarkerIcon(MarkerIcon.WORLD);
|
||||||
|
}
|
||||||
|
WorldListener wl = new WorldListener() {
|
||||||
|
public void onWorldLoad(WorldLoadEvent event) {
|
||||||
|
World w = event.getWorld(); /* Get the world */
|
||||||
|
Location loc = w.getSpawnLocation(); /* Get location of spawn */
|
||||||
|
if(loc != null)
|
||||||
|
addUpdateWorld(w, loc);
|
||||||
|
}
|
||||||
|
public void onSpawnChange(SpawnChangeEvent event) {
|
||||||
|
World w = event.getWorld(); /* Get the world */
|
||||||
|
Location loc = w.getSpawnLocation(); /* Get location of spawn */
|
||||||
|
if(loc != null)
|
||||||
|
addUpdateWorld(w, loc);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
plugin.registerEvent(org.bukkit.event.Event.Type.WORLD_LOAD, wl);
|
||||||
|
plugin.registerEvent(org.bukkit.event.Event.Type.SPAWN_CHANGE, wl);
|
||||||
|
/* Initialize already loaded worlds */
|
||||||
|
for(DynmapWorld w : plugin.getMapManager().getWorlds()) {
|
||||||
|
World world = w.world;
|
||||||
|
Location loc = world.getSpawnLocation();
|
||||||
|
if(loc != null)
|
||||||
|
addUpdateWorld(world, loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addUpdateWorld(World w, Location loc) {
|
||||||
|
MarkerSet ms = api.getMarkerSet(MarkerSet.DEFAULT);
|
||||||
|
if(ms != null) {
|
||||||
|
String spawnid = "_spawn_" + w.getName();
|
||||||
|
Marker m = ms.findMarker(spawnid); /* See if defined */
|
||||||
|
if(m == null) { /* Not defined yet, add it */
|
||||||
|
ms.createMarker(spawnid, spawnlbl, w.getName(), loc.getX(), loc.getY(), loc.getZ(),
|
||||||
|
spawnicon, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m.setLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if(signmgr != null) {
|
if(signmgr != null) {
|
||||||
|
@ -8,6 +8,8 @@ public interface MarkerIcon {
|
|||||||
public static final String DEFAULT = "default";
|
public static final String DEFAULT = "default";
|
||||||
/** Default sign marker icon - always exists */
|
/** Default sign marker icon - always exists */
|
||||||
public static final String SIGN = "sign";
|
public static final String SIGN = "sign";
|
||||||
|
/** Default world marker icon - always exists */
|
||||||
|
public static final String WORLD = "world";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ID of the marker icon (unique among marker icons)
|
* Get ID of the marker icon (unique among marker icons)
|
||||||
|
@ -49,6 +49,12 @@ components:
|
|||||||
#enablesigns: true
|
#enablesigns: true
|
||||||
# If set, make markers layer hidden by default
|
# If set, make markers layer hidden by default
|
||||||
#hidebydefault: true
|
#hidebydefault: true
|
||||||
|
# If set, show spawn points on each world
|
||||||
|
showspawn: true
|
||||||
|
# Marker used for spawn point
|
||||||
|
spawnicon: world
|
||||||
|
# Label for spawn points
|
||||||
|
spawnlabel: "Spawn"
|
||||||
|
|
||||||
- class: org.dynmap.ClientComponent
|
- class: org.dynmap.ClientComponent
|
||||||
type: chat
|
type: chat
|
||||||
|
Loading…
Reference in New Issue
Block a user