summaryrefslogtreecommitdiff
path: root/src/main/java/com/redstoner/modules/adminchat
diff options
context:
space:
mode:
authorDavid Panić <david@panic.tk>2018-11-10 22:42:49 +0100
committerDavid Panić <david@panic.tk>2018-11-10 22:42:49 +0100
commit0b1c2c69fd0a991ef515ded68eb19163df002a70 (patch)
treec5c77ac8b5d3f5ff67dafd71c427375090c263c0 /src/main/java/com/redstoner/modules/adminchat
parentfe80557b8a7df5c1d03874931f76e6d88173d302 (diff)
Code cleanup batch 1
Diffstat (limited to 'src/main/java/com/redstoner/modules/adminchat')
-rw-r--r--src/main/java/com/redstoner/modules/adminchat/Adminchat.java199
1 files changed, 97 insertions, 102 deletions
diff --git a/src/main/java/com/redstoner/modules/adminchat/Adminchat.java b/src/main/java/com/redstoner/modules/adminchat/Adminchat.java
index d736f8f..7df0374 100644
--- a/src/main/java/com/redstoner/modules/adminchat/Adminchat.java
+++ b/src/main/java/com/redstoner/modules/adminchat/Adminchat.java
@@ -25,190 +25,185 @@ import com.redstoner.modules.Module;
import net.nemez.chatapi.ChatAPI;
-/** AdminChat module. Allows staff to chat to other staff using /ac \<message\> as well as a one char prefix or a toggle.
+/**
+ * AdminChat module. Allows staff to chat to other staff using /ac \<message\>
+ * as well as a one char prefix or a toggle.
*
- * @author Pepich */
+ * @author Pepich
+ */
@Commands(CommandHolderType.File)
@AutoRegisterListener
@Version(major = 4, minor = 1, revision = 0, compatible = 4)
-public class Adminchat implements Module, Listener
-{
+public class Adminchat implements Module, Listener {
private static final char defaultKey = ',';
private static final File keysLocation = new File(Main.plugin.getDataFolder(), "adminchat_keys.json");
private ArrayList<UUID> actoggled;
private static JSONObject keys;
-
+
+ private static final BroadcastFilter AC_PERM_BROADCAST_FILTER = new BroadcastFilter() {
+ @Override
+ public boolean sendTo(CommandSender recipient) {
+ return recipient.hasPermission("utils.ac");
+ }
+ };
+
@Override
- public boolean onEnable()
- {
+ public boolean onEnable() {
keys = JsonManager.getObject(keysLocation);
- if (keys == null)
- {
+
+ if (keys == null) {
keys = new JSONObject();
saveKeys();
}
+
actoggled = new ArrayList<>();
return true;
}
-
+
@Command(hook = "ac_msg")
- public boolean acSay(CommandSender sender, String message)
- {
+ public boolean acSay(CommandSender sender, String message) {
String name;
- if (sender instanceof Player)
- name = ((Player) sender).getDisplayName();
- else
- name = sender.getName();
- Utils.broadcast("§8[§cAC§8] §9" + name + "§8: §b", ChatAPI.colorify(sender, message), new BroadcastFilter()
- {
- @Override
- public boolean sendTo(CommandSender recipient)
- {
- return recipient.hasPermission("utils.ac");
- }
- });
+
+ if (sender instanceof Player) name = ((Player) sender).getDisplayName();
+ else name = sender.getName();
+
+ Utils.broadcast("§8[§cAC§8] §9" + name + "§8: §b", ChatAPI.colorify(sender, message), AC_PERM_BROADCAST_FILTER);
return true;
}
-
+
@Command(hook = "acn_msg")
- public boolean acnSay(CommandSender sender, String name, String message)
- {
- Utils.broadcast("§8[§cAC§8] §9" + name + "§8: §b", ChatAPI.colorify(sender, message), new BroadcastFilter()
- {
- @Override
- public boolean sendTo(CommandSender recipient)
- {
- return recipient.hasPermission("utils.ac");
- }
- });
+ public boolean acnSay(CommandSender sender, String name, String message) {
+ Utils.broadcast("§8[§cAC§8] §9" + name + "§8: §b", ChatAPI.colorify(sender, message), AC_PERM_BROADCAST_FILTER);
return true;
}
-
- /** Let's a Player toggle their ac-toglge status to allow for automatically sending chat messages to adminchat.
+
+ /**
+ * Lets a Player toggle their AC toggle status to allow automatically sending
+ * chat messages to admin chat.
*
* @param sender the issuer of the command.
- * @param _void ignored.
- * @return true. */
+ * @param _void ignored.
+ * @return true.
+ */
@Command(hook = "act")
- public boolean acToggleCommand(CommandSender sender)
- {
- if (actoggled.contains(((Player) sender).getUniqueId()))
- {
+ public boolean acToggleCommand(CommandSender sender) {
+ if (actoggled.contains(((Player) sender).getUniqueId())) {
actoggled.remove(((Player) sender).getUniqueId());
getLogger().message(sender, "ACT now §cdisabled");
- }
- else
- {
+ } else {
actoggled.add(((Player) sender).getUniqueId());
getLogger().message(sender, "ACT now §aenabled");
}
+
return true;
}
-
- /** Let's a Player toggle their ac-toglge status to allow for automatically sending chat messages to adminchat.
+
+ /**
+ * Lets a Player toggle their AC toggle status to allow automatically sending
+ * chat messages to admin chat.
*
* @param sender the issuer of the command.
- * @return true. */
+ * @return true.
+ */
@Command(hook = "act_on")
- public boolean acToggleOnCommand(CommandSender sender)
- {
- if (!actoggled.contains(((Player) sender).getUniqueId()))
- {
+ public boolean acToggleOnCommand(CommandSender sender) {
+ if (!actoggled.contains(((Player) sender).getUniqueId())) {
actoggled.add(((Player) sender).getUniqueId());
getLogger().message(sender, "ACT now §aenabled");
- }
- else
+ } else {
getLogger().message(sender, "ACT was already enabled");
+ }
+
return true;
}
-
- /** Let's a Player toggle their ac-toglge status to allow for automatically sending chat messages to adminchat.
+
+ /**
+ * Lets a Player toggle their AC toggle status to allow automatically sending chat messages to admin chat.
*
* @param sender the issuer of the command.
- * @return true. */
+ * @return true.
+ */
@Command(hook = "act_off")
- public boolean acToggleOffCommand(CommandSender sender)
- {
- if (actoggled.contains(((Player) sender).getUniqueId()))
- {
+ public boolean acToggleOffCommand(CommandSender sender) {
+ if (actoggled.contains(((Player) sender).getUniqueId())) {
actoggled.remove(((Player) sender).getUniqueId());
getLogger().message(sender, "ACT now §cdisabled");
- }
- else
- {
+ } else {
getLogger().message(sender, "ACT was already disabled");
}
+
return true;
}
-
- /** Deals with chat events to allow for ackeys and actoggle.
+
+ /**
+ * Deals with chat events to allow for ackeys and actoggle.
*
- * @param event the chat event containing the player and the message. */
+ * @param event the chat event containing the player and the message.
+ */
@EventHandler
- public void onPlayerChat(AsyncPlayerChatEvent event)
- {
+ public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
- if (!player.hasPermission("utils.ac"))
- return;
- if (event.getMessage().startsWith(getKey(player)))
- {
+
+ if (!player.hasPermission("utils.ac")) return;
+
+ if (event.getMessage().startsWith(getKey(player))) {
event.setCancelled(true);
acSay(event.getPlayer(), event.getMessage().replaceFirst(Pattern.quote(getKey(player)), ""));
- }
- else if (actoggled.contains(event.getPlayer().getUniqueId()))
- {
+ } else if (actoggled.contains(event.getPlayer().getUniqueId())) {
event.setCancelled(true);
acSay(event.getPlayer(), event.getMessage());
}
}
-
- /** Sets the ackey of a Player.
+
+ /**
+ * Sets the ackey of a Player.
*
* @param sender the issuer of the command.
- * @param key the key to be set. Set to NULL or "" to get your current key.
- * @return true. */
+ * @param key the key to be set. Set to NULL or "" to get your current key.
+ * @return true.
+ */
@SuppressWarnings("unchecked")
@Command(hook = "setackey")
- public boolean setAcKey(CommandSender sender, String key)
- {
- if (key.length() > 1)
- {
- getLogger().message(sender, true,
- "Could not set your key to §6" + key + " §7, it can be at most one char.");
+ public boolean setAcKey(CommandSender sender, String key) {
+ if (key.length() > 1) {
+ getLogger().message(sender, true, "Could not set your key to §6" + key + " §7, it can be at most one char.");
return true;
}
- if (key == null || key.length() == 0)
- {
+
+ if (key == null || key.length() == 0) {
getAcKey(sender);
return true;
}
+
getLogger().message(sender, "Set your key to §6" + key);
keys.put(((Player) sender).getUniqueId().toString(), key + "");
+
saveKeys();
return true;
}
-
- /** This method will find the AdminChat key of any player.
+
+ /**
+ * This method will find the AdminChat key of any player.
*
* @param player the player to get the key from.
- * @return the key. */
- public static String getKey(Player player)
- {
+ * @return the key.
+ */
+ public static String getKey(Player player) {
String key = (String) keys.get(player.getUniqueId().toString());
return (key == null ? "" + defaultKey : key);
}
-
- /** Prints a Players ackey to their chat.
+
+ /**
+ * Prints a Player's ackey to their chat.
*
- * @param sender the issuer of the command. */
- public void getAcKey(CommandSender sender)
- {
+ * @param sender the issuer of the command.
+ */
+ public void getAcKey(CommandSender sender) {
getLogger().message(sender, "Your current ackey is §6" + getKey((Player) sender));
}
-
+
/** Saves the keys. */
- private void saveKeys()
- {
+ private void saveKeys() {
JsonManager.save(keys, keysLocation);
}
}