Skip to content

Commit 5866103

Browse files
committed
Closed PotatoCraft-Studio#518, Impl per shop tax account
1 parent 9565468 commit 5866103

File tree

8 files changed

+153
-8
lines changed

8 files changed

+153
-8
lines changed

src/main/java/org/maxgamer/quickshop/command/CommandManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ public CommandManager(QuickShop plugin) {
316316
.permission("quickshop.currency")
317317
.executor(new SubCommand_Currency(plugin))
318318
.build());
319+
registerCmd(CommandContainer.builder()
320+
.prefix("taxaccount")
321+
.permission("quickshop.taxaccount")
322+
.executor(new SubCommand_TaxAccount(plugin))
323+
.build());
319324
// registerCmd(CommandContainer.builder()
320325
// .prefix("backup")
321326
// .permission("quickshop.backup")
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is SubCommand_Currency.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.command.subcommand;
21+
22+
import lombok.AllArgsConstructor;
23+
import org.bukkit.Bukkit;
24+
import org.bukkit.block.Block;
25+
import org.bukkit.entity.Player;
26+
import org.bukkit.util.BlockIterator;
27+
import org.jetbrains.annotations.NotNull;
28+
import org.maxgamer.quickshop.QuickShop;
29+
import org.maxgamer.quickshop.command.CommandHandler;
30+
import org.maxgamer.quickshop.shop.Shop;
31+
import org.maxgamer.quickshop.util.Util;
32+
33+
import java.util.Collections;
34+
import java.util.List;
35+
import java.util.UUID;
36+
37+
@AllArgsConstructor
38+
public class SubCommand_TaxAccount implements CommandHandler<Player> {
39+
40+
private final QuickShop plugin;
41+
42+
@Override
43+
public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
44+
BlockIterator bIt = new BlockIterator(sender, 10);
45+
46+
while (bIt.hasNext()) {
47+
final Block b = bIt.next();
48+
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
49+
50+
51+
if (shop != null) {
52+
if (shop.getModerator().isModerator(sender.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.taxaccount")) {
53+
if (cmdArg.length < 1) {
54+
shop.setTaxAccount(null);
55+
plugin.text().of(sender, "taxaccount-unset").send();
56+
return;
57+
}
58+
if(Util.isUUID(cmdArg[0]))
59+
shop.setTaxAccount(UUID.fromString(cmdArg[0]));
60+
else
61+
shop.setTaxAccount(Bukkit.getOfflinePlayer(cmdArg[0]).getUniqueId());
62+
plugin.text().of(sender, "taxaccount-unset", cmdArg[0]).send();
63+
return;
64+
} else {
65+
plugin.text().of(sender, "not-managed-shop").send();
66+
}
67+
return;
68+
}
69+
}
70+
plugin.text().of(sender, "not-looking-at-shop").send();
71+
}
72+
73+
@NotNull
74+
@Override
75+
public List<String> onTabComplete(
76+
@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
77+
return Collections.emptyList();
78+
}
79+
80+
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private ContainerShop(@NotNull ContainerShop s) {
116116
this.inventoryPreview = null;
117117
this.currency = s.currency;
118118
this.disableDisplay = s.disableDisplay;
119+
this.taxAccount = s.taxAccount;
119120
initDisplayItem();
120121
}
121122

@@ -143,7 +144,8 @@ public ContainerShop(
143144
@NotNull ShopType type,
144145
@NotNull YamlConfiguration extra,
145146
@Nullable String currency,
146-
@NotNull boolean disableDisplay) {
147+
boolean disableDisplay,
148+
@Nullable UUID taxAccount) {
147149
Util.ensureThread(false);
148150
this.location = location;
149151
this.price = price;
@@ -171,6 +173,7 @@ public ContainerShop(
171173
this.extra = extra;
172174
this.currency = currency;
173175
this.disableDisplay = disableDisplay;
176+
this.taxAccount = taxAccount;
174177
initDisplayItem();
175178
this.dirty = false;
176179
updateShopData();
@@ -181,6 +184,7 @@ private void updateShopData() {
181184
if (section.getString("currency") != null) {
182185
this.currency = section.getString("currency");
183186
section.set("currency", null);
187+
Util.debugLog("Shop "+this+" currency data upgrade successful.");
184188
}
185189
setExtra(plugin, section);
186190
setDirty();
@@ -191,6 +195,13 @@ public boolean isDisableDisplay() {
191195
return disableDisplay;
192196
}
193197

198+
@Override
199+
public void setDisableDisplay(boolean disabled) {
200+
this.disableDisplay = disabled;
201+
setDirty();
202+
update();
203+
}
204+
194205
@Override
195206
@Nullable
196207
public UUID getTaxAccount() {
@@ -201,6 +212,13 @@ public UUID getTaxAccount() {
201212
return null;
202213
}
203214

215+
@Override
216+
public void setTaxAccount(@Nullable UUID taxAccount) {
217+
this.taxAccount = taxAccount;
218+
setDirty();
219+
update();
220+
}
221+
204222
private void initDisplayItem() {
205223
Util.ensureThread(false);
206224
if (plugin.isDisplay()) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,25 @@ default String[] getSignText() {
501501
*/
502502
boolean isDisableDisplay();
503503

504+
/**
505+
* Set the display disable state
506+
* @param disabled Has been disabled
507+
*/
508+
void setDisableDisplay(boolean disabled);
509+
504510
/**
505511
* Getting the shop tax account, it can be specific uuid or general tax account
506512
* @return Shop Tax Account, null if use general tax account
507513
*/
508514
@Nullable
509515
UUID getTaxAccount();
510516

517+
/**
518+
* Sets shop taxAccount
519+
* @param taxAccount tax account, null to use general tax account
520+
*/
521+
void setTaxAccount(@Nullable UUID taxAccount);
522+
523+
511524

512525
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,17 @@ public void actionBuy(
682682
} else {
683683
total = e.getTotal(); // Allow addon to set it
684684
}
685+
Trader taxAccount;
686+
if(shop.getTaxAccount() != null)
687+
taxAccount = new Trader(shop.getTaxAccount().toString(), Bukkit.getOfflinePlayer(shop.getTaxAccount()));
688+
else
689+
taxAccount = this.cacheTaxAccount;
685690
EconomyTransaction transaction;
686691
EconomyTransaction.EconomyTransactionBuilder builder = EconomyTransaction.builder()
687692
.core(eco)
688693
.amount(total)
689694
.taxModifier(taxModifier)
690-
.taxAccount(cacheTaxAccount)
695+
.taxAccount(taxAccount)
691696
.currency(shop.getCurrency())
692697
.world(shop.getLocation().getWorld())
693698
.to(buyer);
@@ -916,7 +921,10 @@ public void actionCreate(@NotNull Player p, @NotNull Info info, @NotNull String
916921
new ShopModerator(p.getUniqueId()),
917922
false,
918923
ShopType.SELLING,
919-
new YamlConfiguration());
924+
new YamlConfiguration(),
925+
null,
926+
false,
927+
null);
920928
if (!bypassProtectionChecks) {
921929
Result result = plugin.getIntegrationHelper()
922930
.callIntegrationsCanCreate(p, info.getLocation());
@@ -1043,13 +1051,18 @@ public void actionSell(
10431051
// Money handling
10441052
// SELLING Player -> Shop Owner
10451053
EconomyTransaction transaction;
1054+
Trader taxAccount;
1055+
if(shop.getTaxAccount() != null)
1056+
taxAccount = new Trader(shop.getTaxAccount().toString(), Bukkit.getOfflinePlayer(shop.getTaxAccount()));
1057+
else
1058+
taxAccount = this.cacheTaxAccount;
10461059
EconomyTransaction.EconomyTransactionBuilder builder = EconomyTransaction.builder()
10471060
.allowLoan(plugin.getConfig().getBoolean("shop.allow-economy-loan", false))
10481061
.core(eco)
10491062
.from(seller)
10501063
.amount(total)
10511064
.taxModifier(taxModifier)
1052-
.taxAccount(cacheTaxAccount)
1065+
.taxAccount(taxAccount)
10531066
.world(shop.getLocation().getWorld())
10541067
.currency(shop.getCurrency());
10551068
if (!shop.isUnlimited()

src/main/java/org/maxgamer/quickshop/watcher/OngoingFeeWatcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.maxgamer.quickshop.watcher;
2121

22+
import org.bukkit.Bukkit;
2223
import org.bukkit.Location;
2324
import org.bukkit.World;
2425
import org.bukkit.scheduler.BukkitRunnable;
@@ -68,14 +69,18 @@ public void run() {
6869
World world = location.getWorld();
6970
//We must check balance manually to avoid shop missing hell when tax account broken
7071
if (allowLoan || plugin.getEconomy().getBalance(shopOwner, Objects.requireNonNull(world), shop.getCurrency()) >= cost) {
71-
Trader trader = plugin.getShopManager().getCacheTaxAccount();
72+
Trader taxAccount;
73+
if(shop.getTaxAccount() != null)
74+
taxAccount = new Trader(shop.getTaxAccount().toString(), Bukkit.getOfflinePlayer(shop.getTaxAccount()));
75+
else
76+
taxAccount = plugin.getShopManager().getCacheTaxAccount();
7277
Util.mainThreadRun(() -> {
7378
EconomyTransaction transaction = EconomyTransaction.builder()
7479
.allowLoan(allowLoan)
7580
.currency(shop.getCurrency())
7681
.core(plugin.getEconomy())
7782
.world(world)
78-
.to(trader == null ? null : trader.getUniqueId())
83+
.to(taxAccount == null ? null : taxAccount.getUniqueId())
7984
.from(shopOwner).build();
8085

8186
boolean success = transaction.failSafeCommit();

src/main/resources/lang-original/messages.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@
176176
"ban": "&eBans a player from the shop",
177177
"unban": "&eUnbans a player from the shop",
178178
"freeze": "&eDisable or Enable shop trading",
179-
"lock": "&eSwitch the shop's lock status"
179+
"lock": "&eSwitch the shop's lock status",
180+
"taxaccount": "&eSet the tax account that shop using"
180181
},
181182
"disabled": "&cThis command is disabled: &e{0}",
182183
"feature-not-enabled": "This feature is not enabled in the config file."
@@ -333,5 +334,8 @@
333334
"scheduled": "&aReload completed. &7(Some changes required a while to affect)"
334335
},
335336
"client-language-changed": "&aQuickShop detected your client language setting has been changed, we're now using {0} locale for you.",
336-
"client-language-unsupported": "&eQuickShop doesn't support your client language, we're fallback to {0} locale now."
337+
"client-language-unsupported": "&eQuickShop doesn't support your client language, we're fallback to {0} locale now.",
338+
"taxaccount-set": "&aThis shop's tax account has been set to &e{0}",
339+
"taxaccount-unset": "&aThis shop's tax account now following server global setting.",
340+
"taxaccount-invalid": "&cTarget account not invalid, please enter a valid player name or uuid(with dashes)."
337341
}

src/main/resources/plugin.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ permissions:
6262
quickshop.staff: true
6363
quickshop.preview: true
6464
quickshop.currency: true
65+
quickshop.taxaccount: true
6566
quickshop.moderator:
6667
description: The permission that provide all moderator need have permissions
6768
default: op
@@ -207,4 +208,10 @@ permissions:
207208
quickshop.showdisabled:
208209
description: Permission to see disabled commands in help list.
209210
default: op
211+
quickshop.taxaccount:
212+
description: Permission to use /qs taxaccount
213+
default: op
214+
quickshop.other.taxaccount:
215+
description: Permission to use /qs taxaccount
216+
default: op
210217

0 commit comments

Comments
 (0)