Java Code Examples for br.net.fabiozumbi12.RedProtect.Bukkit.Region#isPvPArena()

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#isPvPArena() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
    Player p = e.getPlayer();

    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }

    String msg = e.getMessage();
    String cmds = msg.split(" ")[0].toLowerCase().replace("/", "");
    //RedProtect.get().logger.severe("Command: "+msg);

    if (RedProtect.get().config.configRoot().server_protection.deny_commands_on_worlds.getOrDefault(p.getWorld().getName(), new ArrayList<>()).contains(cmds) && !p.hasPermission("redprotect.bypass")) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.command-notallowed");
        e.setCancelled(true);
        return;
    }

    if (RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.containsKey(cmds.toLowerCase().replace("/", "")) && !cmds.equals(".")) {
        double min = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).min_range;
        double max = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).max_range;
        String mesg = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).command_ranges.get(cmds).message;
        double py = p.getLocation().getY();
        if (py < min || py > max) {
            if (mesg != null && !mesg.equals("")) {
                RedProtect.get().lang.sendMessage(p, mesg);
            }
            e.setCancelled(true);
            return;
        }
    }

    if (cmds.equalsIgnoreCase("back") || cmds.equalsIgnoreCase("home")) {
        PlayerCmd.put(p.getName(), msg);
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null) {

        if ((cmds.equalsIgnoreCase("petc") || cmds.equalsIgnoreCase("petcall")) && RedProtect.get().hooks.myPet && !r.canPet(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantpet");
            e.setCancelled(true);
            return;
        }

        if (!r.isCmdAllowed(msg)) {
            if (cmds.equalsIgnoreCase("rp") || cmds.equalsIgnoreCase("redprotect")) {
                return;
            }
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand");
            e.setCancelled(true);
            return;
        }

        if (!r.isCmdDenied(msg)) {
            for (String alias : RedProtect.get().getCommand("RedProtect").getAliases()) {
                if (cmds.equalsIgnoreCase(alias)) {
                    return;
                }
            }

            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantcommand");
            e.setCancelled(true);
            return;
        }

        if (cmds.equalsIgnoreCase("sethome") && !r.isHomeAllowed(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.canthome");
            e.setCancelled(true);
            return;
        }

        //Pvp check
        if (cmds.equalsIgnoreCase("pvp") && RedProtect.get().hooks.pvpm) {
            if (r.isPvPArena() && !PvPlayer.get(p).hasPvPEnabled() && !r.canBuild(p)) {
                RedProtect.get().lang.sendMessage(p, "playerlistener.region.pvpenabled");
                RedProtect.get().getServer().dispatchCommand(RedProtect.get().getServer().getConsoleSender(), RedProtect.get().config.configRoot().flags_configuration.pvparena_nopvp_kick_cmd.replace("{player}", p.getName()));
            }
        }
    }
}