Search in sources :

Example 56 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class CursedMineListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        event.setCancelled(true);
        return;
    }
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        BlockType originalType = block.getOriginal().getState().getType();
        if (cursedOres.contains(originalType)) {
            // we were having some multi-firing problems
            if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
                /*if (Probability.getChance(3000)) {
            ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
            player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
          }*/
                ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
                xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
                inst.eatFood(player);
                inst.poison(player, 6);
                inst.ghost(player, originalType);
            }
        } else if (stealableFluids.contains(originalType)) {
            inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
        } else {
            block.setCustom(block.getOriginal());
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockRecord(com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 57 with Listener

use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.

the class EventManager method onRespawnPlayerEvent.

@Listener
public void onRespawnPlayerEvent(RespawnPlayerEvent event) {
    World world = event.getFromTransform().getExtent();
    WorldProperties properties = world.getProperties();
    String worldName = properties.getGameRule("spawnOnDeath").get();
    Optional<World> optionalSpawnWorld = Sponge.getServer().getWorld(worldName);
    if (!optionalSpawnWorld.isPresent()) {
        return;
    }
    World spawnWorld = optionalSpawnWorld.get();
    Transform<World> transform = event.getToTransform().setLocation(spawnWorld.getSpawnLocation());
    event.setToTransform(transform);
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 58 with Listener

use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.

the class EventManager method onDamageEntityEvent.

@Listener
public void onDamageEntityEvent(DamageEntityEvent event, @Root EntityDamageSource damageSource) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Player victim = (Player) event.getTargetEntity();
    if (!isValidPlayer(damageSource)) {
        return;
    }
    World world = victim.getWorld();
    WorldProperties properties = world.getProperties();
    if (!properties.isPVPEnabled() || victim.hasPermission("pjw.override.pvp")) {
        event.setCancelled(true);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 59 with Listener

use of org.spongepowered.api.event.Listener in project ProjectWorlds by trentech.

the class EventManager method onChangeWorldWeatherEvent.

@Listener
public void onChangeWorldWeatherEvent(ChangeWorldWeatherEvent event) {
    World world = event.getTargetWorld();
    WorldProperties properties = world.getProperties();
    if (properties.getGameRule("doWeatherCycle").get().equalsIgnoreCase("false")) {
        event.setCancelled(true);
    }
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 60 with Listener

use of org.spongepowered.api.event.Listener in project LuckPerms by lucko.

the class SpongeConnectionListener method onClientAuth.

@Listener(order = Order.EARLY)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuth(ClientConnectionEvent.Auth e) {
    /* Called when the player first attempts a connection with the server.
           Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) */
    final GameProfile profile = e.getProfile();
    final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId()));
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
    }
    recordConnection(profile.getUniqueId());
    /* Actually process the login for the connection.
           We do this here to delay the login until the data is ready.
           If the login gets cancelled later on, then this will be cleaned up.

           This includes:
           - loading uuid data
           - loading permissions
           - creating a user instance in the UserManager for this connection.
           - setting up cached data. */
    try {
        User user = loadUser(profile.getUniqueId(), username);
        this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
    } catch (Exception ex) {
        this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
        ex.printStackTrace();
        this.deniedAsyncLogin.add(profile.getUniqueId());
        e.setCancelled(true);
        e.setMessageCancelled(false);
        // noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
Also used : User(me.lucko.luckperms.common.model.User) GameProfile(org.spongepowered.api.profile.GameProfile) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

Listener (org.spongepowered.api.event.Listener)360 Player (org.spongepowered.api.entity.living.player.Player)118 World (org.spongepowered.api.world.World)97 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)65 Entity (org.spongepowered.api.entity.Entity)58 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)46 Text (org.spongepowered.api.text.Text)46 ItemStack (org.spongepowered.api.item.inventory.ItemStack)45 Location (org.spongepowered.api.world.Location)45 Sponge (org.spongepowered.api.Sponge)22 BlockType (org.spongepowered.api.block.BlockType)22 Task (org.spongepowered.api.scheduler.Task)17 IOException (java.io.IOException)16 Optional (java.util.Optional)16 Living (org.spongepowered.api.entity.living.Living)15 ItemType (org.spongepowered.api.item.ItemType)15 UUID (java.util.UUID)14 Monster (org.spongepowered.api.entity.living.monster.Monster)14 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)14 Map (java.util.Map)13