mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 10:44:42 +02:00
Trying to reduce reliance on Bukkit
This commit is contained in:
@ -12,65 +12,189 @@ import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IPlotMain {
|
||||
|
||||
/**
|
||||
* Log a message to console
|
||||
* @param message
|
||||
*/
|
||||
void log(String message);
|
||||
|
||||
/**
|
||||
* Get the `PlotSquared` directory (e.g. /plugins/PlotSquared or /mods/PlotSquared)
|
||||
* @return
|
||||
*/
|
||||
File getDirectory();
|
||||
|
||||
/**
|
||||
* Disable the implementation
|
||||
* - If a full disable isn't feasibly, just disable what it can
|
||||
*/
|
||||
void disable();
|
||||
|
||||
/**
|
||||
* Get the version of the PlotSquared being used
|
||||
* @return
|
||||
*/
|
||||
int[] getPluginVersion();
|
||||
|
||||
/**
|
||||
* Get the version of Minecraft that is running
|
||||
* (used to check what protocols and such are supported)
|
||||
* @return
|
||||
*/
|
||||
int[] getServerVersion();
|
||||
|
||||
void handleKick(UUID uuid, C c);
|
||||
|
||||
/**
|
||||
* The task manager will run and manage minecraft tasks
|
||||
* @return
|
||||
*/
|
||||
TaskManager getTaskManager();
|
||||
|
||||
/**
|
||||
* Run the task that will kill road mobs
|
||||
*/
|
||||
void runEntityTask();
|
||||
|
||||
/**
|
||||
* Register the implementation specific commands
|
||||
*/
|
||||
void registerCommands();
|
||||
|
||||
/**
|
||||
* Register the protection system (used to protect blocks and such)
|
||||
*/
|
||||
void registerPlayerEvents();
|
||||
|
||||
/**
|
||||
* Register inventory related events (used for inventory guis)
|
||||
*/
|
||||
void registerInventoryEvents();
|
||||
|
||||
/**
|
||||
* Register plot plus related events (whatever these are?)
|
||||
*/
|
||||
void registerPlotPlusEvents();
|
||||
|
||||
/**
|
||||
* Register force field events (why is this a thing?)
|
||||
*/
|
||||
void registerForceFieldEvents();
|
||||
|
||||
/**
|
||||
* Register the WorldEdit hook
|
||||
*/
|
||||
void registerWorldEditEvents();
|
||||
|
||||
/**
|
||||
* Register TNT related events (if TNT protection is enabled)
|
||||
*/
|
||||
void registerTNTListener();
|
||||
|
||||
/**
|
||||
* Get the economy provider
|
||||
* @return
|
||||
*/
|
||||
EconHandler getEconomyHandler();
|
||||
|
||||
/**
|
||||
* Get the block manager
|
||||
* @return
|
||||
*/
|
||||
BlockManager initBlockManager();
|
||||
|
||||
/**
|
||||
* Get the EventUtil class
|
||||
* @return
|
||||
*/
|
||||
EventUtil initEventUtil();
|
||||
|
||||
/**
|
||||
* Get the chunk manager
|
||||
* @return
|
||||
*/
|
||||
ChunkManager initChunkManager();
|
||||
|
||||
/**
|
||||
* Get the setuputils class (used for world creation)
|
||||
* @return
|
||||
*/
|
||||
SetupUtils initSetupUtils();
|
||||
|
||||
/**
|
||||
* Get HybridUtils class (common functions useful for hybrid world generation)
|
||||
* @return
|
||||
*/
|
||||
HybridUtils initHybridUtils();
|
||||
|
||||
/**
|
||||
* Start the metrics task
|
||||
*/
|
||||
void startMetrics();
|
||||
|
||||
/**
|
||||
* If a world is already loaded, set the generator (use NMS if required)
|
||||
* @param world
|
||||
*/
|
||||
void setGenerator(String world);
|
||||
|
||||
/**
|
||||
* Get the UUIDHandlerImplementation which will cache and provide UUIDs
|
||||
* @return
|
||||
*/
|
||||
UUIDHandlerImplementation initUUIDHandler();
|
||||
|
||||
/**
|
||||
* Get the InventoryUtil class (used for implementation specific inventory guis)
|
||||
* @return
|
||||
*/
|
||||
InventoryUtil initInventoryUtil();
|
||||
|
||||
/**
|
||||
* Run the converter for the implementation (not necessarily PlotMe, just any plugin that we can convert from)
|
||||
* @return
|
||||
*/
|
||||
boolean initPlotMeConverter();
|
||||
|
||||
/**
|
||||
* Unregister a PlotPlayer from cache e.g. if they have logged off
|
||||
* @param player
|
||||
*/
|
||||
void unregister(PlotPlayer player);
|
||||
|
||||
/**
|
||||
* Get the generator wrapper for a world (world) and generator (name)
|
||||
* @param world
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
PlotGenerator<?> getGenerator(String world, String name);
|
||||
|
||||
/**
|
||||
* Get the PlotListener class for this implementation
|
||||
* (We should try to make this generic so we don't need this)
|
||||
* @return
|
||||
*/
|
||||
APlotListener initPlotListener();
|
||||
|
||||
/**
|
||||
* Register the chunk processor which will clean out chunks that have too many blockstates or entities
|
||||
*/
|
||||
void registerChunkProcessor();
|
||||
|
||||
/**
|
||||
* Register the world initialization events (used to keep track of worlds being generated)
|
||||
*/
|
||||
void registerWorldEvents();
|
||||
|
||||
/**
|
||||
* This class is currently really empty, but player related stuff can go in here
|
||||
* @return
|
||||
*/
|
||||
PlayerManager initPlayerManager();
|
||||
|
||||
/**
|
||||
* Get the name of the server
|
||||
* @return
|
||||
*/
|
||||
String getServerName();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
@ -114,6 +115,12 @@ public class PS {
|
||||
IMP.registerForceFieldEvents();
|
||||
IMP.registerWorldEditEvents();
|
||||
IMP.registerWorldEvents();
|
||||
if (Settings.METRICS) {
|
||||
IMP.startMetrics();
|
||||
} else {
|
||||
log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
|
||||
}
|
||||
IMP.startMetrics();
|
||||
if (Settings.TNT_LISTENER) {
|
||||
IMP.registerTNTListener();
|
||||
}
|
||||
@ -122,6 +129,7 @@ public class PS {
|
||||
}
|
||||
// create UUIDWrapper
|
||||
UUIDHandler.implementation = IMP.initUUIDHandler();
|
||||
UUIDHandler.implementation.startCaching(null); // TODO maybe a notification when this is done?
|
||||
// create event util class
|
||||
EventUtil.manager = IMP.initEventUtil();
|
||||
// create Hybrid utility class
|
||||
@ -171,9 +179,21 @@ public class PS {
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
// Auto clearing
|
||||
if (Settings.AUTO_CLEAR) {
|
||||
ExpireManager.runTask();
|
||||
}
|
||||
|
||||
// World generators:
|
||||
ConfigurationSection section = config.getConfigurationSection("worlds");
|
||||
if (section != null) {
|
||||
for (String world : section.getKeys(false)) {
|
||||
if (BlockManager.manager.isWorld(world)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy files
|
||||
copyFile("town.template", "templates");
|
||||
|
@ -89,7 +89,7 @@ public class DebugClaimTest extends SubCommand {
|
||||
}
|
||||
final Location loc = manager.getSignLoc(plotworld, plot);
|
||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
|
||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
|
||||
if (!result) {
|
||||
continue;
|
||||
}
|
||||
|
@ -23,11 +23,12 @@ package com.intellectualcrafters.plot.commands;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -153,7 +154,7 @@ public class DebugExec extends SubCommand {
|
||||
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
|
||||
BukkitHybridUtils.chunks.remove(0);
|
||||
HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
|
||||
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
|
||||
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk, true, true);
|
||||
}
|
||||
PS.log("&cCancelled!");
|
||||
return true;
|
||||
|
@ -28,11 +28,15 @@ import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.object.InfoInventory;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -129,7 +133,22 @@ public class Info extends SubCommand {
|
||||
}
|
||||
}
|
||||
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||
new InfoInventory(plot, player).build().display();
|
||||
PlotInventory inv = new PlotInventory(player) {
|
||||
@Override
|
||||
public boolean onClick(int index) {
|
||||
// TODO InfoInventory not implemented yet!!!!!!!!
|
||||
// See plot rating or musicsubcommand on examples
|
||||
return false;
|
||||
}
|
||||
};
|
||||
UUID uuid = player.getUUID();
|
||||
String name = MainUtil.getName(plot.owner);
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] { "&cID: &6" + plot.getId().toString(), "&cOwner: &6" + name, "&cAlias: &6" + plot.getSettings().getAlias(), "&cBiome: &6" + plot.getSettings().getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + plot.isAdded(uuid), "&cIs Denied: &6" + plot.isDenied(uuid)}));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] {"&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users"}));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] {"&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members"}));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] {"&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players"}));
|
||||
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] {"&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags"}));
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
final boolean hasOwner = plot.hasOwner();
|
||||
@ -194,7 +213,7 @@ public class Info extends SubCommand {
|
||||
final String alias = plot.getSettings().getAlias().length() > 0 ? plot.getSettings().getAlias() : C.NONE.s();
|
||||
Location top = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||
final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2));
|
||||
final String biome = BlockManager.manager.getBiome(plot.world, bot.getX() + ((top.getX() - bot.getX()) / 2), bot.getZ() + ((top.getZ() - bot.getZ()) / 2));
|
||||
final String trusted = getPlayerList(plot.getTrusted());
|
||||
final String members = getPlayerList(plot.getMembers());
|
||||
final String denied = getPlayerList(plot.getDenied());
|
||||
|
@ -1,480 +0,0 @@
|
||||
package com.intellectualcrafters.plot.generator;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.plotsquared.bukkit.generator.AugmentedPopulator;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.material.Directional;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BukkitHybridUtils extends HybridUtils {
|
||||
|
||||
public static List<ChunkLoc> regions;
|
||||
public static List<ChunkLoc> chunks = new ArrayList<>();
|
||||
public static String world;
|
||||
private static boolean UPDATE = false;
|
||||
public int task;
|
||||
private long last;
|
||||
|
||||
@Override
|
||||
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
// int diff, int variety, int verticies, int rotation, int height_sd
|
||||
|
||||
/*
|
||||
* diff: compare to base by looping through all blocks
|
||||
* variety: add to hashset for each plotblock
|
||||
* height_sd: loop over all blocks and get top block
|
||||
*
|
||||
* verticies: store air map and compare with neighbours
|
||||
* for each block check the adjacent
|
||||
* - Store all blocks then go through in second loop
|
||||
* - recheck each block
|
||||
*
|
||||
*/
|
||||
final World world = Bukkit.getWorld(plot.world);
|
||||
final ChunkGenerator gen = world.getGenerator();
|
||||
if (gen == null) {
|
||||
return;
|
||||
}
|
||||
final BiomeGrid base = new BiomeGrid() { @Override public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) {return null;}};
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
final int bx = bot.getX();
|
||||
final int bz = bot.getZ();
|
||||
final int tx = top.getX();
|
||||
final int tz = top.getZ();
|
||||
final int cbx = bx >> 4;
|
||||
final int cbz = bz >> 4;
|
||||
final int ctx = tx >> 4;
|
||||
final int ctz = tz >> 4;
|
||||
final Random r = new Random();
|
||||
AugmentedPopulator.initCache();
|
||||
final int width = tx - bx + 1;
|
||||
final int length = tz - bz + 1;
|
||||
|
||||
System.gc();
|
||||
System.gc();
|
||||
final short[][][] oldblocks = new short[256][width][length];
|
||||
final short[][][] newblocks = new short[256][width][length];
|
||||
|
||||
final List<ChunkLoc> chunks = new ArrayList<>();
|
||||
final List<ChunkLoc> processed_chunks = new ArrayList<>();
|
||||
|
||||
for (int X = cbx; X <= ctx; X++) {
|
||||
for (int Z = cbz; Z <= ctz; Z++) {
|
||||
// Chunk chunk = world.getChunkAt(X, Z);
|
||||
chunks.add(new ChunkLoc(X, Z));
|
||||
}
|
||||
}
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (ChunkLoc chunk : processed_chunks) {
|
||||
short[][] result = gen.generateExtBlockSections(world, r, chunk.x, chunk.z, base);
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
int xb = ((X) << 4) - bx;
|
||||
int zb = ((Z) << 4) - bz;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
if (result[i] == null) {
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < result[i].length; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = result[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
int size = width * length;
|
||||
int[] changes = new int[size];
|
||||
int[] faces = new int[size];
|
||||
int[] data = new int[size];
|
||||
int[] air = new int[size];
|
||||
int[] variety = new int[size];
|
||||
|
||||
int i = 0;
|
||||
for (int x = 0; x < width;x++) {
|
||||
for (int z = 0; z < length;z++) {
|
||||
HashSet<Short> types = new HashSet<>();
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short old = oldblocks[y][x][z];
|
||||
short now = newblocks[y][x][z];
|
||||
if (old != now) {
|
||||
changes[i]++;
|
||||
}
|
||||
if (now == 0) {
|
||||
air[i]++;
|
||||
}
|
||||
else {
|
||||
// check verticies
|
||||
// modifications_adjacent
|
||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
||||
if (newblocks[y - 1][x][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x - 1][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x][z - 1] == 0) faces[i]++;
|
||||
if (newblocks[y + 1][x][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x + 1][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x][z + 1] == 0) faces[i]++;
|
||||
}
|
||||
|
||||
Material material = Material.getMaterial(now);
|
||||
Class<? extends MaterialData> md = material.getData();
|
||||
if (md.equals(Directional.class)) {
|
||||
data[i] += 8;
|
||||
}
|
||||
else if (!md.equals(MaterialData.class)) {
|
||||
data[i]++;
|
||||
}
|
||||
types.add(now);
|
||||
}
|
||||
}
|
||||
variety[i] = types.size();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// analyze plot
|
||||
// put in analysis obj
|
||||
|
||||
// run whenDone
|
||||
PlotAnalysis analysis = new PlotAnalysis();
|
||||
analysis.changes = (int) (MathMan.getMean(changes) * 100);
|
||||
analysis.faces = (int) (MathMan.getMean(faces) * 100);
|
||||
analysis.data = (int) (MathMan.getMean(data) * 100);
|
||||
analysis.air = (int) (MathMan.getMean(air) * 100);
|
||||
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
||||
|
||||
analysis.changes_sd = (int) (MathMan.getSD(changes, analysis.changes));
|
||||
analysis.faces_sd = (int) (MathMan.getSD(faces, analysis.faces));
|
||||
analysis.data_sd = (int) (MathMan.getSD(data, analysis.data));
|
||||
analysis.air_sd = (int) (MathMan.getSD(air, analysis.air));
|
||||
analysis.variety_sd = (int) (MathMan.getSD(variety, analysis.variety));
|
||||
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(analysis.changes);
|
||||
result.add(analysis.faces);
|
||||
result.add(analysis.data);
|
||||
result.add(analysis.air);
|
||||
result.add(analysis.variety);
|
||||
|
||||
result.add(analysis.changes_sd);
|
||||
result.add(analysis.faces_sd);
|
||||
result.add(analysis.data_sd);
|
||||
result.add(analysis.air_sd);
|
||||
result.add(analysis.variety_sd);
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
System.gc();
|
||||
System.gc();
|
||||
whenDone.value = analysis;
|
||||
whenDone.run();
|
||||
}
|
||||
};
|
||||
System.gc();
|
||||
AugmentedPopulator.initCache();
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = chunks.size() - 1;
|
||||
if (index == -1) {
|
||||
PS.get().TASK.cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.runTaskAsync(run);
|
||||
return;
|
||||
}
|
||||
ChunkLoc chunk = chunks.remove(0);
|
||||
world.loadChunk(chunk.x, chunk.z);
|
||||
processed_chunks.add(chunk);
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
int minX;
|
||||
int minZ;
|
||||
int maxX;
|
||||
int maxZ;
|
||||
if (X == cbx) minX = bx & 0x0f;
|
||||
else minX = 0;
|
||||
if (Z == cbz) minZ = bz & 0x0f;
|
||||
else minZ = 0;
|
||||
if (X == ctx) maxX = tx & 0x0f;
|
||||
else maxX = 16;
|
||||
if (Z == ctz) maxZ = tz & 0x0f;
|
||||
else maxZ = 16;
|
||||
|
||||
int cbx = X << 4;
|
||||
int cbz = Z << 4;
|
||||
|
||||
int xb = (cbx) - bx;
|
||||
int zb = (cbz) - bz;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int xx = cbx + cbz;
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int zz = cbz + z;
|
||||
for (int y = 0; y < 256; y++) {
|
||||
Block block = world.getBlockAt(xx, y, zz);
|
||||
int xr = xb + x;
|
||||
int zr = zb + z;
|
||||
newblocks[y][xr][zr] = (short) block.getTypeId();
|
||||
}
|
||||
}
|
||||
}
|
||||
world.unloadChunkRequest(chunk.x, chunk.z, true);
|
||||
}
|
||||
}, 1);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
}
|
||||
|
||||
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
int bx = bot.getX() >> 4;
|
||||
int bz = bot.getZ() >> 4;
|
||||
int tx = top.getX() >> 4;
|
||||
int tz = top.getZ() >> 4;
|
||||
World world = BukkitUtil.getWorld(plot.world);
|
||||
final HashSet<Chunk> chunks = new HashSet<>();
|
||||
for (int X = bx; X <= tx; X++) {
|
||||
for (int Z = bz; Z <= tz; Z++) {
|
||||
chunks.add(world.getChunkAt(X,Z));
|
||||
}
|
||||
}
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
if (!(plotworld instanceof ClassicPlotWorld)) {
|
||||
whenDone.value = -1;
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
|
||||
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (chunks.size() == 0) {
|
||||
whenDone.value = count.intValue();
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
return;
|
||||
}
|
||||
Iterator<Chunk> iter = chunks.iterator();
|
||||
final Chunk chunk = iter.next();
|
||||
iter.remove();
|
||||
int bx = Math.max(chunk.getX() << 4, bot.getX());
|
||||
int bz = Math.max(chunk.getZ() << 4, bot.getZ());
|
||||
int ex = Math.min((chunk.getX() << 4) + 15, top.getX());
|
||||
int ez = Math.min((chunk.getZ() << 4) + 15, top.getZ());
|
||||
// count changes
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK));
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK));
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }));
|
||||
}
|
||||
}, 1);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
int count = 0;
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
final int id = block.getTypeId();
|
||||
boolean same = false;
|
||||
for (final PlotBlock p : blocks) {
|
||||
if (id == p.id) {
|
||||
same = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!same) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
final int maxY = world.getMaxHeight();
|
||||
int ey = sy;
|
||||
for (int x = sx; x <= ex; x++) {
|
||||
for (int z = sz; z <= ez; z++) {
|
||||
for (int y = sy; y < maxY; y++) {
|
||||
if (y > ey) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
if (block.getTypeId() != 0) {
|
||||
ey = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ey;
|
||||
}
|
||||
|
||||
public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
final int sx = loc.x << 5;
|
||||
final int sz = loc.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
final Chunk chunk = world.getChunkAt(x, z);
|
||||
chunk.load(false);
|
||||
}
|
||||
}
|
||||
final ArrayList<Chunk> chunks2 = new ArrayList<>();
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
final Chunk chunk = world.getChunkAt(x, z);
|
||||
chunks2.add(chunk);
|
||||
regenerateRoad(worldname, new ChunkLoc(x, z), 0);
|
||||
MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final ArrayList<ChunkLoc> getChunks(ChunkLoc region) {
|
||||
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
final int sx = region.x << 5;
|
||||
final int sz = region.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
chunks.add(new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scheduleRoadUpdate(final String world, int extend) {
|
||||
if (BukkitHybridUtils.UPDATE) {
|
||||
return false;
|
||||
}
|
||||
BukkitHybridUtils.UPDATE = true;
|
||||
final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
|
||||
return scheduleRoadUpdate(world, regions, extend);
|
||||
}
|
||||
|
||||
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
|
||||
BukkitHybridUtils.regions = rgs;
|
||||
BukkitHybridUtils.world = world;
|
||||
chunks = new ArrayList<ChunkLoc>();
|
||||
final Plugin plugin = BukkitMain.THIS;
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
count.incrementAndGet();
|
||||
if (count.intValue() % 20 == 0) {
|
||||
PS.log("PROGRESS: " + ((100 * (2048 - chunks.size())) / 2048) + "%");
|
||||
}
|
||||
if (regions.size() == 0 && chunks.size() == 0) {
|
||||
BukkitHybridUtils.UPDATE = false;
|
||||
PS.log(C.PREFIX.s() + "Finished road conversion");
|
||||
Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
if (chunks.size() < 1024) {
|
||||
if (regions.size() > 0) {
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.log("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
|
||||
PS.log(" - Remaining: " + regions.size());
|
||||
chunks.addAll(getChunks(loc));
|
||||
regions.remove(0);
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
if (chunks.size() > 0) {
|
||||
long diff = System.currentTimeMillis() + 25;
|
||||
if (System.currentTimeMillis() - last > 1200 && last != 0) {
|
||||
last = 0;
|
||||
PS.log(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s");
|
||||
while (chunks.size() > 0) {
|
||||
ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
regenerateRoad(world, chunk, extend);
|
||||
ChunkManager.manager.unloadChunk(world, chunk);
|
||||
}
|
||||
Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scheduleRoadUpdate(world, regions, extend);
|
||||
}
|
||||
}, 600);
|
||||
return;
|
||||
}
|
||||
if (System.currentTimeMillis() - last < 1000) {
|
||||
while (System.currentTimeMillis() < diff && chunks.size() > 0) {
|
||||
ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
regenerateRoad(world, chunk, extend);
|
||||
ChunkManager.manager.unloadChunk(world, chunk);
|
||||
}
|
||||
}
|
||||
last = System.currentTimeMillis();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
|
||||
final int sx = loc.x << 5;
|
||||
final int sz = loc.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
PS.log("&d - Potentially skipping 1024 chunks");
|
||||
PS.log("&d - TODO: recommend chunkster if corrupt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20, 20);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -23,10 +23,10 @@ package com.intellectualcrafters.plot.generator;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.Template;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -181,14 +181,14 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
public void run() {
|
||||
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
|
||||
if (canRegen && value[6] == 0) {
|
||||
BukkitUtil.regenerateChunk(world, value[0], value[1]);
|
||||
ChunkManager.manager.regenerateChunk(world, new ChunkLoc(value[0], value[1]));
|
||||
return;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Set the biome
|
||||
BukkitUtil.setBiome(plot.world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME);
|
||||
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME);
|
||||
// These two locations are for each component (e.g. bedrock, main block, floor, air)
|
||||
Location bot = new Location(world, value[2], 0, value[3]);
|
||||
Location top = new Location(world, value[4] + 1, 1, value[5] + 1);
|
||||
|
@ -7,7 +7,7 @@ import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.plotsquared.bukkit.object.PlotPopulator;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@ -17,7 +17,7 @@ import java.util.HashSet;
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class HybridPop extends PlotPopulator {
|
||||
public class HybridPop extends BukkitPlotPopulator {
|
||||
/*
|
||||
* Sorry, this isn't well documented at the moment.
|
||||
* We advise you to take a look at a world generation tutorial for
|
||||
|
@ -89,7 +89,7 @@ public abstract class HybridUtils {
|
||||
final PlotId id1 = manager.getPlotId(plotworld, x, 0, z);
|
||||
final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez);
|
||||
if ((id1 == null) || (id2 == null) || (id1 != id2)) {
|
||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk);
|
||||
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
|
||||
if (result) {
|
||||
if (id1 != null) {
|
||||
final Plot p1 = MainUtil.getPlot(world, id1);
|
||||
|
@ -186,25 +186,12 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
||||
* Set a plot biome
|
||||
*/
|
||||
@Override
|
||||
public boolean setBiome(final Plot plot, final int biome) {
|
||||
public boolean setBiome(final Plot plot, final String biome) {
|
||||
final int bottomX = MainUtil.getPlotBottomLoc(plot.world, plot.id).getX() - 1;
|
||||
final int topX = MainUtil.getPlotTopLoc(plot.world, plot.id).getX() + 1;
|
||||
final int topX = MainUtil.getPlotTopLoc(plot.world, plot.id).getX();
|
||||
final int bottomZ = MainUtil.getPlotBottomLoc(plot.world, plot.id).getZ() - 1;
|
||||
final int topZ = MainUtil.getPlotTopLoc(plot.world, plot.id).getZ() + 1;
|
||||
final int size = ((topX - bottomX) + 1) * ((topZ - bottomZ) + 1);
|
||||
final int[] xb = new int[size];
|
||||
final int[] zb = new int[size];
|
||||
final int[] biomes = new int[size];
|
||||
int index = 0;
|
||||
for (int x = bottomX; x <= topX; x++) {
|
||||
for (int z = bottomZ; z <= topZ; z++) {
|
||||
xb[index] = x;
|
||||
zb[index] = z;
|
||||
biomes[index] = biome;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
BlockManager.setBiomes(plot.world, xb, zb, biomes);
|
||||
final int topZ = MainUtil.getPlotTopLoc(plot.world, plot.id).getZ();
|
||||
MainUtil.setBiome(plot.world, bottomX, bottomZ, topX, topZ, biome);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Wrapper class for blocks, using pure data rather than the object.
|
||||
*
|
||||
* Useful for NMS
|
||||
*
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class BlockWrapper {
|
||||
/**
|
||||
* X Coordinate
|
||||
*/
|
||||
public final int x;
|
||||
/**
|
||||
* Y Coordinate
|
||||
*/
|
||||
public final int y;
|
||||
/**
|
||||
* Z Coordinate
|
||||
*/
|
||||
public final int z;
|
||||
/**
|
||||
* Block ID
|
||||
*/
|
||||
public final int id;
|
||||
/**
|
||||
* Block Data Value
|
||||
*/
|
||||
public final byte data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param x X Loc Value
|
||||
* @param y Y Loc Value
|
||||
* @param z Z Loc Value
|
||||
* @param id Material ID
|
||||
* @param data Data Value
|
||||
*/
|
||||
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
|
@ -7,7 +7,7 @@ public class PlotItemStack {
|
||||
public final String name;
|
||||
public final String[] lore;
|
||||
|
||||
public PlotItemStack(int id, short data, int amount, String name, String[] lore) {
|
||||
public PlotItemStack(int id, short data, int amount, String name, String... lore) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
this.amount = amount;
|
||||
|
@ -61,7 +61,7 @@ public abstract class PlotManager {
|
||||
|
||||
public abstract boolean setComponent(final PlotWorld plotworld, final PlotId plotid, final String component, final PlotBlock[] blocks);
|
||||
|
||||
public abstract boolean setBiome(final Plot plot, final int biome);
|
||||
public abstract boolean setBiome(final Plot plot, final String biome);
|
||||
|
||||
/*
|
||||
* PLOT MERGING (return false if your generator does not support plot
|
||||
|
@ -116,7 +116,7 @@ public class PlotSettings {
|
||||
*/
|
||||
public String getBiome() {
|
||||
final Location loc = MainUtil.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1);
|
||||
return BlockManager.manager.getBiome(loc);
|
||||
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
|
||||
}
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
|
@ -21,9 +21,11 @@ public abstract class BlockManager {
|
||||
|
||||
public abstract int getBlockIdFromString(String block);
|
||||
|
||||
public abstract int getHeighestBlock(Location loc);
|
||||
public abstract int getHeighestBlock(String world, int x, int z);
|
||||
|
||||
public abstract String getBiome(Location loc);
|
||||
public abstract String getBiome(String world, int x, int z);
|
||||
|
||||
public abstract PlotBlock getBlock(Location loc);
|
||||
|
||||
public abstract Location getSpawn(String world);
|
||||
|
||||
@ -37,9 +39,9 @@ public abstract class BlockManager {
|
||||
|
||||
public abstract void functionSetBlock(String worldname, int x, int y, int z, int id, byte data);
|
||||
|
||||
public abstract void functionSetBiomes(final String worldname, final int[] x, final int z[], final int[] biome);
|
||||
public abstract void functionSetBiomes(final String worldname, final int[] x, final int z[], final String biome);
|
||||
|
||||
public static void setBiomes(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 String biome) {
|
||||
manager.functionSetBiomes(worldname, x, z, biome);
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,9 @@ public abstract class ChunkManager {
|
||||
|
||||
public abstract int[] countEntities(Plot plot);
|
||||
|
||||
public abstract boolean loadChunk(String world, ChunkLoc loc);
|
||||
public abstract boolean loadChunk(String world, ChunkLoc loc, boolean force);
|
||||
|
||||
public abstract boolean unloadChunk(String world, ChunkLoc loc);
|
||||
public abstract boolean unloadChunk(String world, ChunkLoc loc, boolean save, boolean safe);
|
||||
|
||||
public abstract List<ChunkLoc> getChunkChunks(String world);
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class ClusterManager {
|
||||
} else {
|
||||
toReturn = getClusterBottom(cluster).add(home.x, home.y, home.z);
|
||||
}
|
||||
final int max = BukkitUtil.getHeighestBlock(cluster.world, toReturn.getX(), toReturn.getZ());
|
||||
final int max = MainUtil.getHeighestBlock(cluster.world, toReturn.getX(), toReturn.getZ());
|
||||
if (max > toReturn.getY()) {
|
||||
toReturn.setY(max);
|
||||
}
|
||||
|
@ -54,6 +54,17 @@ public class MainUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getName(UUID owner) {
|
||||
if (owner == null) {
|
||||
return "unowned";
|
||||
}
|
||||
String name = UUIDHandler.getName(owner);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static List<PlotPlayer> getPlayersInPlot(Plot plot) {
|
||||
ArrayList<PlotPlayer> players = new ArrayList<>();
|
||||
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
|
||||
@ -1032,9 +1043,10 @@ public class MainUtil {
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override
|
||||
public void run() {
|
||||
BukkitUtil.loadChunkAt(plot.world, value[0], value[1], false);
|
||||
BukkitUtil.setBiome(plot.world, value[2], value[3], value[4], value[4], biome);
|
||||
BukkitUtil.unloadChunkAt(plot.world, value[0], value[1], true, true);
|
||||
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
|
||||
ChunkManager.manager.loadChunk(plot.world, loc, false);
|
||||
setBiome(plot.world, value[2], value[3], value[4], value[4], biome);
|
||||
ChunkManager.manager.unloadChunk(plot.world, loc, true, true);
|
||||
}
|
||||
}, new Runnable() {
|
||||
@Override
|
||||
@ -1045,8 +1057,23 @@ public class MainUtil {
|
||||
}, 5);
|
||||
}
|
||||
|
||||
public static void setBiome(final String world, int p1x, int p1z, int p2x, int p2z, final String biome) {
|
||||
final int length = (p2x - p1x + 1) * (p2z - p1z + 1);
|
||||
final int[] xl = new int[length];
|
||||
final int[] zl = new int[length];
|
||||
int index = 0;
|
||||
for (int x = p1x; x <= p2x; x++) {
|
||||
for (int z = p1z; z <= p2z; z++) {
|
||||
xl[index] = x;
|
||||
zl[index] = z;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
BlockManager.setBiomes(world, xl, zl, biome);
|
||||
}
|
||||
|
||||
public static int getHeighestBlock(final String world, final int x, final int z) {
|
||||
final int result = BukkitUtil.getHeighestBlock(world, x, z);
|
||||
final int result = BlockManager.manager.getHeighestBlock(world, x, z);
|
||||
if (result == 0) {
|
||||
return 64;
|
||||
}
|
||||
@ -1070,7 +1097,7 @@ public class MainUtil {
|
||||
return getDefaultHome(plot);
|
||||
} else {
|
||||
Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z);
|
||||
if (BukkitUtil.getBlock(loc).id != 0) {
|
||||
if (BlockManager.manager.getBlock(loc).id != 0) {
|
||||
// sendConsoleMessage("ID was " + BukkitUtil.getBlock(loc).id);
|
||||
loc.setY(Math.max(getHeighestBlock(w, bot.getX(), bot.getZ()), bot.getY()));
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public abstract class SchematicHandler {
|
||||
y_offset = 0;
|
||||
}
|
||||
else {
|
||||
y_offset = BukkitUtil.getHeighestBlock(plot.world, bottom.getX() + 1, bottom.getZ() + 1);
|
||||
y_offset = MainUtil.getHeighestBlock(plot.world, bottom.getX() + 1, bottom.getZ() + 1);
|
||||
}
|
||||
Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1 + x_offset, y_offset - 1, 1 + z_offset);
|
||||
Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
|
||||
@ -346,10 +346,10 @@ public abstract class SchematicHandler {
|
||||
return false;
|
||||
}
|
||||
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
|
||||
final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
|
||||
final int sy = MainUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
|
||||
final Dimension demensions = schematic.getSchematicDimension();
|
||||
final int HEIGHT = demensions.getY();
|
||||
if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) {
|
||||
if ((HEIGHT < 255)) {
|
||||
l1 = l1.add(1, sy - 1, 1);
|
||||
} else {
|
||||
l1 = l1.add(1, 0, 1);
|
||||
|
Reference in New Issue
Block a user