mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-23 19:16:40 +01:00
Don't send too many "can't do this" messages at a time.
This commit is contained in:
parent
0d7e3ad2de
commit
3336b73536
@ -34,6 +34,7 @@
|
||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||
import com.sk89q.worldguard.bukkit.util.Events;
|
||||
import com.sk89q.worldguard.bukkit.util.Materials;
|
||||
import com.sk89q.worldguard.bukkit.util.WGMetadata;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
@ -53,6 +54,9 @@
|
||||
*/
|
||||
public class RegionProtectionListener extends AbstractListener {
|
||||
|
||||
private static final String LAST_MESSAGE_KEY = "worldguard.region.lastMessage";
|
||||
private static final int LAST_MESSAGE_DELAY = 500;
|
||||
|
||||
/**
|
||||
* Construct the listener.
|
||||
*
|
||||
@ -73,12 +77,18 @@ private void tellErrorMessage(Cause cause, Location location, String what) {
|
||||
Object rootCause = cause.getRootCause();
|
||||
|
||||
if (rootCause instanceof Player) {
|
||||
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||
Player player = (Player) rootCause;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
Long lastTime = WGMetadata.getIfPresent(player, LAST_MESSAGE_KEY, Long.class);
|
||||
if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) {
|
||||
RegionQuery query = getPlugin().getRegionContainer().createQuery();
|
||||
String message = query.queryValue(location, player, DefaultFlag.DENY_MESSAGE);
|
||||
if (message != null) {
|
||||
player.sendMessage(message.replace("%what%", what));
|
||||
}
|
||||
WGMetadata.put(player, LAST_MESSAGE_KEY, now);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user