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

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect#get() . 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: Compat18.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInteractAS(PlayerInteractEvent e) {
    if (e.getClickedBlock() == null) {
        return;
    }

    if (RedProtect.get().bukkitVersion <= 180) {
        return;
    }
    Player p = e.getPlayer();
    Location l = e.getClickedBlock().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Material m = p.getItemInHand().getType();

    if (RedProtect.get().bukkitVersion >= 190 && e.getItem() != null) {
        m = e.getItem().getType();
    }

    if (m.equals(Material.ARMOR_STAND) || m.equals(Material.END_CRYSTAL)) {
        if (r != null && !r.canBuild(p) && !r.canPlace(m) && !r.canBreak(m)) {
            e.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
        }
    }
}
 
Example 2
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public boolean denyPotion(ItemStack result, Player p) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion <= 180 && Potion.fromItemStack(result) != null) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        if (Pots.contains(potname)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.denypotion");
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: SelectWECommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender || !RedProtect.get().ph.hasCommandPerm(sender, "select-we")) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        if (RedProtect.get().hooks.worldEdit) {
            Region r = RedProtect.get().rm.getTopRegion(player.getLocation());
            if (r == null) {
                RedProtect.get().lang.sendMessage(player, "cmdmanager.region.doesexists");
                return true;
            }
            WEHook.setSelectionFromRP(player, r.getMinLocation(), r.getMaxLocation());
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "select-we", true);
    return true;
}
 
Example 4
Source File: RegenAllCommand.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 1) {
        if (!RedProtect.get().hooks.worldEdit) {
            return true;
        }
        int regen = RedProtect.get().rm.regenAll(args[0]);
        if (regen <= 0) {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.noneregenerated"));
        } else {
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.regenerated").replace("{regions}", regen + "").replace("{player}", args[0]));
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "regenall", true);
    return true;
}
 
Example 5
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public boolean denyPotion(ItemStack result, World world) {
    List<String> Pots = RedProtect.get().config.globalFlagsRoot().worlds.get(world.getName()).deny_potions;
    if (result != null && Pots.size() > 0 && (result.getType().name().contains("POTION") || result.getType().name().contains("TIPPED"))) {
        String potname = "";
        if (RedProtect.get().bukkitVersion >= 190) {
            PotionMeta pot = (PotionMeta) result.getItemMeta();
            potname = pot.getBasePotionData().getType().name();
        }
        if (RedProtect.get().bukkitVersion < 190) {
            potname = Potion.fromItemStack(result).getType().name();
        }
        return Pots.contains(potname);
    }
    return false;
}
 
Example 6
Source File: RegionManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void remove(Region r, String w) {
    r.notifyRemove();
    WorldRegionManager rms = this.regionManagers.get(w);
    rms.remove(r);
    removeCache(r);
    if (RedProtect.get().hooks.Dyn && RedProtect.get().config.configRoot().hooks.dynmap.enable) {
        try {
            RedProtect.get().hooks.dynmapHook.removeMark(r);
        } catch (Exception ex) {
            ex.printStackTrace();
            RedProtect.get().logger.severe("Problems when remove marks to Dynmap. Is Dynmap updated?");
        }
    }
}
 
Example 7
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private void SendWelcomeMsg(final Player p, String wel) {
    if (RedProtect.get().config.configRoot().notify.welcome_mode.equalsIgnoreCase("OFF")) {
        return;
    }
    if (RedProtect.get().config.configRoot().notify.welcome_mode.equalsIgnoreCase("BOSSBAR")) {
        if (RedProtect.get().bukkitVersion >= 1110) {
            Compat111.sendBarMsg(wel, "GREEN", p);
        } else {
            if (RedProtect.get().hooks.bossBar) {
                BossBarAPI.setMessage(p, wel);
            } else {
                p.sendMessage(wel);
            }
        }
    }
    if (RedProtect.get().config.configRoot().notify.region_enter_mode.equalsIgnoreCase("ACTIONBAR")) {
        try {
            Class.forName("net.md_5.bungee.api.chat.BaseComponent");
            SpigotHelper.sendSpigotActionBar(p, wel);
        } catch (Exception ignored) {
            if (RedProtect.get().hooks.actionBar) {
                ActionBarAPI.sendActionBar(p, wel);
            } else {
                p.sendMessage(wel);
            }
        }
    }
    if (RedProtect.get().config.configRoot().notify.welcome_mode.equalsIgnoreCase("CHAT")) {
        p.sendMessage(wel);
    }
}
 
