Search in sources :

Example 1 with CachedServerIcon

use of org.bukkit.util.CachedServerIcon in project Denizen-For-Bukkit by DenizenScript.

the class ListPingScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    String determineLow = CoreUtilities.toLowerCase(determination);
    if (determineLow.startsWith("icon:")) {
        String iconFile = determination.substring("icon:".length());
        CachedServerIcon icon = iconCache.get(iconFile);
        if (icon != null) {
            event.setServerIcon(icon);
            return true;
        }
        File file = new File(iconFile);
        if (!Utilities.canReadFile(file)) {
            Debug.echoError("Cannot read icon file '" + iconFile + "' due to security settings in Denizen/config.yml");
            return false;
        }
        try {
            icon = Bukkit.loadServerIcon(file);
        } catch (Exception ex) {
            Debug.echoError(ex);
        }
        if (icon != null) {
            iconCache.put(iconFile, icon);
            event.setServerIcon(icon);
        }
        return true;
    }
    if (determination.length() > 0 && !determineLow.equalsIgnoreCase("none")) {
        List<String> values = CoreUtilities.split(determination, '|', 2);
        if (ArgumentHelper.matchesInteger(values.get(0))) {
            event.setMaxPlayers(Integer.parseInt(values.get(0)));
            if (values.size() == 2) {
                setMotd(values.get(1));
            }
        } else {
            setMotd(determination);
        }
        return true;
    } else {
        return super.applyDetermination(path, determinationObj);
    }
}
Also used : CachedServerIcon(org.bukkit.util.CachedServerIcon) File(java.io.File)

Aggregations

File (java.io.File)1 CachedServerIcon (org.bukkit.util.CachedServerIcon)1