|
|
|
@ -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));
|
|
|
|
|
Cache.playerIslands.remove(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);
|
|
|
|
|
|
|
|
|
|
}, 60 * 20L);
|
|
|
|
|
|
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AreaCleanerRunnable cleanerRunnable = new AreaCleanerRunnable(startFrom, endAt, playerName, cleanUpID);
|
|
|
|
|
cleanerRunnable.task = Bukkit.getScheduler().runTaskTimerAsynchronously(LimboManager.getInstance(),
|
|
|
|
|
cleanerRunnable,
|
|
|
|
|
20L,1L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|