Update BlockTracker to use Spigot API directly instead of compatibility

layer
Fixes #4692 Fixes #4698
This commit is contained in:
nossr50
2021-12-27 11:09:27 -08:00
parent ddc9a69f4b
commit dd550feb65
7 changed files with 38 additions and 117 deletions

View File

@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.util.compat.layers.world.WorldCompatibilityLayer;
import com.gmail.nossr50.util.random.RandomChanceSkill;
import com.gmail.nossr50.util.random.RandomChanceUtil;
import org.bukkit.Material;
@ -302,11 +301,17 @@ public final class BlockUtils {
return hasWoodcuttingXP(block.getState()) || isNonWoodPartOfTree(block.getType());
}
public static boolean isWithinWorldBounds(@NotNull WorldCompatibilityLayer worldCompatibilityLayer, @NotNull Block block) {
/**
* Checks to see if a Block is within the world bounds
* Prevent processing blocks from other plugins (or perhaps odd spigot anomalies) from sending blocks that can't exist within the world
* @param block
* @return
*/
public static boolean isWithinWorldBounds(@NotNull Block block) {
World world = block.getWorld();
//World min height = inclusive | World max height = exclusive
return block.getY() >= worldCompatibilityLayer.getMinWorldHeight(world) && block.getY() < worldCompatibilityLayer.getMaxWorldHeight(world);
return block.getY() >= world.getMinHeight() && block.getY() < world.getMaxHeight();
}
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.util.blockmeta;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
@ -25,7 +24,7 @@ public class BitSetChunkStore implements ChunkStore {
private transient boolean dirty = false;
public BitSetChunkStore(@NotNull World world, int cx, int cz) {
this(world.getUID(), mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(world), world.getMaxHeight(), cx, cz);
this(world.getUID(), world.getMinHeight(), world.getMaxHeight(), cx, cz);
}
private BitSetChunkStore(@NotNull UUID worldUid, int worldMin, int worldMax, int cx, int cz) {
@ -109,23 +108,23 @@ public class BitSetChunkStore implements ChunkStore {
return (z * 16 + x) + (256 * (y + yOffset));
}
private static int getWorldMin(@NotNull UUID worldUid, int storedWorldMin) {
private static int getWorldMin(@NotNull UUID worldUid) {
World world = Bukkit.getWorld(worldUid);
// Not sure how this case could come up, but might as well handle it gracefully. Loading a chunkstore for an unloaded world?
if (world == null)
return storedWorldMin;
throw new RuntimeException("Cannot grab a minimum world height for an unloaded world");
return mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(world);
return world.getMinHeight();
}
private static int getWorldMax(@NotNull UUID worldUid, int storedWorldMax)
private static int getWorldMax(@NotNull UUID worldUid)
{
World world = Bukkit.getWorld(worldUid);
// Not sure how this case could come up, but might as well handle it gracefully. Loading a chunkstore for an unloaded world?
if (world == null)
return storedWorldMax;
throw new RuntimeException("Cannot grab a maximum world height for an unloaded world");
return world.getMaxHeight();
}
@ -171,8 +170,8 @@ public class BitSetChunkStore implements ChunkStore {
in.readFully(temp);
BitSet stored = BitSet.valueOf(temp);
int currentWorldMin = getWorldMin(worldUid, worldMin);
int currentWorldMax = getWorldMax(worldUid, worldMax);
int currentWorldMin = getWorldMin(worldUid);
int currentWorldMax = getWorldMax(worldUid);
// The order in which the world height update code occurs here is important, the world max truncate math only holds up if done before adjusting for min changes
// Lop off extra data if world max has shrunk
@ -273,8 +272,8 @@ public class BitSetChunkStore implements ChunkStore {
public @NotNull BitSetChunkStore convert()
{
int currentWorldMin = getWorldMin(worldUid, 0);
int currentWorldMax = getWorldMax(worldUid, worldMax);
int currentWorldMin = getWorldMin(worldUid);
int currentWorldMax = getWorldMax(worldUid);
BitSetChunkStore converted = new BitSetChunkStore(worldUid, currentWorldMin, currentWorldMax, cx, cz);

View File

@ -10,12 +10,9 @@ import com.gmail.nossr50.util.compat.layers.persistentdata.SpigotPersistentDataL
import com.gmail.nossr50.util.compat.layers.persistentdata.SpigotPersistentDataLayer_1_14;
import com.gmail.nossr50.util.compat.layers.skills.AbstractMasterAnglerCompatibility;
import com.gmail.nossr50.util.compat.layers.skills.MasterAnglerCompatibilityLayer;
import com.gmail.nossr50.util.compat.layers.world.WorldCompatibilityLayer;
import com.gmail.nossr50.util.compat.layers.world.WorldCompatibilityLayer_1_16_4;
import com.gmail.nossr50.util.nms.NMSVersion;
import com.gmail.nossr50.util.platform.MinecraftGameVersion;
import com.gmail.nossr50.util.text.StringUtils;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -40,7 +37,6 @@ public class CompatibilityManager {
private AbstractPersistentDataLayer persistentDataLayer;
private AbstractBungeeSerializerCompatibilityLayer bungeeSerializerCompatibilityLayer;
private AbstractMasterAnglerCompatibility masterAnglerCompatibility;
private WorldCompatibilityLayer worldCompatibilityLayer;
public CompatibilityManager(@NotNull MinecraftGameVersion minecraftGameVersion) {
mcMMO.p.getLogger().info("Loading compatibility layers...");
@ -71,29 +67,10 @@ public class CompatibilityManager {
initPersistentDataLayer();
initBungeeSerializerLayer();
initMasterAnglerLayer();
initWorldCompatibilityLayer();
isFullyCompatibleServerSoftware = true;
}
private void initWorldCompatibilityLayer() {
if(minecraftGameVersion.isAtLeast(1, 17, 0)) {
worldCompatibilityLayer = new WorldCompatibilityLayer_1_16_4();
} else {
worldCompatibilityLayer = new WorldCompatibilityLayer() {
@Override
public int getMinWorldHeight(@NotNull World world) {
return WorldCompatibilityLayer.super.getMinWorldHeight(world);
}
@Override
public int getMaxWorldHeight(@NotNull World world) {
return WorldCompatibilityLayer.super.getMaxWorldHeight(world);
}
};
}
}
private void initMasterAnglerLayer() {
if(minecraftGameVersion.isAtLeast(1, 16, 3)) {
masterAnglerCompatibility = new MasterAnglerCompatibilityLayer();
@ -202,10 +179,6 @@ public class CompatibilityManager {
return masterAnglerCompatibility;
}
public @NotNull WorldCompatibilityLayer getWorldCompatibilityLayer() {
return worldCompatibilityLayer;
}
public @Nullable MinecraftGameVersion getMinecraftGameVersion() {
return minecraftGameVersion;
}

View File

@ -1,11 +0,0 @@
package com.gmail.nossr50.util.compat.layers.world;
import com.gmail.nossr50.util.compat.CompatibilityLayer;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
public interface WorldCompatibilityLayer extends CompatibilityLayer {
default int getMinWorldHeight(@NotNull World world) { return 0; }
default int getMaxWorldHeight(@NotNull World world) { return 256; }
}

View File

@ -1,16 +0,0 @@
package com.gmail.nossr50.util.compat.layers.world;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
public class WorldCompatibilityLayer_1_16_4 implements WorldCompatibilityLayer {
@Override
public int getMinWorldHeight(@NotNull World world) {
return world.getMinHeight();
}
@Override
public int getMaxWorldHeight(@NotNull World world) {
return world.getMaxHeight();
}
}