Skip to content

Commit a2d4de4

Browse files
committed
spilt api interface (part 6)
1 parent 07d7ea3 commit a2d4de4

File tree

19 files changed

+119
-124
lines changed

19 files changed

+119
-124
lines changed

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import org.maxgamer.quickshop.api.command.CommandManager;
4949
import org.maxgamer.quickshop.api.compatibility.CompatibilityManager;
5050
import org.maxgamer.quickshop.api.database.DatabaseHelper;
51+
import org.maxgamer.quickshop.api.economy.AbstractEconomy;
5152
import org.maxgamer.quickshop.api.economy.EconomyCore;
53+
import org.maxgamer.quickshop.api.economy.EconomyType;
5254
import org.maxgamer.quickshop.api.integration.IntegrateStage;
5355
import org.maxgamer.quickshop.api.integration.IntegrationManager;
5456
import org.maxgamer.quickshop.api.localization.text.TextManager;
@@ -106,6 +108,8 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
106108
private JavaShopManager shopManager;
107109
private JavaTextManager textManager;
108110
private boolean priceChangeRequiresFee = false;
111+
private final Map<String, Integer> limits = new HashMap<>(15);
112+
private final GameVersion gameVersion = GameVersion.get(Util.getNMSVersion());
109113
/* Public QuickShop API End */
110114

111115
/**
@@ -120,6 +124,7 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
120124
*/
121125
private static PermissionManager permissionManager;
122126
private static boolean loaded = false;
127+
123128
/**
124129
* If running environment test
125130
*/
@@ -129,13 +134,9 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
129134
/**
130135
* The shop limites.
131136
*/
132-
@Getter
133-
private final Map<String, Integer> limits = new HashMap<>(15);
134137
private final ConfigProvider configProvider = new ConfigProvider(this, new File(getDataFolder(), "config.yml"));
135138
private final List<BukkitTask> timerTaskList = new ArrayList<>(3);
136139
@Getter
137-
private final GameVersion gameVersion = GameVersion.get(Util.getNMSVersion());
138-
@Getter
139140
private final ReloadManager reloadManager = new ReloadManager();
140141
boolean onLoadCalled = false;
141142
/**
@@ -145,7 +146,6 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
145146
@Getter
146147
@Setter
147148
private BootError bootError;
148-
149149
/**
150150
* Queued database manager
151151
*/
@@ -168,9 +168,7 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
168168
* The economy we hook into for transactions
169169
*/
170170
@Getter
171-
private Economy economy;
172-
173-
171+
private AbstractEconomy economy;
174172
/**
175173
* Whether or not to limit players shop amounts
176174
*/
@@ -484,9 +482,6 @@ public boolean loadEcon() {
484482
if (!core.isValid()) {
485483
setupBootError(BuiltInSolution.econError(), false);
486484
return false;
487-
} else {
488-
this.economy = new Economy(this, ServiceInjector.getEconomyCore(core));
489-
return true;
490485
}
491486
} catch (Exception e) {
492487
this.getSentryErrorReporter().ignoreThrow();
@@ -497,6 +492,7 @@ public boolean loadEcon() {
497492
getLogger().severe("Plugin listeners was disabled, please fix the economy issue.");
498493
return false;
499494
}
495+
return true;
500496
}
501497

502498
// /**
@@ -1019,7 +1015,7 @@ private void submitMeritcs() {
10191015
vaultVer = "Vault not found";
10201016
}
10211017
// Use internal Metric class not Maven for solve plugin name issues
1022-
String economyType = Economy.getNowUsing().name();
1018+
String economyType = AbstractEconomy.getNowUsing().name();
10231019
if (getEconomy() != null) {
10241020
economyType = this.getEconomy().getName();
10251021
}
@@ -2011,4 +2007,14 @@ public boolean isPriceChangeRequiresFee() {
20112007
public CommandManager getCommandManager() {
20122008
return this.commandManager;
20132009
}
2010+
2011+
@Override
2012+
public Map<String, Integer> getLimits() {
2013+
return this.limits;
2014+
}
2015+
2016+
@Override
2017+
public GameVersion getGameVersion() {
2018+
return this.gameVersion;
2019+
}
20142020
}

