Start 1.20.5 code

This commit is contained in:
Michael Primm 2024-04-26 20:54:41 -05:00
parent 9878719337
commit 669c75322a
12 changed files with 891 additions and 29 deletions

1
bukkit-helper-120-5/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build/

View File

@ -0,0 +1,17 @@
eclipse {
project {
name = "Dynmap(Spigot-1.20.5)"
}
}
description = 'bukkit-helper-1.20.5'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaLanguageVersion.of(17) // Need this here so eclipse task generates correctly.
dependencies {
implementation project(':bukkit-helper')
implementation project(':dynmap-api')
implementation project(path: ':DynmapCore', configuration: 'shadow')
compileOnly group: 'org.spigotmc', name: 'spigot-api', version:'1.20.4-R0.1-SNAPSHOT'
compileOnly group: 'org.spigotmc', name: 'spigot', version:'1.20.5-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,130 @@
package org.dynmap.bukkit.helper.v120_5;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.level.chunk.Chunk;
import net.minecraft.world.level.chunk.IChunkAccess;
import net.minecraft.world.level.chunk.storage.ChunkRegionLoader;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_20_R4.CraftServer;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.dynmap.MapManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
/**
* The provider used to work with paper libs
* Because paper libs need java 17 we can't interact with them directly
*/
@SuppressWarnings({"JavaReflectionMemberAccess"}) //java don't know about paper
public class AsyncChunkProvider120_5 {
private final Method getChunk;
private final Method getAsyncSaveData;
private final Method save;
private final Enum<?> data;
private final Enum<?> priority;
private int currTick = MinecraftServer.currentTick;
private int currChunks = 0;
AsyncChunkProvider120_5() {
try {
Method getChunk1 = null;
Method getAsyncSaveData1 = null;
Method save1 = null;
Enum<?> priority1 = null;
Enum<?> data1 = null;
try {
Class<?> threadClass = Class.forName("io.papermc.paper.chunk.system.io.RegionFileIOThread");
Class<?> dataclass = Arrays.stream(threadClass.getDeclaredClasses())
.filter(c -> c.getSimpleName().equals("RegionFileType"))
.findAny()
.orElseThrow(NullPointerException::new);
data1 = Enum.valueOf(cast(dataclass), "CHUNK_DATA");
Class<?> priorityClass = Arrays.stream(Class.forName("ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor").getClasses())
.filter(c -> c.getSimpleName().equals("Priority"))
.findAny()
.orElseThrow(NullPointerException::new);
//Almost lowest priority, but not quite so low as to be considered idle
//COMPLETING->BLOCKING->HIGHEST->HIGHER->HIGH->NORMAL->LOW->LOWER->LOWEST->IDLE
priority1 = Enum.valueOf(cast(priorityClass), "LOWEST");
getAsyncSaveData1 = ChunkRegionLoader.class.getMethod("getAsyncSaveData", WorldServer.class, IChunkAccess.class);
save1 = ChunkRegionLoader.class.getMethod("saveChunk", WorldServer.class, IChunkAccess.class, getAsyncSaveData1.getReturnType());
getChunk1 = threadClass.getMethod("loadDataAsync", WorldServer.class, int.class, int.class, data1.getClass(), BiConsumer.class, boolean.class, priority1.getClass());
} catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
}
getAsyncSaveData = Objects.requireNonNull(getAsyncSaveData1);
save = Objects.requireNonNull(save1);
getChunk = Objects.requireNonNull(getChunk1);
data = Objects.requireNonNull(data1);
priority = Objects.requireNonNull(priority1);
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
private <T> T cast(Object o) {
return (T) o;
}
public CompletableFuture<NBTTagCompound> getChunk(WorldServer world, int x, int y) throws InvocationTargetException, IllegalAccessException {
CompletableFuture<NBTTagCompound> future = new CompletableFuture<>();
getChunk.invoke(null, world, x, y, data, (BiConsumer<NBTTagCompound, Throwable>) (nbt, exception) -> future.complete(nbt), true, priority);
return future;
}
public synchronized Supplier<NBTTagCompound> getLoadedChunk(CraftWorld world, int x, int z) {
if (!world.isChunkLoaded(x, z)) return () -> null;
Chunk c = world.getHandle().getChunkIfLoaded(x, z); //already safe async on vanilla
if ((c == null) || !c.q) return () -> null; // c.loaded
if (currTick != MinecraftServer.currentTick) {
currTick = MinecraftServer.currentTick;
currChunks = 0;
}
//prepare data synchronously
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
//Null will mean that we save with spigot methods, which may be risky on async
//Since we're not in main thread, it now refuses new tasks because of shutdown, the risk is lower
if (!Bukkit.isPrimaryThread()) return null;
try {
return getAsyncSaveData.invoke(null, world.getHandle(), c);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}, ((CraftServer) Bukkit.getServer()).getServer());
//we shouldn't stress main thread
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
try {
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
} catch (InterruptedException ignored) {}
}
//save data asynchronously
return () -> {
Object o = null;
try {
o = future.get();
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, o);
} catch (InterruptedException e) {
return null;
} catch (InvocationTargetException e) {
//We tried to use simple spigot methods at shutdown and failed, hopes for reading from disk
if (o == null) return null;
throw new RuntimeException(e);
} catch (ReflectiveOperationException | ExecutionException e) {
throw new RuntimeException(e);
}
};
}
}

