mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
56bc8ba551
@ -50,7 +50,6 @@ public class ConfigManager implements Reloadable {
|
||||
private static final String[] languages = {"french", "chinese", "spanish", "russian", "polish"};
|
||||
|
||||
public ConfigManager() {
|
||||
|
||||
mkdir("layouts");
|
||||
mkdir("item");
|
||||
mkdir("language");
|
||||
@ -310,6 +309,7 @@ public class ConfigManager implements Reloadable {
|
||||
GEN_TEMPLATES("", "gen-templates"),
|
||||
UPGRADE_TEMPLATES("", "upgrade-templates"),
|
||||
EXAMPLE_MODIFIERS("modifiers", "example-modifiers"),
|
||||
CUSTOM_STATS("", "custom-stats"),
|
||||
|
||||
// Default language files -> /MMOItems/language
|
||||
LORE_FORMAT("language", "lore-format"),
|
||||
|
@ -4,11 +4,17 @@ import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.element.Element;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.stat.type.*;
|
||||
import net.Indyuce.mmoitems.util.ElementStatType;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
@ -36,8 +42,11 @@ public class StatManager {
|
||||
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.get(null) instanceof ItemStat)
|
||||
register((ItemStat<?, ?>) field.get(null));
|
||||
} catch (IllegalArgumentException | IllegalAccessException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't register stat called '%s'".formatted(field.getName()), exception.getMessage());
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, String.format("Couldn't register stat called '%s'", field.getName()), exception.getMessage());
|
||||
}
|
||||
|
||||
// Custom stats
|
||||
loadCustom();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,6 +61,25 @@ public class StatManager {
|
||||
|
||||
// Register elemental stats
|
||||
loadElements();
|
||||
|
||||
// Register custom stats
|
||||
loadCustom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load custom stats
|
||||
*/
|
||||
public void loadCustom() {
|
||||
ConfigManager.DefaultFile.CUSTOM_STATS.checkFile();
|
||||
ConfigFile config = new ConfigFile("custom-stats");
|
||||
ConfigurationSection section = config.getConfig().getConfigurationSection("custom-stats");
|
||||
Validate.notNull(section, "Custom stats section is null");
|
||||
section.getKeys(true)
|
||||
.stream()
|
||||
.filter(section::isConfigurationSection)
|
||||
.map(section::getConfigurationSection)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(this::registerCustomStat);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,4 +198,50 @@ public class StatManager {
|
||||
.filter(stat::isCompatible)
|
||||
.forEach(type -> type.getAvailableStats().add(stat));
|
||||
}
|
||||
|
||||
private void registerCustomStat(@NotNull ConfigurationSection section) {
|
||||
final String name = section.getString("name");
|
||||
final String type = section.getString("type");
|
||||
|
||||
Validate.notNull(section, "Cannot register a custom stat from a null section");
|
||||
Validate.notNull(name, "Cannot register a custom stat without a name");
|
||||
Validate.notNull(type, "Cannot register a custom stat without a type");
|
||||
|
||||
Class<? extends ItemStat<?, ?>> statClass;
|
||||
switch (type.toLowerCase()) {
|
||||
case "double":
|
||||
statClass = DoubleStat.class;
|
||||
break;
|
||||
case "boolean":
|
||||
statClass = BooleanStat.class;
|
||||
break;
|
||||
case "text":
|
||||
statClass = StringStat.class;
|
||||
break;
|
||||
case "text-list":
|
||||
statClass = StringListStat.class;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Cannot register a custom stat of type " + type);
|
||||
}
|
||||
|
||||
final String statId = String.format("custom_%s", name.replace(" ", "_")).toUpperCase();
|
||||
|
||||
// Lore
|
||||
String[] lore = new String[0];
|
||||
if (section.isList("lore"))
|
||||
lore = section.getStringList("lore").toArray(new String[]{});
|
||||
else if (section.isString("lore"))
|
||||
lore = new String[]{section.getString("lore")};
|
||||
|
||||
// Create a new stat instance
|
||||
try {
|
||||
ItemStat<?, ?> stat = statClass.getConstructor(String.class, Material.class, String.class, String[].class, String[].class, Material[].class)
|
||||
.newInstance(statId, Material.PAPER, name, lore, new String[]{"!miscellaneous", "!block", "all"}, new Material[0]);
|
||||
register(stat);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||
NoSuchMethodException e) {
|
||||
throw new RuntimeException("Unable to create a custom stat of type " + type, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
MMOItems-Dist/src/main/resources/default/custom-stats.yml
Normal file
22
MMOItems-Dist/src/main/resources/default/custom-stats.yml
Normal file
@ -0,0 +1,22 @@
|
||||
# Add as many custom stats as you want below
|
||||
# -
|
||||
# For each custom stat you add, you must also add a corresponding
|
||||
# entry in the lore-format.yml and stats.yml files
|
||||
custom-stats:
|
||||
|
||||
# The key doesn't really matter, although it must be unique
|
||||
# The lore for each stat can be defined in language/stats.yml
|
||||
1:
|
||||
# The name will be used in the edition GUI and also for the stat id
|
||||
# Format: "MyLuck" will be replaced with "CUSTOM_MYLUCK"
|
||||
name: "MyLuck"
|
||||
|
||||
# Allowed stats type:
|
||||
# - double (numbers)
|
||||
# - text (Will not work as placeholder. You have get this value from ntb tag of the item with your custom plugin)
|
||||
type: "double"
|
||||
|
||||
# The lore must be a list of strings
|
||||
lore:
|
||||
- "This is a test line #1"
|
||||
- "This is a test line #2"
|
@ -30,6 +30,7 @@ lore-format:
|
||||
- '#profession-woodcutting#'
|
||||
# - '{bar}&8&m--------&f&l &nStatistics&8 &m-------------'
|
||||
- '{bar}'
|
||||
- '#custom-myluck#'
|
||||
- '#can-identify#'
|
||||
- '#can-deconstruct#'
|
||||
- '#can-deskin#'
|
||||
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Luck: &f<plus>{value}'
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ 机会: &f<plus>{value}'
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Chance: &f<plus>{value}'
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Szansa: &f<plus>{value}'
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Шанс: &f<plus>{value}'
|
@ -146,3 +146,6 @@ elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Oportunidad: &f<plus>{value}'
|
Loading…
Reference in New Issue
Block a user