Search in sources :

Example 41 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class ClearTileEntity method run.

public static void run(ClearMob plugin, List<TileEntityType> list, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<TileEntity> e = new ArrayList<TileEntity>();
    for (World world : worlds) {
        for (TileEntity entity : world.getTileEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (TileEntity entity : e) {
            for (int i = 0; i <= list.size() - 1; i++) {
                if ((entity.getType().equals(list.get(i)))) {
                    entity.getLocation().removeBlock(Cause.source(Sponge.getPluginManager().fromInstance(plugin).get()).build());
                    removedentities++;
                }
            }
        }
    }
    feedback(plugin, src, removedentities);
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World)

Example 42 with World

use of org.spongepowered.api.world.World in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method placeBlock.

@Listener
public void placeBlock(ChangeBlockEvent event) {
    if (event.getCause().root() instanceof Player) {
        Player plr = (Player) event.getCause().root();
        if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Break) {
            BlockType t = event.getTransactions().get(0).getOriginal().getLocation().get().getBlock().getType();
            Location<World> location = event.getTransactions().get(0).getOriginal().getLocation().get();
            location.getBlock().toContainer().set(DataQuery.of("rock"), 1);
            //location.getBlock().with()
            if (validCrateBlocks.contains(t)) {
                //crateUtilities.recognizeChest(event.getTransactions().get(0).getOriginal().getLocation().get());
                if (event instanceof ChangeBlockEvent.Place) {
                    if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                        Optional<Object> tt = plr.getItemInHand(HandTypes.MAIN_HAND).get().toContainer().get(DataQuery.of("UnsafeData", "crateID"));
                        if (tt.isPresent()) {
                            String crateID = tt.get().toString();
                            if (!plr.hasPermission("huskycrates.tester")) {
                                event.setCancelled(true);
                                return;
                            }
                            if (!crateUtilities.physicalCrates.containsKey(location))
                                crateUtilities.physicalCrates.put(location, new PhysicalCrate(location, crateID, this));
                            crateUtilities.physicalCrates.get(location).createHologram();
                            updatePhysicalCrates();
                        }
                    }
                }
            } else {
                if (crateUtilities.physicalCrates.containsKey(location)) {
                    if (!plr.hasPermission("huskycrates.tester")) {
                        event.setCancelled(true);
                        return;
                    }
                    crateUtilities.flag = true;
                    crateUtilities.physicalCrates.get(location).as.remove();
                    crateUtilities.physicalCrates.remove(location);
                    updatePhysicalCrates();
                }
            }
        }
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) Player(org.spongepowered.api.entity.living.player.Player) BlockType(org.spongepowered.api.block.BlockType) JSONObject(org.json.JSONObject) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 43 with World

use of org.spongepowered.api.world.World in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameReloaded.

@Listener
public void gameReloaded(GameReloadEvent event) {
    for (World bit : Sponge.getServer().getWorlds()) {
        for (Entity ent : bit.getEntities()) {
            if (ent instanceof ArmorStand) {
                ArmorStand arm = (ArmorStand) ent;
                if (arm.getCreator().isPresent()) {
                    if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
                        arm.remove();
                    }
                }
            }
        }
    }
    langData = new SharedLangData("", "You won %a %R&rfrom a %C&r!", "&e%p just won %a %R&r&e from a %C&r!", "You need a %K&r to open this crate.");
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual())
            langData = new SharedLangData(conf.getNode("lang"));
        else
            logger.info("Using default lang settings.");
    } catch (IOException e) {
        e.printStackTrace();
        logger.warn("Lang load failed, using defaults.");
    }
    crateUtilities.generateVirtualCrates(crateConfig);
    CommentedConfigurationNode root = null;
    try {
        root = crateConfig.load();
        for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
            Location<World> ee;
            try {
                ee = node.getNode("location").getValue(TypeToken.of(Location.class));
            } catch (InvalidDataException err2) {
                logger.warn("Bug sponge developers about world UUIDs!");
                ee = new Location<World>(Sponge.getServer().getWorld(node.getNode("location", "WorldName").getString()).get(), node.getNode("location", "X").getDouble(), node.getNode("location", "Y").getDouble(), node.getNode("location", "Z").getDouble());
            }
            if (!crateUtilities.physicalCrates.containsKey(ee))
                crateUtilities.physicalCrates.put(ee, new PhysicalCrate(ee, node.getNode("crateID").getString(), HuskyCrates.instance));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
    crateUtilities.startParticleEffects();
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) IOException(java.io.IOException) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Example 44 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class VelocityEntitySpawner method sendRadial.

