From 50cb6c4ca9f21c3374c1a4f90b6e440890597a52 Mon Sep 17 00:00:00 2001 From: ZeroEpoch1969 <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Sun, 18 Mar 2018 01:32:50 -0700 Subject: [PATCH] Improvements --- .../totalfreedommod/AntiSpam.java | 11 ++++++ .../totalfreedommod/ChatManager.java | 34 +++++++++++++++++-- .../totalfreedommod/LoginProcess.java | 2 +- .../totalfreedom/totalfreedommod/Muter.java | 23 +++++++++++-- .../totalfreedommod/ServerPing.java | 9 +++-- .../command/Command_consolesay.java | 10 ++++-- .../totalfreedommod/command/Command_say.java | 2 ++ .../totalfreedommod/command/Command_stfu.java | 1 + .../command/Command_toggle.java | 3 +- .../command/Command_wipeflatlands.java | 20 ++--------- .../totalfreedommod/player/FPlayer.java | 16 +++++++-- 11 files changed, 100 insertions(+), 31 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java index 9bc6bc48..b82fde99 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/AntiSpam.java @@ -62,6 +62,12 @@ public class AntiSpam extends FreedomService public void onAsyncPlayerChat(AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); + + if (plugin.al.isAdmin(player)) + { + return; + } + String message = event.getMessage().trim(); final FPlayer playerdata = plugin.pl.getPlayerSync(player); @@ -104,6 +110,11 @@ public class AntiSpam extends FreedomService return; } + if (plugin.al.isAdmin(player)) + { + return; + } + if (fPlayer.incrementAndGetMsgCount() > MSG_PER_CYCLE) { FUtil.bcastMsg(player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index deeace93..ad56ce72 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -4,7 +4,8 @@ import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FSync; import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; -import org.bukkit.Bukkit; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -71,7 +72,10 @@ public class ChatManager extends FreedomService } if (((float) caps / (float) message.length()) > 0.65) //Compute a ratio so that longer sentences can have more caps. { - message = message.toLowerCase(); + if (!plugin.al.isAdmin(player)) + { + message = message.toLowerCase(); + } } } @@ -84,6 +88,9 @@ public class ChatManager extends FreedomService return; } + // Check for mentions + checkMentions(message); + // Finally, set message event.setMessage(message); @@ -100,10 +107,33 @@ public class ChatManager extends FreedomService event.setFormat(format); } + public void checkMentions(String message) + { + checkMentions(message, false); + } + + public void checkMentions(String message, boolean adminOnly) + { + for (Player player : server.getOnlinePlayers()) + { + // This is so if admins for some reason mention non-admins in admin chat, they won't be notified + if (adminOnly && !plugin.al.isAdmin(player)) + { + return; + } + + if (ChatColor.stripColor(message).toLowerCase().contains("@" + player.getName().toLowerCase())) + { + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_PLING, SoundCategory.PLAYERS, 100F, 0.9F); + } + } + } + public void adminChat(CommandSender sender, String message) { String name = sender.getName() + " " + plugin.rm.getDisplay(sender).getColoredTag() + ChatColor.WHITE; FLog.info("[ADMIN] " + name + ": " + message); + checkMentions(message, true); for (Player player : server.getOnlinePlayers()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 34400234..152251c6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -26,7 +26,7 @@ public class LoginProcess extends FreedomService // @Getter @Setter - private boolean lockdownEnabled = false; + private static boolean lockdownEnabled = false; public LoginProcess(TotalFreedomMod plugin) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java index f184d604..21e37f9c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; @@ -14,11 +15,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; public class Muter extends FreedomService { public static final List MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,tell,reply,mail", ",")); + public final List MUTED_PLAYERS = new ArrayList(); public Muter(TotalFreedomMod plugin) { @@ -38,16 +41,19 @@ public class Muter extends FreedomService @EventHandler(priority = EventPriority.LOW) public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { - FPlayer fPlayer = plugin.pl.getPlayerSync(event.getPlayer()); + Player player = event.getPlayer(); + + FPlayer fPlayer = plugin.pl.getPlayerSync(player); if (!fPlayer.isMuted()) { return; } - if (plugin.al.isAdminSync(event.getPlayer())) + if (plugin.al.isAdminSync(player)) { fPlayer.setMuted(false); + MUTED_PLAYERS.remove(player.getName()); return; } @@ -101,4 +107,17 @@ public class Muter extends FreedomService } } + @EventHandler(priority = EventPriority.LOW) + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + FPlayer playerdata = plugin.pl.getPlayer(player); + + if (MUTED_PLAYERS.contains(player.getName())) + { + playerdata.setMuted(true); + } + } + + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java b/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java index 8bd6748f..467159b0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ServerPing.java @@ -43,6 +43,12 @@ public class ServerPing extends FreedomService return; } + if (LoginProcess.isLockdownEnabled()) + { + event.setMotd(ChatColor.RED + "Server is in lock-down."); + return; + } + if (Bukkit.hasWhitelist()) { event.setMotd(ChatColor.RED + "Whitelist enabled."); @@ -55,8 +61,7 @@ public class ServerPing extends FreedomService return; } -// String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion()); - String baseMotd = ConfigEntry.SERVER_MOTD.getString(); + String baseMotd = ConfigEntry.SERVER_MOTD.getString().replace("%mcversion%", plugin.si.getVersion()); baseMotd = baseMotd.replace("\\n", "\n"); baseMotd = FUtil.colorize(baseMotd); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java index e692cac8..47d4c7c6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_consolesay.java @@ -8,17 +8,21 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_CONSOLE) -@CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/ ", aliases = "csay") +@CommandParameters(description = "Telnet command - Send a chat message with chat formatting over telnet.", usage = "/ ", aliases = "csay") public class Command_consolesay extends FreedomCommand { @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length > 0) + if (args.length == 0) { - FUtil.bcastMsg(String.format("§7[CONSOLE]§f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " "))); + return false; } + + String message = StringUtils.join(args, " "); + plugin.cm.checkMentions(message); + FUtil.bcastMsg(String.format("§7[CONSOLE] §f<§c%s§f> %s", sender.getName(), StringUtils.join(args, " "))); return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java index 4d5e8211..cb774161 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_say.java @@ -40,6 +40,8 @@ public class Command_say extends FreedomCommand } } + plugin.cm.checkMentions(message); + FUtil.bcastMsg(String.format("[Server:%s] %s", sender.getName(), message), ChatColor.LIGHT_PURPLE); return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java index 8082fc59..fb1f6cc9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java @@ -62,6 +62,7 @@ public class Command_stfu extends FreedomCommand count++; } } + plugin.mu.MUTED_PLAYERS.clear(); msg("Unmuted " + count + " players."); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 7f8d3625..b7c4c9f3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -1,7 +1,6 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.GameRuleHandler; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -70,7 +69,7 @@ public class Command_toggle extends FreedomCommand else if (args[0].equals("firespread")) { toggle("Fire spread is", ConfigEntry.ALLOW_FIRE_SPREAD); - ((TotalFreedomMod)this.plugin).gr.setGameRule(GameRuleHandler.GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()); + plugin.gr.setGameRule(GameRuleHandler.GameRule.DO_FIRE_TICK, ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean()); return true; } else if (args[0].equals("prelog")) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeflatlands.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeflatlands.java index 20760b0b..c6e90f31 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeflatlands.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wipeflatlands.java @@ -25,27 +25,13 @@ public class Command_wipeflatlands extends FreedomCommand player.kickPlayer("Server is going offline for flatlands wipe, come back in a few minutes."); } - if (!plugin.cpb.isEnabled()) + if (!plugin.amp.enabled) { - if(!plugin.amp.enabled) - { - server.shutdown(); - } - else - { - plugin.amp.restartServer(); - } + server.shutdown(); } else { - new BukkitRunnable() - { - @Override - public void run() - { - plugin.cpb.clearDatabase(plugin.wm.flatlands.getWorld(), true); - } - }.runTaskAsynchronously(plugin); + plugin.amp.restartServer(); } return true; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java b/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java index 4d63233f..949919ce 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/player/FPlayer.java @@ -287,6 +287,7 @@ public class FPlayer public void setMuted(boolean muted) { FUtil.cancel(unmuteTask); + plugin.mu.MUTED_PLAYERS.remove(getPlayer().getName()); unmuteTask = null; if (!muted) @@ -298,13 +299,24 @@ public class FPlayer { return; } + + plugin.mu.MUTED_PLAYERS.add(getPlayer().getName()); + unmuteTask = new BukkitRunnable() { @Override public void run() { - FUtil.adminAction("TotalFreedom", "Unmuting " + getPlayer().getName(), false); - setMuted(false); + if (getPlayer() != null) + { + FUtil.adminAction("TotalFreedom", "Unmuting " + getPlayer().getName(), false); + setMuted(false); + } + else + { + FUtil.adminAction("TotalFreedom", "Unmuting " + getName(), false); + plugin.mu.MUTED_PLAYERS.remove(getName()); + } } }.runTaskLater(plugin, AUTO_PURGE_TICKS); }