2012-08-10 21:44:32 +02:00
|
|
|
package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
2012-08-10 18:56:16 +02:00
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
2012-08-10 18:56:16 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.PreTransactionEvent;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
|
|
|
import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.SPAM_CLICKING_PROTECTION;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class SpamClickProtector implements Listener {
|
|
|
|
private final Map<Player, Long> TIME_OF_LATEST_CLICK = new WeakHashMap<Player, Long>();
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOWEST)
|
|
|
|
public void onClick(PreTransactionEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player clicker = event.getClient();
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (TIME_OF_LATEST_CLICK.containsKey(clicker) && (System.currentTimeMillis() - TIME_OF_LATEST_CLICK.get(clicker)) < Properties.SHOP_INTERACTION_INTERVAL) {
|
2012-08-10 18:56:16 +02:00
|
|
|
event.setCancelled(SPAM_CLICKING_PROTECTION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIME_OF_LATEST_CLICK.put(clicker, System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
}
|