Fix some issues I caused with Guice

This commit is contained in:
dordsor21 2020-07-24 12:18:36 +01:00
parent 2cfb646065
commit d906a85095
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
9 changed files with 181 additions and 203 deletions

View File

@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>com.plotsquared</groupId> <groupId>com.plotsquared</groupId>
<artifactId>PlotSquared-Core</artifactId> <artifactId>PlotSquared-Core</artifactId>
<version>5.12.5</version> <version>6.0.0-SUPER-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -27,7 +27,6 @@ package com.plotsquared.bukkit.util;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.location.PlotLoc; import com.plotsquared.core.location.PlotLoc;
@ -40,13 +39,10 @@ import com.plotsquared.core.queue.ScopedQueueCoordinator;
import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.RegionUtil;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -62,9 +58,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Semaphore;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL;
import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY;
@ -78,38 +72,8 @@ public class BukkitRegionManager extends RegionManager {
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName()); LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
@Inject private WorldUtil worldUtil;
@Inject private GlobalBlockQueue blockQueue; @Inject private GlobalBlockQueue blockQueue;
@Override public Set<BlockVector2> getChunkChunks(String world) {
Set<BlockVector2> chunks = super.getChunkChunks(world);
if (Bukkit.isPrimaryThread()) {
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
chunks.add(loc);
}
} else {
final Semaphore semaphore = new Semaphore(1);
try {
semaphore.acquire();
Bukkit.getScheduler()
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> {
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world))
.getLoadedChunks()) {
BlockVector2 loc =
BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
chunks.add(loc);
}
semaphore.release();
});
semaphore.acquireUninterruptibly();
} catch (final Exception e) {
e.printStackTrace();
}
}
return chunks;
}
@Override public boolean handleClear(Plot plot, Runnable whenDone, PlotManager manager) { @Override public boolean handleClear(Plot plot, Runnable whenDone, PlotManager manager) {
return false; return false;
} }
@ -189,7 +153,7 @@ public class BukkitRegionManager extends RegionManager {
return count; return count;
} }
@Override @Inject public boolean regenerateRegion(final Location pos1, final Location pos2, @Override public boolean regenerateRegion(final Location pos1, final Location pos2,
final boolean ignoreAugment, final Runnable whenDone) { final boolean ignoreAugment, final Runnable whenDone) {
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld()); final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());

View File

