Search in sources :

Example 81 with Listener

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

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onFireSpread.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(NotifyNeighborBlockEvent e, @Root BlockSnapshot source) {
    Map<Direction, BlockState> dirs = e.getNeighbors();
    for (Direction dir : dirs.keySet()) {
        BlockSnapshot b = source.getLocation().get().getRelative(dir).createSnapshot();
        BlockState bstate = source.getState();
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
        if (r != null) {
            return;
        }
        if ((bstate.getType().equals(BlockTypes.FIRE) || bstate.getType().getName().contains("lava")) && !RedProtect.get().cfgs.getGlobalFlag(b.getLocation().get().getExtent().getName(), "fire-spread")) {
            e.setCancelled(true);
            return;
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 83 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockPlace.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is ChangeBlockEvent event! Cancelled? " + e.isCancelled());
    BlockSnapshot b = e.getTransactions().get(0).getFinal();
    ItemType item = ItemTypes.NONE;
    if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        item = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
    } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
        item = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
    }
    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, b.getLocation().get())) {
        e.setCancelled(true);
        return;
    }
    if (item.getName().contains("minecart") || item.getName().contains("boat")) {
        if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("default", "RPGlobalListener - Can't place minecart/boat!");
        }
    } else {
        if (!bypassBuild(p, b, 1)) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("default", "RPGlobalListener - Can't Build!");
        }
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 84 with Listener

use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.

the class RPMine18 method onAttemptInteractAS.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) {
    Entity ent = e.getTargetEntity();
    Location<World> l = ent.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r == null) {
        // global flags
        if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
            if (!RedProtect.get().cfgs.getGlobalFlag(l.getExtent().getName(), "build")) {
                e.setCancelled(true);
                return;
            }
        }
        return;
    }
    ItemType itemInHand = ItemTypes.NONE;
    if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
    } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
        itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
    }
    if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) {
        if (r != null && !r.canBuild(p)) {
            e.setCancelled(true);
            RPLang.sendMessage(p, "blocklistener.region.cantbuild");
            return;
        }
    }
    // TODO Not working!
    if (ent.getType().equals(EntityTypes.ARMOR_STAND)) {
        if (r != null && !r.canBuild(p)) {
            if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
                RPLang.sendMessage(p, "playerlistener.region.cantedit");
                e.setCancelled(true);
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) ItemType(org.spongepowered.api.item.ItemType) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 85 with Listener

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

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