Search in sources :

Example 1 with ArmorStand

use of org.spongepowered.api.entity.living.ArmorStand 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 2 with ArmorStand

use of org.spongepowered.api.entity.living.ArmorStand in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onPlayerInteract.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEntityEvent e, @Root Player p) {
    Entity ent = e.getTargetEntity();
    Location<World> l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (!canInteract(p, r)) {
        e.setCancelled(true);
    }
    if (r != null) {
        return;
    }
    if (ent instanceof Minecart || ent instanceof Boat) {
        if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
    }
    if (ent instanceof Hanging || ent instanceof ArmorStand) {
        if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
    }
    if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "interact") && !p.hasPermission("redprotect.world.bypass") && (!(ent instanceof Player))) {
        e.setCancelled(true);
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Example 3 with ArmorStand

use of org.spongepowered.api.entity.living.ArmorStand in project RedProtect by FabioZumbi12.

the class RPMine18 method onEntityDamage.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e, @First Entity e2) {
    Entity e1 = e.getTargetEntity();
    Location<World> loc = e1.getLocation();
    Player damager = null;
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Player) {
            damager = (Player) proj.getShooter();
        }
    } else if (e2 instanceof Player) {
        damager = (Player) e2;
    }
    Region r1 = RedProtect.get().rm.getTopRegion(loc);
    if (r1 == null) {
        // global flags
        if (e1 instanceof ArmorStand) {
            if (e2 instanceof Player) {
                if (!RedProtect.get().cfgs.getGlobalFlag(loc.getExtent().getName(), "build")) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
        return;
    }
    if (e1 instanceof ArmorStand) {
        if (r1 != null && !r1.canBuild(damager)) {
            e.setCancelled(true);
            RPLang.sendMessage(damager, "blocklistener.region.cantbreak");
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Example 4 with ArmorStand

use of org.spongepowered.api.entity.living.ArmorStand in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method postGameStart.

@Listener(order = Order.POST)
public void postGameStart(GameStartedServerEvent event) {
    Sponge.getScheduler().createTaskBuilder().async().execute(new Consumer<Task>() {

        @Override
        public void accept(Task task) {
            try {
                JSONObject obj = JsonReader.readJsonFromUrl("https://api.github.com/repos/codehusky/HuskyCrates-Sponge/releases");
                String[] thisVersion = pC.getVersion().get().split("\\.");
                String[] remoteVersion = obj.getJSONArray("releases").getJSONObject(0).getString("tag_name").replace("v", "").split("\\.");
                for (int i = 0; i < Math.min(remoteVersion.length, thisVersion.length); i++) {
                    if (!thisVersion[i].equals(remoteVersion[i])) {
                        if (Integer.parseInt(thisVersion[i]) > Integer.parseInt(remoteVersion[i])) {
                            //we're ahead
                            logger.warn("----------------------------------------------------");
                            logger.warn("Running unreleased version. (Developer build?)");
                            logger.warn("----------------------------------------------------");
                        } else {
                            //we're behind
                            logger.warn("----------------------------------------------------");
                            logger.warn("Your version of HuskyCrates is out of date!");
                            logger.warn("Your version: v" + pC.getVersion().get());
                            logger.warn("Latest version: " + obj.getJSONArray("releases").getJSONObject(0).getString("tag_name"));
                            logger.warn("Update here: https://goo.gl/hgtPMR");
                            logger.warn("----------------------------------------------------");
                        }
                        return;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }).submit(this);
    Sponge.getScheduler().createTaskBuilder().execute(new Consumer<Task>() {

        @Override
        public void accept(Task task) {
            logger.info("Deleting existing armor stands...");
            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();
                            }
                        }
                    }
                }
            }
            logger.info("Initalizing config...");
            if (!crateUtilities.hasInitalizedVirtualCrates) {
                crateUtilities.generateVirtualCrates(crateConfig);
            }
            // doublecheck
            crateUtilities.hasInitalizedVirtualCrates = true;
            logger.info("Done initalizing config.");
            logger.info("Populating physical crates...");
            CommentedConfigurationNode root = null;
            try {
                root = crateConfig.load();
                double max = root.getNode("positions").getChildrenList().size();
                double count = 0;
                for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
                    count++;
                    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));
                    logger.info("PROGRESS: " + Math.round((count / max) * 100) + "%");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ObjectMappingException e) {
                e.printStackTrace();
            }
            crateUtilities.startParticleEffects();
            logger.info("Done populating physical crates.");
            logger.info("Initalization complete.");
        }
    }).delayTicks(1).submit(this);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Task(org.spongepowered.api.scheduler.Task) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) IOException(java.io.IOException) World(org.spongepowered.api.world.World) Consumer(java.util.function.Consumer) JSONObject(org.json.JSONObject) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) Location(org.spongepowered.api.world.Location) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Example 5 with ArmorStand

use of org.spongepowered.api.entity.living.ArmorStand in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onProjectileHit.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onProjectileHit(CollideEntityEvent event, @Root Projectile proj) {
    RedProtect.get().logger.debug("entity", "Is CollideEntityEvent(onProjectileHit) event.");
    RedProtect.get().logger.debug("entity", "Projectile: " + proj.getType().getName());
    if (RedProtect.get().rm.getTopRegion(proj.getLocation()) != null)
        return;
    for (Entity ent : event.getEntities()) {
        RedProtect.get().logger.debug("entity", "Entity: " + ent.getType().getName());
        if (proj.getShooter() instanceof Player) {
            Player p = (Player) proj.getShooter();
            if (ent instanceof Player) {
                if (!p.equals(ent) && !RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Animal || ent instanceof Villager || ent instanceof Golem || ent instanceof Ambient) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Monster) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                    return;
                }
            }
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass")) {
                    event.setCancelled(true);
                }
            }
        } else {
            if (ent instanceof Hanging || ent instanceof ArmorStand) {
                if (!RedProtect.get().cfgs.getGlobalFlag(ent.getWorld().getName(), "entity-block-damage")) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : Golem(org.spongepowered.api.entity.living.golem.Golem) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Ambient(org.spongepowered.api.entity.living.Ambient) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Listener(org.spongepowered.api.event.Listener)

Aggregations

Entity (org.spongepowered.api.entity.Entity)7 ArmorStand (org.spongepowered.api.entity.living.ArmorStand)7 Listener (org.spongepowered.api.event.Listener)6 World (org.spongepowered.api.world.World)5 Player (org.spongepowered.api.entity.living.player.Player)4 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)3 Hanging (org.spongepowered.api.entity.hanging.Hanging)3 IOException (java.io.IOException)2 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)2 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)2 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)2 Ambient (org.spongepowered.api.entity.living.Ambient)2 Villager (org.spongepowered.api.entity.living.Villager)2 Animal (org.spongepowered.api.entity.living.animal.Animal)2 Golem (org.spongepowered.api.entity.living.golem.Golem)2 Monster (org.spongepowered.api.entity.living.monster.Monster)2 Projectile (org.spongepowered.api.entity.projectile.Projectile)2 Boat (org.spongepowered.api.entity.vehicle.Boat)2 Minecart (org.spongepowered.api.entity.vehicle.minecart.Minecart)2 TNTMinecart (org.spongepowered.api.entity.vehicle.minecart.TNTMinecart)2