PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java

85 lines
3.1 KiB
Java
Raw Normal View History

2015-02-19 04:24:05 +01:00
package com.intellectualcrafters.plot.util;
2015-02-22 07:30:58 +01:00
import com.intellectualcrafters.plot.object.Location;
2015-02-19 04:24:05 +01:00
import com.intellectualcrafters.plot.object.PlotBlock;
2015-02-19 07:08:15 +01:00
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
2015-02-19 04:24:05 +01:00
public abstract class BlockManager {
2015-02-21 03:49:25 +01:00
public static BlockManager manager = new BukkitUtil();
2015-02-19 04:24:05 +01:00
private static long state = 1;
public static long nextLong() {
final long a = state;
state = xorShift64(a);
return a;
}
2015-02-20 07:34:19 +01:00
2015-02-19 04:24:05 +01:00
public static long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
2015-02-20 07:34:19 +01:00
2015-02-19 04:24:05 +01:00
public static int random(final int n) {
if (n == 1) {
return 0;
}
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
2015-02-22 12:30:46 +01:00
public abstract int getHeighestBlock(Location loc);
2015-02-22 08:13:27 +01:00
public abstract String getBiome(Location loc);
2015-02-22 07:56:46 +01:00
public abstract Location getSpawn(String world);
2015-02-22 07:30:58 +01:00
public abstract String[] getSign(Location loc);
public abstract boolean isWorld(String world);
2015-02-19 11:12:26 +01:00
public abstract void functionSetBlocks(String worldname, int[] x, int[] y, int[] z, int[] id, byte[] data);
2015-02-19 04:24:05 +01:00
2015-02-19 11:12:26 +01:00
public abstract void functionSetSign(String worldname, int x, int y, int z, String[] lines);
2015-02-19 04:24:05 +01:00
2015-02-21 03:49:25 +01:00
public abstract void functionSetBlock(String worldname, int x, int y, int z, int id, byte data);
2015-02-20 17:17:34 +01:00
public abstract void functionSetBiomes(final String worldname, final int[] x, final int z[], final int[] biome);
public static void setBiomes(final String worldname, final int[] x, final int z[], final int[] biome) {
manager.functionSetBiomes(worldname, x, z, biome);
}
2015-02-20 07:34:19 +01:00
public static void setBlocks(final String worldname, final int[] x, final int y[], final int z[], final PlotBlock[][] blocks) {
final int[] id = new int[blocks.length];
final byte[] data = new byte[blocks.length];
2015-02-19 04:24:05 +01:00
for (int i = 0; i < blocks.length; i++) {
2015-02-20 07:34:19 +01:00
final PlotBlock[] current = blocks[i];
final int n = random(current.length);
2015-02-19 04:24:05 +01:00
id[i] = current[n].id;
data[i] = current[n].data;
}
setBlocks(worldname, x, y, z, id, data);
}
2015-02-20 07:34:19 +01:00
public static void setBlocks(final String worldname, final int[] x, final int y[], final int z[], final PlotBlock[] blocks) {
final int[] id = new int[blocks.length];
final byte[] data = new byte[blocks.length];
2015-02-19 04:24:05 +01:00
for (int i = 0; i < blocks.length; i++) {
2015-02-20 07:34:19 +01:00
final PlotBlock current = blocks[i];
2015-02-19 04:24:05 +01:00
id[i] = current.id;
data[i] = current.data;
}
setBlocks(worldname, x, y, z, id, data);
}
2015-02-20 07:34:19 +01:00
public static void setSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
2015-02-19 11:12:26 +01:00
manager.functionSetSign(worldname, x, y, z, lines);
}
2015-02-20 07:34:19 +01:00
public static void setBlocks(final String worldname, final int[] x, final int[] y, final int[] z, final int[] id, final byte[] data) {
2015-02-19 11:12:26 +01:00
manager.functionSetBlocks(worldname, x, y, z, id, data);
2015-02-19 04:24:05 +01:00
}
}