Example 8
Source File: RegionManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void unloadAll() {
    for (String w : this.regionManagers.keySet()) {
        regionManagers.get(w).clearRegions();
        if (RedProtect.get().hooks.Dyn && RedProtect.get().config.configRoot().hooks.dynmap.enable) {
            try {
                RedProtect.get().hooks.dynmapHook.removeAll(w);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    this.regionManagers.clear();
    this.bLoc.clear();
}
 
Example 9
Source File: Pos2Command.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;
    String claimmode = RedProtect.get().config.getWorldClaimType(player.getWorld().getName());
    if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().ph.hasCommandPerm(player, "redefine")) {
        return true;
    }

    if (args.length == 0) {
        Location pl = player.getLocation();
        RedProtect.get().secondLocationSelections.put(player, pl);
        player.sendMessage(RedProtect.get().lang.get("playerlistener.wand2") + RedProtect.get().lang.get("general.color") + " (" + ChatColor.GOLD + pl.getBlockX() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockY() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockZ() + RedProtect.get().lang.get("general.color") + ").");

        //show preview border
        if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
            Location loc1 = RedProtect.get().firstLocationSelections.get(player);
            Location loc2 = RedProtect.get().secondLocationSelections.get(player);
            if (RedProtect.get().hooks.worldEdit && RedProtect.get().config.configRoot().hooks.useWECUI) {
                WEHook.setSelectionRP(player, loc1, loc2);
            }

            if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RedProtect.get().config.configRoot().region_settings.max_scan && !RedProtect.get().ph.hasPerm(player, "redprotect.bypass.define-max-distance")) {
                double dist = loc1.distanceSquared(loc2);
                RedProtect.get().lang.sendMessage(player, String.format(RedProtect.get().lang.get("regionbuilder.selection.maxdefine"), RedProtect.get().config.configRoot().region_settings.max_scan, (int) dist));
            } else {
                RedProtect.get().getUtil().addBorder(player, new Region("", loc1, loc2, player.getWorld().getName()));
            }
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "pos2", true);
    return true;
}
 
Example 10
Source File: Pos1Command.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    String claimmode = RedProtect.get().config.getWorldClaimType(player.getWorld().getName());
    if (!claimmode.equalsIgnoreCase("WAND") && !claimmode.equalsIgnoreCase("BOTH") && !RedProtect.get().ph.hasCommandPerm(player, "redefine")) {
        return true;
    }

    if (args.length == 0) {
        Location pl = player.getLocation();
        RedProtect.get().firstLocationSelections.put(player, pl);
        player.sendMessage(RedProtect.get().lang.get("playerlistener.wand1") + RedProtect.get().lang.get("general.color") + " (" + ChatColor.GOLD + pl.getBlockX() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockY() + RedProtect.get().lang.get("general.color") + ", " + ChatColor.GOLD + pl.getBlockZ() + RedProtect.get().lang.get("general.color") + ").");

        //show preview border
        if (RedProtect.get().firstLocationSelections.containsKey(player) && RedProtect.get().secondLocationSelections.containsKey(player)) {
            Location loc1 = RedProtect.get().firstLocationSelections.get(player);
            Location loc2 = RedProtect.get().secondLocationSelections.get(player);
            if (RedProtect.get().hooks.worldEdit && RedProtect.get().config.configRoot().hooks.useWECUI) {
                WEHook.setSelectionRP(player, loc1, loc2);
            }

            if (loc1.getWorld().equals(loc2.getWorld()) && loc1.distanceSquared(loc2) > RedProtect.get().config.configRoot().region_settings.max_scan) {
                double dist = loc1.distanceSquared(loc2);
                RedProtect.get().lang.sendMessage(player, String.format(RedProtect.get().lang.get("regionbuilder.selection.maxdefine"), RedProtect.get().config.configRoot().region_settings.max_scan, (int) dist));
            } else {
                RedProtect.get().getUtil().addBorder(player, new Region("", loc1, loc2, player.getWorld().getName()));
            }
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "pos1", true);
    return true;
}
 
