Search in sources :

Example 71 with World

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

the class WorldServiceImpl method onPlayerJoin.

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        Player player = event.getTargetEntity();
        UUID uuid = player.getUniqueId();
        World world = player.getWorld();
        Record1<Timestamp> result = create.select(WORLDS.CREATED_AT).from(WORLDS).where(WORLDS.NAME.equal(world.getName())).fetchOne();
        Timestamp worldCreationTimestamp = result.getValue(WORLDS.CREATED_AT);
        long worldCreationTime = 0;
        if (worldCreationTimestamp != null) {
            worldCreationTime = worldCreationTimestamp.getTime();
        }
        if (worldCreationTime > lastPlayerLogin.remove(uuid)) {
            Location<World> spawn = getEffectWrapper(MainWorldWrapper.class).get().getPrimaryWorld().getSpawnLocation();
            player.setLocation(spawn);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) Player(org.spongepowered.api.entity.living.player.Player) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) World(org.spongepowered.api.world.World) Timestamp(java.sql.Timestamp) Listener(org.spongepowered.api.event.Listener)

Example 72 with World

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

the class SkyWarsInstance method spawnChickens.

private void spawnChickens() {
    Vector3i bvMax = getRegion().getMaximumPoint();
    Vector3i bvMin = getRegion().getMinimumPoint();
    for (int i = 0; i < getPlayers(PARTICIPANT).size(); ++i) {
        Location<World> testLoc = new Location<>(getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY() - 10, Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
        Vector2d testPos = new Vector2d(testLoc.getX(), testLoc.getZ());
        Vector2d originPos = new Vector2d(startingLocation.getX(), startingLocation.getZ());
        if (testPos.distanceSquared(originPos) >= 70 * 70) {
            --i;
            continue;
        }
        Chicken chicken = (Chicken) testLoc.getExtent().createEntity(EntityTypes.CHICKEN, testLoc.getPosition());
        chicken.offer(Keys.PERSISTS, false);
        testLoc.getExtent().spawnEntity(chicken, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    }
}
Also used : Vector2d(com.flowpowered.math.vector.Vector2d) Vector3i(com.flowpowered.math.vector.Vector3i) Chicken(org.spongepowered.api.entity.living.animal.Chicken) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 73 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 74 with World

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

the class CrateUtilities method particleRunner.

private void particleRunner() {
    if (flag)
        return;
    try {
        ArrayList<Location<World>> invalidLocations = new ArrayList<>();
        HashSet<World> invalidLocationWorlds = new HashSet<>();
        for (Location<World> b : physicalCrates.keySet()) {
            PhysicalCrate c = physicalCrates.get(b);
            if (c.vc.crateBlockType != c.location.getBlock().getType() && c.location.getExtent().isLoaded() && c.location.getExtent().getChunk(c.location.getChunkPosition()).isPresent()) {
                if (c.location.getExtent().getChunk(c.location.getChunkPosition()).get().isLoaded()) {
                    invalidLocations.add(c.location);
                    invalidLocationWorlds.add(c.location.getExtent());
                    continue;
                }
            }
            c.runParticles();
        }
        for (World w : invalidLocationWorlds) {
            for (Entity e : w.getEntities()) {
                if (invalidLocations.contains(e.getLocation()) && e.getType() != EntityTypes.ARMOR_STAND) {
                    //System.out.println("woah");
                    invalidLocations.remove(e.getLocation());
                    physicalCrates.get(e.getLocation()).runParticles();
                }
            }
        }
        for (Location<World> l : invalidLocations) {
            PhysicalCrate c = physicalCrates.get(l);
            HuskyCrates.instance.logger.warn("Removing crate that no longer exists! " + c.location.getPosition().toString());
            c.as.remove();
            physicalCrates.remove(l);
            flag = true;
        }
    } catch (Exception e) {
    }
    if (flag)
        HuskyCrates.instance.updatePhysicalCrates();
}
Also used : Entity(org.spongepowered.api.entity.Entity) World(org.spongepowered.api.world.World) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Location(org.spongepowered.api.world.Location)

Example 75 with World

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

the class HuskyCrates method crateInteract.

@Listener
public void crateInteract(InteractBlockEvent.Secondary.MainHand event) {
    //pp.getInventory().offer(ItemStack.builder().fromContainer(ss.toContainer().set(DataQuery.of("UnsafeDamage"),3)).build());*/
    if (!event.getTargetBlock().getLocation().isPresent())
        return;
    Location<World> blk = event.getTargetBlock().getLocation().get();
    //System.out.println(blk.getBlock().getType());
    if (validCrateBlocks.contains(blk.getBlockType())) {
        Player plr = (Player) event.getCause().root();
        if (crateUtilities.physicalCrates.containsKey(blk)) {
            String crateType = crateUtilities.physicalCrates.get(blk).vc.id;
            VirtualCrate vc = crateUtilities.getVirtualCrate(crateType);
            crateUtilities.physicalCrates.get(blk).createHologram();
            if (vc.crateBlockType == blk.getBlockType()) {
                event.setCancelled(true);
            } else {
                return;
            }
            //crateUtilities.recognizeChest(te.getLocation());
            if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                ItemStack inhand = plr.getItemInHand(HandTypes.MAIN_HAND).get();
                if (inhand.getItem() == vc.getKeyType()) {
                    if (inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).isPresent()) {
                        String id = inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).get().toString();
                        if (id.equals(crateType)) {
                            if (!plr.hasPermission("huskycrates.tester")) {
                                if (inhand.getQuantity() == 1)
                                    plr.setItemInHand(HandTypes.MAIN_HAND, null);
                                else {
                                    ItemStack tobe = inhand.copy();
                                    tobe.setQuantity(tobe.getQuantity() - 1);
                                    plr.setItemInHand(HandTypes.MAIN_HAND, tobe);
                                }
                            }
                            Task.Builder upcoming = scheduler.createTaskBuilder();
                            upcoming.execute(() -> {
                                crateUtilities.launchCrateForPlayer(crateType, plr, this);
                            }).delayTicks(1).submit(this);
                            return;
                        }
                    }
                }
            }
            plr.playSound(SoundTypes.BLOCK_ANVIL_LAND, blk.getPosition(), 0.3);
            try {
                plr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(vc.langData.formatter(vc.langData.prefix + vc.langData.noKeyMessage, null, plr, vc, null)));
            } catch (Exception e) {
                plr.sendMessage(Text.of(TextColors.RED, "Critical crate failure, contact the administrator. (Admins, check console!)"));
                e.printStackTrace();
            }
        }
    }
}
Also used : VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) Player(org.spongepowered.api.entity.living.player.Player) Task(org.spongepowered.api.scheduler.Task) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

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