This commit is contained in:
Indyuce 2020-02-16 15:01:43 +01:00
parent 2a2a7f7007
commit cae5e090e2

View File

@ -32,7 +32,11 @@ public class LootableChestManager {
public LootableChestManager(FileConfiguration config) { public LootableChestManager(FileConfiguration config) {
for (String key : config.getKeys(false)) for (String key : config.getKeys(false))
try {
register(new LootableChest(config.getConfigurationSection(key))); register(new LootableChest(config.getConfigurationSection(key)));
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not register loot chest '" + key + "': " + exception.getMessage());
}
if (runnable != null) if (runnable != null)
runnable.cancel(); runnable.cancel();
@ -48,11 +52,9 @@ public class LootableChestManager {
} }
public void register(LootableChest chest) { public void register(LootableChest chest) {
if (chest.isValid()) {
map.add(chest); map.add(chest);
chest.whenClosed(false); chest.whenClosed(false);
} }
}
public LootableChest getLootableChest(Location loc) { public LootableChest getLootableChest(Location loc) {
for (LootableChest chest : map) for (LootableChest chest : map)
@ -66,15 +68,15 @@ public class LootableChestManager {
} }
public class LootableChest { public class LootableChest {
private Location loc; private final Location loc;
private DropTable table; private final DropTable table;
private int regenTime = -1; private final int regenTime;
private final Particle effectParticle;
private final ChestParticleEffect effect;
private long lastDisappear; private long lastDisappear;
private Particle effectParticle;
private ChestParticleEffect effect;
public LootableChest(ConfigurationSection config) { public LootableChest(ConfigurationSection config) {
try {
loc = readLocation(config.getName()); loc = readLocation(config.getName());
regenTime = config.getInt("regen-time"); regenTime = config.getInt("regen-time");
table = MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table")); table = MMOCore.plugin.dropTableManager.loadDropTable(config.get("drop-table"));
@ -87,14 +89,11 @@ public class LootableChestManager {
format = config.getString("effect.type"); format = config.getString("effect.type");
Validate.notNull(format, "Particle is missing effect type"); Validate.notNull(format, "Particle is missing effect type");
effect = ChestParticleEffect.valueOf(format.toUpperCase().replace("-", "_")); effect = ChestParticleEffect.valueOf(format.toUpperCase().replace("-", "_"));
}
} catch (IllegalArgumentException | IndexOutOfBoundsException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't read the loot chest config '" + config.getName() + "':" + exception.getMessage());
}
}
public boolean isValid() { } else {
return loc != null && table != null && regenTime > -1; effectParticle = null;
effect = null;
}
} }
public boolean hasEffect() { public boolean hasEffect() {
@ -126,7 +125,7 @@ public class LootableChestManager {
loc.getWorld().playSound(loc, Sound.ITEM_ARMOR_EQUIP_LEATHER, 1, 1); loc.getWorld().playSound(loc, Sound.ITEM_ARMOR_EQUIP_LEATHER, 1, 1);
loc.getWorld().spawnParticle(Particle.CRIT, loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5); loc.getWorld().spawnParticle(Particle.CRIT, loc.clone().add(.5, .5, .5), 16, 0, 0, 0, .5);
} }
if(loc.getBlock().getState() instanceof Chest) if (loc.getBlock().getState() instanceof Chest)
((Chest) loc.getBlock().getState()).getBlockInventory().clear(); ((Chest) loc.getBlock().getState()).getBlockInventory().clear();
loc.getBlock().setType(Material.AIR); loc.getBlock().setType(Material.AIR);
lastDisappear = System.currentTimeMillis(); lastDisappear = System.currentTimeMillis();