View File

@ -0,0 +1,464 @@
package org.dynmap.bukkit.helper.v120_5;
import org.bukkit.*;
import org.bukkit.craftbukkit.v1_20_R4.CraftChunk;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.dynmap.DynmapChunk;
import org.dynmap.Log;
import org.dynmap.bukkit.helper.BukkitMaterial;
import org.dynmap.bukkit.helper.BukkitVersionHelper;
import org.dynmap.bukkit.helper.BukkitWorld;
import org.dynmap.bukkit.helper.BukkitVersionHelperGeneric.TexturesPayload;
import org.dynmap.renderer.DynmapBlockState;
import org.dynmap.utils.MapChunkCache;
import org.dynmap.utils.Polygon;
import com.google.common.collect.Iterables;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import net.minecraft.core.RegistryBlockID;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.core.BlockPosition;
import net.minecraft.core.IRegistry;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.nbt.NBTBase;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tags.TagsBlock;
import net.minecraft.world.level.BlockAccessAir;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BlockFluids;
import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Helper for isolation of bukkit version specific issues
*/
public class BukkitVersionHelperSpigot120_5 extends BukkitVersionHelper {
private final boolean unsafeAsync;
public BukkitVersionHelperSpigot120_5() {
boolean unsafeAsync1;
try {
Class.forName("io.papermc.paper.chunk.system.io.RegionFileIOThread");
unsafeAsync1 = false;
} catch (ClassNotFoundException e) {
unsafeAsync1 = true;
}
this.unsafeAsync = unsafeAsync1;
}
@Override
public boolean isUnsafeAsync() {
return unsafeAsync;
}
/**
* Get block short name list
*/
@Override
public String[] getBlockNames() {
RegistryBlockID<IBlockData> bsids = Block.q;
Block baseb = null;
Iterator<IBlockData> iter = bsids.iterator();
ArrayList<String> names = new ArrayList<String>();
while (iter.hasNext()) {
IBlockData bs = iter.next();
Block b = bs.b();
// If this is new block vs last, it's the base block state
if (b != baseb) {
baseb = b;
continue;
}
MinecraftKey id = BuiltInRegistries.e.b(b);
String bn = id.toString();
if (bn != null) {
names.add(bn);
Log.info("block=" + bn);
}
}
return names.toArray(new String[0]);
}
private static IRegistry<BiomeBase> reg = null;
private static IRegistry<BiomeBase> getBiomeReg() {
if (reg == null) {
reg = MinecraftServer.getServer().bc().d(Registries.az);
}
return reg;
}
private Object[] biomelist;
/**
* Get list of defined biomebase objects
*/
@Override
public Object[] getBiomeBaseList() {
if (biomelist == null) {
biomelist = new BiomeBase[256];
Iterator<BiomeBase> iter = getBiomeReg().iterator();
while (iter.hasNext()) {
BiomeBase b = iter.next();
int bidx = getBiomeReg().a(b);
if (bidx >= biomelist.length) {
biomelist = Arrays.copyOf(biomelist, bidx + biomelist.length);
}
biomelist[bidx] = b;
}
}
return biomelist;
}
/** Get ID from biomebase */
@Override
public int getBiomeBaseID(Object bb) {
return getBiomeReg().a((BiomeBase)bb);
}
public static IdentityHashMap<IBlockData, DynmapBlockState> dataToState;
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
@Override
public void initializeBlockStates() {
dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
RegistryBlockID<IBlockData> bsids = Block.q;
Block baseb = null;
Iterator<IBlockData> iter = bsids.iterator();
ArrayList<String> names = new ArrayList<String>();
// Loop through block data states
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
IBlockData bd = iter.next();
Block b = bd.b();
MinecraftKey id = BuiltInRegistries.e.b(b);
String bname = id.toString();
DynmapBlockState lastbs = lastBlockState.get(bname); // See if we have seen this one
int idx = 0;
if (lastbs != null) { // Yes
idx = lastbs.getStateCount(); // Get number of states so far, since this is next
}
// Build state name
String sb = "";
String fname = bd.toString();
int off1 = fname.indexOf('[');
if (off1 >= 0) {
int off2 = fname.indexOf(']');
sb = fname.substring(off1+1, off2);
}
int lightAtten = bd.b(BlockAccessAir.a, BlockPosition.c); // getLightBlock
//Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setAttenuatesLight(lightAtten);
if (bd.w() != null) { bld.setMaterial(bd.w().toString()); }
if (bd.e()) { bld.setSolid(); }
if (bd.i()) { bld.setAir(); }
if (bd.a(TagsBlock.t)) { bld.setLog(); }
if (bd.a(TagsBlock.O)) { bld.setLeaves(); }
if ((!bd.u().c()) && ((bd.b() instanceof BlockFluids) == false)) { // Test if fluid type for block is not empty
bld.setWaterlogged();
//Log.info("statename=" + bname + "[" + sb + "] = waterlogged");
}
DynmapBlockState dbs = bld.build(); // Build state
dataToState.put(bd, dbs);
lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
}
}
/**
* Create chunk cache for given chunks of given world
* @param dw - world
* @param chunks - chunk list
* @return cache
*/
@Override
public MapChunkCache getChunkCache(BukkitWorld dw, List<DynmapChunk> chunks) {
MapChunkCache120_5 c = new MapChunkCache120_5(gencache);
c.setChunks(dw, chunks);
return c;
}
/**
* Get biome base water multiplier
*/
@Override
public int getBiomeBaseWaterMult(Object bb) {
BiomeBase biome = (BiomeBase) bb;
return biome.i(); // waterColor
}
/** Get temperature from biomebase */
@Override
public float getBiomeBaseTemperature(Object bb) {
return ((BiomeBase)bb).g();
}
/** Get humidity from biomebase */
@Override
public float getBiomeBaseHumidity(Object bb) {
String vals = ((BiomeBase)bb).i.toString(); // Sleazy
float humidity = 0.5F;
int idx = vals.indexOf("downfall=");
if (idx >= 0) {
humidity = Float.parseFloat(vals.substring(idx+9, vals.indexOf(']', idx)));
}
return humidity;
}
@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)) {
size = size / 2;
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;
}
// Send title/subtitle to user
public void sendTitleText(Player p, String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTIcks) {
if (p != null) {
p.sendTitle(title, subtitle, fadeInTicks, stayTicks, fadeOutTIcks);
}
}
/**
* Get material map by block ID
*/
@Override
public BukkitMaterial[] getMaterialList() {
return new BukkitMaterial[4096]; // Not used
}
@Override
public void unloadChunkNoSave(World w, org.bukkit.Chunk c, int cx, int cz) {
Log.severe("unloadChunkNoSave not implemented");
}
private String[] biomenames;
@Override
public String[] getBiomeNames() {
if (biomenames == null) {
biomenames = new String[256];
Iterator<BiomeBase> iter = getBiomeReg().iterator();
while (iter.hasNext()) {
BiomeBase b = iter.next();
int bidx = getBiomeReg().a(b);
if (bidx >= biomenames.length) {
biomenames = Arrays.copyOf(biomenames, bidx + biomenames.length);
}
biomenames[bidx] = b.toString();
}
}
return biomenames;
}
@Override
public String getStateStringByCombinedId(int blkid, int meta) {
Log.severe("getStateStringByCombinedId not implemented");
return null;
}
@Override
/** Get ID string from biomebase */
public String getBiomeBaseIDString(Object bb) {
return getBiomeReg().b((BiomeBase)bb).a();
}
@Override
public String getBiomeBaseResourceLocsation(Object bb) {
return getBiomeReg().b((BiomeBase)bb).toString();
}
@Override
public Object getUnloadQueue(World world) {
Log.warning("getUnloadQueue not implemented yet");
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isInUnloadQueue(Object unloadqueue, int x, int z) {
Log.warning("isInUnloadQueue not implemented yet");
// TODO Auto-generated method stub
return false;
}
@Override
public Object[] getBiomeBaseFromSnapshot(ChunkSnapshot css) {
Log.warning("getBiomeBaseFromSnapshot not implemented yet");
// TODO Auto-generated method stub
return new Object[256];
}
@Override
public long getInhabitedTicks(Chunk c) {
return ((CraftChunk)c).getHandle(ChunkStatus.n).u();
}
@Override
public Map<?, ?> getTileEntitiesForChunk(Chunk c) {
return ((CraftChunk)c).getHandle(ChunkStatus.n).k;
}
@Override
public int getTileEntityX(Object te) {
TileEntity tileent = (TileEntity) te;
return tileent.ay_().u();
}
@Override
public int getTileEntityY(Object te) {
TileEntity tileent = (TileEntity) te;
return tileent.ay_().v();
}
@Override
public int getTileEntityZ(Object te) {
TileEntity tileent = (TileEntity) te;
return tileent.ay_().w();
}
@Override
public Object readTileEntityNBT(Object te) {
TileEntity tileent = (TileEntity) te;
NBTTagCompound nbt = new NBTTagCompound(); //TODO tileent.o();
return nbt;
}
@Override
public Object getFieldValue(Object nbt, String field) {
NBTTagCompound rec = (NBTTagCompound) nbt;
NBTBase val = rec.c(field);
if(val == null) return null;
if(val instanceof NBTTagByte) {
return ((NBTTagByte)val).h();
}
else if(val instanceof NBTTagShort) {
return ((NBTTagShort)val).g();
}
else if(val instanceof NBTTagInt) {
return ((NBTTagInt)val).f();
}
else if(val instanceof NBTTagLong) {
return ((NBTTagLong)val).e();
}
else if(val instanceof NBTTagFloat) {
return ((NBTTagFloat)val).j();
}
else if(val instanceof NBTTagDouble) {
return ((NBTTagDouble)val).i();
}
else if(val instanceof NBTTagByteArray) {
return ((NBTTagByteArray)val).d();
}
else if(val instanceof NBTTagString) {
return ((NBTTagString)val).s_();
}
else if(val instanceof NBTTagIntArray) {
return ((NBTTagIntArray)val).f();
}
return null;
}
@Override
public Player[] getOnlinePlayers() {
Collection<? extends Player> p = Bukkit.getServer().getOnlinePlayers();
return p.toArray(new Player[0]);
}
@Override
public double getHealth(Player p) {
return p.getHealth();
}
private static final Gson gson = new GsonBuilder().create();
/**
* Get skin URL for player
* @param player
*/
@Override
public String getSkinURL(Player player) {
String url = null;
CraftPlayer cp = (CraftPlayer)player;
GameProfile profile = cp.getProfile();
if (profile != null) {
PropertyMap pm = profile.getProperties();
if (pm != null) {
Collection<Property> txt = pm.get("textures");
Property textureProperty = Iterables.getFirst(pm.get("textures"), null);
if (textureProperty != null) {
String val = textureProperty.value();
if (val != null) {
TexturesPayload result = null;
try {
String json = new String(Base64.getDecoder().decode(val), StandardCharsets.UTF_8);
result = gson.fromJson(json, TexturesPayload.class);
} catch (JsonParseException e) {
} catch (IllegalArgumentException x) {
Log.warning("Malformed response from skin URL check: " + val);
}
if ((result != null) && (result.textures != null) && (result.textures.containsKey("SKIN"))) {
url = result.textures.get("SKIN").url;
}
}
}
}
}
return url;
}
// Get minY for world
@Override
public int getWorldMinY(World w) {
CraftWorld cw = (CraftWorld) w;
return cw.getMinHeight();
}
@Override
public boolean useGenericCache() {
return true;
}
}

