Search in sources :

Example 1 with PvPlayer

use of me.NoChance.PvPManager.PvPlayer in project MyPet by xXKeyleXx.

the class PvPManagerHook method canHurt.

@Override
public boolean canHurt(Player attacker, Player defender) {
    try {
        PvPlayer pvpAttacker = PvPlayer.get(attacker);
        PvPlayer pvpDefender = PvPlayer.get(defender);
        if (pvpAttacker.hasOverride()) {
            return true;
        }
        if (pvpDefender.hasRespawnProtection() || pvpAttacker.hasRespawnProtection()) {
            return false;
        }
        if (pvpDefender.isNewbie() || pvpAttacker.isNewbie()) {
            return false;
        }
        if (!pvpDefender.hasPvPEnabled() || !pvpAttacker.hasPvPEnabled()) {
            return false;
        }
        return true;
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : PvPlayer(me.NoChance.PvPManager.PvPlayer)

Example 2 with PvPlayer

use of me.NoChance.PvPManager.PvPlayer in project RedProtect by FabioZumbi12.

the class RPPlayerListener method RegionFlags.

private void RegionFlags(final Region r, Region er, final Player p) {
    // Pvp check to enter on region
    if (RedProtect.get().PvPm) {
        if (r.isPvPArena() && !PvPlayer.get(p).hasPvPEnabled() && !r.canBuild(p)) {
            RPLang.sendMessage(p, "playerlistener.region.pvpenabled");
            RedProtect.get().serv.dispatchCommand(RedProtect.get().serv.getConsoleSender(), RPConfig.getString("flags-configuration.pvparena-nopvp-kick-cmd").replace("{player}", p.getName()));
        }
    }
    // enter Gamemode flag
    if (r.canEnter(p) && r.flagExists("gamemode") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.gamemode")) {
        p.setGameMode(GameMode.valueOf(r.getFlagString("gamemode").toUpperCase()));
    }
    // Exit gamemode
    if (er != null && er.flagExists("gamemode") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.gamemode")) {
        p.setGameMode(Bukkit.getServer().getDefaultGameMode());
    }
    // Enter command as player
    if (r.canEnter(p) && r.flagExists("player-enter-command") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.player-enter-command")) {
        String[] cmds = r.getFlagString("player-enter-command").split(",");
        for (String cmd : cmds) {
            if (cmd.startsWith("/")) {
                cmd = cmd.substring(1);
            }
            p.getServer().dispatchCommand(p.getPlayer(), cmd.replace("{player}", p.getName()).replace("{region}", r.getName()));
        }
    }
    // Enter command as console
    if (r.canEnter(p) && r.flagExists("server-enter-command") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.server-enter-command")) {
        String[] cmds = r.getFlagString("server-enter-command").split(",");
        for (String cmd : cmds) {
            if (cmd.startsWith("/")) {
                cmd = cmd.substring(1);
            }
            RedProtect.get().serv.dispatchCommand(RedProtect.get().serv.getConsoleSender(), cmd.replace("{player}", p.getName()).replace("{region}", r.getName()));
        }
    }
    // Check portal (/rp flag set-portal <rp> <world>
    if (r.canEnter(p) && r.flagExists("set-portal")) {
        String[] cmds = r.getFlagString("set-portal").split(" ");
        RedProtect.get().serv.dispatchCommand(RedProtect.get().serv.getConsoleSender(), "rp teleport " + p.getName() + " " + cmds[0] + " " + cmds[1]);
    }
    // Enter MagicCarpet
    if (r.canEnter(p) && r.flagExists("allow-magiccarpet") && !r.getFlagBool("allow-magiccarpet") && RedProtect.get().Mc) {
        if (MagicCarpet.getCarpets().getCarpet(p) != null) {
            MagicCarpet.getCarpets().remove(p);
            RPLang.sendMessage(p, "playerlistener.region.cantmc");
        }
    }
    if (er != null) {
        // Exit effect
        if (er.flagExists("effects") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.effects")) {
            String[] effects = er.getFlagString("effects").split(",");
            for (String effect : effects) {
                if (PlayertaskID.containsValue(p.getName())) {
                    String eff = effect.split(" ")[0];
                    String amplifier = effect.split(" ")[1];
                    PotionEffect fulleffect = new PotionEffect(PotionEffectType.getByName(eff), RPConfig.getInt("flags-configuration.effects-duration") * 20, Integer.parseInt(amplifier));
                    p.removePotionEffect(fulleffect.getType());
                    List<String> removeTasks = new ArrayList<>();
                    for (String taskId : PlayertaskID.keySet()) {
                        int id = Integer.parseInt(taskId.split("_")[0]);
                        String ideff = id + "_" + eff + er.getName();
                        if (PlayertaskID.containsKey(ideff) && PlayertaskID.get(ideff).equals(p.getName())) {
                            Bukkit.getScheduler().cancelTask(id);
                            removeTasks.add(taskId);
                            RedProtect.get().logger.debug("(RegionFlags-eff)Removed task ID: " + taskId + " for player " + p.getName());
                        }
                    }
                    for (String key : removeTasks) {
                        PlayertaskID.remove(key);
                    }
                    removeTasks.clear();
                }
            }
        } else // exit fly flag
        if (er.flagExists("forcefly") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.forcefly") && (p.getGameMode().equals(GameMode.SURVIVAL) || p.getGameMode().equals(GameMode.ADVENTURE))) {
            if (PlayertaskID.containsValue(p.getName())) {
                if (r.flagExists("forcefly")) {
                    p.setAllowFlight(r.getFlagBool("forcefly"));
                    p.setFlying(r.getFlagBool("forcefly"));
                } else {
                    p.setAllowFlight(false);
                    p.setFlying(false);
                }
                List<String> removeTasks = new ArrayList<>();
                for (String taskId : PlayertaskID.keySet()) {
                    int id = Integer.parseInt(taskId.split("_")[0]);
                    String ideff = id + "_" + "forcefly" + er.getName();
                    if (PlayertaskID.containsKey(ideff) && PlayertaskID.get(ideff).equals(p.getName())) {
                        Bukkit.getScheduler().cancelTask(id);
                        removeTasks.add(taskId);
                        RedProtect.get().logger.debug("(RegionFlags fly)Removed task ID: " + taskId + " for player " + p.getName());
                    }
                }
                for (String key : removeTasks) {
                    PlayertaskID.remove(key);
                }
                removeTasks.clear();
            }
        } else {
            stopTaskPlayer(p);
        }
        // Exit command as player
        if (er.flagExists("player-exit-command") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.player-exit-command")) {
            String[] cmds = er.getFlagString("player-exit-command").split(",");
            for (String cmd : cmds) {
                if (cmd.startsWith("/")) {
                    cmd = cmd.substring(1);
                }
                p.getServer().dispatchCommand(p.getPlayer(), cmd.replace("{player}", p.getName()).replace("{region}", er.getName()));
            }
        }
        // Pvp check to exit region
        if (er.flagExists("forcepvp") && RedProtect.get().PvPm) {
            if (PvPState.containsKey(p.getName()) && !p.hasPermission("redprotect.forcepvp.bypass")) {
                if (PvPState.get(p.getName()) != PvPlayer.get(p).hasPvPEnabled()) {
                    PvPlayer.get(p).setPvP(PvPState.get(p.getName()));
                }
                PvPState.remove(p.getName());
            }
        }
        // Exit command as console
        if (er.flagExists("server-exit-command") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.server-exit-command")) {
            String[] cmds = er.getFlagString("server-exit-command").split(",");
            for (String cmd : cmds) {
                if (cmd.startsWith("/")) {
                    cmd = cmd.substring(1);
                }
                RedProtect.get().serv.dispatchCommand(RedProtect.get().serv.getConsoleSender(), cmd.replace("{player}", p.getName()).replace("{region}", er.getName()));
            }
        }
    }
    // Enter check forcepvp flag
    if (RedProtect.get().PvPm) {
        if (r.canEnter(p) && r.flagExists("forcepvp") && !p.hasPermission("redprotect.forcepvp.bypass")) {
            PvPlayer pvpp = PvPlayer.get(p);
            if (r.forcePVP() != pvpp.hasPvPEnabled()) {
                PvPState.put(p.getName(), pvpp.hasPvPEnabled());
                pvpp.setPvP(r.forcePVP());
            }
        }
    }
    // Enter effect
    if (r.canEnter(p) && r.flagExists("effects") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.effects")) {
        String[] effects = r.getFlagString("effects").split(",");
        for (String effect : effects) {
            String eff = effect.split(" ")[0];
            String amplifier = effect.split(" ")[1];
            final PotionEffect fulleffect = new PotionEffect(PotionEffectType.getByName(eff), RPConfig.getInt("flags-configuration.effects-duration") * 20, Integer.parseInt(amplifier));
            int TaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(RedProtect.get(), new Runnable() {

                public void run() {
                    if (p.isOnline() && r.flagExists("effects")) {
                        p.addPotionEffect(fulleffect, true);
                    } else {
                        p.setAllowFlight(false);
                        try {
                            this.finalize();
                        } catch (Throwable e) {
                            RedProtect.get().logger.debug("Effects not finalized...");
                        }
                    }
                }
            }, 0, 20);
            PlayertaskID.put(TaskId + "_" + eff + r.getName(), p.getName());
            RedProtect.get().logger.debug("Added task ID: " + TaskId + "_" + eff + " for player " + p.getName());
        }
    }
    // enter fly flag
    if (r.canEnter(p) && r.flagExists("forcefly") && !RedProtect.get().ph.hasPermOrBypass(p, "redprotect.admin.flag.forcefly") && (p.getGameMode().equals(GameMode.SURVIVAL) || p.getGameMode().equals(GameMode.ADVENTURE))) {
        p.setAllowFlight(r.getFlagBool("forcefly"));
        p.setFlying(r.getFlagBool("forcefly"));
        int TaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(RedProtect.get(), new Runnable() {

            public void run() {
                if (p.isOnline() && r.flagExists("forcefly")) {
                    p.setAllowFlight(r.getFlagBool("forcefly"));
                    p.setFlying(r.getFlagBool("forcefly"));
                } else {
                    p.setAllowFlight(false);
                    p.setFlying(false);
                    try {
                        this.finalize();
                    } catch (Throwable e) {
                        RedProtect.get().logger.debug("forcefly not finalized...");
                    }
                }
            }
        }, 0, 80);
        PlayertaskID.put(TaskId + "_" + "forcefly" + r.getName(), p.getName());
        RedProtect.get().logger.debug("(RegionFlags fly)Added task ID: " + TaskId + "_" + "forcefly" + " for player " + p.getName());
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PvPlayer(me.NoChance.PvPManager.PvPlayer)

Example 3 with PvPlayer

use of me.NoChance.PvPManager.PvPlayer in project RedProtect by FabioZumbi12.

the class RPPlayerListener method PlayerLogin.

@EventHandler
public void PlayerLogin(PlayerJoinEvent e) {
    Player p = e.getPlayer();
    // Adjust inside region
    p.teleport(new Location(p.getWorld(), p.getLocation().getBlockX(), p.getLocation().getBlockY() + 0.1, p.getLocation().getBlockZ()));
    if (p.hasPermission("redprotect.update") && RedProtect.get().Update && !RPConfig.getBool("update-check.auto-update")) {
        RPLang.sendMessage(p, ChatColor.AQUA + "An update is available for RedProtect: " + RedProtect.get().UptVersion);
        RPLang.sendMessage(p, ChatColor.AQUA + "Use /rp update to download and automatically install this update.");
    }
    if (RPConfig.getString("region-settings.record-player-visit-method").equalsIgnoreCase("ON-LOGIN")) {
        String uuid = p.getUniqueId().toString();
        if (!RedProtect.get().OnlineMode) {
            uuid = p.getName().toLowerCase();
        }
        for (Region r : RedProtect.get().rm.getMemberRegions(uuid)) {
            if (r.getDate() == null || !r.getDate().equals(RPUtil.DateNow())) {
                r.setDate(RPUtil.DateNow());
            }
        }
    }
    String worldneeded = RPConfig.getString("server-protection.teleport-player.on-join.need-world-to-teleport");
    if (RPConfig.getBool("server-protection.teleport-player.on-join.enable") && (worldneeded.equals("none") || worldneeded.equals(p.getWorld().getName()))) {
        String[] loc = RPConfig.getString("server-protection.teleport-player.on-join.location").split(",");
        e.getPlayer().teleport(new Location(Bukkit.getWorld(loc[0]), Double.parseDouble(loc[1]) + 0.500, Double.parseDouble(loc[2]), Double.parseDouble(loc[3]) + 0.500));
    }
    // Pvp check on join
    if (RedProtect.get().PvPm) {
        Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
        if (!p.hasPermission("redprotect.forcepvp.bypass") && r != null && r.flagExists("forcepvp")) {
            PvPlayer pvpp = PvPlayer.get(p);
            if (r.forcePVP() != pvpp.hasPvPEnabled()) {
                PvPState.put(p.getName(), pvpp.hasPvPEnabled());
                pvpp.setPvP(r.forcePVP());
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PvPlayer(me.NoChance.PvPManager.PvPlayer) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PvPlayer (me.NoChance.PvPManager.PvPlayer)3 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)1 Location (org.bukkit.Location)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 PotionEffect (org.bukkit.potion.PotionEffect)1