mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Fix some issues I caused with Guice
This commit is contained in:
parent
2cfb646065
commit
d906a85095
@ -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>
|
||||||
|
@ -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());
|
||||||
|
|
||||||
|
@ -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,12 +193,12 @@ 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));
|
||||||
}
|
}
|
||||||
@ -211,8 +208,8 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
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,8 +385,7 @@ 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) {
|
||||||
@ -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,24 +428,20 @@ 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,
|
||||||
@ -461,8 +449,7 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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)");
|
||||||
|
@ -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<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(() -> {
|
||||||
|
@ -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,12 +66,6 @@ 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
|
||||||
*
|
*
|
||||||
@ -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
|
||||||
@ -240,7 +235,8 @@ public abstract class WorldUtil {
|
|||||||
|
|
||||||
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(
|
||||||
|
home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||||
@Override public void run(OutputStream output) {
|
@Override public void run(OutputStream output) {
|
||||||
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
|
||||||
File dat = getDat(plot.getWorldName());
|
File dat = getDat(plot.getWorldName());
|
||||||
@ -275,7 +271,7 @@ public abstract class WorldUtil {
|
|||||||
int brz = bot.getZ() >> 9;
|
int brz = bot.getZ() >> 9;
|
||||||
int trx = top.getX() >> 9;
|
int trx = top.getX() >> 9;
|
||||||
int trz = top.getZ() >> 9;
|
int trz = top.getZ() >> 9;
|
||||||
Set<BlockVector2> files = regionManager.getChunkChunks(bot.getWorldName());
|
Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
|
||||||
for (BlockVector2 mca : files) {
|
for (BlockVector2 mca : files) {
|
||||||
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
|
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
|
||||||
&& mca.getZ() <= trz) {
|
&& mca.getZ() <= trz) {
|
||||||
@ -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)
|
||||||
*
|
*
|
||||||
|
@ -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") {
|
||||||
|
Loading…
Reference in New Issue
Block a user