Search in sources :

Example 96 with Region

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

the class RPCommands method handleRemoveLeader.

private static void handleRemoveLeader(Player p, String sVictim) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    Region rLow = RedProtect.get().rm.getLowRegion(p.getLocation());
    Map<Integer, Region> regions = RedProtect.get().rm.getGroupRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "removeleader", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        Player pVictim = RedProtect.get().serv.getPlayer(sVictim);
        String VictimUUID = RPUtil.PlayerToUUID(sVictim);
        if (RPUtil.UUIDtoPlayer(VictimUUID) == null) {
            RPLang.sendMessage(p, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }
        if (rLow != r && ((!RedProtect.get().ph.hasRegionPermLeader(p, "removeleader", rLow) || (regions.size() > 1 && rLow.isLeader(VictimUUID))))) {
            RPLang.sendMessage(p, RPLang.get("cmdmanager.region.leader.cantremove.lowregion").replace("{player}", sVictim) + " " + rLow.getName());
            return;
        }
        String victname = RPUtil.UUIDtoPlayer(VictimUUID);
        if (r.isLeader(VictimUUID)) {
            if (r.leaderSize() > 1) {
                RPLang.sendMessage(p, RPLang.get("general.color") + sVictim + " " + RPLang.get("cmdmanager.region.admin.added") + " " + r.getName());
                r.removeLeader(VictimUUID);
                RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " DEMOTED TO ADMIN " + victname + " to region " + r.getName());
                if (pVictim != null && pVictim.isOnline() && !pVictim.equals(p)) {
                    RPLang.sendMessage(pVictim, RPLang.get("cmdmanager.region.leader.youdemoted").replace("{region}", r.getName()) + " " + p.getName());
                }
            } else {
                RPLang.sendMessage(p, RPLang.get("cmdmanager.region.leader.cantremove").replace("{player}", sVictim));
            }
        } else {
            RPLang.sendMessage(p, ChatColor.RED + sVictim + " " + RPLang.get("cmdmanager.region.leader.notleader"));
        }
    } else {
        sendNoPermissionMessage(p);
    }
}
Also used : Player(org.bukkit.entity.Player) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Example 97 with Region

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

the class RPCommands method handleRemoveMember.

private static void handleRemoveMember(Player p, String sVictim) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermAdmin(p, "removemember", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        Player pVictim = RedProtect.get().serv.getPlayer(sVictim);
        String VictimUUID = RPUtil.PlayerToUUID(sVictim);
        if (RPUtil.UUIDtoPlayer(VictimUUID) == null) {
            RPLang.sendMessage(p, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }
        String victname = RPUtil.UUIDtoPlayer(VictimUUID);
        if ((r.isMember(VictimUUID) || r.isAdmin(VictimUUID)) && !r.isLeader(VictimUUID)) {
            RPLang.sendMessage(p, RPLang.get("general.color") + sVictim + " " + RPLang.get("cmdmanager.region.member.removed") + " " + r.getName());
            r.removeMember(VictimUUID);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " REMOVED MEMBER " + victname + " to region " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(p)) {
                RPLang.sendMessage(pVictim, RPLang.get("cmdmanager.region.member.youremoved").replace("{region}", r.getName()) + " " + p.getName());
            }
        } else {
            RPLang.sendMessage(p, ChatColor.RED + sVictim + " " + RPLang.get("cmdmanager.region.member.notmember"));
        }
    } else {
        sendNoPermissionMessage(p);
    }
}
Also used : Player(org.bukkit.entity.Player) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Example 98 with Region

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

the class RPCommands method handlePrioritySingle.

private static void handlePrioritySingle(Player p, int prior, String region) {
    Region r = RedProtect.get().rm.getRegion(region, p.getWorld());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "priority", r)) {
        if (r != null) {
            r.setPrior(prior);
            RPLang.sendMessage(p, RPLang.get("cmdmanager.region.priority.set").replace("{region}", r.getName()) + " " + prior);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " SET PRIORITY of region " + r.getName() + " to " + prior);
        } else {
            RPLang.sendMessage(p, "cmdmanager.region.todo.that");
        }
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Example 99 with Region

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

