-
Notifications
You must be signed in to change notification settings - Fork 2
/
PurchaseAction.java
87 lines (70 loc) · 2.48 KB
/
PurchaseAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* QuestManager: An RPG plugin for the Bukkit API.
* Copyright (C) 2015-2016 Github Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.skyisland.questmanager.ui.menu.action;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.skyisland.questmanager.player.QuestPlayer;
/**
* The action of purchasing an item or service from an NPC.
* This event specifically details purchases done from within an InventoryMenu, where it has
* an ItemStack to give to the player
*
*/
public class PurchaseAction implements MenuAction {
private int cost;
private int fameCheck;
private ItemStack item;
private QuestPlayer player;
private static final String DENIAL_FAME = "Not famous enough!";
private static final String DENIAL_MONEY = "Not enough money!";
private static final String DENIAL_SPACE = "Not enough room in your inventory!";
public PurchaseAction(QuestPlayer player, ItemStack item, int cost, int fameRequirement) {
this.player = player;
this.item = item;
this.cost = cost;
this.fameCheck = fameRequirement;
}
@Override
public void onAction() {
//check if they have enough fame and money.
// If they do, give them the item and subtract the cost
// If they don't don't give them the item and tell them off those noobs
if (!player.getPlayer().isOnline()) {
return;
//something fishy happened...
}
Player p = player.getPlayer().getPlayer();
//if (player.getFame() < fameCheck) {
if (player.getAlphaFame() < fameCheck) {
p.sendMessage(DENIAL_FAME);
return;
}
if (player.getMoney() < cost) {
p.sendMessage(DENIAL_MONEY);
return;
}
//make sure there's room in their inventory
if (p.getInventory().firstEmpty() == -1) {
p.sendMessage(DENIAL_SPACE);
return;
}
//everything's good, so throw it in!
p.getInventory().addItem(item);
player.addMoney(-cost);
}
}