Fixes #783
Fixes #780
This commit is contained in:
Jesse Boyd 2015-12-15 03:15:30 +11:00
parent 35589dcc5f
commit 163ccc9eae
6 changed files with 110 additions and 21 deletions

View File

@ -7,7 +7,7 @@ public abstract class SquarePlotWorld extends GridPlotWorld {
public static int PLOT_WIDTH_DEFAULT = 42; public static int PLOT_WIDTH_DEFAULT = 42;
public static int ROAD_WIDTH_DEFAULT = 7; public static int ROAD_WIDTH_DEFAULT = 7;
public static int ROAD_OFFSET_X_DEFAULT = 0; public static int ROAD_OFFSET_X_DEFAULT = 0;
public static int ROAD_OFFSET__Z_DEFAULT = 0; public static int ROAD_OFFSET_Z_DEFAULT = 0;
public int PLOT_WIDTH; public int PLOT_WIDTH;
public int ROAD_WIDTH; public int ROAD_WIDTH;
public int ROAD_OFFSET_X; public int ROAD_OFFSET_X;

View File

@ -100,6 +100,16 @@ public abstract class ChunkManager {
public abstract void setChunk(final ChunkWrapper loc, final PlotBlock[][] result); public abstract void setChunk(final ChunkWrapper loc, final PlotBlock[][] result);
/**
* 0 = Entity
* 1 = Animal
* 2 = Monster
* 3 = Mob
* 4 = Boat
* 5 = Misc
* @param plot
* @return
*/
public abstract int[] countEntities(final Plot plot); public abstract int[] countEntities(final Plot plot);
public abstract boolean loadChunk(final String world, final ChunkLoc loc, final boolean force); public abstract boolean loadChunk(final String world, final ChunkLoc loc, final boolean force);

View File

@ -42,11 +42,13 @@ import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.json.JSONArray; import com.intellectualcrafters.json.JSONArray;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
@ -138,7 +140,7 @@ public abstract class SchematicHandler {
* @return boolean true if succeeded * @return boolean true if succeeded
*/ */
public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset, final RunnableVal<Boolean> whenDone) { public void paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset, final RunnableVal<Boolean> whenDone) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
if (whenDone != null) { if (whenDone != null) {
@ -169,11 +171,15 @@ public abstract class SchematicHandler {
final int y_offset; final int y_offset;
if (HEIGHT >= 256) { if (HEIGHT >= 256) {
y_offset = 0; y_offset = 0;
} else {
PlotWorld pw = plot.getWorld();
if (pw instanceof ClassicPlotWorld) {
y_offset = ((ClassicPlotWorld) pw).PLOT_HEIGHT;
} else { } else {
y_offset = MainUtil.getHeighestBlock(plot.world, region.minX + 1, region.minZ + 1); y_offset = MainUtil.getHeighestBlock(plot.world, region.minX + 1, region.minZ + 1);
} }
}
final Location pos1 = new Location(plot.world, region.minX + x_offset, y_offset, region.minZ + z_offset); final Location pos1 = new Location(plot.world, region.minX + x_offset, y_offset, region.minZ + z_offset);
// Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ);
final Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); final Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
// TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate); // TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate);
final int p1x = pos1.getX(); final int p1x = pos1.getX();
@ -817,6 +823,57 @@ public abstract class SchematicHandler {
} }
return collection; return collection;
} }
public Schematic copySection(RegionWrapper region) {
int x1 = region.minX;
int x2 = region.maxX;
int z1 = region.minZ;
int z2 = region.maxZ;
int y1 = region.minY;
int y2 = Math.min(region.maxY, 255);
int width = x2 - x1 + 1;
int length = z2 - z1 + 1;
int height = y2 - y1 + 1;
short[] ids2 = new short[width * length * height];
byte[] datas2 = new byte[width * length * height];
int dx = schematicDimension.getX();
int dy = schematicDimension.getY();
int dz = schematicDimension.getZ();
for (int y = y1; y <= y2; y++) {
int yy = y >= 0 ? (y < dy ? y : y - dy) : y + dy;
int i1 = yy * dx * dz;
int j1 = (y - y1) * width * length;
for (int z = z1; z <= z2; z++) {
int zz = z >= 0 ? (z < dz ? z : z - dz) : z + dz;
int i2 = i1 + zz * dx;
int j2 = j1 + (z - z1) * width;
for (int x = x1; x <= x2; x++) {
int xx = x >= 0 ? (x < dx ? x : x - dx) : x + dx;
int i3 = i2 + xx;
int j3 = j2 + (x - x1);
ids2[j3] = ids[i3];
datas2[j3] = datas[i3];
}
}
}
return new Schematic(ids2, datas2, new Dimension(width, height, length));
}
public void save(final File file) {
byte[] ids2 = new byte[ids.length];
for (int i = 0; i < ids.length; i++) {
ids2[i] = (byte) ids[i];
}
CompoundTag tag = createTag(ids2, datas, schematicDimension);
SchematicHandler.this.save(tag, file.toString());
}
} }
/** /**

View File

@ -156,7 +156,7 @@ public class LikePlotMeConverter {
return false; return false;
} }
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' in the 'settings.yml'"); sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
mergeWorldYml(plugin, plotConfig); mergeWorldYml(plugin, plotConfig);

View File

@ -2,6 +2,7 @@ package com.plotsquared.bukkit.generator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -109,7 +110,7 @@ public class HybridPop extends BukkitPlotPopulator {
} }
if (requiredRegion != null) { if (requiredRegion != null) {
if (!doFloor && !doFilling && plotworld.G_SCH_STATE == null) { if (!doFloor && !doFilling && plotworld.G_SCH_DATA == null) {
return; return;
} }
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
@ -127,8 +128,8 @@ public class HybridPop extends BukkitPlotPopulator {
final PlotLoc loc = new PlotLoc(absX, absZ); final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { for (Entry<Short, Byte> entry : blocks.entrySet()) {
setBlockAbs(x, (short) (plotheight + y), z, blocks.get(y)); setBlockAbs(x, (short) (plotheight + entry.getKey()), z, entry.getValue());
} }
} }
if (plotworld.G_SCH_STATE != null) { if (plotworld.G_SCH_STATE != null) {
@ -164,8 +165,8 @@ public class HybridPop extends BukkitPlotPopulator {
final PlotLoc loc = new PlotLoc(absX, absZ); final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { for (Entry<Short, Byte> entry : blocks.entrySet()) {
setBlockAbs(x, (short) (plotheight + y), z, blocks.get(y)); setBlockAbs(x, (short) (plotheight + entry.getKey()), z, entry.getValue());
} }
} }
if (plotworld.G_SCH_STATE != null) { if (plotworld.G_SCH_STATE != null) {
@ -199,8 +200,8 @@ public class HybridPop extends BukkitPlotPopulator {
final PlotLoc loc = new PlotLoc(absX, absZ); final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { for (Entry<Short, Byte> entry : blocks.entrySet()) {
setBlockAbs(x, (short) (roadheight + y), z, blocks.get(y)); setBlockAbs(x, (short) (roadheight + entry.getKey()), z, entry.getValue());
} }
} }
} }

View File

@ -74,7 +74,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -405,7 +405,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConnect(final PlayerLoginEvent event) { public void onConnect(final PlayerJoinEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
BukkitUtil.getPlayer(event.getPlayer()).unregister(); BukkitUtil.getPlayer(event.getPlayer()).unregister();
final PlotPlayer pp = BukkitUtil.getPlayer(player); final PlotPlayer pp = BukkitUtil.getPlayer(player);
@ -428,7 +428,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
TaskManager.runTaskLaterAsync(new Runnable() { TaskManager.runTaskLaterAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!player.hasPlayedBefore()) { if (!player.hasPlayedBefore() && player.isOnline()) {
player.saveData(); player.saveData();
} }
ExpireManager.dates.put(uuid, System.currentTimeMillis()); ExpireManager.dates.put(uuid, System.currentTimeMillis());
@ -1623,12 +1623,19 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
Plot now = MainUtil.getPlot(loc); Plot now = MainUtil.getPlot(loc);
final Plot lastPlot = (Plot) pp.getMeta("lastplot"); final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (now == null) { if (now == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot)) { if ((lastPlot != null) && !plotExit(pp, lastPlot) && tmp_teleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
tmp_teleport = false;
player.teleport(from); player.teleport(from);
tmp_teleport = true;
} else { } else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
tmp_teleport = false;
player.teleport(player.getWorld().getSpawnLocation()); player.teleport(player.getWorld().getSpawnLocation());
tmp_teleport = true;
}
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -1636,29 +1643,43 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} else if ((lastPlot != null) && now.equals(lastPlot)) { } else if ((lastPlot != null) && now.equals(lastPlot)) {
return; return;
} else { } else {
if (!plotEntry(pp, now)) { if (!plotEntry(pp, now) && tmp_teleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!now.equals(lastPlot)) { if (!now.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
tmp_teleport = false;
player.teleport(from); player.teleport(from);
tmp_teleport = true;
} else { } else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
tmp_teleport = false;
player.teleport(player.getWorld().getSpawnLocation()); player.teleport(player.getWorld().getSpawnLocation());
tmp_teleport = true;
}
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
final Integer border = MainUtil.worldBorder.get(worldname); final Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) { if (border != null && tmp_teleport) {
if (z2 > border) { if (z2 > border) {
to.setZ(border - 4); to.setZ(border - 4);
tmp_teleport = false;
player.teleport(event.getTo()); player.teleport(event.getTo());
tmp_teleport = true;
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
return;
} else if (z2 < -border) { } else if (z2 < -border) {
to.setZ(-border + 4); to.setZ(-border + 4);
tmp_teleport = false;
player.teleport(event.getTo()); player.teleport(event.getTo());
tmp_teleport = true;
MainUtil.sendMessage(pp, C.BORDER); MainUtil.sendMessage(pp, C.BORDER);
return;
} }
} }
return;
} }
} }