Search in sources :

Example 1 with EncompassRegionBuilder

use of br.net.fabiozumbi12.RedProtect.Bukkit.actions.EncompassRegionBuilder 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 2 with EncompassRegionBuilder

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

the class RPBlockListener method onSignPlace.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onSignPlace(ChangeSignEvent e, @First Player p) {
    RedProtect.get().logger.debug("blocks", "BlockListener - Is SignChangeEvent event! Cancelled? " + e.isCancelled());
    Sign s = e.getTargetTile();
    List<Text> lines = e.getText().asList();
    Location<World> loc = s.getLocation();
    World w = p.getWorld();
    BlockSnapshot b = w.createSnapshot(loc.getBlockPosition());
    if (b == null) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.block.null"));
        return;
    }
    Region signr = RedProtect.get().rm.getTopRegion(loc);
    if (signr != null && !signr.canSign(p)) {
        RPLang.sendMessage(p, "playerlistener.region.cantinteract");
        e.setCancelled(true);
        return;
    }
    Text line1 = lines.get(0);
    if (lines.size() != 4) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.sign.wronglines"));
        return;
    }
    if (RedProtect.get().cfgs.getBool("server-protection.sign-spy.enabled")) {
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
        if (!RedProtect.get().cfgs.getBool("server-protection.sign-spy.only-console")) {
            for (Player play : Sponge.getServer().getOnlinePlayers()) {
                if (RedProtect.get().ph.hasGenPerm(play, "redprotect.signspy")) /* && !play.equals(p)*/
                {
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
                }
            }
        }
    }
    if ((RedProtect.get().cfgs.getBool("private.use") && s.getType().equals(TileEntityTypes.SIGN)) && (line1.toPlain().equalsIgnoreCase("private") || line1.toPlain().equalsIgnoreCase("[private]") || line1.toPlain().equalsIgnoreCase(RPLang.get("blocklistener.container.signline")) || line1.toPlain().equalsIgnoreCase("[" + RPLang.get("blocklistener.container.signline") + "]"))) {
        Region r = RedProtect.get().rm.getTopRegion(loc);
        Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
        if (out || r != null) {
            if (cont.isContainer(b)) {
                int length = p.getName().length();
                if (length > 16) {
                    length = 16;
                }
                lines.set(1, RPUtil.toText(p.getName().substring(0, length)));
                e.getText().setElements(lines);
                RPLang.sendMessage(p, "blocklistener.container.protected");
                return;
            } else {
                RPLang.sendMessage(p, "blocklistener.container.notprotected");
                // w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
                return;
            }
        } else {
            RPLang.sendMessage(p, "blocklistener.container.notregion");
            // w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
            return;
        }
    }
    if (line1.toPlain().equalsIgnoreCase("[rp]")) {
        String claimmode = RedProtect.get().cfgs.getWorldClaimType(p.getWorld().getName());
        if ((!claimmode.equalsIgnoreCase("BLOCK") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasPerm(p, "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();
            lines.set(0, RPUtil.toText(RPLang.get("blocklistener.region.signcreated")));
            lines.set(1, RPUtil.toText(r.getName()));
            e.getText().setElements(lines);
            // RPLang.sendMessage(p, RPLang.get("blocklistener.region.created").replace("{region}",  r.getName()));
            RedProtect.get().rm.add(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.EncompassRegionBuilder) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Sign(org.spongepowered.api.block.tileentity.Sign) RegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.RegionBuilder) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.EncompassRegionBuilder) Listener(org.spongepowered.api.event.Listener)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 RegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.RegionBuilder)1 EncompassRegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.actions.EncompassRegionBuilder)1 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 RegionBuilder (br.net.fabiozumbi12.RedProtect.Sponge.RegionBuilder)1 EncompassRegionBuilder (br.net.fabiozumbi12.RedProtect.Sponge.actions.EncompassRegionBuilder)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Sign (org.spongepowered.api.block.tileentity.Sign)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 Text (org.spongepowered.api.text.Text)1 World (org.spongepowered.api.world.World)1