daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Jul 21st, 2018 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.anonym927;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Server;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.EventPriority;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.player.PlayerChatEvent;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.PluginManager;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin implements Listener
  18. {
  19.     private static Logger console;
  20.     private static Main instance;
  21.     public static final String RED = ChatColor.RED.toString();
  22.  
  23.     @Override
  24.     public void onDisable()
  25.     {
  26.         instance = null;
  27.         console.info("ChatSecurer disabled!");
  28.     }
  29.  
  30.     @Override
  31.     public void onEnable()
  32.     {
  33.         instance = this;
  34.         Server s = this.getServer();
  35.         console = this.getLogger();
  36.         PluginManager pm = s.getPluginManager();
  37.         pm.registerEvents(this, this);
  38.         PluginDescriptionFile pdf = this.getDescription();
  39.         console.info("ChatSecurer enabled!");
  40.     }
  41.     private long refreshingTime = 5000;//what time to wait for all messages
  42.     private int messageCap = 3;//how many messages can be sent in said time
  43.     private long chatLock = 5000;
  44.    
  45.     private double messages = 0;
  46.     private long chatLocked = 0;
  47.     private long lastTime = System.currentTimeMillis();
  48.    
  49.     @EventHandler(priority = EventPriority.NORMAL)
  50.     public void onPlayerChat(PlayerChatEvent e)
  51.     {
  52.         long currentTime = System.currentTimeMillis();
  53.         long delta = currentTime -lastTime;
  54.         chatLocked -= delta;
  55.         messages -= messageCap * ((double)delta / refreshingTime);
  56.         if(messages < 0D)
  57.             messages = 0D;
  58.         lastTime = currentTime;
  59.         Player sender = e.getPlayer();
  60.         if(chatLocked > 0)
  61.         {
  62.             sender.sendMessage(RED.concat("Der Chat ist gesperrt! Deine Nachricht wurde nicht gesendet!"));
  63.             e.setCancelled(true);
  64.             return;
  65.         }
  66.         messages++;
  67.         if(messages > messageCap)
  68.         {
  69.             Bukkit.getServer().broadcastMessage(new StringBuilder(RED).append("Die Message-Grenze wurde ├╝berschritten durch die Nachricht von").append(sender.getName()).append("! Chat wird f├╝r 5 Sekunden gesperrt!").toString());
  70.             e.setCancelled(true);
  71.             chatLocked = chatLock;
  72.             messages = 0;
  73.         }
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top