mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +01:00
Add cooldown for empty/full shop owner notifications
This commit is contained in:
parent
cef571223e
commit
b0523b2199
@ -164,6 +164,8 @@ public class Properties {
|
||||
public static boolean SHOW_MESSAGE_OUT_OF_STOCK = true;
|
||||
@ConfigurationComment("Do you want to show \"Full shop\" messages?")
|
||||
public static boolean SHOW_MESSAGE_FULL_SHOP = true;
|
||||
@ConfigurationComment("How many seconds do you want to wait before showing notifications for the same shop to the owner again?")
|
||||
public static long NOTIFICATION_MESSAGE_COOLDOWN = 10;
|
||||
|
||||
@PrecededBySpace
|
||||
@ConfigurationComment("Can players hide the \"Out of stock\" messages with /cstoggle?")
|
||||
|
@ -7,14 +7,19 @@ import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Database.Account;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.CLIENT_DEPOSIT_FAILED;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.NOT_ENOUGH_STOCK_IN_YOUR_SHOP;
|
||||
import static com.Acrobot.ChestShop.Configuration.Messages.NOT_ENOUGH_SPACE_IN_YOUR_SHOP;
|
||||
@ -23,6 +28,16 @@ import static com.Acrobot.ChestShop.Configuration.Messages.NOT_ENOUGH_SPACE_IN_Y
|
||||
* @author Acrobot
|
||||
*/
|
||||
public class ErrorMessageSender implements Listener {
|
||||
|
||||
private static Table<UUID, String, Long> notificationCooldowns = HashBasedTable.create();
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public static void onQuit(PlayerQuitEvent event) {
|
||||
if (Properties.NOTIFICATION_MESSAGE_COOLDOWN > 0) {
|
||||
notificationCooldowns.rowMap().remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public static void onMessage(PreTransactionEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
@ -108,10 +123,20 @@ public class ErrorMessageSender implements Listener {
|
||||
Player player = Bukkit.getPlayer(ownerAccount.getUuid());
|
||||
if (player != null) {
|
||||
message = message.replace("%material", "%item");
|
||||
String replacedMessage = message.replace("%item", MaterialUtil.getItemList(stock));
|
||||
|
||||
if (Properties.NOTIFICATION_MESSAGE_COOLDOWN > 0) {
|
||||
Long last = notificationCooldowns.get(player.getUniqueId(), replacedMessage);
|
||||
if (last != null && last + Properties.NOTIFICATION_MESSAGE_COOLDOWN * 1000 > System.currentTimeMillis()) {
|
||||
return;
|
||||
}
|
||||
notificationCooldowns.put(player.getUniqueId(), replacedMessage, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, message, stock)) {
|
||||
return;
|
||||
}
|
||||
player.sendMessage(message.replace("%item", MaterialUtil.getItemList(stock)));
|
||||
player.sendMessage(replacedMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user