-
Notifications
You must be signed in to change notification settings - Fork 17
/
EssentialsCurrency.java
110 lines (90 loc) · 2.92 KB
/
EssentialsCurrency.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* This file is part of LWC (https://github.com/Hidendra/LWC)
*
* 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.griefcraft.integration.currency;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.api.NoLoanPermittedException;
import com.earth2me.essentials.api.UserDoesNotExistException;
import com.griefcraft.integration.ICurrency;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class EssentialsCurrency implements ICurrency {
/**
* The Essentials plugin object
*/
private Essentials essentials;
public EssentialsCurrency() {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
if(plugin == null) {
return;
}
essentials = (Essentials) plugin;
}
public boolean isActive() {
return false;
}
public String format(double money) {
return Economy.format(money);
}
public String getMoneyName() {
return essentials.getSettings().getCurrencySymbol();
}
public double getBalance(Player player) {
if(player == null) {
return 0;
}
try {
return Economy.getMoney(player.getName());
} catch(UserDoesNotExistException e) {
return 0d;
}
}
public boolean canAfford(Player player, double money) {
if(player == null) {
return false;
}
try {
return Economy.hasEnough(player.getName(), money);
} catch(UserDoesNotExistException e) {
return false;
}
}
public double addMoney(Player player, double money) {
if(player == null) {
return 0;
}
try {
Economy.add(player.getName(), money);
} catch(UserDoesNotExistException e) {
return 0;
} catch(NoLoanPermittedException e) {
return 0;
}
return getBalance(player);
}
public double removeMoney(Player player, double money) {
try {
Economy.subtract(player.getName(), money);
} catch(UserDoesNotExistException e) {
return 0;
} catch(NoLoanPermittedException e) {
return 0;
}
return getBalance(player);
}
}