src/main/java/org/maxgamer/quickshop/api/QuickShopAPI.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import org.maxgamer.quickshop.api.localization.text.TextManager;
77
import org.maxgamer.quickshop.api.shop.ItemMatcher;
88
import org.maxgamer.quickshop.api.shop.ShopManager;
9+
import org.maxgamer.quickshop.util.GameVersion;
10+
11+
import java.util.Map;
912

1013
public interface QuickShopAPI {
1114

@@ -29,4 +32,8 @@ public interface QuickShopAPI {
2932

3033
CommandManager getCommandManager();
3134

35+
Map<String, Integer> getLimits();
36+
37+
GameVersion getGameVersion();
38+
3239
}

src/main/java/org/maxgamer/quickshop/economy/Economy.java renamed to src/main/java/org/maxgamer/quickshop/api/economy/AbstractEconomy.java

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,62 @@
1717
*
1818
*/
1919

20-
package org.maxgamer.quickshop.economy;
20+
package org.maxgamer.quickshop.api.economy;
2121

22-
import lombok.Getter;
23-
import lombok.Setter;
2422
import org.bukkit.OfflinePlayer;
2523
import org.bukkit.World;
2624
import org.bukkit.plugin.Plugin;
2725
import org.jetbrains.annotations.NotNull;
2826
import org.jetbrains.annotations.Nullable;
2927
import org.maxgamer.quickshop.QuickShop;
30-
import org.maxgamer.quickshop.api.economy.EconomyCore;
31-
import org.maxgamer.quickshop.util.Util;
3228
import org.maxgamer.quickshop.util.reload.ReloadResult;
3329
import org.maxgamer.quickshop.util.reload.ReloadStatus;
30+
import org.maxgamer.quickshop.util.reload.Reloadable;
3431

3532
import java.util.UUID;
3633

37-
public class Economy implements EconomyCore {
34+
public abstract class AbstractEconomy implements EconomyCore, Reloadable {
3835

3936
private final QuickShop plugin;
40-
@Getter
41-
@Setter
42-
@NotNull
43-
private EconomyCore core;
4437

45-
public Economy(@NotNull QuickShop plugin, @NotNull EconomyCore core) {
38+
public AbstractEconomy(@NotNull QuickShop plugin) {
4639
this.plugin = plugin;
47-
this.core = core;
40+
4841
}
4942

5043
public static EconomyType getNowUsing() {
5144
return EconomyType.fromID(QuickShop.getInstance().getConfig().getInt("economy-type"));
5245
}
5346

5447
@Override
55-
public String toString() {
56-
return core.getClass().getName().split("_")[1];
57-
}
48+
public abstract String toString();
49+
// return core.getClass().getName().split("_")[1];
50+
//}
51+
5852

5953
@Override
60-
public boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
61-
return core.deposit(name, amount, world, currency);
54+
public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency) {
55+
if (!isValid()) {
56+
return false;
57+
}
58+
if (this.getBalance(from, world, currency) >= amount) {
59+
if (this.withdraw(from, amount, world, currency)) {
60+
if (this.deposit(to, amount, world, currency)) {
61+
this.deposit(from, amount, world, currency);
62+
return false;
63+
}
64+
return true;
65+
}
66+
return false;
67+
}
68+
return false;
6269
}
6370

6471
@Override
65-
public boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency) {
66-
return core.deposit(trader, amount, world, currency);
67-
}
72+
public abstract boolean deposit(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency);
73+
74+
@Override
75+
public abstract boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency);
6876

6977
/**
7078
* Formats the given number... E.g. 50.5 becomes $50.5 Dollars, or 50 Dollars 5 Cents
@@ -73,35 +81,22 @@ public boolean deposit(@NotNull OfflinePlayer trader, double amount, @NotNull Wo
7381
* @return The balance in human readable text.
7482
*/
7583
@Override
76-
public String format(double balance, @NotNull World world, @Nullable String currency) {
77-
return Util.parseColours(core.format(balance, world, currency));
78-
// Fix color issue from some stupid economy plugin....
79-
}
84+
public abstract String format(double balance, @NotNull World world, @Nullable String currency);
85+
// return Util.parseColours(core.format(balance, world, currency));
86+
// // Fix color issue from some stupid economy plugin....
87+
//}
8088

8189
@Override
82-
public double getBalance(@NotNull UUID name, @NotNull World world, @Nullable String currency) {
83-
return core.getBalance(name, world, currency);
84-
}
90+
public abstract double getBalance(@NotNull UUID name, @NotNull World world, @Nullable String currency);
8591

8692
@Override
87-
public double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @Nullable String currency) {
88-
return core.getBalance(player, world, currency);
89-
}
93+
public abstract double getBalance(@NotNull OfflinePlayer player, @NotNull World world, @Nullable String currency);
9094

9195
@Override
92-
public boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency) {
93-
return core.transfer(from, to, amount, world, currency);
94-
}
96+
public abstract boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency);
9597

9698
@Override
97-
public boolean withdraw(@NotNull UUID name, double amount, @NotNull World world, @Nullable String currency) {
98-
return core.withdraw(name, amount, world, currency);
99-
}
100-
101-
@Override
102-
public boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency) {
103-
return core.withdraw(trader, amount, world, currency);
104-
}
99+
public abstract boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull World world, @Nullable String currency);
105100

106101
/**
107102
* Gets the currency does exists
@@ -110,29 +105,23 @@ public boolean withdraw(@NotNull OfflinePlayer trader, double amount, @NotNull W
110105
* @return exists
111106
*/
112107
@Override
113-
public boolean hasCurrency(@NotNull World world, @NotNull String currency) {
114-
return this.core.hasCurrency(world, currency);
115-
}
108+
public abstract boolean hasCurrency(@NotNull World world, @NotNull String currency);
116109

117110
/**
118111
* Gets currency supports status
119112
*
120113
* @return true if supports
121114
*/
122115
@Override
123-
public boolean supportCurrency() {
124-
return this.core.supportCurrency();
125-
}
116+
public abstract boolean supportCurrency();
126117

127118
/**
128119
* Checks that this economy is valid. Returns false if it is not valid.
129120
*
130121
* @return True if this economy will work, false if it will not.
131122
*/
132123
@Override
133-
public boolean isValid() {
134-
return core.isValid();
135-
}
124+
public abstract boolean isValid();
136125

137126
@Override
138127
public @NotNull String getName() {

src/main/java/org/maxgamer/quickshop/api/economy/EconomyCore.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
import org.bukkit.plugin.Plugin;
2525
import org.jetbrains.annotations.NotNull;
2626
import org.jetbrains.annotations.Nullable;
27-
import org.maxgamer.quickshop.util.reload.Reloadable;
2827

2928
import java.util.UUID;
3029

3130
/**
3231
* @author netherfoam Represents an economy.
3332
*/
34-
public interface EconomyCore extends Reloadable {
33+
public interface EconomyCore {
3534
/**
3635
* Deposits a given amount of money from thin air to the given username.
3736
*
@@ -94,22 +93,7 @@ public interface EconomyCore extends Reloadable {
9493
* @param world The transaction world
9594
* @return true if success (Payer had enough cash, receiver was able to receive the funds)
9695
*/
97-
default boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency) {
98-
if (!isValid()) {
99-
return false;
100-
}
101-
if (this.getBalance(from, world, currency) >= amount) {
102-
if (this.withdraw(from, amount, world, currency)) {
103-
if (this.deposit(to, amount, world, currency)) {
104-
this.deposit(from, amount, world, currency);
105-
return false;
106-
}
107-
return true;
108-
}
109-
return false;
110-
}
111-
return false;
112-
}
96+
boolean transfer(@NotNull UUID from, @NotNull UUID to, double amount, @NotNull World world, @Nullable String currency);
11397

11498
/**
11599
* Withdraws a given amount of money from the given username and turns it to thin air.

src/main/java/org/maxgamer/quickshop/economy/EconomyTransaction.java renamed to src/main/java/org/maxgamer/quickshop/api/economy/EconomyTransaction.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*
1818
*/
1919

20-
package org.maxgamer.quickshop.economy;
20+
package org.maxgamer.quickshop.api.economy;
2121

2222
import lombok.Builder;
2323
import lombok.Getter;
2424
import org.bukkit.World;
2525
import org.jetbrains.annotations.NotNull;
2626
import org.jetbrains.annotations.Nullable;
2727
import org.maxgamer.quickshop.QuickShop;
28-
import org.maxgamer.quickshop.api.economy.EconomyCore;
28+
import org.maxgamer.quickshop.economy.Trader;
2929
import org.maxgamer.quickshop.event.EconomyCommitEvent;
3030
import org.maxgamer.quickshop.util.CalculateUtil;
3131
import org.maxgamer.quickshop.util.JsonUtil;
@@ -46,11 +46,11 @@ public class EconomyTransaction {
4646
@NotNull
4747
@JsonUtil.Hidden
4848
private final EconomyCore core;
49-
private final double actualAmount; //
49+
private final double actualAmount;
5050
private final double tax;
5151
private final Trader taxer;
5252
private final boolean allowLoan;
53-
private final boolean tryingFixBanlanceInsuffient;
53+
private final boolean tryingFixBalanceInsufficient;
5454
@Getter
5555
private final World world;
5656
@Getter
@@ -101,11 +101,11 @@ public EconomyTransaction(@Nullable UUID from, @Nullable UUID to, double amount,
101101
//For passing Test
102102
//noinspection ConstantConditions
103103
if (QuickShop.getInstance() != null) {
104-
this.tryingFixBanlanceInsuffient = QuickShop.getInstance().getConfig().getBoolean("trying-fix-banlance-insuffient");
104+
this.tryingFixBalanceInsufficient = QuickShop.getInstance().getConfig().getBoolean("trying-fix-banlance-insuffient");
105105
} else {
106-
this.tryingFixBanlanceInsuffient = false;
106+
this.tryingFixBalanceInsufficient = false;
107107
}
108-
if (tryingFixBanlanceInsuffient) {
108+
if (tryingFixBalanceInsufficient) {
109109
//Fetch some stupid plugin caching
110110
if (from != null) {
111111
this.core.getBalance(from, world, currency);
@@ -140,7 +140,7 @@ public boolean commit() {
140140
return this.commit(new TransactionCallback() {
141141
@Override
142142
public void onSuccess(@NotNull EconomyTransaction economyTransaction) {
143-
if (tryingFixBanlanceInsuffient) {
143+
if (tryingFixBalanceInsufficient) {
144144
//Fetch some stupid plugin caching
145145
if (from != null) {
146146
core.getBalance(from, world, currency);
@@ -248,7 +248,7 @@ public enum TransactionSteps {
248248
DONE
249249
}
250250

251-
interface TransactionCallback {
251+
public interface TransactionCallback {
252252
/**
253253
* Calling while Transaction commit
254254
*

src/main/java/org/maxgamer/quickshop/economy/EconomyType.java renamed to src/main/java/org/maxgamer/quickshop/api/economy/EconomyType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*/
1919

20-
package org.maxgamer.quickshop.economy;
20+
package org.maxgamer.quickshop.api.economy;
2121

2222
import org.jetbrains.annotations.NotNull;
2323

0 commit comments

Comments
 (0)