last commit before 4.0.0

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-03-14 21:49:33 -04:00
parent cf1764723f
commit 7f14e88c4c
24 changed files with 303 additions and 310 deletions

View File

@ -73,7 +73,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS); WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS);
} catch (final Throwable throwable) { } catch (final Throwable throwable) {
throw new IllegalStateException( throw new IllegalStateException(
"Failed to force load WorldEdit." + " Road schematics will fail to generate", "Failed to force load WorldEdit. Road schematics will fail to generate",
throwable); throwable);
} }
} }

View File

@ -181,13 +181,13 @@ public final class Reflection {
*/ */
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) { public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
if (!_loadedMethods.containsKey(clazz)) { if (!_loadedMethods.containsKey(clazz)) {
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>()); _loadedMethods.put(clazz, new HashMap<>());
} }
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames =
_loadedMethods.get(clazz); _loadedMethods.get(clazz);
if (!loadedMethodNames.containsKey(name)) { if (!loadedMethodNames.containsKey(name)) {
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>()); loadedMethodNames.put(name, new HashMap<>());
} }
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name); Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);

View File

@ -24,7 +24,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
return generator; return generator;
} }
@Override public void populate(World world, Random r, Chunk chunk) { @Override public void populate(World world, Random random, Chunk source) {
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null); AugmentedUtils.generate(world.getName(), source.getX(), source.getZ(), null);
} }
} }

View File

@ -69,12 +69,10 @@ public class BukkitPlotGenerator extends ChunkGenerator
+ " is already a BukkitPlotGenerator!"); + " is already a BukkitPlotGenerator!");
} }
this.full = false; this.full = false;
PlotSquared.debug("BukkitPlotGenerator does not fully support: " + cg); //todo figure out why this was put here in the first place:
//PlotSquared.debug("BukkitPlotGenerator does not fully support: " + cg);
this.platformGenerator = cg; this.platformGenerator = cg;
this.plotGenerator = new IndependentPlotGenerator() { this.plotGenerator = new IndependentPlotGenerator() {
@Override public void processSetup(SetupObject setup) {
}
@Override public void initialize(PlotArea area) { @Override public void initialize(PlotArea area) {
} }

View File

@ -59,8 +59,7 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
world.setAutoSave(false); world.setAutoSave(false);
} }
TaskManager.runTaskRepeat(new Runnable() { TaskManager.runTaskRepeat(() -> {
@Override public void run() {
try { try {
HashSet<Chunk> toUnload = new HashSet<>(); HashSet<Chunk> toUnload = new HashSet<>();
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
@ -69,10 +68,9 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
continue; continue;
} }
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world); Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
Object chunkMap = Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w); Method methodIsChunkInUse =
Method methodIsChunkInUse = chunkMap.getClass() chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
.getDeclaredMethod("isChunkInUse", int.class, int.class);
Chunk[] chunks = world.getLoadedChunks(); Chunk[] chunks = world.getLoadedChunks();
for (Chunk chunk : chunks) { for (Chunk chunk : chunks) {
if ((boolean) methodIsChunkInUse if ((boolean) methodIsChunkInUse
@ -101,7 +99,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
}
}, 1); }, 1);
} }
@ -222,13 +219,12 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
private void cleanChunk(final Chunk chunk) { private void cleanChunk(final Chunk chunk) {
TaskManager.index.incrementAndGet(); TaskManager.index.incrementAndGet();
final Integer currentIndex = TaskManager.index.get(); final Integer currentIndex = TaskManager.index.get();
Integer task = TaskManager.runTaskRepeat(new Runnable() { Integer task = TaskManager.runTaskRepeat(() -> {
@Override public void run() {
if (!chunk.isLoaded()) { if (!chunk.isLoaded()) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex); TaskManager.tasks.remove(currentIndex);
PlotSquared.debug( PlotSquared
Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!"); .debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true); chunk.unload(true, true);
return; return;
} }
@ -236,8 +232,8 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
if (tiles.length == 0) { if (tiles.length == 0) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex); TaskManager.tasks.remove(currentIndex);
PlotSquared.debug( PlotSquared
Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!"); .debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
chunk.unload(true, true); chunk.unload(true, true);
return; return;
} }
@ -255,7 +251,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
tiles[i].getBlock().setType(Material.AIR, false); tiles[i].getBlock().setType(Material.AIR, false);
i++; i++;
} }
}
}, 5); }, 5);
TaskManager.tasks.put(currentIndex, task); TaskManager.tasks.put(currentIndex, task);
} }

