Add support for optional spawn-bed layer (show player's spawn beds)

This commit is contained in:
Mike Primm 2012-01-04 23:34:32 -06:00
parent a8c1558e3c
commit 08fc4145b1
5 changed files with 107 additions and 15 deletions

View File

@ -44,6 +44,7 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
@ -1462,7 +1463,18 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
} }
} }
} }
@Override
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerBedLeave(event);
}
}
}
@Override @Override
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
/* Call listeners */ /* Call listeners */
@ -1560,6 +1572,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
case PLAYER_JOIN: case PLAYER_JOIN:
case PLAYER_QUIT: case PLAYER_QUIT:
case PLAYER_MOVE: case PLAYER_MOVE:
case PLAYER_BED_LEAVE:
pm.registerEvent(type, ourPlayerEventHandler, Event.Priority.Monitor, this); pm.registerEvent(type, ourPlayerEventHandler, Event.Priority.Monitor, this);
break; break;
case BLOCK_PLACE: case BLOCK_PLACE:

View File

@ -5,6 +5,7 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -27,8 +28,11 @@ public class MarkersComponent extends ClientComponent {
private String spawnlbl; private String spawnlbl;
private MarkerSet offlineset; private MarkerSet offlineset;
private MarkerIcon offlineicon; private MarkerIcon offlineicon;
private MarkerSet spawnbedset;
private MarkerIcon spawnbedicon;
private static final String OFFLINE_PLAYERS_SETID = "offline_players"; private static final String OFFLINE_PLAYERS_SETID = "offline_players";
private static final String PLAYER_SPAWN_BED_SETID = "spawn_beds";
public MarkersComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { public MarkersComponent(final DynmapPlugin plugin, ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
@ -123,6 +127,72 @@ public class MarkersComponent extends ClientComponent {
offlineset.deleteMarkerSet(); offlineset.deleteMarkerSet();
} }
} }
/* If showing player spawn bed locations as markers */
if(configuration.getBoolean("showspawnbeds", false)) {
/* Make set, if needed */
spawnbedset = api.getMarkerSet(PLAYER_SPAWN_BED_SETID);
if(spawnbedset == null) {
spawnbedset = api.createMarkerSet(PLAYER_SPAWN_BED_SETID, configuration.getString("spawnbedlabel", "Spawn Beds"), null, true);
}
spawnbedset.setHideByDefault(configuration.getBoolean("spawnbedhidebydefault", true));
spawnbedset.setMinZoom(configuration.getInteger("spawnbedminzoom", 0));
spawnbedicon = api.getMarkerIcon(configuration.getString("spawnbedicon", "bed"));
final String spawnbedformat = configuration.getString("spawnbedformat", "%name%'s bed");
/* Add listener for players coming and going */
PlayerListener pl = new PlayerListener() {
private void updatePlayer(Player p) {
Location bl = p.getBedSpawnLocation();
Marker m = spawnbedset.findMarker(p.getName()+"_bed");
if(bl == null) { /* No bed location */
if(m != null) {
m.deleteMarker();
}
}
else {
if(m != null)
m.setLocation(bl.getWorld().getName(), bl.getX(), bl.getY(), bl.getZ());
else
m = spawnbedset.createMarker(p.getName()+"_bed", spawnbedformat.replace("%name%", ChatColor.stripColor(p.getDisplayName())), false,
bl.getWorld().getName(), bl.getX(), bl.getY(), bl.getZ(),
spawnbedicon, true);
}
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
updatePlayer(p);
}
@Override
public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
final Player p = event.getPlayer();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
updatePlayer(p);
}
});
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
Player p = event.getPlayer();
Marker m = spawnbedset.findMarker(p.getName()+"_bed");
if(m != null) {
m.deleteMarker();
}
}
};
plugin.registerEvent(Type.PLAYER_JOIN, pl);
plugin.registerEvent(Type.PLAYER_QUIT, pl);
plugin.registerEvent(Type.PLAYER_BED_LEAVE, pl);
}
else {
/* Make set, if needed */
spawnbedset = api.getMarkerSet(PLAYER_SPAWN_BED_SETID);
if(spawnbedset != null) {
spawnbedset.deleteMarkerSet();
}
}
} }
private void addUpdateWorld(World w, Location loc) { private void addUpdateWorld(World w, Location loc) {

View File

@ -63,7 +63,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
/* Built-in icons */ /* Built-in icons */
private static final String[] builtin_icons = { private static final String[] builtin_icons = {
"anchor", "bank", "basket", "beer", "bighouse", "blueflag", "bomb", "bookshelf", "bricks", "bronzemedal", "bronzestar", "anchor", "bank", "basket", "bed", "beer", "bighouse", "blueflag", "bomb", "bookshelf", "bricks", "bronzemedal", "bronzestar",
"building", "cake", "camera", "cart", "caution", "chest", "church", "coins", "comment", "compass", "construction", "building", "cake", "camera", "cart", "caution", "chest", "church", "coins", "comment", "compass", "construction",
"cross", "cup", "cutlery", "default", "diamond", "dog", "door", "down", "drink", "exclamation", "factory", "cross", "cup", "cutlery", "default", "diamond", "dog", "door", "down", "drink", "exclamation", "factory",
"fire", "flower", "gear", "goldmedal", "goldstar", "greenflag", "hammer", "heart", "house", "key", "king", "fire", "flower", "gear", "goldmedal", "goldstar", "greenflag", "hammer", "heart", "house", "key", "king",

View File

@ -67,21 +67,29 @@ components:
# Note: this component is needed for the dmarker commands, and for the Marker API to be available to other plugins # Note: this component is needed for the dmarker commands, and for the Marker API to be available to other plugins
- class: org.dynmap.MarkersComponent - class: org.dynmap.MarkersComponent
type: markers type: markers
#showlabel: true showlabel: false
#enablesigns: true enablesigns: false
# (optional) add spawn point markers to standard marker layer # (optional) add spawn point markers to standard marker layer
showspawn: true showspawn: true
spawnicon: world spawnicon: world
spawnlabel: "Spawn" spawnlabel: "Spawn"
# (optional) layer for showing offline player's positions # (optional) layer for showing offline player's positions
#showofflineplayers: true showofflineplayers: false
#offlinelabel: "Offline" offlinelabel: "Offline"
#offlineicon: offlineuser offlineicon: offlineuser
#offlinehidebydefault: true offlinehidebydefault: true
#offlineminzoom: 0 offlineminzoom: 0
# (optional) layer for showing player's spawn beds
showspawnbeds: false
spawnbedlabel: "Spawn Beds"
spawnbedicon: bed
spawnbedhidebydefault: true
spawnbedminzoom: 0
spawnbedformat: "%name%'s bed"
- class: org.dynmap.ClientComponent - class: org.dynmap.ClientComponent
type: chat type: chat
allowurlname: false
- class: org.dynmap.ClientComponent - class: org.dynmap.ClientComponent
type: chatballoon type: chatballoon
focuschatballoons: false focuschatballoons: false
@ -97,12 +105,13 @@ components:
showplayerhealth: true showplayerhealth: true
# Option to make player faces small - don't use with showplayerhealth # Option to make player faces small - don't use with showplayerhealth
smallplayerfaces: false smallplayerfaces: false
# # Optional - make player faces layer hidden by default # Optional - make player faces layer hidden by default
# hidebydefault: true hidebydefault: false
# # Optional - ordering priority in layer menu (low goes before high - default is 0) # Optional - ordering priority in layer menu (low goes before high - default is 0)
# layerprio: 1 layerprio: 0
# # Optional - label for player marker layer (default is 'Players') # Optional - label for player marker layer (default is 'Players')
# label: "Players" label: "Players"
#- class: org.dynmap.ClientComponent #- class: org.dynmap.ClientComponent
# type: digitalclock # type: digitalclock
- class: org.dynmap.ClientComponent - class: org.dynmap.ClientComponent

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB