11package org.maxgamer.quickshop.economy;
22
3+ import gg.jps.jpscore.JpsCore;
4+ import gg.jps.jpscore.api.JpsApiResponse;
5+ import gg.jps.jpscore.api.i.IJpsBankApi;
6+ import gg.jps.jpscore.core.JpsUtils;
7+ import gg.jps.jpscore.db.def.strChar.PlayerUuidStr;
8+ import gg.jps.jpscore.db.def.varchar.PassBookNote;
9+ import gg.jps.jpscore.db.def.varchar.PluginName;
10+ import gg.jps.jpscore.define.JpsConst;
11+ import gg.jps.jpscore.define.exception.JpsApiException;
12+ import gg.jps.jpscore.economy.def.MoneyJp;
313import org.bukkit.OfflinePlayer;
414import org.bukkit.World;
515import org.bukkit.plugin.Plugin;
@@ -14,70 +24,125 @@ public class Economy_JpsCore extends AbstractEconomy {
1424
1525 private static final QuickShop plugin = QuickShop.getInstance();
1626
27+ private final IJpsBankApi api = JpsCore.API().JpsBankApi();
28+
29+ private String lastError = null;
1730 @Override
18- public boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
19- //TODO implement
20- return false;
31+ public @Nullable String getLastError() {
32+ return this.lastError;
33+ }
34+
35+ @Override
36+ public boolean deposit(@NotNull UUID toPlayer, double amount, @NotNull World world, @Nullable String currency) {
37+ try {
38+ JpsApiResponse<Boolean> res = api.giveBySystem(
39+ new PlayerUuidStr(toPlayer), PluginName.instance(plugin.getName()), new MoneyJp(amount),
40+ PassBookNote.instance("ショップ収入"), IJpsBankApi.AddableToDailyEarnAmount.YES
41+ );
42+ return res.get();
43+ }catch(JpsApiException e){
44+ plugin.getLogger().warning(e.getMessage());
45+ JpsUtils.Logging.fail(e.getCause());
46+ lastError = e.getCause().getMessage();
47+ return false;
48+ }
2149 }
2250
2351 @Override
2452 public boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency) {
25- //TODO implement
26- return false;
53+ try {
54+ JpsApiResponse<Boolean> res = api.giveBySystem(
55+ PlayerUuidStr.instance(trader), PluginName.instance(plugin.getName()), new MoneyJp(amount),
56+ PassBookNote.instance("ショップ収入"), IJpsBankApi.AddableToDailyEarnAmount.YES
57+ );
58+ return res.get();
59+ }catch(JpsApiException e){
60+ plugin.getLogger().warning(e.getMessage());
61+ JpsUtils.Logging.fail(e.getCause());
62+ lastError = e.getCause().getMessage();
63+ return false;
64+ }
2765 }
2866
2967 @Override
3068 public String format(double balance, @NotNull World world, @Nullable String currency) {
31- //TODO implement
32- return null;
69+ return new MoneyJp(balance).toUnitString();
3370 }
3471
3572 @Override
3673 public double getBalance(@NotNull UUID name, @NotNull World world, @Nullable String currency) {
37- //TODO implement
38- return 0;
74+ try{
75+ JpsApiResponse<MoneyJp> res = api.currentCharge(api.getAccountId(new PlayerUuidStr(name)).get());
76+ return res.get().doubleValue();
77+ }catch(JpsApiException e){
78+ plugin.getLogger().warning(e.getMessage());
79+ JpsUtils.Logging.fail(e.getCause());
80+ return 0;
81+ }
3982 }
4083
4184 @Override
4285 public double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @Nullable String currency) {
43- //TODO implement
44- return 0;
86+ try{
87+ JpsApiResponse<MoneyJp> res = api.currentCharge(api.getAccountId(PlayerUuidStr.instance(player)).get());
88+ return res.get().doubleValue();
89+ }catch(JpsApiException e){
90+ plugin.getLogger().warning(e.getMessage());
91+ JpsUtils.Logging.fail(e.getCause());
92+ return 0;
93+ }
4594 }
4695
4796 @Override
48- public boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
49- //TODO implement
50- return false;
97+ public boolean withdraw(@NotNull UUID fromPlayer, double amount, @NotNull World world, @Nullable String currency) {
98+ try {
99+ JpsApiResponse<Boolean> res = api.tollBySystem(
100+ new PlayerUuidStr(fromPlayer), PluginName.instance(plugin.getName()),
101+ new MoneyJp(amount), PassBookNote.instance("ショップ費用")
102+ );
103+ return res.get();
104+ }catch(JpsApiException e){
105+ plugin.getLogger().warning(e.getMessage());
106+ JpsUtils.Logging.fail(e.getCause());
107+ lastError = e.getCause().getMessage();
108+ return false;
109+ }
51110 }
52111
53112 @Override
54113 public boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency) {
55- //TODO implement
56- return false;
114+ try {
115+ JpsApiResponse<Boolean> res = api.tollBySystem(
116+ PlayerUuidStr.instance(trader), PluginName.instance(plugin.getName()),
117+ new MoneyJp(amount), PassBookNote.instance("ショップ費用")
118+ );
119+ return res.get();
120+ }catch(JpsApiException e){
121+ plugin.getLogger().warning(e.getMessage());
122+ JpsUtils.Logging.fail(e.getCause());
123+ lastError = e.getCause().getMessage();
124+ return false;
125+ }
57126 }
58127
59128 @Override
60129 public boolean hasCurrency(@NotNull World world, @NotNull String currency) {
61- //TODO implement
62130 return false;
63131 }
64132
65133 @Override
66134 public boolean supportCurrency() {
67- //TODO implement
68135 return false;
69136 }
70137
71138 @Override
72- public @Nullable String getLastError() {
73- //TODO implement
74- return null;
139+ public boolean isValid() {
140+ return api != null;
75141 }
76142
77143 @Override
78- public boolean isValid() {
79- //TODO implement
80- return false;
144+ public @NotNull String getName() {
145+ return JpsConst.pluginName.get();
81146 }
82147
83148 @Override
@@ -87,7 +152,6 @@ public boolean isValid() {
87152
88153 @Override
89154 public String toString() {
90- //TODO implement
91- return null;
155+ return getClass().getName() +":{isValid:"+ isValid() +", lastError:"+ lastError +"}";
92156 }
93157}
0 commit comments