View File

@ -0,0 +1,112 @@
package org.dynmap.bukkit.helper.v120_5;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.biome.BiomeFog;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
import org.dynmap.DynmapChunk;
import org.dynmap.bukkit.helper.BukkitVersionHelper;
import org.dynmap.bukkit.helper.BukkitWorld;
import org.dynmap.common.BiomeMap;
import org.dynmap.common.chunk.GenericChunk;
import org.dynmap.common.chunk.GenericChunkCache;
import org.dynmap.common.chunk.GenericMapChunkCache;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.level.ChunkCoordIntPair;
import net.minecraft.world.level.chunk.storage.ChunkRegionLoader;
import net.minecraft.world.level.chunk.Chunk;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
/**
* Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread
*/
public class MapChunkCache120_5 extends GenericMapChunkCache {
private static final AsyncChunkProvider120_5 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider120_5();
private World w;
/**
* Construct empty cache
*/
public MapChunkCache120_5(GenericChunkCache cc) {
super(cc);
}
// Load generic chunk from existing and already loaded chunk
@Override
protected Supplier<GenericChunk> getLoadedChunkAsync(DynmapChunk chunk) {
Supplier<NBTTagCompound> supplier = provider.getLoadedChunk((CraftWorld) w, chunk.x, chunk.z);
return () -> {
NBTTagCompound nbt = supplier.get();
return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null;
};
}
protected GenericChunk getLoadedChunk(DynmapChunk chunk) {
CraftWorld cw = (CraftWorld) w;
if (!cw.isChunkLoaded(chunk.x, chunk.z)) return null;
Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z);
if (c == null || !c.q) return null; // c.loaded
NBTTagCompound nbt = ChunkRegionLoader.a(cw.getHandle(), c);
return nbt != null ? parseChunkFromNBT(new NBT.NBTCompound(nbt)) : null;
}
// Load generic chunk from unloaded chunk
@Override
protected Supplier<GenericChunk> loadChunkAsync(DynmapChunk chunk){
try {
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
return () -> {
NBTTagCompound compound;
try {
compound = nbt.get();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
};
} catch (InvocationTargetException | IllegalAccessException ignored) {
return () -> null;
}
}
protected GenericChunk loadChunk(DynmapChunk chunk) {
CraftWorld cw = (CraftWorld) w;
NBTTagCompound nbt = null;
ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
GenericChunk gc = null;
try { // BUGBUG - convert this all to asyn properly, since now native async
nbt = cw.getHandle().l().a.e(cc).join().get(); // playerChunkMap
} catch (CancellationException cx) {
} catch (NoSuchElementException snex) {
}
if (nbt != null) {
gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
}
return gc;
}
public void setChunks(BukkitWorld dw, List<DynmapChunk> chunks) {
this.w = dw.getWorld();
super.setChunks(dw, chunks);
}
@Override
public int getFoliageColor(BiomeMap bm, int[] colormap, int x, int z) {
return bm.<BiomeBase>getBiomeObject().map(BiomeBase::h).flatMap(BiomeFog::e).orElse(colormap[bm.biomeLookup()]);
}
@Override
public int getGrassColor(BiomeMap bm, int[] colormap, int x, int z) {
BiomeFog fog = bm.<BiomeBase>getBiomeObject().map(BiomeBase::h).orElse(null);
if (fog == null) return colormap[bm.biomeLookup()];
return fog.g().a(x, z, fog.f().orElse(colormap[bm.biomeLookup()]));
}
}

