Search in sources :

Example 11 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onPlayerInteract.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerInteract(InteractEvent e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is InteractEvent event! Cancelled? " + e.isCancelled());
    if (!e.getInteractionPoint().isPresent()) {
        return;
    }
    BlockSnapshot b = p.getWorld().createSnapshot(e.getInteractionPoint().get().toInt());
    String bname = b.getState().getName().toLowerCase();
    Location<World> loc = new Location<>(p.getWorld(), e.getInteractionPoint().get());
    // Temporary fix until this event return wrong location
    if (new Location<>(p.getWorld(), e.getInteractionPoint().get()).getBlockY() <= 2) {
        loc = p.getLocation();
    }
    Region r = RedProtect.get().rm.getTopRegion(loc);
    if (!canInteract(p, r)) {
        e.setCancelled(true);
    }
    if (r != null) {
        return;
    }
    if (bname.contains("rail") || bname.contains("water")) {
        if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
        }
    } else {
        if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "interact") && !p.hasPermission("redprotect.world.bypass")) {
            e.setCancelled(true);
            return;
        }
        if (!RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(), "build") && !p.hasPermission("redprotect.world.bypass") && bname.contains("leaves")) {
            e.setCancelled(true);
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 12 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onEntityDamageEntity.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEntity(DamageEntityEvent e) {
    Entity e1 = e.getTargetEntity();
    Entity e2;
    RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName());
    Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
    if (e1 instanceof Living && !(e1 instanceof Monster)) {
        if (r == null && RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "invincible")) {
            e.setCancelled(true);
        }
    }
    if (e.getCause().first(Living.class).isPresent()) {
        e2 = e.getCause().first(Living.class).get();
        RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - Is DamageEntityEvent event. Damager " + e2.getType().getName());
    } else {
        return;
    }
    RedProtect.get().logger.debug("entity", "RPGlobalListener: DamageEntityEvent - e1: " + e1.getType().getName() + " - e2: " + e2.getType().getName());
    Location<World> loc = e1.getLocation();
    Region r1 = RedProtect.get().rm.getTopRegion(loc);
    if (r1 != null) {
        return;
    }
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Entity) {
            e2 = (Entity) proj.getShooter();
        }
        if (!(e2 instanceof Player)) {
            if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
                if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (e2 instanceof Creeper || e2 instanceof PrimedTNT || e2 instanceof TNTMinecart) {
        if (e1 instanceof Player) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "explosion-entity-damage")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage")) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Player) {
        Player p = (Player) e2;
        if (e1 instanceof Player) {
            if (!e1.equals(e2) && !RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "pvp") && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-passives") && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "player-hurt-monsters") && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Boat || e1 instanceof Minecart) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "use-minecart") && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
            if (!RedProtect.get().cfgs.getGlobalFlag(e1.getWorld().getName(), "entity-block-damage") && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) Hanging(org.spongepowered.api.entity.hanging.Hanging) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Example 13 with RPGlobalListener

use of br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPGlobalListener in project RedProtect by FabioZumbi12.

the class RedProtect method onServerStart.

@Listener
public void onServerStart(GameStartedServerEvent event) {
    try {
        String v = Sponge.getGame().getPlatform().getContainer(Component.API).getVersion().get();
        instance = this;
        if (v.startsWith("5") || v.startsWith("6")) {
            pvhelp = (RPVHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.RPVHelper56").newInstance();
        }
        if (v.startsWith("7")) {
            pvhelp = (RPVHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.RPVHelper7").newInstance();
        }
        initVars();
        OnlineMode = serv.getOnlineMode();
        cmdService.register(container, new RPCommands(), Arrays.asList("redprotect", "rp", "regionp", "regp"));
        game.getEventManager().registerListeners(container, new RPGlobalListener());
        game.getEventManager().registerListeners(container, new RPBlockListener());
        game.getEventManager().registerListeners(container, new RPPlayerListener());
        game.getEventManager().registerListeners(container, new RPEntityListener());
        game.getEventManager().registerListeners(container, new RPWorldListener());
        game.getEventManager().registerListeners(container, new RPMine18());
        game.getEventManager().registerListeners(container, new RPAddProtection());
        loadRegions();
        logger.info("Loading API...");
        this.rpAPI = new RedProtectAPI();
        logger.info("API Loaded!");
        logger.clear("&4 _   _  _  &c _   _   _  _ _  _  _ _ _  __");
        logger.clear("&4|_| |_ | \\ &c|_| |_| | |  |  |_ |   |    / ");
        logger.clear("&4| \\ |_ |_/ &c|   | \\ |_|  |  |_ |_  |   /");
        logger.clear("&a¯ Redprotect " + container.getVersion().get() + " enabled");
        logger.clear("");
    } catch (Exception e) {
        e.printStackTrace();
        logger.severe("Error enabling RedProtect, plugin will shut down.");
    }
}
Also used : RPBlockListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener) RPPlayerListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener) RPWorldListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPWorldListener) RPEntityListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPEntityListener) RedProtectAPI(br.net.fabiozumbi12.RedProtect.Sponge.API.RedProtectAPI) RPGlobalListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPGlobalListener) RPAddProtection(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPAddProtection) RPMine18(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPMine18) RPCommands(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPCommands) RPGlobalListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPGlobalListener) RPWorldListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPWorldListener) RPEntityListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPEntityListener) RPBlockListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener) RPPlayerListener(br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPPlayerListener) Listener(org.spongepowered.api.event.Listener)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)7 EventHandler (org.bukkit.event.EventHandler)7 Block (org.bukkit.block.Block)5 Player (org.bukkit.entity.Player)5 Listener (org.spongepowered.api.event.Listener)5 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)4 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)3 World (org.spongepowered.api.world.World)3 Location (org.bukkit.Location)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Monster (org.bukkit.entity.Monster)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1 MPListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.MPListener)1 McMMoListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.McMMoListener)1 RPDynmap (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPDynmap)1 RPFactions (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPFactions)1 RPPlaceHoldersAPI (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.RPPlaceHoldersAPI)1 SkillAPIListener (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.SkillAPIListener)1 RPAddProtection (br.net.fabiozumbi12.RedProtect.Bukkit.listeners.RPAddProtection)1