diff --git a/obsidiandestroyer/pom.xml b/obsidiandestroyer/pom.xml index 46ca978..2f10714 100644 --- a/obsidiandestroyer/pom.xml +++ b/obsidiandestroyer/pom.xml @@ -5,7 +5,7 @@ ObsidianDestroyer ObsidianDestroyer https://github.com/drtshock/ObsidianDestroyer - 4.4.16 + 4.4.17 UTF-8 diff --git a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/ObsidianDestroyer.java b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/ObsidianDestroyer.java index 1593a6c..366bd28 100644 --- a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/ObsidianDestroyer.java +++ b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/ObsidianDestroyer.java @@ -8,6 +8,7 @@ import com.drtshock.obsidiandestroyer.managers.HookManager; import com.drtshock.obsidiandestroyer.managers.MaterialManager; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.plugin.PluginManager; @@ -59,10 +60,26 @@ public static int getDurability(Location location) { if (!instance.isEnabled()) { return 0; } - return ChunkManager.getInstance().getMaterialDurability(location); } + /** + * Gets the durability of a material type + * + * @param material the material to check + * @param data optional byte data for legacy material support. + * @return the durability amount + */ + public static int getDurability(Material material, byte data) { + if (instance == null || MaterialManager.getInstance() == null) { + return 0; + } + if (!instance.isEnabled()) { + return 0; + } + return MaterialManager.getInstance().getDurability(material.name(), data); + } + /** * Raw damage to a block at a location. Can specify amount. * @@ -80,7 +97,6 @@ public static DamageResult damageBlock(Location location, int damageAmount) { if (damageAmount <= 0) { return DamageResult.NONE; } - return ChunkManager.getInstance().damageBlock(location, damageAmount); } @@ -98,7 +114,6 @@ public static DamageResult damageBlock(Location location, EntityType entityType) if (!instance.isEnabled()) { return DamageResult.ERROR; } - return ChunkManager.getInstance().damageBlock(location, entityType); } @@ -116,11 +131,9 @@ public static DamageResult damageBlock(Location location, Entity entity) { if (!instance.isEnabled()) { return DamageResult.ERROR; } - if (entity == null) { return DamageResult.ERROR; } - return ChunkManager.getInstance().damageBlock(location, entity); } diff --git a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/datatypes/DurabilityMaterial.java b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/datatypes/DurabilityMaterial.java index 21f6acd..e59ef61 100644 --- a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/datatypes/DurabilityMaterial.java +++ b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/datatypes/DurabilityMaterial.java @@ -88,6 +88,15 @@ public DurabilityMaterial(Material type, int typeData, ConfigurationSection sect this.tallyKittens(); } + public static boolean isEnabled(ConfigurationSection section) { + if (section.contains("Durability")) { + if (section.contains("Durability.Enabled") && section.contains("Durability.Amount")) { + return section.getBoolean("Durability.Enabled") && section.getInt("Durability.Amount") > 0; + } + } + return false; + } + private void tallyKittens() { if (blastRadius < 0) { blastRadius = 1; diff --git a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/managers/ConfigManager.java b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/managers/ConfigManager.java index 7be6d58..1a9f095 100644 --- a/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/managers/ConfigManager.java +++ b/obsidiandestroyer/src/main/java/com/drtshock/obsidiandestroyer/managers/ConfigManager.java @@ -205,23 +205,31 @@ public List getDisabledWorlds() { * @return map of materials keys and material durability data */ public Map getDurabilityMaterials() { - ConfigurationSection section = materials.getConfigurationSection("HandledMaterials"); - Map durabilityMaterials = new HashMap(); + final long time = System.currentTimeMillis(); + final ConfigurationSection section = materials.getConfigurationSection("HandledMaterials"); + int errorDuraCount = 0; + int invalidDuraCount = 0; + int disabledDuraCount = 0; + Map durabilityMaterials = new HashMap<>(); for (String durabilityMaterial : section.getKeys(false)) { try { - ConfigurationSection materialSection = section.getConfigurationSection(durabilityMaterial); + final ConfigurationSection materialSection = section.getConfigurationSection(durabilityMaterial); Material material = Material.matchMaterial(durabilityMaterial); if (material == null) { - if (Material.getMaterial(durabilityMaterial) == null) { - ObsidianDestroyer.LOG.log(Level.SEVERE, "Invalid Material Type: Unable to load ''{0}''", durabilityMaterial); + material = Material.matchMaterial(durabilityMaterial, true); + if (material == null) { + if (DurabilityMaterial.isEnabled(materialSection)) { + ObsidianDestroyer.LOG.log(Level.WARNING, "Invalid Material Type: Unable to load ''{0}''", durabilityMaterial); + } + invalidDuraCount++; continue; } else { - material = Material.getMaterial(durabilityMaterial); - ObsidianDestroyer.LOG.log(Level.SEVERE, "Semi-Valid Material Type: Loaded as ''{0}''", material.name()); + ObsidianDestroyer.LOG.log(Level.WARNING, "Semi-Valid Material Type: Loaded as ''{0}''", material.name()); } } if (!Util.isSolid(material) && !materialSection.contains("HandleNonSolid") && !materialSection.getBoolean("HandleNonSolid")) { ObsidianDestroyer.LOG.log(Level.WARNING, "Non-Solid Material Type: Did not load ''{0}''", durabilityMaterial); + invalidDuraCount++; continue; } final DurabilityMaterial durablock; @@ -237,11 +245,15 @@ public Map getDurabilityMaterials() { durabilityMaterials.put(durablock.toString(), durablock); } else if (getDebug()) { ObsidianDestroyer.debug("Disabled durability of '" + durablock.getDurability() + "' for '" + durablock.toString() + "'"); + disabledDuraCount++; } } catch (Exception e) { ObsidianDestroyer.LOG.log(Level.SEVERE, "Failed loading material ''{0}''", durabilityMaterial); + errorDuraCount++; } } + ObsidianDestroyer.LOG.log(Level.INFO, "Loaded and enabled ''{0}'' material durabilities from config in ''{1}'' ms.", new Object[]{durabilityMaterials.size(), (System.currentTimeMillis() - time)}); + ObsidianDestroyer.LOG.log(Level.INFO, "Material in Error: ''{0}'' Invalid: ''{1}'' Disabled: ''{2}''", new Object[]{errorDuraCount, invalidDuraCount, disabledDuraCount}); return durabilityMaterials; } diff --git a/obsidiandestroyer/src/main/resources/plugin.yml b/obsidiandestroyer/src/main/resources/plugin.yml index e030195..79bab43 100644 --- a/obsidiandestroyer/src/main/resources/plugin.yml +++ b/obsidiandestroyer/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ main: com.drtshock.obsidiandestroyer.ObsidianDestroyer version: ${project.version} authors: [drtshock, squidicuz] softdepend: [mcore, MassiveCore, Factions] -api-version: "1.13" +api-version: "1.14" commands: od: