Skip to content

Commit c7b5c8e

Browse files
committed
Closed Ghost-chu#805, Impl the ability to toggle the display per shop
1 parent 5866103 commit c7b5c8e

File tree

5 files changed

+105
-7
lines changed

5 files changed

+105
-7
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
@@ -321,6 +321,11 @@ public CommandManager(QuickShop plugin) {
321321
.permission("quickshop.taxaccount")
322322
.executor(new SubCommand_TaxAccount(plugin))
323323
.build());
324+
registerCmd(CommandContainer.builder()
325+
.prefix("toggledisplay")
326+
.permission("quickshop.toggledisplay")
327+
.executor(new SubCommand_ToggleDisplay(plugin))
328+
.build());
324329
// registerCmd(CommandContainer.builder()
325330
// .prefix("backup")
326331
// .permission("quickshop.backup")
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.block.Block;
24+
import org.bukkit.entity.Player;
25+
import org.bukkit.util.BlockIterator;
26+
import org.jetbrains.annotations.NotNull;
27+
import org.maxgamer.quickshop.QuickShop;
28+
import org.maxgamer.quickshop.command.CommandHandler;
29+
import org.maxgamer.quickshop.shop.Shop;
30+
31+
import java.util.Collections;
32+
import java.util.List;
33+
34+
@AllArgsConstructor
35+
public class SubCommand_ToggleDisplay implements CommandHandler<Player> {
36+
37+
private final QuickShop plugin;
38+
39+
@Override
40+
public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
41+
BlockIterator bIt = new BlockIterator(sender, 10);
42+
43+
while (bIt.hasNext()) {
44+
final Block b = bIt.next();
45+
final Shop shop = plugin.getShopManager().getShop(b.getLocation());
46+
47+
48+
if (shop != null) {
49+
if (shop.getModerator().isModerator(sender.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.toggledisplay")) {
50+
if(shop.isDisableDisplay()){
51+
shop.setDisableDisplay(false);
52+
plugin.text().of(sender,"display-turn-on").send();
53+
}else{
54+
shop.setDisableDisplay(true);
55+
plugin.text().of(sender,"display-turn-off").send();
56+
}
57+
} else {
58+
plugin.text().of(sender, "not-managed-shop").send();
59+
}
60+
return;
61+
}
62+
}
63+
plugin.text().of(sender, "not-looking-at-shop").send();
64+
}
65+
66+
@NotNull
67+
@Override
68+
public List<String> onTabComplete(
69+
@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
70+
return Collections.emptyList();
71+
}
72+
73+
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public void setDisableDisplay(boolean disabled) {
200200
this.disableDisplay = disabled;
201201
setDirty();
202202
update();
203+
checkDisplay();
203204
}
204205

205206
@Override
@@ -221,7 +222,7 @@ public void setTaxAccount(@Nullable UUID taxAccount) {
221222

222223
private void initDisplayItem() {
223224
Util.ensureThread(false);
224-
if (plugin.isDisplay()) {
225+
if (plugin.isDisplay() && !isDisableDisplay()) {
225226
switch (DisplayItem.getNowUsing()) {
226227
case REALITEM:
227228
this.displayItem = new RealDisplayItem(this);
@@ -354,8 +355,13 @@ public void buy(@NotNull UUID buyer, @NotNull Inventory buyerInventory,
354355
@Override
355356
public void checkDisplay() {
356357
Util.ensureThread(false);
357-
if (!plugin.isDisplay() || !this.isLoaded || this
358-
.isDeleted()) { // FIXME: Reinit scheduler on reloading config
358+
if (!plugin.isDisplay() || this.disableDisplay || !this.isLoaded || this.isDeleted()) { // FIXME: Reinit scheduler on reloading config
359+
if(this.displayItem != null){
360+
if(this.displayItem.isSpawned()){
361+
this.displayItem.remove();
362+
}
363+
this.displayItem = null;
364+
}
359365
return;
360366
}
361367

@@ -527,9 +533,11 @@ public void onUnload() {
527533
}
528534
if (inventoryPreview != null) {
529535
inventoryPreview.close();
536+
inventoryPreview = null;
530537
}
531538
if (this.displayItem != null) {
532539
this.displayItem.remove();
540+
this.displayItem = null;
533541
}
534542
update();
535543
this.isLoaded = false;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@
177177
"unban": "&eUnbans a player from the shop",
178178
"freeze": "&eDisable or Enable shop trading",
179179
"lock": "&eSwitch the shop's lock status",
180-
"taxaccount": "&eSet the tax account that shop using"
180+
"taxaccount": "&eSet the tax account that shop using",
181+
"toggledisplay": "&eToggle the shop display item status"
181182
},
182183
"disabled": "&cThis command is disabled: &e{0}",
183184
"feature-not-enabled": "This feature is not enabled in the config file."
@@ -337,5 +338,7 @@
337338
"client-language-unsupported": "&eQuickShop doesn't support your client language, we're fallback to {0} locale now.",
338339
"taxaccount-set": "&aThis shop's tax account has been set to &e{0}",
339340
"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)."
341+
"taxaccount-invalid": "&cTarget account not invalid, please enter a valid player name or uuid(with dashes).",
342+
"display-turn-on": "&aSuccessfully turn on the shop display.",
343+
"display-turn-off": "&aSuccessfully turn off the shop display."
341344
}

src/main/resources/plugin.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ permissions:
6363
quickshop.preview: true
6464
quickshop.currency: true
6565
quickshop.taxaccount: true
66+
quickshop.toggledisplay: true
6667
quickshop.moderator:
6768
description: The permission that provide all moderator need have permissions
6869
default: op
@@ -76,6 +77,9 @@ permissions:
7677
quickshop.other.changeitem: true
7778
quickshop.other.changeamount: true
7879
quickshop.other.staff: true
80+
quickshop.other.currency: true
81+
quickshop.other.taxaccount: true
82+
quickshop.other.toggledisplay: true
7983
quickshop.create.sell:
8084
description: Allows a player to sell from a shop.
8185
default: op
@@ -212,6 +216,11 @@ permissions:
212216
description: Permission to use /qs taxaccount
213217
default: op
214218
quickshop.other.taxaccount:
215-
description: Permission to use /qs taxaccount
219+
description: Permission to use /qs taxaccount on others shops
220+
default: op
221+
quickshop.toggledisplay:
222+
description: Permission to use /qs toggledisplay
223+
default: op
224+
quickshop.other.toggledisplay:
225+
description: Permission to use /qs toggledisplay on others shops
216226
default: op
217-

0 commit comments

Comments
 (0)