mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 14:06:17 +01:00
SPIGOT-4325: Validate coordinate arguments in Chunk/ChunkSnapshot
This commit is contained in:
parent
a1ab86d8cb
commit
3831ae621f
@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -69,6 +70,8 @@ public class CraftChunk implements Chunk {
|
||||
}
|
||||
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
validateChunkCoordinates(x, y, z);
|
||||
|
||||
return new CraftBlock(worldServer, new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z));
|
||||
}
|
||||
|
||||
@ -275,6 +278,12 @@ public class CraftChunk implements Chunk {
|
||||
return temps;
|
||||
}
|
||||
|
||||
static void validateChunkCoordinates(int x, int y, int z) {
|
||||
Preconditions.checkArgument(0 <= x && x <= 15, "x out of range (expected 0-15, got %s)", x);
|
||||
Preconditions.checkArgument(0 <= y && y <= 255, "y out of range (expected 0-255, got %s)", y);
|
||||
Preconditions.checkArgument(0 <= z && z <= 15, "z out of range (expected 0-15, got %s)", z);
|
||||
}
|
||||
|
||||
static {
|
||||
Arrays.fill(emptySkyLight, (byte) 0xFF);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -57,38 +58,54 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
||||
|
||||
@Override
|
||||
public Material getBlockType(int x, int y, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, y, z);
|
||||
|
||||
return CraftMagicNumbers.getMaterial(blockids[y >> 4].a(x, y & 0xF, z).getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final BlockData getBlockData(int x, int y, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, y, z);
|
||||
|
||||
return CraftBlockData.fromData(blockids[y >> 4].a(x, y & 0xF, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getData(int x, int y, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, y, z);
|
||||
|
||||
return CraftMagicNumbers.toLegacyData(blockids[y >> 4].a(x, y & 0xF, z));
|
||||
}
|
||||
|
||||
public final int getBlockSkyLight(int x, int y, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, y, z);
|
||||
|
||||
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
|
||||
return (skylight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
|
||||
}
|
||||
|
||||
public final int getBlockEmittedLight(int x, int y, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, y, z);
|
||||
|
||||
int off = ((y & 0xF) << 7) | (z << 3) | (x >> 1);
|
||||
return (emitlight[y >> 4][off] >> ((x & 1) << 2)) & 0xF;
|
||||
}
|
||||
|
||||
public final int getHighestBlockYAt(int x, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, 0, z);
|
||||
|
||||
return hmap.a(x, z);
|
||||
}
|
||||
|
||||
public final Biome getBiome(int x, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, 0, z);
|
||||
|
||||
return CraftBlock.biomeBaseToBiome(biome[z << 4 | x]);
|
||||
}
|
||||
|
||||
public final double getRawBiomeTemperature(int x, int z) {
|
||||
CraftChunk.validateChunkCoordinates(x, 0, z);
|
||||
|
||||
return biomeTemp[z << 4 | x];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user