Skip to content

Commit

Permalink
Fix durability being reset, fixed exception that occurs when being shot
Browse files Browse the repository at this point in the history
  • Loading branch information
CJCrafter committed Jul 29, 2022
1 parent 3146806 commit a3e220f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ nbactions.xml
.gradle/
build/
!gradle/wrapper/gradle-wrapper.jar
gradle.properties

# Maven
log/
Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

group = "me.cjcrafter"
version = "1.3.0"
version = "1.3.2"

plugins {
`java-library`
Expand Down Expand Up @@ -34,8 +34,8 @@ repositories {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/WeaponMechanics/MechanicsMain")
credentials {
username = "CJCrafter"
password = "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" // this is a public token created in CJCrafter's name which will never expire
username = findProperty("user").toString()
password = findProperty("pass").toString() // Check WeaponMechanics wiki on how to use this in your repo!
}
}

Expand All @@ -52,6 +52,7 @@ dependencies {
compileOnly("me.deecaad:weaponmechanics:1.8.3-BETA")
implementation("io.lumine:Mythic-Dist:5.0.1-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("me.cjcrafter:mechanicsautodownload:1.0.2")
}

tasks.named<ShadowJar>("shadowJar") {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/me/cjcrafter/armormechanics/ArmorMechanicsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public static String getArmorTitle(ItemStack armor) {
return CompatibilityAPI.getNBTCompatibility().getString(armor, "ArmorMechanics", "armor-title");
}

@Nonnull
public static ItemStack generateArmor(String armorTitle) {
if (armorTitle == null || !ArmorMechanics.INSTANCE.armors.containsKey(armorTitle))
throw new IllegalArgumentException("Unknown armor-title '" + armorTitle + "'");

return ArmorMechanics.INSTANCE.armors.get(armorTitle).clone();
}

/**
* Returns the expected {@link EquipmentSlot} that the given material
* would be worn on. However, using commands or plugins may allow players
Expand Down Expand Up @@ -281,8 +289,13 @@ public static void update(ItemStack armor) {
return;
}

// We need to save the old durability and set it to the new item, since
// setItemMeta will reset the item's durability.
short durability = armor.getDurability();

ItemStack template = ArmorMechanics.INSTANCE.armors.get(title);
armor.setType(template.getType());
armor.setItemMeta(template.getItemMeta());
armor.setDurability(durability);
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/cjcrafter/armormechanics/BonusEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public double getBulletResistance() {
}

public double getBulletResistance(String weaponTitle) {
if (perWeaponResistances.containsKey(weaponTitle))
if (perWeaponResistances.size() != 0 && perWeaponResistances.containsKey(weaponTitle))
return perWeaponResistances.get(weaponTitle);

return bulletResistance;
Expand Down

0 comments on commit a3e220f

Please # to comment.