the class RPCommands method validate.

private static boolean validate(String flag, Object value) {
    if ((flag.equalsIgnoreCase("forcefly") || flag.equalsIgnoreCase("can-death") || flag.equalsIgnoreCase("can-pickup") || flag.equalsIgnoreCase("can-drop") || flag.equalsIgnoreCase("keep-inventory") || flag.equalsIgnoreCase("keep-levels") || flag.equalsIgnoreCase("allow-fly") || flag.equalsIgnoreCase("door") || flag.equalsIgnoreCase("button") || flag.equalsIgnoreCase("lever") || flag.equalsIgnoreCase("pvp") || flag.equalsIgnoreCase("player-damage") || flag.equalsIgnoreCase("can-hunger") || flag.equalsIgnoreCase("can-projectiles") || flag.equalsIgnoreCase("can-pet") || flag.equalsIgnoreCase("portal-enter") || flag.equalsIgnoreCase("allow-create-portal") || flag.equalsIgnoreCase("allow-mod") || flag.equalsIgnoreCase("portal-exit") || flag.equalsIgnoreCase("enderpearl") || flag.equalsIgnoreCase("can-back") || flag.equalsIgnoreCase("up-skills") || flag.equalsIgnoreCase("enter") || flag.equalsIgnoreCase("treefarm") || flag.equalsIgnoreCase("sign") || flag.equalsIgnoreCase("invincible") || flag.equalsIgnoreCase("flow-damage") || flag.equalsIgnoreCase("mob-loot") || flag.equalsIgnoreCase("allow-potions") || flag.equalsIgnoreCase("smart-door") || flag.equalsIgnoreCase("allow-magiccarpet") || flag.equalsIgnoreCase("allow-home") || flag.equalsIgnoreCase("spawn-monsters") || flag.equalsIgnoreCase("spawn-animals") || flag.equalsIgnoreCase("minecart") || flag.equalsIgnoreCase("forcepvp") || flag.equalsIgnoreCase("minefarm")) && !(value instanceof Boolean)) {
        return false;
    }
    if (flag.equalsIgnoreCase("gamemode")) {
        if (!(value instanceof String)) {
            return false;
        }
        try {
            GameMode.valueOf(((String) value).toUpperCase());
        } catch (IllegalArgumentException e) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("setclan") && RedProtect.get().SC) {
        if (!(value instanceof String)) {
            return false;
        }
        if (RedProtect.get().clanManager.getClan((String) value) == null) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("set-portal")) {
        if (!(value instanceof String)) {
            return false;
        }
        String[] valida = ((String) value).split(" ");
        if (valida.length != 2) {
            return false;
        }
        if (Bukkit.getWorld(valida[1]) == null) {
            return false;
        }
        Region r = RedProtect.get().rm.getRegion(valida[0], valida[1]);
        if (r == null) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("max-players")) {
        try {
            Integer.parseInt(value.toString());
        } catch (NumberFormatException e) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("allow-enter-items") || flag.equalsIgnoreCase("deny-enter-items")) {
        if (!(value instanceof String)) {
            return false;
        }
        String[] valida = ((String) value).replace(" ", "").split(",");
        for (String item : valida) {
            if (Material.getMaterial(item.toUpperCase()) == null) {
                return false;
            }
        }
    }
    if (flag.equalsIgnoreCase("allow-place") || flag.equalsIgnoreCase("allow-break")) {
        if (!(value instanceof String)) {
            return false;
        }
        String[] valida = ((String) value).replace(" ", "").split(",");
        for (String item : valida) {
            if (Material.getMaterial(item.toUpperCase()) == null && EntityType.valueOf(item.toUpperCase()) == null) {
                return false;
            }
        }
    }
    if (flag.equalsIgnoreCase("cmd-onhealth")) {
        if (!(value instanceof String)) {
            return false;
        }
        try {
            String[] args = ((String) value).split(",");
            for (String arg : args) {
                if (!arg.split(" ")[0].startsWith("health:") || !arg.split(" ")[1].startsWith("cmd:")) {
                    return false;
                }
                // test health
                int health = Integer.valueOf(arg.split(" ")[0].substring(7));
                if (health < 0 || health > 20) {
                    return false;
                }
            }
        } catch (Exception ex) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("allow-cmds") || flag.equalsIgnoreCase("deny-cmds")) {
        if (!(value instanceof String)) {
            return false;
        }
        try {
            String[] cmds = ((String) value).split(",");
            for (String cmd : cmds) {
                if (cmds.length > 0 && (cmd.contains("cmd:") || cmd.contains("arg:"))) {
                    String[] cmdargs = cmd.split(" ");
                    for (String cmd1 : cmdargs) {
                        if (cmd1.startsWith("cmd:")) {
                            if (cmd1.split(":")[1].length() == 0) {
                                return false;
                            }
                        }
                        if (cmd1.startsWith("arg:")) {
                            if (cmd1.split(":")[1].length() == 0) {
                                return false;
                            }
                        }
                    }
                } else {
                    return false;
                }
            }
        } catch (Exception e) {
            return false;
        }
    }
    if (flag.equalsIgnoreCase("effects")) {
        if (!(value instanceof String)) {
            return false;
        }
        String[] effects = ((String) value).split(",");
        for (String eff : effects) {
            String[] effect = eff.split(" ");
            if (effect.length < 2) {
                return false;
            }
            if (PotionEffectType.getByName(effect[0]) == null) {
                return false;
            }
            try {
                Integer.parseInt(effect[1]);
            } catch (NumberFormatException e) {
                return false;
            }
        }
    }
    return true;
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 100 with Region

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

the class RPCommands method handleAddMember.

private void handleAddMember(Player p, String sVictim) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermAdmin(p, "addmember", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        String VictimUUID = RPUtil.PlayerToUUID(sVictim);
        if (RPUtil.UUIDtoPlayer(VictimUUID) == null) {
            RPLang.sendMessage(p, RPLang.get("cmdmanager.noplayer.thisname").replace("{player}", sVictim));
            return;
        }
        Player pVictim = RedProtect.get().serv.getPlayer(sVictim);
        if (r.isLeader(VictimUUID)) {
            RPLang.sendMessage(p, ChatColor.RED + sVictim + " " + RPLang.get("cmdmanager.region.leader.already"));
            return;
        }
        if (r.isAdmin(VictimUUID)) {
            r.addMember(VictimUUID);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " ADDED MEMBER " + RPUtil.UUIDtoPlayer(VictimUUID) + " to region " + r.getName());
            RPLang.sendMessage(p, RPLang.get("general.color") + sVictim + " " + RPLang.get("cmdmanager.region.member.demoted") + " " + r.getName());
            if (pVictim != null && pVictim.isOnline()) {
                RPLang.sendMessage(pVictim, RPLang.get("cmdmanager.region.admin.youdemoted").replace("{region}", r.getName()) + " " + p.getName());
            }
        } else if (!r.isMember(VictimUUID)) {
            r.addMember(VictimUUID);
            RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " ADDED MEMBER " + RPUtil.UUIDtoPlayer(VictimUUID) + " to region " + r.getName());
            RPLang.sendMessage(p, RPLang.get("general.color") + sVictim + " " + RPLang.get("cmdmanager.region.member.added") + " " + r.getName());
            if (pVictim != null && pVictim.isOnline() && !pVictim.equals(p)) {
                RPLang.sendMessage(pVictim, RPLang.get("cmdmanager.region.member.youadded").replace("{region}", r.getName()) + " " + p.getName());
            }
        } else {
            RPLang.sendMessage(p, ChatColor.RED + sVictim + " " + RPLang.get("cmdmanager.region.member.already"));
        }
    } else {
        sendNoPermissionMessage(p);
    }
}
Also used : Player(org.bukkit.entity.Player) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

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