Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.mttprvst13;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.logging.Logger;
- import net.milkbowl.vault.chat.Chat;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- import ru.tehkode.permissions.PermissionGroup;
- import ru.tehkode.permissions.PermissionUser;
- import ru.tehkode.permissions.bukkit.PermissionsEx;
- import com.onarandombox.MultiverseCore.MultiverseCore;
- import com.onarandombox.MultiverseCore.api.MultiverseWorld;
- public class Main extends JavaPlugin {
- Logger log = this.getLogger();
- ChatListener cl = new ChatListener(this);
- private MultiverseCore core;
- private boolean mv;
- private MultiverseWorld mvWorld;
- private String worldName;
- public static Chat chat = null;
- public void onEnable() {
- this.saveDefaultConfig();
- this.getServer().getPluginManager().registerEvents(cl, this);
- if (this.getServer().getPluginManager()
- .isPluginEnabled("Multiverse-Core")) {
- mv = true;
- core = (MultiverseCore) getServer().getPluginManager().getPlugin(
- "Multiverse-Core");
- }
- if (this.getServer().getPluginManager().isPluginEnabled("Vault")) {
- setupChat();
- }
- log.info("Enabled!");
- }
- public void onDisable() {
- log.info("Disabled.");
- }
- public List<Player> getLocalRecipients(Player sender, String message,
- double range) {
- Location playerLocation = sender.getLocation();
- List<Player> recipients = new LinkedList<Player>();
- double squaredDistance = Math.pow(range, 2);
- for (Player recipient : getServer().getOnlinePlayers()) {
- // Recipient are not from same world
- if (!recipient.getWorld().equals(sender.getWorld())) {
- continue;
- }
- if (playerLocation.distanceSquared(recipient.getLocation()) > squaredDistance) {
- continue;
- }
- recipients.add(recipient);
- }
- return recipients;
- }
- private boolean setupChat() {
- RegisteredServiceProvider<Chat> chatProvider = getServer()
- .getServicesManager().getRegistration(
- net.milkbowl.vault.chat.Chat.class);
- if (chatProvider != null) {
- chat = chatProvider.getProvider();
- }
- return (chat != null);
- }
- public String formatChat(Player player, String format) {
- if (mv) {
- mvWorld = core.getMVWorldManager().getMVWorld(player.getWorld());
- }
- if (mvWorld != null) {
- log.info(mvWorld.getName() + " - " + format);
- format.replaceAll("%MVWORLD%", mvWorld.getName());
- } else {
- format.replaceAll("%MVWORLD", "");
- }
- worldName = player.getWorld().getName();
- String[] stuff = getStuff(player);
- format = format
- .replaceAll("%PREFIX%", stuff[0])
- .replaceAll("%SUFFIX%", stuff[1])
- .replaceAll("%WORLD%", worldName)
- .replaceAll("%UUID%", player.getUniqueId().toString())
- // for people who really want UUIDs in chat
- .replaceAll("%PLAYER%", player.getName())
- .replaceAll("%DISPLAYNAME%", player.getDisplayName())
- .replaceAll("%GROUP%", stuff[2]);
- return format;
- }
- public String colorize(String string) {
- if (string == null) {
- return "";
- }
- return string.replaceAll("&([a-z0-9])", "\u00A7$1");
- }
- @SuppressWarnings("deprecation")
- public String[] getStuff(Player player) {
- String prefix = null;
- String suffix = null;
- String group = null;
- if (getServer().getPluginManager().getPlugin("PermissionsEx") != null) {
- PermissionUser user = PermissionsEx.getUser(player.getName());
- PermissionGroup[] groups = user.getGroups();
- prefix = "";
- suffix = "";
- group = "";
- for (PermissionGroup g : groups) {
- prefix = prefix + "" + g.getOwnPrefix();
- suffix = suffix + "" + g.getOwnSuffix();
- group = group + "" + g.getName();
- }
- } else if (getServer().getPluginManager().getPlugin("bPermissions") != null) {
- prefix = Main.chat.getPlayerPrefix(player);
- suffix = Main.chat.getPlayerSuffix(player);
- group = chat.getPrimaryGroup(player);
- }
- String[] ret;
- ret = new String[3];
- ret[0] = prefix;
- ret[1] = suffix;
- ret[2] = group;
- return ret;
- }
- public List<Player> getSpies() {
- List<Player> recipients = new LinkedList<Player>();
- for (Player p : getServer().getOnlinePlayers()) {
- if (p.hasPermission("tellme.spy")) {
- recipients.add(p);
- }
- }
- return recipients;
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label,
- String[] args) {
- if (cmd.getName().equalsIgnoreCase("tmr")) {
- this.reloadConfig();
- sender.sendMessage(ChatColor.GREEN + "[TellMe] Reload Complete.");
- }
- if(cmd.getName().equalsIgnoreCase("/s") || cmd.getName().equalsIgnoreCase("/shout")){
- if(sender instanceof Player){
- Player player = (Player) sender;
- String msg = "";
- for(String word : args){
- msg = msg + word + " ";
- }
- player.chat("!" + msg);
- log.info("!" + msg);
- }else{
- sender.sendMessage(ChatColor.RED + "You must be a player to do that command.");
- }
- }
- return false;
- }
- public boolean filter(Player player, String msg) {
- if (getConfig().getBoolean("Anti-Spam.Anti-Spam", true)) {
- String[] splitmsg = msg.split("");
- int configcl = getConfig().getInt("Anti-Spam.Consecutive-Letters");
- String ll = null;
- int cl = 0;
- for (String l : splitmsg) {
- if (ll == null) {
- ll = l;
- } else {
- if (ll.equalsIgnoreCase(l)) {
- cl++;
- } else {
- cl = 0;
- }
- ll = l;
- if (cl >= configcl) {
- player.sendMessage(ChatColor.RED
- + "You have done an excecive amount of consecutive letters.");
- return false;
- }
- }
- }
- }
- if (getConfig().getBoolean("Anti-Spam.CapsControl", true)) {
- String[] splitmsg = msg.split("");
- int configcl = getConfig().getInt("Anti-Spam.Consecutive-Caps");
- String lastLetter = null;
- int conLetter = 0;
- for (String letter : splitmsg) {
- if (lastLetter == null) {
- lastLetter = letter;
- } else {
- if (testIfCap(letter)) {
- conLetter++;
- } else {
- conLetter = 0;
- }
- lastLetter = letter;
- if (conLetter >= configcl) {
- player.sendMessage(ChatColor.RED
- + "You have done an excecive amount of consecutive caps.");
- return false;
- }
- }
- }
- splitmsg = msg.split("");
- configcl = getConfig().getInt("Anti-Spam.Total-Caps");
- lastLetter = null;
- conLetter = 0;
- for (String letter1 : splitmsg) {
- log.info("Letter: " + letter1);
- if(letter1.equalsIgnoreCase("")){
- continue;
- }
- if (testIfCap(letter1)) {
- conLetter++;
- }
- if (conLetter >= configcl) {
- player.sendMessage(ChatColor.RED
- + "You have done an excecive amount of caps.");
- return false;
- }
- }
- }
- return true;
- }
- public boolean testIfCap(String letter) {
- char c = letter.charAt(0);
- if (c >= 97 && c <= 122) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement