forked from dentych/EnchantGUI
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79fd057
commit 45a0593
Showing
3 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/me/tychsen/enchantgui/economy/MaterialPayment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.tychsen.enchantgui.economy; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
|
||
public class MaterialPayment implements PaymentStrategy { | ||
private final Material material; | ||
|
||
public MaterialPayment(Material material) { | ||
this.material = material; | ||
} | ||
|
||
@Override | ||
public boolean withdraw(@NotNull Player player, int amount) { | ||
if(!hasSufficientFunds(player,amount)) return false; | ||
|
||
//do stuff | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean withdraw(@NotNull Player player, double amount) { | ||
return withdraw(player, (int) amount); | ||
} | ||
|
||
//todo not precise. | ||
@Override | ||
public boolean hasSufficientFunds(@NotNull Player player, int amount) { | ||
final int count = Arrays.stream(player.getInventory().getContents()) | ||
.filter(itemStack -> itemStack.getType() == material) | ||
.mapToInt(ItemStack::getAmount) | ||
.sum(); | ||
|
||
return count >= amount; | ||
} | ||
|
||
@Override | ||
public boolean hasSufficientFunds(@NotNull Player player, double amount) { | ||
return hasSufficientFunds(player, (int) amount); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "MaterialPayment"; | ||
} | ||
|
||
@Override | ||
public String getCurrency() { | ||
return material.name().toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters