Search in sources :

Example 16 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class PlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
    RedProtect.get().logger.debug(LogLevel.PLAYER, "PlayerListener - PlayerInteractEvent canceled? " + event.isCancelled());
    final Player p = event.getPlayer();
    Block b = event.getClickedBlock();
    ItemStack itemInHand = event.getItem();
    Location l;
    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.tpcancelled");
    }
    if (b != null) {
        l = b.getLocation();
    } else {
        l = p.getLocation();
    }
    if (itemInHand != null && !itemInHand.getType().equals(Material.AIR)) {
        String claimmode = RedProtect.get().getConfigManager().getWorldClaimType(p.getWorld().getName());
        if (itemInHand.getType().name().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().wands.adminWandID) && (p.hasPermission("redprotect.command.admin.wand") || (claimmode.equalsIgnoreCase("WAND") || claimmode.equalsIgnoreCase("BOTH")))) {
            if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
                if (!RedProtect.get().getUtil().canBuildNear(p, l)) {
                    event.setCancelled(true);
                    return;
                }
                RedProtect.get().secondLocationSelections.put(p, l);
                p.sendMessage(RedProtect.get().getLanguageManager().get("playerlistener.wand2") + RedProtect.get().getLanguageManager().get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RedProtect.get().getLanguageManager().get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RedProtect.get().getLanguageManager().get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RedProtect.get().getLanguageManager().get("general.color") + ").");
                event.setCancelled(true);
            }
            if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                if (!RedProtect.get().getUtil().canBuildNear(p, l)) {
                    event.setCancelled(true);
                    return;
                }
                RedProtect.get().firstLocationSelections.put(p, l);
                p.sendMessage(RedProtect.get().getLanguageManager().get("playerlistener.wand1") + RedProtect.get().getLanguageManager().get("general.color") + " (" + ChatColor.GOLD + l.getBlockX() + RedProtect.get().getLanguageManager().get("general.color") + ", " + ChatColor.GOLD + l.getBlockY() + RedProtect.get().getLanguageManager().get("general.color") + ", " + ChatColor.GOLD + l.getBlockZ() + RedProtect.get().getLanguageManager().get("general.color") + ").");
                event.setCancelled(true);
            }
            // show preview border
            if (RedProtect.get().firstLocationSelections.containsKey(p) && RedProtect.get().secondLocationSelections.containsKey(p)) {
                Location loc1 = RedProtect.get().firstLocationSelections.get(p);
                Location loc2 = RedProtect.get().secondLocationSelections.get(p);
                Region reference = new Region("", loc1, loc2, p.getWorld().getName());
                RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("cmdmanager.region.distance") + reference.getArea());
                if (RedProtect.get().hooks.checkWe() && RedProtect.get().getConfigManager().configRoot().hooks.useWECUI) {
                    WEHook.setSelectionRP(p, loc1, loc2);
                }
                if (loc1.getWorld().equals(loc2.getWorld()) && reference.getArea() > RedProtect.get().getConfigManager().configRoot().region_settings.max_scan && !RedProtect.get().getPermissionHandler().hasPerm(p, "redprotect.bypass.define-max-distance")) {
                    RedProtect.get().getLanguageManager().sendMessage(p, String.format(RedProtect.get().getLanguageManager().get("regionbuilder.selection.maxdefine"), RedProtect.get().getConfigManager().configRoot().region_settings.max_scan, reference.getArea()));
                } else {
                    RedProtect.get().getUtil().addBorder(p, reference);
                }
            }
            return;
        }
        if (itemInHand.getType().name().equalsIgnoreCase(RedProtect.get().getConfigManager().configRoot().wands.infoWandID)) {
            Region r = RedProtect.get().getRegionManager().getTopRegion(l);
            if (r == null) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.noregion.atblock");
            } else if (RedProtect.get().getPermissionHandler().hasRegionPermMember(p, "infowand", r)) {
                p.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "--------------- [" + ChatColor.GOLD + r.getName() + RedProtect.get().getLanguageManager().get("general.color") + "] ---------------");
                p.sendMessage(r.info());
                p.sendMessage(RedProtect.get().getLanguageManager().get("general.color") + "-----------------------------------------");
            } else {
                p.sendMessage(RedProtect.get().getLanguageManager().get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", r.getLeadersDesc()));
            }
            event.setCancelled(true);
            return;
        }
        if ((itemInHand.getType().name().contains("_HOE") || (!itemInHand.getType().isBlock() && b != null && b.getType().name().equals("FARMLAND"))) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
            Region r = RedProtect.get().getRegionManager().getTopRegion(l);
            if (r != null && r.canCrops()) {
                return;
            }
        }
    }
    if (event.isCancelled()) {
        return;
    }
    Region r = RedProtect.get().getRegionManager().getTopRegion(l);
    // start player checks
    if (r == null) {
        try {
            if (b != null && (b.getType().equals(Material.ANVIL) || b.getState() instanceof InventoryHolder || RedProtect.get().getConfigManager().configRoot().private_cat.allowed_blocks.stream().anyMatch(b.getType().name()::matches))) {
                boolean out = RedProtect.get().getConfigManager().configRoot().private_cat.allow_outside;
                if (out && !cont.canOpen(b, p)) {
                    RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                    event.setCancelled(true);
                }
            }
        } catch (Exception ignored) {
        }
    } else {
        // other blocks and interactions
        if (itemInHand != null && (event.getAction().name().equals("RIGHT_CLICK_BLOCK") || b == null)) {
            Material hand = itemInHand.getType();
            if (hand.equals(Material.ENDER_PEARL) && !r.canTeleport(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if ((hand.equals(Material.BOW) || (hand.name().contains("SNOW") && hand.name().contains("BALL")) || hand.name().contains("FIREWORK") || hand.equals(Material.EGG)) && !r.canProtectiles(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if (hand.equals(Material.POTION) && !r.usePotions(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            } else if (hand.name().contains("_EGG") && !r.canInteractPassives(p)) {
                RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                event.setCancelled(true);
                event.setUseItemInHand(Event.Result.DENY);
                return;
            }
        }
        // if (r != null) && (b != null) >>
        try {
            if (b != null) {
                if (b.getType().name().endsWith("PRESSURE_PLATE")) {
                    if (!r.canPressPlate(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantpressplate");
                        event.setCancelled(true);
                    }
                } else if (b.getType().equals(Material.DRAGON_EGG) || b.getType().name().contains("NOTE_BLOCK") || b.getType().name().contains("CAKE")) {
                    if (!r.canBuild(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                        event.setCancelled(true);
                    }
                } else if (b.getType().name().equalsIgnoreCase("BED") || b.getType().name().contains("_BED")) {
                    if (!r.isHomeAllowed(p) && !r.canBuild(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                        event.setCancelled(true);
                    }
                } else if (b.getState() instanceof Sign && RedProtect.get().getConfigManager().configRoot().region_settings.enable_flag_sign) {
                    Sign s = (Sign) b.getState();
                    String[] lines = s.getLines();
                    if (lines[0].equalsIgnoreCase("[flag]") && r.getFlags().containsKey(lines[1])) {
                        String flag = lines[1];
                        if (!(r.getFlags().get(flag) instanceof Boolean)) {
                            RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("playerlistener.region.sign.cantflag"));
                            return;
                        }
                        if (RedProtect.get().getPermissionHandler().hasFlagPerm(p, flag) && (RedProtect.get().getConfigManager().configRoot().flags.containsKey(flag) || RedProtect.get().getConfigManager().ADMIN_FLAGS.contains(flag))) {
                            if (r.isAdmin(p) || r.isLeader(p) || RedProtect.get().getPermissionHandler().hasPerm(p, "redprotect.admin.flag." + flag)) {
                                if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.enable) {
                                    if (RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.flags.contains(flag)) {
                                        if (!RedProtect.get().changeWait.contains(r.getName() + flag)) {
                                            RedProtect.get().getUtil().startFlagChanger(r.getName(), flag, p);
                                            changeFlag(r, flag, p, s);
                                            return;
                                        } else {
                                            RedProtect.get().getLanguageManager().sendMessage(p, RedProtect.get().getLanguageManager().get("gui.needwait.tochange").replace("{seconds}", "" + RedProtect.get().getConfigManager().configRoot().flags_configuration.change_flag_delay.seconds));
                                            return;
                                        }
                                    }
                                }
                                changeFlag(r, flag, p, s);
                                return;
                            }
                        }
                        RedProtect.get().getLanguageManager().sendMessage(p, "cmdmanager.region.flag.nopermregion");
                    }
                } else if (b.getType().name().contains("LEAVES") || b.getType().name().contains("LOG") || b.getType().name().contains("_WOOD")) {
                    if (!r.canTree() && !r.canBuild(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                        event.setCancelled(true);
                    }
                } else if (b.getType().equals(Material.ENDER_CHEST)) {
                    if (!r.canEnderChest(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                        event.setCancelled(true);
                    }
                } else if (b.getType().name().contains("SPAWNER")) {
                    if (!r.canPlaceSpawner(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                        event.setCancelled(true);
                    }
                } else if (b.getType().equals(Material.ANVIL) || b.getState().getData() instanceof InventoryHolder || RedProtect.get().getConfigManager().configRoot().private_cat.allowed_blocks.stream().anyMatch(b.getType().name()::matches)) {
                    if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantopen");
                        event.setCancelled(true);
                    }
                } else if (b.getType().name().contains("DAYLIGHT") || b.getType().name().contains("COMPARATOR") || b.getType().name().contains("REPEATER") || (b.getType().name().contains("REDSTONE") && !b.getType().equals(Material.REDSTONE_ORE))) {
                    if (!r.canRedstone(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                        event.setCancelled(true);
                    }
                } else if (b.getType().name().contains("LEVER")) {
                    if (!r.canLever(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantlever");
                        event.setCancelled(true);
                    }
                } else if (b.getType().name().contains("LECTERN")) {
                // Do nothing to allow read books
                } else if (b.getType().name().contains("BUTTON")) {
                    if (!r.canButton(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantbutton");
                        event.setCancelled(true);
                    }
                } else if (DoorManager.isOpenable(b) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
                    {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantdoor");
                        event.setCancelled(true);
                    } else {
                        DoorManager.ChangeDoor(b, r);
                    }
                } else if (itemInHand != null && (itemInHand.getType().name().startsWith("BOAT") || itemInHand.getType().name().contains("MINECART"))) {
                    if (!r.canMinecart(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "blocklistener.region.cantplace");
                        event.setUseItemInHand(Event.Result.DENY);
                        event.setCancelled(true);
                    }
                } else if (itemInHand != null && itemInHand.getType().equals(Material.WATER_BUCKET)) {
                    if (!r.canFish(p)) {
                        RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                        event.setUseItemInHand(Event.Result.DENY);
                        event.setCancelled(true);
                    }
                } else if ((event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && b.getType().name().contains("SIGN") && !r.canSign(p)) {
                    Sign sign = (Sign) b.getState();
                    for (String tag : RedProtect.get().getConfigManager().configRoot().region_settings.allow_sign_interact_tags) {
                        // check first rule
                        if (tag.equalsIgnoreCase(sign.getLine(0))) {
                            return;
                        }
                        // check if tag is owners or members names
                        if (tag.equalsIgnoreCase("{membername}")) {
                            for (PlayerRegion leader : r.getLeaders()) {
                                if (sign.getLine(0).equalsIgnoreCase(leader.getPlayerName())) {
                                    return;
                                }
                            }
                            for (PlayerRegion admin : r.getAdmins()) {
                                if (sign.getLine(0).equalsIgnoreCase(admin.getPlayerName())) {
                                    return;
                                }
                            }
                            for (PlayerRegion member : r.getMembers()) {
                                if (sign.getLine(0).equalsIgnoreCase(member.getPlayerName())) {
                                    return;
                                }
                            }
                        }
                        // check if tag is player name
                        if (tag.equalsIgnoreCase("{playername}")) {
                            if (sign.getLine(0).equalsIgnoreCase(p.getName())) {
                                return;
                            }
                        }
                    }
                    RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract.signs");
                    event.setUseItemInHand(Event.Result.DENY);
                    event.setCancelled(true);
                } else if ((itemInHand != null && !itemInHand.getType().equals(Material.AIR)) && !r.canBuild(p) && !r.canPlace(itemInHand.getType()) && !r.canBreak(itemInHand.getType()) && (itemInHand.getType().equals(Material.FLINT_AND_STEEL) || itemInHand.getType().equals(Material.BUCKET) || itemInHand.getType().equals(Material.LAVA_BUCKET) || itemInHand.getType().equals(Material.ITEM_FRAME) || itemInHand.getType().name().equals("END_CRYSTAL") || (!r.canFish(p) && itemInHand.getType().equals(Material.WATER_BUCKET)) || itemInHand.getType().equals(Material.PAINTING))) {
                    RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantuse");
                    event.setCancelled(true);
                    event.setUseItemInHand(Event.Result.DENY);
                    event.setUseInteractedBlock(Event.Result.DENY);
                } else if (!r.allowMod(p) && !RedProtect.get().getUtil().isBukkitBlock(b) && !r.canBreak(b.getType()) && !r.canPlace(b.getType())) {
                    RedProtect.get().getLanguageManager().sendMessage(p, "playerlistener.region.cantinteract");
                    event.setCancelled(true);
                    event.setUseItemInHand(Event.Result.DENY);
                    event.setUseInteractedBlock(Event.Result.DENY);
                }
            }
        } catch (Exception ex) {
            RedProtect.get().logger.warning("Theres an error on PlayerInteractEvent event: " + ex.getLocalizedMessage());
        }
    }
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Block(org.bukkit.block.Block) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Sign(org.bukkit.block.Sign) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 17 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class Region method addLeader.

/**
 * Add an leader to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
 *
 * @param uuid - UUID or Player Name.
 */
public void addLeader(String uuid) {
    setToSave(true);
    String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
    PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
    this.members.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.admins.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.leaders.add(pInfo);
    RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 18 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class Region method removeAdmin.

/**
 * Remove an admin to the Region. The string need to be UUID if Online Mode, or Player Name if Offline Mode.
 *
 * @param uuid - UUID or Player Name.
 */
public void removeAdmin(String uuid) {
    setToSave(true);
    String name = RedProtect.get().getUtil().UUIDtoPlayer(uuid).toLowerCase();
    PlayerRegion pInfo = new PlayerRegion(RedProtect.get().getUtil().PlayerToUUID(uuid), name);
    this.leaders.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.admins.removeIf(m -> m.getUUID().equalsIgnoreCase(uuid) || m.getPlayerName().equalsIgnoreCase(uuid));
    this.members.add(pInfo);
    RedProtect.get().getRegionManager().updateLiveRegion(this, "leaders", serializeMembers(leaders));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "admins", serializeMembers(admins));
    RedProtect.get().getRegionManager().updateLiveRegion(this, "members", serializeMembers(members));
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 19 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class PlayerListener method EnterExitNotify.

private void EnterExitNotify(Region r, Player p) {
    if (RedProtect.get().getConfigManager().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().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("CHAT") || RedProtect.get().getConfigManager().configRoot().notify.region_enter_mode.equalsIgnoreCase("BOSSBAR")) {
            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().getLanguageManager().get("playerlistener.region.entered");
            m = m.replace("{leaders}", leaderstring);
            m = m.replace("{region}", r.getName());
        }
        SendNotifyMsg(p, m);
    } else {
        String wel = r.getWelcome().replace("{r}", r.getName()).replace("{player}", p.getName());
        SendWelcomeMsg(p, RedProtect.get().getLanguageManager().get("playerlistener.region.welcome").replace("{region}", r.getName()).replace("{message}", wel));
    }
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Example 20 with PlayerRegion

use of br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion in project RedProtect by FabioZumbi12.

the class WorldMySQLRegionManager method load.

@Override
public void load() {
    if (this.dbcon == null) {
        ConnectDB();
    }
    try {
        PreparedStatement st = this.dbcon.prepareStatement("SELECT * FROM `" + tableName + "` WHERE world = ?");
        st.setString(1, this.world);
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            String finalName = "";
            try {
                RedProtect.get().logger.debug(LogLevel.DEFAULT, "Load Region: " + rs.getString("name") + ", World: " + this.world);
                HashMap<String, Object> flags = new HashMap<>();
                String rname = rs.getString("name");
                finalName = rname;
                int maxMbrX = rs.getInt("maxMbrX");
                int minMbrX = rs.getInt("minMbrX");
                int maxMbrZ = rs.getInt("maxMbrZ");
                int minMbrZ = rs.getInt("minMbrZ");
                int maxY = rs.getInt("maxY");
                int minY = rs.getInt("minY");
                int prior = rs.getInt("prior");
                String world = rs.getString("world");
                String date = rs.getString("date");
                String wel = rs.getString("wel");
                long value = rs.getLong("value");
                boolean candel = rs.getBoolean("candelete");
                boolean canPurge = rs.getBoolean("canpurge");
                Location<World> tppoint = null;
                if (rs.getString("tppoint") != null && !rs.getString("tppoint").equalsIgnoreCase("")) {
                    String[] tpstring = rs.getString("tppoint").split(",");
                    tppoint = new Location<>(Sponge.getServer().getWorld(world).get(), Double.parseDouble(tpstring[0]), Double.parseDouble(tpstring[1]), Double.parseDouble(tpstring[2]));
                }
                String serverName = RedProtect.get().getConfigManager().configRoot().region_settings.default_leader;
                Set<PlayerRegion> leaders;
                if (!rs.getString("leaders").isEmpty()) {
                    leaders = new HashSet<>(Arrays.asList(rs.getString("leaders").split(","))).stream().map(s -> {
                        String[] pi = s.split("@");
                        String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
                        if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
                            if (RedProtect.get().getUtil().isUUIDs(p[1])) {
                                String before = p[1];
                                p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
                                RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
                            }
                        }
                        return new PlayerRegion(p[0], p[1]);
                    }).collect(Collectors.toSet());
                } else {
                    leaders = new HashSet<>();
                }
                Set<PlayerRegion> admins;
                if (!rs.getString("admins").isEmpty()) {
                    admins = new HashSet<>(Arrays.asList(rs.getString("admins").split(","))).stream().map(s -> {
                        String[] pi = s.split("@");
                        String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
                        if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
                            if (RedProtect.get().getUtil().isUUIDs(p[1])) {
                                String before = p[1];
                                p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
                                RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
                            }
                        }
                        return new PlayerRegion(p[0], p[1]);
                    }).collect(Collectors.toSet());
                } else {
                    admins = new HashSet<>();
                }
                Set<PlayerRegion> members;
                if (!rs.getString("members").isEmpty()) {
                    members = new HashSet<>(Arrays.asList(rs.getString("members").split(","))).stream().map(s -> {
                        String[] pi = s.split("@");
                        String[] p = new String[] { pi[0], pi.length == 2 ? pi[1] : pi[0] };
                        if (!p[0].equalsIgnoreCase(serverName) && !p[1].equalsIgnoreCase(serverName)) {
                            if (RedProtect.get().getUtil().isUUIDs(p[1])) {
                                String before = p[1];
                                p[1] = RedProtect.get().getUtil().UUIDtoPlayer(p[1]) == null ? p[1] : RedProtect.get().getUtil().UUIDtoPlayer(p[1]).toLowerCase();
                                RedProtect.get().logger.success("Updated region " + rname + ", player &6" + before + " &ato &6" + p[1]);
                            }
                        }
                        return new PlayerRegion(p[0], p[1]);
                    }).collect(Collectors.toSet());
                } else {
                    members = new HashSet<>();
                }
                for (String flag : rs.getString("flags").split(",")) {
                    String key = flag.split(":")[0];
                    String replace = key + ":";
                    if (replace.length() <= flag.length()) {
                        flags.put(key, RedProtect.get().getUtil().parseObject(flag.substring(replace.length())));
                    }
                }
                Region newr = new Region(rname, admins, members, leaders, maxMbrX, minMbrX, maxMbrZ, minMbrZ, minY, maxY, flags, wel, prior, world, date, value, tppoint, candel, canPurge);
                regions.put(rname, newr);
            } catch (Exception e) {
                RedProtect.get().logger.severe("Error on load region " + finalName);
                CoreUtil.printJarVersion();
                e.printStackTrace();
            }
        }
        st.close();
        rs.close();
    } catch (SQLException e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) World(org.spongepowered.api.world.World) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)

Aggregations

PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)31 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)11 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)6 World (org.spongepowered.api.world.World)6 DefineRegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.actions.DefineRegionBuilder)4 RegionBuilder (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionBuilder)4 File (java.io.File)4 IOException (java.io.IOException)4 Player (org.bukkit.entity.Player)4 CoreUtil (br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Location (org.bukkit.Location)3 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)3 RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)2 LogLevel (br.net.fabiozumbi12.RedProtect.Core.helpers.LogLevel)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 ClipboardFormat (com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat)2 ClipboardReader (com.sk89q.worldedit.extent.clipboard.io.ClipboardReader)2 Operation (com.sk89q.worldedit.function.operation.Operation)2