Search in sources :

Example 1 with IBlockPlacerListener

use of org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacerListener in project RedProtect by FabioZumbi12.

the class AWEListener method regenRegion.

public static void regenRegion(final br.net.fabiozumbi12.RedProtect.Bukkit.Region r, final World w, final Location p1, final Location p2, final int delay, final CommandSender sender, final boolean remove) {
    Bukkit.getScheduler().scheduleSyncDelayedTask(RedProtect.get(), () -> {
        if (RPUtil.stopRegen) {
            return;
        }
        CuboidSelection csel = new CuboidSelection(w, p1, p2);
        Region wreg;
        try {
            wreg = csel.getRegionSelector().getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
            return;
        }
        AsyncWorldEditBukkit aweMain = (AsyncWorldEditBukkit) Bukkit.getPluginManager().getPlugin("AsyncWorldEdit");
        IBlockPlacer bPlacer = aweMain.getBlockPlacer();
        final IBlockPlacerListener listener = new IBlockPlacerListener() {

            @Override
            public void jobAdded(IJobEntry job) {
            /*if (job.getPlayer().getName().equals("redprotect")){
                        String name = job.getName();
                        //job.addStateChangedListener(stateListener);
                        RedProtect.get().logger.warning("JobAdded: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.isTaskDone());
                    }*/
            }

            @Override
            public void jobRemoved(IJobEntry job) {
                if (job.getPlayer().getName().equals("redprotect")) {
                    String name = job.getName();
                    // job.addStateChangedListener(stateListener);
                    if (RPConfig.getBool("purge.regen.awe-logs") && job.isTaskDone()) {
                        RedProtect.get().logger.sucess("JobDone: " + name + " of region " + r.getName() + " - " + job.getStatus() + ": " + job.getStatusString());
                    }
                }
            }
        };
        bPlacer.addListener(listener);
        AsyncEditSessionFactory factory = (AsyncEditSessionFactory) WorldEdit.getInstance().getEditSessionFactory();
        EditSession ess = factory.getEditSession(wreg.getWorld(), -1);
        eSessions.put(r.getID(), ess);
        int delayCount = 1 + delay / 10;
        if (sender != null) {
            if (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
                RPLang.sendMessage(sender, "[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
            } else {
                RPLang.sendMessage(sender, "[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
            }
        } else {
            if (AsyncWorld.wrap(wreg.getWorld(), new PlayerManager(aweMain).createFakePlayer("redprotect", UUID.randomUUID())).regenerate(wreg, ess)) {
                RedProtect.get().logger.warning("[" + delayCount + "]" + " &aRegion " + r.getID().split("@")[0] + " regenerated with success!");
            } else {
                RedProtect.get().logger.warning("[" + delayCount + "]" + " &cTheres an error when regen the region " + r.getID().split("@")[0] + "!");
            }
        }
        if (remove) {
            RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(r.getWorld()));
        }
        if (RPConfig.getInt("purge.regen.stop-server-every") > 0 && delayCount > RPConfig.getInt("purge.regen.stop-server-every")) {
            Bukkit.getScheduler().cancelTasks(RedProtect.get());
            RedProtect.get().rm.saveAll();
            Bukkit.getServer().shutdown();
        }
    }, delay);
}
Also used : AsyncWorldEditBukkit(org.primesoft.asyncworldedit.AsyncWorldEditBukkit) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) PlayerManager(org.primesoft.asyncworldedit.playerManager.PlayerManager) IBlockPlacer(org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacer) IBlockPlacerListener(org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacerListener) IJobEntry(org.primesoft.asyncworldedit.api.blockPlacer.entries.IJobEntry) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) AsyncEditSessionFactory(org.primesoft.asyncworldedit.worldedit.AsyncEditSessionFactory)

Aggregations

EditSession (com.sk89q.worldedit.EditSession)1 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)1 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)1 Region (com.sk89q.worldedit.regions.Region)1 AsyncWorldEditBukkit (org.primesoft.asyncworldedit.AsyncWorldEditBukkit)1 IBlockPlacer (org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacer)1 IBlockPlacerListener (org.primesoft.asyncworldedit.api.blockPlacer.IBlockPlacerListener)1 IJobEntry (org.primesoft.asyncworldedit.api.blockPlacer.entries.IJobEntry)1 PlayerManager (org.primesoft.asyncworldedit.playerManager.PlayerManager)1 AsyncEditSessionFactory (org.primesoft.asyncworldedit.worldedit.AsyncEditSessionFactory)1