mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 16:09:24 +00:00
Added configs and boss loading
This commit is contained in:
@@ -1,5 +1,71 @@
|
||||
package com.willfp.ecobosses.bosses;
|
||||
|
||||
public class EcoBoss {
|
||||
import com.willfp.eco.internal.config.AbstractUndefinedConfig;
|
||||
import com.willfp.ecobosses.EcoBossesPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
}
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EcoBoss {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
private static final EcoBossesPlugin PLUGIN = EcoBossesPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The name of the set.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The config of the set.
|
||||
*/
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final AbstractUndefinedConfig config;
|
||||
|
||||
/**
|
||||
* Create a new Boss.
|
||||
*
|
||||
* @param name The name of the set.
|
||||
* @param config The set's config.
|
||||
*/
|
||||
public EcoBoss(@NotNull final String name,
|
||||
@NotNull final AbstractUndefinedConfig config) {
|
||||
this.config = config;
|
||||
this.name = name;
|
||||
|
||||
if (this.getConfig().getBool("enabled")) {
|
||||
EcoBosses.addBoss(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof EcoBoss)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EcoBoss boss = (EcoBoss) o;
|
||||
return this.getName().equals(boss.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EcoBoss{"
|
||||
+ this.getName()
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.willfp.ecobosses.bosses;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.ecobosses.EcoBossesPlugin;
|
||||
import com.willfp.ecobosses.config.configs.BaseBossConfig;
|
||||
import com.willfp.ecobosses.config.configs.CustomConfig;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class EcoBosses {
|
||||
/**
|
||||
* Registered armor sets.
|
||||
*/
|
||||
private static final BiMap<String, EcoBoss> BY_NAME = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Sets that exist by default.
|
||||
*/
|
||||
private static final List<String> DEFAULT_BOSSES = Arrays.asList(
|
||||
"illusioner"
|
||||
);
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoBoss}es.
|
||||
*
|
||||
* @return A list of all {@link EcoBoss}es.
|
||||
*/
|
||||
public static List<EcoBoss> values() {
|
||||
return ImmutableList.copyOf(BY_NAME.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EcoBoss} matching name.
|
||||
*
|
||||
* @param name The name to search for.
|
||||
* @return The matching {@link EcoBoss}, or null if not found.
|
||||
*/
|
||||
public static EcoBoss getByName(@NotNull final String name) {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all {@link EcoBoss}s.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
for (EcoBoss boss : values()) {
|
||||
removeBoss(boss);
|
||||
}
|
||||
|
||||
for (String defaultSetName : DEFAULT_BOSSES) {
|
||||
new EcoBoss(defaultSetName, new BaseBossConfig(defaultSetName));
|
||||
}
|
||||
|
||||
try {
|
||||
Files.walk(Paths.get(new File(EcoBossesPlugin.getInstance().getDataFolder(), "bosses/").toURI()))
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(path -> {
|
||||
String name = path.getFileName().toString().replace(".yml", "");
|
||||
new EcoBoss (
|
||||
name,
|
||||
new CustomConfig(name, YamlConfiguration.loadConfiguration(path.toFile()))
|
||||
);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link EcoBoss} to EcoBosses.
|
||||
*
|
||||
* @param set The {@link EcoBoss} to add.
|
||||
*/
|
||||
public static void addBoss(@NotNull final EcoBoss set) {
|
||||
BY_NAME.remove(set.getName());
|
||||
BY_NAME.put(set.getName(), set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link EcoBoss} from EcoBosses.
|
||||
*
|
||||
* @param set The {@link EcoBoss} to remove.
|
||||
*/
|
||||
public static void removeBoss(@NotNull final EcoBoss set) {
|
||||
BY_NAME.remove(set.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.ecobosses.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.ExtendableConfig;
|
||||
import com.willfp.ecobosses.EcoBossesPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BaseBossConfig extends ExtendableConfig {
|
||||
/**
|
||||
* Create new EcoBoss config.
|
||||
*
|
||||
* @param configName The name of the config.
|
||||
*/
|
||||
public BaseBossConfig(@NotNull final String configName) {
|
||||
super(configName, true, EcoBossesPlugin.getInstance(), EcoBossesPlugin.class, "bosses/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.ecobosses.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.StaticOptionalConfig;
|
||||
import com.willfp.ecobosses.EcoBossesPlugin;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CustomConfig extends StaticOptionalConfig {
|
||||
/**
|
||||
* Create new custom config.
|
||||
*
|
||||
* @param configName The name of the config.
|
||||
* @param config The config.
|
||||
*/
|
||||
public CustomConfig(@NotNull final String configName,
|
||||
@NotNull final YamlConfiguration config) {
|
||||
super(configName, EcoBossesPlugin.getInstance(), config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user