Search in sources :

Example 1 with HiddenChunkStyle

use of org.dynmap.utils.MapChunkCache.HiddenChunkStyle in project dynmap by webbukkit.

the class DynmapMapCommands method handleWorldAddLimit.

private boolean handleWorldAddLimit(DynmapCommandSender sender, String[] args, DynmapCore core) {
    if (!core.checkPlayerPermission(sender, "dmap.worldset"))
        return true;
    if (args.length < 2) {
        sender.sendMessage("World ID required");
        return true;
    }
    /* Test if render active - quit if so */
    if (checkIfActive(core, sender)) {
        return true;
    }
    String world_id = args[1];
    DynmapWorld w = core.getMapManager().getWorld(world_id);
    if (w == null) {
        sender.sendMessage(String.format("World %s not found", world_id));
        return true;
    }
    String limittype = "visible";
    // Default to rectangle
    String type = "rect";
    int[] corner1 = null;
    int[] corner2 = null;
    int[] center = null;
    int radius = 0;
    HiddenChunkStyle style = null;
    // Other args are field:value
    for (int argid = 2; argid < args.length; argid++) {
        String[] argval = args[argid].split(":");
        if (argval.length != 2) {
            sender.sendMessage("Argument witout value: " + args[argid]);
            return false;
        }
        String[] toks;
        String id = argval[0];
        String val = argval[1];
        switch(id) {
            case "type":
                if ((val.equals("round")) || (val.equals("rect"))) {
                    type = val;
                } else {
                    sender.sendMessage("Bad type value: " + val);
                    return false;
                }
                break;
            case "limittype":
                if ((val.equals("visible")) || (val.equals("hidden"))) {
                    limittype = val;
                } else {
                    sender.sendMessage("Bad limittype value: " + val);
                    return false;
                }
                break;
            case "corner1":
            case "corner2":
            case "center":
                if ((type.equals("rect") && id.equals("center")) || (type.equals("round") && (!id.equals("center")))) {
                    sender.sendMessage("Bad parameter for type " + type + ": " + id);
                    return false;
                }
                toks = val.split("/");
                if (toks.length == 2) {
                    int x = 0, z = 0;
                    x = Integer.valueOf(toks[0]);
                    z = Integer.valueOf(toks[1]);
                    switch(id) {
                        case "corner1":
                            corner1 = new int[] { x, z };
                            break;
                        case "corner2":
                            corner2 = new int[] { x, z };
                            break;
                        case "center":
                            center = new int[] { x, z };
                            break;
                    }
                } else {
                    sender.sendMessage("Bad value for parameter " + id + ": " + val);
                    return false;
                }
                break;
            case "radius":
                if (!type.equals("round")) {
                    sender.sendMessage("Bad parameter for type " + type + ": " + id);
                    return false;
                }
                radius = Integer.valueOf(val);
                break;
            case "style":
                style = HiddenChunkStyle.fromValue(val);
                if (style == null) {
                    sender.sendMessage("Bad parameter for style: " + val);
                    return false;
                }
                break;
            default:
                sender.sendMessage("Bad parameter: " + id);
                return false;
        }
    }
    // If enough for rectange area, add it
    VisibilityLimit newlimit = null;
    if ((type.contentEquals("rect") && (corner1 != null) && (corner2 != null))) {
        newlimit = new RectangleVisibilityLimit(corner1[0], corner1[1], corner2[0], corner2[1]);
    } else if ((type.contentEquals("round") && (center != null) && (radius > 0.0))) {
        newlimit = new RoundVisibilityLimit(center[0], center[1], radius);
    }
    boolean updated = false;
    if (newlimit != null) {
        if (limittype.contentEquals("visible")) {
            if (w.visibility_limits == null) {
                w.visibility_limits = new ArrayList<VisibilityLimit>();
            }
            w.visibility_limits.add(newlimit);
        } else {
            if (w.hidden_limits == null) {
                w.hidden_limits = new ArrayList<VisibilityLimit>();
            }
            w.hidden_limits.add(newlimit);
        }
        updated = true;
    }
    // If new style, apply it
    if (style != null) {
        w.hiddenchunkstyle = style;
        updated = true;
    }
    // Apply update
    if (updated) {
        core.updateWorldConfig(w);
        sender.sendMessage("Refreshing configuration for world " + world_id);
        core.refreshWorld(world_id);
    }
    return true;
}
Also used : VisibilityLimit(org.dynmap.utils.VisibilityLimit) RoundVisibilityLimit(org.dynmap.utils.RoundVisibilityLimit) RectangleVisibilityLimit(org.dynmap.utils.RectangleVisibilityLimit) HiddenChunkStyle(org.dynmap.utils.MapChunkCache.HiddenChunkStyle) RectangleVisibilityLimit(org.dynmap.utils.RectangleVisibilityLimit) RoundVisibilityLimit(org.dynmap.utils.RoundVisibilityLimit)

Aggregations

HiddenChunkStyle (org.dynmap.utils.MapChunkCache.HiddenChunkStyle)1 RectangleVisibilityLimit (org.dynmap.utils.RectangleVisibilityLimit)1 RoundVisibilityLimit (org.dynmap.utils.RoundVisibilityLimit)1 VisibilityLimit (org.dynmap.utils.VisibilityLimit)1