mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 11:55:38 +01:00
Fix some issues I caused with Guice
This commit is contained in:
parent
2cfb646065
commit
d906a85095
@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.12.5</version>
|
||||
<version>6.0.0-SUPER-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -27,7 +27,6 @@ package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.location.Location;
|
||||
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.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
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.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -62,9 +58,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
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_ENTITY;
|
||||
@ -78,38 +72,8 @@ public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
|
||||
@Inject private WorldUtil worldUtil;
|
||||
@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) {
|
||||
return false;
|
||||
}
|
||||
@ -189,7 +153,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
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 BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
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.MathMan;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -102,6 +100,7 @@ import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.stream.Stream;
|
||||
@ -110,13 +109,10 @@ import java.util.stream.Stream;
|
||||
@Singleton
|
||||
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<>();
|
||||
|
||||
@Inject public BukkitUtil(@Nonnull final RegionManager regionManager) {
|
||||
super(regionManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -156,7 +152,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
*/
|
||||
@Nonnull public static Location adapt(@Nonnull final org.bukkit.Location location) {
|
||||
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) {
|
||||
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(),
|
||||
location.getPitch());
|
||||
MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()), location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,8 +177,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
* @return Bukkit location
|
||||
*/
|
||||
@Nonnull public static org.bukkit.Location adapt(@Nonnull final Location location) {
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(), location.getX(),
|
||||
location.getY(), location.getZ());
|
||||
return new org.bukkit.Location((World) location.getWorld().getPlatformWorld(),
|
||||
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,
|
||||
@Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)),
|
||||
x >> 4, z >> 4, true)
|
||||
PaperLib.getChunkAtAsync(Objects.requireNonNull(getWorld(world)), x >> 4, z >> 4, true)
|
||||
.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)
|
||||
.thenAccept(chunk -> ensureMainThread(chunkConsumer, chunk));
|
||||
}
|
||||
|
||||
private static <T> void ensureMainThread(@Nonnull final Consumer<T> consumer,
|
||||
@Nonnull final T value) {
|
||||
@Nonnull final T value) {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
consumer.accept(value);
|
||||
} else {
|
||||
Bukkit.getScheduler()
|
||||
.runTask(BukkitPlatform.getPlugin(BukkitPlatform.class), () -> consumer.accept(value));
|
||||
Bukkit.getScheduler().runTask(BukkitPlatform.getPlugin(BukkitPlatform.class),
|
||||
() -> consumer.accept(value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,8 +225,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
|
||||
@Override public boolean isBlockSame(@Nonnull final BlockState block1,
|
||||
@Nonnull final BlockState block2) {
|
||||
@Override
|
||||
public boolean isBlockSame(@Nonnull final BlockState block1, @Nonnull final BlockState block2) {
|
||||
if (block1.equals(block2)) {
|
||||
return true;
|
||||
}
|
||||
@ -242,19 +239,18 @@ public class BukkitUtil extends WorldUtil {
|
||||
return getWorld(worldName) != null;
|
||||
}
|
||||
|
||||
@Override public void getBiome(@Nonnull final String world, final int x,
|
||||
final int z, @Nonnull final Consumer<BiomeType> result) {
|
||||
@Override public void getBiome(@Nonnull final String world, final int x, final int z,
|
||||
@Nonnull final Consumer<BiomeType> result) {
|
||||
ensureLoaded(world, x, z,
|
||||
chunk -> result.accept(BukkitAdapter.adapt(getWorld(world).getBiome(x, z))));
|
||||
}
|
||||
|
||||
@Override @Nonnull public BiomeType getBiomeSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
@Override @Nonnull
|
||||
public BiomeType getBiomeSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
return BukkitAdapter.adapt(Objects.requireNonNull(getWorld(world)).getBiome(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHighestBlock(@Nonnull final String world, final int x, final int z,
|
||||
@Override public void getHighestBlock(@Nonnull final String world, final int x, final int z,
|
||||
@Nonnull final IntConsumer result) {
|
||||
ensureLoaded(world, x, z, chunk -> {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
@ -282,8 +278,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override @Nonnegative
|
||||
public int getHighestBlockSynchronous(@Nonnull final String world,
|
||||
final int x, final int z) {
|
||||
public int getHighestBlockSynchronous(@Nonnull final String world, final int x, final int z) {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
@ -305,8 +300,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
@Override @Nonnull public String[] getSignSynchronous(@Nonnull final Location location) {
|
||||
Block block = Objects.requireNonNull(getWorld(location.getWorldName()))
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
try {
|
||||
@ -323,8 +317,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public Location getSpawn(@Nonnull final String world) {
|
||||
@Override @Nonnull public Location getSpawn(@Nonnull final String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return Location
|
||||
.at(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(),
|
||||
@ -392,9 +385,8 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(@Nonnull final String worldName,
|
||||
@Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
public void setBiomes(@Nonnull final String worldName, @Nonnull final CuboidRegion region,
|
||||
@Nonnull final BiomeType biomeType) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == 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));
|
||||
}
|
||||
|
||||
@ -420,15 +413,14 @@ public class BukkitUtil extends WorldUtil {
|
||||
Bukkit.getWorld(world).refreshChunk(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBlock(@Nonnull final Location location,
|
||||
@Nonnull final Consumer<BlockState> result) {
|
||||
@Override public void getBlock(@Nonnull final Location location,
|
||||
@Nonnull final Consumer<BlockState> result) {
|
||||
ensureLoaded(location, chunk -> {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
result.accept(Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState());
|
||||
result.accept(Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType()))
|
||||
.getDefaultState());
|
||||
});
|
||||
}
|
||||
|
||||
@ -436,33 +428,28 @@ public class BukkitUtil extends WorldUtil {
|
||||
final World world = getWorld(location.getWorldName());
|
||||
final Block block = Objects.requireNonNull(world)
|
||||
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
return Objects.requireNonNull(BukkitAdapter
|
||||
.asBlockType(block.getType())).getDefaultState();
|
||||
return Objects.requireNonNull(BukkitAdapter.asBlockType(block.getType())).getDefaultState();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public double getHealth(@Nonnull final PlotPlayer player) {
|
||||
return Objects.requireNonNull(Bukkit
|
||||
.getPlayer(player.getUUID())).getHealth();
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getHealth();
|
||||
}
|
||||
|
||||
@Override @Nonnegative public int getFoodLevel(@Nonnull final PlotPlayer<?> player) {
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.getFoodLevel();
|
||||
return Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).getFoodLevel();
|
||||
}
|
||||
|
||||
@Override public void setHealth(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID()))
|
||||
.setHealth(health);
|
||||
@Override
|
||||
public void setHealth(@Nonnull final PlotPlayer<?> player, @Nonnegative final double health) {
|
||||
Objects.requireNonNull(Bukkit.getPlayer(player.getUUID())).setHealth(health);
|
||||
}
|
||||
|
||||
@Override public void setFoodLevel(@Nonnull final PlotPlayer<?> player,
|
||||
@Nonnegative final int foodLevel) {
|
||||
@Nonnegative final int foodLevel) {
|
||||
Bukkit.getPlayer(player.getUUID()).setFoodLevel(foodLevel);
|
||||
}
|
||||
|
||||
@Override @Nonnull
|
||||
public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
|
||||
@Override @Nonnull public Set<com.sk89q.worldedit.world.entity.EntityType> getTypesInCategory(
|
||||
@Nonnull final String category) {
|
||||
final Collection<Class<?>> allowedInterfaces = new HashSet<>();
|
||||
switch (category) {
|
||||
@ -567,11 +554,38 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override @Nonnegative
|
||||
public int getTileEntityCount(@Nonnull final String world,
|
||||
@Nonnull final BlockVector2 chunk) {
|
||||
public int getTileEntityCount(@Nonnull final String world, @Nonnull final BlockVector2 chunk) {
|
||||
return Objects.requireNonNull(getWorld(world)).
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ())
|
||||
.getTileEntities().length;
|
||||
getChunkAt(chunk.getBlockX(), chunk.getBlockZ()).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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
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.EntityCategory;
|
||||
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 final PlotAreaManager plotAreaManager;
|
||||
private final RegionManager regionManager;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Debug(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@Nonnull final RegionManager regionManager) {
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.regionManager = regionManager;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
@ -78,7 +79,7 @@ public class Debug extends SubCommand {
|
||||
final long start = System.currentTimeMillis();
|
||||
MainUtil.sendMessage(player, "Fetching loaded chunks...");
|
||||
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
|
||||
.currentThread().getName()));
|
||||
return true;
|
||||
|
@ -98,7 +98,7 @@ public class Trim extends SubCommand {
|
||||
if (ExpireManager.IMP != null) {
|
||||
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<>();
|
||||
MainUtil.sendMessage(null, " - MCA #: " + result.value1.size());
|
||||
MainUtil.sendMessage(null, " - CHUNKS: " + (result.value1.size() * 1024) + " (max)");
|
||||
|
@ -406,7 +406,7 @@ public class HybridUtils {
|
||||
return false;
|
||||
}
|
||||
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<>());
|
||||
}
|
||||
|
||||
|
@ -78,31 +78,6 @@ public abstract class RegionManager {
|
||||
*/
|
||||
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,
|
||||
final Runnable whenDone) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
|
@ -53,6 +53,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -65,20 +66,14 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
public abstract class WorldUtil {
|
||||
|
||||
private final RegionManager regionManager;
|
||||
|
||||
public WorldUtil(@Nonnull final RegionManager regionManager) {
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the biome in a region
|
||||
*
|
||||
* @param world World name
|
||||
* @param p1x Min X
|
||||
* @param p1z Min Z
|
||||
* @param p2x Max X
|
||||
* @param p2z Max Z
|
||||
* @param p1x Min X
|
||||
* @param p1z Min Z
|
||||
* @param p2x Max X
|
||||
* @param p2z Max Z
|
||||
* @param biome 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
|
||||
* @deprecated Use {@link #getHighestBlock(String, int, int, IntConsumer)}
|
||||
*/
|
||||
@Deprecated @Nonnegative
|
||||
public abstract int getHighestBlockSynchronous(@Nonnull String world, int x, int z);
|
||||
@Deprecated @Nonnegative public abstract int getHighestBlockSynchronous(@Nonnull String world,
|
||||
int x, int z);
|
||||
|
||||
/**
|
||||
* Set the text in a sign
|
||||
@ -232,81 +227,82 @@ public abstract class WorldUtil {
|
||||
/**
|
||||
* Refresh (resend) chunk to player. Usually after setting the biome
|
||||
*
|
||||
* @param x Chunk x location
|
||||
* @param z Chunk z location
|
||||
* @param x Chunk x location
|
||||
* @param z Chunk z location
|
||||
* @param world World of the chunk
|
||||
*/
|
||||
public abstract void refreshChunk(int x, int z, String world);
|
||||
|
||||
public void upload(@Nonnull final Plot plot, @Nullable final UUID uuid,
|
||||
@Nullable final String file, @Nonnull final RunnableVal<URL> whenDone) {
|
||||
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
@Override public void run(OutputStream output) {
|
||||
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
||||
File dat = getDat(plot.getWorldName());
|
||||
Location spawn = getSpawn(plot.getWorldName());
|
||||
if (dat != null) {
|
||||
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
|
||||
zos.putNextEntry(ze);
|
||||
try (NBTInputStream nis = new NBTInputStream(
|
||||
new GZIPInputStream(new FileInputStream(dat)))) {
|
||||
CompoundTag tag = (CompoundTag) nis.readNamedTag().getTag();
|
||||
CompoundTag data = (CompoundTag) tag.getValue().get("Data");
|
||||
Map<String, Tag> map = ReflectionUtils.getMap(data.getValue());
|
||||
map.put("SpawnX", new IntTag(home.getX()));
|
||||
map.put("SpawnY", new IntTag(home.getY()));
|
||||
map.put("SpawnZ", new IntTag(home.getZ()));
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
try (NBTOutputStream out = new NBTOutputStream(
|
||||
new GZIPOutputStream(baos, true))) {
|
||||
//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);
|
||||
}
|
||||
plot.getHome(
|
||||
home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
@Override public void run(OutputStream output) {
|
||||
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
||||
File dat = getDat(plot.getWorldName());
|
||||
Location spawn = getSpawn(plot.getWorldName());
|
||||
if (dat != null) {
|
||||
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
|
||||
zos.putNextEntry(ze);
|
||||
try (NBTInputStream nis = new NBTInputStream(
|
||||
new GZIPInputStream(new FileInputStream(dat)))) {
|
||||
CompoundTag tag = (CompoundTag) nis.readNamedTag().getTag();
|
||||
CompoundTag data = (CompoundTag) tag.getValue().get("Data");
|
||||
Map<String, Tag> map = ReflectionUtils.getMap(data.getValue());
|
||||
map.put("SpawnX", new IntTag(home.getX()));
|
||||
map.put("SpawnY", new IntTag(home.getY()));
|
||||
map.put("SpawnZ", new IntTag(home.getZ()));
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
try (NBTOutputStream out = new NBTOutputStream(
|
||||
new GZIPOutputStream(baos, true))) {
|
||||
//TODO Find what this should be called
|
||||
out.writeNamedTag("Schematic????", tag);
|
||||
}
|
||||
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) {
|
||||
@ -328,6 +324,32 @@ public abstract class WorldUtil {
|
||||
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)
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ ext {
|
||||
}
|
||||
|
||||
def ver = "6.0.0"
|
||||
def versuffix = "SUPER-SNAPSHOT"
|
||||
def versuffix = "-SUPER-SNAPSHOT"
|
||||
ext {
|
||||
if (project.hasProperty("versionsuffix")) {
|
||||
versuffix = "-$versionsuffix"
|
||||
@ -125,6 +125,8 @@ subprojects { subproject ->
|
||||
dependencies {
|
||||
include(dependency("org.json:json:20200518"))
|
||||
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("org.json", "com.plotsquared.json") {
|
||||
|
Loading…
Reference in New Issue
Block a user