mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
last commit before 4.0.0
Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
parent
cf1764723f
commit
7f14e88c4c
@ -73,7 +73,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS);
|
||||
} catch (final Throwable throwable) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -181,13 +181,13 @@ public final class Reflection {
|
||||
*/
|
||||
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
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 =
|
||||
_loadedMethods.get(clazz);
|
||||
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);
|
||||
|
@ -24,7 +24,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override public void populate(World world, Random r, Chunk chunk) {
|
||||
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
||||
@Override public void populate(World world, Random random, Chunk source) {
|
||||
AugmentedUtils.generate(world.getName(), source.getX(), source.getZ(), null);
|
||||
}
|
||||
}
|
||||
|
@ -69,12 +69,10 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
+ " is already a BukkitPlotGenerator!");
|
||||
}
|
||||
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.plotGenerator = new IndependentPlotGenerator() {
|
||||
@Override public void processSetup(SetupObject setup) {
|
||||
}
|
||||
|
||||
@Override public void initialize(PlotArea area) {
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,7 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
world.setAutoSave(false);
|
||||
}
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskRepeat(() -> {
|
||||
try {
|
||||
HashSet<Chunk> toUnload = new HashSet<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
@ -69,10 +68,9 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
continue;
|
||||
}
|
||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||
Object chunkMap =
|
||||
w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||
Method methodIsChunkInUse = chunkMap.getClass()
|
||||
.getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||
Method methodIsChunkInUse =
|
||||
chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
for (Chunk chunk : chunks) {
|
||||
if ((boolean) methodIsChunkInUse
|
||||
@ -101,7 +99,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@ -222,13 +219,12 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
private void cleanChunk(final Chunk chunk) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override public void run() {
|
||||
Integer task = TaskManager.runTaskRepeat(() -> {
|
||||
if (!chunk.isLoaded()) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
@ -236,8 +232,8 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
if (tiles.length == 0) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
@ -255,7 +251,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}, 5);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
}
|
||||
|
@ -65,10 +65,10 @@ public class EntitySpawnListener implements Listener {
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
Plot plot = location.getOwnedPlotAbs();
|
||||
if (plot == null) {
|
||||
if (!area.MOB_SPAWNING) {
|
||||
EntityType type = entity.getType();
|
||||
|
@ -237,10 +237,7 @@ import java.util.regex.Pattern;
|
||||
@EventHandler public void onVehicleEntityCollision(VehicleEntityCollisionEvent e) {
|
||||
if (e.getVehicle().getType() == EntityType.BOAT) {
|
||||
Location location = BukkitUtil.getLocation(e.getEntity());
|
||||
if (location.getPlotArea() == null) {
|
||||
//we don't care about events that happen outside of a plot area.
|
||||
return;
|
||||
}
|
||||
if (location.isPlotArea()) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity());
|
||||
Plot plot = player.getCurrentPlot();
|
||||
@ -260,6 +257,7 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onRedstoneEvent(BlockRedstoneEvent event) {
|
||||
Block block = event.getBlock();
|
||||
@ -315,7 +313,7 @@ import java.util.regex.Pattern;
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlot(loc);
|
||||
Plot plot = loc.getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
@ -655,7 +653,7 @@ import java.util.regex.Pattern;
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = PlotPlayer.wrap(player);
|
||||
Location loc = BukkitUtil.getLocation(to);
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
|
||||
PlotArea area = loc.getPlotArea();
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
@ -1029,7 +1027,7 @@ import java.util.regex.Pattern;
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
if (location.getPlotArea() != null) {
|
||||
if (location.isPlotArea()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@ -1095,15 +1093,14 @@ import java.util.regex.Pattern;
|
||||
pp.deleteMeta("perm");
|
||||
}
|
||||
Location loc = pp.getLocation();
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(loc);
|
||||
if (area == null) {
|
||||
return;
|
||||
}
|
||||
plot = area.getPlot(loc);
|
||||
PlotArea area = loc.getPlotArea();
|
||||
if (loc.isPlotArea()) {
|
||||
plot = loc.getPlot();
|
||||
if (plot != null) {
|
||||
plotEntry(pp, plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPeskyMobsChangeTheWorldLikeWTFEvent(EntityChangeBlockEvent event) {
|
||||
@ -1372,8 +1369,7 @@ import java.util.regex.Pattern;
|
||||
return;
|
||||
}
|
||||
for (Block block1 : event.getBlocks()) {
|
||||
if (BukkitUtil.getLocation(block1.getLocation().add(relative)).getPlotArea()
|
||||
!= null) {
|
||||
if (BukkitUtil.getLocation(block1.getLocation().add(relative)).isPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1414,7 +1410,7 @@ import java.util.regex.Pattern;
|
||||
try {
|
||||
for (Block pulled : event.getBlocks()) {
|
||||
location = BukkitUtil.getLocation(pulled.getLocation());
|
||||
if (location.getPlotArea() != null) {
|
||||
if (location.isPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1427,7 +1423,7 @@ import java.util.regex.Pattern;
|
||||
BlockFace dir = event.getDirection();
|
||||
location = BukkitUtil.getLocation(block.getLocation()
|
||||
.add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
|
||||
if (location.getPlotArea() != null) {
|
||||
if (location.isPlotArea()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -1512,7 +1508,7 @@ import java.util.regex.Pattern;
|
||||
if (area == null) {
|
||||
for (int i = blocks.size() - 1; i >= 0; i--) {
|
||||
location = BukkitUtil.getLocation(blocks.get(i).getLocation());
|
||||
if (location.getPlotArea() != null) {
|
||||
if (location.isPlotArea()) {
|
||||
blocks.remove(i);
|
||||
}
|
||||
}
|
||||
@ -1746,7 +1742,7 @@ import java.util.regex.Pattern;
|
||||
Iterator<Block> iterator = event.blockList().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
location = BukkitUtil.getLocation(iterator.next().getLocation());
|
||||
if (location.getPlotArea() != null) {
|
||||
if (location.isPlotArea()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
@ -2054,12 +2050,6 @@ import java.util.regex.Pattern;
|
||||
case TNT_MINECART:
|
||||
eventType = PlayerBlockEventType.PLACE_VEHICLE;
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
location = BukkitUtil
|
||||
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||
eventType = PlayerBlockEventType.PLACE_HANGING;
|
||||
break;
|
||||
default:
|
||||
eventType = PlayerBlockEventType.INTERACT_BLOCK;
|
||||
break;
|
||||
|
@ -36,8 +36,7 @@ import java.util.UUID;
|
||||
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
|
||||
|
||||
public static void startRunnable(JavaPlugin plugin) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override public void run() {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (!healRunnable.isEmpty()) {
|
||||
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
@ -78,7 +77,6 @@ import java.util.UUID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
this.done = classChunk.getField("done").getRealField();
|
||||
this.lit = classChunk.getField("lit").getRealField();
|
||||
this.s = classChunk.getField("s").getRealField();
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
@ -111,10 +111,82 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location pos2,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location newPos,
|
||||
@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);
|
||||
|
||||
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 int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
@ -140,7 +212,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
map.saveEntitiesIn(chunk, region);
|
||||
for (int x = bx & 15; x <= (tx & 15); x++) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override public boolean regenerateRegion(
|
||||
final com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||
final com.github.intellectualsites.plotsquared.plot.object.Location pos2,
|
||||
@Override public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
final boolean ignoreAugment, final Runnable whenDone) {
|
||||
final String world = pos1.getWorld();
|
||||
|
||||
@ -275,8 +345,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
AugmentedUtils.bypass(ignoreAugment,
|
||||
() -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||
@Override public void run(ScopedLocalBlockQueue value) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location min =
|
||||
value.getMin();
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
@ -317,9 +386,22 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location pos2) {
|
||||
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||
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 clearAllEntities(Location pos1, Location pos2) {
|
||||
String world = pos1.getWorld();
|
||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||
int bx = pos1.getX();
|
||||
@ -340,25 +422,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||
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,
|
||||
@Override public void swap(Location bot1, Location top1, Location bot2, Location top2,
|
||||
final Runnable whenDone) {
|
||||
RegionWrapper region1 =
|
||||
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) {
|
||||
switch (entity.getType()) {
|
||||
case PLAYER:
|
||||
@ -595,6 +584,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
count[0]++;
|
||||
}
|
||||
|
||||
|
||||
public static class ContentMap {
|
||||
|
||||
final Set<EntityWrapper> entities;
|
||||
@ -629,8 +619,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
|
||||
public void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||
BukkitUtil.getLocation(entity);
|
||||
Location loc = BukkitUtil.getLocation(entity);
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
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,
|
||||
boolean delete) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||
BukkitUtil.getLocation(entity);
|
||||
Location loc = BukkitUtil.getLocation(entity);
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
if (!isIn(region, x, z)) {
|
||||
@ -683,6 +671,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
this.entities.clear();
|
||||
}
|
||||
|
||||
//todo optimize maxY
|
||||
public void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX,
|
||||
int offsetZ) {
|
||||
maxY = Math.min(255, maxY);
|
||||
|
@ -192,8 +192,7 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
for (int x = 0; x < lc.biomes.length; x++) {
|
||||
String[] biomes2 = lc.biomes[x];
|
||||
if (biomes2 != null) {
|
||||
for (int y = 0; y < biomes2.length; y++) {
|
||||
String biomeStr = biomes2[y];
|
||||
for (String biomeStr : biomes2) {
|
||||
if (biomeStr != null) {
|
||||
if (last == null || !StringMan.isEqual(last, biomeStr)) {
|
||||
biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
@ -247,8 +246,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
if (disableResult != null) {
|
||||
try {
|
||||
fieldNeighbors.set(disableResult[0], disableResult[1]);
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,15 @@ import java.util.*;
|
||||
if (this.engine != null) {
|
||||
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) {
|
||||
this.engine = new ScriptEngineManager(null).getEngineByName("JavaScript");
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
||||
|
||||
@CommandDeclaration(usage = "/plot move <X;Z>", command = "move", description = "Move a plot",
|
||||
aliases = {"debugmove"}, permission = "plots.move", category = CommandCategory.CLAIMING,
|
||||
requiredType = RequiredType.NONE) public class Move extends SubCommand {
|
||||
aliases = {"debugmove"}, permission = "plots.move", category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER)
|
||||
public class Move extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||
Location loc = player.getLocation();
|
||||
|
@ -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.util.StringMan;
|
||||
|
||||
@CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players",
|
||||
usage = "/plot near", category = CommandCategory.INFO) public class Near extends Command {
|
||||
@CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players", usage = "/plot near", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
|
||||
public class Near extends Command {
|
||||
public Near() {
|
||||
super(MainCommand.getInstance(), true);
|
||||
}
|
||||
|
@ -107,8 +107,8 @@ import java.util.Set;
|
||||
MainUtil.sendMessage(null, " - TIME ESTIMATE: 12 Parsecs");
|
||||
TaskManager.objectTask(plots, new RunnableVal<Plot>() {
|
||||
@Override public void run(Plot plot) {
|
||||
Location pos1 = plot.getBottom();
|
||||
Location pos2 = plot.getTop();
|
||||
Location pos1 = plot.getCorners()[0];
|
||||
Location pos2 = plot.getCorners()[1];
|
||||
int ccx1 = pos1.getX() >> 9;
|
||||
int ccz1 = pos1.getZ() >> 9;
|
||||
int ccx2 = pos2.getX() >> 9;
|
||||
|
@ -44,7 +44,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
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;
|
||||
setWallFilling(dpw, plot.getId(), dpw.WALL_FILLING);
|
||||
setWall(dpw, plot.getId(), dpw.WALL_BLOCK);
|
||||
|
@ -57,7 +57,11 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
@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() {
|
||||
@ -65,7 +69,7 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
public Plot getOwnedPlot() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
if (area != null) {
|
||||
return area.getOwnedPlot(this);
|
||||
} else {
|
||||
@ -74,7 +78,7 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
public Plot getOwnedPlotAbs() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
if (area != null) {
|
||||
return area.getOwnedPlotAbs(this);
|
||||
} else {
|
||||
@ -83,16 +87,16 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
public boolean isPlotArea() {
|
||||
return PlotSquared.get().getPlotAreaAbs(this) != null;
|
||||
return getPlotArea() != null;
|
||||
}
|
||||
|
||||
public boolean isPlotRoad() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
return area != null && area.getPlotAbs(this) == null;
|
||||
}
|
||||
|
||||
public boolean isUnownedPlotArea() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
return area != null && area.getOwnedPlotAbs(this) == null;
|
||||
}
|
||||
|
||||
@ -106,7 +110,7 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
public Plot getPlotAbs() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
if (area != null) {
|
||||
return area.getPlotAbs(this);
|
||||
} else {
|
||||
@ -115,7 +119,7 @@ public class Location implements Cloneable, Comparable<Location> {
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(this);
|
||||
PlotArea area = getPlotArea();
|
||||
if (area != null) {
|
||||
return area.getPlot(this);
|
||||
} else {
|
||||
|
@ -226,7 +226,7 @@ public class Plot {
|
||||
* @see PlotPlayer#getCurrentPlot() if a player is expected here.
|
||||
*/
|
||||
public static Plot getPlot(Location location) {
|
||||
PlotArea pa = PlotSquared.get().getPlotAreaAbs(location);
|
||||
PlotArea pa = location.getPlotArea();
|
||||
if (pa != null) {
|
||||
return pa.getPlot(location);
|
||||
}
|
||||
@ -457,7 +457,7 @@ public class Plot {
|
||||
* Gets or create plot settings.
|
||||
*
|
||||
* @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() {
|
||||
if (this.settings == null) {
|
||||
@ -837,7 +837,7 @@ public class Plot {
|
||||
};
|
||||
for (Plot current : plots) {
|
||||
if (isDelete || current.owner == null) {
|
||||
manager.unclaimPlot(Plot.this.area, current, null);
|
||||
manager.unClaimPlot(Plot.this.area, current, null);
|
||||
} else {
|
||||
manager.claimPlot(Plot.this.area, current);
|
||||
}
|
||||
@ -1567,13 +1567,19 @@ public class Plot {
|
||||
*/
|
||||
public boolean swapData(Plot plot, Runnable whenDone) {
|
||||
if (this.owner == null) {
|
||||
if (plot != null && plot.hasOwner()) {
|
||||
if (plot == null) {
|
||||
return false;
|
||||
}
|
||||
if (plot.hasOwner()) {
|
||||
plot.moveData(this, whenDone);
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
@ -2900,7 +2906,7 @@ public class Plot {
|
||||
getManager().claimPlot(current.getArea(), current);
|
||||
Plot originPlot = originArea.getPlotAbs(
|
||||
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();
|
||||
TaskManager.runTask(whenDone);
|
||||
|
@ -31,7 +31,7 @@ public abstract class PlotManager {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -83,10 +83,7 @@ public class StringPlotBlock extends PlotBlock {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
StringPlotBlock other = (StringPlotBlock) obj;
|
||||
|
@ -46,7 +46,7 @@ public class SinglePlotManager extends PlotManager {
|
||||
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) {
|
||||
whenDone.run();
|
||||
}
|
||||
|
@ -76,11 +76,7 @@ public abstract class EventUtil {
|
||||
}
|
||||
final Plot plot = player.getCurrentPlot();
|
||||
if (Settings.Teleport.ON_LOGIN && plot != null) {
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override public void run() {
|
||||
plot.teleportPlayer(player);
|
||||
}
|
||||
});
|
||||
TaskManager.runTask(() -> plot.teleportPlayer(player));
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.TELEPORTED_TO_ROAD.f() + " (on-login) " + "(" + plot.getId().x + ";" + plot
|
||||
.getId().y + ")");
|
||||
@ -97,19 +93,13 @@ public abstract class EventUtil {
|
||||
|
||||
public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type,
|
||||
Location location, LazyBlock block, boolean notifyPerms) {
|
||||
PlotArea area = PlotSquared.get().getPlotAreaAbs(location);
|
||||
Plot plot;
|
||||
if (area != null) {
|
||||
plot = area.getPlot(location);
|
||||
} else {
|
||||
plot = null;
|
||||
}
|
||||
if (plot == null) {
|
||||
if (area == null) {
|
||||
PlotArea area = location.getPlotArea();
|
||||
assert area != null;
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
if (plot.isAdded(player.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
} else if (plot.isAdded(player.getUUID())) {
|
||||
return true;
|
||||
}
|
||||
switch (type) {
|
||||
case TELEPORT_OBJECT:
|
||||
@ -400,8 +390,6 @@ public abstract class EventUtil {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case PLACE_HANGING: // Handled elsewhere
|
||||
return true;
|
||||
case PLACE_MISC: {
|
||||
if (plot == null) {
|
||||
return Permissions
|
||||
|
@ -70,8 +70,8 @@ public class DelegateLocalBlockQueue extends LocalBlockQueue {
|
||||
return parent.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int y, String biome) {
|
||||
return parent.setBiome(x, y, biome);
|
||||
@Override public boolean setBiome(int x, int z, String biome) {
|
||||
return parent.setBiome(x, z, biome);
|
||||
}
|
||||
|
||||
@Override public String getWorld() {
|
||||
|
@ -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()
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user