Added strengths

This commit is contained in:
Auxilor
2021-01-01 21:32:36 +00:00
parent 6a48b695c6
commit 75c5b7e8c8
23 changed files with 74 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ package com.willfp.talismans.config;
import com.willfp.eco.util.config.ValueGetter;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.talismans.talismans.meta.TalismanStrength;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.configuration.InvalidConfigurationException;
@@ -48,24 +49,37 @@ public abstract class TalismanYamlConfig extends PluginDependent implements Valu
*/
private final Class<?> source;
/**
* The talisman strength.
*/
private final TalismanStrength strength;
/**
* Create new talisman config yml.
*
* @param name The config name.
* @param source The class of the main class of source or extension.
* @param name The config name.
* @param strength The talisman strength.
* @param source The class of the main class of source or extension.
*/
protected TalismanYamlConfig(@NotNull final String name,
@NotNull final TalismanStrength strength,
@NotNull final Class<?> source) {
super(AbstractEcoPlugin.getInstance());
this.name = name;
this.source = source;
this.strength = strength;
File basedir = new File(this.getPlugin().getDataFolder(), "talismans/");
if (!basedir.exists()) {
basedir.mkdirs();
}
this.directory = basedir;
File dir = new File(basedir, strength.name().toLowerCase() + "/");
if (!dir.exists()) {
dir.mkdirs();
}
this.directory = dir;
if (!new File(directory, name + ".yml").exists()) {
createFile();
@@ -78,7 +92,7 @@ public abstract class TalismanYamlConfig extends PluginDependent implements Valu
}
private void saveResource() {
String resourcePath = "/talismans/" + name + ".yml";
String resourcePath = "/talismans/" + strength.name().toLowerCase() + "/" + name + ".yml";
InputStream in = source.getResourceAsStream(resourcePath);
@@ -116,7 +130,7 @@ public abstract class TalismanYamlConfig extends PluginDependent implements Valu
try {
config.load(configFile);
String resourcePath = "/talismans/" + name + ".yml";
String resourcePath = "/talismans/" + strength.name().toLowerCase() + "/" + name + ".yml";
InputStream newIn = source.getResourceAsStream(resourcePath);
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));

View File

@@ -1,6 +1,7 @@
package com.willfp.talismans.config.configs;
import com.willfp.talismans.config.TalismanYamlConfig;
import com.willfp.talismans.talismans.meta.TalismanStrength;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@@ -14,12 +15,14 @@ public class TalismanConfig extends TalismanYamlConfig {
/**
* Instantiate a new config for a talisman.
*
* @param name The name of the config.
* @param plugin The provider of the talisman.
* @param name The name of the config.
* @param strength The strength of the talisman.
* @param plugin The provider of the talisman.
*/
public TalismanConfig(@NotNull final String name,
@NotNull final TalismanStrength strength,
@NotNull final Class<?> plugin) {
super(name, plugin);
super(name, strength, plugin);
this.name = name;
}
}

View File

@@ -8,6 +8,7 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.talismans.config.TalismansConfigs;
import com.willfp.talismans.config.configs.TalismanConfig;
import com.willfp.talismans.display.TalismanDisplay;
import com.willfp.talismans.talismans.meta.TalismanStrength;
import com.willfp.talismans.talismans.util.TalismanUtils;
import com.willfp.talismans.talismans.util.Watcher;
import lombok.AccessLevel;
@@ -70,6 +71,14 @@ public abstract class Talisman implements Listener, Watcher {
@Getter
private final String configName;
/**
* The strength of the talisman
* <p>
* Talisman is weakest, then ring, then relic.
*/
@Getter
private final TalismanStrength strength;
/**
* The talisman's config.
*/
@@ -103,14 +112,17 @@ public abstract class Talisman implements Listener, Watcher {
/**
* Create a new Talisman.
*
* @param key The key name of the talisman
* @param prerequisites Optional {@link Prerequisite}s that must be met
* @param key The key name of the talisman.
* @param strength The strength of the talisman.
* @param prerequisites Optional {@link Prerequisite}s that must be met.
*/
protected Talisman(@NotNull final String key,
@NotNull final TalismanStrength strength,
@NotNull final Prerequisite... prerequisites) {
this.strength = strength;
this.key = this.getPlugin().getNamespacedKeyFactory().create(key);
this.configName = key.replace("_", "");
TalismansConfigs.addTalismanConfig(new TalismanConfig(this.configName, this.getClass()));
TalismansConfigs.addTalismanConfig(new TalismanConfig(this.configName, this.strength, this.getClass()));
this.config = TalismansConfigs.getTalismanConfig(this.configName);
if (!Prerequisite.areMet(prerequisites)) {

View File

@@ -0,0 +1,26 @@
package com.willfp.talismans.talismans.meta;
import com.willfp.eco.util.config.Configs;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum TalismanStrength {
TALISMAN(() -> Configs.CONFIG.getString("strengths.talisman.color")),
RING(() -> Configs.CONFIG.getString("strengths.ring.color")),
RELIC(() -> Configs.CONFIG.getString("strengths.relic.color"));
private String color;
private final Supplier<String> colorSupplier;
TalismanStrength(@NotNull final Supplier<String> colorSupplier) {
this.colorSupplier = colorSupplier;
this.color = colorSupplier.get();
}
public static void update() {
for (TalismanStrength strength : TalismanStrength.values()) {
strength.color = strength.colorSupplier.get();
}
}
}

View File

@@ -7,6 +7,14 @@ description:
# How many characters to have on each line of description.
wrap: 20
strengths:
talisman:
color: "&e"
ring:
color: "&c"
relic:
color: "&d"
drops:
### ADVANCED OPTIONS
collate: false