mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-31 14:49:35 +01:00
Fixed Impact reducing durability of non-armor equipped blocks
This commit is contained in:
parent
56056797bc
commit
2fac0170e7
@ -30,6 +30,7 @@ Version 1.4.00-dev
|
|||||||
+ Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
|
+ Added Shears, Buckets, Fishing Rods, Flint & Steel, Carrot Sticks, and Bows to the list of items that can be Salvaged
|
||||||
+ Added the "wait" music disc to the default fishing treasures
|
+ Added the "wait" music disc to the default fishing treasures
|
||||||
+ Added "Chinese (Taiwan)" localization files (zh_TW)
|
+ Added "Chinese (Taiwan)" localization files (zh_TW)
|
||||||
|
= Fixed Impact reducing durability of non-armor equipped blocks
|
||||||
= Fixed multiple commands not working properly on offline players
|
= Fixed multiple commands not working properly on offline players
|
||||||
= Fixed /mmoedit not giving feedback when modifying another players stats
|
= Fixed /mmoedit not giving feedback when modifying another players stats
|
||||||
= Fixed the guide usage string showing up every time /skillname was called
|
= Fixed the guide usage string showing up every time /skillname was called
|
||||||
|
@ -49,10 +49,7 @@ public class AxeManager extends SkillManager {
|
|||||||
public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
|
public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
|
||||||
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
|
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
|
||||||
|
|
||||||
if (Misc.hasArmor(target)) {
|
if (!eventHandler.applyImpact()) {
|
||||||
eventHandler.damageArmor();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
eventHandler.applyGreaterImpact();
|
eventHandler.applyGreaterImpact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.inventory.EntityEquipment;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.util.ItemChecks;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
|
|
||||||
@ -16,38 +17,46 @@ public class ImpactEventHandler {
|
|||||||
private Player player;
|
private Player player;
|
||||||
private EntityDamageByEntityEvent event;
|
private EntityDamageByEntityEvent event;
|
||||||
private short durabilityDamage = 1;
|
private short durabilityDamage = 1;
|
||||||
private EntityEquipment equipment;
|
private EntityEquipment entityEquipment;
|
||||||
private ItemStack[] armorContents;
|
|
||||||
protected LivingEntity defender;
|
protected LivingEntity defender;
|
||||||
|
boolean impactApplied;
|
||||||
|
|
||||||
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
|
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.player = manager.getMcMMOPlayer().getPlayer();
|
this.player = manager.getMcMMOPlayer().getPlayer();
|
||||||
this.event = event;
|
this.event = event;
|
||||||
this.defender = defender;
|
this.defender = defender;
|
||||||
this.equipment = defender.getEquipment();
|
this.entityEquipment = defender.getEquipment();
|
||||||
this.armorContents = equipment.getArmorContents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void damageArmor() {
|
protected boolean applyImpact() {
|
||||||
// Every 50 Skill Levels you gain 1 durability damage (default values)
|
// Every 50 Skill Levels you gain 1 durability damage (default values)
|
||||||
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
|
durabilityDamage += (short) (manager.getSkillLevel() / Axes.impactIncreaseLevel);
|
||||||
|
// getArmorContents.length can't be used because it's always equal to 4 (no armor = air block)
|
||||||
|
boolean hasArmor = false;
|
||||||
|
|
||||||
for (ItemStack armor : armorContents) {
|
for (ItemStack itemStack : entityEquipment.getArmorContents()) {
|
||||||
if (Misc.getRandom().nextInt(100) > 75) {
|
if (ItemChecks.isArmor(itemStack)) {
|
||||||
|
damageArmor(itemStack);
|
||||||
for (int i = 0; i <= durabilityDamage; i++) {
|
hasArmor = true;
|
||||||
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
|
|
||||||
handleDurabilityEnchantment(armor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
damageValidation(armor);
|
|
||||||
armor.setDurability((short) (armor.getDurability() + durabilityDamage));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
equipment.setArmorContents(armorContents);
|
return hasArmor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void damageArmor(ItemStack armor) {
|
||||||
|
if (Misc.getRandom().nextInt(100) >= 25) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float modifier = 1;
|
||||||
|
|
||||||
|
if (armor.containsEnchantment(Enchantment.DURABILITY)) {
|
||||||
|
modifier /= armor.getEnchantmentLevel(Enchantment.DURABILITY) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
armor.setDurability((short) (durabilityDamage * modifier + armor.getDurability()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void applyGreaterImpact() {
|
protected void applyGreaterImpact() {
|
||||||
@ -73,20 +82,4 @@ public class ImpactEventHandler {
|
|||||||
((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
|
((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDurabilityEnchantment(ItemStack armor) {
|
|
||||||
int enchantmentLevel = armor.getEnchantmentLevel(Enchantment.DURABILITY);
|
|
||||||
|
|
||||||
if (Misc.getRandom().nextInt(enchantmentLevel + 1) > 0) {
|
|
||||||
durabilityDamage--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void damageValidation(ItemStack armor) {
|
|
||||||
short maxDurability = (short) (armor.getType().getMaxDurability() * Axes.impactMaxDurabilityDamageModifier);
|
|
||||||
|
|
||||||
if (durabilityDamage > maxDurability) {
|
|
||||||
durabilityDamage = maxDurability;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user