public static List<Entity> sendRadial(EntityType type, Living living, int amt, float speed, Cause cause) {
    Location<World> livingLocation = living.getLocation();
    Optional<EyeLocationProperty> optEyeLoc = living.getProperty(EyeLocationProperty.class);
    if (optEyeLoc.isPresent()) {
        Vector3d eyePosition = optEyeLoc.get().getValue();
        livingLocation = livingLocation.setPosition(eyePosition);
    }
    return sendRadial(type, livingLocation, amt, speed, cause);
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) World(org.spongepowered.api.world.World) EyeLocationProperty(org.spongepowered.api.data.property.entity.EyeLocationProperty)

Example 45 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class JungleRaidEffectProcessor method distributor.

private static void distributor(JungleRaidInstance inst) {
    FlagEffectData data = inst.getFlagData();
    boolean isSuddenDeath = inst.isSuddenDeath();
    if (isSuddenDeath) {
        data.amt = 100;
    }
    if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES) || inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET) || isSuddenDeath) {
        Vector3i bvMax = inst.getRegion().getMaximumPoint();
        Vector3i bvMin = inst.getRegion().getMinimumPoint();
        for (int i = 0; i < Probability.getRangedRandom(data.amt / 3, data.amt); i++) {
            Location<World> testLoc = new Location<>(inst.getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY(), Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
            if (testLoc.getBlockType() != BlockTypes.AIR)
                continue;
            if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || isSuddenDeath) {
                PrimedTNT explosive = (PrimedTNT) inst.getRegion().getExtent().createEntity(EntityTypes.PRIMED_TNT, testLoc.getPosition());
                explosive.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, random.nextDouble() * 2 * -1, random.nextDouble() * 2.0 - 1));
                explosive.offer(Keys.FUSE_DURATION, 20 * 4);
                // TODO used to have a 1/4 chance of creating fire
                inst.getRegion().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
            }
            if (inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET)) {
                PotionEffectType type = Probability.pickOneOf(Sponge.getRegistry().getAllOf(PotionEffectType.class));
                for (int ii = Probability.getRandom(5); ii > 0; --ii) {
                    ThrownPotion potion = (ThrownPotion) inst.getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, testLoc.getPosition());
                    potion.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, 0, random.nextDouble() * 2.0 - 1));
                    potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(PotionEffect.of(type, 1, type.isInstant() ? 1 : 20 * 10)));
                    inst.getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            }
            if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
                new ItemDropper(testLoc).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.SNOWBALL, Probability.getRandom(3))), SpawnTypes.PLUGIN);
            }
        }
        if (data.amt < 150 && Probability.getChance(inst.isFlagEnabled(JungleRaidFlag.SUPER) ? 9 : 25))
            ++data.amt;
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) ItemDropper(com.skelril.nitro.item.ItemDropper) Vector3d(com.flowpowered.math.vector.Vector3d) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) Vector3i(com.flowpowered.math.vector.Vector3i) ThrownPotion(org.spongepowered.api.entity.projectile.ThrownPotion) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Aggregations

World (org.spongepowered.api.world.World)81 Listener (org.spongepowered.api.event.Listener)24 Location (org.spongepowered.api.world.Location)23 Entity (org.spongepowered.api.entity.Entity)18 Player (org.spongepowered.api.entity.living.player.Player)18 Vector3i (com.flowpowered.math.vector.Vector3i)11 WorldService (com.skelril.skree.service.WorldService)11 BlockType (org.spongepowered.api.block.BlockType)10 ItemStack (org.spongepowered.api.item.inventory.ItemStack)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 ArrayList (java.util.ArrayList)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)7 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)6 Living (org.spongepowered.api.entity.living.Living)5 Monster (org.spongepowered.api.entity.living.monster.Monster)5 ItemDropper (com.skelril.nitro.item.ItemDropper)4 ModifierService (com.skelril.skree.service.ModifierService)4 IOException (java.io.IOException)4