Skip to content

Commit ab04df7

Browse files
committed
spilt api interface (part 2)
1 parent 1e8fa34 commit ab04df7

14 files changed

+97
-64
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.maxgamer.quickshop.api.shop;
2+
3+
import org.bukkit.inventory.ItemStack;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
public interface PriceLimiter {
7+
8+
@NotNull
9+
PriceLimiterCheckResult check(@NotNull ItemStack stack, double price);
10+
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.maxgamer.quickshop.api.shop;
2+
3+
public interface PriceLimiterCheckResult {
4+
PriceLimiterStatus getStatus();
5+
double getMin();
6+
double getMax();
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.maxgamer.quickshop.api.shop;
2+
3+
public enum PriceLimiterStatus {
4+
PASS,
5+
REACHED_PRICE_MAX_LIMIT,
6+
REACHED_PRICE_MIN_LIMIT,
7+
PRICE_RESTRICTED,
8+
NOT_A_WHOLE_NUMBER,
9+
NOT_VALID
10+
}

src/main/java/org/maxgamer/quickshop/api/shop/ShopManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,6 @@ public interface ShopManager {
202202
* It defined in configuration.
203203
*/
204204
void migrateOwnerToUnlimitedShopOwner(Shop shop);
205+
206+
PriceLimiter getPriceLimiter();
205207
}

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Item.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import org.jetbrains.annotations.NotNull;
2929
import org.maxgamer.quickshop.QuickShop;
3030
import org.maxgamer.quickshop.api.command.CommandHandler;
31+
import org.maxgamer.quickshop.api.shop.PriceLimiterCheckResult;
32+
import org.maxgamer.quickshop.api.shop.PriceLimiterStatus;
3133
import org.maxgamer.quickshop.api.shop.Shop;
32-
import org.maxgamer.quickshop.util.PriceLimiter;
34+
import org.maxgamer.quickshop.shop.JavaPriceLimiter;
3335
import org.maxgamer.quickshop.util.Util;
3436

3537
@AllArgsConstructor
@@ -65,13 +67,13 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
6567
if (!plugin.isAllowStack() && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.create.stacks")) {
6668
itemStack.setAmount(1);
6769
}
68-
PriceLimiter limiter = new PriceLimiter(
70+
JavaPriceLimiter limiter = new JavaPriceLimiter(
6971
plugin.getConfig().getDouble("shop.minimum-price"),
7072
plugin.getConfig().getInt("shop.maximum-price"),
7173
plugin.getConfig().getBoolean("shop.allow-free-shop"),
7274
plugin.getConfig().getBoolean("whole-number-prices-only"));
73-
PriceLimiter.CheckResult checkResult = limiter.check(itemStack, shop.getPrice());
74-
if (checkResult.getStatus() != PriceLimiter.Status.PASS) {
75+
PriceLimiterCheckResult checkResult = limiter.check(itemStack, shop.getPrice());
76+
if (checkResult.getStatus() != PriceLimiterStatus.PASS) {
7577
plugin.text().of(sender, "restricted-prices", Util.getItemStackName(shop.getItem()),
7678
String.valueOf(checkResult.getMin()),
7779
String.valueOf(checkResult.getMax())).send();

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Price.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import org.jetbrains.annotations.NotNull;
2727
import org.maxgamer.quickshop.QuickShop;
2828
import org.maxgamer.quickshop.api.command.CommandHandler;
29+
import org.maxgamer.quickshop.api.shop.PriceLimiterCheckResult;
30+
import org.maxgamer.quickshop.api.shop.PriceLimiterStatus;
2931
import org.maxgamer.quickshop.economy.EconomyTransaction;
3032
import org.maxgamer.quickshop.shop.ContainerShop;
3133
import org.maxgamer.quickshop.api.shop.Shop;
3234
import org.maxgamer.quickshop.util.MsgUtil;
33-
import org.maxgamer.quickshop.util.PriceLimiter;
35+
import org.maxgamer.quickshop.shop.JavaPriceLimiter;
3436
import org.maxgamer.quickshop.util.Util;
3537

3638
import java.util.Collections;
@@ -81,7 +83,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
8183
return;
8284
}
8385

84-
PriceLimiter limiter = new PriceLimiter(
86+
JavaPriceLimiter limiter = new JavaPriceLimiter(
8587
plugin.getConfig().getDouble("shop.minimum-price"),
8688
plugin.getConfig().getInt("shop.maximum-price"),
8789
plugin.getConfig().getBoolean("shop.allow-free-shop"),
@@ -104,16 +106,16 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
104106
return;
105107
}
106108

107-
PriceLimiter.CheckResult checkResult = limiter.check(shop.getItem(), price);
108-
if (checkResult.getStatus() == PriceLimiter.Status.REACHED_PRICE_MIN_LIMIT) {
109+
PriceLimiterCheckResult checkResult = limiter.check(shop.getItem(), price);
110+
if (checkResult.getStatus() == PriceLimiterStatus.REACHED_PRICE_MIN_LIMIT) {
109111
plugin.text().of(sender, "price-too-cheap", (format) ? MsgUtil.decimalFormat(checkResult.getMin()) : Double.toString(checkResult.getMin())).send();
110112
return;
111113
}
112-
if (checkResult.getStatus() == PriceLimiter.Status.REACHED_PRICE_MAX_LIMIT) {
114+
if (checkResult.getStatus() == PriceLimiterStatus.REACHED_PRICE_MAX_LIMIT) {
113115
plugin.text().of(sender, "price-too-high", (format) ? MsgUtil.decimalFormat(checkResult.getMax()) : Double.toString(checkResult.getMax())).send();
114116
return;
115117
}
116-
if (checkResult.getStatus() == PriceLimiter.Status.PRICE_RESTRICTED) {
118+
if (checkResult.getStatus() == PriceLimiterStatus.PRICE_RESTRICTED) {
117119
plugin.text().of(sender, "restricted-prices", Util.getItemStackName(shop.getItem()),
118120
String.valueOf(checkResult.getMin()),
119121
String.valueOf(checkResult.getMax())).send();

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_SilentUnlimited.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.maxgamer.quickshop.QuickShop;
2626
import org.maxgamer.quickshop.api.command.CommandHandler;
2727
import org.maxgamer.quickshop.api.shop.Shop;
28+
import org.maxgamer.quickshop.shop.JavaShopManager;
2829
import org.maxgamer.quickshop.util.MsgUtil;
2930
import org.maxgamer.quickshop.util.Util;
3031

@@ -56,7 +57,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5657
plugin.text().of(sender, "command.toggle-unlimited.unlimited").send();
5758
if (plugin.getConfig().getBoolean("unlimited-shop-owner-change")) {
5859
plugin.getShopManager().migrateOwnerToUnlimitedShopOwner(shop);
59-
plugin.text().of(sender, "unlimited-shop-owner-changed", plugin.getShopManager().getCacheUnlimitedShopAccount().getName()).send();
60+
plugin.text().of(sender, "unlimited-shop-owner-changed", ((JavaShopManager)plugin.getShopManager()).getCacheUnlimitedShopAccount().getName()).send();
6061
}
6162
return;
6263
}

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Size.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import org.jetbrains.annotations.Nullable;
2929
import org.maxgamer.quickshop.QuickShop;
3030
import org.maxgamer.quickshop.api.command.CommandHandler;
31+
import org.maxgamer.quickshop.api.shop.PriceLimiterCheckResult;
32+
import org.maxgamer.quickshop.api.shop.PriceLimiterStatus;
3133
import org.maxgamer.quickshop.api.shop.Shop;
32-
import org.maxgamer.quickshop.util.PriceLimiter;
34+
import org.maxgamer.quickshop.shop.JavaPriceLimiter;
3335
import org.maxgamer.quickshop.util.Util;
3436

3537
import java.util.Collections;
@@ -69,13 +71,13 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
6971
}
7072
ItemStack pendingItemStack = shop.getItem().clone();
7173
pendingItemStack.setAmount(amount);
72-
PriceLimiter limiter = new PriceLimiter(
74+
JavaPriceLimiter limiter = new JavaPriceLimiter(
7375
plugin.getConfig().getDouble("shop.minimum-price"),
7476
plugin.getConfig().getInt("shop.maximum-price"),
7577
plugin.getConfig().getBoolean("shop.allow-free-shop"),
7678
plugin.getConfig().getBoolean("whole-number-prices-only"));
77-
PriceLimiter.CheckResult checkResult = limiter.check(pendingItemStack, shop.getPrice());
78-
if (checkResult.getStatus() != PriceLimiter.Status.PASS) {
79+
PriceLimiterCheckResult checkResult = limiter.check(pendingItemStack, shop.getPrice());
80+
if (checkResult.getStatus() != PriceLimiterStatus.PASS) {
7981
plugin.text().of(sender, "restricted-prices", Util.getItemStackName(shop.getItem()),
8082
String.valueOf(checkResult.getMin()),
8183
String.valueOf(checkResult.getMax())).send();

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Unlimited.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.maxgamer.quickshop.QuickShop;
2828
import org.maxgamer.quickshop.api.command.CommandHandler;
2929
import org.maxgamer.quickshop.api.shop.Shop;
30+
import org.maxgamer.quickshop.shop.JavaShopManager;
3031

3132
@AllArgsConstructor
3233
public class SubCommand_Unlimited implements CommandHandler<Player> {
@@ -54,7 +55,7 @@ public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @Not
5455
plugin.text().of(sender, "command.toggle-unlimited.unlimited").send();
5556
if (plugin.getConfig().getBoolean("unlimited-shop-owner-change")) {
5657
plugin.getShopManager().migrateOwnerToUnlimitedShopOwner(shop);
57-
plugin.text().of(sender, "unlimited-shop-owner-changed", plugin.getShopManager().getCacheUnlimitedShopAccount().getName()).send();
58+
plugin.text().of(sender, "unlimited-shop-owner-changed", ((JavaShopManager)plugin.getShopManager()).getCacheUnlimitedShopAccount().getName()).send();
5859
}
5960
return;
6061
}

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@
4848
import org.jetbrains.annotations.NotNull;
4949
import org.jetbrains.annotations.Nullable;
5050
import org.maxgamer.quickshop.QuickShop;
51-
import org.maxgamer.quickshop.api.shop.AbstractDisplayItem;
52-
import org.maxgamer.quickshop.api.shop.Shop;
53-
import org.maxgamer.quickshop.api.shop.ShopInfoStorage;
54-
import org.maxgamer.quickshop.api.shop.ShopType;
51+
import org.maxgamer.quickshop.api.shop.*;
5552
import org.maxgamer.quickshop.event.*;
5653
import org.maxgamer.quickshop.api.chat.ComponentPackage;
57-
import org.maxgamer.quickshop.util.PriceLimiter;
5854
import org.maxgamer.quickshop.util.Util;
5955
import org.maxgamer.quickshop.util.logging.container.ShopRemoveLog;
6056

@@ -221,8 +217,8 @@ public UUID getTaxAccount() {
221217
if (taxAccount != null) {
222218
uuid = taxAccount;
223219
}else {
224-
if (plugin.getShopManager().getCacheTaxAccount() != null) {
225-
uuid = plugin.getShopManager().getCacheTaxAccount().getUniqueId();
220+
if (((JavaShopManager)plugin.getShopManager()).getCacheTaxAccount() != null) {
221+
uuid = ((JavaShopManager)plugin.getShopManager()).getCacheTaxAccount().getUniqueId();
226222
}
227223
}
228224
ShopTaxAccountGettingEvent event = new ShopTaxAccountGettingEvent(uuid,this);
@@ -246,7 +242,7 @@ public void setTaxAccount(@Nullable UUID taxAccount) {
246242

247243
private void initDisplayItem() {
248244
Util.ensureThread(false);
249-
if (plugin.isDisplay() && !isDisableDisplay()) {
245+
if (plugin.isDisplayEnabled() && !isDisableDisplay()) {
250246
switch (AbstractDisplayItem.getNowUsing()) {
251247
case REALITEM:
252248
this.displayItem = new RealDisplayItem(this);
@@ -379,7 +375,7 @@ public void buy(@NotNull UUID buyer, @NotNull Inventory buyerInventory,
379375
@Override
380376
public void checkDisplay() {
381377
Util.ensureThread(false);
382-
if (!plugin.isDisplay() || this.disableDisplay || !this.isLoaded || this.isDeleted()) { // FIXME: Reinit scheduler on reloading config
378+
if (!plugin.isDisplayEnabled() || this.disableDisplay || !this.isLoaded || this.isDeleted()) { // FIXME: Reinit scheduler on reloading config
383379
if (this.displayItem != null) {
384380
if (this.displayItem.isSpawned()) {
385381
this.displayItem.remove();
@@ -890,7 +886,7 @@ public void refresh() {
890886
displayItem.remove();
891887
}
892888

893-
if (plugin.isDisplay() && !isDisableDisplay()) {
889+
if (plugin.isDisplayEnabled() && !isDisableDisplay()) {
894890
if (displayItem != null) {
895891
displayItem.remove();
896892
}
@@ -940,14 +936,14 @@ public void onLoad() {
940936
plugin.getShopContainerWatcher().scheduleCheck(this);
941937

942938
// check price restriction
943-
PriceLimiter.CheckResult priceRestriction = plugin.getShopManager().getPriceLimiter().check(item, price);
939+
PriceLimiterCheckResult priceRestriction = plugin.getShopManager().getPriceLimiter().check(item, price);
944940
boolean markUpdate = false;
945-
if (priceRestriction.getStatus() != PriceLimiter.Status.PASS) {
946-
if (priceRestriction.getStatus() == PriceLimiter.Status.NOT_A_WHOLE_NUMBER) {
941+
if (priceRestriction.getStatus() != PriceLimiterStatus.PASS) {
942+
if (priceRestriction.getStatus() == PriceLimiterStatus.NOT_A_WHOLE_NUMBER) {
947943
setDirty();
948944
price = Math.floor(price);
949945
markUpdate = true;
950-
} else if (priceRestriction.getStatus() == PriceLimiter.Status.NOT_VALID) {
946+
} else if (priceRestriction.getStatus() == PriceLimiterStatus.NOT_VALID) {
951947
setDirty();
952948
price = priceRestriction.getMin();
953949
markUpdate = true;

0 commit comments

Comments
 (0)