Use WorldEdit API for area cleanup instead
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3ef681e839
commit
e68326cb87
@ -44,3 +44,6 @@ public class PlayerChecker implements Listener
|
||||
event.setQuitMessage(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// todo: entity drop cancel
|
@ -1,6 +1,7 @@
|
||||
package wtf.beatrice.limbomanager.listeners;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -11,10 +12,13 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -22,14 +26,12 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import wtf.beatrice.limbomanager.Cache;
|
||||
import wtf.beatrice.limbomanager.LimboManager;
|
||||
import wtf.beatrice.limbomanager.objects.AreaCleanerRunnable;
|
||||
import wtf.beatrice.limbomanager.objects.Coordinates;
|
||||
import wtf.beatrice.limbomanager.utils.LocationUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerTeleporter implements Listener
|
||||
{
|
||||
@ -114,17 +116,29 @@ public class PlayerTeleporter implements Listener
|
||||
islandSpawnLocation.getWorld().getMaxHeight(),
|
||||
islandSpawnLocation.getZ() + maxRange);
|
||||
|
||||
LimboManager.getInstance().getLogger().info("Player " + playerName + " quit, clearing region...");
|
||||
|
||||
// set the area as being "cleaned up".
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
String cleanUpID = "cleanup-" + randomUUID.toString();
|
||||
Cache.playerIslands.put(cleanUpID, Cache.playerIslands.get(playerName));
|
||||
World weWorld = BukkitAdapter.adapt(islandSpawnLocation.getWorld());
|
||||
try(EditSession editSession = WorldEdit.getInstance().newEditSession(weWorld))
|
||||
{
|
||||
BlockState air = BukkitAdapter.adapt(Material.AIR.createBlockData());
|
||||
|
||||
BlockVector3 min = BlockVector3.at(startFrom.getBlockX(), startFrom.getBlockY(), startFrom.getBlockZ());
|
||||
BlockVector3 max = BlockVector3.at(endAt.getBlockX(), endAt.getBlockY(), endAt.getBlockZ());
|
||||
CuboidRegion cuboidRegion = new CuboidRegion(weWorld, min, max);
|
||||
editSession.setBlocks(cuboidRegion, air);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(LimboManager.getInstance(), () -> {
|
||||
|
||||
LimboManager.getInstance().getLogger().info("Region for " + playerName + " is now available again.");
|
||||
Cache.playerIslands.remove(playerName);
|
||||
|
||||
AreaCleanerRunnable cleanerRunnable = new AreaCleanerRunnable(startFrom, endAt, playerName, cleanUpID);
|
||||
cleanerRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(LimboManager.getInstance(),
|
||||
cleanerRunnable,
|
||||
20L,1L);
|
||||
}, 60 * 20L);
|
||||
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ import wtf.beatrice.limbomanager.LimboManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated // this works, but it's too slow. (fast-async)worldedit's api has a far better way of handling it.
|
||||
public class AreaCleanerRunnable implements Runnable
|
||||
{
|
||||
public BukkitTask task;
|
||||
@ -73,97 +74,5 @@ public class AreaCleanerRunnable implements Runnable
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int locationsDone = 0;
|
||||
|
||||
for(int x = min.getBlockX(); x < max.getBlockX(); x++) {
|
||||
for (int y = min.getBlockY(); y < max.getBlockY(); y++) {
|
||||
for (int z = min.getBlockZ(); z < max.getBlockZ(); z++) {
|
||||
|
||||
if(locationsDone == blocksPerRun)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
blocksList.add(new Location(min.getWorld(), x, y, z));
|
||||
locationsDone++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(blocksList.isEmpty())
|
||||
{
|
||||
// we finished, free the location and cancel the task.
|
||||
Cache.playerIslands.remove(playerName); // todo: what if player rejoins in the meanwhile
|
||||
LimboManager.getInstance().getLogger().info("finished cleaning area for " + playerName);
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < blocksPerRun; i++)
|
||||
{
|
||||
if(i >= blocksList.size())
|
||||
{
|
||||
// we finished, free the location and cancel the task.
|
||||
Cache.playerIslands.remove(playerName); // todo: what if player rejoins in the meanwhile
|
||||
LimboManager.getInstance().getLogger().info("finished cleaning area for " + playerName);
|
||||
task.cancel();
|
||||
break;
|
||||
}
|
||||
|
||||
Location loc = blocksList.get(i);
|
||||
|
||||
Bukkit.getScheduler().runTask(LimboManager.getInstance(), () ->
|
||||
{
|
||||
LimboManager.getInstance().getLogger().info("c: " + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ());
|
||||
loc.getBlock().setType(Material.AIR);
|
||||
});
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*for(int i = 0; i < blocksPerRun; i++)
|
||||
{
|
||||
|
||||
// sync block write
|
||||
Bukkit.getScheduler().runTask(LimboManager.getInstance(), () ->
|
||||
{
|
||||
LimboManager.getInstance().getLogger().info("c: " + current.getBlockX() + " " + current.getBlockY() + " " + current.getBlockZ());
|
||||
current.getBlock().setType(Material.AIR);
|
||||
|
||||
// update current coordinates
|
||||
if(current.getBlockX() < max.getBlockX())
|
||||
{
|
||||
current.setX(current.getBlockX() + 1);
|
||||
}
|
||||
else {
|
||||
current.setX(min.getBlockX());
|
||||
if(current.getBlockY() < max.getBlockY())
|
||||
{
|
||||
current.setY(max.getBlockY() + 1);
|
||||
} else {
|
||||
current.setY(min.getBlockY());
|
||||
if(current.getBlockZ() < max.getBlockZ())
|
||||
{
|
||||
current.setZ(max.getBlockZ() + 1);
|
||||
} else {
|
||||
// we finished, free the location and cancel the task.
|
||||
Cache.playerIslands.remove(playerName); // todo: what if player rejoins in the meanwhile
|
||||
LimboManager.getInstance().getLogger().info("finished cleaning area for " + playerName);
|
||||
task.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user