mirror of
https://github.com/encounter/dynmap.git
synced 2026-03-30 11:08:39 -07:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f0885abea2 | |||
| 2b17cb215b | |||
| 68f0c17f70 | |||
| a20e55beab | |||
| 413542fe61 | |||
| a250732d31 |
Binary file not shown.
@@ -127,7 +127,9 @@
|
||||
<dependency>
|
||||
<groupId>com.nijikokun.bukkit</groupId>
|
||||
<artifactId>Permissions</artifactId>
|
||||
<version>[2.5.4,)</version>
|
||||
<version>3.1.6</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/Permissions.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
@@ -184,5 +186,5 @@
|
||||
<version>1.2.5-R5.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
</project>
|
||||
|
||||
@@ -17,13 +17,36 @@ public class BukkitWorld extends DynmapWorld {
|
||||
private World world;
|
||||
private World.Environment env;
|
||||
private boolean skylight;
|
||||
private DynmapLocation spawnloc = new DynmapLocation();
|
||||
|
||||
public BukkitWorld(World w) {
|
||||
super(w.getName(), w.getMaxHeight(), w.getSeaLevel());
|
||||
this(w.getName(), w.getMaxHeight(), w.getSeaLevel(), w.getEnvironment());
|
||||
setWorldLoaded(w);
|
||||
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
|
||||
}
|
||||
public BukkitWorld(String name, int height, int sealevel, World.Environment env) {
|
||||
super(name, height, sealevel);
|
||||
world = null;
|
||||
this.env = env;
|
||||
skylight = (env == World.Environment.NORMAL);
|
||||
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
|
||||
}
|
||||
/**
|
||||
* Set world online
|
||||
* @param w - loaded world
|
||||
*/
|
||||
public void setWorldLoaded(World w) {
|
||||
world = w;
|
||||
env = world.getEnvironment();
|
||||
skylight = (env == World.Environment.NORMAL);
|
||||
new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP);
|
||||
}
|
||||
/**
|
||||
* Set world unloaded
|
||||
*/
|
||||
@Override
|
||||
public void setWorldUnloaded() {
|
||||
getSpawnLocation(); /* Remember spawn location before unload */
|
||||
world = null;
|
||||
}
|
||||
/* Test if world is nether */
|
||||
@Override
|
||||
@@ -33,26 +56,44 @@ public class BukkitWorld extends DynmapWorld {
|
||||
/* 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 = normalizeWorldName(sloc.getWorld().getName());
|
||||
return dloc;
|
||||
if(world != null) {
|
||||
Location sloc = world.getSpawnLocation();
|
||||
spawnloc.x = sloc.getBlockX();
|
||||
spawnloc.y = sloc.getBlockY();
|
||||
spawnloc.z = sloc.getBlockZ();
|
||||
spawnloc.world = normalizeWorldName(sloc.getWorld().getName());
|
||||
}
|
||||
return spawnloc;
|
||||
}
|
||||
/* Get world time */
|
||||
@Override
|
||||
public long getTime() {
|
||||
return world.getTime();
|
||||
if(world != null) {
|
||||
return world.getTime();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* World is storming */
|
||||
@Override
|
||||
public boolean hasStorm() {
|
||||
return world.hasStorm();
|
||||
if(world != null) {
|
||||
return world.hasStorm();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* World is thundering */
|
||||
@Override
|
||||
public boolean isThundering() {
|
||||
return world.isThundering();
|
||||
if(world != null) {
|
||||
return world.isThundering();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/* World is loaded */
|
||||
@Override
|
||||
@@ -62,22 +103,37 @@ public class BukkitWorld extends DynmapWorld {
|
||||
/* Get light level of block */
|
||||
@Override
|
||||
public int getLightLevel(int x, int y, int z) {
|
||||
return world.getBlockAt(x, y, z).getLightLevel();
|
||||
if(world != null) {
|
||||
return world.getBlockAt(x, y, z).getLightLevel();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* Get highest Y coord of given location */
|
||||
@Override
|
||||
public int getHighestBlockYAt(int x, int z) {
|
||||
return world.getHighestBlockYAt(x, z);
|
||||
if(world != null) {
|
||||
return world.getHighestBlockYAt(x, z);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* Test if sky light level is requestable */
|
||||
@Override
|
||||
public boolean canGetSkyLightLevel() {
|
||||
return skylight;
|
||||
return skylight && (world != null);
|
||||
}
|
||||
/* Return sky light level */
|
||||
@Override
|
||||
public int getSkyLightLevel(int x, int y, int z) {
|
||||
return world.getBlockAt(x, y, z).getLightFromSky();
|
||||
if(world != null) {
|
||||
return world.getBlockAt(x, y, z).getLightFromSky();
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get world environment ID (lower case - normal, the_end, nether)
|
||||
@@ -91,9 +147,14 @@ public class BukkitWorld extends DynmapWorld {
|
||||
*/
|
||||
@Override
|
||||
public MapChunkCache getChunkCache(List<DynmapChunk> chunks) {
|
||||
NewMapChunkCache c = new NewMapChunkCache();
|
||||
c.setChunks(this, chunks);
|
||||
return c;
|
||||
if(isLoaded()) {
|
||||
NewMapChunkCache c = new NewMapChunkCache();
|
||||
c.setChunks(this, chunks);
|
||||
return c;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dynmap.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -15,6 +16,8 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import net.minecraft.server.BiomeBase;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
@@ -125,6 +128,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
bw = new BukkitWorld(w);
|
||||
world_by_name.put(w.getName(), bw);
|
||||
}
|
||||
else if(bw.isLoaded() == false) {
|
||||
bw.setWorldLoaded(w);
|
||||
}
|
||||
last_world = w;
|
||||
last_bworld = bw;
|
||||
|
||||
@@ -254,7 +260,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
pm.registerEvents(new Listener() {
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onSpawnChange(SpawnChangeEvent evt) {
|
||||
DynmapWorld w = getWorld(evt.getWorld());
|
||||
BukkitWorld w = getWorld(evt.getWorld());
|
||||
core.listenerManager.processWorldEvent(EventType.WORLD_SPAWN_CHANGE, w);
|
||||
}
|
||||
}, DynmapPlugin.this);
|
||||
@@ -406,6 +412,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
public MapChunkCache createMapChunkCache(DynmapWorld w, List<DynmapChunk> chunks,
|
||||
boolean blockdata, boolean highesty, boolean biome, boolean rawbiome) {
|
||||
MapChunkCache c = w.getChunkCache(chunks);
|
||||
if(c == null) { /* Can fail if not currently loaded */
|
||||
return null;
|
||||
}
|
||||
if(w.visibility_limits != null) {
|
||||
for(MapChunkCache.VisibilityLimit limit: w.visibility_limits) {
|
||||
c.setVisibleRange(limit);
|
||||
@@ -442,8 +451,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
public Boolean call() throws Exception {
|
||||
boolean exhausted;
|
||||
synchronized(loadlock) {
|
||||
if(chunks_in_cur_tick > 0)
|
||||
if(chunks_in_cur_tick > 0) {
|
||||
chunks_in_cur_tick -= cc.loadChunks(chunks_in_cur_tick);
|
||||
}
|
||||
exhausted = (chunks_in_cur_tick == 0);
|
||||
}
|
||||
return exhausted;
|
||||
@@ -462,6 +472,9 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
try { Thread.sleep(25); } catch (InterruptedException ix) {}
|
||||
}
|
||||
}
|
||||
/* If cancelled due to world unload return nothing */
|
||||
if(w.isLoaded() == false)
|
||||
return null;
|
||||
return c;
|
||||
}
|
||||
@Override
|
||||
@@ -622,6 +635,60 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadExtraBiomes() {
|
||||
Field tmpfld;
|
||||
Field humfld;
|
||||
int cnt = 0;
|
||||
try {
|
||||
tmpfld = BiomeBase.class.getField("temperature");
|
||||
} catch (NoSuchFieldException nsfx) {
|
||||
try {
|
||||
tmpfld = BiomeBase.class.getField("F");
|
||||
} catch (NoSuchFieldException nsfx2) {
|
||||
Log.warning("BiomeBase.temperature field not found");
|
||||
tmpfld = null;
|
||||
}
|
||||
}
|
||||
if((tmpfld != null) && (tmpfld.getType().getClass().isAssignableFrom(float.class) == false)) {
|
||||
tmpfld = null;
|
||||
}
|
||||
try {
|
||||
humfld = BiomeBase.class.getField("humidity");
|
||||
} catch (NoSuchFieldException nsfx) {
|
||||
try {
|
||||
humfld = BiomeBase.class.getField("G");
|
||||
} catch (NoSuchFieldException nsfx2) {
|
||||
Log.warning("BiomeBase.humidity field not found");
|
||||
humfld = null;
|
||||
}
|
||||
}
|
||||
if((humfld != null) && (humfld.getType().getClass().isAssignableFrom(float.class) == false)) {
|
||||
humfld = null;
|
||||
}
|
||||
|
||||
for(int i = BiomeMap.LAST_WELL_KNOWN+1; i < BiomeBase.biomes.length; i++) {
|
||||
BiomeBase bb = BiomeBase.biomes[i];
|
||||
if(bb != null) {
|
||||
String id = "BIOME_" + i;
|
||||
float tmp = 0.5F, hum = 0.5F;
|
||||
try {
|
||||
id = bb.y;
|
||||
} catch (Exception x) {}
|
||||
try {
|
||||
if(tmpfld != null)
|
||||
tmp = tmpfld.getFloat(bb);
|
||||
if(humfld != null)
|
||||
hum = humfld.getFloat(bb);
|
||||
} catch (Exception x) {
|
||||
}
|
||||
BiomeMap m = new BiomeMap(i, id, tmp, hum);
|
||||
Log.verboseinfo("Add custom biome [" + m.toString() + "] (" + i + ")");
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
Log.info("Added " + cnt + " custom biome mappings");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
pm = this.getServer().getPluginManager();
|
||||
@@ -629,6 +696,8 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
version = pdfFile.getVersion();
|
||||
|
||||
/* Load extra biomes, if any */
|
||||
loadExtraBiomes();
|
||||
|
||||
/* Set up player login/quit event handler */
|
||||
registerPlayerLoginListener();
|
||||
@@ -1283,17 +1352,18 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI {
|
||||
Listener worldTrigger = new Listener() {
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onWorldLoad(WorldLoadEvent event) {
|
||||
core.updateConfigHashcode();
|
||||
BukkitWorld w = getWorld(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);
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
core.updateConfigHashcode();
|
||||
DynmapWorld w = getWorld(event.getWorld());
|
||||
core.listenerManager.processWorldEvent(EventType.WORLD_UNLOAD, w);
|
||||
removeWorld(event.getWorld());
|
||||
BukkitWorld w = getWorld(event.getWorld());
|
||||
if(w != null) {
|
||||
core.listenerManager.processWorldEvent(EventType.WORLD_UNLOAD, w);
|
||||
w.setWorldUnloaded();
|
||||
core.processWorldUnload(w);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void onStructureGrow(StructureGrowEvent event) {
|
||||
|
||||
@@ -8,12 +8,14 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import net.minecraft.server.BiomeBase;
|
||||
import net.minecraft.server.ChunkProviderServer;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.craftbukkit.CraftChunk;
|
||||
import org.bukkit.craftbukkit.CraftChunkSnapshot;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.util.LongHashset;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
@@ -35,6 +37,8 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
private static boolean use_spout = false;
|
||||
private static Field unloadqueue = null;
|
||||
private static Method queuecontainskey = null;
|
||||
private static Field biomesnapshot = null;
|
||||
|
||||
|
||||
private World w;
|
||||
private DynmapWorld dw;
|
||||
@@ -145,15 +149,37 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
sameneighborbiomecnt[i] = new byte[z_size];
|
||||
biomemap[i] = new BiomeMap[z_size];
|
||||
}
|
||||
BiomeBase[] biomebase = null;
|
||||
ChunkSnapshot biome_css = null;
|
||||
for(int i = 0; i < x_size; i++) {
|
||||
initialize(i + x_base, 64, z_base);
|
||||
for(int j = 0; j < z_size; j++) {
|
||||
Biome bb = snap.getBiome(bx, bz);
|
||||
BiomeMap bm;
|
||||
if(bb == null)
|
||||
bm = BiomeMap.NULL;
|
||||
else
|
||||
bm = biome_to_bmap[bb.ordinal()];
|
||||
|
||||
if((biomesnapshot != null) && (snap != biome_css)) {
|
||||
biomebase = null;
|
||||
biome_css = snap;
|
||||
try {
|
||||
if (biome_css instanceof SpoutChunkSnapshot) {
|
||||
biome_css = ((SpoutChunkSnapshot)biome_css).chunk;
|
||||
}
|
||||
if(biome_css instanceof CraftChunkSnapshot) {
|
||||
biomebase = (BiomeBase[]) biomesnapshot.get(biome_css);
|
||||
}
|
||||
} catch (IllegalArgumentException iax) {
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
}
|
||||
if(biomebase != null) {
|
||||
bm = BiomeMap.byBiomeID(biomebase[bz << 4 | bx].id);
|
||||
}
|
||||
else {
|
||||
Biome bb = snap.getBiome(bx, bz);
|
||||
if(bb == null)
|
||||
bm = BiomeMap.NULL;
|
||||
else
|
||||
bm = biome_to_bmap[bb.ordinal()];
|
||||
}
|
||||
biomemap[i][j] = bm;
|
||||
int cnt = 0;
|
||||
if(i > 0) {
|
||||
@@ -681,12 +707,22 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
} catch (NoSuchMethodException nsmx) {
|
||||
unloadqueue = null;
|
||||
}
|
||||
try {
|
||||
biomesnapshot = CraftChunkSnapshot.class.getDeclaredField("biome");
|
||||
biomesnapshot.setAccessible(true);
|
||||
} catch (NoSuchFieldException nsfx) {
|
||||
biomesnapshot = null;
|
||||
Log.warning("Unable to find biome field in ChunkSnapshot");
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
}
|
||||
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
|
||||
this.dw = dw;
|
||||
this.w = dw.getWorld();
|
||||
if(this.w == null) {
|
||||
this.chunks = new ArrayList<DynmapChunk>();
|
||||
}
|
||||
nsect = dw.worldheight >> 4;
|
||||
this.chunks = chunks;
|
||||
/* Compute range */
|
||||
@@ -729,6 +765,8 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
}
|
||||
|
||||
public int loadChunks(int max_to_load) {
|
||||
if(dw.isLoaded() == false)
|
||||
return 0;
|
||||
long t0 = System.nanoTime();
|
||||
CraftWorld cw = (CraftWorld)w;
|
||||
Object queue = null;
|
||||
@@ -893,6 +931,11 @@ public class NewMapChunkCache implements MapChunkCache {
|
||||
* Test if done loading
|
||||
*/
|
||||
public boolean isDoneLoading() {
|
||||
if(dw.isLoaded() == false) {
|
||||
isempty = true;
|
||||
unloadChunks();
|
||||
return true;
|
||||
}
|
||||
if(iterator != null)
|
||||
return !iterator.hasNext();
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user