Add chat cool-down feature
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2de28d64a5
commit
e6eb4a416b
@ -2,14 +2,18 @@ package wtf.beatrice.limbomanager;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import wtf.beatrice.limbomanager.objects.Coordinates;
|
||||
import wtf.beatrice.limbomanager.objects.LocationCheckRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Cache
|
||||
{
|
||||
|
||||
public static List<Player> chatCooldown = new ArrayList<>();
|
||||
public static final String worldName = "limbo";
|
||||
public static World limboWorld;
|
||||
public static final Coordinates baseCoords = new Coordinates(1000, 1000);
|
||||
|
@ -35,6 +35,7 @@ public class LimboManager extends JavaPlugin {
|
||||
pluginManager.registerEvents(new CommandCanceller(), this);
|
||||
pluginManager.registerEvents(new RiskyBlocksHandler(), this);
|
||||
pluginManager.registerEvents(new WorldLoadHandler(), this);
|
||||
pluginManager.registerEvents(new PlayerChatManager(), this);
|
||||
|
||||
// no need to check if folder exists, it will just skip creation.
|
||||
getDataFolder().mkdirs();
|
||||
|
@ -0,0 +1,33 @@
|
||||
package wtf.beatrice.limbomanager.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import wtf.beatrice.limbomanager.Cache;
|
||||
import wtf.beatrice.limbomanager.LimboManager;
|
||||
|
||||
public class PlayerChatManager implements Listener
|
||||
{
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
|
||||
int coolDown = Cache.getConfiguration().getInt("chat.cool-down", 3);
|
||||
if(coolDown < 1) return; // disable this feature if cooldown is 0 or negative.
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(Cache.chatCooldown.contains(player))
|
||||
{
|
||||
player.sendMessage("Chat is limited in this server. Please wait.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Cache.chatCooldown.add(player);
|
||||
Bukkit.getScheduler().runTaskLater(LimboManager.getInstance(), () -> Cache.chatCooldown.remove(player), 20L * coolDown);
|
||||
}
|
||||
}
|
@ -8,4 +8,6 @@ island:
|
||||
y: 20.0
|
||||
z: 0.0
|
||||
yaw: 0.0
|
||||
pitch: 0.0
|
||||
pitch: 0.0
|
||||
chat:
|
||||
cool-down: 3
|
Loading…
Reference in New Issue
Block a user