From c4e7e5a8abf0e0746018f63fc9f413a8dadd35a5 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 5 Jun 2017 14:20:00 +0200 Subject: [PATCH] Added auto removal of click type after 15 seconds --- .../de/epiceric/shopchest/ShopCommand.java | 41 +++++++++++++++++-- .../shopchest/language/LanguageUtils.java | 8 ++-- src/main/resources/lang/de_DE.lang | 8 ++-- src/main/resources/lang/en_US.lang | 8 ++-- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/ShopCommand.java b/src/main/java/de/epiceric/shopchest/ShopCommand.java index eedb743..a8df220 100644 --- a/src/main/java/de/epiceric/shopchest/ShopCommand.java +++ b/src/main/java/de/epiceric/shopchest/ShopCommand.java @@ -34,6 +34,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -290,7 +291,7 @@ class ShopCommand implements CommandExecutor { * @param shopType The {@link ShopType}, the shop will have * @param p The command executor */ - private void create(String[] args, ShopType shopType, Player p) { + private void create(String[] args, ShopType shopType, final Player p) { plugin.debug(p.getName() + " wants to create a shop"); int amount; @@ -470,6 +471,14 @@ class ShopCommand implements CommandExecutor { ClickType.setPlayerClickType(p, new ClickType(EnumClickType.CREATE, product, buyPrice, sellPrice, shopType)); plugin.debug(p.getName() + " can now click a chest"); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE)); + + // Remove ClickType after 15 seconds if player has not clicked a chest + new BukkitRunnable() { + @Override + public void run() { + ClickType.removePlayerClickType(p); + } + }.runTaskLater(plugin, 300); } else { plugin.debug("Shop pre create event cancelled"); } @@ -479,7 +488,7 @@ class ShopCommand implements CommandExecutor { * A given player removes a shop * @param p The command executor */ - private void remove(Player p) { + private void remove(final Player p) { plugin.debug(p.getName() + " wants to remove a shop"); ShopPreRemoveEvent event = new ShopPreRemoveEvent(p); @@ -492,13 +501,21 @@ class ShopCommand implements CommandExecutor { plugin.debug(p.getName() + " can now click a chest"); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE)); ClickType.setPlayerClickType(p, new ClickType(EnumClickType.REMOVE)); + + // Remove ClickType after 15 seconds if player has not clicked a chest + new BukkitRunnable() { + @Override + public void run() { + ClickType.removePlayerClickType(p); + } + }.runTaskLater(plugin, 300); } /** * A given player retrieves information about a shop * @param p The command executor */ - private void info(Player p) { + private void info(final Player p) { plugin.debug(p.getName() + " wants to retrieve information"); ShopPreInfoEvent event = new ShopPreInfoEvent(p); @@ -511,13 +528,21 @@ class ShopCommand implements CommandExecutor { plugin.debug(p.getName() + " can now click a chest"); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_INFO)); ClickType.setPlayerClickType(p, new ClickType(EnumClickType.INFO)); + + // Remove ClickType after 15 seconds if player has not clicked a chest + new BukkitRunnable() { + @Override + public void run() { + ClickType.removePlayerClickType(p); + } + }.runTaskLater(plugin, 300); } /** * A given player opens a shop * @param p The command executor */ - private void open(Player p) { + private void open(final Player p) { plugin.debug(p.getName() + " wants to open a shop"); ShopPreOpenEvent event = new ShopPreOpenEvent(p); @@ -530,6 +555,14 @@ class ShopCommand implements CommandExecutor { plugin.debug(p.getName() + " can now click a chest"); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN)); ClickType.setPlayerClickType(p, new ClickType(EnumClickType.OPEN)); + + // Remove ClickType after 15 seconds if player has not clicked a chest + new BukkitRunnable() { + @Override + public void run() { + ClickType.removePlayerClickType(p); + } + }.runTaskLater(plugin, 300); } private void removeAll(CommandSender sender, String[] args) { diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 5f00e07..f1a6758 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -1039,10 +1039,10 @@ public class LanguageUtils { messages.add(new LocalizedMessage(LocalizedMessage.Message.AMOUNT_IS_ZERO, langConfig.getString("message.amount-is-zero", "&cAmount must be greater than 0."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.PRICES_CONTAIN_DECIMALS, langConfig.getString("message.prices-contain-decimals", "&cPrices must not contain decimals."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_ITEM_IN_HAND, langConfig.getString("message.no-item-in-hand", "&cNo item in hand"))); - messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE, langConfig.getString("message.click-chest-to-create-shop", "&aClick a chest to create a shop."))); - messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop to remove it."))); - messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_INFO, langConfig.getString("message.click-chest-for-info", "&aClick a shop to retrieve information."))); - messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN, langConfig.getString("message.click-chest-to-open-shop", "&aClick a shop to open it."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE, langConfig.getString("message.click-chest-to-create-shop", "&aClick a chest within 15 seconds to create a shop."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop within 15 seconds to remove it."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_INFO, langConfig.getString("message.click-chest-for-info", "&aClick a shop within 15 seconds to retrieve information."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN, langConfig.getString("message.click-chest-to-open-shop", "&aClick a shop within 15 seconds to open it."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.OPENED_SHOP, langConfig.getString("message.opened-shop", "&aYou opened %VENDOR%'s shop."), Placeholder.VENDOR)); messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP, langConfig.getString("message.cannot-break-shop", "&cYou can't break a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_SELL_BROKEN_ITEM, langConfig.getString("message.cannot-sell-broken-item", "&cYou can't sell a broken item."))); diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index 378c53d..72789ed 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -40,10 +40,10 @@ message.amount-and-price-not-number=&cAnzahl und Preise müssen Zahlen sein. message.amount-is-zero=&cAnzahl muss größer als 0 sein. message.prices-contain-decimals=&cPreise dürfen keine Dezimalen enthalten. message.no-item-in-hand=&cKein Item in der Hand. -message.click-chest-to-create-shop=&aKlicke auf eine Truhe, um einen Shop zu erstellen. -message.click-chest-to-remove-shop=&aKlicke auf einen Shop, um ihn zu entfernen. -message.click-chest-for-info=&aKlicke auf einen Shop, um Informationen über ihn zu bekommen. -message.click-chest-to-open-shop=&Klicke auf einen Shop, um ihn zu öffnen. +message.click-chest-to-create-shop=&aKlicke innerhalb von 15 Sekunden auf eine Truhe, um einen Shop zu erstellen. +message.click-chest-to-remove-shop=&aKlicke innerhalb von 15 Sekunden auf einen Shop, um ihn zu entfernen. +message.click-chest-for-info=&aKlicke innerhalb von 15 Sekunden auf einen Shop, um Informationen über ihn zu bekommen. +message.click-chest-to-open-shop=&Klicke innerhalb von 15 Sekunden auf einen Shop, um ihn zu öffnen. message.opened-shop=&aDu hast &6%VENDOR%&as Shop geöffnet. message.cannot-break-shop=&cDu kannst einen Shop nicht zerstören. message.cannot-sell-broken-item=&cDu kannst kein kaputtes Artikel verkaufen. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index 19e9957..053e461 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -150,16 +150,16 @@ message.prices-contain-decimals=&cPrices must not contain decimals. message.no-item-in-hand=&cNo item in hand # Set the message when the player must click a chest to create a shop. -message.click-chest-to-create-shop=&aClick a chest to create a shop. +message.click-chest-to-create-shop=&aClick a chest within 15 seconds to create a shop. # Set the message when the player must click a shop to remove it. -message.click-chest-to-remove-shop=&aClick a shop to remove it. +message.click-chest-to-remove-shop=&aClick a shop within 15 seconds to remove it. # Set the message when the player must click a shop to retrieve information. -message.click-chest-for-info=&aClick a shop to retrieve information. +message.click-chest-for-info=&aClick a shop within 15 seconds to retrieve information. # Set the message when the player must click a shop to open it. -message.click-chest-to-open-shop=&aClick a shop to open it. +message.click-chest-to-open-shop=&aClick a shop within 15 seconds to open it. # Set the message when the player opened a shop. # Usable Placeholders: %VENDOR%