Skip to content

Commit cf77564

Browse files
committed
Move some methods into ShopManager, exact EconomyFormatter
1 parent e962016 commit cf77564

File tree

10 files changed

+462
-132
lines changed

10 files changed

+462
-132
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is Unstable.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package org.maxgamer.quickshop.api.annotations;
21+
22+
import java.lang.annotation.*;
23+
24+
/**
25+
* The annotation that marks the unstable apis (maybe removed/changed in future)
26+
*/
27+
@Documented
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
30+
@Inherited
31+
@Deprecated
32+
public @interface Unstable {
33+
}

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is ShopManager.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.api.shop;
221

322
import org.bukkit.Chunk;
@@ -8,12 +27,14 @@
827
import org.bukkit.entity.Player;
928
import org.jetbrains.annotations.NotNull;
1029
import org.jetbrains.annotations.Nullable;
30+
import org.maxgamer.quickshop.api.annotations.Unstable;
1131

1232
import java.util.*;
1333

1434
/**
1535
* The manager that managing shops
1636
*/
37+
@SuppressWarnings("ALL")
1738
public interface ShopManager {
1839

1940
/**
@@ -77,11 +98,22 @@ public interface ShopManager {
7798
/**
7899
* Format the price use economy system
79100
*
80-
* @param d price
101+
* @param d price
102+
* @param currency currency
103+
* @param world shop world
81104
* @return formated price
82105
*/
83106
@Nullable String format(double d, @NotNull World world, @Nullable String currency);
84107

108+
/**
109+
* Format the price use economy system
110+
*
111+
* @param d price
112+
* @param shop The shop
113+
* @return formated price
114+
*/
115+
@Nullable String format(double d, @NotNull Shop shop);
116+
85117
/**
86118
* Gets a shop in a specific location
87119
*
@@ -206,7 +238,39 @@ public interface ShopManager {
206238

207239
/**
208240
* Getting the Shop Price Limiter
241+
*
209242
* @return The shop price limiter
210243
*/
244+
@NotNull
211245
PriceLimiter getPriceLimiter();
246+
247+
/**
248+
* Send a purchaseSuccess message for a player.
249+
*
250+
* @param purchaser Target player
251+
* @param shop Target shop
252+
* @param amount Trading item amounts.
253+
*/
254+
@Unstable
255+
void sendPurchaseSuccess(@NotNull UUID purchaser, @NotNull Shop shop, int amount);
256+
257+
/**
258+
* Send a sellSuccess message for a player.
259+
*
260+
* @param seller Target player
261+
* @param shop Target shop
262+
* @param amount Trading item amounts.
263+
*/
264+
@Unstable
265+
void sendSellSuccess(@NotNull UUID seller, @NotNull Shop shop, int amount);
266+
267+
/**
268+
* Send a shop infomation to a player.
269+
*
270+
* @param p Target player
271+
* @param shop The shop
272+
*/
273+
@Unstable
274+
void sendShopInfo(@NotNull Player p, @NotNull Shop shop) ;
275+
212276
}

src/main/java/org/maxgamer/quickshop/economy/Economy_GemsEconomy.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.jetbrains.annotations.Nullable;
3232
import org.maxgamer.quickshop.QuickShop;
3333
import org.maxgamer.quickshop.api.economy.AbstractEconomy;
34-
import org.maxgamer.quickshop.util.Util;
34+
import org.maxgamer.quickshop.util.economyformatter.BuiltInEconomyFormatter;
3535
import org.maxgamer.quickshop.util.reload.ReloadResult;
3636
import org.maxgamer.quickshop.util.reload.ReloadStatus;
3737

@@ -46,10 +46,12 @@ public class Economy_GemsEconomy extends AbstractEconomy {
4646
@Getter
4747
@Setter
4848
private GemsEconomyAPI api;
49+
private final BuiltInEconomyFormatter formatter;
4950

5051
public Economy_GemsEconomy(@NotNull QuickShop plugin) {
5152
super();
5253
this.plugin = plugin;
54+
this.formatter = new BuiltInEconomyFormatter(plugin);
5355
plugin.getReloadManager().register(this);
5456
init();
5557
setupEconomy();
@@ -125,7 +127,7 @@ private String formatInternal(double balance, @NotNull World world, @Nullable St
125127
return "Error";
126128
}
127129

128-
return Util.format(balance, true, world, currency);
130+
return this.formatter.getInternalFormat(balance, currency);
129131
}
130132

131133
/**

src/main/java/org/maxgamer/quickshop/economy/Economy_Vault.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.maxgamer.quickshop.QuickShop;
3737
import org.maxgamer.quickshop.api.economy.AbstractEconomy;
3838
import org.maxgamer.quickshop.util.Util;
39+
import org.maxgamer.quickshop.util.economyformatter.BuiltInEconomyFormatter;
3940
import org.maxgamer.quickshop.util.reload.ReloadResult;
4041
import org.maxgamer.quickshop.util.reload.ReloadStatus;
4142

@@ -54,11 +55,13 @@ public class Economy_Vault extends AbstractEconomy implements Listener {
5455
@Setter
5556
@Nullable
5657
private net.milkbowl.vault.economy.Economy vault;
58+
private final BuiltInEconomyFormatter formatter;
5759

5860

5961
public Economy_Vault(@NotNull QuickShop plugin) {
6062
super();
6163
this.plugin = plugin;
64+
this.formatter = new BuiltInEconomyFormatter(plugin);
6265
plugin.getReloadManager().register(this);
6366
init();
6467
setupEconomy();
@@ -170,7 +173,7 @@ private String formatInternal(double balance) {
170173
return "Error";
171174
}
172175

173-
return Util.format(balance, true, plugin.getServer().getWorlds().get(0), (String) null);
176+
return this.formatter.getInternalFormat(balance, null);
174177
}
175178

176179
@Override

src/main/java/org/maxgamer/quickshop/listener/PlayerListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void postTrade(PlayerInteractEvent e) {
187187
shop.onClick();
188188
this.playClickSound(e.getPlayer());
189189
// Text menu
190-
MsgUtil.sendShopInfo(p, shop);
190+
plugin.getShopManager().sendShopInfo(p, shop);
191191
shop.setSignText();
192192

193193
final AbstractEconomy eco = plugin.getEconomy();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,10 @@ public List<ComponentPackage> getSignText(@NotNull String locale) {
753753
String line4;
754754
if (this.isStackingShop()) {
755755
line4 = plugin.text().of("signs.stack-price",
756-
Util.format(this.getPrice(), this), Integer.toString(item.getAmount()),
756+
plugin.getShopManager().format(this.getPrice(), this), Integer.toString(item.getAmount()),
757757
Util.getItemStackName(item)).forLocale();
758758
} else {
759-
line4 = plugin.text().of("signs.price", Util.format(this.getPrice(), this)).forLocale();
759+
line4 = plugin.text().of("signs.price", plugin.getShopManager().format(this.getPrice(), this)).forLocale();
760760
}
761761
lines.add(new ComponentPackage(TextComponent.fromLegacyText(line4)));
762762
return lines;

0 commit comments

Comments
 (0)