Search in sources :

Example 6 with EditSession

use of com.sk89q.worldedit.EditSession in project Skree by Skelril.

the class CursedMineInstance method ghost.

public void ghost(final Player player, BlockType blockID) {
    if (Probability.getChance(player.getLocation().getBlockY())) {
        if (Probability.getChance(2)) {
            switch(Probability.getRandom(6)) {
                case 1:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Caspher the friendly ghost drops some bread."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.BREAD, Probability.getRandom(16))), SpawnTypes.DROPPED_ITEM);
                    break;
                case 2:
                    player.sendMessage(Text.of(TextColors.YELLOW, "COOKIE gives you a cookie."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.COOKIE)), SpawnTypes.DROPPED_ITEM);
                    break;
                case 3:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Caspher the friendly ghost appears."));
                    List<ItemStack> caspherLoot = new ArrayList<>();
                    for (int i = 0; i < 8; i++) {
                        caspherLoot.add(newItemStack(ItemTypes.IRON_INGOT, Probability.getRandom(64)));
                        caspherLoot.add(newItemStack(ItemTypes.GOLD_INGOT, Probability.getRandom(64)));
                        caspherLoot.add(newItemStack(ItemTypes.DIAMOND, Probability.getRandom(64)));
                    }
                    new ItemDropper(player.getLocation()).dropStacks(caspherLoot, SpawnTypes.DROPPED_ITEM);
                    break;
                case 4:
                    player.sendMessage(Text.of(TextColors.YELLOW, "John gives you a new jacket."));
                    new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.LEATHER_CHESTPLATE)), SpawnTypes.DROPPED_ITEM);
                    break;
                case 5:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Tim teleports items to you."));
                    getContained(Item.class).forEach(i -> i.setLocation(player.getLocation()));
                    // Add in some extra drops just in case the loot wasn't very juicy
                    List<ItemStack> teleportLootExtras = Lists.newArrayList(newItemStack(ItemTypes.IRON_INGOT, Probability.getRandom(64)), newItemStack(ItemTypes.GOLD_INGOT, Probability.getRandom(64)), newItemStack(ItemTypes.DIAMOND, Probability.getRandom(64)));
                    new ItemDropper(player.getLocation()).dropStacks(teleportLootExtras, SpawnTypes.DROPPED_ITEM);
                    break;
                case 6:
                    player.sendMessage(Text.of(TextColors.YELLOW, "Dan gives you a sparkling touch."));
                    ItemType sparkingType;
                    switch(Probability.getRandom(3)) {
                        case 1:
                            sparkingType = ItemTypes.IRON_INGOT;
                            break;
                        case 2:
                            sparkingType = ItemTypes.GOLD_INGOT;
                            break;
                        case 3:
                            sparkingType = ItemTypes.DIAMOND;
                            break;
                        default:
                            sparkingType = ItemTypes.REDSTONE;
                            break;
                    }
                    TimedRunnable inventoryFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new InventoryCurse(sparkingType, 64).accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 10);
                    inventoryFX.setTask(Task.builder().execute(inventoryFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(inventoryFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                default:
                    break;
            }
        } else {
            switch(Probability.getRandom(11)) {
                case 1:
                    if (Probability.getChance(4)) {
                        if (blockID == BlockTypes.DIAMOND_ORE) {
                            hitList.addPlayer(player);
                            player.sendMessage(Text.of(TextColors.RED, "You ignite fumes in the air!"));
                            EditSession ess = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new WorldResolver(getRegion().getExtent()).getWorldEditWorld(), -1);
                            try {
                                Vector3d pos = player.getLocation().getPosition();
                                ess.fillXZ(new Vector(pos.getX(), pos.getY(), pos.getZ()), WorldEdit.getInstance().getBaseBlockFactory().getBaseBlock(BlockID.FIRE), 20, 20, true);
                            } catch (MaxChangedBlocksException ignored) {
                            }
                            for (int i = Probability.getRandom(24) + 20; i > 0; --i) {
                                final boolean untele = i == 11;
                                Task.builder().execute(() -> {
                                    if (untele) {
                                        recordSystem.revertByPlayer(player.getUniqueId());
                                        hitList.remPlayer(player);
                                    }
                                    if (!contains(player)) {
                                        return;
                                    }
                                    Vector3i pos = new PositionRandomizer(3).createPosition3i(player.getLocation().getPosition());
                                    player.getLocation().getExtent().triggerExplosion(Explosion.builder().radius(3).location(player.getLocation().setPosition(pos.toDouble().add(.5, .5, .5))).shouldDamageEntities(true).canCauseFire(true).build(), Cause.source(SkreePlugin.container()).build());
                                }).delayTicks(12 * i).submit(SkreePlugin.inst());
                            }
                        } else {
                            hitList.addPlayer(player);
                            // player.chat("Who's a good ghost?!?!");
                            Task.builder().execute(() -> {
                                // player.chat("Don't hurt me!!!");
                                Task.builder().execute(() -> {
                                    // player.chat("Nooooooooooo!!!");
                                    TimedRunnable cannonFX = new TimedRunnable<>(new IntegratedRunnable() {

                                        @Override
                                        public boolean run(int times) {
                                            new CannonCurse().accept(player);
                                            return true;
                                        }

                                        @Override
                                        public void end() {
                                        }
                                    }, 120);
                                    cannonFX.setTask(Task.builder().execute(cannonFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                                    activeTask.merge(player, Lists.newArrayList(cannonFX.getTask()), (a, b) -> {
                                        a.addAll(b);
                                        return a;
                                    });
                                }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
                            }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
                        }
                        break;
                    }
                case 2:
                    player.sendMessage(Text.of(TextColors.RED, "Dave attaches to your soul..."));
                    for (int i = 20; i > 0; --i) {
                        Task.builder().execute(() -> {
                            if (!contains(player)) {
                                return;
                            }
                            player.offer(Keys.HEALTH, Probability.getRandom(Probability.getRandom(player.get(Keys.MAX_HEALTH).get())) - 1);
                        }).delayTicks(12 * i).submit(SkreePlugin.inst());
                    }
                    break;
                case 3:
                    player.sendMessage(Text.of(TextColors.RED, "George plays with fire, sadly too close to you."));
                    TimedRunnable fireFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new FireCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 90);
                    fireFX.setTask(Task.builder().execute(fireFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(fireFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 4:
                    player.sendMessage(Text.of(TextColors.RED, "Simon says pick up sticks."));
                    List<ItemStack> sticks = new ArrayList<>();
                    for (int i = 0; i < player.getInventory().size() * 1.5; i++) {
                        sticks.add(newItemStack(ItemTypes.STICK, 64));
                    }
                    new ItemDropper(player.getLocation()).dropStacks(sticks, SpawnTypes.DROPPED_ITEM);
                    break;
                case 5:
                    player.sendMessage(Text.of(TextColors.RED, "Ben dumps out your backpack."));
                    TimedRunnable butterFingerFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new ButterFingersCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 20);
                    butterFingerFX.setTask(Task.builder().execute(butterFingerFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(butterFingerFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 6:
                    player.sendMessage(Text.of(TextColors.RED, "Merlin attacks with a mighty rage!"));
                    TimedRunnable merlinFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new MerlinCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 40);
                    merlinFX.setTask(Task.builder().execute(merlinFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(merlinFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 7:
                    player.sendMessage(Text.of(TextColors.RED, "Dave tells everyone that your mining!"));
                    MessageChannel.TO_PLAYERS.send(Text.of(TextColors.GOLD, player.getName() + " is mining in the cursed mine!!!"));
                    break;
                case 8:
                    player.sendMessage(Text.of(TextColors.RED, "Dave likes your food."));
                    hitList.addPlayer(player);
                    TimedRunnable starvationFX = new TimedRunnable<>(new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            new StarvationCurse().accept(player);
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    }, 40);
                    starvationFX.setTask(Task.builder().execute(starvationFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                    activeTask.merge(player, Lists.newArrayList(starvationFX.getTask()), (a, b) -> {
                        a.addAll(b);
                        return a;
                    });
                    break;
                case 9:
                    player.sendMessage(Text.of(TextColors.RED, "Hallow declares war on YOU!"));
                    for (int i = 0; i < Probability.getRangedRandom(10, 30); i++) {
                        Blaze blaze = (Blaze) getRegion().getExtent().createEntity(EntityTypes.BLAZE, player.getLocation().getPosition());
                        blaze.setTarget(player);
                        getRegion().getExtent().spawnEntity(blaze, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
                    }
                    break;
                case 10:
                    player.sendMessage(Text.of(TextColors.RED, "A legion of hell hounds appears!"));
                    for (int i = 0; i < Probability.getRangedRandom(10, 30); i++) {
                        Wolf wolf = (Wolf) getRegion().getExtent().createEntity(EntityTypes.WOLF, player.getLocation().getPosition());
                        wolf.setTarget(player);
                        getRegion().getExtent().spawnEntity(wolf, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
                    }
                    break;
                case 11:
                    if (blockID == BlockTypes.EMERALD_ORE) {
                        player.sendMessage(Text.of(TextColors.RED, "Dave got a chemistry set!"));
                        hitList.addPlayer(player);
                        TimedRunnable deadlyPotionFX = new TimedRunnable<>(new IntegratedRunnable() {

                            @Override
                            public boolean run(int times) {
                                new DeadlyPotionCurse().accept(player);
                                return true;
                            }

                            @Override
                            public void end() {
                            }
                        }, 2 * 60 * 30);
                        deadlyPotionFX.setTask(Task.builder().execute(deadlyPotionFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                        activeTask.merge(player, Lists.newArrayList(deadlyPotionFX.getTask()), (a, b) -> {
                            a.addAll(b);
                            return a;
                        });
                    } else {
                        player.sendMessage(Text.of(TextColors.RED, "Dave says hi, that's not good."));
                        hitList.addPlayer(player);
                        TimedRunnable attackOfDaveFX = new TimedRunnable<>(new IntegratedRunnable() {

                            @Override
                            public boolean run(int times) {
                                new AttackOfDaveCurse().accept(player);
                                return true;
                            }

                            @Override
                            public void end() {
                            }
                        }, 2 * 60 * 30);
                        attackOfDaveFX.setTask(Task.builder().execute(attackOfDaveFX).interval(500, TimeUnit.MILLISECONDS).submit(SkreePlugin.inst()));
                        activeTask.merge(player, Lists.newArrayList(attackOfDaveFX.getTask()), (a, b) -> {
                            a.addAll(b);
                            return a;
                        });
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : PositionRandomizer(com.skelril.nitro.position.PositionRandomizer) ItemDropper(com.skelril.nitro.item.ItemDropper) WorldResolver(com.skelril.skree.service.internal.zone.WorldResolver) ItemType(org.spongepowered.api.item.ItemType) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) Item(org.spongepowered.api.entity.Item) Wolf(org.spongepowered.api.entity.living.animal.Wolf) Vector(com.sk89q.worldedit.Vector) TimedRunnable(com.skelril.nitro.time.TimedRunnable) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) Vector3d(com.flowpowered.math.vector.Vector3d) Blaze(org.spongepowered.api.entity.living.monster.Blaze) Vector3i(com.flowpowered.math.vector.Vector3i) EditSession(com.sk89q.worldedit.EditSession) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 7 with EditSession

use of com.sk89q.worldedit.EditSession in project AreaShop by NLthijs48.

the class WorldEditHandler5 method saveRegionBlocks.

@Override
public boolean saveRegionBlocks(File file, GeneralRegionInterface regionInterface) {
    boolean result = true;
    ProtectedRegion region = regionInterface.getRegion();
    // Get the origin and size of the region
    Vector origin = new Vector(region.getMinimumPoint().getBlockX(), region.getMinimumPoint().getBlockY(), region.getMinimumPoint().getBlockZ());
    Vector size = (new Vector(region.getMaximumPoint().getBlockX(), region.getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockZ()).subtract(origin)).add(new Vector(1, 1, 1));
    EditSession editSession = new EditSession(new BukkitWorld(regionInterface.getWorld()), pluginInterface.getConfig().getInt("maximumBlocks"));
    // Save the schematic
    editSession.enableQueue();
    CuboidClipboard clipboard = new CuboidClipboard(size, origin);
    clipboard.copy(editSession);
    Exception otherException = null;
    try {
        SchematicFormat.MCEDIT.save(clipboard, file);
    } catch (DataException | IOException e) {
        otherException = e;
    }
    if (otherException != null) {
        pluginInterface.getLogger().warning("Failed to save schematic for region " + regionInterface.getName());
        pluginInterface.debugI(ExceptionUtils.getStackTrace(otherException));
        result = false;
    }
    editSession.flushQueue();
    return result;
}
Also used : DataException(com.sk89q.worldedit.data.DataException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) CuboidClipboard(com.sk89q.worldedit.CuboidClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) Vector(com.sk89q.worldedit.Vector) DataException(com.sk89q.worldedit.data.DataException) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) IOException(java.io.IOException)

Example 8 with EditSession

use of com.sk89q.worldedit.EditSession in project RedProtect by FabioZumbi12.

the class WEListener 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 = null;
        try {
            wreg = csel.getRegionSelector().getRegion();
        } catch (IncompleteRegionException e1) {
            e1.printStackTrace();
        }
        EditSession esession = new EditSession(LocalWorldAdapter.adapt(wreg.getWorld()), -1);
        eSessions.put(r.getID(), esession);
        int delayCount = 1 + delay / 10;
        if (sender != null) {
            if (wreg.getWorld().regenerate(wreg, esession)) {
                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 (wreg.getWorld().regenerate(wreg, esession)) {
                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 : CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) IncompleteRegionException(com.sk89q.worldedit.IncompleteRegionException) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession)

Example 9 with EditSession

use of com.sk89q.worldedit.EditSession in project RedProtect by FabioZumbi12.

the class WEListener method pasteWithWE.

public static void pasteWithWE(Player p, File file) {
    World world = p.getWorld();
    Location loc = p.getLocation();
    EditSession es = new EditSession(new BukkitWorld(world), 999999999);
    try {
        CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
        cc.paste(es, new com.sk89q.worldedit.Vector(loc.getX(), loc.getY(), loc.getZ()), false);
    } catch (DataException | IOException | MaxChangedBlocksException e) {
        e.printStackTrace();
    }
}
Also used : DataException(com.sk89q.worldedit.world.DataException) CuboidClipboard(com.sk89q.worldedit.CuboidClipboard) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) EditSession(com.sk89q.worldedit.EditSession) IOException(java.io.IOException) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) World(org.bukkit.World) Location(org.bukkit.Location) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException)

Example 10 with EditSession

use of com.sk89q.worldedit.EditSession in project RedProtect by FabioZumbi12.

the class WEListener method regenRegion.

public static void regenRegion(final br.net.fabiozumbi12.RedProtect.Sponge.Region r, final World w, final Location<World> p1, final Location<World> p2, final int delay, final CommandSource sender, final boolean remove) {
    Sponge.getScheduler().createSyncExecutor(RedProtect.get().container).schedule(() -> {
        if (RPUtil.stopRegen) {
            return;
        }
        Region wreg = new CuboidRegion(new Vector(p1.getX(), p1.getY(), p1.getZ()), new Vector(p2.getX(), p2.getY(), p2.getZ())).getFaces();
        SpongeWorld ws = SpongeWorldEdit.inst().getWorld(w);
        EditSession esession = new EditSessionFactory().getEditSession(ws, -1);
        eSessions.put(r.getID(), esession);
        int delayCount = 1 + delay / 10;
        if (sender != null) {
            if (ws.regenerate(wreg, esession)) {
                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 (ws.regenerate(wreg, esession)) {
                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()).get());
        }
    }, delay, TimeUnit.MILLISECONDS);
}
Also used : SpongeWorld(com.sk89q.worldedit.sponge.SpongeWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) EditSession(com.sk89q.worldedit.EditSession) Vector(com.sk89q.worldedit.Vector) EditSessionFactory(com.sk89q.worldedit.EditSessionFactory)

Aggregations

EditSession (com.sk89q.worldedit.EditSession)14 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)7 Vector (com.sk89q.worldedit.Vector)7 Region (com.sk89q.worldedit.regions.Region)6 IOException (java.io.IOException)6 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)5 IncompleteRegionException (com.sk89q.worldedit.IncompleteRegionException)4 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)4 EditSessionBuilder (com.boydti.fawe.util.EditSessionBuilder)3 CuboidClipboard (com.sk89q.worldedit.CuboidClipboard)3 Vector3i (com.flowpowered.math.vector.Vector3i)2 DataException (com.sk89q.worldedit.data.DataException)2 BlockArrayClipboard (com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 ForwardExtentCopy (com.sk89q.worldedit.function.operation.ForwardExtentCopy)2 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)2 Closer (com.sk89q.worldedit.util.io.Closer)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 EditSessionFactory (com.sk89q.worldedit.EditSessionFactory)1