Example 11
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private static void sendFlagHelp(Player p) {
    p.sendMessage(RedProtect.get().lang.get("general.color") + "-------------[RedProtect Flags]------------");
    p.sendMessage(RedProtect.get().lang.get("cmdmanager.region.flag.list") + " " + RedProtect.get().config.getDefFlags());
    p.sendMessage(RedProtect.get().lang.get("general.color") + "------------------------------------");

    StringBuilder sb = new StringBuilder();
    for (String flag : RedProtect.get().config.AdminFlags) {
        if (RedProtect.get().ph.hasFlagPerm(p, flag))
            sb.append(flag).append(", ");
    }
    if (sb.length() > 1) {
        p.sendMessage(RedProtect.get().lang.get("cmdmanager.region.flag.admlist") + " [" + sb.toString().substring(0, sb.length() - 2) + "]");
        p.sendMessage(RedProtect.get().lang.get("general.color") + "------------------------------------");
    }
}
 
Example 12
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handletp(CommandSender sender, String rname, String wname, Player play) {
    World w = RedProtect.get().getServer().getWorld(wname);
    if (w == null) {
        RedProtect.get().lang.sendMessage(sender, "cmdmanager.region.invalidworld");
        return;
    }
    Region region = RedProtect.get().rm.getRegion(rname, w.getName());
    if (region == null) {
        RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + rname);
        return;
    }

    if (play == null) {
        if (sender instanceof Player && !RedProtect.get().ph.hasRegionPermMember((Player) sender, "teleport", region)) {
            RedProtect.get().lang.sendMessage(sender, "no.permission");
            return;
        }
    } else {
        if (!RedProtect.get().ph.hasPerm(sender, "redprotect.command.admin.teleport")) {
            RedProtect.get().lang.sendMessage(sender, "no.permission");
            return;
        }
    }

    Location loc = null;
    if (region.getTPPoint() != null) {
        loc = region.getTPPoint();
        loc.setX(loc.getBlockX() + 0.500);
        loc.setZ(loc.getBlockZ() + 0.500);
    } else {
        int limit = w.getMaxHeight();
        if (w.getEnvironment().equals(World.Environment.NETHER)) {
            limit = 124;
        }
        for (int i = limit; i > 0; i--) {
            Material mat = w.getBlockAt(region.getCenterX(), i, region.getCenterZ()).getType();
            Material mat1 = w.getBlockAt(region.getCenterX(), i + 1, region.getCenterZ()).getType();
            Material mat2 = w.getBlockAt(region.getCenterX(), i + 2, region.getCenterZ()).getType();
            if (!mat.name().contains("LAVA") && !mat.equals(Material.AIR) && mat1.equals(Material.AIR) && mat2.equals(Material.AIR)) {
                loc = new Location(w, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500);
                break;
            }
        }
    }

    if (loc != null) {
        if (play != null) {
            if (RedProtect.get().hooks.essentials && sender instanceof Player) {
                RedProtect.get().hooks.pless.getUser(sender).setLastLocation();
            }
            play.teleport(loc);
            RedProtect.get().lang.sendMessage(play, RedProtect.get().lang.get("cmdmanager.region.teleport") + " " + rname);
            RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.tpother") + " " + rname);
        } else if (sender instanceof Player) {
            tpWait((Player) sender, loc, rname);
        }
    }
}
 
