Improved support for Vault

This commit is contained in:
Indyuce 2022-08-20 20:25:39 +02:00
parent 5a0f51331c
commit 75fe7a737b
2 changed files with 12 additions and 11 deletions

View File

@ -241,12 +241,11 @@ public class PlayerData {
// Apply permissions if Vault exists // Apply permissions if Vault exists
if (MMOItems.plugin.hasPermissions() && item.hasData(ItemStats.GRANTED_PERMISSIONS)) { 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()); permissions.addAll(((StringListData) item.getData(ItemStats.GRANTED_PERMISSIONS)).getList());
Permission perms = MMOItems.plugin.getVault().getPermissions();
permissions.forEach(perm -> { permissions.forEach(perm -> {
if (!perms.has(getPlayer(), perm)) { if (!perms.has(getPlayer(), perm))
perms.playerAdd(getPlayer(), perm); perms.playerAdd(getPlayer(), perm);
}
}); });
} }
} }
@ -281,10 +280,12 @@ public class PlayerData {
// Apply item set bonuses // Apply item set bonuses
if (setBonuses != null) { if (setBonuses != null) {
final Permission perms = MMOItems.plugin.getVault().getPermissions(); if (MMOItems.plugin.hasPermissions()) {
for (String perm : setBonuses.getPermissions()) final Permission perms = MMOItems.plugin.getVault().getPermissions();
if (!perms.has(getPlayer(), perm)) for (String perm : setBonuses.getPermissions())
perms.playerAdd(getPlayer(), perm); if (!perms.has(getPlayer(), perm))
perms.playerAdd(getPlayer(), perm);
}
for (AbilityData ability : setBonuses.getAbilities()) for (AbilityData ability : setBonuses.getAbilities())
mmoData.getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", ability, EquipmentSlot.OTHER, ModifierSource.OTHER)); mmoData.getPassiveSkillMap().addModifier(new PassiveSkill("MMOItemsItem", ability, EquipmentSlot.OTHER, ModifierSource.OTHER));
for (ParticleData particle : setBonuses.getParticles()) for (ParticleData particle : setBonuses.getParticles())

View File

@ -1,9 +1,10 @@
package net.Indyuce.mmoitems.comp.eco; package net.Indyuce.mmoitems.comp.eco;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.crafting.condition.Condition; import net.Indyuce.mmoitems.api.crafting.condition.Condition;
import net.Indyuce.mmoitems.api.player.PlayerData; 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 { public class MoneyCondition extends Condition {
private final double amount; private final double amount;
@ -11,13 +12,13 @@ public class MoneyCondition extends Condition {
public MoneyCondition(MMOLineConfig config) { public MoneyCondition(MMOLineConfig config) {
super("money"); super("money");
config.validate("amount"); Validate.isTrue(MMOItems.plugin.hasEconomy(), "No economy plugin found");
config.validateKeys("amount");
amount = config.getDouble("amount"); amount = config.getDouble("amount");
} }
@Override @Override
public boolean isMet(PlayerData data) { public boolean isMet(PlayerData data) {
if(!data.isOnline()) return false;
return MMOItems.plugin.getVault().getEconomy().has(data.getPlayer(), amount); return MMOItems.plugin.getVault().getEconomy().has(data.getPlayer(), amount);
} }
@ -28,7 +29,6 @@ public class MoneyCondition extends Condition {
@Override @Override
public void whenCrafting(PlayerData data) { public void whenCrafting(PlayerData data) {
if(!data.isOnline()) return;
MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount); MMOItems.plugin.getVault().getEconomy().withdrawPlayer(data.getPlayer(), amount);
} }
} }