Small cleanup

This commit is contained in:
Indyuce 2020-12-27 19:46:14 +01:00
parent c14ad43b4c
commit 6ff1dc9fa5
2 changed files with 17 additions and 21 deletions

View File

@ -16,9 +16,11 @@ public abstract class UntargetedWeapon extends Weapon {
this.weaponType = weaponType;
}
/*
* called first when the player clicks his item and allows to apply
* durability onto a weapon that is not targeted
/**
* Called when the player interacts with the item. This method is used to
* apply durability and cast the weapon attack
*
* @param slot Slot being interacted with
*/
public abstract void untargetedAttack(EquipmentSlot slot);
@ -26,7 +28,15 @@ public abstract class UntargetedWeapon extends Weapon {
return weaponType;
}
public enum WeaponType {
/**
* Used to determine if the item must be left or right clicked in order to
* cast a basic attack. Whips, staffs are left click weapons whereas muskets
* are right click weapons
*
* @author cympe
*
*/
public static enum WeaponType {
RIGHT_CLICK,
LEFT_CLICK;

View File

@ -21,7 +21,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.EquipmentSlot;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
@ -50,7 +49,8 @@ public class ItemUse implements Listener {
@EventHandler
public void a(PlayerInteractEvent event) {
if (!event.hasItem() || event.getHand() != EquipmentSlot.HAND)
if (!event.hasItem())
// || event.getHand() != EquipmentSlot.HAND
return;
NBTItem item = MMOLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
@ -99,7 +99,7 @@ public class ItemUse implements Listener {
UntargetedWeapon weapon = (UntargetedWeapon) useItem;
if ((event.getAction().name().contains("RIGHT_CLICK") && weapon.getWeaponType() == WeaponType.RIGHT_CLICK)
|| (event.getAction().name().contains("LEFT_CLICK") && weapon.getWeaponType() == WeaponType.LEFT_CLICK))
weapon.untargetedAttack(EquipmentSlot.HAND);
weapon.untargetedAttack(event.getHand());
}
}
@ -128,7 +128,6 @@ public class ItemUse implements Listener {
*/
PlayerData playerData = PlayerData.get(player);
NBTItem item = MMOLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInMainHand());
NBTItem offhandItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInOffHand());
ItemAttackResult result = new ItemAttackResult(event.getDamage(), DamageType.WEAPON, DamageType.PHYSICAL);
if (item.hasType() && Type.get(item.getType()) != Type.BLOCK) {
@ -150,19 +149,6 @@ public class ItemUse implements Listener {
return;
}
}
if (offhandItem.hasType() && Type.get(item.getType()) != Type.BLOCK) {
Weapon weapon = new Weapon(playerData, offhandItem);
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
event.setCancelled(true);
return;
}
if (!weapon.applyItemCosts()) {
event.setCancelled(true);
return;
}
}
/*
* cast on-hit abilities and add the extra damage to the damage event