Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config loading less scary when mismatches due to legacy materials. #86

Merged
merged 11 commits into from
Apr 5, 2020
2 changes: 1 addition & 1 deletion obsidiandestroyer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>ObsidianDestroyer</artifactId>
<name>ObsidianDestroyer</name>
<url>https://github.com/drtshock/ObsidianDestroyer</url>
<version>4.4.16</version>
<version>4.4.17</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -80,7 +97,6 @@ public static DamageResult damageBlock(Location location, int damageAmount) {
if (damageAmount <= 0) {
return DamageResult.NONE;
}

return ChunkManager.getInstance().damageBlock(location, damageAmount);
}

Expand All @@ -98,7 +114,6 @@ public static DamageResult damageBlock(Location location, EntityType entityType)
if (!instance.isEnabled()) {
return DamageResult.ERROR;
}

return ChunkManager.getInstance().damageBlock(location, entityType);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,31 @@ public List<String> getDisabledWorlds() {
* @return map of materials keys and material durability data
*/
public Map<String, DurabilityMaterial> getDurabilityMaterials() {
ConfigurationSection section = materials.getConfigurationSection("HandledMaterials");
Map<String, DurabilityMaterial> durabilityMaterials = new HashMap<String, DurabilityMaterial>();
final long time = System.currentTimeMillis();
final ConfigurationSection section = materials.getConfigurationSection("HandledMaterials");
int errorDuraCount = 0;
int invalidDuraCount = 0;
int disabledDuraCount = 0;
Map<String, DurabilityMaterial> 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;
Expand All @@ -237,11 +245,15 @@ public Map<String, DurabilityMaterial> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion obsidiandestroyer/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down