View File

@ -65,10 +65,10 @@ public class EntitySpawnListener implements Listener {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity.getLocation()); Location location = BukkitUtil.getLocation(entity.getLocation());
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
if (area == null) { if (!location.isPlotArea()) {
return; return;
} }
Plot plot = area.getOwnedPlotAbs(location); Plot plot = location.getOwnedPlotAbs();
if (plot == null) { if (plot == null) {
if (!area.MOB_SPAWNING) { if (!area.MOB_SPAWNING) {
EntityType type = entity.getType(); EntityType type = entity.getType();

View File

@ -237,10 +237,7 @@ import java.util.regex.Pattern;
@EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) { @EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
if (e.getVehicle().getType() == EntityType.BOAT) { if (e.getVehicle().getType() == EntityType.BOAT) {
Location location = BukkitUtil.getLocation(e.getEntity()); Location location = BukkitUtil.getLocation(e.getEntity());
if (location.getPlotArea() == null) { if (location.isPlotArea()) {
//we don't care about events that happen outside of a plot area.
return;
}
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity()); PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity());
Plot plot = player.getCurrentPlot(); Plot plot = player.getCurrentPlot();
@ -260,6 +257,7 @@ import java.util.regex.Pattern;
} }
} }
} }
}
@EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) { @EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
@ -315,7 +313,7 @@ import java.util.regex.Pattern;
if (area == null) { if (area == null) {
return; return;
} }
Plot plot = area.getOwnedPlot(loc); Plot plot = loc.getOwnedPlot();
if (plot == null) { if (plot == null) {
return; return;
} }
@ -655,7 +653,7 @@ import java.util.regex.Pattern;
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer pp = PlotPlayer.wrap(player); PlotPlayer pp = PlotPlayer.wrap(player);
Location loc = BukkitUtil.getLocation(to); Location loc = BukkitUtil.getLocation(to);
PlotArea area = PlotSquared.get().getPlotAreaAbs(loc); PlotArea area = loc.getPlotArea();
if (area == null) { if (area == null) {
return; return;
} }
@ -1029,7 +1027,7 @@ import java.util.regex.Pattern;
Iterator<Block> iterator = event.blockList().iterator(); Iterator<Block> iterator = event.blockList().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
iterator.next(); iterator.next();
if (location.getPlotArea() != null) { if (location.isPlotArea()) {
iterator.remove(); iterator.remove();
} }
} }
@ -1095,15 +1093,14 @@ import java.util.regex.Pattern;
pp.deleteMeta("perm"); pp.deleteMeta("perm");
} }
Location loc = pp.getLocation(); Location loc = pp.getLocation();
PlotArea area = PlotSquared.get().getPlotAreaAbs(loc); PlotArea area = loc.getPlotArea();
if (area == null) { if (loc.isPlotArea()) {
return; plot = loc.getPlot();
}
plot = area.getPlot(loc);
if (plot != null) { if (plot != null) {
plotEntry(pp, plot); plotEntry(pp, plot);
} }
} }
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) { public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
@ -1372,8 +1369,7 @@ import java.util.regex.Pattern;
return; return;
} }
for (Block block1 : event.getBlocks()) { for (Block block1 : event.getBlocks()) {
if (BukkitUtil.getLocation(block1.getLocation().add(relative)).getPlotArea() if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) {
!= null) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -1414,7 +1410,7 @@ import java.util.regex.Pattern;
try { try {
for (Block pulled : event.getBlocks()) { for (Block pulled : event.getBlocks()) {
location = BukkitUtil.getLocation(pulled.getLocation()); location = BukkitUtil.getLocation(pulled.getLocation());
if (location.getPlotArea() != null) { if (location.isPlotArea()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -1427,7 +1423,7 @@ import java.util.regex.Pattern;
BlockFace dir = event.getDirection(); BlockFace dir = event.getDirection();
location = BukkitUtil.getLocation(block.getLocation() location = BukkitUtil.getLocation(block.getLocation()
.add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2)); .add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
if (location.getPlotArea() != null) { if (location.isPlotArea()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -1512,7 +1508,7 @@ import java.util.regex.Pattern;
if (area == null) { if (area == null) {
for (int i = blocks.size() - 1; i >= 0; i--) { for (int i = blocks.size() - 1; i >= 0; i--) {
location = BukkitUtil.getLocation(blocks.get(i).getLocation()); location = BukkitUtil.getLocation(blocks.get(i).getLocation());
if (location.getPlotArea() != null) { if (location.isPlotArea()) {
blocks.remove(i); blocks.remove(i);
} }
} }
@ -1746,7 +1742,7 @@ import java.util.regex.Pattern;
Iterator<Block> iterator = event.blockList().iterator(); Iterator<Block> iterator = event.blockList().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
location = BukkitUtil.getLocation(iterator.next().getLocation()); location = BukkitUtil.getLocation(iterator.next().getLocation());
if (location.getPlotArea() != null) { if (location.isPlotArea()) {
iterator.remove(); iterator.remove();
} }
} }
@ -2054,12 +2050,6 @@ import java.util.regex.Pattern;
case TNT_MINECART: case TNT_MINECART:
eventType = PlayerBlockEventType.PLACE_VEHICLE; eventType = PlayerBlockEventType.PLACE_VEHICLE;
break; break;
case ITEM_FRAME:
case PAINTING:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_HANGING;
break;
default: default:
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
break; break;

View File

@ -36,8 +36,7 @@ import java.util.UUID;
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>(); private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
public static void startRunnable(JavaPlugin plugin) { public static void startRunnable(JavaPlugin plugin) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
@Override public void run() {
if (!healRunnable.isEmpty()) { if (!healRunnable.isEmpty()) {
for (Iterator<Entry<UUID, Interval>> iterator = for (Iterator<Entry<UUID, Interval>> iterator =
healRunnable.entrySet().iterator(); iterator.hasNext(); ) { healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
@ -78,7 +77,6 @@ import java.util.UUID;
} }
} }
} }
}
}, 0L, 20L); }, 0L, 20L);
} }

View File

@ -33,8 +33,8 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
this.done = classChunk.getField("done").getRealField(); this.done = classChunk.getField("done").getRealField();
this.lit = classChunk.getField("lit").getRealField(); this.lit = classChunk.getField("lit").getRealField();
this.s = classChunk.getField("s").getRealField(); this.s = classChunk.getField("s").getRealField();
} catch (Throwable ignore) { } catch (Exception e) {
ignore.printStackTrace(); e.printStackTrace();
} }
Bukkit.getPluginManager().registerEvents(this, plugin); Bukkit.getPluginManager().registerEvents(this, plugin);
} }

