From 75fe7a737b895d3d13cdbee6d3cb7789702cdd90 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 20 Aug 2022 20:25:39 +0200 Subject: [PATCH] Improved support for Vault --- .../Indyuce/mmoitems/api/player/PlayerData.java | 15 ++++++++------- .../Indyuce/mmoitems/comp/eco/MoneyCondition.java | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 3afe20fb..953007b7 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -241,12 +241,11 @@ public class PlayerData { // Apply permissions if Vault exists if (MMOItems.plugin.hasPermissions() && item.hasData(ItemStats.GRANTED_PERMISSIONS)) { + final Permission perms = MMOItems.plugin.getVault().getPermissions(); permissions.addAll(((StringListData) item.getData(ItemStats.GRANTED_PERMISSIONS)).getList()); - Permission perms = MMOItems.plugin.getVault().getPermissions(); permissions.forEach(perm -> { - if (!perms.has(getPlayer(), perm)) { + if (!perms.has(getPlayer(), perm)) perms.playerAdd(getPlayer(), perm); - } }); } } @@ -281,10 +280,12 @@ public class PlayerData { // Apply item set bonuses if (setBonuses != null) { - final Permission perms = MMOItems.plugin.getVault().getPermissions(); - for (String perm : setBonuses.getPermissions()) - if (!perms.has(getPlayer(), perm)) - perms.playerAdd(getPlayer(), perm); + if (MMOItems.plugin.hasPermissions()) { + final Permission perms = MMOItems.plugin.getVault().getPermissions(); + for (String perm : setBonuses.getPermissions()) + if (!perms.has(getPlayer(), perm)) + perms.playerAdd(getPlayer(), perm); + } for (AbilityData ability : setBonuses.getAbilities()) mmoData.getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", ability, EquipmentSlot.OTHER, ModifierSource.OTHER)); for (ParticleData particle : setBonuses.getParticles()) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java index 1c76c32e..72fa8e29 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/eco/MoneyCondition.java @@ -1,9 +1,10 @@ package net.Indyuce.mmoitems.comp.eco; +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.crafting.condition.Condition; import net.Indyuce.mmoitems.api.player.PlayerData; -import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; public class MoneyCondition extends Condition { private final double amount; @@ -11,13 +12,13 @@ public class MoneyCondition extends Condition { public MoneyCondition(MMOLineConfig config) { super("money"); - config.validate("amount"); + Validate.isTrue(MMOItems.plugin.hasEconomy(), "No economy plugin found"); + config.validateKeys("amount"); amount = config.getDouble("amount"); } @Override public boolean isMet(PlayerData data) { - if(!data.isOnline()) return false; return MMOItems.plugin.getVault().getEconomy().has(data.getPlayer(), amount); } @@ -28,7 +29,6 @@ public class MoneyCondition extends Condition { @Override public void whenCrafting(PlayerData data) { - if(!data.isOnline()) return; MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount); } }