From c7b5c8e8ce6ee170afbbd54ada173dcdbc09fd8a Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Sat, 2 Oct 2021 15:54:29 +0800 Subject: [PATCH] Closed #805, Impl the ability to toggle the display per shop --- .../quickshop/command/CommandManager.java | 5 ++ .../subcommand/SubCommand_ToggleDisplay.java | 73 +++++++++++++++++++ .../quickshop/shop/ContainerShop.java | 14 +++- .../resources/lang-original/messages.json | 7 +- src/main/resources/plugin.yml | 13 +++- 5 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_ToggleDisplay.java diff --git a/src/main/java/org/maxgamer/quickshop/command/CommandManager.java b/src/main/java/org/maxgamer/quickshop/command/CommandManager.java index 2c00c4490..e27135e7c 100644 --- a/src/main/java/org/maxgamer/quickshop/command/CommandManager.java +++ b/src/main/java/org/maxgamer/quickshop/command/CommandManager.java @@ -321,6 +321,11 @@ public class CommandManager implements TabCompleter, CommandExecutor { .permission("quickshop.taxaccount") .executor(new SubCommand_TaxAccount(plugin)) .build()); + registerCmd(CommandContainer.builder() + .prefix("toggledisplay") + .permission("quickshop.toggledisplay") + .executor(new SubCommand_ToggleDisplay(plugin)) + .build()); // registerCmd(CommandContainer.builder() // .prefix("backup") // .permission("quickshop.backup") diff --git a/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_ToggleDisplay.java b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_ToggleDisplay.java new file mode 100644 index 000000000..1515d979d --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_ToggleDisplay.java @@ -0,0 +1,73 @@ +/* + * This file is a part of project QuickShop, the name is SubCommand_Currency.java + * Copyright (C) PotatoCraft Studio and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.maxgamer.quickshop.command.subcommand; + +import lombok.AllArgsConstructor; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.util.BlockIterator; +import org.jetbrains.annotations.NotNull; +import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.command.CommandHandler; +import org.maxgamer.quickshop.shop.Shop; + +import java.util.Collections; +import java.util.List; + +@AllArgsConstructor +public class SubCommand_ToggleDisplay implements CommandHandler { + + private final QuickShop plugin; + + @Override + public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { + BlockIterator bIt = new BlockIterator(sender, 10); + + while (bIt.hasNext()) { + final Block b = bIt.next(); + final Shop shop = plugin.getShopManager().getShop(b.getLocation()); + + + if (shop != null) { + if (shop.getModerator().isModerator(sender.getUniqueId()) || QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.toggledisplay")) { + if(shop.isDisableDisplay()){ + shop.setDisableDisplay(false); + plugin.text().of(sender,"display-turn-on").send(); + }else{ + shop.setDisableDisplay(true); + plugin.text().of(sender,"display-turn-off").send(); + } + } else { + plugin.text().of(sender, "not-managed-shop").send(); + } + return; + } + } + plugin.text().of(sender, "not-looking-at-shop").send(); + } + + @NotNull + @Override + public List onTabComplete( + @NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) { + return Collections.emptyList(); + } + +} diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index 98e87a9b5..276a5e573 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -200,6 +200,7 @@ public class ContainerShop implements Shop { this.disableDisplay = disabled; setDirty(); update(); + checkDisplay(); } @Override @@ -221,7 +222,7 @@ public class ContainerShop implements Shop { private void initDisplayItem() { Util.ensureThread(false); - if (plugin.isDisplay()) { + if (plugin.isDisplay() && !isDisableDisplay()) { switch (DisplayItem.getNowUsing()) { case REALITEM: this.displayItem = new RealDisplayItem(this); @@ -354,8 +355,13 @@ public class ContainerShop implements Shop { @Override public void checkDisplay() { Util.ensureThread(false); - if (!plugin.isDisplay() || !this.isLoaded || this - .isDeleted()) { // FIXME: Reinit scheduler on reloading config + if (!plugin.isDisplay() || this.disableDisplay || !this.isLoaded || this.isDeleted()) { // FIXME: Reinit scheduler on reloading config + if(this.displayItem != null){ + if(this.displayItem.isSpawned()){ + this.displayItem.remove(); + } + this.displayItem = null; + } return; } @@ -527,9 +533,11 @@ public class ContainerShop implements Shop { } if (inventoryPreview != null) { inventoryPreview.close(); + inventoryPreview = null; } if (this.displayItem != null) { this.displayItem.remove(); + this.displayItem = null; } update(); this.isLoaded = false; diff --git a/src/main/resources/lang-original/messages.json b/src/main/resources/lang-original/messages.json index dd6293b83..dbcf7ffe6 100644 --- a/src/main/resources/lang-original/messages.json +++ b/src/main/resources/lang-original/messages.json @@ -177,7 +177,8 @@ "unban": "&eUnbans a player from the shop", "freeze": "&eDisable or Enable shop trading", "lock": "&eSwitch the shop's lock status", - "taxaccount": "&eSet the tax account that shop using" + "taxaccount": "&eSet the tax account that shop using", + "toggledisplay": "&eToggle the shop display item status" }, "disabled": "&cThis command is disabled: &e{0}", "feature-not-enabled": "This feature is not enabled in the config file." @@ -337,5 +338,7 @@ "client-language-unsupported": "&eQuickShop doesn't support your client language, we're fallback to {0} locale now.", "taxaccount-set": "&aThis shop's tax account has been set to &e{0}", "taxaccount-unset": "&aThis shop's tax account now following server global setting.", - "taxaccount-invalid": "&cTarget account not invalid, please enter a valid player name or uuid(with dashes)." + "taxaccount-invalid": "&cTarget account not invalid, please enter a valid player name or uuid(with dashes).", + "display-turn-on": "&aSuccessfully turn on the shop display.", + "display-turn-off": "&aSuccessfully turn off the shop display." } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7daf415e3..83664a326 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -63,6 +63,7 @@ permissions: quickshop.preview: true quickshop.currency: true quickshop.taxaccount: true + quickshop.toggledisplay: true quickshop.moderator: description: The permission that provide all moderator need have permissions default: op @@ -76,6 +77,9 @@ permissions: quickshop.other.changeitem: true quickshop.other.changeamount: true quickshop.other.staff: true + quickshop.other.currency: true + quickshop.other.taxaccount: true + quickshop.other.toggledisplay: true quickshop.create.sell: description: Allows a player to sell from a shop. default: op @@ -212,6 +216,11 @@ permissions: description: Permission to use /qs taxaccount default: op quickshop.other.taxaccount: - description: Permission to use /qs taxaccount + description: Permission to use /qs taxaccount on others shops + default: op + quickshop.toggledisplay: + description: Permission to use /qs toggledisplay + default: op + quickshop.other.toggledisplay: + description: Permission to use /qs toggledisplay on others shops default: op -