@ -25,7 +25,6 @@
*/ */
package com.plotsquared.bukkit.util; package com.plotsquared.bukkit.util;
import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.player.BukkitPlayer;
@ -36,7 +35,6 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.BlockUtil; import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.StringComparison; import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
@ -102,6 +100,7 @@ import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Semaphore;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -110,13 +109,10 @@ import java.util.stream.Stream;
@Singleton @Singleton
public class BukkitUtil extends WorldUtil { public class BukkitUtil extends WorldUtil {
private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName()); private static final Logger logger =
LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName());
private final Collection<BlockType> tileEntityTypes = new HashSet<>(); private final Collection<BlockType> tileEntityTypes = new HashSet<>();
@Inject public BukkitUtil(@Nonnull final RegionManager regionManager) {
super(regionManager);
}
/** /**
* Get a {@link PlotPlayer} from an {@link OfflinePlayer}. If the player is * Get a {@link PlotPlayer} from an {@link OfflinePlayer}. If the player is
* online, it returns a complete player. If the player is offline, it creates * online, it returns a complete player. If the player is offline, it creates
@ -156,7 +152,8 @@ public class BukkitUtil extends WorldUtil {
*/ */
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) { @Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
MathMan.roundInt(location.getZ()));
} }
/** /**
@ -168,8 +165,8 @@ public class BukkitUtil extends WorldUtil {
*/ */
@Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) { @Nonnull public static Location adaptComplete(@Nonnull final org.bukkit.Location location) {
return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()), return Location.at(com.plotsquared.bukkit.util.BukkitWorld.of(location.getWorld()),
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
location.getPitch()); MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch());
} }
/** /**
@ -180,8 +177,8 @@ public class BukkitUtil extends WorldUtil {
* @return Bukkit location * @return Bukkit location
*/ */
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) { @Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(), return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(),
location.getY(), location.getZ()); location.getX(), location.getY(), location.getZ());
} }
/** /**
@ -196,23 +193,23 @@ public class BukkitUtil extends WorldUtil {
private static void ensureLoaded(@Nonnull final String world, final int x, final int z, private static void ensureLoaded(@Nonnull final String world, final int x, final int z,
@Nonnull final Consumer<Chunk> chunkConsumer) { @Nonnull final Consumer<Chunk> chunkConsumer) {
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
x >> 4, z >> 4, true)
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk)); .thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
} }
private static void ensureLoaded(@Nonnull final Location location, @Nonnull final Consumer<Chunk> chunkConsumer) { private static void ensureLoaded(@Nonnull final Location location,
@Nonnull final Consumer<Chunk> chunkConsumer) {
PaperLib.getChunkAtAsync(adapt(location), true) PaperLib.getChunkAtAsync(adapt(location), true)
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk)); .thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
} }
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer, private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer,
@Nonnull final T value) { @Nonnull final T value) {
if (Bukkit.isPrimaryThread()) { if (Bukkit.isPrimaryThread()) {
consumer.accept(value); consumer.accept(value);
} else { } else {
Bukkit.getScheduler() Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class),
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value)); () -> consumer.accept(value));
} }
} }
@ -228,8 +225,8 @@ public class BukkitUtil extends WorldUtil {
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid)); return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
} }
@Override public boolean isBlockSame(@Nonnull final BlockState block1, @Override
@Nonnull final BlockState block2) { public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
if (block1.equals(block2)) { if (block1.equals(block2)) {
return true; return true;
} }
@ -242,19 +239,18 @@ public class BukkitUtil extends WorldUtil {
return getWorld(worldName) != null; return getWorld(worldName) != null;
} }
@Override public void getBiome(@Nonnull final String world, final int x, @Override public void getBiome(@Nonnull final String world, final int x, final int z,
final int z, @Nonnull final Consumer<BiomeType> result) { @Nonnull final Consumer<BiomeType> result) {
ensureLoaded(world, x, z, ensureLoaded(world, x, z,
chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z)))); chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
} }
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world, @Override @Nonnull
final int x, final int z) { public BiomeType getBiomeSynchronous(@Nonnull final String world, final int x, final int z) {
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z)); return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z));
} }
@Override @Override public void getHighestBlock(@Nonnull final String world, final int x, final int z,
public void getHighestBlock(@Nonnull final String world, final int x, final int z,
@Nonnull final IntConsumer result) { @Nonnull final IntConsumer result) {
ensureLoaded(world, x, z, chunk -> { ensureLoaded(world, x, z, chunk -> {
final World bukkitWorld = Objects.requireNonNull(getWorld(world)); final World bukkitWorld = Objects.requireNonNull(getWorld(world));
@ -282,8 +278,7 @@ public class BukkitUtil extends WorldUtil {
} }
@Override @Nonnegative @Override @Nonnegative
public int getHighestBlockSynchronous(@Nonnull final String world, public int getHighestBlockSynchronous(@Nonnull final String world, final int x, final int z) {
final int x, final int z) {
final World bukkitWorld = Objects.requireNonNull(getWorld(world)); final World bukkitWorld = Objects.requireNonNull(getWorld(world));
// Skip top and bottom block // Skip top and bottom block
int air = 1; int air = 1;
@ -305,8 +300,7 @@ public class BukkitUtil extends WorldUtil {
return bukkitWorld.getMaxHeight() - 1; return bukkitWorld.getMaxHeight() - 1;
} }
@Override @Nonnull @Override @Nonnull public String[] getSignSynchronous(@Nonnull final Location location) {
public String[] getSignSynchronous(@Nonnull final Location location) {
Block block = Objects.requireNonNull(getWorld(location.getWorldName())) Block block = Objects.requireNonNull(getWorld(location.getWorldName()))
.getBlockAt(location.getX(), location.getY(), location.getZ()); .getBlockAt(location.getX(), location.getY(), location.getZ());
try { try {
@ -323,8 +317,7 @@ public class BukkitUtil extends WorldUtil {
return new String[0]; return new String[0];
} }
@Override @Nonnull @Override @Nonnull public Location getSpawn(@Nonnull final String world) {
public Location getSpawn(@Nonnull final String world) {
final org.bukkit.Location temp = getWorld(world).getSpawnLocation(); final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
return Location return Location
.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), .at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(),
@ -392,9 +385,8 @@ public class BukkitUtil extends WorldUtil {
} }
@Override @Override
public void setBiomes(@Nonnull final String worldName, public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region,
@Nonnull final CuboidRegion region, @Nonnull final BiomeType biomeType) {
@Nonnull final BiomeType biomeType) {
final World world = getWorld(worldName); final World world = getWorld(worldName);
if (world == null) { if (world == null) {
logger.warn("[P2] An error occured while setting the biome because the world was null", logger.warn("[P2] An error occured while setting the biome because the world was null",
@ -412,7 +404,8 @@ public class BukkitUtil extends WorldUtil {
} }
} }
@Override @Nonnull public com.sk89q.worldedit.world.World getWeWorld(@Nonnull final String world) { @Override @Nonnull
public com.sk89q.worldedit.world.World getWeWorld(@Nonnull final String world) {
return new BukkitWorld(Bukkit.getWorld(world)); return new BukkitWorld(Bukkit.getWorld(world));
} }
@ -420,15 +413,14 @@ public class BukkitUtil extends WorldUtil {
Bukkit.getWorld(world).refreshChunk(x, z); Bukkit.getWorld(world).refreshChunk(x, z);
} }
@Override @Override public void getBlock(@Nonnull final Location location,
public void getBlock(@Nonnull final Location location, @Nonnull final Consumer<BlockState> result) {
@Nonnull final Consumer<BlockState> result) {
ensureLoaded(location, chunk -> { ensureLoaded(location, chunk -> {
final World world = getWorld(location.getWorldName()); final World world = getWorld(location.getWorldName());
final Block block = Objects.requireNonNull(world) final Block block = Objects.requireNonNull(world)
.getBlockAt(location.getX(), location.getY(), location.getZ()); .getBlockAt(location.getX(), location.getY(), location.getZ());
result.accept(Objects.requireNonNull(BukkitAdapter result.accept(Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType()))
.asBlockType(block.getType())).getDefaultState()); .getDefaultState());
}); });
} }
@ -436,33 +428,28 @@ public class BukkitUtil extends WorldUtil {
final World world = getWorld(location.getWorldName()); final World world = getWorld(location.getWorldName());
final Block block = Objects.requireNonNull(world) final Block block = Objects.requireNonNull(world)
.getBlockAt(location.getX(), location.getY(), location.getZ()); .getBlockAt(location.getX(), location.getY(), location.getZ());
return Objects.requireNonNull(BukkitAdapter return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
.asBlockType(block.getType())).getDefaultState();
} }
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) { @Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
return Objects.requireNonNull(Bukkit return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getHealth();
.getPlayer(player.getUUID())).getHealth();
} }
@Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) { @Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) {
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())) return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getFoodLevel();
.getFoodLevel();
} }
@Override public void setHealth(@Nonnull final PlotPlayer<?> player, @Override
@Nonnegative final double health) { public void setHealth(@Nonnull final PlotPlayer<?> player, @Nonnegative final double health) {
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())) Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).setHealth(health);
.setHealth(health);
} }
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player, @Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player,
@Nonnegative final int foodLevel) { @Nonnegative final int foodLevel) {
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel); Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
} }
@Override @Nonnull @Override @Nonnull public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
@Nonnull final String category) { @Nonnull final String category) {
final Collection<Class<?>> allowedInterfaces = new HashSet<>(); final Collection<Class<?>> allowedInterfaces = new HashSet<>();
switch (category) { switch (category) {
@ -567,11 +554,38 @@ public class BukkitUtil extends WorldUtil {
} }
@Override @Nonnegative @Override @Nonnegative
public int getTileEntityCount(@Nonnull final String world, public int getTileEntityCount(@Nonnull final String world, @Nonnull final BlockVector2 chunk) {
@Nonnull final BlockVector2 chunk) {
return Objects.requireNonNull(getWorld(world)). return Objects.requireNonNull(getWorld(world)).
getChunkAt(chunk.getBlockX(), chunk.getBlockZ()) getChunkAt(chunk.getBlockX(), chunk.getBlockZ()).getTileEntities().length;
.getTileEntities().length; }
@Override public Set<BlockVector2> getChunkChunks(String world) {
Set<BlockVector2> chunks = super.getChunkChunks(world);
if (Bukkit.isPrimaryThread()) {
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world)).getLoadedChunks()) {
BlockVector2 loc = BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
chunks.add(loc);
}
} else {
final Semaphore semaphore = new Semaphore(1);
try {
semaphore.acquire();
Bukkit.getScheduler()
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> {
for (Chunk chunk : Objects.requireNonNull(Bukkit.getWorld(world))
.getLoadedChunks()) {
BlockVector2 loc =
BlockVector2.at(chunk.getX() >> 5, chunk.getZ() >> 5);
chunks.add(loc);
}
semaphore.release();
});
semaphore.acquireUninterruptibly();
} catch (final Exception e) {
e.printStackTrace();
}
}
return chunks;
} }
} }

View File

@ -33,6 +33,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.entity.EntityCategory; import com.plotsquared.core.util.entity.EntityCategory;
import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.PlotQuery;
@ -57,12 +58,12 @@ public class Debug extends SubCommand {
private static final Logger logger = LoggerFactory.getLogger("P2/" + Debug.class.getSimpleName()); private static final Logger logger = LoggerFactory.getLogger("P2/" + Debug.class.getSimpleName());
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final RegionManager regionManager; private final WorldUtil worldUtil;
@Inject public Debug(@Nonnull final PlotAreaManager plotAreaManager, @Inject public Debug(@Nonnull final PlotAreaManager plotAreaManager,
@Nonnull final RegionManager regionManager) { @Nonnull final WorldUtil worldUtil) {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.regionManager = regionManager; this.worldUtil = worldUtil;
} }
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) { @Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
@ -78,7 +79,7 @@ public class Debug extends SubCommand {
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
MainUtil.sendMessage(player, "Fetching loaded chunks..."); MainUtil.sendMessage(player, "Fetching loaded chunks...");
TaskManager.runTaskAsync(() -> MainUtil.sendMessage(player, TaskManager.runTaskAsync(() -> MainUtil.sendMessage(player,
"Loaded chunks: " + this.regionManager.getChunkChunks(player.getLocation().getWorldName()).size() + "(" + ( "Loaded chunks: " + this.worldUtil.getChunkChunks(player.getLocation().getWorldName()).size() + "(" + (
System.currentTimeMillis() - start) + "ms) using thread: " + Thread System.currentTimeMillis() - start) + "ms) using thread: " + Thread
.currentThread().getName())); .currentThread().getName()));
return true; return true;

View File

@ -98,7 +98,7 @@ public class Trim extends SubCommand {
if (ExpireManager.IMP != null) { if (ExpireManager.IMP != null) {
plots.removeAll(ExpireManager.IMP.getPendingExpired()); plots.removeAll(ExpireManager.IMP.getPendingExpired());
} }
result.value1 = new HashSet<>(PlotSquared.platform().getRegionManager().getChunkChunks(world)); result.value1 = new HashSet<>(PlotSquared.platform().getWorldUtil().getChunkChunks(world));
result.value2 = new HashSet<>(); result.value2 = new HashSet<>();
MainUtil.sendMessage(null, " - MCA #: " + result.value1.size()); MainUtil.sendMessage(null, " - MCA #: " + result.value1.size());
MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)"); MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)");

View File

@ -406,7 +406,7 @@ public class HybridUtils {
return false; return false;
} }
HybridUtils.UPDATE = true; HybridUtils.UPDATE = true;
Set<BlockVector2> regions = this.regionManager.getChunkChunks(area.getWorldName()); Set<BlockVector2> regions = this.worldUtil.getChunkChunks(area.getWorldName());
return scheduleRoadUpdate(area, regions, extend, new HashSet<>()); return scheduleRoadUpdate(area, regions, extend, new HashSet<>());
} }

View File

@ -78,31 +78,6 @@ public abstract class RegionManager {
*/ */
public abstract int[] countEntities(Plot plot); public abstract int[] countEntities(Plot plot);
public Set<BlockVector2> getChunkChunks(String world) {
File folder =
new File(PlotSquared.platform().getWorldContainer(), world + File.separator + "region");
File[] regionFiles = folder.listFiles();
if (regionFiles == null) {
throw new RuntimeException(
"Could not find worlds folder: " + folder + " ? (no read access?)");
}
HashSet<BlockVector2> chunks = new HashSet<>();
for (File file : regionFiles) {
String name = file.getName();
if (name.endsWith("mca")) {
String[] split = name.split("\\.");
try {
int x = Integer.parseInt(split[1]);
int z = Integer.parseInt(split[2]);
BlockVector2 loc = BlockVector2.at(x, z);
chunks.add(loc);
} catch (NumberFormatException ignored) {
}
}
}
return chunks;
}
public void deleteRegionFiles(final String world, final Collection<BlockVector2> chunks, public void deleteRegionFiles(final String world, final Collection<BlockVector2> chunks,
final Runnable whenDone) { final Runnable whenDone) {
TaskManager.runTaskAsync(() -> { TaskManager.runTaskAsync(() -> {

View File

@ -53,6 +53,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -65,20 +66,14 @@ import java.util.zip.ZipOutputStream;
public abstract class WorldUtil { public abstract class WorldUtil {
private final RegionManager regionManager;
public WorldUtil(@Nonnull final RegionManager regionManager) {
this.regionManager = regionManager;
}
/** /**
* Set the biome in a region * Set the biome in a region
* *
* @param world World name * @param world World name
* @param p1x Min X * @param p1x Min X
* @param p1z Min Z * @param p1z Min Z
* @param p2x Max X * @param p2x Max X
* @param p2z Max Z * @param p2z Max Z
* @param biome Biome * @param biome Biome
*/ */
public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) { public static void setBiome(String world, int p1x, int p1z, int p2x, int p2z, BiomeType biome) {
@ -196,8 +191,8 @@ public abstract class WorldUtil {
* @return Result * @return Result
* @deprecated Use {@link #getHighestBlock(String, int, int, IntConsumer)} * @deprecated Use {@link #getHighestBlock(String, int, int, IntConsumer)}
*/ */
@Deprecated @Nonnegative @Deprecated @Nonnegative public abstract int getHighestBlockSynchronous(@Nonnull String world,
public abstract int getHighestBlockSynchronous(@Nonnull String world, int x, int z); int x, int z);
/** /**
* Set the text in a sign * Set the text in a sign
@ -232,81 +227,82 @@ public abstract class WorldUtil {
/** /**
* Refresh (resend) chunk to player. Usually after setting the biome * Refresh (resend) chunk to player. Usually after setting the biome
* *
* @param x Chunk x location * @param x Chunk x location
* @param z Chunk z location * @param z Chunk z location
* @param world World of the chunk * @param world World of the chunk
*/ */
public abstract void refreshChunk(int x, int z, String world); public abstract void refreshChunk(int x, int z, String world);
public void upload(@Nonnull final Plot plot, @Nullable final UUID uuid, public void upload(@Nonnull final Plot plot, @Nullable final UUID uuid,
@Nullable final String file, @Nonnull final RunnableVal<URL> whenDone) { @Nullable final String file, @Nonnull final RunnableVal<URL> whenDone) {
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() { plot.getHome(
@Override public void run(OutputStream output) { home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
try (final ZipOutputStream zos = new ZipOutputStream(output)) { @Override public void run(OutputStream output) {
File dat = getDat(plot.getWorldName()); try (final ZipOutputStream zos = new ZipOutputStream(output)) {
Location spawn = getSpawn(plot.getWorldName()); File dat = getDat(plot.getWorldName());
if (dat != null) { Location spawn = getSpawn(plot.getWorldName());
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName()); if (dat != null) {
zos.putNextEntry(ze); ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
try (NBTInputStream nis = new NBTInputStream( zos.putNextEntry(ze);
new GZIPInputStream(new FileInputStream(dat)))) { try (NBTInputStream nis = new NBTInputStream(
CompoundTag tag = (CompoundTag) nis.readNamedTag().getTag(); new GZIPInputStream(new FileInputStream(dat)))) {
CompoundTag data = (CompoundTag) tag.getValue().get("Data"); CompoundTag tag = (CompoundTag) nis.readNamedTag().getTag();
Map<String, Tag> map = ReflectionUtils.getMap(data.getValue()); CompoundTag data = (CompoundTag) tag.getValue().get("Data");
map.put("SpawnX", new IntTag(home.getX())); Map<String, Tag> map = ReflectionUtils.getMap(data.getValue());
map.put("SpawnY", new IntTag(home.getY())); map.put("SpawnX", new IntTag(home.getX()));
map.put("SpawnZ", new IntTag(home.getZ())); map.put("SpawnY", new IntTag(home.getY()));
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { map.put("SpawnZ", new IntTag(home.getZ()));
try (NBTOutputStream out = new NBTOutputStream( try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
new GZIPOutputStream(baos, true))) { try (NBTOutputStream out = new NBTOutputStream(
//TODO Find what this should be called new GZIPOutputStream(baos, true))) {
out.writeNamedTag("Schematic????", tag); //TODO Find what this should be called
} out.writeNamedTag("Schematic????", tag);
zos.write(baos.toByteArray());
}
}
}
setSpawn(spawn);
byte[] buffer = new byte[1024];
for (Plot current : plot.getConnectedPlots()) {
Location bot = current.getBottomAbs();
Location top = current.getTopAbs();
int brx = bot.getX() >> 9;
int brz = bot.getZ() >> 9;
int trx = top.getX() >> 9;
int trz = top.getZ() >> 9;
Set<BlockVector2> files = regionManager.getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
&& mca.getZ() <= trz) {
final File file =
getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
if (file != null) {
//final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry(
"world" + File.separator + "region" + File.separator
+ name);
zos.putNextEntry(ze);
try (FileInputStream in = new FileInputStream(file)) {
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
} }
zos.closeEntry(); zos.write(baos.toByteArray());
} }
} }
} }
setSpawn(spawn);
byte[] buffer = new byte[1024];
for (Plot current : plot.getConnectedPlots()) {
Location bot = current.getBottomAbs();
Location top = current.getTopAbs();
int brx = bot.getX() >> 9;
int brz = bot.getZ() >> 9;
int trx = top.getX() >> 9;
int trz = top.getZ() >> 9;
Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
&& mca.getZ() <= trz) {
final File file =
getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
if (file != null) {
//final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry(
"world" + File.separator + "region" + File.separator
+ name);
zos.putNextEntry(ze);
try (FileInputStream in = new FileInputStream(file)) {
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
}
zos.closeEntry();
}
}
}
}
zos.closeEntry();
zos.flush();
zos.finish();
} catch (IOException e) {
e.printStackTrace();
} }
zos.closeEntry();
zos.flush();
zos.finish();
} catch (IOException e) {
e.printStackTrace();
} }
} }, whenDone));
}, whenDone));
} }
@Nullable final File getDat(@Nonnull final String world) { @Nullable final File getDat(@Nonnull final String world) {
@ -328,6 +324,32 @@ public abstract class WorldUtil {
return null; return null;
} }
public Set<BlockVector2> getChunkChunks(String world) {
File folder =
new File(PlotSquared.platform().getWorldContainer(), world + File.separator + "region");
File[] regionFiles = folder.listFiles();
if (regionFiles == null) {
throw new RuntimeException(
"Could not find worlds folder: " + folder + " ? (no read access?)");
}
HashSet<BlockVector2> chunks = new HashSet<>();
for (File file : regionFiles) {
String name = file.getName();
if (name.endsWith("mca")) {
String[] split = name.split("\\.");
try {
int x = Integer.parseInt(split[1]);
int z = Integer.parseInt(split[2]);
BlockVector2 loc = BlockVector2.at(x, z);
chunks.add(loc);
} catch (NumberFormatException ignored) {
}
}
}
return chunks;
}
/** /**
* Check if two blocks are the same type) * Check if two blocks are the same type)
* *

View File

@ -31,7 +31,7 @@ ext {
} }
def ver = "6.0.0" def ver = "6.0.0"
def versuffix = "SUPER-SNAPSHOT" def versuffix = "-SUPER-SNAPSHOT"
ext { ext {
if (project.hasProperty("versionsuffix")) { if (project.hasProperty("versionsuffix")) {
versuffix = "-$versionsuffix" versuffix = "-$versionsuffix"
@ -125,6 +125,8 @@ subprojects { subproject ->
dependencies { dependencies {
include(dependency("org.json:json:20200518")) include(dependency("org.json:json:20200518"))
include(dependency("net.kyori:text-api:3.0.2")) include(dependency("net.kyori:text-api:3.0.2"))
include(dependency("javax.inject:javax.inject:1"))
include(dependency("aopalliance:aopalliance:1.0"))
} }
relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib") relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
relocate("org.json", "com.plotsquared.json") { relocate("org.json", "com.plotsquared.json") {