Search in sources :

Example 46 with Region

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

the class RPBlockListener method onSignPlace.

@EventHandler(priority = EventPriority.HIGH)
public void onSignPlace(SignChangeEvent e) {
    RedProtect.get().logger.debug("BlockListener - Is SignChangeEvent event! Cancelled? " + e.isCancelled());
    if (e.isCancelled()) {
        return;
    }
    Block b = e.getBlock();
    Player p = e.getPlayer();
    if (b == null) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.block.null"));
        return;
    }
    Region signr = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (signr != null && !signr.canSign(p)) {
        RPLang.sendMessage(p, "playerlistener.region.cantinteract");
        e.setCancelled(true);
        return;
    }
    String[] lines = e.getLines();
    String line1 = lines[0];
    if (lines.length != 4) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.sign.wronglines"));
        return;
    }
    if (RPConfig.getBool("server-protection.sign-spy.enabled") && !(lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty())) {
        Bukkit.getConsoleSender().sendMessage(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + b.getX()).replace("{y}", "" + b.getY()).replace("{z}", "" + b.getZ()).replace("{world}", b.getWorld().getName()));
        Bukkit.getConsoleSender().sendMessage(RPLang.get("blocklistener.signspy.player").replace("{player}", e.getPlayer().getName()));
        Bukkit.getConsoleSender().sendMessage(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines[0].toString()).replace("{line2}", lines[1].toString()));
        Bukkit.getConsoleSender().sendMessage(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines[2].toString()).replace("{line4}", lines[3].toString()));
        if (!RPConfig.getBool("server-protection.sign-spy.only-console")) {
            for (Player play : Bukkit.getOnlinePlayers()) {
                if (play.hasPermission("redprotect.signspy")) /* && !play.equals(p)*/
                {
                    play.sendMessage(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + b.getX()).replace("{y}", "" + b.getY()).replace("{z}", "" + b.getZ()).replace("{world}", b.getWorld().getName()));
                    play.sendMessage(RPLang.get("blocklistener.signspy.player").replace("{player}", e.getPlayer().getName()));
                    play.sendMessage(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines[0].toString()).replace("{line2}", lines[1].toString()));
                    play.sendMessage(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines[2].toString()).replace("{line4}", lines[3].toString()));
                }
            }
        }
    }
    String priv = RPLang.get("blocklistener.container.signline");
    String more = RPLang.get("blocklistener.container.signline.more");
    if ((RPConfig.getBool("private.use") && b.getType().equals(Material.WALL_SIGN))) {
        Boolean out = RPConfig.getBool("private.allow-outside");
        if (line1.equalsIgnoreCase("more") || line1.equalsIgnoreCase("[more]") || line1.equalsIgnoreCase(more) || line1.equalsIgnoreCase("[" + more + "]")) {
            if (out || signr != null) {
                if (cont.isContainer(b, true)) {
                    int length = p.getName().length();
                    if (length > 16) {
                        length = 16;
                    }
                    RPLang.sendMessage(p, "blocklistener.container.protected.added");
                    return;
                } else {
                    RPLang.sendMessage(p, "blocklistener.container.protected.notadded");
                    b.breakNaturally();
                    return;
                }
            } else {
                RPLang.sendMessage(p, "blocklistener.container.notregion");
                b.breakNaturally();
                return;
            }
        }
        if (line1.equalsIgnoreCase("private") || line1.equalsIgnoreCase("[private]") || line1.equalsIgnoreCase(priv) || line1.equalsIgnoreCase("[" + priv + "]")) {
            if (out || signr != null) {
                if (cont.isContainer(b, false)) {
                    int length = p.getName().length();
                    if (length > 16) {
                        length = 16;
                    }
                    e.setLine(1, p.getName().substring(0, length));
                    RPLang.sendMessage(p, "blocklistener.container.protected");
                    return;
                } else {
                    RPLang.sendMessage(p, "blocklistener.container.notprotected");
                    b.breakNaturally();
                    return;
                }
            } else {
                RPLang.sendMessage(p, "blocklistener.container.notregion");
                b.breakNaturally();
                return;
            }
        }
    }
    if (line1.equalsIgnoreCase("[rp]")) {
        String claimmode = RPConfig.getWorldClaimType(p.getWorld().getName());
        if ((!claimmode.equalsIgnoreCase("BLOCK") && !claimmode.equalsIgnoreCase("BOTH")) && !p.hasPermission("redprotect.admin.create")) {
            this.setErrorSign(e, p, RPLang.get("blocklistener.region.claimmode"));
            return;
        }
        RegionBuilder rb = new EncompassRegionBuilder(e);
        if (rb.ready()) {
            Region r = rb.build();
            e.setLine(0, RPLang.get("blocklistener.region.signcreated"));
            e.setLine(1, r.getName());
            // RPLang.sendMessage(p, RPLang.get("blocklistener.region.created").replace("{region}",  r.getName()));
            RedProtect.get().rm.add(r, RedProtect.get().serv.getWorld(r.getWorld()));
        }
    } else if (RPConfig.getBool("region-settings.enable-flag-sign") && line1.equalsIgnoreCase("[flag]") && signr != null) {
        if (signr.flags.containsKey(lines[1])) {
            String flag = lines[1];
            if (!(signr.flags.get(flag) instanceof Boolean)) {
                RPLang.sendMessage(p, RPLang.get("playerlistener.region.sign.cantflag"));
                b.breakNaturally();
                return;
            }
            if (RedProtect.get().ph.hasPerm(p, "redprotect.flag." + flag)) {
                if (signr.isAdmin(p) || signr.isLeader(p) || RedProtect.get().ph.hasPerm(p, "redprotect.admin.flag." + flag)) {
                    e.setLine(1, flag);
                    e.setLine(2, ChatColor.DARK_AQUA + "" + ChatColor.BOLD + signr.getName());
                    e.setLine(3, RPLang.get("region.value") + " " + RPLang.translBool(signr.getFlagString(flag)));
                    RPLang.sendMessage(p, "playerlistener.region.sign.placed");
                    RPConfig.putSign(signr.getID(), b.getLocation());
                    return;
                }
            }
            RPLang.sendMessage(p, "cmdmanager.region.flag.nopermregion");
            b.breakNaturally();
        } else {
            RPLang.sendMessage(p, "playerlistener.region.sign.invalidflag");
            b.breakNaturally();
        }
    }
}
Also used : Player(org.bukkit.entity.Player) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.actions.EncompassRegionBuilder) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) RegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.RegionBuilder) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Bukkit.actions.EncompassRegionBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 47 with Region

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

