Added command "/shop removeall <player>"

- Needs permission "shopchest.remove.other"

Closes #101
This commit is contained in:
Eric 2017-05-25 14:06:03 +02:00
parent 4dde2d9f53
commit 5589ab6655
6 changed files with 115 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -22,6 +23,8 @@ import org.bukkit.plugin.Plugin;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
class ShopCommand implements CommandExecutor {
@ -170,6 +173,16 @@ class ShopCommand implements CommandExecutor {
needsHelp = false;
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG));
}
} else if (args[0].equalsIgnoreCase("removeall")) {
if (sender.hasPermission(Permissions.REMOVE_OTHER)) {
if (args.length >= 2) {
needsHelp = false;
removeAll(sender, args);
}
} else {
needsHelp = false;
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS));
}
}
}
@ -503,6 +516,35 @@ class ShopCommand implements CommandExecutor {
ClickType.setPlayerClickType(p, new ClickType(EnumClickType.OPEN));
}
private void removeAll(CommandSender sender, String[] args) {
OfflinePlayer vendor = Bukkit.getOfflinePlayer(args[1]);
plugin.debug(sender.getName() + " is removing all shops of " + vendor.getName());
List<Shop> shops = new ArrayList<>();
for (Shop shop : shopUtils.getShops()) {
if (shop.getVendor().getUniqueId().equals(vendor.getUniqueId())) {
shops.add(shop);
}
}
ShopRemoveAllEvent event = new ShopRemoveAllEvent(sender, vendor, shops);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()){
plugin.debug("Remove all event cancelled");
return;
}
for (Shop shop : shops) {
shopUtils.removeShop(shop, true);
}
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ALL_SHOPS_REMOVED,
new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(shops.size())),
new LocalizedMessage.ReplacedRegex(Placeholder.VENDOR, vendor.getName())));
}
/**
* Sends the basic help message
* @param sender {@link CommandSender} who will receive the message
@ -534,6 +576,10 @@ class ShopCommand implements CommandExecutor {
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " open - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_OPEN));
}
if (sender.hasPermission(Permissions.REMOVE_OTHER)) {
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " removeall <player> - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVEALL));
}
if (sender.hasPermission(Permissions.RELOAD)) {
sender.sendMessage(ChatColor.GREEN + "/" + plugin.getShopChestConfig().main_command_name + " reload - " + LanguageUtils.getMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD));
}

View File

@ -0,0 +1,56 @@
package de.epiceric.shopchest.event;
import de.epiceric.shopchest.shop.Shop;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import java.util.List;
public class ShopRemoveAllEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private CommandSender sender;
private OfflinePlayer vendor;
private List<Shop> shops;
private boolean cancelled;
public ShopRemoveAllEvent(CommandSender sender, OfflinePlayer vendor, List<Shop> shops) {
this.sender = sender;
this.vendor = vendor;
this.shops = shops;
}
public CommandSender getSender() {
return sender;
}
public OfflinePlayer getVendor() {
return vendor;
}
public List<Shop> getShops() {
return shops;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1002,6 +1002,7 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_BLOCKED, langConfig.getString("message.chest-blocked", "&cThere must not be a block above the chest.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.DOUBLE_CHEST_BLOCKED, langConfig.getString("message.double-chest-blocked", "&cThere must not be a block above the chest.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_REMOVED, langConfig.getString("message.shop-removed", "&6Shop removed.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.ALL_SHOPS_REMOVED, langConfig.getString("message.all-shops-removed", "&6Removed all (&c%AMOUNT%&6) shop/s of &c%VENDOR%&6."), Placeholder.AMOUNT, Placeholder.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_NO_SHOP, langConfig.getString("message.chest-no-shop", "&cChest is not a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, langConfig.getString("message.shop-create-not-enough-money", "&cNot enough money. You need &6%CREATION-PRICE% &cto create a shop."), Placeholder.CREATION_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR, langConfig.getString("message.shopInfo.vendor", "&6Vendor: &e%VENDOR%"), Placeholder.VENDOR));
@ -1078,6 +1079,7 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVEALL, langConfig.getString("message.commandDescription.removeall", "Remove all shops of a player.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_RELOAD, langConfig.getString("message.commandDescription.reload", "Reload shops.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_UPDATE, langConfig.getString("message.commandDescription.update", "Check for Updates.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits.")));

View File

@ -47,6 +47,7 @@ public class LocalizedMessage {
CHEST_BLOCKED,
DOUBLE_CHEST_BLOCKED,
SHOP_REMOVED,
ALL_SHOPS_REMOVED,
CHEST_NO_SHOP,
SHOP_CREATE_NOT_ENOUGH_MONEY,
SHOP_INFO_VENDOR,
@ -123,6 +124,7 @@ public class LocalizedMessage {
COMMAND_DESC_CREATE,
COMMAND_DESC_REMOVE,
COMMAND_DESC_INFO,
COMMAND_DESC_REMOVEALL,
COMMAND_DESC_RELOAD,
COMMAND_DESC_UPDATE,
COMMAND_DESC_LIMITS,

View File

@ -3,6 +3,7 @@ message.chest-already-shop=&cTruhe ist bereits ein Shop.
message.chest-blocked=&cÜber der Truhe ist kein Platz.
message.double-chest-blocked=&cÜber der Truhe ist kein Platz.
message.shop-removed=&6Shop entfernt.
message.all-shops-removed=&6Alle (&c%AMOUNT%&6) Shop/s von &c%VENDOR%&6 wurden entfernt.
message.chest-no-shop=&cTruhe ist kein Shop.
message.shop-create-not-enough-money=&cNicht genug Geld. Du brauchst &6%CREATION-PRICE% &cum einen Shop zu erstellen.
message.shopInfo.vendor=&6Verkäufer: &e%VENDOR%
@ -79,6 +80,7 @@ message.noPermission.extend-protected=&cDu hast keine Berechtigung diesen Shop n
message.commandDescription.create=Erstelle einen Shop.
message.commandDescription.remove=Entferne einen Shop.
message.commandDescription.info=Rufe Informationen über den Shop ab.
message.commandDescription.removeall=Entferne alle Shops eines Spielers.
message.commandDescription.reload=Lade die Shops neu.
message.commandDescription.update=Suche nach Aktualisierungen.
message.commandDescription.limits=Betrachte die Shop Limits.

View File

@ -14,6 +14,10 @@ message.double-chest-blocked=&cThere must not be a block above the chest.
# Set the message when the clicked shop is removed.
message.shop-removed=&6Shop removed.
# Set the message when all shops of a player were removed.
# Usable Placeholders: %AMOUNT%, %VENDOR%
message.all-shops-removed=&6Removed all (&c%AMOUNT%&6) shop/s of &c%VENDOR%&6.
# Set the message when the clicked chest is not a shop.
message.chest-no-shop=&cChest is not a shop.
@ -272,6 +276,9 @@ message.commandDescription.remove=Remove a shop.
# Set the command description message for '/shop info' when you type '/shop'.
message.commandDescription.info=Retrieve shop information.
# Set the command description message for '/shop removeall' when you type '/shop'.
message.commandDescription.removeall=Remove all shops of a player.
# Set the command description message for '/shop reload' when you type '/shop'.
message.commandDescription.reload=Reload shops.