View File

@ -0,0 +1,126 @@
package org.dynmap.bukkit.helper.v120_5;
import org.dynmap.common.chunk.GenericBitStorage;
import org.dynmap.common.chunk.GenericNBTCompound;
import org.dynmap.common.chunk.GenericNBTList;
import java.util.Set;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.SimpleBitStorage;
public class NBT {
public static class NBTCompound implements GenericNBTCompound {
private final NBTTagCompound obj;
public NBTCompound(NBTTagCompound t) {
this.obj = t;
}
@Override
public Set<String> getAllKeys() {
return obj.e();
}
@Override
public boolean contains(String s) {
return obj.e(s);
}
@Override
public boolean contains(String s, int i) {
return obj.b(s, i);
}
@Override
public byte getByte(String s) {
return obj.f(s);
}
@Override
public short getShort(String s) {
return obj.g(s);
}
@Override
public int getInt(String s) {
return obj.h(s);
}
@Override
public long getLong(String s) {
return obj.i(s);
}
@Override
public float getFloat(String s) {
return obj.j(s);
}
@Override
public double getDouble(String s) {
return obj.k(s);
}
@Override
public String getString(String s) {
return obj.l(s);
}
@Override
public byte[] getByteArray(String s) {
return obj.m(s);
}
@Override
public int[] getIntArray(String s) {
return obj.n(s);
}
@Override
public long[] getLongArray(String s) {
return obj.o(s);
}
@Override
public GenericNBTCompound getCompound(String s) {
return new NBTCompound(obj.p(s));
}
@Override
public GenericNBTList getList(String s, int i) {
return new NBTList(obj.c(s, i));
}
@Override
public boolean getBoolean(String s) {
return obj.q(s);
}
@Override
public String getAsString(String s) {
return obj.c(s).s_();
}
@Override
public GenericBitStorage makeBitStorage(int bits, int count, long[] data) {
return new OurBitStorage(bits, count, data);
}
public String toString() {
return obj.toString();
}
}
public static class NBTList implements GenericNBTList {
private final NBTTagList obj;
public NBTList(NBTTagList t) {
obj = t;
}
@Override
public int size() {
return obj.size();
}
@Override
public String getString(int idx) {
return obj.j(idx);
}
@Override
public GenericNBTCompound getCompound(int idx) {
return new NBTCompound(obj.a(idx));
}
public String toString() {
return obj.toString();
}
}
public static class OurBitStorage implements GenericBitStorage {
private final SimpleBitStorage bs;
public OurBitStorage(int bits, int count, long[] data) {
bs = new SimpleBitStorage(bits, count, data);
}
@Override
public int get(int idx) {
return bs.a(idx);
}
}
}