the class RPBlockListener method onFireSpread.

@EventHandler
public void onFireSpread(BlockSpreadEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockSpreadEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block bfrom = e.getSource();
    Block bto = e.getBlock();
    RedProtect.get().logger.debug("Is BlockSpreadEvent event, source is " + bfrom.getType().name());
    Region rfrom = RedProtect.get().rm.getTopRegion(bfrom.getLocation());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation());
    if ((bfrom.getType().equals(Material.FIRE) || bfrom.getType().name().contains("LAVA")) && rfrom != null && !rfrom.canFire()) {
        e.setCancelled(true);
        return;
    }
    // deny blocks spread in/out regions
    if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
        e.setCancelled(true);
        return;
    }
    if (rfrom == null && rto != null) {
        e.setCancelled(true);
        return;
    }
    if (rfrom != null && rto == null) {
        e.setCancelled(true);
    }
}
Also used : Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 48 with Region

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

the class RPBlockListener method onBlockStartBurn.

@EventHandler
public void onBlockStartBurn(BlockIgniteEvent e) {
    RedProtect.get().logger.debug("RPBlockListener - Is BlockIgniteEvent event");
    if (e.isCancelled()) {
        return;
    }
    Block b = e.getBlock();
    Block bignit = e.getIgnitingBlock();
    if (b == null) {
        return;
    }
    RedProtect.get().logger.debug("Is BlockIgniteEvent event. Canceled? " + e.isCancelled());
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (r != null && !r.canFire()) {
        if (e.getIgnitingEntity() != null) {
            if (e.getIgnitingEntity() instanceof Player) {
                Player p = (Player) e.getIgnitingEntity();
                if (!r.canBuild(p)) {
                    RPLang.sendMessage(p, "blocklistener.region.cantplace");
                    e.setCancelled(true);
                    return;
                }
            } else {
                e.setCancelled(true);
                return;
            }
        }
        if (bignit != null && (bignit.getType().equals(Material.FIRE) || bignit.getType().name().contains("LAVA"))) {
            e.setCancelled(true);
            return;
        }
        if (e.getCause().equals(IgniteCause.LIGHTNING) || e.getCause().equals(IgniteCause.EXPLOSION) || e.getCause().equals(IgniteCause.FIREBALL)) {
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 49 with Region

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

the class RPBlockListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent e) {
    RedProtect.get().logger.debug("BlockListener - Is BlockPlaceEvent event! Cancelled? " + e.isCancelled());
    if (e.isCancelled()) {
        return;
    }
    Player p = e.getPlayer();
    Block b = e.getBlockPlaced();
    World w = p.getWorld();
    Material m = null;
    if (e.getItemInHand() != null) {
        m = e.getItemInHand().getType();
    }
    Boolean antih = RPConfig.getBool("region-settings.anti-hopper");
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass") && antih && m != null && (m.equals(Material.HOPPER) || m.name().contains("RAIL"))) {
        int x = b.getX();
        int y = b.getY();
        int z = b.getZ();
        Block ib = w.getBlockAt(x, y + 1, z);
        if (!cont.canBreak(p, ib) || !cont.canBreak(p, b)) {
            RPLang.sendMessage(p, "blocklistener.container.chestinside");
            e.setCancelled(true);
            return;
        }
    }
    if (r == null && RPConfig.getGlobalFlagList(p.getWorld().getName() + ".if-build-false.place-blocks").contains(b.getType().name())) {
        return;
    }
    if (r != null) {
        if (m != null && !r.canMinecart(p) && (m.name().contains("MINECART") || m.name().contains("BOAT"))) {
            RPLang.sendMessage(p, "blocklistener.region.cantplace");
            e.setCancelled(true);
            return;
        }
        if (b.getType().equals(Material.MOB_SPAWNER) && r.allowSpawner(p)) {
            return;
        }
        if (!r.canBuild(p) && !r.canPlace(b.getType())) {
            RPLang.sendMessage(p, "blocklistener.region.cantbuild");
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Material(org.bukkit.Material) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 50 with Region

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

the class RPBlockListener method onFrameBrake.

@EventHandler
public void onFrameBrake(HangingBreakByEntityEvent e) {
    RedProtect.get().logger.debug("Is BlockListener - HangingBreakByEntityEvent event");
    if (e.isCancelled()) {
        return;
    }
    Entity remover = e.getRemover();
    Entity ent = e.getEntity();
    Location l = e.getEntity().getLocation();
    if ((ent instanceof ItemFrame || ent instanceof Painting) && remover instanceof Monster) {
        Region r = RedProtect.get().rm.getTopRegion(l);
        if (r != null && !r.canMobLoot()) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Monster(org.bukkit.entity.Monster) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ItemFrame(org.bukkit.entity.ItemFrame) Location(org.bukkit.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)113 EventHandler (org.bukkit.event.EventHandler)92 Player (org.bukkit.entity.Player)69 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)47 Listener (org.spongepowered.api.event.Listener)46 Location (org.bukkit.Location)43 World (org.spongepowered.api.world.World)30 Block (org.bukkit.block.Block)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)20 PvPlayer (me.NoChance.PvPManager.PvPlayer)20 Entity (org.bukkit.entity.Entity)20 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)19 Entity (org.spongepowered.api.entity.Entity)19 LivingEntity (org.bukkit.entity.LivingEntity)16 Player (org.spongepowered.api.entity.living.player.Player)16 World (org.bukkit.World)10 Monster (org.bukkit.entity.Monster)10 Material (org.bukkit.Material)9 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)8 OfflinePlayer (org.bukkit.OfflinePlayer)8