View File

@ -111,10 +111,82 @@ public class BukkitChunkManager extends ChunkManager {
return chunks; return chunks;
} }
@Override @Override public int[] countEntities(Plot plot) {
public boolean copyRegion(com.github.intellectualsites.plotsquared.plot.object.Location pos1, int[] existing = (int[]) plot.getMeta("EntityCount");
com.github.intellectualsites.plotsquared.plot.object.Location pos2, if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
com.github.intellectualsites.plotsquared.plot.object.Location newPos, < 1000)) {
return existing;
}
PlotArea area = plot.getArea();
World world = BukkitUtil.getWorld(area.worldname);
Location bot = plot.getBottomAbs();
Location top = plot.getTopAbs();
int bx = bot.getX() >> 4;
int bz = bot.getZ() >> 4;
int tx = top.getX() >> 4;
int tz = top.getZ() >> 4;
int size = tx - bx << 4;
Set<Chunk> chunks = new HashSet<>();
for (int X = bx; X <= tx; X++) {
for (int Z = bz; Z <= tz; Z++) {
if (world.isChunkLoaded(X, Z)) {
chunks.add(world.getChunkAt(X, Z));
}
}
}
boolean doWhole = false;
List<Entity> entities = null;
if (size > 200 && chunks.size() > 200) {
entities = world.getEntities();
if (entities.size() < 16 + size / 8) {
doWhole = true;
}
}
int[] count = new int[6];
if (doWhole) {
for (Entity entity : entities) {
org.bukkit.Location location = entity.getLocation();
Chunk chunk = location.getChunk();
if (chunks.contains(chunk)) {
int X = chunk.getX();
int Z = chunk.getZ();
if (X > bx && X < tx && Z > bz && Z < tz) {
count(count, entity);
} else {
Plot other = area.getPlot(BukkitUtil.getLocation(location));
if (plot.equals(other)) {
count(count, entity);
}
}
}
}
} else {
for (Chunk chunk : chunks) {
int X = chunk.getX();
int Z = chunk.getZ();
Entity[] entities1 = chunk.getEntities();
for (Entity entity : entities1) {
if (X == bx || X == tx || Z == bz || Z == tz) {
Plot other = area.getPlot(BukkitUtil.getLocation(entity));
if (plot.equals(other)) {
count(count, entity);
}
} else {
count(count, entity);
}
}
}
}
return count;
}
@Override public boolean copyRegion(Location pos1, Location pos2, Location newPos,
final Runnable whenDone) { final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX(); final int relX = newPos.getX() - pos1.getX();
final int relZ = newPos.getZ() - pos1.getZ(); final int relZ = newPos.getZ() - pos1.getZ();
@ -140,7 +212,7 @@ public class BukkitChunkManager extends ChunkManager {
map.saveEntitiesIn(chunk, region); map.saveEntitiesIn(chunk, region);
for (int x = bx & 15; x <= (tx & 15); x++) { for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) { for (int z = bz & 15; z <= (tz & 15); z++) {
map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ); map.saveBlocks(oldBukkitWorld, cxx + x, czz + z, relX, relZ);
} }
} }
} }
@ -165,9 +237,7 @@ public class BukkitChunkManager extends ChunkManager {
return true; return true;
} }
@Override public boolean regenerateRegion( @Override public boolean regenerateRegion(final Location pos1, final Location pos2,
final com.github.intellectualsites.plotsquared.plot.object.Location pos1,
final com.github.intellectualsites.plotsquared.plot.object.Location pos2,
final boolean ignoreAugment, final Runnable whenDone) { final boolean ignoreAugment, final Runnable whenDone) {
final String world = pos1.getWorld(); final String world = pos1.getWorld();
@ -275,8 +345,7 @@ public class BukkitChunkManager extends ChunkManager {
AugmentedUtils.bypass(ignoreAugment, AugmentedUtils.bypass(ignoreAugment,
() -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() { () -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
@Override public void run(ScopedLocalBlockQueue value) { @Override public void run(ScopedLocalBlockQueue value) {
com.github.intellectualsites.plotsquared.plot.object.Location min = Location min = value.getMin();
value.getMin();
int bx = min.getX(); int bx = min.getX();
int bz = min.getZ(); int bz = min.getZ();
for (int x1 = 0; x1 < 16; x1++) { for (int x1 = 0; x1 < 16; x1++) {
@ -317,9 +386,22 @@ public class BukkitChunkManager extends ChunkManager {
return true; return true;
} }
@Override @Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
public void clearAllEntities(com.github.intellectualsites.plotsquared.plot.object.Location pos1, return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
com.github.intellectualsites.plotsquared.plot.object.Location pos2) { }
@SuppressWarnings("deprecation") @Override
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
final boolean safe) {
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
TaskManager
.runTask(() -> BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe));
} else {
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
}
}
@Override public void clearAllEntities(Location pos1, Location pos2) {
String world = pos1.getWorld(); String world = pos1.getWorld();
List<Entity> entities = BukkitUtil.getEntities(world); List<Entity> entities = BukkitUtil.getEntities(world);
int bx = pos1.getX(); int bx = pos1.getX();
@ -340,25 +422,7 @@ public class BukkitChunkManager extends ChunkManager {
} }
} }
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) { @Override public void swap(Location bot1, Location top1, Location bot2, Location top2,
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
}
@SuppressWarnings("deprecation") @Override
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
final boolean safe) {
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
TaskManager
.runTask(() -> BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe));
} else {
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
}
}
@Override public void swap(com.github.intellectualsites.plotsquared.plot.object.Location bot1,
com.github.intellectualsites.plotsquared.plot.object.Location top1,
com.github.intellectualsites.plotsquared.plot.object.Location bot2,
com.github.intellectualsites.plotsquared.plot.object.Location top2,
final Runnable whenDone) { final Runnable whenDone) {
RegionWrapper region1 = RegionWrapper region1 =
new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ()); new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
@ -387,81 +451,6 @@ public class BukkitChunkManager extends ChunkManager {
}); });
} }
@Override public int[] countEntities(Plot plot) {
int[] existing = (int[]) plot.getMeta("EntityCount");
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
< 1000)) {
return existing;
}
PlotArea area = plot.getArea();
World world = BukkitUtil.getWorld(area.worldname);
com.github.intellectualsites.plotsquared.plot.object.Location bot = plot.getBottomAbs();
com.github.intellectualsites.plotsquared.plot.object.Location top = plot.getTopAbs();
int bx = bot.getX() >> 4;
int bz = bot.getZ() >> 4;
int tx = top.getX() >> 4;
int tz = top.getZ() >> 4;
int size = tx - bx << 4;
Set<Chunk> chunks = new HashSet<>();
for (int X = bx; X <= tx; X++) {
for (int Z = bz; Z <= tz; Z++) {
if (world.isChunkLoaded(X, Z)) {
chunks.add(world.getChunkAt(X, Z));
}
}
}
boolean doWhole = false;
List<Entity> entities = null;
if (size > 200 && chunks.size() > 200) {
entities = world.getEntities();
if (entities.size() < 16 + size / 8) {
doWhole = true;
}
}
int[] count = new int[6];
if (doWhole) {
for (Entity entity : entities) {
org.bukkit.Location location = entity.getLocation();
Chunk chunk = location.getChunk();
if (chunks.contains(chunk)) {
int X = chunk.getX();
int Z = chunk.getZ();
if (X > bx && X < tx && Z > bz && Z < tz) {
count(count, entity);
} else {
Plot other = area.getPlot(BukkitUtil.getLocation(location));
if (plot.equals(other)) {
count(count, entity);
}
}
}
}
} else {
for (Chunk chunk : chunks) {
int X = chunk.getX();
int Z = chunk.getZ();
Entity[] entities1 = chunk.getEntities();
for (Entity entity : entities1) {
if (X == bx || X == tx || Z == bz || Z == tz) {
Plot other = area.getPlot(BukkitUtil.getLocation(entity));
if (plot.equals(other)) {
count(count, entity);
}
} else {
count(count, entity);
}
}
}
}
return count;
}
private void count(int[] count, Entity entity) { private void count(int[] count, Entity entity) {
switch (entity.getType()) { switch (entity.getType()) {
case PLAYER: case PLAYER:
@ -595,6 +584,7 @@ public class BukkitChunkManager extends ChunkManager {
count[0]++; count[0]++;
} }
public static class ContentMap { public static class ContentMap {
final Set<EntityWrapper> entities; final Set<EntityWrapper> entities;
@ -629,8 +619,7 @@ public class BukkitChunkManager extends ChunkManager {
public void saveEntitiesOut(Chunk chunk, RegionWrapper region) { public void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
for (Entity entity : chunk.getEntities()) { for (Entity entity : chunk.getEntities()) {
com.github.intellectualsites.plotsquared.plot.object.Location loc = Location loc = BukkitUtil.getLocation(entity);
BukkitUtil.getLocation(entity);
int x = loc.getX(); int x = loc.getX();
int z = loc.getZ(); int z = loc.getZ();
if (isIn(region, x, z)) { if (isIn(region, x, z)) {
@ -648,8 +637,7 @@ public class BukkitChunkManager extends ChunkManager {
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ,
boolean delete) { boolean delete) {
for (Entity entity : chunk.getEntities()) { for (Entity entity : chunk.getEntities()) {
com.github.intellectualsites.plotsquared.plot.object.Location loc = Location loc = BukkitUtil.getLocation(entity);
BukkitUtil.getLocation(entity);
int x = loc.getX(); int x = loc.getX();
int z = loc.getZ(); int z = loc.getZ();
if (!isIn(region, x, z)) { if (!isIn(region, x, z)) {
@ -683,6 +671,7 @@ public class BukkitChunkManager extends ChunkManager {
this.entities.clear(); this.entities.clear();
} }
//todo optimize maxY
public void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX, public void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX,
int offsetZ) { int offsetZ) {
maxY = Math.min(255, maxY); maxY = Math.min(255, maxY);

View File

@ -192,8 +192,7 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
for (int x = 0; x < lc.biomes.length; x++) { for (int x = 0; x < lc.biomes.length; x++) {
String[] biomes2 = lc.biomes[x]; String[] biomes2 = lc.biomes[x];
if (biomes2 != null) { if (biomes2 != null) {
for (int y = 0; y < biomes2.length; y++) { for (String biomeStr : biomes2) {
String biomeStr = biomes2[y];
if (biomeStr != null) { if (biomeStr != null) {
if (last == null || !StringMan.isEqual(last, biomeStr)) { if (last == null || !StringMan.isEqual(last, biomeStr)) {
biome = Biome.valueOf(biomeStr.toUpperCase()); biome = Biome.valueOf(biomeStr.toUpperCase());
@ -247,8 +246,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
if (disableResult != null) { if (disableResult != null) {
try { try {
fieldNeighbors.set(disableResult[0], disableResult[1]); fieldNeighbors.set(disableResult[0], disableResult[1]);
} catch (Throwable ignore) { } catch (Exception e) {
ignore.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -69,7 +69,15 @@ import java.util.*;
if (this.engine != null) { if (this.engine != null) {
return; return;
} }
this.engine = new ScriptEngineManager(null).getEngineByName("nashorn"); //create script engine manager
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
//create nashorn engine
this.engine = scriptEngineManager.getEngineByName("nashorn");
try {
engine.eval("print('PlotSquared Scripting Test');");
} catch (ScriptException e) {
e.printStackTrace();
}
if (this.engine == null) { if (this.engine == null) {
this.engine = new ScriptEngineManager(null).getEngineByName("JavaScript"); this.engine = new ScriptEngineManager(null).getEngineByName("JavaScript");
} }

View File

@ -11,8 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.Permissions;
@CommandDeclaration(usage = "/plot move <X;Z>", command = "move", description = "Move a plot", @CommandDeclaration(usage = "/plot move <X;Z>", command = "move", description = "Move a plot",
aliases = {"debugmove"}, permission = "plots.move", category = CommandCategory.CLAIMING, aliases = {"debugmove"}, permission = "plots.move", category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER)
requiredType = RequiredType.NONE) public class Move extends SubCommand { public class Move extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) { @Override public boolean onCommand(final PlotPlayer player, String[] args) {
Location loc = player.getLocation(); Location loc = player.getLocation();

View File

@ -9,8 +9,8 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players", @CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players", usage = "/plot near", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
usage = "/plot near", category = CommandCategory.INFO) public class Near extends Command { public class Near extends Command {
public Near() { public Near() {
super(MainCommand.getInstance(), true); super(MainCommand.getInstance(), true);
} }

View File

@ -107,8 +107,8 @@ import java.util.Set;
MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs"); MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs");
TaskManager.objectTask(plots, new RunnableVal<Plot>() { TaskManager.objectTask(plots, new RunnableVal<Plot>() {
@Override public void run(Plot plot) { @Override public void run(Plot plot) {
Location pos1 = plot.getBottom(); Location pos1 = plot.getCorners()[0];
Location pos2 = plot.getTop(); Location pos2 = plot.getCorners()[1];
int ccx1 = pos1.getX() >> 9; int ccx1 = pos1.getX() >> 9;
int ccz1 = pos1.getZ() >> 9; int ccz1 = pos1.getZ() >> 9;
int ccx2 = pos2.getX() >> 9; int ccx2 = pos2.getX() >> 9;

View File

@ -44,7 +44,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return false; return false;
} }
@Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { @Override public boolean unClaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
setWallFilling(dpw, plot.getId(), dpw.WALL_FILLING); setWallFilling(dpw, plot.getId(), dpw.WALL_FILLING);
setWall(dpw, plot.getId(), dpw.WALL_BLOCK); setWall(dpw, plot.getId(), dpw.WALL_BLOCK);

View File

@ -57,7 +57,11 @@ public class Location implements Cloneable, Comparable<Location> {
} }
@Override public Location clone() { @Override public Location clone() {
return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch); try {
return (Location) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(); //can't happen
}
} }
public PlotArea getPlotArea() { public PlotArea getPlotArea() {
@ -65,7 +69,7 @@ public class Location implements Cloneable, Comparable<Location> {
} }
public Plot getOwnedPlot() { public Plot getOwnedPlot() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
if (area != null) { if (area != null) {
return area.getOwnedPlot(this); return area.getOwnedPlot(this);
} else { } else {
@ -74,7 +78,7 @@ public class Location implements Cloneable, Comparable<Location> {
} }
public Plot getOwnedPlotAbs() { public Plot getOwnedPlotAbs() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
if (area != null) { if (area != null) {
return area.getOwnedPlotAbs(this); return area.getOwnedPlotAbs(this);
} else { } else {
@ -83,16 +87,16 @@ public class Location implements Cloneable, Comparable<Location> {
} }
public boolean isPlotArea() { public boolean isPlotArea() {
return PlotSquared.get().getPlotAreaAbs(this) != null; return getPlotArea() != null;
} }
public boolean isPlotRoad() { public boolean isPlotRoad() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
return area != null && area.getPlotAbs(this) == null; return area != null && area.getPlotAbs(this) == null;
} }
public boolean isUnownedPlotArea() { public boolean isUnownedPlotArea() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
return area != null && area.getOwnedPlotAbs(this) == null; return area != null && area.getOwnedPlotAbs(this) == null;
} }
@ -106,7 +110,7 @@ public class Location implements Cloneable, Comparable<Location> {
} }
public Plot getPlotAbs() { public Plot getPlotAbs() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
if (area != null) { if (area != null) {
return area.getPlotAbs(this); return area.getPlotAbs(this);
} else { } else {
@ -115,7 +119,7 @@ public class Location implements Cloneable, Comparable<Location> {
} }
public Plot getPlot() { public Plot getPlot() {
PlotArea area = PlotSquared.get().getPlotAreaAbs(this); PlotArea area = getPlotArea();
if (area != null) { if (area != null) {
return area.getPlot(this); return area.getPlot(this);
} else { } else {

View File

@ -226,7 +226,7 @@ public class Plot {
* @see PlotPlayer#getCurrentPlot() if a player is expected here. * @see PlotPlayer#getCurrentPlot() if a player is expected here.
*/ */
public static Plot getPlot(Location location) { public static Plot getPlot(Location location) {
PlotArea pa = PlotSquared.get().getPlotAreaAbs(location); PlotArea pa = location.getPlotArea();
if (pa != null) { if (pa != null) {
return pa.getPlot(location); return pa.getPlot(location);
} }
@ -457,7 +457,7 @@ public class Plot {
* Gets or create plot settings. * Gets or create plot settings.
* *
* @return PlotSettings * @return PlotSettings
* @deprecated use equivalent plot method; * @deprecated use equivalent plot method; please file github issue if one does not exist.
*/ */
@Deprecated public PlotSettings getSettings() { @Deprecated public PlotSettings getSettings() {
if (this.settings == null) { if (this.settings == null) {
@ -837,7 +837,7 @@ public class Plot {
}; };
for (Plot current : plots) { for (Plot current : plots) {
if (isDelete || current.owner == null) { if (isDelete || current.owner == null) {
manager.unclaimPlot(Plot.this.area, current, null); manager.unClaimPlot(Plot.this.area, current, null);
} else { } else {
manager.claimPlot(Plot.this.area, current); manager.claimPlot(Plot.this.area, current);
} }
@ -1567,13 +1567,19 @@ public class Plot {
*/ */
public boolean swapData(Plot plot, Runnable whenDone) { public boolean swapData(Plot plot, Runnable whenDone) {
if (this.owner == null) { if (this.owner == null) {
if (plot != null && plot.hasOwner()) { if (plot == null) {
return false;
}
if (plot.hasOwner()) {
plot.moveData(this, whenDone); plot.moveData(this, whenDone);
return true; return true;
} }
return false; return false;
} }
if (plot == null || plot.owner == null) { if (plot == null) {
this.moveData(plot, whenDone);
return true;
} else if (plot.owner == null) {
this.moveData(plot, whenDone); this.moveData(plot, whenDone);
return true; return true;
} }
@ -2900,7 +2906,7 @@ public class Plot {
getManager().claimPlot(current.getArea(), current); getManager().claimPlot(current.getArea(), current);
Plot originPlot = originArea.getPlotAbs( Plot originPlot = originArea.getPlotAbs(
new PlotId(current.id.x - offset.x, current.id.y - offset.y)); new PlotId(current.id.x - offset.x, current.id.y - offset.y));
originPlot.getManager().unclaimPlot(originArea, originPlot, null); originPlot.getManager().unClaimPlot(originArea, originPlot, null);
} }
plot.setSign(); plot.setSign();
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);

View File

@ -31,7 +31,7 @@ public abstract class PlotManager {
public abstract boolean claimPlot(PlotArea plotArea, Plot plot); public abstract boolean claimPlot(PlotArea plotArea, Plot plot);
public abstract boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone); public abstract boolean unClaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone);
public abstract Location getSignLoc(PlotArea plotArea, Plot plot); public abstract Location getSignLoc(PlotArea plotArea, Plot plot);

View File

@ -83,10 +83,7 @@ public class StringPlotBlock extends PlotBlock {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (obj == null || getClass() != obj.getClass()) {
return false;
}
if (getClass() != obj.getClass()) {
return false; return false;
} }
StringPlotBlock other = (StringPlotBlock) obj; StringPlotBlock other = (StringPlotBlock) obj;

View File

@ -46,7 +46,7 @@ public class SinglePlotManager extends PlotManager {
return true; return true;
} }
@Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { @Override public boolean unClaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) {
if (whenDone != null) { if (whenDone != null) {
whenDone.run(); whenDone.run();
} }

View File

@ -76,11 +76,7 @@ public abstract class EventUtil {
} }
final Plot plot = player.getCurrentPlot(); final Plot plot = player.getCurrentPlot();
if (Settings.Teleport.ON_LOGIN && plot != null) { if (Settings.Teleport.ON_LOGIN && plot != null) {
TaskManager.runTask(new Runnable() { TaskManager.runTask(() -> plot.teleportPlayer(player));
@Override public void run() {
plot.teleportPlayer(player);
}
});
MainUtil.sendMessage(player, MainUtil.sendMessage(player,
Captions.TELEPORTED_TO_ROAD.f() + " (on-login) " + "(" + plot.getId().x + ";" + plot Captions.TELEPORTED_TO_ROAD.f() + " (on-login) " + "(" + plot.getId().x + ";" + plot
.getId().y + ")"); .getId().y + ")");
@ -97,19 +93,13 @@ public abstract class EventUtil {
public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type, public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type,
Location location, LazyBlock block, boolean notifyPerms) { Location location, LazyBlock block, boolean notifyPerms) {
PlotArea area = PlotSquared.get().getPlotAreaAbs(location); PlotArea area = location.getPlotArea();
Plot plot; assert area != null;
if (area != null) { Plot plot = area.getPlot(location);
plot = area.getPlot(location); if (plot != null) {
} else { if (plot.isAdded(player.getUUID())) {
plot = null;
}
if (plot == null) {
if (area == null) {
return true; return true;
} }
} else if (plot.isAdded(player.getUUID())) {
return true;
} }
switch (type) { switch (type) {
case TELEPORT_OBJECT: case TELEPORT_OBJECT:
@ -400,8 +390,6 @@ public abstract class EventUtil {
} }
return true; return true;
} }
case PLACE_HANGING: // Handled elsewhere
return true;
case PLACE_MISC: { case PLACE_MISC: {
if (plot == null) { if (plot == null) {
return Permissions return Permissions

View File

@ -70,8 +70,8 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
return parent.getBlock(x, y, z); return parent.getBlock(x, y, z);
} }
@Override public boolean setBiome(int x, int y, String biome) { @Override public boolean setBiome(int x, int z, String biome) {
return parent.setBiome(x, y, biome); return parent.setBiome(x, z, biome);
} }
@Override public String getWorld() { @Override public String getWorld() {

View File

@ -0,0 +1,21 @@
package com.github.intellectualsites.plotsquared.plot.object;
import org.junit.Test;
import java.util.logging.Logger;
public class LocationTest {
private static final Logger logger = Logger.getLogger(LocationTest.class.getName());
@Test public void cloning() {
String world = "plotworld";
Location location1 = new Location(world, 0, 0, 0);
logger.info(location1.toString());
Location clone = location1.clone();
world = "normal";
logger.info(clone.toString());
location1.getBlockVector3()
}
}