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