Files
src
build.gradle
gradle.properties
Griece particals
manifest.kod
settings.gradle
Code
22 1,082
src/client/java/com/kodari/swordglow/ParticleBrightnessConfig.java
package com.kodari.swordglow;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Properties;
import java.awt.Color;
public final class ParticleBrightnessConfig {
private static final Path CONFIG_PATH = Path.of("config", "swordglow_particles.properties");
private static final EnumMap<Material, Color> COLORS = loadColors();
private static final EnumMap<Material, Float> BRIGHTNESS = loadBrightness();
private static boolean enchantedHitParticlesEnabled = loadEnchantedHitParticlesEnabled();
public enum Material {
WOOD,
STONE,
IRON,
COPPER,
MACE,
GOLD,
DIAMOND,
NETHERITE
}
private ParticleBrightnessConfig() {
}
public static Color getColor(Material material) {
return COLORS.get(material);
}
public static void setColor(Material material, Color color) {
COLORS.put(material, new Color(color.getRed(), color.getGreen(), color.getBlue()));
}
public static float getBrightness(Material material) {
return BRIGHTNESS.get(material);
}
public static void setBrightness(Material material, float value) {
if (Float.isFinite(value)) {
BRIGHTNESS.put(material, Math.max(0.0F, Math.min(2.0F, value)));
}
}
public static boolean isEnchantedHitParticlesEnabled() {
return enchantedHitParticlesEnabled;
}
public static void setEnchantedHitParticlesEnabled(boolean enabled) {
enchantedHitParticlesEnabled = enabled;
}
public static void save() {
Properties properties = new Properties();
properties.setProperty("enchanted_hit_particles_enabled", Boolean.toString(enchantedHitParticlesEnabled));
for (Material material : Material.values()) {
properties.setProperty(material.name().toLowerCase(Locale.ROOT),
String.format(Locale.ROOT, "%06X", COLORS.get(material).getRGB() & 0xFFFFFF));
properties.setProperty(material.name().toLowerCase(Locale.ROOT) + "_brightness",
Float.toString(BRIGHTNESS.get(material)));
}
try {
Files.createDirectories(CONFIG_PATH.getParent());
try (OutputStream output = Files.newOutputStream(CONFIG_PATH)) {
properties.store(output, "Swordglow particle settings");
}
} catch (IOException ignored) {
}
}
private static EnumMap<Material, Color> loadColors() {
EnumMap<Material, Color> colors = defaultColors();
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(CONFIG_PATH)) {
properties.load(input);
} catch (IOException ignored) {
return colors;
}
for (Material material : Material.values()) {
String value = properties.getProperty(material.name().toLowerCase(Locale.ROOT));
if (value == null) {
continue;
}
try {
colors.put(material, new Color(Integer.parseInt(value, 16)));
} catch (NumberFormatException ignored) {
}
}
return colors;
}
private static EnumMap<Material, Float> loadBrightness() {
EnumMap<Material, Float> brightness = new EnumMap<>(Material.class);
for (Material material : Material.values()) {
brightness.put(material, 1.0F);
}
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(CONFIG_PATH)) {
properties.load(input);
} catch (IOException ignored) {
return brightness;
}
for (Material material : Material.values()) {
String value = properties.getProperty(material.name().toLowerCase(Locale.ROOT) + "_brightness");
if (value == null) {
continue;
}
try {
float parsed = Float.parseFloat(value);
if (Float.isFinite(parsed)) {
brightness.put(material, Math.max(0.0F, Math.min(2.0F, parsed)));
}
} catch (NumberFormatException ignored) {
}
}
return brightness;
}
private static boolean loadEnchantedHitParticlesEnabled() {
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(CONFIG_PATH)) {
properties.load(input);
return Boolean.parseBoolean(properties.getProperty("enchanted_hit_particles_enabled", "true"));
} catch (IOException ignored) {
return true;
}
}
private static EnumMap<Material, Color> defaultColors() {
EnumMap<Material, Color> colors = new EnumMap<>(Material.class);
colors.put(Material.WOOD, new Color(0xB98555));
colors.put(Material.STONE, new Color(0x9DA3A7));
colors.put(Material.IRON, new Color(0xD9E3EA));
colors.put(Material.COPPER, new Color(0xC87941));
colors.put(Material.MACE, new Color(0xFF6A1F));
colors.put(Material.GOLD, new Color(0xFFD54A));
colors.put(Material.DIAMOND, new Color(0x36E6D5));
colors.put(Material.NETHERITE, new Color(0x9C69D8));
return colors;
}
}