mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-23 12:06:15 +01:00
chunk
This commit is contained in:
parent
c55961e299
commit
d836286b6f
@ -95,7 +95,6 @@ import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotSelection;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.PlayerFunctions;
|
||||
|
@ -1,136 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
|
||||
/**
|
||||
* Created 2014-10-12 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings("deprecation") public class PlotSelection {
|
||||
|
||||
public final static HashMap<String, PlotSelection> currentSelection = new HashMap<>();
|
||||
|
||||
private final PlotBlock[] plotBlocks;
|
||||
|
||||
private final int width;
|
||||
|
||||
private final Plot plot;
|
||||
|
||||
private final Biome biome;
|
||||
|
||||
public PlotSelection(final int width, final World world, final Plot plot) {
|
||||
this.width = width;
|
||||
this.plot = plot;
|
||||
|
||||
this.plotBlocks = new PlotBlock[(width * width) * (world.getMaxHeight() - 1)];
|
||||
|
||||
final Location bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()), top = PlotHelper.getPlotTopLocAbs(world, plot.getId());
|
||||
final int minX = bot.getBlockX(), maxX = top.getBlockX(), minZ = bot.getBlockZ(), maxZ = top.getBlockZ(), minY = 1, maxY = world.getMaxHeight();
|
||||
Block current;
|
||||
|
||||
this.biome = world.getBiome(minX, minZ);
|
||||
|
||||
int index = 0;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
current = world.getBlockAt(x + 1, y, z + 1);
|
||||
this.plotBlocks[index++] = new PlotBlock((short) current.getTypeId(), current.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yay :D
|
||||
}
|
||||
|
||||
public static boolean swap(final World world, final PlotId id1, final PlotId id2) {
|
||||
|
||||
final Location bot2 = PlotHelper.getPlotBottomLocAbs(world, id2).add(1, 0, 1);
|
||||
final Location bot1 = PlotHelper.getPlotBottomLocAbs(world, id1).add(1, 0, 1);
|
||||
final Location top1 = PlotHelper.getPlotTopLocAbs(world, id1);
|
||||
final int minX = bot1.getBlockX(), maxX = top1.getBlockX(), minZ = bot1.getBlockZ(), maxZ = top1.getBlockZ(), minX2 = bot2.getBlockX(), minZ2 = bot2.getBlockZ();
|
||||
for (int x = 0; x <= (maxX - minX); x++) {
|
||||
for (int z = 0; z <= (maxZ - minZ); z++) {
|
||||
for (int y = 1; y <= world.getMaxHeight(); y++) {
|
||||
|
||||
final Block block1 = world.getBlockAt(x + minX, y, z + minZ);
|
||||
final Block block2 = world.getBlockAt(x + minX2, y, z + minZ2);
|
||||
|
||||
final BlockWrapper b1 = wrapBlock(block1);
|
||||
final BlockWrapper b2 = wrapBlock(block2);
|
||||
|
||||
if ((b1.id != b2.id) || (b1.data != b2.data)) {
|
||||
PlotHelper.setBlock(world, b1.x, b1.y, b1.z, b2.id, b2.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static BlockWrapper wrapBlock(final Block block) {
|
||||
return new BlockWrapper(block.getX(), block.getY(), block.getZ(), (short) block.getTypeId(), block.getData());
|
||||
}
|
||||
|
||||
public PlotBlock[] getBlocks() {
|
||||
return this.plotBlocks;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
public void paste(final World world, final Plot plot) {
|
||||
|
||||
final Location bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()), top = PlotHelper.getPlotTopLocAbs(world, plot.getId());
|
||||
final int minX = bot.getBlockX(), maxX = top.getBlockX(), minZ = bot.getBlockZ(), maxZ = top.getBlockZ(), minY = 1, maxY = world.getMaxHeight();
|
||||
|
||||
if (this.biome != world.getBiome(minX, minZ)) {
|
||||
PlotHelper.setBiome(world, plot, this.biome);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
PlotBlock current;
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
current = this.plotBlocks[index++];
|
||||
world.getBlockAt(x + 1, y, z + 1).setTypeIdAndData(current.id, current.data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import org.bukkit.block.Biome;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
/**
|
||||
* plot settings
|
||||
@ -106,7 +107,8 @@ import com.intellectualcrafters.plot.util.PlotHelper;
|
||||
* @return biome at plot loc
|
||||
*/
|
||||
public Biome getBiome() {
|
||||
return PlotHelper.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1).getBlock().getBiome();
|
||||
Location loc = PlotHelper.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1);
|
||||
return BukkitUtil.getBiome(loc);
|
||||
}
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
|
||||
public abstract class AChunkManager {
|
||||
|
||||
public static AChunkManager manager = null;
|
||||
public static RegionWrapper CURRENT_PLOT_CLEAR = null;
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Short>> GENERATE_BLOCKS = new HashMap<>();
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Byte>> GENERATE_DATA = new HashMap<>();
|
||||
|
||||
public static ChunkLoc getChunkChunk(Location loc) {
|
||||
int x = loc.getX() >> 9;
|
||||
int z = loc.getZ() >> 9;
|
||||
return new ChunkLoc(x, z);
|
||||
}
|
||||
|
||||
public abstract List<ChunkLoc> getChunkChunks(String world);
|
||||
|
||||
public abstract void deleteRegionFile(final String world, final ChunkLoc loc);
|
||||
|
||||
public abstract Plot hasPlot(String world, ChunkLoc chunk);
|
||||
|
||||
public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone);
|
||||
|
||||
public abstract boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone);
|
||||
}
|
@ -39,6 +39,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.intellectualcrafters.plot.BukkitMain;
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
@ -49,22 +50,13 @@ import com.intellectualcrafters.plot.object.entity.EntityWrapper;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
public class ChunkManager {
|
||||
public class ChunkManager extends AChunkManager {
|
||||
|
||||
public static RegionWrapper CURRENT_PLOT_CLEAR = null;
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Short>> GENERATE_BLOCKS = new HashMap<>();
|
||||
public static HashMap<ChunkLoc, HashMap<Short, Byte>> GENERATE_DATA = new HashMap<>();
|
||||
public static MutableInt index = new MutableInt(0);
|
||||
public static HashMap<Integer, Integer> tasks = new HashMap<>();
|
||||
|
||||
public static ChunkLoc getChunkChunk(Location loc) {
|
||||
int x = loc.getX() >> 9;
|
||||
int z = loc.getZ() >> 9;
|
||||
return new ChunkLoc(x, z);
|
||||
}
|
||||
|
||||
public static ArrayList<ChunkLoc> getChunkChunks(World world) {
|
||||
String directory = new File(".").getAbsolutePath() + File.separator + world.getName() + File.separator + "region";
|
||||
public ArrayList<ChunkLoc> getChunkChunks(String world) {
|
||||
String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region";
|
||||
|
||||
File folder = new File(directory);
|
||||
File[] regionFiles = folder.listFiles();
|
||||
@ -84,8 +76,7 @@ public class ChunkManager {
|
||||
catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
||||
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
if (!chunks.contains(loc)) {
|
||||
chunks.add(loc);
|
||||
@ -95,7 +86,7 @@ public class ChunkManager {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public static void deleteRegionFile(final String world, final ChunkLoc loc) {
|
||||
public void deleteRegionFile(final String world, final ChunkLoc loc) {
|
||||
BukkitTaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -109,9 +100,9 @@ public class ChunkManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static Plot hasPlot(World world, Chunk chunk) {
|
||||
int x1 = chunk.getX() << 4;
|
||||
int z1 = chunk.getZ() << 4;
|
||||
public Plot hasPlot(String world, ChunkLoc chunk) {
|
||||
int x1 = chunk.x << 4;
|
||||
int z1 = chunk.z << 4;
|
||||
int x2 = x1 + 15;
|
||||
int z2 = z1 + 15;
|
||||
|
||||
@ -152,18 +143,18 @@ public class ChunkManager {
|
||||
/**
|
||||
* Copy a region to a new location (in the same world)
|
||||
*/
|
||||
public static boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
index.increment();
|
||||
final int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
|
||||
final World world = pos1.getWorld();
|
||||
Chunk c1 = world.getChunkAt(pos1);
|
||||
Chunk c2 = world.getChunkAt(pos2);
|
||||
|
||||
Chunk c3 = world.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4);
|
||||
Chunk c4 = world.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4);
|
||||
final World world = Bukkit.getWorld(pos1.getWorld());
|
||||
Chunk c1 = world.getChunkAt(pos1.getX(), pos1.getZ());
|
||||
Chunk c2 = world.getChunkAt(pos2.getX(), pos2.getZ());
|
||||
|
||||
Chunk c3 = world.getChunkAt((pos1.getX() + relX), (pos1.getZ() + relZ));
|
||||
Chunk c4 = world.getChunkAt((pos2.getX() + relX), (pos2.getZ() + relZ));
|
||||
|
||||
final int sx = pos1.getX();
|
||||
final int sz = pos1.getZ();
|
||||
@ -185,12 +176,12 @@ public class ChunkManager {
|
||||
// Load chunks
|
||||
for (int x = c1x; x <= c2x; x ++) {
|
||||
for (int z = c1z; z <= c2z; z ++) {
|
||||
Chunk chunk = world.getChunkAt(x, z);
|
||||
Chunk chunk = world.getChunkAt(x << 4, z << 4);
|
||||
toGenerate.add(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
final Plugin plugin = (Plugin) PlotSquared.getMain();
|
||||
final Plugin plugin = (Plugin) BukkitMain.THIS;
|
||||
final Integer currentIndex = index.toInteger();
|
||||
final int loadTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
@ -268,13 +259,13 @@ public class ChunkManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) {
|
||||
index.increment();
|
||||
final Plugin plugin = (Plugin) PlotSquared.getMain();
|
||||
final Plugin plugin = (Plugin) BukkitMain.THIS;
|
||||
|
||||
final World world = pos1.getWorld();
|
||||
Chunk c1 = world.getChunkAt(pos1);
|
||||
Chunk c2 = world.getChunkAt(pos2);
|
||||
final World world = Bukkit.getWorld(pos1.getWorld());
|
||||
Chunk c1 = world.getChunkAt(pos1.getX(), pos1.getZ());
|
||||
Chunk c2 = world.getChunkAt(pos2.getX(), pos2.getZ());
|
||||
|
||||
final int sx = pos1.getX();
|
||||
final int sz = pos1.getZ();
|
||||
@ -396,7 +387,7 @@ public class ChunkManager {
|
||||
|
||||
public static void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
Location loc = entity.getLocation();
|
||||
Location loc = BukkitUtil.getLocation(entity);
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
if (isIn(region, x, z)) {
|
||||
|
@ -10,7 +10,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.BukkitMain;
|
||||
|
@ -520,7 +520,7 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
runners.put(plot, 1);
|
||||
if (plotworld.TERRAIN != 0) {
|
||||
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
|
||||
ChunkManager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (player != null && player.isOnline()) {
|
||||
@ -883,11 +883,11 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
plot.id.y += offset_y;
|
||||
PlotSquared.getPlots(world).put(plot.id, plot);
|
||||
}
|
||||
ChunkManager.copyRegion(bot1, top, bot2, new Runnable() {
|
||||
AChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Location bot = bot1.clone().add(1, 0, 1);
|
||||
ChunkManager.regenerateRegion(bot, top, null);
|
||||
AChunkManager.manager.regenerateRegion(bot, top, null);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
}
|
||||
});
|
||||
|
@ -27,6 +27,10 @@ public class BukkitUtil extends BlockManager {
|
||||
private static String lastString = null;
|
||||
private static World lastWorld = null;
|
||||
|
||||
public static Biome getBiome(Location loc) {
|
||||
return getWorld(loc.getWorld()).getBiome(loc.getX(), loc.getZ());
|
||||
}
|
||||
|
||||
public static World getWorld(String string) {
|
||||
if (lastString == string) {
|
||||
return lastWorld;
|
||||
|
Loading…
Reference in New Issue
Block a user