Fix 1.13 world border support, handle world border changes

This commit is contained in:
Mike Primm 2018-12-08 00:15:06 -06:00
parent 3650dc7d2a
commit 95decf005c
7 changed files with 86 additions and 1 deletions

View File

@ -104,6 +104,7 @@ public class DynmapMapCommands {
sb.append(", extrazoomout=").append(w.getExtraZoomOutLevels()).append(", sendhealth=").append(w.sendhealth); sb.append(", extrazoomout=").append(w.getExtraZoomOutLevels()).append(", sendhealth=").append(w.sendhealth);
sb.append(", sendposition=").append(w.sendposition); sb.append(", sendposition=").append(w.sendposition);
sb.append(", protected=").append(w.is_protected); sb.append(", protected=").append(w.is_protected);
sb.append(", showborder=").append(w.showborder);
if(w.tileupdatedelay > 0) { if(w.tileupdatedelay > 0) {
sb.append(", tileupdatedelay=").append(w.tileupdatedelay); sb.append(", tileupdatedelay=").append(w.tileupdatedelay);
} }
@ -172,6 +173,15 @@ public class DynmapMapCommands {
core.updateWorldConfig(w); core.updateWorldConfig(w);
did_update = true; did_update = true;
} }
else if(tok[0].equalsIgnoreCase("showborder")) {
if(w == null) {
sender.sendMessage("Cannot set sendworldborder on disabled or undefined world");
return true;
}
w.showborder = tok[1].equals("true");
core.updateWorldConfig(w);
did_update = true;
}
else if(tok[0].equalsIgnoreCase("protected")) { else if(tok[0].equalsIgnoreCase("protected")) {
if(w == null) { if(w == null) {
sender.sendMessage("Cannot set protected on disabled or undefined world"); sender.sendMessage("Cannot set protected on disabled or undefined world");

View File

@ -37,6 +37,7 @@ public abstract class DynmapWorld {
public int servertime; public int servertime;
public boolean sendposition; public boolean sendposition;
public boolean sendhealth; public boolean sendhealth;
public boolean showborder;
private int extrazoomoutlevels; /* Number of additional zoom out levels to generate */ private int extrazoomoutlevels; /* Number of additional zoom out levels to generate */
private boolean cancelled; private boolean cancelled;
private final String wname; private final String wname;
@ -326,6 +327,7 @@ public abstract class DynmapWorld {
servertime = (int)(getTime() % 24000); servertime = (int)(getTime() % 24000);
sendposition = worldconfig.getBoolean("sendposition", true); sendposition = worldconfig.getBoolean("sendposition", true);
sendhealth = worldconfig.getBoolean("sendhealth", true); sendhealth = worldconfig.getBoolean("sendhealth", true);
showborder = worldconfig.getBoolean("showborder", true);
is_protected = worldconfig.getBoolean("protected", false); is_protected = worldconfig.getBoolean("protected", false);
setExtraZoomOutLevels(worldconfig.getInteger("extrazoomout", 0)); setExtraZoomOutLevels(worldconfig.getInteger("extrazoomout", 0));
setTileUpdateDelay(worldconfig.getInteger("tileupdatedelay", -1)); setTileUpdateDelay(worldconfig.getInteger("tileupdatedelay", -1));
@ -419,6 +421,7 @@ public abstract class DynmapWorld {
node.put("title", getTitle()); node.put("title", getTitle());
node.put("enabled", is_enabled); node.put("enabled", is_enabled);
node.put("protected", is_protected); node.put("protected", is_protected);
node.put("showborder", showborder);
if(tileupdatedelay > 0) { if(tileupdatedelay > 0) {
node.put("tileupdatedelay", tileupdatedelay); node.put("tileupdatedelay", tileupdatedelay);
} }

View File

@ -27,11 +27,13 @@ import java.util.concurrent.atomic.AtomicLong;
import org.dynmap.common.DynmapCommandSender; import org.dynmap.common.DynmapCommandSender;
import org.dynmap.common.DynmapPlayer; import org.dynmap.common.DynmapPlayer;
import org.dynmap.common.DynmapListenerManager.EventType;
import org.dynmap.debug.Debug; import org.dynmap.debug.Debug;
import org.dynmap.exporter.OBJExport; import org.dynmap.exporter.OBJExport;
import org.dynmap.hdmap.HDMapManager; import org.dynmap.hdmap.HDMapManager;
import org.dynmap.renderer.DynmapBlockState; import org.dynmap.renderer.DynmapBlockState;
import org.dynmap.utils.MapChunkCache; import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.Polygon;
import org.dynmap.utils.TileFlags; import org.dynmap.utils.TileFlags;
public class MapManager { public class MapManager {
@ -775,6 +777,7 @@ public class MapManager {
} }
private class CheckWorldTimes implements Runnable { private class CheckWorldTimes implements Runnable {
HashMap<String, Polygon> last_worldborder = new HashMap<String, Polygon>();
public void run() { public void run() {
Future<Integer> f = core.getServer().callSyncMethod(new Callable<Integer>() { Future<Integer> f = core.getServer().callSyncMethod(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
@ -789,6 +792,15 @@ public class MapManager {
if(wasday != isday) { if(wasday != isday) {
pushUpdate(w, new Client.DayNight(isday)); pushUpdate(w, new Client.DayNight(isday));
} }
// Check world border
Polygon wb = w.getWorldBorder();
Polygon oldwb = last_worldborder.get(w.getName());
if (((wb == null) && (oldwb == null)) ||
wb.equals(oldwb)) { // No change
}
else {
core.listenerManager.processWorldEvent(EventType.WORLD_SPAWN_CHANGE, w);
}
} }
/* Tick invalidated tiles processing */ /* Tick invalidated tiles processing */
for(MapTypeState mts : w.mapstate) { for(MapTypeState mts : w.mapstate) {

View File

@ -254,7 +254,7 @@ public class MarkersComponent extends ClientComponent {
String borderid = "_worldborder_" + w.getName(); String borderid = "_worldborder_" + w.getName();
AreaMarker am = ms.findAreaMarker(borderid); AreaMarker am = ms.findAreaMarker(borderid);
Polygon p = null; Polygon p = null;
if (showBorder) { if (showBorder && w.showborder) {
p = w.getWorldBorder(); p = w.getWorldBorder();
} }
if ((p != null) && (p.size() > 1)) { if ((p != null) && (p.size() > 1)) {

View File

@ -15,8 +15,10 @@ import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.bukkit.helper.BukkitVersionHelper;
@ -169,4 +171,22 @@ public class BukkitVersionHelperSpigot113_1 extends BukkitVersionHelperCB {
return ((BiomeBase)bb).n(); return ((BiomeBase)bb).n();
} }
@Override
public Polygon getWorldBorder(World world) {
Polygon p = null;
WorldBorder wb = world.getWorldBorder();
if (wb != null) {
Location c = wb.getCenter();
double size = wb.getSize();
if ((size > 1) && (size < 1E7)) {
p = new Polygon();
p.addVertex(c.getX()-size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()+size);
p.addVertex(c.getX()-size, c.getZ()+size);
}
}
return p;
}
} }

View File

@ -15,8 +15,10 @@ import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.bukkit.helper.BukkitVersionHelper;
@ -169,4 +171,22 @@ public class BukkitVersionHelperSpigot113_2 extends BukkitVersionHelperCB {
return ((BiomeBase)bb).n(); return ((BiomeBase)bb).n();
} }
@Override
public Polygon getWorldBorder(World world) {
Polygon p = null;
WorldBorder wb = world.getWorldBorder();
if (wb != null) {
Location c = wb.getCenter();
double size = wb.getSize();
if ((size > 1) && (size < 1E7)) {
p = new Polygon();
p.addVertex(c.getX()-size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()+size);
p.addVertex(c.getX()-size, c.getZ()+size);
}
}
return p;
}
} }

View File

@ -15,8 +15,10 @@ import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.dynmap.DynmapChunk; import org.dynmap.DynmapChunk;
import org.dynmap.Log; import org.dynmap.Log;
import org.dynmap.bukkit.helper.BukkitVersionHelper; import org.dynmap.bukkit.helper.BukkitVersionHelper;
@ -163,4 +165,22 @@ public class BukkitVersionHelperSpigot113 extends BukkitVersionHelperCB {
return ((BiomeBase)bb).n(); return ((BiomeBase)bb).n();
} }
@Override
public Polygon getWorldBorder(World world) {
Polygon p = null;
WorldBorder wb = world.getWorldBorder();
if (wb != null) {
Location c = wb.getCenter();
double size = wb.getSize();
if ((size > 1) && (size < 1E7)) {
p = new Polygon();
p.addVertex(c.getX()-size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()-size);
p.addVertex(c.getX()+size, c.getZ()+size);
p.addVertex(c.getX()-size, c.getZ()+size);
}
}
return p;
}
} }