Example 13
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public FlagGui(String name, Player player, Region region, boolean editable, int maxSlots) {
    this.editable = editable;
    this.name = name;
    this.player = player;
    this.region = region;
    if (maxSlots <= 9) {
        this.size = 9;
    } else if (maxSlots <= 18) {
        this.size = 18;
    } else if (maxSlots <= 27) {
        this.size = 27;
    } else if (maxSlots <= 36) {
        this.size = 36;
    } else if (maxSlots <= 45) {
        this.size = 45;
    } else if (maxSlots <= 54) {
        this.size = 54;
    } else {
        throw new IllegalArgumentException("Parameter size is exceeding size limit (54)");
    }
    this.guiItems = new ItemStack[this.size];

    allowEnchant = RedProtect.get().bukkitVersion >= 181;

    for (String flag : RedProtect.get().config.getDefFlags()) {
        try {
            if (!RedProtect.get().config.guiRoot().gui_flags.containsKey(flag)) {
                continue;
            }
            if (RedProtect.get().ph.hasFlagPerm(player, flag) && (RedProtect.get().config.configRoot().flags.containsKey(flag) || RedProtect.get().config.AdminFlags.contains(flag))) {
                if (flag.equals("pvp") && !RedProtect.get().config.configRoot().flags.containsKey("pvp")) {
                    continue;
                }

                int i = RedProtect.get().config.getGuiSlot(flag);

                Object flagValue = region.getFlags().get(flag);

                String flagString;
                if (flagValue instanceof Boolean) {
                    flagString = RedProtect.get().guiLang.getFlagString(flagValue.toString());
                } else {
                    flagString = RedProtect.get().guiLang.getFlagString("list");
                }

                if (flag.equalsIgnoreCase("clan")) {
                    if (flagValue.toString().equals("")) {
                        flagString = RedProtect.get().guiLang.getFlagString("false");
                    } else {
                        flagString = RedProtect.get().guiLang.getFlagString("true");
                    }
                }

                this.guiItems[i] = new ItemStack(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material));
                ItemMeta guiMeta = this.guiItems[i].getItemMeta();
                guiMeta.setDisplayName(translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagName(flag)));
                List<String> lore = new ArrayList<>(Arrays.asList(
                        translateAlternateColorCodes('&', RedProtect.get().guiLang.getFlagString("value") + " " + flagString),
                        "ยง0" + flag));
                lore.addAll(RedProtect.get().guiLang.getFlagDescription(flag));
                guiMeta.setLore(lore);
                if (allowEnchant) {
                    if (flagValue.toString().equalsIgnoreCase("true")) {
                        guiMeta.addEnchant(Enchantment.DURABILITY, 0, true);
                    } else {
                        guiMeta.removeEnchant(Enchantment.DURABILITY);
                    }
                    guiMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
                } else {
                    if (flagValue.toString().equalsIgnoreCase("true")) {
                        this.guiItems[i].setAmount(2);
                    } else {
                        this.guiItems[i].setAmount(1);
                    }
                }
                this.guiItems[i].setType(Material.getMaterial(RedProtect.get().config.guiRoot().gui_flags.get(flag).material));
                this.guiItems[i].setItemMeta(guiMeta);
            }
        } catch (Exception e) {
            this.player.sendMessage(ChatColor.RED + "Seems RedProtect have a wrong Item Gui or a problem on guiconfig for flag " + flag);
        }
    }

    for (int slotc = 0; slotc < this.size; slotc++) {
        if (this.guiItems[slotc] == null) {
            this.guiItems[slotc] = RedProtect.get().config.getGuiSeparator();
        }
    }
}
 
Example 14
Source File: TaskChain.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public TaskChain() {
    this.plugin = RedProtect.get(); // TODO: Change to get an instance to your plugin!
    this.async = !Bukkit.isPrimaryThread();
}
 
Example 15
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public static void handleDelete(Player p) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }

        int claims = RedProtect.get().config.configRoot().region_settings.can_delete_first_home_after_claims;
        if (!r.canDelete() && (claims == -1 || RedProtect.get().rm.getPlayerRegions(p.getUniqueId().toString(), p.getWorld().getName()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }

        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }

        String rname = r.getName();
        String w = r.getWorld();
        RedProtect.get().rm.remove(r, w);
        RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + w + ") Player " + p.getName() + " REMOVED region " + rname);

        // Handle money
        if (RedProtect.get().config.ecoRoot().claim_cost_per_block.enable && RedProtect.get().hooks.vault && !p.hasPermission("redprotect.eco.bypass")) {
            long reco = r.getArea() * RedProtect.get().config.ecoRoot().claim_cost_per_block.cost_per_block;

            if (!RedProtect.get().config.ecoRoot().claim_cost_per_block.y_is_free) {
                reco = reco * Math.abs(r.getMaxY() - r.getMinY());
            }

            if (reco > 0) {
                RedProtect.get().economy.depositPlayer(p, reco);
                p.sendMessage(RedProtect.get().lang.get("economy.region.deleted").replace("{price}", RedProtect.get().config.ecoRoot().economy_symbol + reco + " " + RedProtect.get().config.ecoRoot().economy_name));
            }
        }
    } else {
        RedProtect.get().lang.sendMessage(p, "no.permission");
    }
}
 
