From dcfc77536172d374446183e8f28ebc81195fa13d Mon Sep 17 00:00:00 2001 From: DeeCaaD Date: Fri, 25 Feb 2022 19:38:38 +0200 Subject: [PATCH] Dual wield support --- .../core/placeholder/PlaceholderAPI.java | 19 +- .../core/placeholder/PlaceholderHandler.java | 7 +- .../commands/CrackShotConvertCommand.java | 2 +- .../CrackShotConvert/Converter.java | 2 +- .../CrackShotConvert/CrackShotConverter.java | 4 +- .../CrackShotPlusConverter.java | 2 +- .../listeners/WeaponListeners.java | 12 +- .../trigger/TriggerEntityListeners.java | 9 +- .../trigger/TriggerPlayerListeners.java | 42 ++-- .../defaultmechanics/CommandMechanic.java | 2 +- .../defaultmechanics/MessageMechanic.java | 16 +- .../weaponmechanics/weapon/WeaponHandler.java | 14 +- .../weapon/damage/DamageHandler.java | 2 + .../weapon/info/InfoHandler.java | 8 +- .../weapon/info/WeaponInfoDisplay.java | 209 ++++++++++++------ .../weapon/info/WeaponInfoDisplay.yml | 15 +- .../weapon/placeholders/PAmmoAvailable.java | 6 +- .../weapon/placeholders/PAmmoLeft.java | 3 +- .../weapon/placeholders/PAmmoType.java | 6 +- .../weapon/placeholders/PFirearmState.java | 3 +- .../weapon/placeholders/PReload.java | 11 +- .../placeholders/PSelectiveFireState.java | 3 +- .../weapon/placeholders/PShooter.java | 3 +- .../weapon/placeholders/PWeaponTitle.java | 3 +- .../weapon/reload/ReloadHandler.java | 8 +- .../weapon/reload/ammo/ItemAmmo.java | 14 +- .../weapon/scope/ScopeHandler.java | 7 +- .../weapon/shoot/AModifyWhen.java | 9 +- .../weapon/shoot/ShootHandler.java | 18 +- .../weapon/shoot/recoil/ModifyRecoilWhen.java | 11 +- .../weapon/shoot/recoil/ModifyRecoilWhen.yml | 3 +- .../weapon/shoot/spread/ChangingSpread.yml | 1 + .../weapon/shoot/spread/ModifySpreadWhen.java | 11 +- .../weapon/shoot/spread/ModifySpreadWhen.yml | 3 +- .../weapon/trigger/Trigger.java | 71 +++++- .../weapon/trigger/Trigger.yml | 6 +- .../weapon/trigger/TriggerType.java | 4 + .../weapons/assault_rifles/AK-47.yml | 1 - .../weapons/assault_rifles/FN_FAL.yml | 1 - .../weapons/assault_rifles/FR_5.56.yml | 1 - .../weapons/assault_rifles/M4A1.yml | 1 - .../weapons/light_machine_guns/MG34.yml | 1 - .../weapons/marksman_rifles/Kar98k.yml | 1 - .../weapons/pistols/357_Magnum.yml | 1 - .../WeaponMechanics/weapons/pistols/50_GS.yml | 14 +- .../weapons/rocket_launchers/RPG-7.yml | 1 - .../weapons/shotguns/Origin-12.yml | 1 - .../WeaponMechanics/weapons/shotguns/R9-0.yml | 1 - .../weapons/sniper_rifles/AX-50.yml | 1 - .../weapons/sub_machine_guns/AUG.yml | 1 - .../weapons/sub_machine_guns/Uzi.yml | 1 - 51 files changed, 356 insertions(+), 240 deletions(-) rename WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/{utils => lib}/CrackShotConvert/Converter.java (98%) rename WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/{utils => lib}/CrackShotConvert/CrackShotConverter.java (99%) rename WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/{utils => lib}/CrackShotConvert/CrackShotPlusConverter.java (99%) diff --git a/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderAPI.java b/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderAPI.java index 56df654ee..13ca167cc 100644 --- a/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderAPI.java +++ b/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderAPI.java @@ -3,6 +3,7 @@ import me.deecaad.core.utils.LogLevel; import me.deecaad.core.utils.StringUtil; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -49,10 +50,11 @@ public static void addPlaceholderHandler(PlaceholderHandler placeholderHandler) * @param player the player involved in event or null * @param itemStack the item stack involved in event or null * @param weaponTitle the weapon title involved in this request, can be null + * @param slot the weapon slot involved in this request, can be null * @return the string with applied placeholders */ - public static String applyPlaceholders(String to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { - return applyPlaceholders(to, player, itemStack, weaponTitle, null); + public static String applyPlaceholders(String to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { + return applyPlaceholders(to, player, itemStack, weaponTitle, slot, null); } /** @@ -63,10 +65,11 @@ public static String applyPlaceholders(String to, @Nullable Player player, @Null * @param player the player involved in event or null * @param itemStack the item stack involved in event or null * @param weaponTitle the weapon title involved in this request, can be null + * @param slot the weapon slot involved in this request, can be null * @param temp the temporary placeholders to be used * @return the string with applied placeholders */ - public static String applyPlaceholders(String to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable Map temp) { + public static String applyPlaceholders(String to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot, @Nullable Map temp) { if (to == null) { return null; } @@ -90,9 +93,9 @@ public static String applyPlaceholders(String to, @Nullable Player player, @Null } String request = null; try { - request = placeholderHandler.onRequest(player, itemStack, weaponTitle); + request = placeholderHandler.onRequest(player, itemStack, weaponTitle, slot); } catch (Exception e) { - debug.log(LogLevel.WARN, "Placeholder using keyword %" + placeholderHandler.getPlaceholderName() + "% caused this exception!", e); + debug.log(LogLevel.WARN, "Placeholder using keyword " + placeholderHandler.getPlaceholderName() + " caused this exception!", e); } if (request == null) { continue; @@ -110,9 +113,9 @@ public static String applyPlaceholders(String to, @Nullable Player player, @Null /** * Creates new list based on given collection. * - * @see PlaceholderAPI#applyPlaceholders(String, Player, ItemStack, String) + * @see PlaceholderAPI#applyPlaceholders(String, Player, ItemStack, String, EquipmentSlot) */ - public static List applyPlaceholders(Collection to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public static List applyPlaceholders(Collection to, @Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (to == null) return null; else if (to.isEmpty()) @@ -122,7 +125,7 @@ else if (to.isEmpty()) List tempList = new ArrayList<>(); while (iterator.hasNext()) { - tempList.add(applyPlaceholders(iterator.next(), player, itemStack, weaponTitle)); + tempList.add(applyPlaceholders(iterator.next(), player, itemStack, weaponTitle, slot)); } return tempList; } diff --git a/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderHandler.java b/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderHandler.java index beb3b4f2f..c24836141 100644 --- a/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderHandler.java +++ b/MechanicsCore/src/main/java/me/deecaad/core/placeholder/PlaceholderHandler.java @@ -1,6 +1,7 @@ package me.deecaad.core.placeholder; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -34,13 +35,15 @@ public String getPlaceholderName() { } /** - * Used to modify placeholder result when this specific placeholder is being requested. Remember to check nulls of player and itemstack! + * Used to modify placeholder result when this specific placeholder is being requested. + * Remember to check nulls! * * @param player the player involved in this request, can be null * @param itemStack the item stack involved in this request, can be null * @param weaponTitle the weapon title involved in this request, can be null + * @param slot the weapon slot involved in this request, can be null * @return the result for placeholder or null */ @Nullable - public abstract String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle); + public abstract String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot); } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java index 5d5556b9b..fcd3de73c 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java @@ -5,7 +5,7 @@ import me.deecaad.core.file.TaskChain; import me.deecaad.weaponmechanics.WeaponMechanics; import me.deecaad.weaponmechanics.WeaponMechanicsAPI; -import me.deecaad.weaponmechanics.utils.CrackShotConvert.Converter; +import me.deecaad.weaponmechanics.lib.CrackShotConvert.Converter; import org.bukkit.command.CommandSender; import java.io.File; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/Converter.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/Converter.java similarity index 98% rename from WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/Converter.java rename to WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/Converter.java index 02bb1b893..42001a2f6 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/Converter.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/Converter.java @@ -1,4 +1,4 @@ -package me.deecaad.weaponmechanics.utils.CrackShotConvert; +package me.deecaad.weaponmechanics.lib.CrackShotConvert; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotConverter.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotConverter.java similarity index 99% rename from WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotConverter.java rename to WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotConverter.java index b27d05882..536fcb87e 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotConverter.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotConverter.java @@ -1,4 +1,4 @@ -package me.deecaad.weaponmechanics.utils.CrackShotConvert; +package me.deecaad.weaponmechanics.lib.CrackShotConvert; import com.shampaggon.crackshot.MaterialManager; import com.shampaggon.crackshot.SoundManager; @@ -22,10 +22,8 @@ public void convertOneKey(YamlConfiguration configuration, String key, YamlConfi if (configuration.get(key + ".Reload.Reload_Amount") != null) { if (configuration.get(key + ".Firearm_Action.Type") != null) { outputConfiguration.set(key + ".Info.Weapon_Info_Display.Action_Bar.Message", "&6" + key + "%firearm-state% &7«&6%ammo-left%&7»&6%reload%"); - outputConfiguration.set(key + ".Info.Weapon_Info_Display.Action_Bar.Time", 40); } else { outputConfiguration.set(key + ".Info.Weapon_Info_Display.Action_Bar.Message", "&6" + key + " &7«&6%ammo-left%&7»&6%reload%"); - outputConfiguration.set(key + ".Info.Weapon_Info_Display.Action_Bar.Time", 40); } } for (Paths path : Paths.values()) { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotPlusConverter.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotPlusConverter.java similarity index 99% rename from WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotPlusConverter.java rename to WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotPlusConverter.java index a254f1177..bc5c016f1 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/utils/CrackShotConvert/CrackShotPlusConverter.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotPlusConverter.java @@ -1,4 +1,4 @@ -package me.deecaad.weaponmechanics.utils.CrackShotConvert; +package me.deecaad.weaponmechanics.lib.CrackShotConvert; import me.DeeCaaD.CrackShotPlus.CSPapi; import me.deecaad.core.utils.NumberUtil; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/WeaponListeners.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/WeaponListeners.java index 59db085bb..65c0a12a6 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/WeaponListeners.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/WeaponListeners.java @@ -47,17 +47,16 @@ public void equip(EntityEquipmentEvent e) { String weaponTitle = weaponHandler.getInfoHandler().getWeaponTitle(weaponStack, true); boolean alreadyUsedEquipMechanics = false; - if (e.getSlot() == EquipmentSlot.HAND) { - entityWrapper.getMainHandData().setCurrentWeaponTitle(weaponTitle); - } else { - entityWrapper.getOffHandData().setCurrentWeaponTitle(weaponTitle); - } + boolean mainhand = e.getSlot() == EquipmentSlot.HAND; + + HandData handData = mainhand ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData(); + handData.setCurrentWeaponTitle(weaponTitle); if (weaponTitle != null) { if (e.getEntityType() == EntityType.PLAYER) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, e.getSlot()); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, e.getSlot()); } weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, e.getSlot()); @@ -68,7 +67,6 @@ public void equip(EntityEquipmentEvent e) { alreadyUsedEquipMechanics = true; } - HandData handData = e.getSlot() == EquipmentSlot.HAND ? entityWrapper.getMainHandData() : entityWrapper.getOffHandData(); handData.setLastEquipTime(System.currentTimeMillis()); if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Weapon_Equip_Delay") && e.getEntityType() == EntityType.PLAYER) { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerEntityListeners.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerEntityListeners.java index 0e37d8c66..bf0cb81c7 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerEntityListeners.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerEntityListeners.java @@ -57,20 +57,13 @@ public void damage(EntityDamageByEntityEvent e) { ItemStack offStack = entityEquipment.getItemInOffHand(); String offWeapon = weaponHandler.getInfoHandler().getWeaponTitle(offStack, false); - if (mainWeapon == null && offWeapon == null) { - entityWrapper.getMainHandData().setCurrentWeaponTitle(null); - entityWrapper.getOffHandData().setCurrentWeaponTitle(null); - return; - } + if (mainWeapon == null && offWeapon == null) return; if (mainWeapon != null) { // Cancel melee with weapons by default e.setCancelled(true); } - entityWrapper.getMainHandData().setCurrentWeaponTitle(mainWeapon); - entityWrapper.getOffHandData().setCurrentWeaponTitle(offWeapon); - // When sweep hit we don't want to do actual melee casts if (cause == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK) return; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerPlayerListeners.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerPlayerListeners.java index 66d9cdbe6..556132164 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerPlayerListeners.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/listeners/trigger/TriggerPlayerListeners.java @@ -28,7 +28,7 @@ public class TriggerPlayerListeners implements Listener { - private WeaponHandler weaponHandler; + private final WeaponHandler weaponHandler; public TriggerPlayerListeners(WeaponHandler weaponHandler) { this.weaponHandler = weaponHandler; @@ -140,11 +140,7 @@ public void interact(PlayerInteractEvent e) { ItemStack offStack = playerEquipment.getItemInOffHand(); String offWeapon = weaponHandler.getInfoHandler().getWeaponTitle(offStack, true); - if (mainWeapon == null && offWeapon == null) { - playerWrapper.getMainHandData().setCurrentWeaponTitle(null); - playerWrapper.getOffHandData().setCurrentWeaponTitle(null); - return; - } + if (mainWeapon == null && offWeapon == null) return; if ((mainWeapon != null && getConfigurations().getBool(mainWeapon + ".Info.Cancel.Block_Interactions") || offWeapon != null && getConfigurations().getBool(offWeapon + ".Info.Cancel.Block_Interactions"))) { @@ -158,9 +154,6 @@ public void interact(PlayerInteractEvent e) { boolean dualWield = mainWeapon != null && offWeapon != null; - playerWrapper.getMainHandData().setCurrentWeaponTitle(mainWeapon); - playerWrapper.getOffHandData().setCurrentWeaponTitle(offWeapon); - if (rightClick) { if (weaponHandler.getInfoHandler().denyDualWielding(TriggerType.RIGHT_CLICK, player, mainWeapon, offWeapon)) return; @@ -240,11 +233,7 @@ public void dropItem(PlayerDropItemEvent e) { ItemStack offStack = playerEquipment.getItemInOffHand(); String offWeapon = weaponHandler.getInfoHandler().getWeaponTitle(offStack, false); - if (mainWeapon == null && offWeapon == null) { - playerWrapper.getMainHandData().setCurrentWeaponTitle(null); - playerWrapper.getOffHandData().setCurrentWeaponTitle(null); - return; - } + if (mainWeapon == null && offWeapon == null) return; // Cancel reload (and other tasks) since drop item will most of the time cause // itemstack reference change which will cause other bugs (e.g. infinite reload bug) @@ -261,9 +250,6 @@ public void dropItem(PlayerDropItemEvent e) { boolean dualWield = mainWeapon != null && offWeapon != null; - playerWrapper.getMainHandData().setCurrentWeaponTitle(mainWeapon); - playerWrapper.getOffHandData().setCurrentWeaponTitle(offWeapon); - if (mainWeapon != null) { playerWrapper.droppedWeapon(); @@ -276,7 +262,8 @@ public void dropItem(PlayerDropItemEvent e) { if (offWeapon != null) { playerWrapper.droppedWeapon(); - weaponHandler.tryUses(playerWrapper, offWeapon, offStack, EquipmentSlot.OFF_HAND, TriggerType.DROP_ITEM, dualWield, null); + Bukkit.getScheduler().runTask(WeaponMechanics.getPlugin(), () -> weaponHandler.tryUses(playerWrapper, offWeapon, + playerEquipment.getItemInOffHand(), EquipmentSlot.OFF_HAND, TriggerType.DROP_ITEM, dualWield, null)); } } @@ -299,11 +286,7 @@ public void swapHandItems(PlayerSwapHandItemsEvent e) { ItemStack toOff = e.getOffHandItem(); String toOffWeapon = weaponHandler.getInfoHandler().getWeaponTitle(toOff, false); - if (toMainWeapon == null && toOffWeapon == null) { - playerWrapper.getMainHandData().setCurrentWeaponTitle(null); - playerWrapper.getOffHandData().setCurrentWeaponTitle(null); - return; - } + if (toMainWeapon == null && toOffWeapon == null) return; if (toMainWeapon != null && getConfigurations().getBool(toMainWeapon + ".Info.Cancel.Swap_Hands") || toOffWeapon != null && getConfigurations().getBool(toOffWeapon + ".Info.Cancel.Swap_Hands")) { @@ -316,22 +299,25 @@ public void swapHandItems(PlayerSwapHandItemsEvent e) { boolean dualWield = toMainWeapon != null && toOffWeapon != null; - playerWrapper.getMainHandData().setCurrentWeaponTitle(toMainWeapon); - playerWrapper.getOffHandData().setCurrentWeaponTitle(toOffWeapon); - if (isValid(toMain)) { // SWAP_TO_MAIN_HAND if (weaponHandler.getInfoHandler().denyDualWielding(TriggerType.SWAP_TO_MAIN_HAND, player, toMainWeapon, toOffWeapon)) return; // Only check off hand going to main hand - if (toMainWeapon != null) weaponHandler.tryUses(playerWrapper, toMainWeapon, toMain, EquipmentSlot.OFF_HAND, TriggerType.SWAP_TO_MAIN_HAND, dualWield, null); + if (toMainWeapon != null) { + Bukkit.getScheduler().runTask(WeaponMechanics.getPlugin(), () -> weaponHandler.tryUses(playerWrapper, toMainWeapon, + playerEquipment.getItemInMainHand(), EquipmentSlot.OFF_HAND, TriggerType.SWAP_TO_MAIN_HAND, dualWield, null)); + } } if (isValid(toOff)) { // SWAP_TO_OFF_HAND if (weaponHandler.getInfoHandler().denyDualWielding(TriggerType.SWAP_TO_OFF_HAND, player, toMainWeapon, toOffWeapon)) return; // Only check main hand going to off hand - if (toOffWeapon != null) weaponHandler.tryUses(playerWrapper, toOffWeapon, toOff, EquipmentSlot.HAND, TriggerType.SWAP_TO_OFF_HAND, dualWield, null); + if (toOffWeapon != null) { + Bukkit.getScheduler().runTask(WeaponMechanics.getPlugin(), () -> weaponHandler.tryUses(playerWrapper, toOffWeapon, + playerEquipment.getItemInOffHand(), EquipmentSlot.HAND, TriggerType.SWAP_TO_OFF_HAND, dualWield, null)); + } } } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/CommandMechanic.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/CommandMechanic.java index 6b2a51e20..e07be1420 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/CommandMechanic.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/CommandMechanic.java @@ -49,7 +49,7 @@ public void use(CastData castData) { Player player = castData.getCaster() instanceof Player ? (Player) castData.getCaster() : null; for (CommandData commandData : commandList) { - String command = PlaceholderAPI.applyPlaceholders(commandData.getCommand(), player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); + String command = PlaceholderAPI.applyPlaceholders(commandData.getCommand(), player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); if (commandData.isConsole()) { Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); } else if (player != null) { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/MessageMechanic.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/MessageMechanic.java index 73313cf0d..e10622f1f 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/MessageMechanic.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/mechanics/defaultmechanics/MessageMechanic.java @@ -85,15 +85,15 @@ private void send(CastData castData, Player player) { } if (chatData != null) { - String chatMessage = PlaceholderAPI.applyPlaceholders(chatData.message, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); + String chatMessage = PlaceholderAPI.applyPlaceholders(chatData.message, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); TextComponent chatMessageComponent = new TextComponent(chatMessage); if (chatData.clickEventAction != null) { chatMessageComponent.setClickEvent(new ClickEvent(chatData.clickEventAction, - PlaceholderAPI.applyPlaceholders(chatData.clickEventValue, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders))); + PlaceholderAPI.applyPlaceholders(chatData.clickEventValue, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders))); } if (chatData.hoverEventValue != null) { Content content = new Text(TextComponent.fromLegacyText( - PlaceholderAPI.applyPlaceholders(chatData.hoverEventValue, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders))); + PlaceholderAPI.applyPlaceholders(chatData.hoverEventValue, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders))); chatMessageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, content)); } player.spigot().sendMessage(ChatMessageType.CHAT, chatMessageComponent); @@ -101,7 +101,7 @@ private void send(CastData castData, Player player) { if (actionBar != null) { - String actionBarMessage = PlaceholderAPI.applyPlaceholders(actionBar, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); + String actionBarMessage = PlaceholderAPI.applyPlaceholders(actionBar, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBarMessage)); if (actionBarTime > 40) { @@ -112,7 +112,7 @@ private void send(CastData castData, Player player) { @Override public void run() { - String actionBarMessage = PlaceholderAPI.applyPlaceholders(actionBar, player, castData.getWeaponStack(), castData.getWeaponTitle(), finalTempPlaceholders); + String actionBarMessage = PlaceholderAPI.applyPlaceholders(actionBar, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, finalTempPlaceholders); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(actionBarMessage)); ticker += 40; @@ -125,8 +125,8 @@ public void run() { } if (titleData != null) { - String titleMessage = PlaceholderAPI.applyPlaceholders(titleData.title, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); - String subtitleMessage = PlaceholderAPI.applyPlaceholders(titleData.subtitle, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); + String titleMessage = PlaceholderAPI.applyPlaceholders(titleData.title, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); + String subtitleMessage = PlaceholderAPI.applyPlaceholders(titleData.subtitle, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); if (CompatibilityAPI.getVersion() < 1.11) { player.sendTitle(titleMessage, subtitleMessage); } else { @@ -135,7 +135,7 @@ public void run() { } if (bossBarData != null) { - String bossBarMessage = PlaceholderAPI.applyPlaceholders(bossBarData.title, player, castData.getWeaponStack(), castData.getWeaponTitle(), tempPlaceholders); + String bossBarMessage = PlaceholderAPI.applyPlaceholders(bossBarData.title, player, castData.getWeaponStack(), castData.getWeaponTitle(), null, tempPlaceholders); BossBar bossBar = Bukkit.createBossBar(bossBarMessage, bossBarData.barColor, bossBarData.barStyle); bossBar.addPlayer(player); new BukkitRunnable() { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/WeaponHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/WeaponHandler.java index 761467a8f..58d887c23 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/WeaponHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/WeaponHandler.java @@ -87,19 +87,12 @@ public void useTrigger(LivingEntity livingEntity, TriggerType triggerType, boole ItemStack offStack = entityEquipment.getItemInOffHand(); String offWeapon = infoHandler.getWeaponTitle(offStack, autoConvert); - if (mainWeapon == null && offWeapon == null) { - entityWrapper.getMainHandData().setCurrentWeaponTitle(null); - entityWrapper.getOffHandData().setCurrentWeaponTitle(null); - return; - } + if (mainWeapon == null && offWeapon == null) return; if (infoHandler.denyDualWielding(triggerType, livingEntity.getType() == EntityType.PLAYER ? (Player) livingEntity : null, mainWeapon, offWeapon)) return; boolean dualWield = mainWeapon != null && offWeapon != null; - entityWrapper.getMainHandData().setCurrentWeaponTitle(mainWeapon); - entityWrapper.getOffHandData().setCurrentWeaponTitle(offWeapon); - if (mainWeapon != null) tryUses(entityWrapper, mainWeapon, mainStack, EquipmentSlot.HAND, triggerType, dualWield, null); if (offWeapon != null) tryUses(entityWrapper, offWeapon, offStack, EquipmentSlot.OFF_HAND, triggerType, dualWield, null); @@ -123,6 +116,7 @@ public void useTrigger(LivingEntity livingEntity, TriggerType triggerType, boole * @param dualWield whether or not this was dual wield */ public void tryUses(EntityWrapper entityWrapper, String weaponTitle, ItemStack weaponStack, EquipmentSlot slot, TriggerType triggerType, boolean dualWield, @Nullable LivingEntity victim) { + if (!weaponStack.hasItemMeta()) return; // Try shooting (and melee) if (shootHandler.tryUse(entityWrapper, weaponTitle, weaponStack, slot, triggerType, dualWield, victim)) { @@ -188,7 +182,7 @@ public void tryUses(EntityWrapper entityWrapper, String weaponTitle, ItemStack w if (selectiveFireMechanics != null) selectiveFireMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack)); WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); entityWrapper.getMainHandData().cancelTasks(); entityWrapper.getOffHandData().cancelTasks(); @@ -216,7 +210,7 @@ public void tryUses(EntityWrapper entityWrapper, String weaponTitle, ItemStack w if (ammoTypeSwitchMechanics != null) ammoTypeSwitchMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack)); WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); entityWrapper.getMainHandData().cancelTasks(); entityWrapper.getOffHandData().cancelTasks(); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/damage/DamageHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/damage/DamageHandler.java index 7734987a0..a5e27b98d 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/damage/DamageHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/damage/DamageHandler.java @@ -73,6 +73,8 @@ public boolean tryUse(LivingEntity victim, double damage, DamagePoint point, boo point = damageEntityEvent.getPoint(); if (DamageUtil.apply(shooter, victim, damageEntityEvent.getFinalDamage())) { + WeaponMechanics.debug.debug("Damage was cancelled"); + // Damage was cancelled return false; } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/InfoHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/InfoHandler.java index dff274b51..0bba142f9 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/InfoHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/InfoHandler.java @@ -167,8 +167,8 @@ public ItemStack generateWeapon(String weaponTitle, int amount) { weaponStack.setAmount(amount); ItemMeta weaponMeta = weaponStack.getItemMeta(); - weaponMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(weaponMeta.getDisplayName(), null, weaponStack, weaponTitle)); - weaponMeta.setLore(PlaceholderAPI.applyPlaceholders(weaponMeta.getLore(), null, weaponStack, weaponTitle)); + weaponMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(weaponMeta.getDisplayName(), null, weaponStack, weaponTitle, null)); + weaponMeta.setLore(PlaceholderAPI.applyPlaceholders(weaponMeta.getLore(), null, weaponStack, weaponTitle, null)); weaponStack.setItemMeta(weaponMeta); // Apply default skin @@ -196,8 +196,8 @@ public void giveOrDropWeapon(String weaponTitle, Player player, int amount) { weaponStack.setAmount(amount); ItemMeta weaponMeta = weaponStack.getItemMeta(); - weaponMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(weaponMeta.getDisplayName(), player, weaponStack, weaponTitle)); - weaponMeta.setLore(PlaceholderAPI.applyPlaceholders(weaponMeta.getLore(), player, weaponStack, weaponTitle)); + weaponMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(weaponMeta.getDisplayName(), player, weaponStack, weaponTitle, null)); + weaponMeta.setLore(PlaceholderAPI.applyPlaceholders(weaponMeta.getLore(), player, weaponStack, weaponTitle, null)); weaponStack.setItemMeta(weaponMeta); // Apply default skin diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.java index cbed3e711..aef636d8d 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MainHand; import org.bukkit.scheduler.BukkitRunnable; import javax.annotation.Nonnull; @@ -75,51 +76,83 @@ public WeaponInfoDisplay(String actionBar, String bossBar, BarColor barColor, Ba this.dualWieldOffBossBar = dualWieldOffBossBar; } - public void send(PlayerWrapper playerWrapper, ItemStack knownStack, EquipmentSlot slot) { - + public void send(PlayerWrapper playerWrapper, EquipmentSlot slot) { Player player = playerWrapper.getPlayer(); + MessageHelper messageHelper = playerWrapper.getMessageHelper(); + String mainWeapon = playerWrapper.getMainHandData().getCurrentWeaponTitle(); String offWeapon = playerWrapper.getOffHandData().getCurrentWeaponTitle(); - MessageHelper messageHelper = playerWrapper.getMessageHelper(); - boolean isDualWielding = mainWeapon != null && offWeapon != null; - boolean isKnownMain = slot == EquipmentSlot.HAND; - - ItemStack mainStack = null; - ItemStack offStack = null; - if (isKnownMain) { - mainStack = knownStack; - if (offWeapon != null) offStack = player.getEquipment().getItemInOffHand(); - } else { - if (mainWeapon != null) mainStack = player.getEquipment().getItemInMainHand(); - offStack = knownStack; + ItemStack mainStack = player.getEquipment().getItemInMainHand(); + ItemStack offStack = player.getEquipment().getItemInOffHand(); + + if (!mainStack.hasItemMeta()) { + mainStack = null; + mainWeapon = null; } + if (!offStack.hasItemMeta()) { + offStack = null; + offWeapon = null; + } + + if (mainStack == null && offWeapon == null) return; + + // Mostly this is RIGHT, but some players may have it LEFT + boolean hasInvertedMainHand = player.getMainHand() == MainHand.LEFT; + + boolean mainhand = slot == EquipmentSlot.HAND; + boolean isDualWielding = mainWeapon != null && offWeapon != null && mainStack != null && offStack != null; if (actionBar != null) { if (isDualWielding) { StringBuilder builder = new StringBuilder(); String dualWieldSplit = getBasicConfigurations().getString("Placeholder_Symbols.Dual_Wield_Split", " &7| "); + String offHand, mainHand; + // OFF HAND < dual wield split > MAIN HAND + // IF inverted: MAIN HAND < dual wield split > if (mainWeapon.equals(offWeapon)) { // Same weapon, use this info display for both - builder.append(PlaceholderAPI.applyPlaceholders(this.dualWieldOffActionBar != null ? this.dualWieldOffActionBar : this.actionBar, player, offStack, offWeapon)) - .append(dualWieldSplit) - .append(PlaceholderAPI.applyPlaceholders(this.dualWieldMainActionBar != null ? this.dualWieldMainActionBar : this.actionBar, player, mainStack, mainWeapon)); + if (hasInvertedMainHand) { + offHand = PlaceholderAPI.applyPlaceholders(this.dualWieldMainActionBar != null ? this.dualWieldMainActionBar : this.actionBar, player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders(this.dualWieldOffActionBar != null ? this.dualWieldOffActionBar : this.actionBar, player, mainStack, mainWeapon, EquipmentSlot.HAND); + } else { + offHand = PlaceholderAPI.applyPlaceholders(this.dualWieldOffActionBar != null ? this.dualWieldOffActionBar : this.actionBar, player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders(this.dualWieldMainActionBar != null ? this.dualWieldMainActionBar : this.actionBar, player, mainStack, mainWeapon, EquipmentSlot.HAND); + } } else { // Other weapon, use other info display - WeaponInfoDisplay other = getConfigurations().getObject((isKnownMain ? mainWeapon : offWeapon) + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - builder.append(PlaceholderAPI.applyPlaceholders(isKnownMain && other != null ? (other.dualWieldOffActionBar != null ? other.dualWieldOffActionBar : other.actionBar) - : (this.dualWieldOffActionBar != null ? this.dualWieldOffActionBar : this.actionBar), player, offStack, offWeapon)) - .append(dualWieldSplit) - .append(PlaceholderAPI.applyPlaceholders(isKnownMain || other == null ? (this.dualWieldMainActionBar != null ? this.dualWieldMainActionBar : this.actionBar) - : (other.dualWieldMainActionBar != null ? other.dualWieldMainActionBar : other.actionBar), player, mainStack, mainWeapon)); + WeaponInfoDisplay mainDisplay = mainhand ? this : getConfigurations().getObject(mainWeapon + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); + WeaponInfoDisplay offDisplay = mainhand ? getConfigurations().getObject(offWeapon + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class) : this; + if (mainDisplay == null) mainDisplay = this; + if (offDisplay == null) offDisplay = this; + + if (hasInvertedMainHand) { + offHand = PlaceholderAPI.applyPlaceholders((offDisplay.dualWieldMainActionBar == null || mainDisplay.dualWieldOffActionBar == null) ? offDisplay.actionBar : offDisplay.dualWieldMainActionBar, + player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders((mainDisplay.dualWieldOffActionBar == null || offDisplay.dualWieldMainActionBar == null) ? mainDisplay.actionBar : mainDisplay.dualWieldOffActionBar, + player, mainStack, mainWeapon, EquipmentSlot.HAND); + } else { + offHand = PlaceholderAPI.applyPlaceholders((offDisplay.dualWieldOffActionBar == null || mainDisplay.dualWieldMainActionBar == null) ? offDisplay.actionBar : offDisplay.dualWieldOffActionBar, + player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders((mainDisplay.dualWieldMainActionBar == null || offDisplay.dualWieldOffActionBar == null) ? mainDisplay.actionBar : mainDisplay.dualWieldMainActionBar, + player, mainStack, mainWeapon, EquipmentSlot.HAND); + } + } + + if (hasInvertedMainHand) { + builder.append(mainHand).append(dualWieldSplit).append(offHand); + } else { + builder.append(offHand).append(dualWieldSplit).append(mainHand); } player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(builder.toString())); } else { - if (isKnownMain) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(PlaceholderAPI.applyPlaceholders(actionBar, player, mainStack, mainWeapon))); - } else { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(PlaceholderAPI.applyPlaceholders(actionBar, player, offStack, offWeapon))); + if (mainhand) { + if (mainStack != null && mainStack.hasItemMeta()) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(PlaceholderAPI.applyPlaceholders(actionBar, player, mainStack, mainWeapon, slot))); + } + } else if (offStack != null && offStack.hasItemMeta()) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(PlaceholderAPI.applyPlaceholders(actionBar, player, offStack, offWeapon, slot))); } } } @@ -128,59 +161,92 @@ public void send(PlayerWrapper playerWrapper, ItemStack knownStack, EquipmentSlo if (bossBar != null) { StringBuilder builder = new StringBuilder(); + if (isDualWielding) { String dualWieldSplit = getBasicConfigurations().getString("Placeholder_Symbols.Dual_Wield_Split", " &7| "); + String offHand, mainHand; + // OFF HAND < dual wield split > MAIN HAND + // IF inverted: MAIN HAND < dual wield split > if (mainWeapon.equals(offWeapon)) { // Same weapon, use this info display for both - builder.append(PlaceholderAPI.applyPlaceholders(this.dualWieldOffBossBar != null ? this.dualWieldOffBossBar : this.bossBar, player, offStack, offWeapon)) - .append(dualWieldSplit) - .append(PlaceholderAPI.applyPlaceholders(this.dualWieldMainBossBar != null ? this.dualWieldMainBossBar : this.bossBar, player, mainStack, mainWeapon)); + if (hasInvertedMainHand) { + offHand = PlaceholderAPI.applyPlaceholders(this.dualWieldMainBossBar != null ? this.dualWieldMainBossBar : this.bossBar, player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders(this.dualWieldOffBossBar != null ? this.dualWieldOffBossBar : this.bossBar, player, mainStack, mainWeapon, EquipmentSlot.HAND); + } else { + offHand = PlaceholderAPI.applyPlaceholders(this.dualWieldOffBossBar != null ? this.dualWieldOffBossBar : this.bossBar, player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders(this.dualWieldMainBossBar != null ? this.dualWieldMainBossBar : this.bossBar, player, mainStack, mainWeapon, EquipmentSlot.HAND); + } } else { // Other weapon, use other info display - WeaponInfoDisplay other = getConfigurations().getObject((isKnownMain ? mainWeapon : offWeapon) + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - builder.append(PlaceholderAPI.applyPlaceholders(isKnownMain && other != null ? (other.dualWieldOffBossBar != null ? other.dualWieldOffBossBar : other.bossBar) - : (this.dualWieldOffBossBar != null ? this.dualWieldOffBossBar : this.bossBar), player, offStack, offWeapon)) - .append(dualWieldSplit) - .append(PlaceholderAPI.applyPlaceholders(isKnownMain || other == null ? (this.dualWieldMainBossBar != null ? this.dualWieldMainBossBar : this.bossBar) - : (other.dualWieldMainBossBar != null ? other.dualWieldMainBossBar : other.bossBar), player, mainStack, mainWeapon)); + WeaponInfoDisplay mainDisplay = mainhand ? this : getConfigurations().getObject(mainWeapon + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); + WeaponInfoDisplay offDisplay = mainhand ? getConfigurations().getObject(offWeapon + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class) : this; + if (mainDisplay == null) mainDisplay = this; + if (offDisplay == null) offDisplay = this; + + if (hasInvertedMainHand) { + offHand = PlaceholderAPI.applyPlaceholders((offDisplay.dualWieldMainBossBar == null || mainDisplay.dualWieldOffBossBar == null) ? offDisplay.bossBar : offDisplay.dualWieldMainBossBar, + player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders((mainDisplay.dualWieldOffBossBar == null || offDisplay.dualWieldMainBossBar == null) ? mainDisplay.bossBar : mainDisplay.dualWieldOffBossBar, + player, mainStack, mainWeapon, EquipmentSlot.HAND); + } else { + offHand = PlaceholderAPI.applyPlaceholders((offDisplay.dualWieldOffBossBar == null || mainDisplay.dualWieldMainBossBar == null) ? offDisplay.bossBar : offDisplay.dualWieldOffBossBar, + player, offStack, offWeapon, EquipmentSlot.OFF_HAND); + mainHand = PlaceholderAPI.applyPlaceholders((mainDisplay.dualWieldMainBossBar == null || offDisplay.dualWieldOffBossBar == null) ? mainDisplay.bossBar : mainDisplay.dualWieldMainBossBar, + player, mainStack, mainWeapon, EquipmentSlot.HAND); + } } - } else { - if (isKnownMain) { - builder.append(PlaceholderAPI.applyPlaceholders(bossBar, player, mainStack, mainWeapon)); + + if (hasInvertedMainHand) { + builder.append(mainHand).append(dualWieldSplit).append(offHand); } else { - builder.append(PlaceholderAPI.applyPlaceholders(bossBar, player, offStack, offWeapon)); + builder.append(offHand).append(dualWieldSplit).append(mainHand); } - } - - BossBar bossBar = messageHelper.getBossBar(); - if (bossBar == null) { - bossBar = Bukkit.createBossBar(builder.toString(), barColor, barStyle); - bossBar.addPlayer(player); - messageHelper.setBossBar(bossBar); } else { - Bukkit.getScheduler().cancelTask(messageHelper.getBossBarTask()); - bossBar.setTitle(builder.toString()); - bossBar.setColor(barColor); - bossBar.setStyle(barStyle); - } - if (showAmmoInBossBarProgress) { - magazineProgress = isKnownMain ? getMagazineProgress(mainStack, mainWeapon) : getMagazineProgress(offStack, offWeapon); - bossBar.setProgress(magazineProgress); + if (mainhand) { + if (mainStack != null && mainStack.hasItemMeta()) { + builder.append(PlaceholderAPI.applyPlaceholders(bossBar, player, mainStack, mainWeapon, slot)); + } + } else if (offStack != null && offStack.hasItemMeta()) { + builder.append(PlaceholderAPI.applyPlaceholders(bossBar, player, offStack, offWeapon, slot)); + } } - messageHelper.setBossBarTask(new BukkitRunnable() { - @Override - public void run() { - messageHelper.getBossBar().removeAll(); - messageHelper.setBossBar(null); - messageHelper.setBossBarTask(0); + + if (builder.length() != 0) { + BossBar bossBar = messageHelper.getBossBar(); + if (bossBar == null) { + bossBar = Bukkit.createBossBar(builder.toString(), barColor, barStyle); + bossBar.addPlayer(player); + messageHelper.setBossBar(bossBar); + } else { + Bukkit.getScheduler().cancelTask(messageHelper.getBossBarTask()); + bossBar.setTitle(builder.toString()); + bossBar.setColor(barColor); + bossBar.setStyle(barStyle); + } + if (showAmmoInBossBarProgress) { + magazineProgress = mainhand ? getMagazineProgress(mainStack, mainWeapon) : getMagazineProgress(offStack, offWeapon); + bossBar.setProgress(magazineProgress); } - }.runTaskLater(WeaponMechanics.getPlugin(), 40).getTaskId()); + messageHelper.setBossBarTask(new BukkitRunnable() { + @Override + public void run() { + messageHelper.getBossBar().removeAll(); + messageHelper.setBossBar(null); + messageHelper.setBossBarTask(0); + } + }.runTaskLater(WeaponMechanics.getPlugin(), 40).getTaskId()); + } } if (showAmmoInExpLevel || showAmmoInExpProgress) { + ItemStack useStack = mainhand ? mainStack : offStack; + String useWeapon = mainhand ? mainWeapon : offWeapon; + + if (useStack == null || !useStack.hasItemMeta() || useWeapon == null) return; + if (magazineProgress == -1) { - magazineProgress = isKnownMain ? getMagazineProgress(mainStack, mainWeapon) : getMagazineProgress(offStack, offWeapon); + magazineProgress = getMagazineProgress(useStack, useWeapon); } int lastExpTask = messageHelper.getExpTask(); @@ -189,9 +255,9 @@ public void run() { if (CompatibilityAPI.getVersion() < 1.15) { CompatibilityAPI.getCompatibility().sendPackets(player, ReflectionUtil.newInstance(packetPlayOutExperienceConstructor, - showAmmoInExpProgress ? (float) (magazineProgress != -1 ? magazineProgress : isKnownMain ? getMagazineProgress(mainStack, mainWeapon) : getMagazineProgress(offStack, offWeapon)) : player.getExp(), + showAmmoInExpProgress ? (float) (magazineProgress != -1 ? magazineProgress : getMagazineProgress(useStack, useWeapon)) : player.getExp(), player.getTotalExperience(), - showAmmoInExpLevel ? isKnownMain ? getAmmoLeft(mainStack, mainWeapon) : getAmmoLeft(offStack, offWeapon) : player.getLevel())); + showAmmoInExpLevel ? getAmmoLeft(useStack, useWeapon) : player.getLevel())); messageHelper.setExpTask(new BukkitRunnable() { public void run() { CompatibilityAPI.getCompatibility().sendPackets(player, @@ -203,8 +269,8 @@ public void run() { } }.runTaskLater(WeaponMechanics.getPlugin(), 40).getTaskId()); } else { - player.sendExperienceChange(showAmmoInExpProgress ? (float) (magazineProgress != -1 ? magazineProgress : isKnownMain ? getMagazineProgress(mainStack, mainWeapon) : getMagazineProgress(offStack, offWeapon)) : player.getExp(), - showAmmoInExpLevel ? isKnownMain ? getAmmoLeft(mainStack, mainWeapon) : getAmmoLeft(offStack, offWeapon) : player.getLevel()); + player.sendExperienceChange(showAmmoInExpProgress ? (float) (magazineProgress != -1 ? magazineProgress : getMagazineProgress(useStack, useWeapon)) : player.getExp(), + showAmmoInExpLevel ? getAmmoLeft(useStack, useWeapon) : player.getLevel()); messageHelper.setExpTask(new BukkitRunnable() { public void run() { player.sendExperienceChange(player.getExp(), player.getLevel()); @@ -249,10 +315,11 @@ public WeaponInfoDisplay serialize(SerializeData data) throws SerializerExceptio boolean expProgress = data.of("Show_Ammo_In.Exp_Progress").getBool(false); boolean bossBarProgress = data.of("Show_Ammo_In.Boss_Bar_Progress").getBool(false); - String dualWieldMainActionBar = data.of("Dual_Wield.Main_Hand.Action_Bar_Message").assertType(String.class).get(null); - String dualWieldMainBossBar = data.of("Dual_Wield.Main_Hand.Boss_Bar_Title").assertType(String.class).get(null); - String dualWieldOffActionBar = data.of("Dual_Wield.Off_Hand.Action_Bar_Message").assertType(String.class).get(null); - String dualWieldOffBossBar = data.of("Dual_Wield.Off_Hand.Boss_Bar_Title").assertType(String.class).get(null); + String dualWieldMainActionBar = data.of("Action_Bar.Dual_Wield.Main_Hand").assertType(String.class).get(null); + String dualWieldMainBossBar = data.of("Boss_Bar.Dual_Wield.Main_Hand").assertType(String.class).get(null); + + String dualWieldOffActionBar = data.of("Action_Bar.Dual_Wield.Off_Hand").assertType(String.class).get(null); + String dualWieldOffBossBar = data.of("Boss_Bar.Dual_Wield.Off_Hand").assertType(String.class).get(null); if (actionBarMessage == null && bossBarMessage == null && !expLevel && !expProgress) { throw data.exception(null, "Found an empty Weapon_Info_Display... Users won't be able to see any changes in their ammo!"); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.yml b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.yml index e475144c3..7d04683d3 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.yml +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/info/WeaponInfoDisplay.yml @@ -2,18 +2,17 @@ Weapon_Info_Display: Action_Bar: Message: + Dual_Wield: + Main_Hand: + Off_Hand: Boss_Bar: Title: Bar_Color: Bar_Style: + Dual_Wield: + Main_Hand: + Off_Hand: Show_Ammo_In: Boss_Bar_Progress: Exp_Level: - Exp_Progress: - Dual_Wield: - Main_Hand: - Action_Bar_Message: - Boss_Bar_Title: - Off_Hand: - Action_Bar_Message: - Boss_Bar_Title: \ No newline at end of file + Exp_Progress: \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoAvailable.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoAvailable.java index 29ddabf00..3d159da31 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoAvailable.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoAvailable.java @@ -3,8 +3,10 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import me.deecaad.weaponmechanics.weapon.reload.ammo.AmmoTypes; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nullable; import static me.deecaad.weaponmechanics.WeaponMechanics.getConfigurations; import static me.deecaad.weaponmechanics.WeaponMechanics.getPlayerWrapper; @@ -17,7 +19,7 @@ public PAmmoAvailable() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (itemStack == null || weaponTitle == null) return null; AmmoTypes ammoTypes = getConfigurations().getObject(weaponTitle + ".Reload.Ammo.Ammo_Types", AmmoTypes.class); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoLeft.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoLeft.java index c7d301060..81af645fb 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoLeft.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoLeft.java @@ -3,6 +3,7 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import me.deecaad.weaponmechanics.utils.CustomTag; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -15,7 +16,7 @@ public PAmmoLeft() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (itemStack == null) return null; return "" + CustomTag.AMMO_LEFT.getInteger(itemStack); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoType.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoType.java index 2fb5eac97..c6a94a459 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoType.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PAmmoType.java @@ -3,8 +3,10 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import me.deecaad.weaponmechanics.weapon.reload.ammo.AmmoTypes; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nullable; import static me.deecaad.weaponmechanics.WeaponMechanics.getConfigurations; @@ -16,7 +18,7 @@ public PAmmoType() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (itemStack == null || weaponTitle == null) return null; AmmoTypes ammoTypes = getConfigurations().getObject(weaponTitle + ".Reload.Ammo.Ammo_Types", AmmoTypes.class); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PFirearmState.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PFirearmState.java index 0b762e74b..2417c7fd1 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PFirearmState.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PFirearmState.java @@ -4,6 +4,7 @@ import me.deecaad.weaponmechanics.weapon.firearm.FirearmAction; import me.deecaad.weaponmechanics.weapon.firearm.FirearmState; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -19,7 +20,7 @@ public PFirearmState() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (itemStack == null || weaponTitle == null) return null; FirearmAction firearmAction = getConfigurations().getObject(weaponTitle + ".Firearm_Action", FirearmAction.class); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PReload.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PReload.java index 919c5cc8c..67c4e3aec 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PReload.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PReload.java @@ -4,6 +4,7 @@ import me.deecaad.weaponmechanics.WeaponMechanics; import me.deecaad.weaponmechanics.wrappers.PlayerWrapper; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -16,14 +17,14 @@ public PReload() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { - if (player == null) return null; + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { + if (player == null || slot == null) return null; PlayerWrapper playerWrapper = WeaponMechanics.getPlayerWrapper(player); - if (!playerWrapper.getMainHandData().isReloading() && !playerWrapper.getOffHandData().isReloading()) { - return ""; + if (slot == EquipmentSlot.HAND ? playerWrapper.getMainHandData().isReloading() : playerWrapper.getOffHandData().isReloading()) { + return WeaponMechanics.getBasicConfigurations().getString("Placeholder_Symbols.Reload"); } - return WeaponMechanics.getBasicConfigurations().getString("Placeholder_Symbols.Reload"); + return ""; } } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PSelectiveFireState.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PSelectiveFireState.java index 097d5926a..5424fd3b2 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PSelectiveFireState.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PSelectiveFireState.java @@ -3,6 +3,7 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import me.deecaad.weaponmechanics.utils.CustomTag; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -17,7 +18,7 @@ public PSelectiveFireState() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { if (itemStack == null) return null; int selectiveFireState = CustomTag.SELECTIVE_FIRE.getInteger(itemStack); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PShooter.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PShooter.java index e27170d76..5ec3b3705 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PShooter.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PShooter.java @@ -2,6 +2,7 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -14,7 +15,7 @@ public PShooter() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { return player != null ? player.getName() : null; } } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PWeaponTitle.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PWeaponTitle.java index a12f7eb16..bbcda8396 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PWeaponTitle.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/placeholders/PWeaponTitle.java @@ -2,6 +2,7 @@ import me.deecaad.core.placeholder.PlaceholderHandler; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; @@ -14,7 +15,7 @@ public PWeaponTitle() { @Nullable @Override - public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle) { + public String onRequest(@Nullable Player player, @Nullable ItemStack itemStack, @Nullable String weaponTitle, @Nullable EquipmentSlot slot) { return weaponTitle; } } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ReloadHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ReloadHandler.java index 828cc1a5a..7069c032f 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ReloadHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ReloadHandler.java @@ -339,7 +339,7 @@ public void setup() { if (playerWrapper != null) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send(playerWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send(playerWrapper, slot); } weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); @@ -406,7 +406,7 @@ public void finishReload(EntityWrapper entityWrapper, String weaponTitle, ItemSt if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); } weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); @@ -507,7 +507,7 @@ public void setup() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); } weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); @@ -547,7 +547,7 @@ public void setup() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); } weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ammo/ItemAmmo.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ammo/ItemAmmo.java index 07fdef58d..cce196675 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ammo/ItemAmmo.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/reload/ammo/ItemAmmo.java @@ -17,12 +17,12 @@ public class ItemAmmo implements IAmmoType { // Defined in ammo types list - private String ammoName; + private final String ammoName; - private String symbol; - private ItemStack bulletItem; - private ItemStack magazineItem; - private AmmoConverter ammoConverter; + private final String symbol; + private final ItemStack bulletItem; + private final ItemStack magazineItem; + private final AmmoConverter ammoConverter; public ItemAmmo(String ammoName, String symbol, ItemStack bulletItem, ItemStack magazineItem, AmmoConverter ammoConverter) { this.ammoName = ammoName; @@ -316,8 +316,8 @@ private void updatePlaceholders(ItemStack itemStack, Player player) { ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) return; - itemMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(itemMeta.getDisplayName(), player, itemStack, null)); - itemMeta.setLore(PlaceholderAPI.applyPlaceholders(itemMeta.getLore(), player, itemStack, null)); + itemMeta.setDisplayName(PlaceholderAPI.applyPlaceholders(itemMeta.getDisplayName(), player, itemStack, null, null)); + itemMeta.setLore(PlaceholderAPI.applyPlaceholders(itemMeta.getLore(), player, itemStack, null, null)); itemStack.setItemMeta(itemMeta); } } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/scope/ScopeHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/scope/ScopeHandler.java index bf25c26e3..038f27d81 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/scope/ScopeHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/scope/ScopeHandler.java @@ -148,7 +148,7 @@ private boolean zoomInWithoutTiming(ItemStack weaponStack, String weaponTitle, E if (zoomStackingMechanics != null) zoomStackingMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack)); WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); return true; } else { @@ -176,13 +176,12 @@ private boolean zoomInWithoutTiming(ItemStack weaponStack, String weaponTitle, E if (zoomMechanics != null) zoomMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack)); WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); if (config.getBool(weaponTitle + ".Scope.Night_Vision")) useNightVision(entityWrapper, zoomData); - return true; } @@ -218,7 +217,7 @@ private boolean zoomOutWithoutTiming(ItemStack weaponStack, String weaponTitle, if (zoomOffMechanics != null) zoomOffMechanics.use(new CastData(entityWrapper, weaponTitle, weaponStack)); WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); weaponHandler.getSkinHandler().tryUse(entityWrapper, weaponTitle, weaponStack, slot); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/AModifyWhen.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/AModifyWhen.java index 6763db97d..325275103 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/AModifyWhen.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/AModifyWhen.java @@ -13,10 +13,13 @@ public abstract class AModifyWhen implements Serializer { private NumberModifier swimming; private NumberModifier inMidair; private NumberModifier gliding; + private NumberModifier dualWielding; public AModifyWhen() { } - public AModifyWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, NumberModifier standing, NumberModifier walking, NumberModifier swimming, NumberModifier inMidair, NumberModifier gliding) { + public AModifyWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, + NumberModifier standing, NumberModifier walking, NumberModifier swimming, + NumberModifier inMidair, NumberModifier gliding, NumberModifier dualWielding) { this.always = always; this.zooming = zooming; this.sneaking = sneaking; @@ -25,6 +28,7 @@ public AModifyWhen(NumberModifier always, NumberModifier zooming, NumberModifier this.swimming = swimming; this.inMidair = inMidair; this.gliding = gliding; + this.dualWielding = dualWielding; } /** @@ -59,6 +63,9 @@ public double applyChanges(EntityWrapper entityWrapper, double tempNumber) { if (gliding != null && entityWrapper.isGliding()) { tempNumber = gliding.applyTo(tempNumber); } + if (dualWielding != null && entityWrapper.isDualWielding()) { + tempNumber = dualWielding.applyTo(tempNumber); + } return Math.max(tempNumber, 0.0); } diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/ShootHandler.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/ShootHandler.java index 22f474d38..f149121da 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/ShootHandler.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/ShootHandler.java @@ -39,6 +39,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MainHand; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -184,7 +185,7 @@ public boolean shootWithoutTrigger(EntityWrapper entityWrapper, String weaponTit if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, slot); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, slot); } if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Firearm_Actions_Time") && entityWrapper.getEntity().getType() == EntityType.PLAYER) { @@ -481,7 +482,7 @@ public void run() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, taskReference, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); } handData.stopFirearmActionTasks(); @@ -500,7 +501,7 @@ public void run() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); } if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Firearm_Actions_Time") && entityWrapper.getEntity().getType() == EntityType.PLAYER) { @@ -521,7 +522,7 @@ public void run() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); } if (getConfigurations().getBool(weaponTitle + ".Info.Show_Cooldown.Firearm_Actions_Time") && entityWrapper.getEntity().getType() == EntityType.PLAYER) { @@ -546,7 +547,7 @@ public void run() { if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, taskReference, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainhand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); } handData.addFirearmActionTask(closeRunnable.runTaskLater(WeaponMechanics.getPlugin(), firearmAction.getCloseTime()).getTaskId()); @@ -604,7 +605,7 @@ public void shoot(EntityWrapper entityWrapper, String weaponTitle, ItemStack wea if (entityWrapper instanceof PlayerWrapper) { WeaponInfoDisplay weaponInfoDisplay = getConfigurations().getObject(weaponTitle + ".Info.Weapon_Info_Display", WeaponInfoDisplay.class); - if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, weaponStack, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); + if (weaponInfoDisplay != null) weaponInfoDisplay.send((PlayerWrapper) entityWrapper, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); } Projectile projectile = config.getObject(weaponTitle + ".Projectile", Projectile.class); @@ -693,7 +694,12 @@ private Location getShootLocation(LivingEntity livingEntity, boolean dualWield, if (!dualWield) return livingEntity.getEyeLocation(); double dividedWidth = WeaponCompatibilityAPI.getWeaponCompatibility().getWidth(livingEntity) / 2.0; + double distance = mainhand ? 2.0 : 0.0; + if (livingEntity.getType() == EntityType.PLAYER && ((Player) livingEntity).getMainHand() == MainHand.LEFT) { + // This rarely happens, but some players use main hand LEFT + distance = mainhand ? 0.0 : 2.0; + } Location eyeLocation = livingEntity.getEyeLocation(); double yawToRad = Math.toRadians(eyeLocation.getYaw() + 90 * distance); diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.java index 25dc2e17b..90c30ded6 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.java @@ -17,8 +17,10 @@ public class ModifyRecoilWhen extends AModifyWhen { public ModifyRecoilWhen() { } - public ModifyRecoilWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, NumberModifier standing, NumberModifier walking, NumberModifier swimming, NumberModifier inMidair, NumberModifier gliding) { - super(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding); + public ModifyRecoilWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, + NumberModifier standing, NumberModifier walking, NumberModifier swimming, + NumberModifier inMidair, NumberModifier gliding, NumberModifier dualWielding) { + super(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding, dualWielding); } @Override @@ -38,14 +40,15 @@ public ModifyRecoilWhen serialize(SerializeData data) throws SerializerException NumberModifier swimming = getModifierHandler(data.of("Swimming")); NumberModifier inMidair = getModifierHandler(data.of("In_Midair")); NumberModifier gliding = getModifierHandler(data.of("Gliding")); + NumberModifier dualWielding = getModifierHandler(data.of("Dual_Wielding")); if (always == null && zooming == null && sneaking == null && standing == null && walking == null - && swimming == null && inMidair == null && gliding == null) { + && swimming == null && inMidair == null && gliding == null && dualWielding == null) { throw data.exception(null, "Tried to use Modify_Recoil_When without any arguments"); } - return new ModifyRecoilWhen(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding); + return new ModifyRecoilWhen(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding, dualWielding); } private NumberModifier getModifierHandler(SerializeData.ConfigAccessor data) throws SerializerException { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.yml b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.yml index f3b859652..0eef4326a 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.yml +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/recoil/ModifyRecoilWhen.yml @@ -6,4 +6,5 @@ Modify_Recoil_When: Walking: or % Swimming: or % In_Midair: or % - Gliding: or % \ No newline at end of file + Gliding: or % + Dual_Wielding: or % \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ChangingSpread.yml b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ChangingSpread.yml index f63f36c67..74dbc0524 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ChangingSpread.yml +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ChangingSpread.yml @@ -10,6 +10,7 @@ Changing_Spread: Swimming: or % In_Midair: or % Gliding: or % + Dual_Wielding: or % Bounds: Reset_After_Reaching_Bound: Minimum_Spread: diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.java index e039f41d9..a0cd27c99 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.java @@ -17,8 +17,10 @@ public class ModifySpreadWhen extends AModifyWhen { */ public ModifySpreadWhen() { } - public ModifySpreadWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, NumberModifier standing, NumberModifier walking, NumberModifier swimming, NumberModifier inMidair, NumberModifier gliding) { - super(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding); + public ModifySpreadWhen(NumberModifier always, NumberModifier zooming, NumberModifier sneaking, + NumberModifier standing, NumberModifier walking, NumberModifier swimming, + NumberModifier inMidair, NumberModifier gliding, NumberModifier dualWielding) { + super(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding, dualWielding); } @Override @@ -37,13 +39,14 @@ public String getKeyword() { NumberModifier swimming = getModifierHandler(data.of("Swimming")); NumberModifier inMidair = getModifierHandler(data.of("In_Midair")); NumberModifier gliding = getModifierHandler(data.of("Gliding")); + NumberModifier dualWielding = getModifierHandler(data.of("Dual_Wielding")); if (always == null && zooming == null && sneaking == null && standing == null && walking == null - && swimming == null && inMidair == null && gliding == null) { + && swimming == null && inMidair == null && gliding == null && dualWielding == null) { throw data.exception(null, "Tried to use Modify_Spread_When without any arguments"); } - return new ModifySpreadWhen(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding); + return new ModifySpreadWhen(always, zooming, sneaking, standing, walking, swimming, inMidair, gliding, dualWielding); } private NumberModifier getModifierHandler(SerializeData.ConfigAccessor data) throws SerializerException { diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.yml b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.yml index 24bbafa3f..f377225a2 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.yml +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/shoot/spread/ModifySpreadWhen.yml @@ -6,4 +6,5 @@ Modify_Spread_When: Walking: or % Swimming: or % In_Midair: or % - Gliding: or % \ No newline at end of file + Gliding: or % + Dual_Wielding: or % \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.java index 13b2ccc90..c676c190d 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.java @@ -5,7 +5,11 @@ import me.deecaad.core.file.SerializerException; import me.deecaad.weaponmechanics.wrappers.EntityWrapper; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.MainHand; import javax.annotation.Nonnull; import java.util.HashSet; @@ -18,16 +22,20 @@ public class Trigger implements Serializer { private TriggerType mainhand; private TriggerType offhand; private Set denyWhen; + private TriggerType dualWieldMainHand; + private TriggerType dualWieldOffHand; /** * Empty constructor to be used as serializer */ public Trigger() {} - public Trigger(TriggerType mainhand, TriggerType offhand, Set denyWhen) { + public Trigger(TriggerType mainhand, TriggerType offhand, Set denyWhen, TriggerType dualWieldMainHand, TriggerType dualWieldOffHand) { this.mainhand = mainhand; this.offhand = offhand; this.denyWhen = denyWhen; + this.dualWieldMainHand = dualWieldMainHand; + this.dualWieldOffHand = dualWieldOffHand; } /** @@ -39,15 +47,41 @@ public Trigger(TriggerType mainhand, TriggerType offhand, Set denyWhen) * @return true if trigger is valid */ public boolean check(TriggerType triggerType, EquipmentSlot slot, EntityWrapper entityWrapper) { - if (slot == EquipmentSlot.HAND - // Main and off hand are both optional, but only either one is necessary - // Thats why this has null checks also - // Null should mean that check is NOT valid - ? (this.mainhand == null || this.mainhand != triggerType) - : (this.offhand == null || this.offhand != triggerType)) { - // Not the same trigger type - return false; + TriggerType typeCheck; + boolean isDual = entityWrapper.isDualWielding(); + LivingEntity livingEntity = entityWrapper.getEntity(); + + if (slot == EquipmentSlot.HAND) { + if (isDual && dualWieldMainHand != null) { + typeCheck = dualWieldMainHand; + if (typeCheck.isRightOrLeft() && livingEntity.getType() == EntityType.PLAYER &&((Player) livingEntity).getMainHand() == MainHand.LEFT) { + // Invert if player has inverted main hand... + typeCheck = typeCheck == TriggerType.RIGHT_CLICK ? TriggerType.LEFT_CLICK : TriggerType.RIGHT_CLICK; + } + } else { + typeCheck = mainhand; + } + } else { + if (isDual && dualWieldOffHand != null) { + typeCheck = dualWieldOffHand; + if (typeCheck.isRightOrLeft() && livingEntity.getType() == EntityType.PLAYER &&((Player) livingEntity).getMainHand() == MainHand.LEFT) { + // Invert if player has inverted main hand... + typeCheck = typeCheck == TriggerType.RIGHT_CLICK ? TriggerType.LEFT_CLICK : TriggerType.RIGHT_CLICK; + } + } else { + typeCheck = offhand; + } } + + if (typeCheck == null || typeCheck != triggerType) return false; + + return checkDeny(entityWrapper); + } + + /** + * @return true if valid + */ + public boolean checkDeny(EntityWrapper entityWrapper) { if (denyWhenReloading() && (entityWrapper.getMainHandData().isReloading() || entityWrapper.getOffHandData().isReloading())) return false; if (denyWhenZooming() && (entityWrapper.getMainHandData().getZoomData().isZooming() || entityWrapper.getOffHandData().getZoomData().isZooming())) return false; if (denyWhenSneaking() && entityWrapper.isSneaking()) return false; @@ -55,6 +89,7 @@ public boolean check(TriggerType triggerType, EquipmentSlot slot, EntityWrapper if (denyWhenWalking() && entityWrapper.isWalking()) return false; if (denyWhenSwimming() && entityWrapper.isSwimming()) return false; if (denyWhenInMidair() && entityWrapper.isInMidair()) return false; + if (denyWhenDualWielding() && entityWrapper.isDualWielding()) return false; return !denyWhenGliding() || !entityWrapper.isGliding(); } @@ -128,6 +163,13 @@ public boolean denyWhenGliding() { return denyWhen.contains("Gliding"); } + /** + * @return true if trigger should be cancelled when dual wielding + */ + public boolean denyWhenDualWielding() { + return denyWhen.contains("Dual_Wielding"); + } + @Override public String getKeyword() { return "Trigger"; @@ -143,8 +185,13 @@ public Trigger serialize(SerializeData data) throws SerializerException { throw data.exception(null, "At least one of Main_Hand or Off_Hand should be used"); } + TriggerType dualMain = data.of("Dual_Wield.Main_Hand").getEnum(TriggerType.class, null); + TriggerType dualOff = data.of("Dual_Wield.Off_Hand").getEnum(TriggerType.class, null); + if (isDisabled(main)) throw data.exception("Main_Hand", "Tried to use trigger which is disabled in config.yml"); if (isDisabled(off)) throw data.exception("Off_Hand", "Tried to use trigger which is disabled in config.yml"); + if (isDisabled(dualMain)) throw data.exception("Dual_Wield.Main_Hand", "Tried to use trigger which is disabled in config.yml"); + if (isDisabled(dualOff)) throw data.exception("Dual_Wield.Off_Hand", "Tried to use trigger which is disabled in config.yml"); Set denyWhen = new HashSet<>(); ConfigurationSection denySection = data.config.getConfigurationSection(data.key + ".Deny_When"); @@ -152,7 +199,8 @@ public Trigger serialize(SerializeData data) throws SerializerException { for (String denyName : denySection.getKeys(false)) { if (!denyName.equals("Reloading") && !denyName.equals("Zooming") && !denyName.equals("Sneaking") && !denyName.equals("Standing") - && !denyName.equals("Walking") && !denyName.equals("Swimming") && !denyName.equals("In_Midair") && !denyName.equals("Gliding")) { + && !denyName.equals("Walking") && !denyName.equals("Swimming") && !denyName.equals("In_Midair") && !denyName.equals("Gliding") + && !denyName.equals("Dual_Wielding")) { throw data.exception("Deny_When", "Unknown key: " + denyName); } @@ -163,10 +211,11 @@ public Trigger serialize(SerializeData data) throws SerializerException { } } - return new Trigger(main, off, denyWhen); + return new Trigger(main, off, denyWhen, dualMain, dualOff); } private boolean isDisabled(TriggerType trigger) { + if (trigger == null) return false; switch (trigger) { case START_SNEAK: case END_SNEAK: diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.yml b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.yml index fadd7437a..bab68732e 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.yml +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/Trigger.yml @@ -2,6 +2,9 @@ Trigger: Main_Hand: Off_Hand: + Dual_Wield: + Main_Hand: + Off_Hand: Deny_When: Reloading: Zooming: @@ -10,4 +13,5 @@ Trigger: Walking: Swimming: In_Midair: - Gliding: \ No newline at end of file + Gliding: + Dual_Wielding: \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/TriggerType.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/TriggerType.java index e18d02586..938407f05 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/TriggerType.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/weapon/trigger/TriggerType.java @@ -39,4 +39,8 @@ public enum TriggerType { public boolean isSprintType() { return this == TriggerType.START_SPRINT || this == TriggerType.END_SPRINT; } + + public boolean isRightOrLeft() { + return this == RIGHT_CLICK || this == LEFT_CLICK; + } } \ No newline at end of file diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/AK-47.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/AK-47.yml index 67e2b2138..bf83d3301 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/AK-47.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/AK-47.yml @@ -11,7 +11,6 @@ AK-47: Weapon_Info_Display: Action_Bar: Message: "&6AK-47 &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FN_FAL.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FN_FAL.yml index 0e9d116d8..5411d8c6e 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FN_FAL.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FN_FAL.yml @@ -11,7 +11,6 @@ FN_FAL: Weapon_Info_Display: Action_Bar: Message: "&6FN FAL &7«&6%ammo-left%&7»&6%reload% &7[&6%selective_fire_state%&7]" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FR_5.56.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FR_5.56.yml index 7a9f9f900..922f5ca07 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FR_5.56.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/FR_5.56.yml @@ -11,7 +11,6 @@ FR_5_56: Weapon_Info_Display: Action_Bar: Message: "&6FR 5.56 &7«&6%ammo-left%&7»&6%reload% &7[&6%selective_fire_state%&7]" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/M4A1.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/M4A1.yml index 8c2178262..e2f543851 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/M4A1.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/assault_rifles/M4A1.yml @@ -11,7 +11,6 @@ M4A1: Weapon_Info_Display: Action_Bar: Message: "&6M4A1 &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/light_machine_guns/MG34.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/light_machine_guns/MG34.yml index fcd0549e4..bab5a9a56 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/light_machine_guns/MG34.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/light_machine_guns/MG34.yml @@ -11,7 +11,6 @@ MG34: Weapon_Info_Display: Action_Bar: Message: "&6MG34 &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/marksman_rifles/Kar98k.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/marksman_rifles/Kar98k.yml index 33ec5e113..f2f11bdd5 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/marksman_rifles/Kar98k.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/marksman_rifles/Kar98k.yml @@ -11,7 +11,6 @@ Kar98k: Weapon_Info_Display: Action_Bar: Message: "&6Kar98k%firearm-state% &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/357_Magnum.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/357_Magnum.yml index ca1b13010..11ecba6e6 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/357_Magnum.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/357_Magnum.yml @@ -11,7 +11,6 @@ Weapon_Info_Display: Action_Bar: Message: "&6.357 Magnum%firearm-state% &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/50_GS.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/50_GS.yml index 05bafbf32..9efcc1f92 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/50_GS.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/pistols/50_GS.yml @@ -11,12 +11,9 @@ Weapon_Info_Display: Action_Bar: Message: "&6.50 GS &7«&6%ammo-left%&7»&6%reload%" - Time: 40 - Dual_Wield: - Main_Hand: - Action_Bar_Message: "&6%ammo-left%&7»&6%reload% &6.50 GS" - Off_Hand: - Action_Bar_Message: "&6.50 GS &6%reload%&7«&6%ammo-left%" + Dual_Wield: + Main_Hand: "&6%ammo-left%&7»&6%reload% &6.50 GS" + Off_Hand: "&6.50 GS &6%reload%&7«&6%ammo-left%" Dual_Wield: Whitelist: true Weapons: @@ -54,6 +51,7 @@ Zooming: 50% Sneaking: 50% In_Midair: 150% + Dual_Wielding: 150% Recoil: Push_Time: 200 Horizontal: @@ -91,8 +89,8 @@ Trigger: Main_Hand: "LEFT_CLICK" Off_Hand: "LEFT_CLICK" - Deny_When: - Dual_Wielding: true + Deny_When: + Dual_Wielding: true Zoom_Amount: 5 Mechanics: Sounds: diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/rocket_launchers/RPG-7.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/rocket_launchers/RPG-7.yml index 64b02f6c1..e5204a823 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/rocket_launchers/RPG-7.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/rocket_launchers/RPG-7.yml @@ -11,7 +11,6 @@ RPG-7: Weapon_Info_Display: Action_Bar: Message: "&6RPG-7 &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/Origin-12.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/Origin-12.yml index 4ff0eb26b..90b620c7a 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/Origin-12.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/Origin-12.yml @@ -11,7 +11,6 @@ Origin_12: Weapon_Info_Display: Action_Bar: Message: "&6Origin 12 &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/R9-0.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/R9-0.yml index 62821bee5..8c0374552 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/R9-0.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/shotguns/R9-0.yml @@ -11,7 +11,6 @@ R9-0: Weapon_Info_Display: Action_Bar: Message: "&6R9-0%firearm-state% &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sniper_rifles/AX-50.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sniper_rifles/AX-50.yml index 4d57f0f4f..b568d8210 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sniper_rifles/AX-50.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sniper_rifles/AX-50.yml @@ -11,7 +11,6 @@ AX-50: Weapon_Info_Display: Action_Bar: Message: "&6AX-50%firearm-state% &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/AUG.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/AUG.yml index 0221ae063..ef594f6e4 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/AUG.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/AUG.yml @@ -11,7 +11,6 @@ AUG: Weapon_Info_Display: Action_Bar: Message: "&6AUG &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75" diff --git a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/Uzi.yml b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/Uzi.yml index 1eb18ccab..87fd3b304 100644 --- a/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/Uzi.yml +++ b/WeaponMechanics/src/main/resources/WeaponMechanics/weapons/sub_machine_guns/Uzi.yml @@ -11,7 +11,6 @@ Uzi: Weapon_Info_Display: Action_Bar: Message: "&6Uzi &7«&6%ammo-left%&7»&6%reload%" - Time: 40 Weapon_Get_Mechanics: Sounds: - "ITEM_ARMOR_EQUIP_CHAIN-1-0.75"