mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-03-11 13:11:50 +01:00
Fixed gauntlets not triggering elements
This commit is contained in:
parent
1502465685
commit
22d4a22d38
@ -36,7 +36,7 @@ public class Type implements CooldownObject, PreloadedObject {
|
||||
|
||||
// Blunt
|
||||
public static final Type HAMMER = new Type("HAMMER", true, ModifierSource.MELEE_WEAPON);
|
||||
public static final Type GAUNTLET = new Type("GAUNTLET", true, ModifierSource.MELEE_WEAPON);
|
||||
public static final Type GAUNTLET = new Type("IRON_SHOVEL", true, ModifierSource.MELEE_WEAPON);
|
||||
|
||||
// Range
|
||||
public static final Type WHIP = new Type("WHIP", true, ModifierSource.RANGED_WEAPON);
|
||||
@ -106,7 +106,7 @@ public class Type implements CooldownObject, PreloadedObject {
|
||||
*/
|
||||
private final List<ItemStat> available = new ArrayList<>();
|
||||
|
||||
private final PostLoadAction postLoadAction = new PostLoadAction(config -> {
|
||||
private final PostLoadAction postLoadAction = new PostLoadAction(true, config -> {
|
||||
onLeftClick = config.contains("on-left-click") ? MythicLib.plugin.getSkills().loadSkillHandler(config.get("on-left-click")) : null;
|
||||
onRightClick = config.contains("on-right-click") ? MythicLib.plugin.getSkills().loadSkillHandler(config.get("on-right-click")) : null;
|
||||
onAttack = config.contains("on-attack") ? MythicLib.plugin.getSkills().loadSkillHandler(config.get("on-attack")) : null;
|
||||
@ -349,10 +349,12 @@ public class Type implements CooldownObject, PreloadedObject {
|
||||
*/
|
||||
@Nullable
|
||||
public static Type get(@Nullable String id) {
|
||||
if (id == null) return null;
|
||||
return id == null ? null : MMOItems.plugin.getTypes().get(UtilityMethods.enumName(id));
|
||||
}
|
||||
|
||||
String format = UtilityMethods.enumName(id);
|
||||
return MMOItems.plugin.getTypes().has(format) ? MMOItems.plugin.getTypes().get(format) : null;
|
||||
@Nullable
|
||||
public static Type get(@NotNull NBTItem item) {
|
||||
return get(item.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,6 +118,7 @@ public class UseItem {
|
||||
} else Bukkit.dispatchCommand(player, parsed);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static UseItem getItem(Player player, NBTItem item, String type) {
|
||||
return getItem(player, item, Type.get(type));
|
||||
}
|
||||
|
@ -50,15 +50,16 @@ public class ItemUse implements Listener {
|
||||
// || event.getHand() != EquipmentSlot.HAND
|
||||
return;
|
||||
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
if (!item.hasType()) return;
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
final Type itemType = Type.get(item);
|
||||
if (itemType == null) return;
|
||||
|
||||
/*
|
||||
* Some consumables must be fully eaten through the vanilla eating
|
||||
* animation and are handled there {@link #handleVanillaEatenConsumables(PlayerItemConsumeEvent)}
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
final UseItem useItem = UseItem.getItem(player, item, item.getType());
|
||||
final UseItem useItem = UseItem.getItem(player, item, itemType);
|
||||
if (useItem instanceof Consumable && ((Consumable) useItem).hasVanillaEating()) return;
|
||||
|
||||
// (BUG FIX) Cancel the event to prevent things like shield blocking
|
||||
@ -95,19 +96,16 @@ public class ItemUse implements Listener {
|
||||
((Weapon) useItem).handleUntargetedAttack(rightClick, EquipmentSlot.fromBukkit(event.getHand()));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void meleeAttacks(PlayerAttackEvent event) {
|
||||
|
||||
// Make sure it's a melee attack
|
||||
if (!(event.getAttack() instanceof MeleeAttackMetadata)) return;
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final PlayerData playerData = PlayerData.get(player);
|
||||
final ItemStack weaponUsed = player.getInventory().getItem(((MeleeAttackMetadata) event.getAttack()).getHand().toBukkit());
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(weaponUsed);
|
||||
if (!item.hasType()) return;
|
||||
|
||||
final Type itemType = Type.get(item.getType());
|
||||
final Type itemType = Type.get(item);
|
||||
if (itemType == Type.BLOCK) return;
|
||||
|
||||
// Prevent melee attacks with non-melee weapons
|
||||
@ -117,6 +115,7 @@ public class ItemUse implements Listener {
|
||||
}
|
||||
|
||||
// Check item requirements
|
||||
final PlayerData playerData = PlayerData.get(player);
|
||||
final Weapon weapon = new Weapon(playerData, item);
|
||||
if (!weapon.checkItemRequirements()) {
|
||||
event.setCancelled(true);
|
||||
@ -154,13 +153,14 @@ public class ItemUse implements Listener {
|
||||
if (!(event.getRightClicked() instanceof LivingEntity)) return;
|
||||
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItem(event.getHand()));
|
||||
if (!item.hasType()) return;
|
||||
final Type itemType = Type.get(item);
|
||||
if (itemType == null) return;
|
||||
|
||||
final LivingEntity target = (LivingEntity) event.getRightClicked();
|
||||
if (!UtilityMethods.canTarget(player, target, InteractionType.OFFENSE_ACTION)) return;
|
||||
|
||||
// Check for usability
|
||||
final UseItem usableItem = UseItem.getItem(player, item, item.getType());
|
||||
final UseItem usableItem = UseItem.getItem(player, item, itemType);
|
||||
if (!usableItem.checkItemRequirements()) return;
|
||||
|
||||
// Apply type-specific entity interactions
|
||||
@ -176,13 +176,14 @@ public class ItemUse implements Listener {
|
||||
// TODO: Rewrite this with a custom 'ApplyMMOItemEvent'?
|
||||
@EventHandler
|
||||
public void gemStonesAndItemStacks(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
if (event.getAction() != InventoryAction.SWAP_WITH_CURSOR) return;
|
||||
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCursor());
|
||||
if (!item.hasType()) return;
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getCursor());
|
||||
final Type type = Type.get(item);
|
||||
if (type == null) return;
|
||||
|
||||
UseItem useItem = UseItem.getItem(player, item, item.getType());
|
||||
final UseItem useItem = UseItem.getItem(player, item, type);
|
||||
if (!useItem.checkItemRequirements()) return;
|
||||
|
||||
if (useItem instanceof ItemSkin) {
|
||||
@ -263,11 +264,12 @@ public class ItemUse implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void handleVanillaEatenConsumables(PlayerItemConsumeEvent event) {
|
||||
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
if (!item.hasType()) return;
|
||||
final NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
|
||||
final Type itemType = Type.get(item);
|
||||
if (itemType == null) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
UseItem useItem = UseItem.getItem(player, item, item.getType());
|
||||
UseItem useItem = UseItem.getItem(player, item, itemType);
|
||||
if (!useItem.checkItemRequirements()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -25,8 +25,6 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* TODO refactor with stat categories
|
||||
* <p>
|
||||
* basically useless as of right now
|
||||
*/
|
||||
@Deprecated
|
||||
private final Map<String, ItemStat<?, ?>> legacyAliases = new HashMap<>();
|
||||
|
Loading…
Reference in New Issue
Block a user