Example 16
Source File: CommandHandler.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
private static boolean handleWGRegions() {
    if (!RedProtect.get().hooks.worldguard) {
        return false;
    }

    WorldGuardHelper helper = RedProtect.get().hooks.worldGuardHelper;

    List<RegionManager> loaded = helper.getLoaded();
    if (loaded.isEmpty()) return false;

    int i = 0;
    for (RegionManager rm : loaded) {
        if (rm.getRegions().isEmpty()) continue;

        String w = rm.getName();
        for (Map.Entry<String, ProtectedRegion> pr : rm.getRegions().entrySet()) {
            if (!pr.getValue().getType().equals(RegionType.CUBOID)) continue;
            if (RedProtect.get().rm.getRegion(pr.getKey(), w) != null) continue;

            Set<PlayerRegion> leaders;
            Set<PlayerRegion> members;

            if (!pr.getValue().getOwners().getUniqueIds().isEmpty())
                leaders = pr.getValue().getOwners().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
            else
                leaders = pr.getValue().getOwners().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());

            if (!pr.getValue().getMembers().getUniqueIds().isEmpty())
                members = pr.getValue().getMembers().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
            else
                members = pr.getValue().getMembers().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());

            if (leaders.isEmpty()) {
                if (members.isEmpty())
                    leaders.add(new PlayerRegion(RedProtect.get().config.configRoot().region_settings.default_leader, RedProtect.get().config.configRoot().region_settings.default_leader));
                else
                    leaders.addAll(members);
            }

            Location min = helper.getMinimumPoint(pr.getValue(), Bukkit.getWorld(w));
            Location max = helper.getMaximumPoint(pr.getValue(), Bukkit.getWorld(w));

            Region r = new Region(pr.getKey(), new HashSet<>(), members, leaders, min, max, RedProtect.get().config.getDefFlagsValues(), "", pr.getValue().getPriority(), w, RedProtect.get().getUtil().dateNow(), 0, null, true, true);

            for (Map.Entry<Flag<?>, Object> flag : pr.getValue().getFlags().entrySet()) {
                if (r.flagExists(flag.getKey().getName()) && RedProtect.get().getUtil().parseObject(flag.getValue().toString()) != null) {
                    r.setFlag(Bukkit.getConsoleSender(), flag.getKey().getName(), RedProtect.get().getUtil().parseObject(flag.getValue().toString()));
                }
            }
            RedProtect.get().rm.add(r, w);
            RedProtect.get().logger.warning("Region converted and named to " + r.getName());
            i++;
        }
        RedProtect.get().logger.success(i + " WorldGuard regions imported for world " + w);
    }
    return i > 0;
}
 
Example 17
Source File: PermissionHandler.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
private boolean hasVaultPerm(CommandSender player, String perm) {
    if (RedProtect.get().config.configRoot().permissions_limits.useVault && player instanceof Player && RedProtect.get().permission != null) {
        return RedProtect.get().permission.playerHas(((Player) player).getWorld().getName(), (Player) player, perm);
    }
    return player.hasPermission(perm);
}
 
Example 18
Source File: HookRedProtect.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static RedProtectAPI getAPI() {
    RedProtect redProtect = RedProtect.get();
    return redProtect.getAPI();
}
 
Example 19
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()));
            }
        }
    }
}
 
Example 20
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
private void EnterExitNotify(Region r, Player p) {
    if (RedProtect.get().config.configRoot().notify.region_enter_mode.equalsIgnoreCase("OFF")) {
        return;
    }

    if (!r.canEnter(p)) {
        return;
    }

    String leaderstring;
    String m = "";
    //Enter-Exit notifications
    if (r.getWelcome().equals("")) {
        if (RedProtect.get().config.configRoot().notify.region_enter_mode.equalsIgnoreCase("BOSSBAR")
                || RedProtect.get().config.configRoot().notify.region_enter_mode.equalsIgnoreCase("CHAT")) {
            StringBuilder leaderstringBuilder = new StringBuilder();
            for (PlayerRegion leader : r.getLeaders()) {
                leaderstringBuilder.append(", ").append(leader.getPlayerName());
            }
            leaderstring = leaderstringBuilder.toString();

            if (r.getLeaders().size() > 0) {
                leaderstring = leaderstring.substring(2);
            } else {
                leaderstring = "None";
            }
            m = RedProtect.get().lang.get("playerlistener.region.entered");
            m = m.replace("{leaders}", leaderstring);
            m = m.replace("{region}", r.getName());
        }
        if (RedProtect.get().bukkitVersion >= 1110) {
            SendNotifyMsg(p, m, "GREEN");
        } else {
            SendNotifyMsg(p, m, null);
        }
    } else {
        String wel = ChatColor.translateAlternateColorCodes('&',
                r.getWelcome().replace("{r}", r.getName())
                        .replace("{player}", p.getName()));
        SendWelcomeMsg(p, RedProtect.get().lang.get("playerlistener.region.welcome")
                .replace("{region}", r.getName()).replace("{message}", wel));
    }
}