Search in sources :

Example 36 with Listener

use of org.spongepowered.api.event.Listener 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 37 with Listener

use of org.spongepowered.api.event.Listener 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 38 with Listener

use of org.spongepowered.api.event.Listener in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameInit.

@Listener
public void gameInit(GamePreInitializationEvent event) {
    logger = LoggerFactory.getLogger(pC.getName());
    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.");
    }
    logger.info("Let's not init VCrates here anymore. ://)");
    instance = this;
}
Also used : CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) IOException(java.io.IOException) Listener(org.spongepowered.api.event.Listener)

Example 39 with Listener

use of org.spongepowered.api.event.Listener in project ClearMob by axle2005.

the class EntityLimiter method handle.

@Listener(beforeModifications = true)
public void handle(SpawnEntityEvent event) throws Exception {
    List<Entity> entity = event.getEntities();
    Integer count = 0;
    Integer xpcount = 0;
    for (World w : plugin.getWorlds()) {
        for (Entity e : w.getEntities()) {
            if (e instanceof Monster && !(e instanceof Boss)) {
                count++;
            }
            if (e instanceof ExperienceOrb) {
                xpcount++;
            }
        }
    }
    for (int i = 0; i < entity.size(); i++) {
        if (entity.get(i) instanceof Monster && (count > plugin.getMobLimit()) && !(entity.get(i) instanceof Boss)) {
            event.setCancelled(true);
        }
        if ((entity.get(i) instanceof ExperienceOrb && entity.get(i).getNearbyEntities(10).size() > 20)) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Boss(org.spongepowered.api.entity.living.monster.Boss) Monster(org.spongepowered.api.entity.living.monster.Monster) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 40 with Listener

use of org.spongepowered.api.event.Listener in project ClearMob by axle2005.

the class ClearMob method preInitialization.

@Listener
public void preInitialization(GamePreInitializationEvent event) {
    config = new Config(this, defaultConfig, configManager);
    events = new ListenersRegister(this);
    w = new Warning();
    listEntityType = Util.getEntityType(config.getList("ClearingLists,EntityList"));
    listTileEntityType = Util.getTileEntityType(config.getList("Clearing,Lists,TileEntityList"));
    listItemType = Util.getItemType(config.getList("Clearing,Lists,ItemList"));
    itemWB = config.getNodeString("Clearing,KillDrops,ListType");
    configoptions[0] = config.getNodeBoolean("Clearing,PassiveMode");
    configoptions[1] = config.getNodeBoolean("Clearing,KillAllMonsters");
    configoptions[2] = config.getNodeBoolean("Clearing,KillDrops,Enabled");
    configoptions[3] = config.getNodeBoolean("Clearing,KillAnimalGroups");
    configoptions[4] = config.getNodeBoolean("Warning,Enabled");
    configoptions[5] = config.getNodeBoolean("Clearing,CrashMode");
    configoptions[6] = config.getNodeBoolean("Clearing,MobLimiter,Enabled");
    interval = config.getNodeInt("Clearing,Interval");
    moblimit = config.getNodeInt("Clearing,MobLimiter,Limit");
    warningmessage = config.getNodeString("Warning,Messages,Warning");
    clearedmessage = config.getNodeString("Warning,Messages,Cleared");
}
Also used : DefaultConfig(org.spongepowered.api.config.DefaultConfig) ListenersRegister(io.github.axle2005.clearmob.listeners.ListenersRegister) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)93 Player (org.spongepowered.api.entity.living.player.Player)41 World (org.spongepowered.api.world.World)28 Location (org.spongepowered.api.world.Location)21 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)18 Entity (org.spongepowered.api.entity.Entity)14 Text (org.spongepowered.api.text.Text)14 BlockType (org.spongepowered.api.block.BlockType)11 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)10 ItemStack (net.minecraft.item.ItemStack)10 Task (org.spongepowered.api.scheduler.Task)10 Vector3d (com.flowpowered.math.vector.Vector3d)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 ItemDropper (com.skelril.nitro.item.ItemDropper)5 ModifierService (com.skelril.skree.service.ModifierService)5 RegionService (com.skelril.skree.service.RegionService)5 WorldService (com.skelril.skree.service.WorldService)5 Region (com.skelril.skree.service.internal.region.Region)5 UUID (java.util.UUID)5