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

The following examples show how to use br.net.fabiozumbi12.RedProtect.Bukkit.Region#getName() . 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: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void addProps(YamlConfiguration fileDB, Region r) {
    String rname = r.getName();
    fileDB.createSection(rname);
    fileDB.set(rname + ".name", rname);
    fileDB.set(rname + ".lastvisit", r.getDate());
    fileDB.set(rname + ".admins", r.getAdmins().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".members", r.getMembers().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".leaders", r.getLeaders().stream().map(t -> t.getUUID() + "@" + t.getPlayerName()).collect(Collectors.toList()));
    fileDB.set(rname + ".priority", r.getPrior());
    fileDB.set(rname + ".welcome", r.getWelcome());
    fileDB.set(rname + ".world", r.getWorld());
    fileDB.set(rname + ".maxX", r.getMaxMbrX());
    fileDB.set(rname + ".maxZ", r.getMaxMbrZ());
    fileDB.set(rname + ".minX", r.getMinMbrX());
    fileDB.set(rname + ".minZ", r.getMinMbrZ());
    fileDB.set(rname + ".maxY", r.getMaxY());
    fileDB.set(rname + ".minY", r.getMinY());
    fileDB.set(rname + ".value", r.getValue());
    fileDB.set(rname + ".flags", r.getFlags());
    fileDB.set(rname + ".candelete", r.canDelete());
    fileDB.set(rname + ".canpurge", r.canPurge());

    Location loc = r.getTPPoint();
    if (loc != null) {
        int x = loc.getBlockX();
        int y = loc.getBlockY();
        int z = loc.getBlockZ();
        float yaw = loc.getYaw();
        float pitch = loc.getPitch();
        fileDB.set(rname + ".tppoint", x + "," + y + "," + z + "," + yaw + "," + pitch);
    } else {
        fileDB.set(rname + ".tppoint", "");
    }
}
 
Example 2
Source File: RedProtectUtil.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public int SingleToFiles() {
    int saved = 0;
    for (World w : Bukkit.getWorlds()) {
        Set<Region> regions = RedProtect.get().rm.getRegionsByWorld(w.getName());
        for (Region r : regions) {
            YamlConfiguration fileDB = new YamlConfiguration();

            File f = new File(RedProtect.get().getDataFolder() + File.separator + "data", w.getName());
            if (!f.exists()) {
                f.mkdir();
            }
            File wf = new File(RedProtect.get().getDataFolder() + File.separator + "data", w.getName() + File.separator + r.getName() + ".yml");

            saved++;
            addProps(fileDB, r);
            saveYaml(fileDB, wf);
        }

        File oldf = new File(RedProtect.get().getDataFolder() + File.separator + "data", "data_" + w.getName() + ".yml");
        if (oldf.exists()) {
            oldf.delete();
        }
    }

    if (!RedProtect.get().config.configRoot().flat_file.region_per_file) {
        RedProtect.get().config.configRoot().flat_file.region_per_file = true;
    }
    RedProtect.get().config.save();
    return saved;
}
 
Example 3
Source File: CommandHandlers.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public static void handleRename(Player p, String newName) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "rename", r)) {
        if (r == null) {
            RedProtect.get().lang.sendMessage(p, "cmdmanager.region.todo.that");
            return;
        }

        //filter name
        newName = RedProtect.get().getUtil().fixRegionName(p, newName);
        if (newName == null) return;

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

        String oldname = event.getOldName();
        newName = event.getNewName();

        Region newRegion = RedProtect.get().rm.renameRegion(newName, r);
        RedProtect.get().lang.sendMessage(p, RedProtect.get().lang.get("cmdmanager.region.rename.newname") + " " + newRegion.getName());
        RedProtect.get().logger.addLog("(World " + r.getWorld() + ") Player " + p.getName() + " RENAMED region " + oldname + " to " + newRegion.getName());
    } else {
        RedProtect.get().lang.sendMessage(p, "no.permission");
    }
}
 
Example 4
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 5
Source File: DynmapHook.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public void addMark(Region r) {
    AreaMarker am = MSet.findAreaMarker(r.getID());

    double[] x = new double[4];
    double[] z = new double[4];
    int i = 0;
    for (Location l : r.get4Points(90)) {
        x[i] = l.getBlockX() + 0.500;
        z[i] = l.getBlockZ() + 0.500;
        i++;
    }

    if (am == null) {
        am = MSet.createAreaMarker(r.getID(), r.getName(), false, r.getWorld(), x, z, true);
    } else {
        am.setCornerLocations(x, z);
    }

    String rName = RedProtect.get().lang.get("region.name") + " <span style=\"font-weight:bold;\">" + r.getName() + "</span><br>";
    String area = RedProtect.get().lang.get("region.area") + " <span style=\"font-weight:bold;\">" + r.getArea() + "</span>";
    am.setDescription(ChatColor.stripColor(rName + area));

    if (RedProtect.get().config.configRoot().hooks.dynmap.show_leaders_admins) {
        String leader = RedProtect.get().lang.get("region.leaders") + " <span style=\"font-weight:bold;\">" + r.getLeadersDesc() + "</span><br>";
        String admin = RedProtect.get().lang.get("region.admins") + " <span style=\"font-weight:bold;\">" + r.getAdminDesc() + "</span><br>";
        am.setDescription(ChatColor.stripColor(rName + leader + admin + area));
    }

    int center = -1;
    if (RedProtect.get().config.configRoot().hooks.dynmap.cuboid_region.enabled) {
        am.setRangeY(r.getMinLocation().getBlockY() + 0.500, r.getMaxLocation().getBlockY() + 0.500);
    } else {
        center = RedProtect.get().config.configRoot().hooks.dynmap.cuboid_region.if_disable_set_center;
        am.setRangeY(center, center);
    }

    String type = "player";
    if (r.isLeader(RedProtect.get().config.configRoot().region_settings.default_leader))
        type = "server";

    am.setLineStyle(
            RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).border_weight,
            RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).border_opacity,
            Integer.decode(RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).border_color.replace("#", "0x")));
    am.setFillStyle(
            RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).fill_opacity,
            Integer.decode(RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).fill_color.replace("#", "0x")));


    if (RedProtect.get().config.configRoot().hooks.dynmap.show_icon) {
        Marker m = MSet.findMarker(r.getID());
        if (center == -1) {
            center = r.getCenterY();
        }

        MarkerIcon icon = MApi.getMarkerIcon(RedProtect.get().config.configRoot().hooks.dynmap.marker.get(type).marker_icon);

        if (m == null) {
            MSet.createMarker(r.getID(), r.getName(), r.getWorld(), r.getCenterX(), center, r.getCenterZ(), icon, true);
        } else {
            m.setLocation(r.getWorld(), r.getCenterX(), center, r.getCenterZ());
        }
    }
}