View File

@ -2,32 +2,35 @@
<projectDescription>
<name>Dynmap(Spigot-Common)</name>
<comment>bukkit-helper</comment>
<projects/>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments/>
</buildCommand>
</buildSpec>
<linkedResources/>
<filteredResources>
<filter>
<id>1</id>
<name></name>
<type>30</type>
<name/>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>

View File

@ -1,16 +1,16 @@
#
#Thu Dec 14 22:32:41 CST 2023
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
#Fri Apr 26 17:37:35 CDT 2024
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.annotation.nonnull=javax.annotation.Nonnull
org.eclipse.jdt.core.compiler.annotation.nullable=javax.annotation.Nullable
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.annotation.nonnull=javax.annotation.Nonnull
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.compliance=1.8

View File

@ -899,8 +899,8 @@ public abstract class AbstractMapChunkCache extends MapChunkCache {
int cz = te_z & 0xF;
String[] te_fields = HDBlockModels.getTileEntityFieldsNeeded(ss.getBlockType(cx, te_y, cz));
if(te_fields != null) {
//Object nbtcompound = BukkitVersionHelper.helper.readTileEntityNBT(t);
Object nbtcompound = BukkitVersionHelper.helper.readTileEntityNBT(t);
vals.clear();
for(String id: te_fields) {
Object val = BukkitVersionHelper.helper.getFieldValue(nbtcompound, id);

View File

@ -25,6 +25,7 @@ include ':bukkit-helper-119-4'
include ':bukkit-helper-120'
include ':bukkit-helper-120-2'
include ':bukkit-helper-120-4'
include ':bukkit-helper-120-5'
include ':bukkit-helper'
include ':dynmap-api'
include ':DynmapCore'
@ -64,6 +65,7 @@ project(':bukkit-helper-119-4').projectDir = "$rootDir/bukkit-helper-119-4" as F
project(':bukkit-helper-120').projectDir = "$rootDir/bukkit-helper-120" as File
project(':bukkit-helper-120-2').projectDir = "$rootDir/bukkit-helper-120-2" as File
project(':bukkit-helper-120-4').projectDir = "$rootDir/bukkit-helper-120-4" as File
project(':bukkit-helper-120-5').projectDir = "$rootDir/bukkit-helper-120-5" as File
project(':bukkit-helper').projectDir = "$rootDir/bukkit-helper" as File
project(':dynmap-api').projectDir = "$rootDir/dynmap-api" as File
project(':DynmapCore').projectDir = "$rootDir/DynmapCore" as File

View File

@ -85,6 +85,9 @@ dependencies {
implementation(project(':bukkit-helper-120-4')) {
transitive = false
}
implementation(project(':bukkit-helper-120-5')) {
transitive = false
}
}
processResources {
@ -124,6 +127,7 @@ shadowJar {
include(dependency(':bukkit-helper-120'))
include(dependency(':bukkit-helper-120-2'))
include(dependency(':bukkit-helper-120-4'))
include(dependency(':bukkit-helper-120-5'))
}
relocate('org.bstats', 'org.dynmap.bstats')
destinationDir = file '../target'

View File

@ -46,9 +46,12 @@ public class Helper {
else if (v.contains("(MC: 1.20.2)")) {
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v120_2.BukkitVersionHelperSpigot120_2");
}
else if (v.contains("(MC: 1.20.")) {
else if (v.contains("(MC: 1.20.3)") || v.contains("(MC: 1.20.4)")) {
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v120_4.BukkitVersionHelperSpigot120_4");
}
else if (v.contains("(MC: 1.20.")) {
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v120_5.BukkitVersionHelperSpigot120_5");
}
else if (v.contains("(MC: 1.19)") || v.contains("(MC: 1.19.1)") || v.contains("(MC: 1.19.2)")) {
BukkitVersionHelper.helper = loadVersionHelper("org.dynmap.bukkit.helper.v119.BukkitVersionHelperSpigot119");
}