use of org.dynmap.utils.VisibilityLimit in project dynmap by webbukkit.
the class FabricServer method createMapChunkCache.
/**
* Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread
*/
@Override
public MapChunkCache createMapChunkCache(DynmapWorld w, List<DynmapChunk> chunks, boolean blockdata, boolean highesty, boolean biome, boolean rawbiome) {
FabricMapChunkCache c = (FabricMapChunkCache) w.getChunkCache(chunks);
if (c == null) {
return null;
}
if (w.visibility_limits != null) {
for (VisibilityLimit limit : w.visibility_limits) {
c.setVisibleRange(limit);
}
c.setHiddenFillStyle(w.hiddenchunkstyle);
}
if (w.hidden_limits != null) {
for (VisibilityLimit limit : w.hidden_limits) {
c.setHiddenRange(limit);
}
c.setHiddenFillStyle(w.hiddenchunkstyle);
}
if (!c.setChunkDataTypes(blockdata, biome, highesty, rawbiome)) {
Log.severe("CraftBukkit build does not support biome APIs");
}
if (chunks.size() == 0) /* No chunks to get? */
{
c.loadChunks(0);
return c;
}
// Now handle any chunks in server thread that are already loaded (on server thread)
final FabricMapChunkCache cc = c;
Future<Boolean> f = this.callSyncMethod(new Callable<Boolean>() {
public Boolean call() throws Exception {
// Update busy state on world
FabricWorld fw = (FabricWorld) cc.getWorld();
// TODO
// setBusy(fw.getWorld());
cc.getLoadedChunks();
return true;
}
}, 0);
try {
f.get();
} catch (CancellationException cx) {
return null;
} catch (InterruptedException cx) {
return null;
} catch (ExecutionException xx) {
Log.severe("Exception while loading chunks", xx.getCause());
return null;
} catch (Exception ix) {
Log.severe(ix);
return null;
}
if (!w.isLoaded()) {
return null;
}
// Now, do rest of chunk reading from calling thread
c.readChunks(chunks.size());
return c;
}
use of org.dynmap.utils.VisibilityLimit in project dynmap by webbukkit.
the class FabricServer method createMapChunkCache.
/**
* Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread
*/
@Override
public MapChunkCache createMapChunkCache(DynmapWorld w, List<DynmapChunk> chunks, boolean blockdata, boolean highesty, boolean biome, boolean rawbiome) {
FabricMapChunkCache c = (FabricMapChunkCache) w.getChunkCache(chunks);
if (c == null) {
return null;
}
if (w.visibility_limits != null) {
for (VisibilityLimit limit : w.visibility_limits) {
c.setVisibleRange(limit);
}
c.setHiddenFillStyle(w.hiddenchunkstyle);
}
if (w.hidden_limits != null) {
for (VisibilityLimit limit : w.hidden_limits) {
c.setHiddenRange(limit);
}
c.setHiddenFillStyle(w.hiddenchunkstyle);
}
if (!c.setChunkDataTypes(blockdata, biome, highesty, rawbiome)) {
Log.severe("CraftBukkit build does not support biome APIs");
}
if (chunks.size() == 0) /* No chunks to get? */
{
c.loadChunks(0);
return c;
}
// Now handle any chunks in server thread that are already loaded (on server thread)
final FabricMapChunkCache cc = c;
Future<Boolean> f = this.callSyncMethod(new Callable<Boolean>() {
public Boolean call() throws Exception {
// Update busy state on world
FabricWorld fw = (FabricWorld) cc.getWorld();
// TODO
// setBusy(fw.getWorld());
cc.getLoadedChunks();
return true;
}
}, 0);
try {
f.get();
} catch (CancellationException cx) {
return null;
} catch (InterruptedException cx) {
return null;
} catch (ExecutionException xx) {
Log.severe("Exception while loading chunks", xx.getCause());
return null;
} catch (Exception ix) {
Log.severe(ix);
return null;
}
if (!w.isLoaded()) {
return null;
}
// Now, do rest of chunk reading from calling thread
c.readChunks(chunks.size());
return c;
}
use of org.dynmap.utils.VisibilityLimit in project dynmap by webbukkit.
the class DynmapMapCommands method handleWorldGetLimits.
private boolean handleWorldGetLimits(DynmapCommandSender sender, String[] args, DynmapCore core) {
if (!core.checkPlayerPermission(sender, "dmap.worldlist"))
return true;
if (args.length < 2) {
sender.sendMessage("World ID required");
return true;
}
String world_id = args[1];
DynmapWorld w = core.getMapManager().getWorld(world_id);
if (w == null) {
sender.sendMessage(String.format("World %s not found", world_id));
return true;
}
sender.sendMessage("limits:");
int viscnt = 0;
if ((w.visibility_limits != null) && (w.visibility_limits.size() > 0)) {
viscnt = w.visibility_limits.size();
for (int i = 0; i < viscnt; i++) {
VisibilityLimit limit = w.visibility_limits.get(i);
if (limit instanceof RoundVisibilityLimit) {
RoundVisibilityLimit rlimit = (RoundVisibilityLimit) limit;
sender.sendMessage(String.format(" %d: limittype=visible, type=round, center=%d/%d, radius=%d", i, rlimit.x_center, rlimit.z_center, rlimit.radius));
} else if (limit instanceof RectangleVisibilityLimit) {
RectangleVisibilityLimit rlimit = (RectangleVisibilityLimit) limit;
sender.sendMessage(String.format(" %d: limittype=visible, type=rect, corner1=%d/%d, corner2=%d/%d", i, rlimit.x_min, rlimit.z_min, rlimit.x_max, rlimit.z_max));
}
}
}
if ((w.hidden_limits != null) && (w.hidden_limits.size() > 0)) {
for (int i = 0; i < w.hidden_limits.size(); i++) {
VisibilityLimit limit = w.hidden_limits.get(i);
if (limit instanceof RoundVisibilityLimit) {
RoundVisibilityLimit rlimit = (RoundVisibilityLimit) limit;
sender.sendMessage(String.format(" %d: limittype=hidden, type=round, center=%d/%d, radius=%d", i + viscnt, rlimit.x_center, rlimit.z_center, rlimit.radius));
} else if (limit instanceof RectangleVisibilityLimit) {
RectangleVisibilityLimit rlimit = (RectangleVisibilityLimit) limit;
sender.sendMessage(String.format(" %d: limittype=hidden, type=rect, corner1=%d/%d, corner2=%d/%d", i + viscnt, rlimit.x_min, rlimit.z_min, rlimit.x_max, rlimit.z_max));
}
}
}
sender.sendMessage("hiddenstyle: " + w.hiddenchunkstyle.getValue());
return true;
}
use of org.dynmap.utils.VisibilityLimit in project dynmap by webbukkit.
the class DynmapMapCommands method handleWorldAddLimit.
private boolean handleWorldAddLimit(DynmapCommandSender sender, String[] args, DynmapCore core) {
if (!core.checkPlayerPermission(sender, "dmap.worldset"))
return true;
if (args.length < 2) {
sender.sendMessage("World ID required");
return true;
}
/* Test if render active - quit if so */
if (checkIfActive(core, sender)) {
return true;
}
String world_id = args[1];
DynmapWorld w = core.getMapManager().getWorld(world_id);
if (w == null) {
sender.sendMessage(String.format("World %s not found", world_id));
return true;
}
String limittype = "visible";
// Default to rectangle
String type = "rect";
int[] corner1 = null;
int[] corner2 = null;
int[] center = null;
int radius = 0;
HiddenChunkStyle style = null;
// Other args are field:value
for (int argid = 2; argid < args.length; argid++) {
String[] argval = args[argid].split(":");
if (argval.length != 2) {
sender.sendMessage("Argument witout value: " + args[argid]);
return false;
}
String[] toks;
String id = argval[0];
String val = argval[1];
switch(id) {
case "type":
if ((val.equals("round")) || (val.equals("rect"))) {
type = val;
} else {
sender.sendMessage("Bad type value: " + val);
return false;
}
break;
case "limittype":
if ((val.equals("visible")) || (val.equals("hidden"))) {
limittype = val;
} else {
sender.sendMessage("Bad limittype value: " + val);
return false;
}
break;
case "corner1":
case "corner2":
case "center":
if ((type.equals("rect") && id.equals("center")) || (type.equals("round") && (!id.equals("center")))) {
sender.sendMessage("Bad parameter for type " + type + ": " + id);
return false;
}
toks = val.split("/");
if (toks.length == 2) {
int x = 0, z = 0;
x = Integer.valueOf(toks[0]);
z = Integer.valueOf(toks[1]);
switch(id) {
case "corner1":
corner1 = new int[] { x, z };
break;
case "corner2":
corner2 = new int[] { x, z };
break;
case "center":
center = new int[] { x, z };
break;
}
} else {
sender.sendMessage("Bad value for parameter " + id + ": " + val);
return false;
}
break;
case "radius":
if (!type.equals("round")) {
sender.sendMessage("Bad parameter for type " + type + ": " + id);
return false;
}
radius = Integer.valueOf(val);
break;
case "style":
style = HiddenChunkStyle.fromValue(val);
if (style == null) {
sender.sendMessage("Bad parameter for style: " + val);
return false;
}
break;
default:
sender.sendMessage("Bad parameter: " + id);
return false;
}
}
// If enough for rectange area, add it
VisibilityLimit newlimit = null;
if ((type.contentEquals("rect") && (corner1 != null) && (corner2 != null))) {
newlimit = new RectangleVisibilityLimit(corner1[0], corner1[1], corner2[0], corner2[1]);
} else if ((type.contentEquals("round") && (center != null) && (radius > 0.0))) {
newlimit = new RoundVisibilityLimit(center[0], center[1], radius);
}
boolean updated = false;
if (newlimit != null) {
if (limittype.contentEquals("visible")) {
if (w.visibility_limits == null) {
w.visibility_limits = new ArrayList<VisibilityLimit>();
}
w.visibility_limits.add(newlimit);
} else {
if (w.hidden_limits == null) {
w.hidden_limits = new ArrayList<VisibilityLimit>();
}
w.hidden_limits.add(newlimit);
}
updated = true;
}
// If new style, apply it
if (style != null) {
w.hiddenchunkstyle = style;
updated = true;
}
// Apply update
if (updated) {
core.updateWorldConfig(w);
sender.sendMessage("Refreshing configuration for world " + world_id);
core.refreshWorld(world_id);
}
return true;
}
use of org.dynmap.utils.VisibilityLimit in project dynmap by webbukkit.
the class DynmapWorld method loadConfiguration.
/* Load world configuration from configuration node */
public boolean loadConfiguration(DynmapCore core, ConfigurationNode worldconfig) {
is_enabled = worldconfig.getBoolean("enabled", false);
if (!is_enabled) {
return false;
}
title = worldconfig.getString("title", title);
ConfigurationNode ctr = worldconfig.getNode("center");
int mid_y = (worldheight + minY) / 2;
if (ctr != null)
center = new DynmapLocation(wname, ctr.getDouble("x", 0.0), ctr.getDouble("y", mid_y), ctr.getDouble("z", 0));
else
center = null;
List<ConfigurationNode> loclist = worldconfig.getNodes("fullrenderlocations");
seedloc = new ArrayList<DynmapLocation>();
seedloccfg = new ArrayList<DynmapLocation>();
servertime = (int) (getTime() % 24000);
sendposition = worldconfig.getBoolean("sendposition", true);
sendhealth = worldconfig.getBoolean("sendhealth", true);
showborder = worldconfig.getBoolean("showborder", true);
is_protected = worldconfig.getBoolean("protected", false);
setExtraZoomOutLevels(worldconfig.getInteger("extrazoomout", 0));
setTileUpdateDelay(worldconfig.getInteger("tileupdatedelay", -1));
storage = core.getDefaultMapStorage();
if (loclist != null) {
for (ConfigurationNode loc : loclist) {
DynmapLocation lx = new DynmapLocation(wname, loc.getDouble("x", 0), loc.getDouble("y", mid_y), loc.getDouble("z", 0));
seedloc.add(lx);
/* Add to both combined and configured seed list */
seedloccfg.add(lx);
}
}
/* Build maps */
maps.clear();
Log.verboseinfo("Loading maps of world '" + wname + "'...");
for (MapType map : worldconfig.<MapType>createInstances("maps", new Class<?>[] { DynmapCore.class }, new Object[] { core })) {
if (map.getName() != null) {
maps.add(map);
}
}
/* Rebuild map state list - match on indexes */
mapstate.clear();
for (MapType map : maps) {
MapTypeState ms = new MapTypeState(this, map);
ms.setInvalidatePeriod(map.getTileUpdateDelay(this));
mapstate.add(ms);
}
Log.info("Loaded " + maps.size() + " maps of world '" + wname + "'.");
/* Load visibility limits, if any are defined */
List<ConfigurationNode> vislimits = worldconfig.getNodes("visibilitylimits");
if (vislimits != null) {
visibility_limits = new ArrayList<VisibilityLimit>();
for (ConfigurationNode vis : vislimits) {
VisibilityLimit lim;
if (vis.containsKey("r")) {
/* It is round visibility limit */
int x_center = vis.getInteger("x", 0);
int z_center = vis.getInteger("z", 0);
int radius = vis.getInteger("r", 0);
lim = new RoundVisibilityLimit(x_center, z_center, radius);
} else {
/* Rectangle visibility limit */
int x0 = vis.getInteger("x0", 0);
int x1 = vis.getInteger("x1", 0);
int z0 = vis.getInteger("z0", 0);
int z1 = vis.getInteger("z1", 0);
lim = new RectangleVisibilityLimit(x0, z0, x1, z1);
}
visibility_limits.add(lim);
/* Also, add a seed location for the middle of each visible area */
seedloc.add(new DynmapLocation(wname, lim.xCenter(), 64, lim.zCenter()));
}
}
/* Load hidden limits, if any are defined */
List<ConfigurationNode> hidelimits = worldconfig.getNodes("hiddenlimits");
if (hidelimits != null) {
hidden_limits = new ArrayList<VisibilityLimit>();
for (ConfigurationNode vis : hidelimits) {
VisibilityLimit lim;
if (vis.containsKey("r")) {
/* It is round visibility limit */
int x_center = vis.getInteger("x", 0);
int z_center = vis.getInteger("z", 0);
int radius = vis.getInteger("r", 0);
lim = new RoundVisibilityLimit(x_center, z_center, radius);
} else {
/* Rectangle visibility limit */
int x0 = vis.getInteger("x0", 0);
int x1 = vis.getInteger("x1", 0);
int z0 = vis.getInteger("z0", 0);
int z1 = vis.getInteger("z1", 0);
lim = new RectangleVisibilityLimit(x0, z0, x1, z1);
}
hidden_limits.add(lim);
}
}
String hiddenchunkstyle = worldconfig.getString("hidestyle", "stone");
this.hiddenchunkstyle = MapChunkCache.HiddenChunkStyle.fromValue(hiddenchunkstyle);
if (this.hiddenchunkstyle == null)
this.hiddenchunkstyle = MapChunkCache.HiddenChunkStyle.FILL_STONE_PLAIN;
return true;
}
Aggregations