2018-08-08 08:39:51 +02:00
|
|
|
package org.dynmap.bukkit.helper;
|
2012-12-10 05:28:21 +01:00
|
|
|
|
2018-08-06 04:27:18 +02:00
|
|
|
import java.util.Arrays;
|
2018-08-08 08:39:51 +02:00
|
|
|
import java.util.List;
|
2012-12-10 05:28:21 +01:00
|
|
|
import java.util.Map;
|
2014-07-10 05:20:33 +02:00
|
|
|
|
2012-12-10 05:28:21 +01:00
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.ChunkSnapshot;
|
|
|
|
import org.bukkit.World;
|
2014-07-10 05:20:33 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2018-08-08 08:39:51 +02:00
|
|
|
import org.dynmap.DynmapChunk;
|
2021-12-05 08:57:59 +01:00
|
|
|
import org.dynmap.common.chunk.GenericChunkCache;
|
2018-08-05 21:38:13 +02:00
|
|
|
import org.dynmap.renderer.DynmapBlockState;
|
2018-08-08 08:39:51 +02:00
|
|
|
import org.dynmap.utils.MapChunkCache;
|
2015-02-15 19:40:30 +01:00
|
|
|
import org.dynmap.utils.Polygon;
|
2012-12-10 05:28:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for isolation of bukkit version specific issues
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract class BukkitVersionHelper {
|
2018-08-08 08:39:51 +02:00
|
|
|
public static BukkitVersionHelper helper = null;
|
2013-01-22 06:54:13 +01:00
|
|
|
|
2021-12-05 08:57:59 +01:00
|
|
|
public static GenericChunkCache gencache;
|
|
|
|
|
2018-08-08 08:39:51 +02:00
|
|
|
public static DynmapBlockState[] stateByID;
|
2018-08-05 21:38:13 +02:00
|
|
|
|
2018-08-27 15:51:13 +02:00
|
|
|
protected boolean isBlockIdNeeded() {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-28 01:55:19 +02:00
|
|
|
protected boolean isBiomeBaseListNeeded() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-27 14:56:16 +02:00
|
|
|
|
2013-01-22 06:54:13 +01:00
|
|
|
protected BukkitVersionHelper() {
|
2012-12-10 05:28:21 +01:00
|
|
|
|
|
|
|
}
|
2022-03-29 22:33:46 +02:00
|
|
|
/**
|
|
|
|
* Get if it's unsafe to load chunks async
|
|
|
|
*/
|
|
|
|
public abstract boolean isUnsafeAsync();
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
2013-01-22 06:54:13 +01:00
|
|
|
* Get list of defined biomebase objects
|
2012-12-10 05:28:21 +01:00
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract Object[] getBiomeBaseList();
|
|
|
|
/**
|
|
|
|
* Get temperature from biomebase
|
|
|
|
*/
|
|
|
|
public abstract float getBiomeBaseTemperature(Object bb);
|
|
|
|
/**
|
|
|
|
* Get humidity from biomebase
|
|
|
|
*/
|
|
|
|
public abstract float getBiomeBaseHumidity(Object bb);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
2013-01-22 06:54:13 +01:00
|
|
|
* Get ID string from biomebase
|
2012-12-10 05:28:21 +01:00
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract String getBiomeBaseIDString(Object bb);
|
2021-12-03 05:18:03 +01:00
|
|
|
/**
|
|
|
|
* Get resource location from biomebase (1.18+)
|
|
|
|
*/
|
|
|
|
public String getBiomeBaseResourceLocsation(Object bb) { return null; }
|
2013-01-22 06:54:13 +01:00
|
|
|
/**
|
|
|
|
* Get ID from biomebase
|
|
|
|
*/
|
|
|
|
public abstract int getBiomeBaseID(Object bb);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
2013-01-22 06:54:13 +01:00
|
|
|
* Get unload queue for given NMS world
|
2012-12-10 05:28:21 +01:00
|
|
|
*/
|
2014-09-07 02:19:20 +02:00
|
|
|
public abstract Object getUnloadQueue(World world);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
2013-01-22 06:54:13 +01:00
|
|
|
* For testing unload queue for presence of givne chunk
|
2012-12-10 05:28:21 +01:00
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract boolean isInUnloadQueue(Object unloadqueue, int x, int z);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
2013-01-22 06:54:13 +01:00
|
|
|
* Read raw biome ID from snapshot
|
2012-12-10 05:28:21 +01:00
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract Object[] getBiomeBaseFromSnapshot(ChunkSnapshot css);
|
|
|
|
/**
|
|
|
|
* Test if normal chunk snapshot
|
|
|
|
*/
|
2014-09-07 02:19:20 +02:00
|
|
|
// public abstract boolean isCraftChunkSnapshot(ChunkSnapshot css);
|
2014-01-18 00:40:39 +01:00
|
|
|
/**
|
|
|
|
* Get inhabited ticks count from chunk
|
|
|
|
*/
|
|
|
|
public abstract long getInhabitedTicks(Chunk c);
|
2013-01-22 06:54:13 +01:00
|
|
|
/**
|
|
|
|
* Get tile entities map from chunk
|
|
|
|
*/
|
2016-05-23 07:35:58 +02:00
|
|
|
public abstract Map<?, ?> getTileEntitiesForChunk(Chunk c);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
|
|
|
* Get X coordinate of tile entity
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract int getTileEntityX(Object te);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
|
|
|
* Get Y coordinate of tile entity
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract int getTileEntityY(Object te);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
|
|
|
* Get Z coordinate of tile entity
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract int getTileEntityZ(Object te);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
|
|
|
* Read tile entity NBT
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract Object readTileEntityNBT(Object te);
|
2012-12-10 05:28:21 +01:00
|
|
|
/**
|
|
|
|
* Get field value from NBT compound
|
|
|
|
*/
|
2013-01-22 06:54:13 +01:00
|
|
|
public abstract Object getFieldValue(Object nbt, String field);
|
2013-03-18 05:43:11 +01:00
|
|
|
/**
|
|
|
|
* Unload chunk no save needed
|
|
|
|
*/
|
2013-03-19 02:30:13 +01:00
|
|
|
public abstract void unloadChunkNoSave(World w, Chunk c, int cx, int cz);
|
2013-04-18 08:20:59 +02:00
|
|
|
/**
|
2018-08-06 04:27:18 +02:00
|
|
|
* Get block name list
|
2013-04-18 08:20:59 +02:00
|
|
|
*/
|
2018-08-06 04:27:18 +02:00
|
|
|
public abstract String[] getBlockNames();
|
2013-04-18 08:20:59 +02:00
|
|
|
/**
|
|
|
|
* Get biome name list
|
|
|
|
*/
|
|
|
|
public abstract String[] getBiomeNames();
|
2014-07-10 05:20:33 +02:00
|
|
|
/**
|
|
|
|
* Get list of online players
|
|
|
|
*/
|
|
|
|
public abstract Player[] getOnlinePlayers();
|
|
|
|
/**
|
|
|
|
* Get player health
|
|
|
|
*/
|
2014-10-13 16:41:14 +02:00
|
|
|
public abstract double getHealth(Player p);
|
2015-02-15 19:40:30 +01:00
|
|
|
/**
|
|
|
|
* Get world border
|
|
|
|
*/
|
|
|
|
public Polygon getWorldBorder(World world) { return null; }
|
2021-08-22 01:03:07 +02:00
|
|
|
/**
|
|
|
|
* Get world minY
|
|
|
|
*/
|
|
|
|
public int getWorldMinY(World world) { return 0; }
|
2016-04-08 07:25:30 +02:00
|
|
|
/**
|
|
|
|
* Test if broken unloadChunk
|
|
|
|
*/
|
|
|
|
public boolean isUnloadChunkBroken() { return false; }
|
2018-02-14 02:11:16 +01:00
|
|
|
/**
|
|
|
|
* Get skin URL for player
|
|
|
|
* @param player
|
|
|
|
*/
|
|
|
|
public String getSkinURL(Player player) { return null; }
|
2018-09-02 06:26:36 +02:00
|
|
|
/**
|
|
|
|
* Get material map by block ID
|
|
|
|
*/
|
|
|
|
public abstract BukkitMaterial[] getMaterialList();
|
2018-08-05 21:38:13 +02:00
|
|
|
/**
|
|
|
|
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
|
|
|
|
*/
|
|
|
|
public void initializeBlockStates() {
|
2018-08-06 04:27:18 +02:00
|
|
|
String[] blkname = getBlockNames();
|
2018-09-02 06:26:36 +02:00
|
|
|
BukkitMaterial[] blkmat = getMaterialList();
|
2018-08-05 21:38:13 +02:00
|
|
|
// Keep it simple for now - just assume 16 meta states for each
|
2018-08-08 08:39:51 +02:00
|
|
|
stateByID = new DynmapBlockState[16*blkname.length];
|
2018-08-06 04:27:18 +02:00
|
|
|
Arrays.fill(stateByID, DynmapBlockState.AIR);
|
2018-08-05 21:38:13 +02:00
|
|
|
for (int i = 0; i < blkname.length; i++) {
|
2018-08-06 04:27:18 +02:00
|
|
|
if (blkname[i] == null) continue;
|
|
|
|
String bn = blkname[i];
|
|
|
|
if (bn.indexOf(':') < 0) {
|
|
|
|
bn = "minecraft:" + bn;
|
|
|
|
}
|
2018-08-05 21:38:13 +02:00
|
|
|
// Only do defined names, and not "air"
|
2018-08-06 04:27:18 +02:00
|
|
|
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
|
2018-09-02 06:26:36 +02:00
|
|
|
BukkitMaterial mat = blkmat[i];
|
2018-12-04 07:44:22 +01:00
|
|
|
DynmapBlockState basebs = null;
|
|
|
|
for (int m = 0; m < 16; m++) {
|
|
|
|
String sn = helper.getStateStringByCombinedId(i, m);
|
|
|
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, sn, mat.name, i);
|
|
|
|
if (basebs == null) basebs = bs;
|
2018-08-06 04:27:18 +02:00
|
|
|
stateByID[(i << 4) + m] = bs;
|
2018-09-02 06:26:36 +02:00
|
|
|
if (mat != null) {
|
|
|
|
if (mat.name.equals("AIR")) {
|
|
|
|
bs.setAir();
|
|
|
|
}
|
|
|
|
if (mat.name.equals("LEAVES")) {
|
|
|
|
bs.setLeaves();
|
|
|
|
}
|
|
|
|
if (mat.name.equals("WOOD")) {
|
|
|
|
bs.setLog();
|
|
|
|
}
|
|
|
|
if (mat.isSolid) {
|
|
|
|
bs.setSolid();
|
|
|
|
}
|
|
|
|
}
|
2018-08-05 21:38:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 07:44:22 +01:00
|
|
|
//for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
|
|
|
|
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
|
|
|
|
// Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
|
|
|
|
//}
|
2018-08-05 21:38:13 +02:00
|
|
|
}
|
2018-08-08 08:39:51 +02:00
|
|
|
/**
|
|
|
|
* Create chunk cache for given chunks of given world
|
|
|
|
* @param dw - world
|
|
|
|
* @param chunks - chunk list
|
|
|
|
* @return cache
|
|
|
|
*/
|
|
|
|
public MapChunkCache getChunkCache(BukkitWorld dw, List<DynmapChunk> chunks) {
|
2018-08-10 08:03:38 +02:00
|
|
|
AbstractMapChunkCache c = new MapChunkCacheClassic();
|
2018-08-08 08:39:51 +02:00
|
|
|
c.setChunks(dw, chunks);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
public Object[] getBlockIDFieldFromSnapshot(ChunkSnapshot css) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-21 07:34:04 +02:00
|
|
|
/**
|
|
|
|
* Get biome base water multiplier
|
|
|
|
*/
|
|
|
|
public int getBiomeBaseWaterMult(Object bb) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-12-04 07:44:22 +01:00
|
|
|
public abstract String getStateStringByCombinedId(int blkid, int meta);
|
2020-05-25 20:55:36 +02:00
|
|
|
|
|
|
|
// Send title/subtitle to user
|
|
|
|
public void sendTitleText(Player p, String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTIcks) {
|
|
|
|
// Do send message for old implementations
|
|
|
|
if (p != null) {
|
|
|
|
if (title != null) p.sendMessage(title);
|
|
|
|
if (subtitle != null) p.sendMessage(subtitle);
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 08:57:59 +01:00
|
|
|
public boolean useGenericCache() {
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-25 20:55:36 +02:00
|
|
|
}
|