Checkpoint on split between bukkit-specific and common code core

This commit is contained in:
Mike Primm 2012-01-15 16:58:19 -06:00
parent 9c49054c89
commit b64094795e
50 changed files with 2333 additions and 1477 deletions

View File

@ -11,7 +11,7 @@ import org.json.simple.JSONObject;
public class ClientComponent extends Component { public class ClientComponent extends Component {
private boolean disabled; private boolean disabled;
public ClientComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) { public ClientComponent(final DynmapCore plugin, final ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() { plugin.events.addListener("buildclientconfiguration", new Event.Listener<JSONObject>() {
@Override @Override

View File

@ -3,18 +3,17 @@ package org.dynmap;
import static org.dynmap.JSONUtils.a; import static org.dynmap.JSONUtils.a;
import static org.dynmap.JSONUtils.s; import static org.dynmap.JSONUtils.s;
import org.bukkit.Location;
import org.dynmap.Event.Listener; import org.dynmap.Event.Listener;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class ClientConfigurationComponent extends Component { public class ClientConfigurationComponent extends Component {
public ClientConfigurationComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { public ClientConfigurationComponent(final DynmapCore core, ConfigurationNode configuration) {
super(plugin, configuration); super(core, configuration);
plugin.events.<JSONObject>addListener("buildclientconfiguration", new Listener<JSONObject>() { core.events.<JSONObject>addListener("buildclientconfiguration", new Listener<JSONObject>() {
@Override @Override
public void triggered(JSONObject t) { public void triggered(JSONObject t) {
ConfigurationNode c = plugin.configuration; ConfigurationNode c = core.configuration;
s(t, "confighash", plugin.getConfigHashcode()); s(t, "confighash", core.getConfigHashcode());
s(t, "updaterate", c.getFloat("updaterate", 1.0f)); s(t, "updaterate", c.getFloat("updaterate", 1.0f));
s(t, "showplayerfacesinmenu", c.getBoolean("showplayerfacesinmenu", true)); s(t, "showplayerfacesinmenu", c.getBoolean("showplayerfacesinmenu", true));
s(t, "joinmessage", c.getString("joinmessage", "%playername% joined")); s(t, "joinmessage", c.getString("joinmessage", "%playername% joined"));
@ -23,11 +22,11 @@ public class ClientConfigurationComponent extends Component {
s(t, "webprefix", unescapeString(c.getString("webprefix", "[WEB] "))); s(t, "webprefix", unescapeString(c.getString("webprefix", "[WEB] ")));
s(t, "defaultzoom", c.getInteger("defaultzoom", 0)); s(t, "defaultzoom", c.getInteger("defaultzoom", 0));
s(t, "sidebaropened", c.getString("sidebaropened", "false")); s(t, "sidebaropened", c.getString("sidebaropened", "false"));
s(t, "dynmapversion", plugin.getDescription().getVersion()); s(t, "dynmapversion", core.getDynmapCoreVersion());
s(t, "cyrillic", c.getBoolean("cyrillic-support", false)); s(t, "cyrillic", c.getBoolean("cyrillic-support", false));
s(t, "showlayercontrol", c.getString("showlayercontrol", "true")); s(t, "showlayercontrol", c.getString("showlayercontrol", "true"));
s(t, "grayplayerswhenhidden", c.getBoolean("grayplayerswhenhidden", true)); s(t, "grayplayerswhenhidden", c.getBoolean("grayplayerswhenhidden", true));
String sn = plugin.getServer().getServerName(); String sn = core.getServer().getServerName();
if(sn.equals("Unknown Server")) if(sn.equals("Unknown Server"))
sn = "Minecraft Dynamic Map"; sn = "Minecraft Dynamic Map";
s(t, "title", c.getString("webpage-title", sn)); s(t, "title", c.getString("webpage-title", sn));
@ -36,7 +35,7 @@ public class ClientConfigurationComponent extends Component {
DynmapWorld defaultWorld = null; DynmapWorld defaultWorld = null;
String defmap = null; String defmap = null;
for(DynmapWorld world : plugin.mapManager.getWorlds()) { for(DynmapWorld world : core.mapManager.getWorlds()) {
if (defaultWorld == null) defaultWorld = world; if (defaultWorld == null) defaultWorld = world;
ConfigurationNode wn = world.configuration; ConfigurationNode wn = world.configuration;
JSONObject wo = new JSONObject(); JSONObject wo = new JSONObject();

View File

@ -3,19 +3,14 @@ package org.dynmap;
import static org.dynmap.JSONUtils.a; import static org.dynmap.JSONUtils.a;
import static org.dynmap.JSONUtils.s; import static org.dynmap.JSONUtils.s;
import java.util.Set; import java.util.List;
import org.dynmap.common.DynmapPlayer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.dynmap.utils.BlockLightLevel;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class ClientUpdateComponent extends Component { public class ClientUpdateComponent extends Component {
private BlockLightLevel bll = new BlockLightLevel();
public ClientUpdateComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { public ClientUpdateComponent(final DynmapCore plugin, ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
plugin.events.addListener("buildclientupdate", new Event.Listener<ClientUpdateEvent>() { plugin.events.addListener("buildclientupdate", new Event.Listener<ClientUpdateEvent>() {
@Override @Override
@ -34,17 +29,19 @@ public class ClientUpdateComponent extends Component {
int hideifunder = configuration.getInteger("hideifundercover", 15); int hideifunder = configuration.getInteger("hideifundercover", 15);
boolean hideifsneaking = configuration.getBoolean("hideifsneaking", false); boolean hideifsneaking = configuration.getBoolean("hideifsneaking", false);
s(u, "confighash", plugin.getConfigHashcode()); s(u, "confighash", core.getConfigHashcode());
s(u, "servertime", world.getTime() % 24000); s(u, "servertime", world.getTime() % 24000);
s(u, "hasStorm", world.hasStorm()); s(u, "hasStorm", world.hasStorm());
s(u, "isThundering", world.isThundering()); s(u, "isThundering", world.isThundering());
s(u, "players", new JSONArray()); s(u, "players", new JSONArray());
Player[] players = plugin.playerList.getVisiblePlayers(); List<DynmapPlayer> players = core.playerList.getVisiblePlayers();
for(int i=0;i<players.length;i++) { for(DynmapPlayer p : players) {
Player p = players[i]; DynmapLocation pl = p.getLocation();
Location pl = p.getLocation(); DynmapWorld pw = core.getWorld(pl.world);
if(pw == null)
continue;
JSONObject jp = new JSONObject(); JSONObject jp = new JSONObject();
boolean hide = false; boolean hide = false;
@ -52,16 +49,16 @@ public class ClientUpdateComponent extends Component {
s(jp, "name", Client.stripColor(p.getDisplayName())); s(jp, "name", Client.stripColor(p.getDisplayName()));
s(jp, "account", p.getName()); s(jp, "account", p.getName());
if(hideifshadow < 15) { if(hideifshadow < 15) {
if(pl.getBlock().getLightLevel() <= hideifshadow) if(pw.getLightLevel((int)pl.x, (int)pl.y, (int)pl.z) <= hideifshadow)
hide = true; hide = true;
} }
if(hideifunder < 15) { if(hideifunder < 15) {
if(bll.isReady()) { /* If we can get real sky level */ if(pw.canGetSkyLightLevel()) { /* If we can get real sky level */
if(bll.getSkyLightLevel(pl.getBlock()) <= hideifunder) if(pw.getSkyLightLevel((int)pl.x, (int)pl.y, (int)pl.z) <= hideifunder)
hide = true; hide = true;
} }
else { else {
if(pl.getWorld().getHighestBlockYAt(pl) > pl.getBlockY()) if(pw.getHighestBlockYAt((int)pl.x, (int)pl.z) > pl.y)
hide = true; hide = true;
} }
} }
@ -69,14 +66,14 @@ public class ClientUpdateComponent extends Component {
hide = true; hide = true;
/* Don't leak player location for world not visible on maps, or if sendposition disbaled */ /* Don't leak player location for world not visible on maps, or if sendposition disbaled */
DynmapWorld pworld = MapManager.mapman.worldsLookup.get(p.getWorld().getName()); DynmapWorld pworld = MapManager.mapman.worldsLookup.get(pl.world);
/* Fix typo on 'sendpositon' to 'sendposition', keep bad one in case someone used it */ /* Fix typo on 'sendpositon' to 'sendposition', keep bad one in case someone used it */
if(configuration.getBoolean("sendposition", true) && configuration.getBoolean("sendpositon", true) && if(configuration.getBoolean("sendposition", true) && configuration.getBoolean("sendpositon", true) &&
(pworld != null) && pworld.sendposition && (!hide)) { (pworld != null) && pworld.sendposition && (!hide)) {
s(jp, "world", p.getWorld().getName()); s(jp, "world", pl.world);
s(jp, "x", pl.getX()); s(jp, "x", pl.x);
s(jp, "y", pl.getY()); s(jp, "y", pl.y);
s(jp, "z", pl.getZ()); s(jp, "z", pl.z);
} }
else { else {
s(jp, "world", "-some-other-bogus-world-"); s(jp, "world", "-some-other-bogus-world-");
@ -87,7 +84,7 @@ public class ClientUpdateComponent extends Component {
/* Only send health if enabled AND we're on visible world */ /* Only send health if enabled AND we're on visible world */
if (configuration.getBoolean("sendhealth", false) && (pworld != null) && pworld.sendhealth && (!hide)) { if (configuration.getBoolean("sendhealth", false) && (pworld != null) && pworld.sendhealth && (!hide)) {
s(jp, "health", p.getHealth()); s(jp, "health", p.getHealth());
s(jp, "armor", Armor.getArmorPoints(p)); s(jp, "armor", p.getArmorPoints());
} }
else { else {
s(jp, "health", 0); s(jp, "health", 0);
@ -96,8 +93,8 @@ public class ClientUpdateComponent extends Component {
a(u, "players", jp); a(u, "players", jp);
} }
if(configuration.getBoolean("includehiddenplayers", false)) { if(configuration.getBoolean("includehiddenplayers", false)) {
Set<Player> hidden = plugin.playerList.getHiddenPlayers(); List<DynmapPlayer> hidden = core.playerList.getHiddenPlayers();
for(Player p : hidden) { for(DynmapPlayer p : hidden) {
JSONObject jp = new JSONObject(); JSONObject jp = new JSONObject();
s(jp, "type", "player"); s(jp, "type", "player");
s(jp, "name", Client.stripColor(p.getDisplayName())); s(jp, "name", Client.stripColor(p.getDisplayName()));
@ -113,7 +110,7 @@ public class ClientUpdateComponent extends Component {
} }
s(u, "updates", new JSONArray()); s(u, "updates", new JSONArray());
for(Object update : plugin.mapManager.getWorldUpdates(worldName, since)) { for(Object update : core.mapManager.getWorldUpdates(worldName, since)) {
a(u, "updates", (Client.Update)update); a(u, "updates", (Client.Update)update);
} }
} }

View File

@ -39,23 +39,23 @@ public class ColorScheme {
} }
} }
private static File getColorSchemeDirectory() { private static File getColorSchemeDirectory(DynmapCore core) {
return new File(DynmapPlugin.dataDirectory, "colorschemes"); return new File(core.getDataFolder(), "colorschemes");
} }
public static ColorScheme getScheme(String name) { public static ColorScheme getScheme(DynmapCore core, String name) {
if (name == null) if (name == null)
name = "default"; name = "default";
ColorScheme scheme = cache.get(name); ColorScheme scheme = cache.get(name);
if (scheme == null) { if (scheme == null) {
scheme = loadScheme(name); scheme = loadScheme(core, name);
cache.put(name, scheme); cache.put(name, scheme);
} }
return scheme; return scheme;
} }
public static ColorScheme loadScheme(String name) { public static ColorScheme loadScheme(DynmapCore core, String name) {
File colorSchemeFile = new File(getColorSchemeDirectory(), name + ".txt"); File colorSchemeFile = new File(getColorSchemeDirectory(core), name + ".txt");
Color[][] colors = new Color[256][]; Color[][] colors = new Color[256][];
Color[][][] datacolors = new Color[256][][]; Color[][][] datacolors = new Color[256][][];
Color[][] biomecolors = new Color[Biome.values().length][]; Color[][] biomecolors = new Color[Biome.values().length][];

View File

@ -1,10 +1,10 @@
package org.dynmap; package org.dynmap;
public abstract class Component { public abstract class Component {
protected DynmapPlugin plugin; protected DynmapCore core;
protected ConfigurationNode configuration; protected ConfigurationNode configuration;
public Component(DynmapPlugin plugin, ConfigurationNode configuration) { public Component(DynmapCore core, ConfigurationNode configuration) {
this.plugin = plugin; this.core = core;
this.configuration = configuration; this.configuration = configuration;
} }

View File

@ -6,9 +6,9 @@ import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
public class DynmapPlayerChatListener extends PlayerListener { public class DynmapPlayerChatListener extends PlayerListener {
DynmapPlugin plugin; DynmapCore plugin;
public DynmapPlayerChatListener(DynmapPlugin plugin) { public DynmapPlayerChatListener(DynmapCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -8,7 +8,9 @@ import java.util.List;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.Location; import org.bukkit.Location;
import org.dynmap.bukkit.NewMapChunkCache;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
import org.dynmap.utils.BlockLightLevel;
import org.dynmap.utils.DynmapBufferedImage; import org.dynmap.utils.DynmapBufferedImage;
import org.dynmap.utils.FileLockManager; import org.dynmap.utils.FileLockManager;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
@ -22,13 +24,13 @@ import java.util.HashSet;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
public class DynmapWorld { public abstract class DynmapWorld {
public enum AutoGenerateOption { public enum AutoGenerateOption {
NONE, NONE,
FORMAPONLY, FORMAPONLY,
PERMANENT PERMANENT
} }
private World world;
public List<MapType> maps = new ArrayList<MapType>(); public List<MapType> maps = new ArrayList<MapType>();
public UpdateQueue updates = new UpdateQueue(); public UpdateQueue updates = new UpdateQueue();
public ConfigurationNode configuration; public ConfigurationNode configuration;
@ -50,9 +52,8 @@ public class DynmapWorld {
private boolean cancelled; private boolean cancelled;
private String wname; private String wname;
public DynmapWorld(World w) { protected DynmapWorld(String wname) {
world = w; this.wname = wname;
wname = w.getName();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setExtraZoomOutLevels(int lvl) { public void setExtraZoomOutLevels(int lvl) {
@ -170,7 +171,7 @@ public class DynmapWorld {
public boolean freshenZoomOutFilesByLevel(int zoomlevel) { public boolean freshenZoomOutFilesByLevel(int zoomlevel) {
int cnt = 0; int cnt = 0;
Debug.debug("freshenZoomOutFiles(" + world.getName() + "," + zoomlevel + ")"); Debug.debug("freshenZoomOutFiles(" + wname + "," + zoomlevel + ")");
if(worldtilepath.exists() == false) /* Quit if not found */ if(worldtilepath.exists() == false) /* Quit if not found */
return true; return true;
HashMap<String, PrefixData> maptab = buildPrefixData(zoomlevel); HashMap<String, PrefixData> maptab = buildPrefixData(zoomlevel);
@ -195,7 +196,7 @@ public class DynmapWorld {
cnt += processZoomDirectory(worldtilepath, maptab.get(pfx)); cnt += processZoomDirectory(worldtilepath, maptab.get(pfx));
} }
} }
Debug.debug("freshenZoomOutFiles(" + world.getName() + "," + zoomlevel + ") - done (" + cnt + " updated files)"); Debug.debug("freshenZoomOutFiles(" + wname + "," + zoomlevel + ") - done (" + cnt + " updated files)");
} }
else { /* Else, only process updates */ else { /* Else, only process updates */
String[] paths = peekQueuedUpdates(zoomlevel); /* Get pending updates */ String[] paths = peekQueuedUpdates(zoomlevel); /* Get pending updates */
@ -461,7 +462,7 @@ public class DynmapWorld {
long crc = hashman.calculateTileHash(kzIm.argb_buf); /* Get hash of tile */ long crc = hashman.calculateTileHash(kzIm.argb_buf); /* Get hash of tile */
int tilex = ztx/step/2; int tilex = ztx/step/2;
int tiley = zty/step/2; int tiley = zty/step/2;
String key = world.getName()+".z"+pd.zoomprefix+pd.baseprefix; String key = wname+".z"+pd.zoomprefix+pd.baseprefix;
if(blank) { if(blank) {
if(zf.exists()) { if(zf.exists()) {
zf.delete(); zf.delete();
@ -490,43 +491,41 @@ public class DynmapWorld {
DynmapBufferedImage.freeBufferedImage(kzIm); DynmapBufferedImage.freeBufferedImage(kzIm);
} }
} }
/* Test if world is nether */
public boolean isNether() {
return world.getEnvironment() == World.Environment.NETHER;
}
/* Get world name */ /* Get world name */
public String getName() { public String getName() {
return wname; return wname;
} }
/* Test if world is nether */
public abstract boolean isNether();
/* Get world spawn location */ /* Get world spawn location */
public DynmapLocation getSpawnLocation() { public abstract DynmapLocation getSpawnLocation();
DynmapLocation dloc = new DynmapLocation();
Location sloc = world.getSpawnLocation();
dloc.x = sloc.getBlockX(); dloc.y = sloc.getBlockY();
dloc.z = sloc.getBlockZ(); dloc.world = sloc.getWorld().getName();
return dloc;
}
public int hashCode() { public int hashCode() {
return wname.hashCode(); return wname.hashCode();
} }
/* Get world time */
public abstract long getTime();
/* World is storming */
public abstract boolean hasStorm();
/* World is thundering */
public abstract boolean isThundering();
/* World is loaded */
public abstract boolean isLoaded();
/* Get light level of block */
public abstract int getLightLevel(int x, int y, int z);
/* Get highest Y coord of given location */
public abstract int getHighestBlockYAt(int x, int z);
/* Test if sky light level is requestable */
public abstract boolean canGetSkyLightLevel();
/* Return sky light level */
public abstract int getSkyLightLevel(int x, int y, int z);
/**
* Get world environment ID (lower case - normal, the_end, nether)
*/
public abstract String getEnvironment();
/**
* Get map chunk cache for world
*/
public abstract MapChunkCache getChunkCache(List<DynmapChunk> chunks);
public long getTime() {
return world.getTime();
}
public boolean hasStorm() {
return world.hasStorm();
}
public boolean isThundering() {
return world.isThundering();
}
public World getWorld() {
return world;
}
public boolean isLoaded() {
return (world != null);
}
} }

View File

@ -7,7 +7,7 @@ import static org.dynmap.JSONUtils.*;
public class InternalClientUpdateComponent extends ClientUpdateComponent { public class InternalClientUpdateComponent extends ClientUpdateComponent {
public InternalClientUpdateComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) { public InternalClientUpdateComponent(final DynmapCore plugin, final ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
plugin.addServlet("/up/world/*", new ClientUpdateServlet(plugin)); plugin.addServlet("/up/world/*", new ClientUpdateServlet(plugin));
@ -43,12 +43,12 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent {
} }
protected void webChat(String name, String message) { protected void webChat(String name, String message) {
if(plugin.mapManager == null) if(core.mapManager == null)
return; return;
// TODO: Change null to something meaningful. // TODO: Change null to something meaningful.
plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null)); core.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
Log.info(unescapeString(plugin.configuration.getString("webprefix", "\u00A72[WEB] ")) + name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + message); Log.info(unescapeString(core.configuration.getString("webprefix", "\u00A72[WEB] ")) + name + ": " + unescapeString(core.configuration.getString("websuffix", "\u00A7f")) + message);
ChatEvent event = new ChatEvent("web", name, message); ChatEvent event = new ChatEvent("web", name, message);
plugin.events.trigger("webchat", event); core.events.trigger("webchat", event);
} }
} }

View File

@ -10,8 +10,6 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.dynmap.web.Json; import org.dynmap.web.Json;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -36,7 +34,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
private long last_confighash; private long last_confighash;
private Charset cs_utf8 = Charset.forName("UTF-8"); private Charset cs_utf8 = Charset.forName("UTF-8");
public JsonFileClientUpdateComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) { public JsonFileClientUpdateComponent(final DynmapCore plugin, final ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
final boolean allowwebchat = configuration.getBoolean("allowwebchat", false); final boolean allowwebchat = configuration.getBoolean("allowwebchat", false);
jsonInterval = (long)(configuration.getFloat("writeinterval", 1) * 1000); jsonInterval = (long)(configuration.getFloat("writeinterval", 1) * 1000);
@ -85,11 +83,11 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
} }
protected File getStandaloneFile(String filename) { protected File getStandaloneFile(String filename) {
File webpath = new File(plugin.configuration.getString("webpath", "web"), "standalone/" + filename); File webpath = new File(core.configuration.getString("webpath", "web"), "standalone/" + filename);
if (webpath.isAbsolute()) if (webpath.isAbsolute())
return webpath; return webpath;
else else
return new File(plugin.getDataFolder(), webpath.toString()); return new File(core.getDataFolder(), webpath.toString());
} }
private static final int RETRY_LIMIT = 5; private static final int RETRY_LIMIT = 5;
@ -97,10 +95,10 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
File outputFile; File outputFile;
File outputTempFile; File outputTempFile;
JSONObject clientConfiguration = new JSONObject(); JSONObject clientConfiguration = new JSONObject();
plugin.events.trigger("buildclientconfiguration", clientConfiguration); core.events.trigger("buildclientconfiguration", clientConfiguration);
outputFile = getStandaloneFile("dynmap_config.json"); outputFile = getStandaloneFile("dynmap_config.json");
outputTempFile = getStandaloneFile("dynmap_config.json.new"); outputTempFile = getStandaloneFile("dynmap_config.json.new");
last_confighash = plugin.getConfigHashcode(); last_confighash = core.getConfigHashcode();
int retrycnt = 0; int retrycnt = 0;
boolean done = false; boolean done = false;
@ -139,13 +137,13 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
protected void writeUpdates() { protected void writeUpdates() {
File outputFile; File outputFile;
File outputTempFile; File outputTempFile;
if(plugin.mapManager == null) return; if(core.mapManager == null) return;
//Handles Updates //Handles Updates
for (DynmapWorld dynmapWorld : plugin.mapManager.getWorlds()) { for (DynmapWorld dynmapWorld : core.mapManager.getWorlds()) {
JSONObject update = new JSONObject(); JSONObject update = new JSONObject();
update.put("timestamp", currentTimestamp); update.put("timestamp", currentTimestamp);
ClientUpdateEvent clientUpdate = new ClientUpdateEvent(currentTimestamp - 30000, dynmapWorld, update); ClientUpdateEvent clientUpdate = new ClientUpdateEvent(currentTimestamp - 30000, dynmapWorld, update);
plugin.events.trigger("buildclientupdate", clientUpdate); core.events.trigger("buildclientupdate", clientUpdate);
outputFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json"); outputFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json");
outputTempFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json.new"); outputTempFile = getStandaloneFile("dynmap_" + dynmapWorld.getName() + ".json.new");
@ -180,10 +178,10 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
} }
} }
} }
plugin.events.<ClientUpdateEvent>trigger("clientupdatewritten", clientUpdate); core.events.<ClientUpdateEvent>trigger("clientupdatewritten", clientUpdate);
} }
plugin.events.<Object>trigger("clientupdateswritten", null); core.events.<Object>trigger("clientupdateswritten", null);
} }
protected void handleWebChat() { protected void handleWebChat() {
@ -224,13 +222,12 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
name = ip; name = ip;
} }
if(useplayerloginip) { /* Try to match using IPs of player logins */ if(useplayerloginip) { /* Try to match using IPs of player logins */
List<String> ids = plugin.getIDsForIP(name); List<String> ids = core.getIDsForIP(name);
if(ids != null) { if(ids != null) {
name = ids.get(0); name = ids.get(0);
isip = false; isip = false;
if(checkuserban) { if(checkuserban) {
OfflinePlayer p = plugin.getServer().getOfflinePlayer(name); if(core.getServer().isPlayerBanned(name)) {
if((p != null) && p.isBanned()) {
Log.info("Ignore message from '" + ip + "' - banned player (" + name + ")"); Log.info("Ignore message from '" + ip + "' - banned player (" + name + ")");
return; return;
} }
@ -259,12 +256,12 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent {
} }
protected void webChat(String name, String message) { protected void webChat(String name, String message) {
if(plugin.mapManager == null) return; if(core.mapManager == null) return;
// TODO: Change null to something meaningful. // TODO: Change null to something meaningful.
plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null)); core.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null));
Log.info(unescapeString(plugin.configuration.getString("webprefix", "\u00A2[WEB] ")) + name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + message); Log.info(unescapeString(core.configuration.getString("webprefix", "\u00A2[WEB] ")) + name + ": " + unescapeString(core.configuration.getString("websuffix", "\u00A7f")) + message);
ChatEvent event = new ChatEvent("web", name, message); ChatEvent event = new ChatEvent("web", name, message);
plugin.events.trigger("webchat", event); core.events.trigger("webchat", event);
} }
@Override @Override

View File

@ -22,16 +22,13 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.bukkit.World; import org.dynmap.DynmapCore.CompassMode;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.dynmap.DynmapPlugin.CompassMode;
import org.dynmap.DynmapWorld.AutoGenerateOption; import org.dynmap.DynmapWorld.AutoGenerateOption;
import org.dynmap.common.DynmapCommandSender;
import org.dynmap.common.DynmapPlayer;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
import org.dynmap.hdmap.HDMapManager; import org.dynmap.hdmap.HDMapManager;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.NewMapChunkCache;
import org.dynmap.utils.SnapshotCache; import org.dynmap.utils.SnapshotCache;
import org.dynmap.utils.TileFlags; import org.dynmap.utils.TileFlags;
@ -42,8 +39,7 @@ public class MapManager {
private static final int DEFAULT_ZOOMOUT_PERIOD = 60; private static final int DEFAULT_ZOOMOUT_PERIOD = 60;
public List<DynmapWorld> worlds = new ArrayList<DynmapWorld>(); public List<DynmapWorld> worlds = new ArrayList<DynmapWorld>();
public Map<String, DynmapWorld> worldsLookup = new HashMap<String, DynmapWorld>(); public Map<String, DynmapWorld> worldsLookup = new HashMap<String, DynmapWorld>();
private BukkitScheduler scheduler; private DynmapCore core;
private DynmapPlugin plug_in;
private long timeslice_int = 0; /* In milliseconds */ private long timeslice_int = 0; /* In milliseconds */
private int max_chunk_loads_per_tick = DEFAULT_CHUNKS_PER_TICK; private int max_chunk_loads_per_tick = DEFAULT_CHUNKS_PER_TICK;
private int parallelrendercnt = 0; private int parallelrendercnt = 0;
@ -221,7 +217,7 @@ public class MapManager {
LinkedList<MapTile> renderQueue = null; LinkedList<MapTile> renderQueue = null;
MapTile tile0 = null; MapTile tile0 = null;
int rendercnt = 0; int rendercnt = 0;
CommandSender sender; DynmapCommandSender sender;
String player; String player;
long timeaccum; long timeaccum;
HashSet<MapType> renderedmaps = new HashSet<MapType>(); HashSet<MapType> renderedmaps = new HashSet<MapType>();
@ -237,7 +233,7 @@ public class MapManager {
AtomicInteger rendercalls = new AtomicInteger(0); AtomicInteger rendercalls = new AtomicInteger(0);
/* Full world, all maps render */ /* Full world, all maps render */
FullWorldRenderState(DynmapWorld dworld, DynmapLocation l, CommandSender sender, String mapname, boolean updaterender) { FullWorldRenderState(DynmapWorld dworld, DynmapLocation l, DynmapCommandSender sender, String mapname, boolean updaterender) {
this(dworld, l, sender, mapname, -1); this(dworld, l, sender, mapname, -1);
if(updaterender) { if(updaterender) {
rendertype = RENDERTYPE_UPDATERENDER; rendertype = RENDERTYPE_UPDATERENDER;
@ -248,15 +244,15 @@ public class MapManager {
} }
/* Full world, all maps render, with optional render radius */ /* Full world, all maps render, with optional render radius */
FullWorldRenderState(DynmapWorld dworld, DynmapLocation l, CommandSender sender, String mapname, int radius) { FullWorldRenderState(DynmapWorld dworld, DynmapLocation l, DynmapCommandSender sender, String mapname, int radius) {
world = dworld; world = dworld;
loc = l; loc = l;
found = new TileFlags(); found = new TileFlags();
rendered = new TileFlags(); rendered = new TileFlags();
renderQueue = new LinkedList<MapTile>(); renderQueue = new LinkedList<MapTile>();
this.sender = sender; this.sender = sender;
if(sender instanceof Player) if(sender instanceof DynmapPlayer)
this.player = ((Player)sender).getName(); this.player = ((DynmapPlayer)sender).getName();
else else
this.player = ""; this.player = "";
if(radius < 0) { if(radius < 0) {
@ -343,7 +339,7 @@ public class MapManager {
updaterender = rendertype.equals(RENDERTYPE_UPDATERENDER); updaterender = rendertype.equals(RENDERTYPE_UPDATERENDER);
sender = null; sender = null;
if(player.length() > 0) { if(player.length() > 0) {
sender = plug_in.getServer().getPlayerExact(player); sender = core.getServer().getPlayer(player);
} }
} }
@ -681,7 +677,7 @@ public class MapManager {
private class CheckWorldTimes implements Runnable { private class CheckWorldTimes implements Runnable {
public void run() { public void run() {
Future<Integer> f = scheduler.callSyncMethod(plug_in, new Callable<Integer>() { Future<Integer> f = core.getServer().callSyncMethod(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
for(DynmapWorld w : worlds) { for(DynmapWorld w : worlds) {
int new_servertime = (int)(w.getTime() % 24000); int new_servertime = (int)(w.getTime() % 24000);
@ -724,8 +720,8 @@ public class MapManager {
} }
} }
public MapManager(DynmapPlugin plugin, ConfigurationNode configuration) { public MapManager(DynmapCore core, ConfigurationNode configuration) {
plug_in = plugin; this.core = core;
mapman = this; mapman = this;
/* Get block hiding data, if any */ /* Get block hiding data, if any */
@ -739,9 +735,9 @@ public class MapManager {
/* Initialize HD map manager */ /* Initialize HD map manager */
hdmapman = new HDMapManager(); hdmapman = new HDMapManager();
hdmapman.loadHDShaders(plugin); hdmapman.loadHDShaders(core);
hdmapman.loadHDPerspectives(plugin); hdmapman.loadHDPerspectives(core);
hdmapman.loadHDLightings(plugin); hdmapman.loadHDLightings(core);
sscache = new SnapshotCache(configuration.getInteger("snapshotcachesize", 500)); sscache = new SnapshotCache(configuration.getInteger("snapshotcachesize", 500));
parallelrendercnt = configuration.getInteger("parallelrendercnt", 0); parallelrendercnt = configuration.getInteger("parallelrendercnt", 0);
progressinterval = configuration.getInteger("progressloginterval", 100); progressinterval = configuration.getInteger("progressloginterval", 100);
@ -771,18 +767,12 @@ public class MapManager {
zoomout_period = configuration.getInteger("zoomoutperiod", DEFAULT_ZOOMOUT_PERIOD); zoomout_period = configuration.getInteger("zoomoutperiod", DEFAULT_ZOOMOUT_PERIOD);
if(zoomout_period < 5) zoomout_period = 5; if(zoomout_period < 5) zoomout_period = 5;
scheduler = plugin.getServer().getScheduler(); hashman = new TileHashManager(core.getTilesFolder(), configuration.getBoolean("enabletilehash", true));
hashman = new TileHashManager(DynmapPlugin.tilesDirectory, configuration.getBoolean("enabletilehash", true));
tileQueue.start(); tileQueue.start();
for (World world : plug_in.getServer().getWorlds()) {
activateWorld(world);
}
} }
void renderFullWorld(DynmapLocation l, CommandSender sender, String mapname, boolean update) { void renderFullWorld(DynmapLocation l, DynmapCommandSender sender, String mapname, boolean update) {
DynmapWorld world = getWorld(l.world); DynmapWorld world = getWorld(l.world);
if (world == null) { if (world == null) {
sender.sendMessage("Could not render: world '" + l.world + "' not defined in configuration."); sender.sendMessage("Could not render: world '" + l.world + "' not defined in configuration.");
@ -808,7 +798,7 @@ public class MapManager {
sender.sendMessage("Full render starting on world '" + wname + "'..."); sender.sendMessage("Full render starting on world '" + wname + "'...");
} }
void renderWorldRadius(DynmapLocation l, CommandSender sender, String mapname, int radius) { void renderWorldRadius(DynmapLocation l, DynmapCommandSender sender, String mapname, int radius) {
DynmapWorld world = getWorld(l.world); DynmapWorld world = getWorld(l.world);
if (world == null) { if (world == null) {
sender.sendMessage("Could not render: world '" + l.world + "' not defined in configuration."); sender.sendMessage("Could not render: world '" + l.world + "' not defined in configuration.");
@ -830,15 +820,15 @@ public class MapManager {
sender.sendMessage("Render of " + radius + " block radius starting on world '" + wname + "'..."); sender.sendMessage("Render of " + radius + " block radius starting on world '" + wname + "'...");
} }
void cancelRender(World w, CommandSender sender) { void cancelRender(String w, DynmapCommandSender sender) {
synchronized(lock) { synchronized(lock) {
if(w != null) { if(w != null) {
FullWorldRenderState rndr; FullWorldRenderState rndr;
rndr = active_renders.get(w.getName()); rndr = active_renders.get(w);
if(rndr != null) { if(rndr != null) {
rndr.cancelRender(); /* Cancel render */ rndr.cancelRender(); /* Cancel render */
if(sender != null) { if(sender != null) {
sender.sendMessage("Cancelled render for '" + w.getName() + "'"); sender.sendMessage("Cancelled render for '" + w + "'");
} }
} }
} }
@ -854,7 +844,7 @@ public class MapManager {
} }
} }
void purgeQueue(CommandSender sender) { void purgeQueue(DynmapCommandSender sender) {
if(tileQueue != null) { if(tileQueue != null) {
int cnt = 0; int cnt = 0;
List<MapTile> popped = tileQueue.popAll(); List<MapTile> popped = tileQueue.popAll();
@ -866,18 +856,17 @@ public class MapManager {
} }
} }
public void activateWorld(World w) { public boolean activateWorld(DynmapWorld dynmapWorld) {
ConfigurationNode worldConfiguration = plug_in.getWorldConfiguration(w); ConfigurationNode worldConfiguration = core.getWorldConfiguration(dynmapWorld);
if (!worldConfiguration.getBoolean("enabled", false)) { if (!worldConfiguration.getBoolean("enabled", false)) {
Log.info("World '" + w.getName() + "' disabled"); Log.info("World '" + dynmapWorld.getName() + "' disabled");
return; return false;
} }
String worldName = w.getName(); String worldName = dynmapWorld.getName();
DynmapWorld dynmapWorld = new DynmapWorld(w);
dynmapWorld.configuration = worldConfiguration; dynmapWorld.configuration = worldConfiguration;
Log.verboseinfo("Loading maps of world '" + worldName + "'..."); Log.verboseinfo("Loading maps of world '" + worldName + "'...");
for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[0], new Object[0])) { for(MapType map : worldConfiguration.<MapType>createInstances("maps", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(map.getName() != null) if(map.getName() != null)
dynmapWorld.maps.add(map); dynmapWorld.maps.add(map);
} }
@ -885,15 +874,15 @@ public class MapManager {
List<ConfigurationNode> loclist = worldConfiguration.getNodes("fullrenderlocations"); List<ConfigurationNode> loclist = worldConfiguration.getNodes("fullrenderlocations");
dynmapWorld.seedloc = new ArrayList<DynmapLocation>(); dynmapWorld.seedloc = new ArrayList<DynmapLocation>();
dynmapWorld.servertime = (int)(w.getTime() % 24000); dynmapWorld.servertime = (int)(dynmapWorld.getTime() % 24000);
dynmapWorld.sendposition = worldConfiguration.getBoolean("sendposition", true); dynmapWorld.sendposition = worldConfiguration.getBoolean("sendposition", true);
dynmapWorld.sendhealth = worldConfiguration.getBoolean("sendhealth", true); dynmapWorld.sendhealth = worldConfiguration.getBoolean("sendhealth", true);
dynmapWorld.bigworld = worldConfiguration.getBoolean("bigworld", false); dynmapWorld.bigworld = worldConfiguration.getBoolean("bigworld", false);
dynmapWorld.setExtraZoomOutLevels(worldConfiguration.getInteger("extrazoomout", 0)); dynmapWorld.setExtraZoomOutLevels(worldConfiguration.getInteger("extrazoomout", 0));
dynmapWorld.worldtilepath = new File(DynmapPlugin.tilesDirectory, w.getName()); dynmapWorld.worldtilepath = new File(core.getTilesFolder(), worldName);
if(loclist != null) { if(loclist != null) {
for(ConfigurationNode loc : loclist) { for(ConfigurationNode loc : loclist) {
DynmapLocation lx = new DynmapLocation(w.getName(), loc.getInteger("x", 0), loc.getInteger("y", 64), loc.getInteger("z", 0)); DynmapLocation lx = new DynmapLocation(worldName, loc.getInteger("x", 0), loc.getInteger("y", 64), loc.getInteger("z", 0));
dynmapWorld.seedloc.add(lx); dynmapWorld.seedloc.add(lx);
} }
} }
@ -909,7 +898,7 @@ public class MapManager {
lim.z1 = vis.getInteger("z1", 0); lim.z1 = vis.getInteger("z1", 0);
dynmapWorld.visibility_limits.add(lim); dynmapWorld.visibility_limits.add(lim);
/* Also, add a seed location for the middle of each visible area */ /* Also, add a seed location for the middle of each visible area */
dynmapWorld.seedloc.add(new DynmapLocation(w.getName(), (lim.x0+lim.x1)/2, 64, (lim.z0+lim.z1)/2)); dynmapWorld.seedloc.add(new DynmapLocation(worldName, (lim.x0+lim.x1)/2, 64, (lim.z0+lim.z1)/2));
} }
} }
/* Load hidden limits, if any are defined */ /* Load hidden limits, if any are defined */
@ -951,7 +940,7 @@ public class MapManager {
// TODO: Make this less... weird... // TODO: Make this less... weird...
// Insert the world on the same spot as in the configuration. // Insert the world on the same spot as in the configuration.
HashMap<String, Integer> indexLookup = new HashMap<String, Integer>(); HashMap<String, Integer> indexLookup = new HashMap<String, Integer>();
List<ConfigurationNode> nodes = plug_in.configuration.getNodes("worlds"); List<ConfigurationNode> nodes = core.configuration.getNodes("worlds");
for (int i = 0; i < nodes.size(); i++) { for (int i = 0; i < nodes.size(); i++) {
ConfigurationNode node = nodes.get(i); ConfigurationNode node = nodes.get(i);
indexLookup.put(node.getString("name"), i); indexLookup.put(node.getString("name"), i);
@ -970,11 +959,12 @@ public class MapManager {
} }
worlds.add(insertIndex, dynmapWorld); worlds.add(insertIndex, dynmapWorld);
} }
worldsLookup.put(w.getName(), dynmapWorld); worldsLookup.put(worldName, dynmapWorld);
plug_in.events.trigger("worldactivated", dynmapWorld); core.events.trigger("worldactivated", dynmapWorld);
/* Now, restore any pending renders for this world */ /* Now, restore any pending renders for this world */
if(saverestorepending) if(saverestorepending)
loadPending(dynmapWorld); loadPending(dynmapWorld);
return true;
} }
public void deactivateWorld(String wname) { public void deactivateWorld(String wname) {
@ -983,7 +973,7 @@ public class MapManager {
private void loadPending(DynmapWorld w) { private void loadPending(DynmapWorld w) {
String wname = w.getName(); String wname = w.getName();
File f = new File(plug_in.getDataFolder(), wname + ".pending"); File f = new File(core.getDataFolder(), wname + ".pending");
if(f.exists()) { if(f.exists()) {
org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f);
saved.load(); saved.load();
@ -1021,7 +1011,7 @@ public class MapManager {
List<MapTile> mt = tileQueue.popAll(); List<MapTile> mt = tileQueue.popAll();
for(DynmapWorld w : worlds) { for(DynmapWorld w : worlds) {
boolean dosave = false; boolean dosave = false;
File f = new File(plug_in.getDataFolder(), w.getName() + ".pending"); File f = new File(core.getDataFolder(), w.getName() + ".pending");
org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration saved = new org.bukkit.util.config.Configuration(f);
ArrayList<ConfigurationNode> savedtiles = new ArrayList<ConfigurationNode>(); ArrayList<ConfigurationNode> savedtiles = new ArrayList<ConfigurationNode>();
for(MapTile tile : mt) { for(MapTile tile : mt) {
@ -1161,7 +1151,7 @@ public class MapManager {
*/ */
public MapChunkCache createMapChunkCache(DynmapWorld w, List<DynmapChunk> chunks, public MapChunkCache createMapChunkCache(DynmapWorld w, List<DynmapChunk> chunks,
boolean blockdata, boolean highesty, boolean biome, boolean rawbiome) { boolean blockdata, boolean highesty, boolean biome, boolean rawbiome) {
MapChunkCache c = new NewMapChunkCache(); MapChunkCache c = w.getChunkCache(chunks);
if(w.visibility_limits != null) { if(w.visibility_limits != null) {
for(MapChunkCache.VisibilityLimit limit: w.visibility_limits) { for(MapChunkCache.VisibilityLimit limit: w.visibility_limits) {
c.setVisibleRange(limit); c.setVisibleRange(limit);
@ -1175,8 +1165,6 @@ public class MapManager {
} }
c.setHiddenFillStyle(w.hiddenchunkstyle); c.setHiddenFillStyle(w.hiddenchunkstyle);
} }
c.setChunks(w.getWorld(), chunks);
if(c.setChunkDataTypes(blockdata, biome, highesty, rawbiome) == false) if(c.setChunkDataTypes(blockdata, biome, highesty, rawbiome) == false)
Log.severe("CraftBukkit build does not support biome APIs"); Log.severe("CraftBukkit build does not support biome APIs");
if(chunks.size() == 0) { /* No chunks to get? */ if(chunks.size() == 0) { /* No chunks to get? */
@ -1194,7 +1182,7 @@ public class MapManager {
cur_tick = now/50; cur_tick = now/50;
} }
} }
Future<Boolean> f = scheduler.callSyncMethod(plug_in, new Callable<Boolean>() { Future<Boolean> f = core.getServer().callSyncMethod(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
boolean exhausted; boolean exhausted;
synchronized(loadlock) { synchronized(loadlock) {
@ -1240,7 +1228,7 @@ public class MapManager {
/** /**
* Print statistics command * Print statistics command
*/ */
public void printStats(CommandSender sender, String prefix) { public void printStats(DynmapCommandSender sender, String prefix) {
sender.sendMessage("Tile Render Statistics:"); sender.sendMessage("Tile Render Statistics:");
MapStats tot = new MapStats(); MapStats tot = new MapStats();
synchronized(lock) { synchronized(lock) {
@ -1283,7 +1271,7 @@ public class MapManager {
/** /**
* Print trigger statistics command * Print trigger statistics command
*/ */
public void printTriggerStats(CommandSender sender) { public void printTriggerStats(DynmapCommandSender sender) {
sender.sendMessage("Render Trigger Statistics:"); sender.sendMessage("Render Trigger Statistics:");
synchronized(lock) { synchronized(lock) {
for(String k: new TreeSet<String>(trigstats.keySet())) { for(String k: new TreeSet<String>(trigstats.keySet())) {
@ -1296,7 +1284,7 @@ public class MapManager {
/** /**
* Reset statistics * Reset statistics
*/ */
public void resetStats(CommandSender sender, String prefix) { public void resetStats(DynmapCommandSender sender, String prefix) {
synchronized(lock) { synchronized(lock) {
for(String k : mapstats.keySet()) { for(String k : mapstats.keySet()) {
if((prefix != null) && !k.startsWith(prefix)) if((prefix != null) && !k.startsWith(prefix))
@ -1327,23 +1315,23 @@ public class MapManager {
} }
public boolean getSwampShading() { public boolean getSwampShading() {
return plug_in.swampshading; return core.swampshading;
} }
public boolean getWaterBiomeShading() { public boolean getWaterBiomeShading() {
return plug_in.waterbiomeshading; return core.waterbiomeshading;
} }
public boolean getFenceJoin() { public boolean getFenceJoin() {
return plug_in.fencejoin; return core.fencejoin;
} }
public boolean getBetterGrass() { public boolean getBetterGrass() {
return plug_in.bettergrass; return core.bettergrass;
} }
public CompassMode getCompassMode() { public CompassMode getCompassMode() {
return plug_in.compassmode; return core.compassmode;
} }
public boolean getHideOres() { public boolean getHideOres() {
@ -1400,7 +1388,7 @@ public class MapManager {
ticklistcalls.incrementAndGet(); ticklistcalls.incrementAndGet();
} }
/* Connect any jobs tied to this player back to the player (resumes output to player) */ /* Connect any jobs tied to this player back to the player (resumes output to player) */
void connectTasksToPlayer(Player p) { void connectTasksToPlayer(DynmapPlayer p) {
String pn = p.getName(); String pn = p.getName();
for(FullWorldRenderState job : active_renders.values()) { for(FullWorldRenderState job : active_renders.values()) {
if(pn.equals(job.player)) { if(pn.equals(job.player)) {

View File

@ -1,17 +1,10 @@
package org.dynmap; package org.dynmap;
import org.bukkit.ChatColor; import org.dynmap.common.DynmapListenerManager;
import org.bukkit.Location; import org.dynmap.common.DynmapListenerManager.EventType;
import org.bukkit.World; import org.dynmap.common.DynmapListenerManager.WorldEventListener;
import org.bukkit.entity.Player; import org.dynmap.common.DynmapListenerManager.PlayerEventListener;
import org.bukkit.event.Event.Type; import org.dynmap.common.DynmapPlayer;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent;
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.Marker;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
@ -30,23 +23,23 @@ public class MarkersComponent extends ClientComponent {
private MarkerIcon offlineicon; private MarkerIcon offlineicon;
private MarkerSet spawnbedset; private MarkerSet spawnbedset;
private MarkerIcon spawnbedicon; private MarkerIcon spawnbedicon;
private String spawnbedformat;
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"; private static final String PLAYER_SPAWN_BED_SETID = "spawn_beds";
public MarkersComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { public MarkersComponent(final DynmapCore core, ConfigurationNode configuration) {
super(plugin, configuration); super(core, configuration);
/* Register API with plugin, if needed */ /* Register API with plugin, if needed */
if(plugin.markerAPIInitialized()) { if(core.markerAPIInitialized()) {
api = (MarkerAPIImpl)plugin.getMarkerAPI(); api = (MarkerAPIImpl)core.getMarkerAPI();
} }
else { else {
api = MarkerAPIImpl.initializeMarkerAPI(plugin); api = MarkerAPIImpl.initializeMarkerAPI(core);
plugin.registerMarkerAPI(api); core.registerMarkerAPI(api);
} }
/* If configuration has enabled sign support, prime it too */ /* If configuration has enabled sign support, prime it too */
if(configuration.getBoolean("enablesigns", false)) { if(configuration.getBoolean("enablesigns", false)) {
signmgr = MarkerSignManager.initializeSignManager(plugin); signmgr = MarkerSignManager.initializeSignManager(core);
} }
/* If we're posting spawn point markers, initialize and add world listener */ /* If we're posting spawn point markers, initialize and add world listener */
if(configuration.getBoolean("showspawn", false)) { if(configuration.getBoolean("showspawn", false)) {
@ -56,27 +49,24 @@ public class MarkersComponent extends ClientComponent {
if(spawnicon == null) { if(spawnicon == null) {
spawnicon = api.getMarkerIcon(MarkerIcon.WORLD); spawnicon = api.getMarkerIcon(MarkerIcon.WORLD);
} }
WorldListener wl = new WorldListener() { /* Add listener for world loads */
public void onWorldLoad(WorldLoadEvent event) { WorldEventListener wel = new WorldEventListener() {
World w = event.getWorld(); /* Get the world */ @Override
Location loc = w.getSpawnLocation(); /* Get location of spawn */ public void worldEvent(DynmapWorld w) {
DynmapLocation loc = w.getSpawnLocation(); /* Get location of spawn */
if(loc != null) if(loc != null)
addUpdateWorld(w, new DynmapLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ())); 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, new DynmapLocation(w.getName(), loc.getX(), loc.getY(), loc.getZ()));
} }
}; };
plugin.registerEvent(org.bukkit.event.Event.Type.WORLD_LOAD, wl); core.listenerManager.addListener(EventType.WORLD_LOAD, wel);
plugin.registerEvent(org.bukkit.event.Event.Type.SPAWN_CHANGE, wl); /* Add listener for spawn changes */
core.listenerManager.addListener(EventType.WORLD_SPAWN_CHANGE, wel);
/* Initialize already loaded worlds */ /* Initialize already loaded worlds */
for(DynmapWorld w : plugin.getMapManager().getWorlds()) { for(DynmapWorld w : core.getMapManager().getWorlds()) {
DynmapLocation loc = w.getSpawnLocation(); DynmapLocation loc = w.getSpawnLocation();
if(loc != null) if(loc != null)
addUpdateWorld(w.getWorld(), loc); addUpdateWorld(w, loc);
} }
} }
/* If showing offline players as markers */ /* If showing offline players as markers */
@ -92,32 +82,30 @@ public class MarkersComponent extends ClientComponent {
offlineicon = api.getMarkerIcon(configuration.getString("offlineicon", "offlineuser")); offlineicon = api.getMarkerIcon(configuration.getString("offlineicon", "offlineuser"));
/* Add listener for players coming and going */ /* Add listener for players coming and going */
PlayerListener pl = new PlayerListener() { core.listenerManager.addListener(EventType.PLAYER_JOIN, new PlayerEventListener() {
@Override @Override
public void onPlayerJoin(PlayerJoinEvent event) { public void playerEvent(DynmapPlayer p) {
Player p = event.getPlayer();
Marker m = offlineset.findMarker(p.getName()); Marker m = offlineset.findMarker(p.getName());
if(m != null) { if(m != null) {
m.deleteMarker(); m.deleteMarker();
} }
} }
});
core.listenerManager.addListener(EventType.PLAYER_QUIT, new PlayerEventListener() {
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void playerEvent(DynmapPlayer p) {
Player p = event.getPlayer(); String pname = p.getName();
Marker m = offlineset.findMarker(p.getName()); Marker m = offlineset.findMarker(pname);
if(m != null) { if(m != null) {
m.deleteMarker(); m.deleteMarker();
} }
if(plugin.playerList.isVisiblePlayer(p)) { if(core.playerList.isVisiblePlayer(pname)) {
Location loc = p.getLocation(); DynmapLocation loc = p.getLocation();
m = offlineset.createMarker(p.getName(), ChatColor.stripColor(p.getDisplayName()), false, m = offlineset.createMarker(p.getName(), core.getServer().stripChatColor(p.getDisplayName()), false,
loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), loc.world, loc.x, loc.y, loc.z, offlineicon, true);
offlineicon, true);
} }
} }
}; });
plugin.registerEvent(Type.PLAYER_JOIN, pl);
plugin.registerEvent(Type.PLAYER_QUIT, pl);
} }
else { else {
/* Make set, if needed */ /* Make set, if needed */
@ -137,53 +125,34 @@ public class MarkersComponent extends ClientComponent {
spawnbedset.setMinZoom(configuration.getInteger("spawnbedminzoom", 0)); spawnbedset.setMinZoom(configuration.getInteger("spawnbedminzoom", 0));
spawnbedicon = api.getMarkerIcon(configuration.getString("spawnbedicon", "bed")); spawnbedicon = api.getMarkerIcon(configuration.getString("spawnbedicon", "bed"));
final String spawnbedformat = configuration.getString("spawnbedformat", "%name%'s bed"); spawnbedformat = configuration.getString("spawnbedformat", "%name%'s bed");
/* Add listener for players coming and going */ /* Add listener for players coming and going */
PlayerListener pl = new PlayerListener() { core.listenerManager.addListener(EventType.PLAYER_JOIN, new PlayerEventListener() {
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 @Override
public void onPlayerJoin(PlayerJoinEvent event) { public void playerEvent(DynmapPlayer p) {
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); updatePlayer(p);
} }
}); });
} core.listenerManager.addListener(EventType.PLAYER_QUIT, new PlayerEventListener() {
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void playerEvent(DynmapPlayer p) {
Player p = event.getPlayer();
Marker m = spawnbedset.findMarker(p.getName()+"_bed"); Marker m = spawnbedset.findMarker(p.getName()+"_bed");
if(m != null) { if(m != null) {
m.deleteMarker(); m.deleteMarker();
} }
} }
}; });
plugin.registerEvent(Type.PLAYER_JOIN, pl); core.listenerManager.addListener(EventType.PLAYER_BED_LEAVE, new PlayerEventListener() {
plugin.registerEvent(Type.PLAYER_QUIT, pl); @Override
plugin.registerEvent(Type.PLAYER_BED_LEAVE, pl); public void playerEvent(final DynmapPlayer p) {
core.getServer().scheduleServerTask(new Runnable() {
public void run() {
updatePlayer(p);
}
}, 0);
}
});
} }
else { else {
/* Make set, if needed */ /* Make set, if needed */
@ -194,7 +163,26 @@ public class MarkersComponent extends ClientComponent {
} }
} }
private void addUpdateWorld(World w, DynmapLocation loc) { private void updatePlayer(DynmapPlayer p) {
DynmapLocation 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.world, bl.x, bl.y, bl.z);
else
m = spawnbedset.createMarker(p.getName()+"_bed", spawnbedformat.replace("%name%", core.getServer().stripChatColor(p.getDisplayName())), false,
bl.world, bl.x, bl.y, bl.z,
spawnbedicon, true);
}
}
private void addUpdateWorld(DynmapWorld w, DynmapLocation loc) {
MarkerSet ms = api.getMarkerSet(MarkerSet.DEFAULT); MarkerSet ms = api.getMarkerSet(MarkerSet.DEFAULT);
if(ms != null) { if(ms != null) {
String spawnid = "_spawn_" + w.getName(); String spawnid = "_spawn_" + w.getName();
@ -212,7 +200,7 @@ public class MarkersComponent extends ClientComponent {
@Override @Override
public void dispose() { public void dispose() {
if(signmgr != null) { if(signmgr != null) {
MarkerSignManager.terminateSignManager(this.plugin); MarkerSignManager.terminateSignManager(this.core);
signmgr = null; signmgr = null;
} }
/* Don't unregister API - other plugins might be using it, and we want to keep non-persistent markers */ /* Don't unregister API - other plugins might be using it, and we want to keep non-persistent markers */

View File

@ -8,10 +8,10 @@ import java.net.URL;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.dynmap.MapType.ImageFormat; import org.dynmap.MapType.ImageFormat;
import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.common.DynmapListenerManager.PlayerEventListener;
import org.dynmap.common.DynmapPlayer;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
import org.dynmap.utils.DynmapBufferedImage; import org.dynmap.utils.DynmapBufferedImage;
import org.dynmap.utils.FileLockManager; import org.dynmap.utils.FileLockManager;
@ -133,22 +133,22 @@ public class PlayerFaces {
/* TODO: signal update for player icon to client */ /* TODO: signal update for player icon to client */
} }
} }
private class LoginListener extends PlayerListener { public PlayerFaces(DynmapCore core) {
fetchskins = core.configuration.getBoolean("fetchskins", true); /* Control whether to fetch skins */
refreshskins = core.configuration.getBoolean("refreshskins", true); /* Control whether to update existing fetched skins or faces */
core.listenerManager.addListener(EventType.PLAYER_JOIN, new PlayerEventListener() {
@Override @Override
public void onPlayerLogin(PlayerLoginEvent event) { public void playerEvent(DynmapPlayer p) {
Runnable job = new LoadPlayerImages(event.getPlayer().getName()); Runnable job = new LoadPlayerImages(p.getName());
if(fetchskins) if(fetchskins)
MapManager.scheduleDelayedJob(job, 0); MapManager.scheduleDelayedJob(job, 0);
else else
job.run(); job.run();
} }
} });
public PlayerFaces(DynmapPlugin plugin) { facesdir = new File(core.getTilesFolder(), "faces");
fetchskins = plugin.configuration.getBoolean("fetchskins", true); /* Control whether to fetch skins */
refreshskins = plugin.configuration.getBoolean("refreshskins", true); /* Control whether to update existing fetched skins or faces */
plugin.registerEvent(Type.PLAYER_LOGIN, new LoginListener());
facesdir = new File(DynmapPlugin.tilesDirectory, "faces");
facesdir.mkdirs(); /* Make sure directory exists */ facesdir.mkdirs(); /* Make sure directory exists */
faces8x8dir = new File(facesdir, "8x8"); faces8x8dir = new File(facesdir, "8x8");
faces8x8dir.mkdirs(); faces8x8dir.mkdirs();

View File

@ -8,20 +8,20 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set;
import org.bukkit.Server; import org.dynmap.common.DynmapPlayer;
import org.bukkit.entity.Player; import org.dynmap.common.DynmapServerInterface;
public class PlayerList { public class PlayerList {
private Server server; private DynmapServerInterface server;
private HashSet<String> hiddenPlayerNames = new HashSet<String>(); private HashSet<String> hiddenPlayerNames = new HashSet<String>();
private File hiddenPlayersFile; private File hiddenPlayersFile;
private ConfigurationNode configuration; private ConfigurationNode configuration;
private Player[] online; private DynmapPlayer[] online;
public PlayerList(Server server, File hiddenPlayersFile, ConfigurationNode configuration) { public PlayerList(DynmapServerInterface server, File hiddenPlayersFile, ConfigurationNode configuration) {
this.server = server; this.server = server;
this.hiddenPlayersFile = hiddenPlayersFile; this.hiddenPlayersFile = hiddenPlayersFile;
this.configuration = configuration; this.configuration = configuration;
@ -74,45 +74,32 @@ public class PlayerList {
hide(playerName); hide(playerName);
} }
// TODO: Clean this up... one day public List<DynmapPlayer> getVisiblePlayers(String worldName) {
public Player[] getVisiblePlayers(String worldName) { ArrayList<DynmapPlayer> visiblePlayers = new ArrayList<DynmapPlayer>();
ArrayList<Player> visiblePlayers = new ArrayList<Player>(); DynmapPlayer[] onlinePlayers = online; /* Use copied list - we don't call from server thread */
Player[] onlinePlayers = online; /* Use copied list - we don't call from server thread */
boolean useWhitelist = configuration.getBoolean("display-whitelist", false); boolean useWhitelist = configuration.getBoolean("display-whitelist", false);
for (int i = 0; i < onlinePlayers.length; i++) { for (int i = 0; i < onlinePlayers.length; i++) {
Player p = onlinePlayers[i]; DynmapPlayer p = onlinePlayers[i];
if(p == null) continue; if(p == null) continue;
if (p.getWorld().getName().equals(worldName) && !(useWhitelist ^ hiddenPlayerNames.contains(p.getName().toLowerCase()))) { if((worldName != null) && (p.getWorld().equals(worldName) == false)) continue;
visiblePlayers.add(p);
}
}
Player[] result = new Player[visiblePlayers.size()];
visiblePlayers.toArray(result);
return result;
}
public Player[] getVisiblePlayers() {
ArrayList<Player> visiblePlayers = new ArrayList<Player>();
Player[] onlinePlayers = online; /* Use copied list - we don't call from server thread */
boolean useWhitelist = configuration.getBoolean("display-whitelist", false);
for (int i = 0; i < onlinePlayers.length; i++) {
Player p = onlinePlayers[i];
if(p == null) continue;
if (!(useWhitelist ^ hiddenPlayerNames.contains(p.getName().toLowerCase()))) { if (!(useWhitelist ^ hiddenPlayerNames.contains(p.getName().toLowerCase()))) {
visiblePlayers.add(p); visiblePlayers.add(p);
} }
} }
Player[] result = new Player[visiblePlayers.size()]; return visiblePlayers;
visiblePlayers.toArray(result);
return result;
} }
public Set<Player> getHiddenPlayers() { public List<DynmapPlayer> getVisiblePlayers() {
HashSet<Player> hidden = new HashSet<Player>(); return getVisiblePlayers(null);
Player[] onlinePlayers = online; /* Use copied list - we don't call from server thread */ }
public List<DynmapPlayer> getHiddenPlayers() {
ArrayList<DynmapPlayer> hidden = new ArrayList<DynmapPlayer>();
DynmapPlayer[] onlinePlayers = online; /* Use copied list - we don't call from server thread */
boolean useWhitelist = configuration.getBoolean("display-whitelist", false); boolean useWhitelist = configuration.getBoolean("display-whitelist", false);
for (int i = 0; i < onlinePlayers.length; i++) { for (int i = 0; i < onlinePlayers.length; i++) {
Player p = onlinePlayers[i]; DynmapPlayer p = onlinePlayers[i];
if(p == null) continue; if(p == null) continue;
if (useWhitelist ^ hiddenPlayerNames.contains(p.getName().toLowerCase())) { if (useWhitelist ^ hiddenPlayerNames.contains(p.getName().toLowerCase())) {
hidden.add(p); hidden.add(p);
@ -121,10 +108,6 @@ public class PlayerList {
return hidden; return hidden;
} }
public boolean isVisiblePlayer(Player p) {
return isVisiblePlayer(p.getName());
}
public boolean isVisiblePlayer(String p) { public boolean isVisiblePlayer(String p) {
boolean useWhitelist = configuration.getBoolean("display-whitelist", false); boolean useWhitelist = configuration.getBoolean("display-whitelist", false);
return (!(useWhitelist ^ hiddenPlayerNames.contains(p.toLowerCase()))); return (!(useWhitelist ^ hiddenPlayerNames.contains(p.toLowerCase())));
@ -133,13 +116,13 @@ public class PlayerList {
/** /**
* Call this from server thread to update player list safely * Call this from server thread to update player list safely
*/ */
void updateOnlinePlayers(Player skipone) { void updateOnlinePlayers(String skipone) {
Player[] players = server.getOnlinePlayers(); DynmapPlayer[] players = server.getOnlinePlayers();
Player[] pl = new Player[players.length]; DynmapPlayer[] pl = new DynmapPlayer[players.length];
System.arraycopy(players, 0, pl, 0, pl.length); System.arraycopy(players, 0, pl, 0, pl.length);
if(skipone != null) { if(skipone != null) {
for(int i = 0; i < pl.length; i++) for(int i = 0; i < pl.length; i++)
if(pl[i] == skipone) if(pl[i].getName().equals(skipone))
pl[i] = null; pl[i] = null;
} }
online = pl; online = pl;

View File

@ -6,18 +6,20 @@ 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;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.dynmap.common.DynmapListenerManager;
import org.dynmap.common.DynmapListenerManager.ChatEventListener;
import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.common.DynmapPlayer;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class SimpleWebChatComponent extends Component { public class SimpleWebChatComponent extends Component {
public SimpleWebChatComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) { public SimpleWebChatComponent(final DynmapCore plugin, final ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() { plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
@Override @Override
public void triggered(ChatEvent t) { public void triggered(ChatEvent t) {
DynmapWebChatEvent evt = new DynmapWebChatEvent(t.source, t.name, t.message); if(plugin.getServer().sendWebChatEvent(t.source, t.name, t.message)) {
plugin.getServer().getPluginManager().callEvent(evt);
if(evt.isCancelled() == false) {
String msg; String msg;
String msgfmt = plugin.configuration.getString("webmsgformat", null); String msgfmt = plugin.configuration.getString("webmsgformat", null);
if(msgfmt != null) { if(msgfmt != null) {
@ -40,35 +42,29 @@ public class SimpleWebChatComponent extends Component {
}); });
if (configuration.getBoolean("allowchat", false)) { if (configuration.getBoolean("allowchat", false)) {
PlayerChatListener playerListener = new PlayerChatListener(); plugin.listenerManager.addListener(EventType.PLAYER_CHAT, new ChatEventListener() {
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_CHAT, playerListener);
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, playerListener);
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_JOIN, playerListener);
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_QUIT, playerListener);
}
}
protected class PlayerChatListener extends PlayerListener {
@Override @Override
public void onPlayerChat(PlayerChatEvent event) { public void chatEvent(DynmapPlayer p, String msg) {
if(event.isCancelled()) return; if(core.mapManager != null)
if(plugin.mapManager != null) core.mapManager.pushUpdate(new Client.ChatMessage("player", "", p.getDisplayName(), msg, p.getName()));
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", "", event.getPlayer().getDisplayName(), event.getMessage(), event.getPlayer().getName()));
} }
});
plugin.listenerManager.addListener(EventType.PLAYER_JOIN, new DynmapListenerManager.PlayerEventListener() {
@Override @Override
public void onPlayerJoin(PlayerJoinEvent event) { public void playerEvent(DynmapPlayer p) {
if((plugin.mapManager != null) && (plugin.playerList != null) && (plugin.playerList.isVisiblePlayer(event.getPlayer()))) { if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName())); core.mapManager.pushUpdate(new Client.PlayerJoinMessage(p.getDisplayName(), p.getName()));
} }
} }
});
plugin.listenerManager.addListener(EventType.PLAYER_QUIT, new DynmapListenerManager.PlayerEventListener() {
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void playerEvent(DynmapPlayer p) {
if((plugin.mapManager != null) && (plugin.playerList != null) && (plugin.playerList.isVisiblePlayer(event.getPlayer()))) { if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName())); core.mapManager.pushUpdate(new Client.PlayerQuitMessage(p.getDisplayName(), p.getName()));
}
}
});
} }
} }
} }
}

View File

@ -2,7 +2,7 @@ package org.dynmap;
public class TestComponent extends Component { public class TestComponent extends Component {
public TestComponent(DynmapPlugin plugin, ConfigurationNode configuration) { public TestComponent(DynmapCore plugin, ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
Log.info("Hello! I'm a component that does stuff! Like saying what is in my configuration: " + configuration.getString("stuff")); Log.info("Hello! I'm a component that does stuff! Like saying what is in my configuration: " + configuration.getString("stuff"));
} }

View File

@ -1,4 +1,4 @@
package org.dynmap; package org.dynmap.bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@ -0,0 +1,416 @@
package org.dynmap.bukkit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.dynmap.Log;
public class BukkitEventProcessor {
private Plugin plugin;
private PluginManager pm;
private HashMap<Event.Type, List<Listener>> event_handlers = new HashMap<Event.Type, List<Listener>>();
public BukkitEventProcessor(Plugin plugin) {
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void cleanup() {
/* Clean up all registered handlers */
for(Event.Type t : event_handlers.keySet()) {
List<Listener> ll = event_handlers.get(t);
ll.clear(); /* Empty list - we use presence of list to remember that we've registered with Bukkit */
}
pm = null;
plugin = null;
}
private BlockListener ourBlockEventHandler = new BlockListener() {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPlace(event);
}
}
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockBreak(event);
}
}
}
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onLeavesDecay(event);
}
}
}
@Override
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockBurn(event);
}
}
}
@Override
public void onBlockForm(BlockFormEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockForm(event);
}
}
}
@Override
public void onBlockFade(BlockFadeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockFade(event);
}
}
}
@Override
public void onBlockSpread(BlockSpreadEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockSpread(event);
}
}
}
@Override
public void onBlockFromTo(BlockFromToEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockFromTo(event);
}
}
}
@Override
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPhysics(event);
}
}
}
@Override
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPistonRetract(event);
}
}
}
@Override
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onBlockPistonExtend(event);
}
}
}
@Override
public void onSignChange(SignChangeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((BlockListener)l).onSignChange(event);
}
}
}
};
private PlayerListener ourPlayerEventHandler = new PlayerListener() {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerJoin(event);
}
}
}
@Override
public void onPlayerLogin(PlayerLoginEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerLogin(event);
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerMove(event);
}
}
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerQuit(event);
}
}
}
@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
public void onPlayerChat(PlayerChatEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((PlayerListener)l).onPlayerChat(event);
}
}
}
};
private WorldListener ourWorldEventHandler = new WorldListener() {
@Override
public void onWorldLoad(WorldLoadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onWorldLoad(event);
}
}
}
@Override
public void onWorldUnload(WorldUnloadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onWorldUnload(event);
}
}
}
@Override
public void onChunkLoad(ChunkLoadEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onChunkLoad(event);
}
}
}
@Override
public void onChunkPopulate(ChunkPopulateEvent event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((WorldListener)l).onChunkPopulate(event);
}
}
}
@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() {
@Override
public void onCustomEvent(Event event) {
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((CustomEventListener)l).onCustomEvent(event);
}
}
}
};
private EntityListener ourEntityEventHandler = new EntityListener() {
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if(event.isCancelled())
return;
/* Call listeners */
List<Listener> ll = event_handlers.get(event.getType());
if(ll != null) {
for(Listener l : ll) {
((EntityListener)l).onEntityExplode(event);
}
}
}
};
/**
* Register event listener - this will be cleaned up properly on a /dynmap reload, unlike
* registering with Bukkit directly
*/
public void registerEvent(Event.Type type, Listener listener) {
List<Listener> ll = event_handlers.get(type);
if(ll == null) {
switch(type) { /* See if it is a type we're brokering */
case PLAYER_LOGIN:
case PLAYER_CHAT:
case PLAYER_JOIN:
case PLAYER_QUIT:
case PLAYER_MOVE:
case PLAYER_BED_LEAVE:
pm.registerEvent(type, ourPlayerEventHandler, Event.Priority.Monitor, plugin);
break;
case BLOCK_PLACE:
case BLOCK_BREAK:
case LEAVES_DECAY:
case BLOCK_BURN:
case BLOCK_FORM:
case BLOCK_FADE:
case BLOCK_SPREAD:
case BLOCK_FROMTO:
case BLOCK_PHYSICS:
case BLOCK_PISTON_EXTEND:
case BLOCK_PISTON_RETRACT:
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Monitor, plugin);
break;
case SIGN_CHANGE:
pm.registerEvent(type, ourBlockEventHandler, Event.Priority.Low, plugin);
break;
case WORLD_LOAD:
case WORLD_UNLOAD:
case CHUNK_LOAD:
case CHUNK_POPULATED:
case SPAWN_CHANGE:
pm.registerEvent(type, ourWorldEventHandler, Event.Priority.Monitor, plugin);
break;
case CUSTOM_EVENT:
pm.registerEvent(type, ourCustomEventHandler, Event.Priority.Monitor, plugin);
break;
case ENTITY_EXPLODE:
pm.registerEvent(type, ourEntityEventHandler, Event.Priority.Monitor, plugin);
break;
default:
Log.severe("registerEvent() in DynmapPlugin does not handle " + type);
return;
}
ll = new ArrayList<Listener>();
event_handlers.put(type, ll); /* Add list for this event */
}
ll.add(listener);
}
}

View File

@ -0,0 +1,94 @@
package org.dynmap.bukkit;
/**
* Bukkit specific implementation of DynmapWorld
*/
import java.util.List;
import org.bukkit.Location;
import org.bukkit.World;
import org.dynmap.DynmapChunk;
import org.dynmap.DynmapLocation;
import org.dynmap.DynmapWorld;
import org.dynmap.utils.BlockLightLevel;
import org.dynmap.utils.MapChunkCache;
public class BukkitWorld extends DynmapWorld {
private World world;
private static BlockLightLevel bll = new BlockLightLevel();
public BukkitWorld(World w) {
super(w.getName());
world = w;
}
/* Test if world is nether */
@Override
public boolean isNether() {
return world.getEnvironment() == World.Environment.NETHER;
}
/* Get world spawn location */
@Override
public DynmapLocation getSpawnLocation() {
DynmapLocation dloc = new DynmapLocation();
Location sloc = world.getSpawnLocation();
dloc.x = sloc.getBlockX(); dloc.y = sloc.getBlockY();
dloc.z = sloc.getBlockZ(); dloc.world = sloc.getWorld().getName();
return dloc;
}
/* Get world time */
@Override
public long getTime() {
return world.getTime();
}
/* World is storming */
@Override
public boolean hasStorm() {
return world.hasStorm();
}
/* World is thundering */
@Override
public boolean isThundering() {
return world.isThundering();
}
/* World is loaded */
@Override
public boolean isLoaded() {
return (world != null);
}
/* Get light level of block */
@Override
public int getLightLevel(int x, int y, int z) {
return world.getBlockAt(x, y, z).getLightLevel();
}
/* Get highest Y coord of given location */
@Override
public int getHighestBlockYAt(int x, int z) {
return world.getHighestBlockYAt(x, z);
}
/* Test if sky light level is requestable */
@Override
public boolean canGetSkyLightLevel() {
return bll.isReady();
}
/* Return sky light level */
@Override
public int getSkyLightLevel(int x, int y, int z) {
return bll.getSkyLightLevel(world.getBlockAt(x, y, z));
}
/**
* Get world environment ID (lower case - normal, the_end, nether)
*/
@Override
public String getEnvironment() {
return world.getEnvironment().name().toLowerCase();
}
/**
* Get map chunk cache for world
*/
@Override
public MapChunkCache getChunkCache(List<DynmapChunk> chunks) {
MapChunkCache c = new NewMapChunkCache();
c.setChunks(world, chunks);
return c;
}
}

View File

@ -0,0 +1,846 @@
package org.dynmap.bukkit;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkPopulateEvent;
import org.bukkit.event.world.SpawnChangeEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation;
import org.dynmap.DynmapWebChatEvent;
import org.dynmap.DynmapWorld;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.common.DynmapCommandSender;
import org.dynmap.common.DynmapPlayer;
import org.dynmap.common.DynmapServerInterface;
import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.permissions.BukkitPermissions;
import org.dynmap.permissions.NijikokunPermissions;
import org.dynmap.permissions.OpPermissions;
import org.dynmap.permissions.PermissionProvider;
public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
private DynmapCore core;
private PermissionProvider permissions;
private String version;
public BukkitEventProcessor bep;
private MapManager mapManager;
public static DynmapPlugin plugin;
public DynmapPlugin() {
plugin = this;
}
/**
* Server access abstraction class
*/
public class BukkitServer implements DynmapServerInterface {
@Override
public void scheduleServerTask(Runnable run, long delay) {
getServer().getScheduler().scheduleSyncDelayedTask(DynmapPlugin.this, run, delay);
}
@Override
public DynmapPlayer[] getOnlinePlayers() {
Player[] players = getServer().getOnlinePlayers();
DynmapPlayer[] dplay = new DynmapPlayer[players.length];
for(int i = 0; i < players.length; i++)
dplay[i] = new BukkitPlayer(players[i]);
return dplay;
}
@Override
public void reload() {
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.disablePlugin(DynmapPlugin.this);
pluginManager.enablePlugin(DynmapPlugin.this);
}
@Override
public DynmapPlayer getPlayer(String name) {
Player p = getServer().getPlayerExact(name);
if(p != null) {
return new BukkitPlayer(p);
}
return null;
}
@Override
public Set<String> getIPBans() {
return getServer().getIPBans();
}
@Override
public <T> Future<T> callSyncMethod(Callable<T> task) {
return getServer().getScheduler().callSyncMethod(DynmapPlugin.this, task);
}
@Override
public String getServerName() {
return getServer().getServerName();
}
@Override
public boolean isPlayerBanned(String pid) {
OfflinePlayer p = getServer().getOfflinePlayer(pid);
if((p != null) && p.isBanned())
return true;
return false;
}
@Override
public String stripChatColor(String s) {
return ChatColor.stripColor(s);
}
private Set<EventType> registered = new HashSet<EventType>();
@Override
public boolean requestEventNotification(EventType type) {
if(registered.contains(type))
return true;
switch(type) {
case WORLD_LOAD:
case WORLD_UNLOAD:
/* Already called for normal world activation/deactivation */
break;
case WORLD_SPAWN_CHANGE:
bep.registerEvent(Type.SPAWN_CHANGE, new WorldListener() {
public void onWorldSpawnChange(SpawnChangeEvent evt) {
DynmapWorld w = new BukkitWorld(evt.getWorld());
core.listenerManager.processWorldEvent(EventType.WORLD_SPAWN_CHANGE, w);
}
});
break;
case PLAYER_JOIN:
case PLAYER_QUIT:
/* Already handled */
break;
case PLAYER_BED_LEAVE:
bep.registerEvent(Type.PLAYER_BED_LEAVE, new PlayerListener() {
@Override
public void onPlayerBedLeave(PlayerBedLeaveEvent evt) {
DynmapPlayer p = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_BED_LEAVE, p);
}
});
break;
case PLAYER_CHAT:
bep.registerEvent(Type.PLAYER_CHAT, new PlayerListener() {
@Override
public void onPlayerChat(PlayerChatEvent evt) {
DynmapPlayer p = null;
if(evt.getPlayer() != null)
p = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processChatEvent(EventType.PLAYER_CHAT, p, evt.getMessage());
}
});
break;
case BLOCK_BREAK:
bep.registerEvent(Type.BLOCK_BREAK, new BlockListener() {
@Override
public void onBlockBreak(BlockBreakEvent evt) {
Block b = evt.getBlock();
Location l = b.getLocation();
core.listenerManager.processBlockEvent(EventType.BLOCK_BREAK, b.getType().getId(),
l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
});
break;
case SIGN_CHANGE:
bep.registerEvent(Type.SIGN_CHANGE, new BlockListener() {
@Override
public void onSignChange(SignChangeEvent evt) {
Block b = evt.getBlock();
Location l = b.getLocation();
String[] lines = evt.getLines(); /* Note: changes to this change event - intentional */
DynmapPlayer dp = null;
Player p = evt.getPlayer();
if(p != null) dp = new BukkitPlayer(p);
core.listenerManager.processSignChangeEvent(EventType.SIGN_CHANGE, b.getType().getId(),
l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ(), lines, dp);
}
});
break;
default:
Log.severe("Unhandled event type: " + type);
return false;
}
return true;
}
@Override
public boolean sendWebChatEvent(String source, String name, String msg) {
DynmapWebChatEvent evt = new DynmapWebChatEvent(source, name, msg);
getServer().getPluginManager().callEvent(evt);
return (evt.isCancelled() == false);
}
@Override
public void broadcastMessage(String msg) {
getServer().broadcastMessage(msg);
}
}
/**
* Player access abstraction class
*/
public class BukkitPlayer extends BukkitCommandSender implements DynmapPlayer {
private Player player;
public BukkitPlayer(Player p) {
super(p);
player = p;
}
@Override
public boolean isConnected() {
return player.isOnline();
}
@Override
public String getName() {
return player.getName();
}
@Override
public String getDisplayName() {
return player.getDisplayName();
}
@Override
public boolean isOnline() {
return player.isOnline();
}
@Override
public DynmapLocation getLocation() {
Location loc = player.getLocation();
return toLoc(loc);
}
@Override
public String getWorld() {
World w = player.getWorld();
if(w != null)
return w.getName();
return null;
}
@Override
public InetSocketAddress getAddress() {
return player.getAddress();
}
@Override
public boolean isSneaking() {
return player.isSneaking();
}
@Override
public int getHealth() {
return player.getHealth();
}
@Override
public int getArmorPoints() {
return Armor.getArmorPoints(player);
}
@Override
public DynmapLocation getBedSpawnLocation() {
Location loc = player.getBedSpawnLocation();
if(loc != null) {
return toLoc(loc);
}
return null;
}
}
/* Handler for generic console command sender */
public class BukkitCommandSender implements DynmapCommandSender {
private CommandSender sender;
public BukkitCommandSender(CommandSender send) {
sender = send;
}
@Override
public boolean hasPrivilege(String privid) {
return permissions.has(sender, privid);
}
@Override
public void sendMessage(String msg) {
sender.sendMessage(msg);
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isOp() {
return sender.isOp();
}
}
@Override
public void onEnable() {
PluginDescriptionFile pdfFile = this.getDescription();
version = pdfFile.getVersion();
/* Initialize event processor */
if(bep == null)
bep = new BukkitEventProcessor(this);
/* Set up player login/quit event handler */
registerPlayerLoginListener();
permissions = NijikokunPermissions.create(getServer(), "dynmap");
if (permissions == null)
permissions = BukkitPermissions.create("dynmap");
if (permissions == null)
permissions = new OpPermissions(new String[] { "fullrender", "cancelrender", "radiusrender", "resetstats", "reload", "purgequeue", "pause", "ips-for-id", "ids-for-ip", "add-id-for-ip", "del-id-for-ip" });
/* Get and initialize data folder */
File dataDirectory = this.getDataFolder();
if(dataDirectory.exists() == false)
dataDirectory.mkdirs();
/* Get MC version */
String bukkitver = getServer().getVersion();
String mcver = "1.0.0";
int idx = bukkitver.indexOf("(MC: ");
if(idx > 0) {
mcver = bukkitver.substring(idx+5);
idx = mcver.indexOf(")");
if(idx > 0) mcver = mcver.substring(0, idx);
}
/* Instantiate core */
if(core == null)
core = new DynmapCore();
/* Inject dependencies */
core.setPluginVersion(version);
core.setMinecraftVersion(mcver);
core.setDataFolder(dataDirectory);
core.setServer(new BukkitServer());
/* Enable core */
if(!core.enableCore()) {
this.setEnabled(false);
return;
}
/* Get map manager from core */
mapManager = core.getMapManager();
/* Initialized the currently loaded worlds */
for (World world : getServer().getWorlds()) {
BukkitWorld w = new BukkitWorld(world);
if(core.processWorldLoad(w)) /* Have core process load first - fire event listeners if good load after */
core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, w);
}
/* Register our update trigger events */
registerEvents();
}
@Override
public void onDisable() {
/* Reset registered listeners */
bep.cleanup();
/* Disable core */
core.disableCore();
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
DynmapCommandSender dsender;
if(sender instanceof Player) {
dsender = new BukkitPlayer((Player)sender);
}
else {
dsender = new BukkitCommandSender(sender);
}
return core.processCommand(dsender, cmd.getName(), commandLabel, args);
}
@Override
public final MarkerAPI getMarkerAPI() {
return core.getMarkerAPI();
}
@Override
public final boolean markerAPIInitialized() {
return core.markerAPIInitialized();
}
@Override
public final boolean sendBroadcastToWeb(String sender, String msg) {
return core.sendBroadcastToWeb(sender, msg);
}
@Override
public final int triggerRenderOfVolume(String wid, int minx, int miny, int minz,
int maxx, int maxy, int maxz) {
return core.triggerRenderOfVolume(wid, minx, miny, minz, maxx, maxy, maxz);
}
@Override
public final int triggerRenderOfBlock(String wid, int x, int y, int z) {
return core.triggerRenderOfBlock(wid, x, y, z);
}
@Override
public final void setPauseFullRadiusRenders(boolean dopause) {
core.setPauseFullRadiusRenders(dopause);
}
@Override
public final boolean getPauseFullRadiusRenders() {
return core.getPauseFullRadiusRenders();
}
@Override
public final void setPauseUpdateRenders(boolean dopause) {
core.setPauseUpdateRenders(dopause);
}
@Override
public final boolean getPauseUpdateRenders() {
return core.getPauseUpdateRenders();
}
@Override
public final void setPlayerVisiblity(String player, boolean is_visible) {
core.setPlayerVisiblity(player, is_visible);
}
@Override
public final boolean getPlayerVisbility(String player) {
return core.getPlayerVisbility(player);
}
@Override
public final void postPlayerMessageToWeb(String playerid, String playerdisplay,
String message) {
core.postPlayerMessageToWeb(playerid, playerdisplay, message);
}
@Override
public final void postPlayerJoinQuitToWeb(String playerid, String playerdisplay,
boolean isjoin) {
core.postPlayerJoinQuitToWeb(playerid, playerdisplay, isjoin);
}
@Override
public final String getDynmapCoreVersion() {
return core.getDynmapCoreVersion();
}
@Override
public final int triggerRenderOfVolume(Location l0, Location l1) {
int x0 = l0.getBlockX(), y0 = l0.getBlockY(), z0 = l0.getBlockZ();
int x1 = l1.getBlockX(), y1 = l1.getBlockY(), z1 = l1.getBlockZ();
return core.triggerRenderOfVolume(l0.getWorld().getName(), Math.min(x0, x1), Math.min(y0, y1),
Math.min(z0, z1), Math.max(x0, x1), Math.max(y0, y1), Math.max(z0, z1));
}
@Override
public final void setPlayerVisiblity(Player player, boolean is_visible) {
core.setPlayerVisiblity(player.getName(), is_visible);
}
@Override
public final boolean getPlayerVisbility(Player player) {
return core.getPlayerVisbility(player.getName());
}
@Override
public final void postPlayerMessageToWeb(Player player, String message) {
core.postPlayerMessageToWeb(player.getName(), player.getDisplayName(), message);
}
@Override
public void postPlayerJoinQuitToWeb(Player player, boolean isjoin) {
core.postPlayerJoinQuitToWeb(player.getName(), player.getDisplayName(), isjoin);
}
@Override
public String getDynmapVersion() {
return version;
}
private static DynmapLocation toLoc(Location l) {
return new DynmapLocation(l.getWorld().getName(), l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
private void registerPlayerLoginListener() {
PlayerListener pl = new PlayerListener() {
public void onPlayerJoin(PlayerJoinEvent evt) {
DynmapPlayer dp = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_JOIN, dp);
}
public void onPlayerQuit(PlayerQuitEvent evt) {
DynmapPlayer dp = new BukkitPlayer(evt.getPlayer());
core.listenerManager.processPlayerEvent(EventType.PLAYER_QUIT, dp);
}
};
bep.registerEvent(Type.PLAYER_JOIN, pl);
bep.registerEvent(Type.PLAYER_QUIT, pl);
}
private boolean onplace;
private boolean onbreak;
private boolean onblockform;
private boolean onblockfade;
private boolean onblockspread;
private boolean onblockfromto;
private boolean onblockphysics;
private boolean onleaves;
private boolean onburn;
private boolean onpiston;
private boolean onplayerjoin;
private boolean onplayermove;
private boolean ongeneratechunk;
private boolean onloadchunk;
private boolean onexplosion;
private void registerEvents() {
BlockListener blockTrigger = new BlockListener() {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onplace) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockplace");
}
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onbreak) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockbreak");
}
}
@Override
public void onLeavesDecay(LeavesDecayEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onleaves) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "leavesdecay");
}
}
@Override
public void onBlockBurn(BlockBurnEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onburn) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockburn");
}
}
@Override
public void onBlockForm(BlockFormEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockform) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockform");
}
}
@Override
public void onBlockFade(BlockFadeEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockfade) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfade");
}
}
@Override
public void onBlockSpread(BlockSpreadEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockspread) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockspread");
}
}
@Override
public void onBlockFromTo(BlockFromToEvent event) {
if(event.isCancelled())
return;
Location loc = event.getToBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockfromto)
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfromto");
loc = event.getBlock().getLocation();
wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockfromto)
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockfromto");
}
@Override
public void onBlockPhysics(BlockPhysicsEvent event) {
if(event.isCancelled())
return;
Location loc = event.getBlock().getLocation();
String wn = loc.getWorld().getName();
mapManager.sscache.invalidateSnapshot(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if(onblockphysics) {
mapManager.touch(wn, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "blockphysics");
}
}
@Override
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if(event.isCancelled())
return;
Block b = event.getBlock();
Location loc = b.getLocation();
BlockFace dir;
try { /* Workaround Bukkit bug = http://leaky.bukkit.org/issues/1227 */
dir = event.getDirection();
} catch (ClassCastException ccx) {
dir = BlockFace.NORTH;
}
String wn = loc.getWorld().getName();
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
mapManager.sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
for(int i = 0; i < 2; i++) {
x += dir.getModX();
y += dir.getModY();
z += dir.getModZ();
mapManager.sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
}
}
@Override
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if(event.isCancelled())
return;
Block b = event.getBlock();
Location loc = b.getLocation();
BlockFace dir;
try { /* Workaround Bukkit bug = http://leaky.bukkit.org/issues/1227 */
dir = event.getDirection();
} catch (ClassCastException ccx) {
dir = BlockFace.NORTH;
}
String wn = loc.getWorld().getName();
int x = loc.getBlockX(), y = loc.getBlockY(), z = loc.getBlockZ();
mapManager.sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
for(int i = 0; i < 1+event.getLength(); i++) {
x += dir.getModX();
y += dir.getModY();
z += dir.getModZ();
mapManager.sscache.invalidateSnapshot(wn, x, y, z);
if(onpiston)
mapManager.touch(wn, x, y, z, "pistonretract");
}
}
};
// To trigger rendering.
onplace = core.isTrigger("blockplaced");
bep.registerEvent(Event.Type.BLOCK_PLACE, blockTrigger);
onbreak = core.isTrigger("blockbreak");
bep.registerEvent(Event.Type.BLOCK_BREAK, blockTrigger);
if(core.isTrigger("snowform")) Log.info("The 'snowform' trigger has been deprecated due to Bukkit changes - use 'blockformed'");
onleaves = core.isTrigger("leavesdecay");
bep.registerEvent(Event.Type.LEAVES_DECAY, blockTrigger);
onburn = core.isTrigger("blockburn");
bep.registerEvent(Event.Type.BLOCK_BURN, blockTrigger);
onblockform = core.isTrigger("blockformed");
bep.registerEvent(Event.Type.BLOCK_FORM, blockTrigger);
onblockfade = core.isTrigger("blockfaded");
bep.registerEvent(Event.Type.BLOCK_FADE, blockTrigger);
onblockspread = core.isTrigger("blockspread");
bep.registerEvent(Event.Type.BLOCK_SPREAD, blockTrigger);
onblockfromto = core.isTrigger("blockfromto");
bep.registerEvent(Event.Type.BLOCK_FROMTO, blockTrigger);
onblockphysics = core.isTrigger("blockphysics");
bep.registerEvent(Event.Type.BLOCK_PHYSICS, blockTrigger);
onpiston = core.isTrigger("pistonmoved");
bep.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, blockTrigger);
bep.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, blockTrigger);
/* Register player event trigger handlers */
PlayerListener playerTrigger = new PlayerListener() {
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
if(onplayerjoin) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playerjoin");
}
core.listenerManager.processPlayerEvent(EventType.PLAYER_JOIN, new BukkitPlayer(event.getPlayer()));
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
core.listenerManager.processPlayerEvent(EventType.PLAYER_QUIT, new BukkitPlayer(event.getPlayer()));
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Location loc = event.getPlayer().getLocation();
mapManager.touch(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), "playermove");
}
};
onplayerjoin = core.isTrigger("playerjoin");
onplayermove = core.isTrigger("playermove");
bep.registerEvent(Event.Type.PLAYER_JOIN, playerTrigger);
bep.registerEvent(Event.Type.PLAYER_QUIT, playerTrigger);
if(onplayermove)
bep.registerEvent(Event.Type.PLAYER_MOVE, playerTrigger);
/* Register entity event triggers */
EntityListener entityTrigger = new EntityListener() {
@Override
public void onEntityExplode(EntityExplodeEvent event) {
Location loc = event.getLocation();
String wname = loc.getWorld().getName();
int minx, maxx, miny, maxy, minz, maxz;
minx = maxx = loc.getBlockX();
miny = maxy = loc.getBlockY();
minz = maxz = loc.getBlockZ();
/* Calculate volume impacted by explosion */
List<Block> blocks = event.blockList();
for(Block b: blocks) {
Location l = b.getLocation();
int x = l.getBlockX();
if(x < minx) minx = x;
if(x > maxx) maxx = x;
int y = l.getBlockY();
if(y < miny) miny = y;
if(y > maxy) maxy = y;
int z = l.getBlockZ();
if(z < minz) minz = z;
if(z > maxz) maxz = z;
}
mapManager.sscache.invalidateSnapshot(wname, minx, miny, minz, maxx, maxy, maxz);
if(onexplosion) {
mapManager.touchVolume(wname, minx, miny, minz, maxx, maxy, maxz, "entityexplode");
}
}
};
onexplosion = core.isTrigger("explosion");
bep.registerEvent(Event.Type.ENTITY_EXPLODE, entityTrigger);
/* Register world event triggers */
WorldListener worldTrigger = new WorldListener() {
@Override
public void onChunkLoad(ChunkLoadEvent event) {
if(core.ignore_chunk_loads)
return;
Chunk c = event.getChunk();
/* Touch extreme corners */
int x = c.getX() << 4;
int z = c.getZ() << 4;
mapManager.touchVolume(event.getWorld().getName(), x, 0, z, x+15, 128, z+16, "chunkload");
}
@Override
public void onChunkPopulate(ChunkPopulateEvent event) {
Chunk c = event.getChunk();
/* Touch extreme corners */
int x = c.getX() << 4;
int z = c.getZ() << 4;
mapManager.touchVolume(event.getWorld().getName(), x, 0, z, x+15, 128, z+16, "chunkpopulate");
}
@Override
public void onWorldLoad(WorldLoadEvent event) {
core.updateConfigHashcode();
BukkitWorld w = new BukkitWorld(event.getWorld());
if(core.processWorldLoad(w)) /* Have core process load first - fire event listeners if good load after */
core.listenerManager.processWorldEvent(EventType.WORLD_LOAD, w);
}
@Override
public void onWorldUnload(WorldUnloadEvent event) {
core.updateConfigHashcode();
DynmapWorld w = core.getWorld(event.getWorld().getName());
if(w != null)
core.listenerManager.processWorldEvent(EventType.WORLD_UNLOAD, w);
}
};
ongeneratechunk = core.isTrigger("chunkgenerated");
if(ongeneratechunk) {
bep.registerEvent(Event.Type.CHUNK_POPULATED, worldTrigger);
}
onloadchunk = core.isTrigger("chunkloaded");
if(onloadchunk) {
bep.registerEvent(Event.Type.CHUNK_LOAD, worldTrigger);
}
// To link configuration to real loaded worlds.
bep.registerEvent(Event.Type.WORLD_LOAD, worldTrigger);
bep.registerEvent(Event.Type.WORLD_UNLOAD, worldTrigger);
}
}

View File

@ -1,4 +1,4 @@
package org.dynmap.utils; package org.dynmap.bukkit;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -14,10 +14,14 @@ import org.bukkit.block.Biome;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.MapIterator;
import org.dynmap.utils.MapChunkCache.HiddenChunkStyle;
import org.dynmap.utils.MapChunkCache.VisibilityLimit;
import org.dynmap.utils.MapIterator.BlockStep; import org.dynmap.utils.MapIterator.BlockStep;
/** /**
@ -446,7 +450,7 @@ public class NewMapChunkCache implements MapChunkCache {
checkTickList(); checkTickList();
DynmapPlugin.setIgnoreChunkLoads(true); DynmapCore.setIgnoreChunkLoads(true);
//boolean isnormral = w.getEnvironment() == Environment.NORMAL; //boolean isnormral = w.getEnvironment() == Environment.NORMAL;
// Load the required chunks. // Load the required chunks.
while((cnt < max_to_load) && iterator.hasNext()) { while((cnt < max_to_load) && iterator.hasNext()) {
@ -556,7 +560,7 @@ public class NewMapChunkCache implements MapChunkCache {
} }
cnt++; cnt++;
} }
DynmapPlugin.setIgnoreChunkLoads(false); DynmapCore.setIgnoreChunkLoads(false);
if(iterator.hasNext() == false) { /* If we're done */ if(iterator.hasNext() == false) { /* If we're done */
isempty = true; isempty = true;

View File

@ -0,0 +1,37 @@
package org.dynmap.common;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
public enum DynmapChatColor {
BLACK(0x0),
DARK_BLUE(0x1),
DARK_GREEN(0x2),
DARK_AQUA(0x3),
DARK_RED(0x4),
DARK_PURPLE(0x5),
GOLD(0x6),
GRAY(0x7),
DARK_GRAY(0x8),
BLUE(0x9),
GREEN(0xA),
AQUA(0xB),
RED(0xC),
LIGHT_PURPLE(0xD),
YELLOW(0xE),
WHITE(0xF);
private final int code;
private final String str;
private DynmapChatColor(final int code) {
this.code = code;
this.str = String.format("\u00A7%x", code);
}
@Override
public String toString() {
return str;
}
}

View File

@ -0,0 +1,24 @@
package org.dynmap.common;
public interface DynmapCommandSender {
/**
* Does command sender have given security privilege
* @param privid - privilege ID
* @return true if it does, false if it doesn't
*/
public boolean hasPrivilege(String privid);
/**
* Send given message to command sender
* @param msg - message to be sent (with color codes marked &0 to &F)
*/
public void sendMessage(String msg);
/**
* Test if command sender is still connected/online
* @return true if connected, false if not
*/
public boolean isConnected();
/**
* Is operator privilege
*/
public boolean isOp();
}

View File

@ -0,0 +1,124 @@
package org.dynmap.common;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld;
/**
* Simple handler for managing event listeners and dispatch in a neutral fashion
*
*/
public class DynmapListenerManager {
private DynmapCore core;
public DynmapListenerManager(DynmapCore core) {
this.core = core;
}
public interface EventListener {
}
public interface WorldEventListener extends EventListener {
public void worldEvent(DynmapWorld w);
}
public interface PlayerEventListener extends EventListener {
public void playerEvent(DynmapPlayer p);
}
public interface ChatEventListener extends EventListener {
public void chatEvent(DynmapPlayer p, String msg);
}
public interface BlockEventListener extends EventListener {
public void blockEvent(int blkid, String w, int x, int y, int z);
}
public interface SignChangeEventListener extends EventListener {
public void signChangeEvent(int blkid, String w, int x, int y, int z, String[] lines, DynmapPlayer p);
}
public enum EventType {
WORLD_LOAD,
WORLD_UNLOAD,
WORLD_SPAWN_CHANGE,
PLAYER_JOIN,
PLAYER_QUIT,
PLAYER_BED_LEAVE,
PLAYER_CHAT,
BLOCK_BREAK,
SIGN_CHANGE
}
private Map<EventType, ArrayList<EventListener>> listeners = new EnumMap<EventType, ArrayList<EventListener>>(EventType.class);
public void addListener(EventType type, EventListener listener) {
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) {
lst = new ArrayList<EventListener>();
listeners.put(type, lst);
core.getServer().requestEventNotification(type);
}
lst.add(listener);
}
public void processWorldEvent(EventType type, DynmapWorld w) {
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) return;
int sz = lst.size();
for(int i = 0; i < sz; i++) {
EventListener el = lst.get(i);
if(el instanceof WorldEventListener) {
((WorldEventListener)el).worldEvent(w);
}
}
}
public void processPlayerEvent(EventType type, DynmapPlayer p) {
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) return;
int sz = lst.size();
for(int i = 0; i < sz; i++) {
EventListener el = lst.get(i);
if(el instanceof PlayerEventListener) {
((PlayerEventListener)el).playerEvent(p);
}
}
}
public void processChatEvent(EventType type, DynmapPlayer p, String msg) {
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) return;
int sz = lst.size();
for(int i = 0; i < sz; i++) {
EventListener el = lst.get(i);
if(el instanceof ChatEventListener) {
((ChatEventListener)el).chatEvent(p, msg);
}
}
}
public void processBlockEvent(EventType type, int blkid, String world, int x, int y, int z)
{
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) return;
int sz = lst.size();
for(int i = 0; i < sz; i++) {
EventListener el = lst.get(i);
if(el instanceof BlockEventListener) {
((BlockEventListener)el).blockEvent(blkid, world, x, y, z);
}
}
}
public void processSignChangeEvent(EventType type, int blkid, String world, int x, int y, int z, String[] lines, DynmapPlayer p)
{
ArrayList<EventListener> lst = listeners.get(type);
if(lst == null) return;
int sz = lst.size();
for(int i = 0; i < sz; i++) {
EventListener el = lst.get(i);
if(el instanceof SignChangeEventListener) {
((SignChangeEventListener)el).signChangeEvent(blkid, world, x, y, z, lines, p);
}
}
}
/* Clean up registered listeners */
public void cleanup() {
for(ArrayList<EventListener> l : listeners.values())
l.clear();
listeners.clear();
}
}

View File

@ -0,0 +1,57 @@
package org.dynmap.common;
import java.net.InetSocketAddress;
import org.bukkit.Location;
import org.dynmap.DynmapLocation;
/**
* Player (server neutral) - represents online or offline player
*/
public interface DynmapPlayer extends DynmapCommandSender {
/**
* Get player ID
* @return ID (case insensitive)
*/
public String getName();
/**
* Get player display name
* @return display name
*/
public String getDisplayName();
/**
* Is player online?
* @return true if online
*/
public boolean isOnline();
/**
* Get current location of player
* @return location
*/
public DynmapLocation getLocation();
/**
* Get world ID of player
* @return id
*/
public String getWorld();
/**
* Get connected address for player
*/
public InetSocketAddress getAddress();
/**
* Check if player is sneaking
*/
public boolean isSneaking();
/**
* Get health
*/
public int getHealth();
/**
* Get armor points
*/
public int getArmorPoints();
/**
* Get spawn bed location
*/
public DynmapLocation getBedSpawnLocation();
}

View File

@ -0,0 +1,75 @@
package org.dynmap.common;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.dynmap.DynmapWorld;
import org.dynmap.common.DynmapListenerManager.EventType;
/**
* This interface defines a server-neutral interface for the DynmapCore and other neutral components to use to access server provided
* services. Platform-specific plugin must supply DynmapCore with an instance of an object implementing this interface.
*/
public interface DynmapServerInterface {
/**
* Schedule task to run on server-safe thread (one suitable for other server API calls)
* @param run - runnable method
* @param delay - delay in server ticks (50msec)
*/
public void scheduleServerTask(Runnable run, long delay);
/**
* Call method on server-safe thread
* @param call - Callable method
* @return future for completion of call
*/
public <T> Future<T> callSyncMethod(Callable<T> task);
/**
* Get list of online players
* @return list of online players
*/
public DynmapPlayer[] getOnlinePlayers();
/**
* Request reload of plugin
*/
public void reload();
/**
* Get active player
* @param name - player name
* @return player
*/
public DynmapPlayer getPlayer(String name);
/**
* Get banned IPs
*/
public Set<String> getIPBans();
/**
* Get server name
*/
public String getServerName();
/**
* Test if player ID is banned
*/
public boolean isPlayerBanned(String pid);
/**
* Strip out chat color
*/
public String stripChatColor(String s);
/**
* Request notificiation for given events (used by DynmapListenerManager)
*/
public boolean requestEventNotification(EventType type);
/**
* Send notification of web chat message
* @param source - source
* @param name - name
* @param msg - message text
* @return true if not cancelled
*/
public boolean sendWebChatEvent(String source, String name, String msg);
/**
* Broadcast message to players
* @param msg
*/
public void broadcastMessage(String msg);
}

View File

@ -14,8 +14,9 @@ import org.dynmap.Color;
import org.dynmap.ColorScheme; import org.dynmap.ColorScheme;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation; import org.dynmap.DynmapLocation;
import org.dynmap.DynmapPlugin.CompassMode; import org.dynmap.DynmapCore.CompassMode;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.TileHashManager; import org.dynmap.TileHashManager;
import org.dynmap.MapTile; import org.dynmap.MapTile;
@ -42,11 +43,11 @@ public class FlatMap extends MapType {
private Texture textured = Texture.NONE; private Texture textured = Texture.NONE;
private boolean isbigmap; private boolean isbigmap;
public FlatMap(ConfigurationNode configuration) { public FlatMap(DynmapCore core, ConfigurationNode configuration) {
this.configuration = configuration; this.configuration = configuration;
name = configuration.getString("name", null); name = configuration.getString("name", null);
prefix = configuration.getString("prefix", name); prefix = configuration.getString("prefix", name);
colorScheme = ColorScheme.getScheme((String) configuration.get("colorscheme")); colorScheme = ColorScheme.getScheme(core, (String) configuration.get("colorscheme"));
Object o = configuration.get("maximumheight"); Object o = configuration.get("maximumheight");
if (o != null) { if (o != null) {
maximumHeight = Integer.parseInt(String.valueOf(o)); maximumHeight = Integer.parseInt(String.valueOf(o));

View File

@ -3,6 +3,7 @@ package org.dynmap.hdmap;
import static org.dynmap.JSONUtils.s; import static org.dynmap.JSONUtils.s;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.MapIterator; import org.dynmap.utils.MapIterator;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -12,7 +13,7 @@ public class CaveHDShader implements HDShader {
private boolean iflit; private boolean iflit;
public CaveHDShader(ConfigurationNode configuration) { public CaveHDShader(DynmapCore core, ConfigurationNode configuration) {
name = (String) configuration.get("name"); name = (String) configuration.get("name");
iflit = configuration.getBoolean("onlyiflit", false); iflit = configuration.getBoolean("onlyiflit", false);
} }

View File

@ -2,13 +2,14 @@ package org.dynmap.hdmap;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import static org.dynmap.JSONUtils.s; import static org.dynmap.JSONUtils.s;
public class DefaultHDLighting implements HDLighting { public class DefaultHDLighting implements HDLighting {
private String name; private String name;
public DefaultHDLighting(ConfigurationNode configuration) { public DefaultHDLighting(DynmapCore core, ConfigurationNode configuration) {
name = (String) configuration.get("name"); name = (String) configuration.get("name");
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.block.Biome;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ColorScheme; import org.dynmap.ColorScheme;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.MapIterator; import org.dynmap.utils.MapIterator;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -19,9 +20,9 @@ public class DefaultHDShader implements HDShader {
} }
protected BiomeColorOption biomecolored = BiomeColorOption.NONE; /* Use biome for coloring */ protected BiomeColorOption biomecolored = BiomeColorOption.NONE; /* Use biome for coloring */
public DefaultHDShader(ConfigurationNode configuration) { public DefaultHDShader(DynmapCore core, ConfigurationNode configuration) {
name = (String) configuration.get("name"); name = (String) configuration.get("name");
colorScheme = ColorScheme.getScheme(configuration.getString("colorscheme", "default")); colorScheme = ColorScheme.getScheme(core, configuration.getString("colorscheme", "default"));
transparency = configuration.getBoolean("transparency", true); /* Default on */ transparency = configuration.getBoolean("transparency", true); /* Default on */
String biomeopt = configuration.getString("biomecolored", "none"); String biomeopt = configuration.getString("biomecolored", "none");
if(biomeopt.equals("biome")) { if(biomeopt.equals("biome")) {

View File

@ -9,6 +9,7 @@ import java.util.List;
import org.dynmap.Client; import org.dynmap.Client;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation; import org.dynmap.DynmapLocation;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Log; import org.dynmap.Log;
@ -36,7 +37,7 @@ public class HDMap extends MapType {
public static final String IMGFORMAT_JPG = "jpg"; public static final String IMGFORMAT_JPG = "jpg";
public HDMap(ConfigurationNode configuration) { public HDMap(DynmapCore core, ConfigurationNode configuration) {
name = configuration.getString("name", null); name = configuration.getString("name", null);
if(name == null) { if(name == null) {
Log.severe("HDMap missing required attribute 'name' - disabled"); Log.severe("HDMap missing required attribute 'name' - disabled");

View File

@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
@ -25,29 +25,29 @@ public class HDMapManager {
public static boolean waterlightingfix; public static boolean waterlightingfix;
public static boolean biomeshadingfix; public static boolean biomeshadingfix;
public void loadHDShaders(DynmapPlugin plugin) { public void loadHDShaders(DynmapCore core) {
Log.verboseinfo("Loading shaders..."); Log.verboseinfo("Loading shaders...");
File f = new File(plugin.getDataFolder(), "shaders.txt"); File f = new File(core.getDataFolder(), "shaders.txt");
if(!plugin.updateUsingDefaultResource("/shaders.txt", f, "shaders")) { if(!core.updateUsingDefaultResource("/shaders.txt", f, "shaders")) {
return; return;
} }
org.bukkit.util.config.Configuration bukkitShaderConfig = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration bukkitShaderConfig = new org.bukkit.util.config.Configuration(f);
bukkitShaderConfig.load(); bukkitShaderConfig.load();
ConfigurationNode shadercfg = new ConfigurationNode(bukkitShaderConfig); ConfigurationNode shadercfg = new ConfigurationNode(bukkitShaderConfig);
for(HDShader shader : shadercfg.<HDShader>createInstances("shaders", new Class<?>[0], new Object[0])) { for(HDShader shader : shadercfg.<HDShader>createInstances("shaders", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(shader.getName() == null) continue; if(shader.getName() == null) continue;
shaders.put(shader.getName(), shader); shaders.put(shader.getName(), shader);
} }
/* Load custom shaders, if file is defined - or create empty one if not */ /* Load custom shaders, if file is defined - or create empty one if not */
f = new File(plugin.getDataFolder(), "custom-shaders.txt"); f = new File(core.getDataFolder(), "custom-shaders.txt");
plugin.createDefaultFileFromResource("/custom-shaders.txt", f); core.createDefaultFileFromResource("/custom-shaders.txt", f);
if(f.exists()) { if(f.exists()) {
bukkitShaderConfig = new org.bukkit.util.config.Configuration(f); bukkitShaderConfig = new org.bukkit.util.config.Configuration(f);
bukkitShaderConfig.load(); bukkitShaderConfig.load();
ConfigurationNode customshadercfg = new ConfigurationNode(bukkitShaderConfig); ConfigurationNode customshadercfg = new ConfigurationNode(bukkitShaderConfig);
for(HDShader shader : customshadercfg.<HDShader>createInstances("shaders", new Class<?>[0], new Object[0])) { for(HDShader shader : customshadercfg.<HDShader>createInstances("shaders", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(shader.getName() == null) continue; if(shader.getName() == null) continue;
shaders.put(shader.getName(), shader); shaders.put(shader.getName(), shader);
} }
@ -57,27 +57,27 @@ public class HDMapManager {
TexturePack.handleHideOres(); TexturePack.handleHideOres();
} }
public void loadHDPerspectives(DynmapPlugin plugin) { public void loadHDPerspectives(DynmapCore core) {
Log.verboseinfo("Loading perspectives..."); Log.verboseinfo("Loading perspectives...");
File f = new File(plugin.getDataFolder(), "perspectives.txt"); File f = new File(core.getDataFolder(), "perspectives.txt");
if(!plugin.updateUsingDefaultResource("/perspectives.txt", f, "perspectives")) { if(!core.updateUsingDefaultResource("/perspectives.txt", f, "perspectives")) {
return; return;
} }
org.bukkit.util.config.Configuration bukkitPerspectiveConfig = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration bukkitPerspectiveConfig = new org.bukkit.util.config.Configuration(f);
bukkitPerspectiveConfig.load(); bukkitPerspectiveConfig.load();
ConfigurationNode perspectivecfg = new ConfigurationNode(bukkitPerspectiveConfig); ConfigurationNode perspectivecfg = new ConfigurationNode(bukkitPerspectiveConfig);
for(HDPerspective perspective : perspectivecfg.<HDPerspective>createInstances("perspectives", new Class<?>[0], new Object[0])) { for(HDPerspective perspective : perspectivecfg.<HDPerspective>createInstances("perspectives", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(perspective.getName() == null) continue; if(perspective.getName() == null) continue;
perspectives.put(perspective.getName(), perspective); perspectives.put(perspective.getName(), perspective);
} }
/* Load custom perspectives, if file is defined - or create empty one if not */ /* Load custom perspectives, if file is defined - or create empty one if not */
f = new File(plugin.getDataFolder(), "custom-perspectives.txt"); f = new File(core.getDataFolder(), "custom-perspectives.txt");
plugin.createDefaultFileFromResource("/custom-perspectives.txt", f); core.createDefaultFileFromResource("/custom-perspectives.txt", f);
if(f.exists()) { if(f.exists()) {
bukkitPerspectiveConfig = new org.bukkit.util.config.Configuration(f); bukkitPerspectiveConfig = new org.bukkit.util.config.Configuration(f);
bukkitPerspectiveConfig.load(); bukkitPerspectiveConfig.load();
perspectivecfg = new ConfigurationNode(bukkitPerspectiveConfig); perspectivecfg = new ConfigurationNode(bukkitPerspectiveConfig);
for(HDPerspective perspective : perspectivecfg.<HDPerspective>createInstances("perspectives", new Class<?>[0], new Object[0])) { for(HDPerspective perspective : perspectivecfg.<HDPerspective>createInstances("perspectives", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(perspective.getName() == null) continue; if(perspective.getName() == null) continue;
perspectives.put(perspective.getName(), perspective); perspectives.put(perspective.getName(), perspective);
} }
@ -85,28 +85,28 @@ public class HDMapManager {
Log.info("Loaded " + perspectives.size() + " perspectives."); Log.info("Loaded " + perspectives.size() + " perspectives.");
} }
public void loadHDLightings(DynmapPlugin plugin) { public void loadHDLightings(DynmapCore core) {
Log.verboseinfo("Loading lightings..."); Log.verboseinfo("Loading lightings...");
File f = new File(plugin.getDataFolder(), "lightings.txt"); File f = new File(core.getDataFolder(), "lightings.txt");
if(!plugin.updateUsingDefaultResource("/lightings.txt", f, "lightings")) { if(!core.updateUsingDefaultResource("/lightings.txt", f, "lightings")) {
return; return;
} }
org.bukkit.util.config.Configuration bukkitLightingsConfig = new org.bukkit.util.config.Configuration(f); org.bukkit.util.config.Configuration bukkitLightingsConfig = new org.bukkit.util.config.Configuration(f);
bukkitLightingsConfig.load(); bukkitLightingsConfig.load();
ConfigurationNode lightingcfg = new ConfigurationNode(bukkitLightingsConfig); ConfigurationNode lightingcfg = new ConfigurationNode(bukkitLightingsConfig);
for(HDLighting lighting : lightingcfg.<HDLighting>createInstances("lightings", new Class<?>[0], new Object[0])) { for(HDLighting lighting : lightingcfg.<HDLighting>createInstances("lightings", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(lighting.getName() == null) continue; if(lighting.getName() == null) continue;
lightings.put(lighting.getName(), lighting); lightings.put(lighting.getName(), lighting);
} }
/* Load custom lightings, if file is defined - or create empty one if not */ /* Load custom lightings, if file is defined - or create empty one if not */
f = new File(plugin.getDataFolder(), "custom-lightings.txt"); f = new File(core.getDataFolder(), "custom-lightings.txt");
plugin.createDefaultFileFromResource("/custom-lightings.txt", f); core.createDefaultFileFromResource("/custom-lightings.txt", f);
if(f.exists()) { if(f.exists()) {
bukkitLightingsConfig = new org.bukkit.util.config.Configuration(f); bukkitLightingsConfig = new org.bukkit.util.config.Configuration(f);
bukkitLightingsConfig.load(); bukkitLightingsConfig.load();
lightingcfg = new ConfigurationNode(bukkitLightingsConfig); lightingcfg = new ConfigurationNode(bukkitLightingsConfig);
for(HDLighting lighting : lightingcfg.<HDLighting>createInstances("lightings", new Class<?>[0], new Object[0])) { for(HDLighting lighting : lightingcfg.<HDLighting>createInstances("lightings", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if(lighting.getName() == null) continue; if(lighting.getName() == null) continue;
lightings.put(lighting.getName(), lighting); lightings.put(lighting.getName(), lighting);
} }

View File

@ -14,8 +14,9 @@ import org.dynmap.Client;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation; import org.dynmap.DynmapLocation;
import org.dynmap.DynmapPlugin.CompassMode; import org.dynmap.DynmapCore.CompassMode;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.MapTile; import org.dynmap.MapTile;
@ -762,7 +763,7 @@ public class IsoHDPerspective implements HDPerspective {
} }
} }
public IsoHDPerspective(ConfigurationNode configuration) { public IsoHDPerspective(DynmapCore core, ConfigurationNode configuration) {
name = configuration.getString("name", null); name = configuration.getString("name", null);
if(name == null) { if(name == null) {
Log.severe("Perspective definition missing name - must be defined and unique"); Log.severe("Perspective definition missing name - must be defined and unique");

View File

@ -2,6 +2,7 @@ package org.dynmap.hdmap;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
public class ShadowHDLighting extends DefaultHDLighting { public class ShadowHDLighting extends DefaultHDLighting {
@ -10,8 +11,8 @@ public class ShadowHDLighting extends DefaultHDLighting {
protected int lightscale[]; /* scale skylight level (light = lightscale[skylight] */ protected int lightscale[]; /* scale skylight level (light = lightscale[skylight] */
protected boolean night_and_day; /* If true, render both day (prefix+'-day') and night (prefix) tiles */ protected boolean night_and_day; /* If true, render both day (prefix+'-day') and night (prefix) tiles */
public ShadowHDLighting(ConfigurationNode configuration) { public ShadowHDLighting(DynmapCore core, ConfigurationNode configuration) {
super(configuration); super(core, configuration);
double shadowweight = configuration.getDouble("shadowstrength", 0.0); double shadowweight = configuration.getDouble("shadowstrength", 0.0);
if(shadowweight > 0.0) { if(shadowweight > 0.0) {
shadowscale = new int[16]; shadowscale = new int[16];

View File

@ -22,7 +22,7 @@ import javax.imageio.ImageIO;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.utils.DynmapBufferedImage; import org.dynmap.utils.DynmapBufferedImage;
@ -219,12 +219,12 @@ public class TexturePack {
} }
/** Get or load texture pack */ /** Get or load texture pack */
public static TexturePack getTexturePack(String tpname) { public static TexturePack getTexturePack(DynmapCore core, String tpname) {
TexturePack tp = packs.get(tpname); TexturePack tp = packs.get(tpname);
if(tp != null) if(tp != null)
return tp; return tp;
try { try {
tp = new TexturePack(tpname); /* Attempt to load pack */ tp = new TexturePack(core, tpname); /* Attempt to load pack */
packs.put(tpname, tp); packs.put(tpname, tp);
return tp; return tp;
} catch (FileNotFoundException fnfx) { } catch (FileNotFoundException fnfx) {
@ -235,9 +235,9 @@ public class TexturePack {
/** /**
* Constructor for texture pack, by name * Constructor for texture pack, by name
*/ */
private TexturePack(String tpname) throws FileNotFoundException { private TexturePack(DynmapCore core, String tpname) throws FileNotFoundException {
ZipFile zf = null; ZipFile zf = null;
File texturedir = getTexturePackDirectory(); File texturedir = getTexturePackDirectory(core);
boolean use_generate = HDMapManager.usegeneratedtextures; boolean use_generate = HDMapManager.usegeneratedtextures;
if(HDMapManager.biomeshadingfix == false) if(HDMapManager.biomeshadingfix == false)
water_toned_op = COLORMOD_OLD_WATERSHADED; water_toned_op = COLORMOD_OLD_WATERSHADED;
@ -650,8 +650,8 @@ public class TexturePack {
} }
/* Get texture pack directory */ /* Get texture pack directory */
private static File getTexturePackDirectory() { private static File getTexturePackDirectory(DynmapCore core) {
return new File(DynmapPlugin.dataDirectory, "texturepacks"); return new File(core.getDataFolder(), "texturepacks");
} }
/** /**

View File

@ -4,6 +4,7 @@ import static org.dynmap.JSONUtils.s;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
@ -19,10 +20,10 @@ public class TexturePackHDShader implements HDShader {
private boolean waterbiomeshaded; private boolean waterbiomeshaded;
private boolean bettergrass; private boolean bettergrass;
public TexturePackHDShader(ConfigurationNode configuration) { public TexturePackHDShader(DynmapCore core, ConfigurationNode configuration) {
tpname = configuration.getString("texturepack", "minecraft"); tpname = configuration.getString("texturepack", "minecraft");
name = configuration.getString("name", tpname); name = configuration.getString("name", tpname);
tp = TexturePack.getTexturePack(tpname); tp = TexturePack.getTexturePack(core, tpname);
biome_shaded = configuration.getBoolean("biomeshaded", true); biome_shaded = configuration.getBoolean("biomeshaded", true);
swamp_shaded = configuration.getBoolean("swampshaded", MapManager.mapman.getSwampShading()); swamp_shaded = configuration.getBoolean("swampshaded", MapManager.mapman.getSwampShading());
waterbiomeshaded = configuration.getBoolean("waterbiomeshaded", MapManager.mapman.getWaterBiomeShading()); waterbiomeshaded = configuration.getBoolean("waterbiomeshaded", MapManager.mapman.getWaterBiomeShading());

View File

@ -4,6 +4,7 @@ import static org.dynmap.JSONUtils.s;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.MapIterator; import org.dynmap.utils.MapIterator;
@ -28,7 +29,7 @@ public class TopoHDShader implements HDShader {
} }
return null; return null;
} }
public TopoHDShader(ConfigurationNode configuration) { public TopoHDShader(DynmapCore core, ConfigurationNode configuration) {
name = (String) configuration.get("name"); name = (String) configuration.get("name");
fillcolor = new Color[128]; /* Color by Y */ fillcolor = new Color[128]; /* Color by Y */

View File

@ -4,7 +4,6 @@ import java.lang.reflect.Method;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Server;
import org.bukkit.event.CustomEventListener; import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
@ -12,9 +11,13 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.dynmap.Client; import org.dynmap.Client;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.bukkit.DynmapPlugin;
/**
* Bukkit specific module - alternate chat handler for interfacing with HeroChat
*/
public class HeroChatHandler { public class HeroChatHandler {
private static final String DEF_CHANNEL = "Global"; private static final String DEF_CHANNEL = "Global";
private static final List<String> DEF_CHANNELS = Collections private static final List<String> DEF_CHANNELS = Collections
@ -22,7 +25,7 @@ public class HeroChatHandler {
private List<String> hcchannels; private List<String> hcchannels;
private String hcwebinputchannel; private String hcwebinputchannel;
private DynmapPlugin plugin; private DynmapCore core;
private HeroChatChannel hcwebinputchan; private HeroChatChannel hcwebinputchan;
private class OurPluginListener extends ServerListener { private class OurPluginListener extends ServerListener {
@ -229,9 +232,9 @@ public class HeroChatHandler {
if (hcchannels.contains(c.getName()) || if (hcchannels.contains(c.getName()) ||
hcchannels.contains(c.getNick())) { hcchannels.contains(c.getNick())) {
if(cce.isSentByPlayer()) { /* Player message? */ if(cce.isSentByPlayer()) { /* Player message? */
org.bukkit.entity.Player p = plugin.getServer().getPlayer(cce.getSource()); org.bukkit.entity.Player p = DynmapPlugin.plugin.getServer().getPlayer(cce.getSource());
if((p != null) && (plugin.mapManager != null)) { if((p != null) && (core.mapManager != null)) {
plugin.mapManager.pushUpdate(new Client.ChatMessage("player", core.mapManager.pushUpdate(new Client.ChatMessage("player",
c.getNick(), c.getNick(),
p.getDisplayName(), p.getDisplayName(),
cce.getMessage(), cce.getMessage(),
@ -244,21 +247,21 @@ public class HeroChatHandler {
} }
} }
public HeroChatHandler(ConfigurationNode cfg, DynmapPlugin plugin, Server server) { public HeroChatHandler(ConfigurationNode cfg, DynmapCore core) {
/* If we're enabling hero chat support */ /* If we're enabling hero chat support */
Log.verboseinfo("HeroChat support configured"); Log.verboseinfo("HeroChat support configured");
this.plugin = plugin; this.core = core;
/* Now, get the monitored channel list */ /* Now, get the monitored channel list */
hcchannels = cfg.getStrings("herochatchannels", DEF_CHANNELS); hcchannels = cfg.getStrings("herochatchannels", DEF_CHANNELS);
/* And get channel to send web messages */ /* And get channel to send web messages */
hcwebinputchannel = cfg.getString("herochatwebchannel", DEF_CHANNEL); hcwebinputchannel = cfg.getString("herochatwebchannel", DEF_CHANNEL);
Plugin hc = server.getPluginManager().getPlugin("HeroChat"); Plugin hc = DynmapPlugin.plugin.getServer().getPluginManager().getPlugin("HeroChat");
if(hc != null) { if(hc != null) {
activateHeroChat(hc); activateHeroChat(hc);
} }
else { else {
/* Set up to hear when HeroChat is enabled */ /* Set up to hear when HeroChat is enabled */
plugin.registerEvent(Event.Type.PLUGIN_ENABLE, new OurPluginListener()); DynmapPlugin.plugin.bep.registerEvent(Event.Type.PLUGIN_ENABLE, new OurPluginListener());
} }
} }
@ -276,7 +279,7 @@ public class HeroChatHandler {
return; return;
} }
/* Register event handler */ /* Register event handler */
plugin.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener()); DynmapPlugin.plugin.bep.registerEvent(Event.Type.CUSTOM_EVENT, new OurEventListener());
Log.verboseinfo("HeroChat integration active"); Log.verboseinfo("HeroChat integration active");
} }
/** /**

View File

@ -2,29 +2,26 @@ package org.dynmap.herochat;
import static org.dynmap.JSONUtils.s; import static org.dynmap.JSONUtils.s;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.dynmap.ChatEvent; import org.dynmap.ChatEvent;
import org.dynmap.Client; import org.dynmap.Client;
import org.dynmap.Component; import org.dynmap.Component;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.DynmapWebChatEvent;
import org.dynmap.Event; import org.dynmap.Event;
import org.dynmap.common.DynmapListenerManager;
import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.common.DynmapPlayer;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class HeroWebChatComponent extends Component { public class HeroWebChatComponent extends Component {
HeroChatHandler handler; HeroChatHandler handler;
public HeroWebChatComponent(final DynmapPlugin plugin, ConfigurationNode configuration) { public HeroWebChatComponent(final DynmapCore plugin, ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
handler = new HeroChatHandler(configuration, plugin, plugin.getServer()); handler = new HeroChatHandler(configuration, plugin);
plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() { plugin.events.addListener("webchat", new Event.Listener<ChatEvent>() {
@Override @Override
public void triggered(ChatEvent t) { public void triggered(ChatEvent t) {
DynmapWebChatEvent evt = new DynmapWebChatEvent(t.source, t.name, t.message); if(plugin.getServer().sendWebChatEvent(t.source, t.name, t.message)) {
plugin.getServer().getPluginManager().callEvent(evt);
if(evt.isCancelled() == false) {
/* Let HeroChat take a look - only broadcast to players if it doesn't handle it */ /* Let HeroChat take a look - only broadcast to players if it doesn't handle it */
if (!handler.sendWebMessageToHeroChat(t.name, t.message)) { if (!handler.sendWebMessageToHeroChat(t.name, t.message)) {
String msg; String msg;
@ -50,25 +47,22 @@ public class HeroWebChatComponent extends Component {
}); });
// Also make HeroChat announce joins and quits. // Also make HeroChat announce joins and quits.
PlayerChatListener playerListener = new PlayerChatListener(); core.listenerManager.addListener(EventType.PLAYER_JOIN, new DynmapListenerManager.PlayerEventListener() {
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_LOGIN, playerListener);
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_JOIN, playerListener);
plugin.registerEvent(org.bukkit.event.Event.Type.PLAYER_QUIT, playerListener);
}
protected class PlayerChatListener extends PlayerListener {
@Override @Override
public void onPlayerJoin(PlayerJoinEvent event) { public void playerEvent(DynmapPlayer p) {
if((plugin.mapManager != null) && (plugin.playerList != null) && (plugin.playerList.isVisiblePlayer(event.getPlayer()))) { if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
plugin.mapManager.pushUpdate(new Client.PlayerJoinMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName())); core.mapManager.pushUpdate(new Client.PlayerJoinMessage(p.getDisplayName(), p.getName()));
} }
} }
});
core.listenerManager.addListener(EventType.PLAYER_QUIT, new DynmapListenerManager.PlayerEventListener() {
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void playerEvent(DynmapPlayer p) {
if((plugin.mapManager != null) && (plugin.playerList != null) && (plugin.playerList.isVisiblePlayer(event.getPlayer()))) { if((core.mapManager != null) && (core.playerList != null) && (core.playerList.isVisiblePlayer(p.getName()))) {
plugin.mapManager.pushUpdate(new Client.PlayerQuitMessage(event.getPlayer().getDisplayName(), event.getPlayer().getName())); core.mapManager.pushUpdate(new Client.PlayerQuitMessage(p.getDisplayName(), p.getName()));
} }
} }
});
} }
} }

View File

@ -2,14 +2,15 @@ package org.dynmap.kzedmap;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.utils.MapIterator; import org.dynmap.utils.MapIterator;
import org.dynmap.utils.MapIterator.BlockStep; import org.dynmap.utils.MapIterator.BlockStep;
public class CaveTileRenderer extends DefaultTileRenderer { public class CaveTileRenderer extends DefaultTileRenderer {
private boolean iflit; private boolean iflit;
public CaveTileRenderer(ConfigurationNode configuration) { public CaveTileRenderer(DynmapCore core, ConfigurationNode configuration) {
super(configuration); super(core, configuration);
iflit = configuration.getBoolean("onlyiflit", false); iflit = configuration.getBoolean("onlyiflit", false);
} }

View File

@ -14,9 +14,10 @@ import org.dynmap.Client;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ColorScheme; import org.dynmap.ColorScheme;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.DynmapPlugin.CompassMode; import org.dynmap.DynmapCore.CompassMode;
import org.dynmap.MapType.ImageFormat; import org.dynmap.MapType.ImageFormat;
import org.dynmap.TileHashManager; import org.dynmap.TileHashManager;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
@ -58,7 +59,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
public boolean isNightAndDayEnabled() { return night_and_day; } public boolean isNightAndDayEnabled() { return night_and_day; }
public DefaultTileRenderer(ConfigurationNode configuration) { public DefaultTileRenderer(DynmapCore core, ConfigurationNode configuration) {
this.configuration = configuration; this.configuration = configuration;
name = configuration.getString("name", null); name = configuration.getString("name", null);
prefix = configuration.getString("prefix", name); prefix = configuration.getString("prefix", name);
@ -94,7 +95,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
lightscale[i] = i - (15-v); lightscale[i] = i - (15-v);
} }
} }
colorScheme = ColorScheme.getScheme((String)configuration.get("colorscheme")); colorScheme = ColorScheme.getScheme(core, (String)configuration.get("colorscheme"));
night_and_day = configuration.getBoolean("night-and-day", false); night_and_day = configuration.getBoolean("night-and-day", false);
transparency = configuration.getBoolean("transparency", true); /* Default on */ transparency = configuration.getBoolean("transparency", true); /* Default on */
String biomeopt = configuration.getString("biomecolored", "none"); String biomeopt = configuration.getString("biomecolored", "none");

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.dynmap.Color; import org.dynmap.Color;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.utils.MapIterator; import org.dynmap.utils.MapIterator;
import org.dynmap.utils.MapIterator.BlockStep; import org.dynmap.utils.MapIterator.BlockStep;
@ -12,8 +13,8 @@ import org.dynmap.utils.MapIterator.BlockStep;
public class HighlightTileRenderer extends DefaultTileRenderer { public class HighlightTileRenderer extends DefaultTileRenderer {
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>(); protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
public HighlightTileRenderer(ConfigurationNode configuration) { public HighlightTileRenderer(DynmapCore core, ConfigurationNode configuration) {
super(configuration); super(core, configuration);
List<Integer> highlight = configuration.<Integer>getList("highlight"); List<Integer> highlight = configuration.<Integer>getList("highlight");
for(Integer i : highlight) { for(Integer i : highlight) {
highlightBlocks.add(i); highlightBlocks.add(i);

View File

@ -9,6 +9,7 @@ import java.util.logging.Logger;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapLocation; import org.dynmap.DynmapLocation;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
@ -40,9 +41,9 @@ public class KzedMap extends MapType {
MapTileRenderer[] renderers; MapTileRenderer[] renderers;
private boolean isbigmap; private boolean isbigmap;
public KzedMap(ConfigurationNode configuration) { public KzedMap(DynmapCore core, ConfigurationNode configuration) {
Log.verboseinfo("Loading renderers for map '" + getClass().toString() + "'..."); Log.verboseinfo("Loading renderers for map '" + getClass().toString() + "'...");
List<MapTileRenderer> renderers = configuration.<MapTileRenderer>createInstances("renderers", new Class<?>[0], new Object[0]); List<MapTileRenderer> renderers = configuration.<MapTileRenderer>createInstances("renderers", new Class<?>[] { DynmapCore.class }, new Object[] { core } );
this.renderers = new MapTileRenderer[renderers.size()]; this.renderers = new MapTileRenderer[renderers.size()];
renderers.toArray(this.renderers); renderers.toArray(this.renderers);
Log.verboseinfo("Loaded " + renderers.size() + " renderers for map '" + getClass().toString() + "'."); Log.verboseinfo("Loaded " + renderers.size() + " renderers for map '" + getClass().toString() + "'.");

View File

@ -20,24 +20,17 @@ import java.util.TreeSet;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.Configuration; import org.bukkit.util.config.Configuration;
import org.bukkit.util.config.ConfigurationNode; import org.bukkit.util.config.ConfigurationNode;
import org.dynmap.Client; import org.dynmap.DynmapCore;
import org.dynmap.ClientUpdateEvent; import org.dynmap.DynmapLocation;
import org.dynmap.DynmapPlugin;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Event; import org.dynmap.Event;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.MapManager; import org.dynmap.MapManager;
import org.dynmap.Client.ComponentMessage; import org.dynmap.Client.ComponentMessage;
import org.dynmap.Client.PlayerJoinMessage; import org.dynmap.common.DynmapCommandSender;
import org.dynmap.common.DynmapPlayer;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.Marker; import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerAPI;
@ -56,9 +49,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
private File markertiledir; /* Marker directory for web server (under tiles) */ private File markertiledir; /* Marker directory for web server (under tiles) */
private HashMap<String, MarkerIconImpl> markericons = new HashMap<String, MarkerIconImpl>(); private HashMap<String, MarkerIconImpl> markericons = new HashMap<String, MarkerIconImpl>();
private HashMap<String, MarkerSetImpl> markersets = new HashMap<String, MarkerSetImpl>(); private HashMap<String, MarkerSetImpl> markersets = new HashMap<String, MarkerSetImpl>();
private HashMap<String, List<Location>> pointaccum = new HashMap<String, List<Location>>(); private HashMap<String, List<DynmapLocation>> pointaccum = new HashMap<String, List<DynmapLocation>>();
private Server server; private DynmapCore core;
private Plugin dynmap;
static MarkerAPIImpl api; static MarkerAPIImpl api;
/* Built-in icons */ /* Built-in icons */
@ -224,23 +216,22 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
dirty_worlds.clear(); dirty_worlds.clear();
} }
server.getScheduler().scheduleSyncDelayedTask(dynmap, this, 20); core.getServer().scheduleServerTask(this, 20);
} }
} }
/** /**
* Singleton initializer * Singleton initializer
*/ */
public static MarkerAPIImpl initializeMarkerAPI(DynmapPlugin plugin) { public static MarkerAPIImpl initializeMarkerAPI(DynmapCore core) {
if(api != null) { if(api != null) {
api.cleanup(plugin); api.cleanup(core);
} }
api = new MarkerAPIImpl(); api = new MarkerAPIImpl();
api.dynmap = plugin; api.core = core;
api.server = plugin.getServer();
/* Initialize persistence file name */ /* Initialize persistence file name */
api.markerpersist = new File(plugin.getDataFolder(), "markers.yml"); api.markerpersist = new File(core.getDataFolder(), "markers.yml");
api.markerpersist_old = new File(plugin.getDataFolder(), "markers.yml.old"); api.markerpersist_old = new File(core.getDataFolder(), "markers.yml.old");
/* Fill in default icons and sets, if needed */ /* Fill in default icons and sets, if needed */
for(int i = 0; i < builtin_icons.length; i++) { for(int i = 0; i < builtin_icons.length; i++) {
String id = builtin_icons[i]; String id = builtin_icons[i];
@ -255,13 +246,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
/* Build paths for markers */ /* Build paths for markers */
api.markerdir = new File(plugin.getDataFolder(), "markers"); api.markerdir = new File(core.getDataFolder(), "markers");
if(api.markerdir.isDirectory() == false) { if(api.markerdir.isDirectory() == false) {
if(api.markerdir.mkdirs() == false) { /* Create directory if needed */ if(api.markerdir.mkdirs() == false) { /* Create directory if needed */
Log.severe("Error creating markers directory - " + api.markerdir.getPath()); Log.severe("Error creating markers directory - " + api.markerdir.getPath());
} }
} }
api.markertiledir = new File(DynmapPlugin.tilesDirectory, "_markers_"); api.markertiledir = new File(core.getTilesFolder(), "_markers_");
if(api.markertiledir.isDirectory() == false) { if(api.markertiledir.isDirectory() == false) {
if(api.markertiledir.mkdirs() == false) { /* Create directory if needed */ if(api.markertiledir.mkdirs() == false) { /* Create directory if needed */
Log.severe("Error creating markers directory - " + api.markertiledir.getPath()); Log.severe("Error creating markers directory - " + api.markertiledir.getPath());
@ -274,7 +265,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
/* Freshen files */ /* Freshen files */
api.freshenMarkerFiles(); api.freshenMarkerFiles();
/* Add listener so we update marker files for other worlds as they become active */ /* Add listener so we update marker files for other worlds as they become active */
plugin.events.addListener("worldactivated", api); core.events.addListener("worldactivated", api);
api.scheduleWriteJob(); /* Start write job */ api.scheduleWriteJob(); /* Start write job */
@ -282,13 +273,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
private void scheduleWriteJob() { private void scheduleWriteJob() {
server.getScheduler().scheduleSyncDelayedTask(dynmap, new DoFileWrites(), 20); core.getServer().scheduleServerTask(new DoFileWrites(), 20);
} }
/** /**
* Cleanup * Cleanup
*/ */
public void cleanup(DynmapPlugin plugin) { public void cleanup(DynmapCore plugin) {
plugin.events.removeListener("worldactivated", api); plugin.events.removeListener("worldactivated", api);
stop = true; stop = true;
@ -589,7 +580,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
} }
private static boolean processAreaArgs(CommandSender sender, AreaMarker marker, Map<String,String> parms) { private static boolean processAreaArgs(DynmapCommandSender sender, AreaMarker marker, Map<String,String> parms) {
String val = null; String val = null;
try { try {
double ytop = marker.getTopY(); double ytop = marker.getTopY();
@ -656,7 +647,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
private static final String ARG_YBOTTOM = "ybottom"; private static final String ARG_YBOTTOM = "ybottom";
/* Parse argument strings : handle 'attrib:value' and quoted strings */ /* Parse argument strings : handle 'attrib:value' and quoted strings */
private static Map<String,String> parseArgs(String[] args, CommandSender snd) { private static Map<String,String> parseArgs(String[] args, DynmapCommandSender snd) {
HashMap<String,String> rslt = new HashMap<String,String>(); HashMap<String,String> rslt = new HashMap<String,String>();
/* Build command line, so we can parse our way - make sure there is trailing space */ /* Build command line, so we can parse our way - make sure there is trailing space */
String cmdline = ""; String cmdline = "";
@ -716,9 +707,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
public static boolean onCommand(DynmapPlugin plugin, CommandSender sender, Command cmd, String commandLabel, String[] args) { public static boolean onCommand(DynmapCore plugin, DynmapCommandSender sender, String cmd, String commandLabel, String[] args) {
String id, setid, file, label, newlabel, iconid, prio, minzoom; String id, setid, file, label, newlabel, iconid, prio, minzoom;
String val;
if(api == null) { if(api == null) {
sender.sendMessage("Markers component is not enabled."); sender.sendMessage("Markers component is not enabled.");
@ -726,16 +716,16 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
if(args.length == 0) if(args.length == 0)
return false; return false;
Player player = null; DynmapPlayer player = null;
if (sender instanceof Player) if (sender instanceof DynmapPlayer)
player = (Player) sender; player = (DynmapPlayer) sender;
/* Check if valid command */ /* Check if valid command */
String c = args[0]; String c = args[0];
if (!commands.contains(c)) { if (!commands.contains(c)) {
return false; return false;
} }
/* Process commands */ /* Process commands */
if(c.equals("add") && plugin.checkPlayerPermission(sender, "marker.add")) { if(c.equals("add") && api.core.checkPlayerPermission(sender, "marker.add")) {
if(player == null) { if(player == null) {
sender.sendMessage("Command can only be used by player"); sender.sendMessage("Command can only be used by player");
} }
@ -748,7 +738,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
id = parms.get(ARG_ID); id = parms.get(ARG_ID);
label = parms.get(ARG_LABEL); label = parms.get(ARG_LABEL);
Location loc = player.getLocation(); DynmapLocation loc = player.getLocation();
/* Fill in defaults for missing parameters */ /* Fill in defaults for missing parameters */
if(iconid == null) { if(iconid == null) {
iconid = MarkerIcon.DEFAULT; iconid = MarkerIcon.DEFAULT;
@ -768,7 +758,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return true; return true;
} }
Marker m = set.createMarker(id, label, Marker m = set.createMarker(id, label,
loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), ico, true); loc.world, loc.x, loc.y, loc.z, ico, true);
if(m == null) { if(m == null) {
sender.sendMessage("Error creating marker"); sender.sendMessage("Error creating marker");
} }
@ -819,8 +809,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return true; return true;
} }
} }
Location loc = player.getLocation(); DynmapLocation loc = player.getLocation();
marker.setLocation(loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ()); marker.setLocation(loc.world, loc.x, loc.y, loc.z);
sender.sendMessage("Updated location of marker id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")"); sender.sendMessage("Updated location of marker id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
} }
else { else {
@ -1268,7 +1258,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
} }
/* Add point to accumulator */ /* Add point to accumulator */
else if(c.equals("addcorner") && plugin.checkPlayerPermission(sender, "marker.addarea")) { else if(c.equals("addcorner") && plugin.checkPlayerPermission(sender, "marker.addarea")) {
Location loc = null; DynmapLocation loc = null;
if(player == null) { if(player == null) {
id = "-console-"; id = "-console-";
} }
@ -1276,28 +1266,28 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
id = player.getName(); id = player.getName();
loc = player.getLocation(); loc = player.getLocation();
} }
List<Location> ll = api.pointaccum.get(id); /* Find list */ List<DynmapLocation> ll = api.pointaccum.get(id); /* Find list */
if(args.length > 2) { /* Enough for coord */ if(args.length > 2) { /* Enough for coord */
World w = null; String w = null;
if(args.length == 3) { /* No world */ if(args.length == 3) { /* No world */
if(ll == null) { /* No points? Error */ if(ll == null) { /* No points? Error */
sender.sendMessage("First added corner needs world ID after coordinates"); sender.sendMessage("First added corner needs world ID after coordinates");
return true; return true;
} }
else { else {
w = ll.get(0).getWorld(); /* Use same world */ w = ll.get(0).world; /* Use same world */
} }
} }
else { /* Get world ID */ else { /* Get world ID */
w = api.server.getWorld(args[3]); w = args[3];
if(w == null) { if(api.core.getWorld(w) == null) {
sender.sendMessage("Invalid world ID: " + args[3]); sender.sendMessage("Invalid world ID: " + args[3]);
return true; return true;
} }
} }
try { try {
loc = new Location(w, Double.parseDouble(args[1]), 64.0, Double.parseDouble(args[2])); loc = new DynmapLocation(w, Double.parseDouble(args[1]), 64.0, Double.parseDouble(args[2]));
} catch (NumberFormatException nfx) { } catch (NumberFormatException nfx) {
sender.sendMessage("Bad format: /dmarker addcorner <x> <z> <world>"); sender.sendMessage("Bad format: /dmarker addcorner <x> <z> <world>");
return true; return true;
@ -1308,16 +1298,16 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
return true; return true;
} }
if(ll == null) { if(ll == null) {
ll = new ArrayList<Location>(); ll = new ArrayList<DynmapLocation>();
api.pointaccum.put(id, ll); api.pointaccum.put(id, ll);
} }
else { /* Else, if list exists, see if world matches */ else { /* Else, if list exists, see if world matches */
if(ll.get(0).getWorld().equals(loc.getWorld()) == false) { if(ll.get(0).world.equals(loc.world) == false) {
ll.clear(); /* Reset list - point on new world */ ll.clear(); /* Reset list - point on new world */
} }
} }
ll.add(loc); ll.add(loc);
sender.sendMessage("Added corner #" + ll.size() + " at {" + loc.getX() + "," + loc.getY() + "," + loc.getZ() + "} to list"); sender.sendMessage("Added corner #" + ll.size() + " at {" + loc.x + "," + loc.y + "," + loc.z + "} to list");
} }
else if(c.equals("clearcorners") && plugin.checkPlayerPermission(sender, "marker.addarea")) { else if(c.equals("clearcorners") && plugin.checkPlayerPermission(sender, "marker.addarea")) {
if(player == null) { if(player == null) {
@ -1337,7 +1327,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
else { else {
pid = player.getName(); pid = player.getName();
} }
List<Location> ll = api.pointaccum.get(pid); /* Find list */ List<DynmapLocation> ll = api.pointaccum.get(pid); /* Find list */
if((ll == null) || (ll.size() < 2)) { /* Not enough points? */ if((ll == null) || (ll.size() < 2)) { /* Not enough points? */
sender.sendMessage("At least two corners must be added with /dmarker addcorner before an area can be added"); sender.sendMessage("At least two corners must be added with /dmarker addcorner before an area can be added");
return true; return true;
@ -1362,12 +1352,12 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
double[] xx = new double[ll.size()]; double[] xx = new double[ll.size()];
double[] zz = new double[ll.size()]; double[] zz = new double[ll.size()];
for(int i = 0; i < ll.size(); i++) { for(int i = 0; i < ll.size(); i++) {
Location loc = ll.get(i); DynmapLocation loc = ll.get(i);
xx[i] = loc.getX(); xx[i] = loc.x;
zz[i] = loc.getZ(); zz[i] = loc.z;
} }
/* Make area marker */ /* Make area marker */
AreaMarker m = set.createAreaMarker(id, label, false, ll.get(0).getWorld().getName(), xx, zz, true); AreaMarker m = set.createAreaMarker(id, label, false, ll.get(0).world, xx, zz, true);
if(m == null) { if(m == null) {
sender.sendMessage("Error creating area"); sender.sendMessage("Error creating area");
} }

View File

@ -2,20 +2,11 @@ package org.dynmap.markers.impl;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor; import org.dynmap.DynmapCore;
import org.bukkit.Location; import org.dynmap.common.DynmapChatColor;
import org.bukkit.Material; import org.dynmap.common.DynmapListenerManager;
import org.bukkit.block.Block; import org.dynmap.common.DynmapListenerManager.EventType;
import org.bukkit.entity.Player; import org.dynmap.common.DynmapPlayer;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.plugin.PluginManager;
import org.dynmap.DynmapPlugin;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.markers.Marker; import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerIcon; import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet; import org.dynmap.markers.MarkerSet;
@ -23,34 +14,35 @@ import org.dynmap.markers.MarkerSet;
public class MarkerSignManager { public class MarkerSignManager {
private static MarkerSignManager mgr = null; private static MarkerSignManager mgr = null;
private static DynmapPlugin plugin = null; private static DynmapCore plugin = null;
private static class SignListener extends BlockListener { private static final int SIGNPOST_ID = 63;
private static final int WALLSIGN_ID = 68;
private static class SignListener implements DynmapListenerManager.BlockEventListener, DynmapListenerManager.SignChangeEventListener {
@Override @Override
public void onSignChange(SignChangeEvent evt) { public void signChangeEvent(int blkid, String wname, int x, int y, int z, String[] lines, DynmapPlayer p) {
if(evt.isCancelled() || (mgr == null)) if(mgr == null)
return; return;
if(!evt.getLine(0).equalsIgnoreCase("[dynmap]")) { /* If not dynmap sign, quit */ if(!lines[0].equalsIgnoreCase("[dynmap]")) { /* If not dynmap sign, quit */
return; return;
} }
Player p = evt.getPlayer();
/* If allowed to do marker signs */ /* If allowed to do marker signs */
if((p == null) || ((plugin != null) && (plugin.checkPlayerPermission(p, "marker.sign")))) { if((p == null) || ((plugin != null) && (plugin.checkPlayerPermission(p, "marker.sign")))) {
Location loc = evt.getBlock().getLocation(); String id = getSignMarkerID(wname, x, y, z); /* Get marker ID */
String id = getSignMarkerID(loc); /* Get marker ID */
String set = MarkerSet.DEFAULT; String set = MarkerSet.DEFAULT;
String icon = MarkerIcon.SIGN; String icon = MarkerIcon.SIGN;
String label = ""; String label = "";
evt.setLine(0, ""); /* Blank out [dynmap] */ lines[0] = ""; /* Blank out [dynmap] */
for(int i = 1; i < 4; i++) { /* Check other lines for icon: or set: */ for(int i = 1; i < 4; i++) { /* Check other lines for icon: or set: */
String v = ChatColor.stripColor(evt.getLine(i)); String v = plugin.getServer().stripChatColor(lines[i]);
if(v.startsWith("icon:")) { /* icon: */ if(v.startsWith("icon:")) { /* icon: */
icon = v.substring(5); icon = v.substring(5);
evt.setLine(i, ""); lines[i] = "";
} }
else if(v.startsWith("set:")) { /* set: */ else if(v.startsWith("set:")) { /* set: */
set = v.substring(4); set = v.substring(4);
evt.setLine(i, ""); lines[i] = "";
} }
else if(v.length() > 0) { else if(v.length() > 0) {
if(label.length() > 0) { if(label.length() > 0) {
@ -63,13 +55,13 @@ public class MarkerSignManager {
MarkerSet ms = MarkerAPIImpl.api.getMarkerSet(set); MarkerSet ms = MarkerAPIImpl.api.getMarkerSet(set);
if(ms == null) { if(ms == null) {
if(p != null) p.sendMessage("Bad marker set - [dynmap] sign invalid"); if(p != null) p.sendMessage("Bad marker set - [dynmap] sign invalid");
evt.setLine(0, ChatColor.RED + "<Bad Marker Set>"); lines[0] = DynmapChatColor.RED + "<Bad Marker Set>";
return; return;
} }
MarkerIcon mi = MarkerAPIImpl.api.getMarkerIcon(icon); /* Get icon */ MarkerIcon mi = MarkerAPIImpl.api.getMarkerIcon(icon); /* Get icon */
if(mi == null) { if(mi == null) {
if(p != null) p.sendMessage("Bad marker icon - [dynmap] sign invalid"); if(p != null) p.sendMessage("Bad marker icon - [dynmap] sign invalid");
evt.setLine(0, ChatColor.RED + "<Bad Marker Icon>"); lines[0] = DynmapChatColor.RED + "<Bad Marker Icon>";
return; return;
} }
Marker marker = ms.findMarker(id); Marker marker = ms.findMarker(id);
@ -79,25 +71,22 @@ public class MarkerSignManager {
marker.setMarkerIcon(mi); marker.setMarkerIcon(mi);
} }
else { /* Make new marker */ else { /* Make new marker */
marker = ms.createMarker(id, label, true, loc.getWorld().getName(), loc.getX() + 0.5, loc.getY() + 0.5, loc.getZ() + 0.5, marker = ms.createMarker(id, label, true, wname, (double)x + 0.5, (double)y + 0.5, (double)z + 0.5,
mi, true); mi, true);
if(marker == null) { if(marker == null) {
if(p != null) p.sendMessage("Bad marker - [dynmap] sign invalid"); if(p != null) p.sendMessage("Bad marker - [dynmap] sign invalid");
evt.setLine(0, ChatColor.RED + "<Bad Marker>"); lines[0] = DynmapChatColor.RED + "<Bad Marker>";
return; return;
} }
} }
} }
} }
@Override @Override
public void onBlockBreak(BlockBreakEvent evt) { public void blockEvent(int blkid, String wname, int x, int y, int z) {
if(evt.isCancelled() || (mgr == null)) if(mgr == null)
return; return;
Block blk = evt.getBlock(); if((blkid == WALLSIGN_ID) || (blkid == SIGNPOST_ID)) { /* If sign */
Material m = blk.getType(); String id = getSignMarkerID(wname, x, y, z); /* Marker sign? */
if((m == Material.SIGN) || (m == Material.SIGN_POST) || (m == Material.WALL_SIGN)) { /* If sign */
Location loc = blk.getLocation();
String id = getSignMarkerID(loc); /* Marker sign? */
Set<MarkerSet> sets = MarkerAPIImpl.api.getMarkerSets(); Set<MarkerSet> sets = MarkerAPIImpl.api.getMarkerSets();
for(MarkerSet ms : sets) { for(MarkerSet ms : sets) {
Marker marker = ms.findMarker(id); /* See if in this set */ Marker marker = ms.findMarker(id); /* See if in this set */
@ -118,22 +107,21 @@ public class MarkerSignManager {
return v; return v;
} }
public static MarkerSignManager initializeSignManager(DynmapPlugin plugin) { public static MarkerSignManager initializeSignManager(DynmapCore plugin) {
mgr = new MarkerSignManager(); mgr = new MarkerSignManager();
if(sl == null) { if(sl == null) {
sl = new SignListener(); sl = new SignListener();
PluginManager pm = plugin.getServer().getPluginManager(); plugin.listenerManager.addListener(EventType.BLOCK_BREAK, sl);
pm.registerEvent(Event.Type.BLOCK_BREAK, sl, Event.Priority.Monitor, plugin); plugin.listenerManager.addListener(EventType.SIGN_CHANGE, sl);
pm.registerEvent(Event.Type.SIGN_CHANGE, sl, Event.Priority.Low, plugin);
} }
MarkerSignManager.plugin = plugin; MarkerSignManager.plugin = plugin;
return mgr; return mgr;
} }
public static void terminateSignManager(DynmapPlugin plugin) { public static void terminateSignManager(DynmapCore plugin) {
mgr = null; mgr = null;
} }
private static String getSignMarkerID(Location loc) { private static String getSignMarkerID(String wname, int x, int y, int z) {
return "_sign_" + loc.getWorld().getName() + "_" + loc.getBlockX() + "_" + loc.getBlockY() + "_" + loc.getBlockZ(); return "_sign_" + wname + "_" + x + "_" + y + "_" + z;
} }
} }

View File

@ -2,14 +2,14 @@ package org.dynmap.regions;
import org.dynmap.Component; import org.dynmap.Component;
import org.dynmap.ConfigurationNode; import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.Log; import org.dynmap.Log;
public class RegionsComponent extends Component { public class RegionsComponent extends Component {
private static String deprecated_ids[] = { "Residence", "Factions", "Towny", "WorldGuard" }; private static String deprecated_ids[] = { "Residence", "Factions", "Towny", "WorldGuard" };
private static String deprecated_new_plugins[] = { "dynmap-residence", "Dynmap-Factions", "Dynmap-Towny", "Dynmap-WorldGuard" }; private static String deprecated_new_plugins[] = { "dynmap-residence", "Dynmap-Factions", "Dynmap-Towny", "Dynmap-WorldGuard" };
public RegionsComponent(final DynmapPlugin plugin, final ConfigurationNode configuration) { public RegionsComponent(final DynmapCore plugin, final ConfigurationNode configuration) {
super(plugin, configuration); super(plugin, configuration);
String regiontype = configuration.getString("name", "WorldGuard"); String regiontype = configuration.getString("name", "WorldGuard");

View File

@ -8,18 +8,18 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Event; import org.dynmap.Event;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class ClientConfigurationServlet extends HttpServlet { public class ClientConfigurationServlet extends HttpServlet {
private static final long serialVersionUID = 9106801553080522469L; private static final long serialVersionUID = 9106801553080522469L;
private DynmapPlugin plugin; private DynmapCore plugin;
private byte[] cachedConfiguration = null; private byte[] cachedConfiguration = null;
private int cached_config_hashcode = 0; private int cached_config_hashcode = 0;
public ClientConfigurationServlet(DynmapPlugin plugin) { public ClientConfigurationServlet(DynmapCore plugin) {
this.plugin = plugin; this.plugin = plugin;
plugin.events.addListener("worldactivated", new Event.Listener<DynmapWorld>() { plugin.events.addListener("worldactivated", new Event.Listener<DynmapWorld>() {
@Override @Override

View File

@ -13,16 +13,16 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.dynmap.ClientUpdateEvent; import org.dynmap.ClientUpdateEvent;
import org.dynmap.DynmapPlugin; import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld; import org.dynmap.DynmapWorld;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.web.HttpField; import org.dynmap.web.HttpField;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class ClientUpdateServlet extends HttpServlet { public class ClientUpdateServlet extends HttpServlet {
private DynmapPlugin plugin; private DynmapCore plugin;
public ClientUpdateServlet(DynmapPlugin plugin) { public ClientUpdateServlet(DynmapCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -1,7 +1,6 @@
package org.dynmap.servlet; package org.dynmap.servlet;
import org.bukkit.OfflinePlayer; import org.dynmap.DynmapCore;
import org.dynmap.DynmapPlugin;
import org.dynmap.Event; import org.dynmap.Event;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.web.HttpStatus; import org.dynmap.web.HttpStatus;
@ -40,7 +39,7 @@ public class SendMessageServlet extends HttpServlet {
public boolean use_player_login_ip = false; public boolean use_player_login_ip = false;
public boolean require_player_login_ip = false; public boolean require_player_login_ip = false;
public boolean check_user_ban = false; public boolean check_user_ban = false;
public DynmapPlugin plug_in; public DynmapCore plug_in;
@Override @Override
@ -77,8 +76,7 @@ public class SendMessageServlet extends HttpServlet {
if (ids != null) { if (ids != null) {
String id = ids.get(0); String id = ids.get(0);
if (check_user_ban) { if (check_user_ban) {
OfflinePlayer p = plug_in.getServer().getOfflinePlayer(id); if (plug_in.getServer().isPlayerBanned(id)) {
if ((p != null) && p.isBanned()) {
Log.info("Ignore message from '" + message.name + "' - banned player (" + id + ")"); Log.info("Ignore message from '" + message.name + "' - banned player (" + id + ")");
response.sendError(HttpStatus.Forbidden.getCode()); response.sendError(HttpStatus.Forbidden.getCode());
return; return;

View File

@ -1,5 +1,5 @@
name: dynmap name: dynmap
main: org.dynmap.DynmapPlugin main: org.dynmap.bukkit.DynmapPlugin
version: "${project.version}-${BUILD_NUMBER}" version: "${project.version}-${BUILD_NUMBER}"
authors: [FrozenCow, mikeprimm] authors: [FrozenCow, mikeprimm]
softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit] softdepend: [ Permissions, PermissionEx, bPermissions, PermissionsBukkit]