Skip to content

Commit

Permalink
New payment implementation: XP
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
dentych committed Jan 26, 2016
1 parent eb0f758 commit ead15a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/me/tychsen/enchantgui/Config/EshopConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.tychsen.enchantgui.Economy.MoneyPayment;
import me.tychsen.enchantgui.Economy.NullPayment;
import me.tychsen.enchantgui.Economy.PaymentStrategy;
import me.tychsen.enchantgui.Economy.XPPayment;
import me.tychsen.enchantgui.Menu.DefaultMenuSystem;
import me.tychsen.enchantgui.Main;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -73,8 +74,7 @@ public PaymentStrategy getEconomy() {
economy = new MoneyPayment();
break;
case "xp":
// TODO: Implement XP payment.
economy = new NullPayment();
economy = new XPPayment();
break;
default:
economy = new NullPayment();
Expand Down
27 changes: 27 additions & 0 deletions src/me/tychsen/enchantgui/Economy/XPPayment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.tychsen.enchantgui.Economy;

import org.bukkit.entity.Player;

/**
* Created by denni on 26/01/2016.
*/
public class XPPayment implements PaymentStrategy {
@Override
public boolean withdraw(Player p, int amount) {
if (p.getLevel() >= amount) {
p.giveExpLevels(-amount);
return true;
}

return false;
}

@Override
public boolean hasSufficientFunds(Player p, int amount) {
if (p.getLevel() >= amount) {
return true;
}

return false;
}
}
2 changes: 1 addition & 1 deletion src/me/tychsen/enchantgui/Menu/DefaultMenuGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Inventory generateEnchantMenu(Player p, ItemStack item, Map<String, Stri
lores.add(ChatColor.GOLD + "Level: " + level);
if (!(config.getEconomy() instanceof NullPayment)) {
int price = config.getPrice(ench, level);
lores.add(ChatColor.GREEN + "Price: $" + price);
lores.add(ChatColor.GREEN + "Price: " + price);
}
meta.setLore(lores);
tmp.setItemMeta(meta);
Expand Down

0 comments on commit ead15a3

Please sign in to comment.