mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-25 15:11:20 +01:00
Improved tier loading system and error messages
This commit is contained in:
parent
05cd857870
commit
7e4565f896
@ -3,29 +3,26 @@ package net.Indyuce.mmoitems.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.droptable.DropTable;
|
||||
import net.Indyuce.mmoitems.comp.itemglow.TierColor;
|
||||
|
||||
public class ItemTier {
|
||||
private final String name, id;
|
||||
private final UnidentificationInfo unidentificationInfo;
|
||||
private final DropTable deconstruct;
|
||||
|
||||
/*
|
||||
* item glow. color is an object because we cant let this class import the
|
||||
* GlowAPI.Color enum since plugin is not a hard dependency.
|
||||
*/
|
||||
private TierColor color;
|
||||
private boolean hint;
|
||||
|
||||
private DropTable deconstruct;
|
||||
private final TierColor color;
|
||||
private final boolean hint;
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final boolean glow = Bukkit.getPluginManager().getPlugin("GlowAPI") != null;
|
||||
@ -33,17 +30,15 @@ public class ItemTier {
|
||||
public ItemTier(ConfigurationSection config) {
|
||||
id = config.getName().toUpperCase().replace("-", "_");
|
||||
name = ChatColor.translateAlternateColorCodes('&', config.getString("name"));
|
||||
if (config.contains("deconstruct-item"))
|
||||
deconstruct = new DropTable(config.getConfigurationSection("deconstruct-item"));
|
||||
deconstruct = config.contains("deconstruct-item") ? new DropTable(config.getConfigurationSection("deconstruct-item")) : null;
|
||||
unidentificationInfo = new UnidentificationInfo(config.getConfigurationSection("unidentification"));
|
||||
|
||||
if (config.contains("item-glow"))
|
||||
try {
|
||||
hint = config.getBoolean("item-glow.hint");
|
||||
color = new TierColor(config.getString("item-glow.color"), glow);
|
||||
} catch (NoClassDefFoundError | IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load tier color from '" + config.getString("item-glow.color") + "'");
|
||||
}
|
||||
try {
|
||||
hint = config.contains("item-glow") && config.getBoolean("item-glow.hint");
|
||||
color = config.contains("item-glow") ? new TierColor(config.getString("item-glow.color"), glow) : null;
|
||||
} catch (NoClassDefFoundError | IllegalAccessException | NoSuchFieldException | SecurityException exception) {
|
||||
throw new IllegalArgumentException("Could not load tier color: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -9,6 +9,7 @@ public class TierColor {
|
||||
|
||||
public TierColor(String format, boolean glow) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
Validate.notNull(format, "String must not be null");
|
||||
|
||||
bukkit = (Color) Color.class.getField(format.toUpperCase().replace("-", "_").replace(" ", "_")).get(Color.class);
|
||||
this.glow = glow ? new GlowColor(bukkit) : null;
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ public class TierManager {
|
||||
for (String key : config.getConfig().getKeys(false))
|
||||
try {
|
||||
register(new ItemTier(config.getConfig().getConfigurationSection(key)));
|
||||
} catch (Exception exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load item tier " + key);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load item tier '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ TRASH:
|
||||
range: 6
|
||||
name: 'Trash'
|
||||
prefix: '&8'
|
||||
deconstruct-item: {}
|
||||
|
||||
COMMON:
|
||||
name: '&7&lCOMMON'
|
||||
@ -20,7 +19,6 @@ COMMON:
|
||||
range: 6
|
||||
name: 'Common'
|
||||
prefix: '&7'
|
||||
deconstruct-item: {}
|
||||
UNCOMMON:
|
||||
|
||||
# Tier name displayed in the item lore.
|
||||
@ -51,7 +49,7 @@ UNCOMMON:
|
||||
color: 'GRAY'
|
||||
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -68,7 +66,7 @@ RARE:
|
||||
range: 6
|
||||
prefix: '&6'
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -85,7 +83,7 @@ VERY_RARE:
|
||||
prefix: '&e'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -102,7 +100,7 @@ LEGENDARY:
|
||||
prefix: '&b'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -119,7 +117,7 @@ MYTHICAL:
|
||||
prefix: '&5'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -136,7 +134,7 @@ EPIC:
|
||||
prefix: '&4'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -154,7 +152,7 @@ MAGICAL:
|
||||
prefix: '&2'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
@ -171,7 +169,7 @@ UNIQUE:
|
||||
prefix: '&c'
|
||||
range: 6
|
||||
deconstruct-item:
|
||||
sucess:
|
||||
success:
|
||||
coef: 1
|
||||
items:
|
||||
MATERIAL:
|
||||
|
Loading…
Reference in New Issue
Block a user