Created
January 4, 2015 13:38
-
-
Save heinrichquirit/751c280d9fd2ee6efa7f to your computer and use it in GitHub Desktop.
NoSpambots Bukkit plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main.java.net.bigbadcraft.nospambots; | |
import java.util.HashMap; | |
import org.bukkit.ChatColor; | |
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.AsyncPlayerChatEvent; | |
import org.bukkit.event.player.PlayerJoinEvent; | |
import org.bukkit.event.player.PlayerMoveEvent; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class NoSpambots extends JavaPlugin implements Listener { | |
private final String bypass_permission = "nospambots.bypass"; | |
private HashMap<String, Location> locations = new HashMap<String, Location>(); | |
public void onEnable() { | |
getServer().getPluginManager().registerEvents(this, this); | |
} | |
@EventHandler | |
public void onJoin(PlayerJoinEvent e) { | |
Player player = e.getPlayer(); | |
Location loc = player.getLocation(); | |
if (!player.hasPermission(bypass_permission)) { | |
locations.put(player.getName(), loc); | |
} | |
} | |
@EventHandler | |
public void onMove(PlayerMoveEvent e) { | |
Player player = e.getPlayer(); | |
if (locations.containsKey(player.getName())) { | |
Location loc = locations.get(player.getName()); | |
if (player.getLocation().distance(loc) >= 1) { | |
locations.remove(player.getName()); | |
player.sendMessage(ChatColor.GREEN + "You are now free to chat."); | |
} | |
} | |
} | |
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) | |
public void onChat(AsyncPlayerChatEvent e) { | |
Player player = e.getPlayer(); | |
if (locations.containsKey(player.getName())) { | |
e.setCancelled(true); | |
player.sendMessage(ChatColor.RED + "You must move a block to chat."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment