AlttdGriefPrevention/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AlttdConfig.java

169 lines
8.6 KiB
Java
Raw Normal View History

2022-02-14 09:18:03 +00:00
package me.ryanhamshire.GriefPrevention.alttd.config;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
2022-02-15 13:07:31 +00:00
import me.ryanhamshire.GriefPrevention.alttd.util.Logger;
import org.spongepowered.configurate.ConfigurationNode;
2022-02-15 14:26:23 +00:00
import java.awt.*;
2022-02-15 13:07:31 +00:00
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
2022-02-14 09:18:03 +00:00
@SuppressWarnings("unused")
public class AlttdConfig extends AbstractConfiguration
{
private AlttdConfig() {
super(GriefPrevention.instance.getDataFolder(),"alttdconfig.yml");
}
static AlttdConfig config;
static int version;
public static void reload() {
config = new AlttdConfig();
version = config.getInt("config-version", 1);
config.set("config-version", 1);
config.readConfig(AlttdConfig.class, null);
}
2022-02-15 13:07:31 +00:00
private HashMap<Long, Long> getMap(String path, HashMap<Long, Long> def) {
set(path, def);
ConfigurationNode node = config.getNode(path);
HashMap<Long, Long> map = new HashMap<>();
for (Map.Entry<Object, ? extends ConfigurationNode> entry : node.childrenMap().entrySet()) {
try {
map.put(Long.parseLong(entry.getKey().toString()), Long.parseLong(entry.getValue().getString()));
} catch (NumberFormatException exception) {
// handle
}
}
return map;
}
2022-02-15 14:26:23 +00:00
Color getColor(String path, Color def) {
config.set(path, colorToHex(def));
return hexToColor(config.getString(path, colorToHex(def)));
}
String colorToHex(final Color color) {
return Integer.toHexString(color.getRGB() & 0x00FFFFFF);
}
Color hexToColor(final String hex) {
if (hex == null) {
return Color.RED;
}
String stripped = hex.replace("#", "");
int rgb = (int) Long.parseLong(stripped, 16);
return new Color(rgb);
}
2022-02-14 09:18:03 +00:00
public static boolean DEBUG_MODE = false;
2022-02-15 13:07:31 +00:00
public static boolean alternativeClaimExpiring = false;
public static int alternativeClaimExpireDays = 1;
public static int expireCheckRate = 1200;
public static HashMap<Long, Long> expiringClaims = new HashMap<>();
2022-02-14 09:18:03 +00:00
private static void settings() {
2022-02-15 13:07:31 +00:00
String node = "alternative-claim-expiring";
2022-02-14 09:18:03 +00:00
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
2022-02-15 13:07:31 +00:00
alternativeClaimExpiring = config.getBoolean(node + ".enabled", alternativeClaimExpiring);
alternativeClaimExpireDays = config.getInt(node + ".days", alternativeClaimExpireDays);
expireCheckRate = config.getInt(node + ".expire-check-rate", expireCheckRate);
// todo create an alternative way of loading these in
expiringClaims.clear();
config.getMap(node + ".claims", new HashMap<>())
.forEach((key, value) -> {
try {
expiringClaims.put(Long.parseLong(key.toString()), value);
} catch (NumberFormatException ignored) {}
});
}
public static void addExpiringClaim(Long id) {
expiringClaims.put(id, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(alternativeClaimExpireDays));
config.set("alternative-claim-expiring.claims", expiringClaims);
config.saveConfig();
2022-02-14 09:18:03 +00:00
}
2022-02-15 14:26:23 +00:00
public static String CONTROL_LABEL = "GriefPrevention";
public static boolean CONTROL_SHOW = true;
public static boolean CONTROL_HIDE = false;
public static String GRID_CONTROL_LABEL = "Gridlines";
public static boolean GRID_CONTROL_SHOW = true;
public static boolean GRID_CONTROL_HIDE = true;
public static int UPDATE_INTERVAL = 300;
public static Color STROKE_COLOR = Color.GREEN;
public static int STROKE_WEIGHT = 1;
public static double STROKE_OPACITY = 1.0D;
public static Color FILL_COLOR = Color.GREEN;
public static double FILL_OPACITY = 0.2D;
public static Color ADMIN_STROKE_COLOR = Color.BLUE;
public static int ADMIN_STROKE_WEIGHT = 1;
public static double ADMIN_STROKE_OPACITY = 1.0D;
public static Color ADMIN_FILL_COLOR = Color.BLUE;
public static double ADMIN_FILL_OPACITY = 0.2D;
public static Color EXPIRING_STROKE_COLOR = Color.PINK;
public static int EXPIRING_STROKE_WEIGHT = 1;
public static double EXPIRING_STROKE_OPACITY = 1.0D;
public static Color EXPIRING_FILL_COLOR = Color.PINK;
public static double EXPIRING_FILL_OPACITY = 0.2D;
public static String STRINGS_PUBLIC = "Public";
public static String CLAIM_TOOLTIP = "Claim Owner: <span style=\"font-weight:bold;\">{owner}</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span>";
public static String ADMIN_CLAIM_TOOLTIP = "<span style=\"font-weight:bold;\">Administrator Claim</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span>";
public static String EXPIRING_CLAIM_TOOLTIP = "<span style=\"font-weight:bold;\">Temporary Claim</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span><br/>" +
"Expires: <span style=\"font-weight:bold;\">{expiretime}</span>" ;
private static void mapSettings() {
CONTROL_LABEL = config.getString("settings.control.label", CONTROL_LABEL);
CONTROL_SHOW = config.getBoolean("settings.control.show", CONTROL_SHOW);
CONTROL_HIDE = config.getBoolean("settings.control.hide-by-default", CONTROL_HIDE);
GRID_CONTROL_LABEL = config.getString("settings.grid.label", GRID_CONTROL_LABEL);
GRID_CONTROL_SHOW = config.getBoolean("settings.grid.show", GRID_CONTROL_SHOW);
GRID_CONTROL_HIDE = config.getBoolean("settings.grid.hide-by-default", GRID_CONTROL_HIDE);
UPDATE_INTERVAL = config.getInt("settings.update-interval", UPDATE_INTERVAL);
STROKE_COLOR = config.getColor("settings.style.regular-claim.stroke.color", STROKE_COLOR);
STROKE_WEIGHT = config.getInt("settings.style.regular-claim.stroke.weight", STROKE_WEIGHT);
STROKE_OPACITY = config.getDouble("settings.regular-claim.style.stroke.opacity", STROKE_OPACITY);
FILL_COLOR = config.getColor("settings.style.regular-claim.fill.color", FILL_COLOR);
FILL_OPACITY = config.getDouble("settings.style.regular-claim.fill.opacity", FILL_OPACITY);
ADMIN_STROKE_COLOR = config.getColor("settings.style.admin-claim.stroke.color", ADMIN_STROKE_COLOR);
ADMIN_STROKE_WEIGHT = config.getInt("settings.style.admin-claim.stroke.weight", ADMIN_STROKE_WEIGHT);
ADMIN_STROKE_OPACITY = config.getDouble("settings.admin-claim.style.stroke.opacity", ADMIN_STROKE_OPACITY);
ADMIN_FILL_COLOR = config.getColor("settings.style.admin-claim.fill.color", ADMIN_FILL_COLOR);
ADMIN_FILL_OPACITY = config.getDouble("settings.style.admin-claim.fill.opacity", ADMIN_FILL_OPACITY);
EXPIRING_STROKE_COLOR = config.getColor("settings.style.expiring-claim.stroke.color", EXPIRING_STROKE_COLOR);
EXPIRING_STROKE_WEIGHT = config.getInt("settings.style.expiring-claim.stroke.weight", EXPIRING_STROKE_WEIGHT);
EXPIRING_STROKE_OPACITY = config.getDouble("settings.expiring-claim.style.stroke.opacity", EXPIRING_STROKE_OPACITY);
EXPIRING_FILL_COLOR = config.getColor("settings.style.expiring-claim.fill.color", EXPIRING_FILL_COLOR);
EXPIRING_FILL_OPACITY = config.getDouble("settings.style.expiring-claim.fill.opacity", EXPIRING_FILL_OPACITY);
STRINGS_PUBLIC = config.getString("settings.strings.public", STRINGS_PUBLIC);
CLAIM_TOOLTIP = config.getString("settings.region.tooltip.regular-claim", CLAIM_TOOLTIP);
ADMIN_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.admin-claim", ADMIN_CLAIM_TOOLTIP);
EXPIRING_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.expiring-claim", EXPIRING_CLAIM_TOOLTIP);
}
2022-02-14 09:18:03 +00:00
}