From db3748213473e0fe88ccc01c579c975842b751a7 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 23 Apr 2017 02:13:51 +0200 Subject: [PATCH 1/6] Started converting command classes --- .../chat/commands/ChatonlyCommand.java | 17 +------------ .../chat/commands/MWikiCommand.java | 17 ++----------- .../chat/commands/OOCCommand.java | 23 ++++-------------- .../chat/commands/UnlolCommand.java | 17 ++----------- .../chat/commands/WaitWhatCommand.java | 16 +++++-------- .../chat/commands/YeehawCommand.java | 17 ++----------- .../appendtext/AppendTextCommandBase.java | 12 ++-------- .../commands/appendtext/ShrugCommand.java | 13 ++++------ .../commands/appendtext/TableflipCommand.java | 11 +++------ .../commands/appendtext/UnflipCommand.java | 11 +++------ .../chat/commands/ucmds/AcceptCommand.java | 9 ++++--- .../chat/commands/ucmds/CCommand.java | 5 ---- .../chat/commands/ucmds/UCommandBase.java | 24 +++++-------------- .../ucmds/admin/AdminCommandBase.java | 18 ++------------ .../commands/ucmds/admin/DebugCommand.java | 5 ---- .../ucmds/admin/PlayerInfoCommand.java | 5 ---- .../commands/ucmds/admin/SaveCommand.java | 5 ---- .../commands/ucmds/admin/SetFlairCommand.java | 5 ---- .../commands/ucmds/admin/UpdatePlugin.java | 5 ---- .../commands/ucmds/announce/AddCommand.java | 5 ---- .../ucmds/announce/AnnounceCommandBase.java | 20 ++++------------ .../commands/ucmds/announce/EditCommand.java | 5 ---- .../commands/ucmds/announce/ListCommand.java | 5 ---- .../ucmds/announce/RemoveCommand.java | 5 ---- .../ucmds/announce/SetTimeCommand.java | 5 ---- 25 files changed, 46 insertions(+), 234 deletions(-) diff --git a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java b/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java index 1ebb8c8..a79e878 100644 --- a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java @@ -8,7 +8,7 @@ import buttondevteam.chat.ChatPlayer; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; -public final class ChatonlyCommand extends TBMCCommandBase { +public final class ChatonlyCommand extends TBMCCommandBase { //TODO: Add annotation @Override public String[] GetHelpText(String alias) { @@ -29,19 +29,4 @@ public final class ChatonlyCommand extends TBMCCommandBase { return true; } - @Override - public String GetCommandPath() { - return "chatonly"; - } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/MWikiCommand.java b/src/main/java/buttondevteam/chat/commands/MWikiCommand.java index 11d3974..3a7e15a 100644 --- a/src/main/java/buttondevteam/chat/commands/MWikiCommand.java +++ b/src/main/java/buttondevteam/chat/commands/MWikiCommand.java @@ -5,8 +5,10 @@ import java.net.URLEncoder; import org.bukkit.command.CommandSender; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; +@CommandClass(modOnly = false) public class MWikiCommand extends TBMCCommandBase { @Override @@ -37,19 +39,4 @@ public class MWikiCommand extends TBMCCommandBase { return true; } - @Override - public String GetCommandPath() { - return "mwiki"; - } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/OOCCommand.java b/src/main/java/buttondevteam/chat/commands/OOCCommand.java index 8773e87..3bfd2c2 100644 --- a/src/main/java/buttondevteam/chat/commands/OOCCommand.java +++ b/src/main/java/buttondevteam/chat/commands/OOCCommand.java @@ -4,10 +4,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.PlayerCommandBase; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; -public final class OOCCommand extends TBMCCommandBase { +@CommandClass(modOnly = false) +public final class OOCCommand extends PlayerCommandBase { @Override public String[] GetHelpText(String alias) { @@ -17,8 +20,7 @@ public final class OOCCommand extends TBMCCommandBase { } @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - Player player = (Player) sender; + public boolean OnCommand(Player player, String alias, String[] args) { if (args.length == 0) { return false; } else { @@ -33,19 +35,4 @@ public final class OOCCommand extends TBMCCommandBase { return true; } - @Override - public String GetCommandPath() { - return "ooc"; - } - - @Override - public boolean GetPlayerOnly() { - return true; - } - - @Override - public boolean GetModOnly() { - return false; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java index de728cd..2fc79f0 100644 --- a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java @@ -6,8 +6,10 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; +@CommandClass(modOnly = false) public final class UnlolCommand extends TBMCCommandBase { public static CommandSender Lastlol = null; @@ -35,19 +37,4 @@ public final class UnlolCommand extends TBMCCommandBase { } return true; } - - @Override - public String GetCommandPath() { - return "unlol"; - } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/WaitWhatCommand.java b/src/main/java/buttondevteam/chat/commands/WaitWhatCommand.java index 3e04c57..c8c8f9f 100644 --- a/src/main/java/buttondevteam/chat/commands/WaitWhatCommand.java +++ b/src/main/java/buttondevteam/chat/commands/WaitWhatCommand.java @@ -4,20 +4,26 @@ import java.util.Arrays; import java.util.stream.Collectors; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.listener.PlayerListener; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; +@CommandClass(modOnly = false) public class WaitWhatCommand extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { Channel channel; if (sender instanceof Player && ((Player) sender).isOnline()) channel = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel; + else if (sender instanceof ConsoleCommandSender) + channel = PlayerListener.ConsoleChannel; else channel = Channel.GlobalChat; final String message; @@ -36,14 +42,4 @@ public class WaitWhatCommand extends TBMCCommandBase { "Wait what" // }; } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/YeehawCommand.java b/src/main/java/buttondevteam/chat/commands/YeehawCommand.java index a8f6d94..6a4b563 100644 --- a/src/main/java/buttondevteam/chat/commands/YeehawCommand.java +++ b/src/main/java/buttondevteam/chat/commands/YeehawCommand.java @@ -4,9 +4,11 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCYEEHAWEvent; +@CommandClass(modOnly = false) public class YeehawCommand extends TBMCCommandBase { @Override @@ -26,19 +28,4 @@ public class YeehawCommand extends TBMCCommandBase { Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender)); return true; } - - @Override - public String GetCommandPath() { - return "yeehaw"; - } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java index 0a566ce..bcf62d0 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java @@ -6,10 +6,12 @@ import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.listener.PlayerListener; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; +@CommandClass(modOnly = false) public abstract class AppendTextCommandBase extends TBMCCommandBase { public abstract String[] GetHelpText(String alias); @@ -31,14 +33,4 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase { TBMCChatAPI.SendChatMessage(Channel.GlobalChat, sender, msg); return true; } - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java index e2fc0f0..56d30dc 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java @@ -4,10 +4,10 @@ public final class ShrugCommand extends AppendTextCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Shrug ----", - "This command appends a shrug after your message", - "Or just makes you shrug", - "Use either /" + alias + " or just /" + alias }; + return new String[] { "§6---- Shrug ----", // + "This command appends a shrug after your message", // + "Or just makes you shrug", // + "Use either /" + alias + " or just /" + alias }; // } @Override @@ -15,9 +15,4 @@ public final class ShrugCommand extends AppendTextCommandBase { return "¯\\\\\\_(ツ)\\_/¯"; } - @Override - public String GetCommandPath() { - return "shrug"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java index 7322871..6a98cc9 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java @@ -4,9 +4,9 @@ public final class TableflipCommand extends AppendTextCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Tableflip ----", - "This command appends a tableflip after your message", - "Or just makes you tableflip", + return new String[] { "§6---- Tableflip ----", // + "This command appends a tableflip after your message", // + "Or just makes you tableflip", // "Use either /" + alias + " or just /" + alias }; } @@ -14,9 +14,4 @@ public final class TableflipCommand extends AppendTextCommandBase { public String GetAppendedText() { return "(╯°□°)╯︵ ┻━┻"; } - - @Override - public String GetCommandPath() { - return "tableflip"; - } } diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java index 7f0e92b..498e077 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java @@ -4,9 +4,9 @@ public final class UnflipCommand extends AppendTextCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Unflip ----", - "This command appends an unflip after your message", - "Or just unflips as you", + return new String[] { "§6---- Unflip ----", // + "This command appends an unflip after your message", // + "Or just unflips as you", // "Use either /" + alias + " or just /" + alias }; } @@ -15,9 +15,4 @@ public final class UnflipCommand extends AppendTextCommandBase { return "┬─┬ ノ( ゜-゜ノ)"; } - @Override - public String GetCommandPath() { - return "unflip"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java index 14a84aa..69cca30 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java @@ -10,8 +10,12 @@ import buttondevteam.chat.FlairStates; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PluginMain; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import buttondevteam.lib.player.TBMCPlayer; +@CommandClass(modOnly = false) +@OptionallyPlayerCommandClass(playerOnly = false) public class AcceptCommand extends UCommandBase { @Override @@ -92,9 +96,4 @@ public class AcceptCommand extends UCommandBase { return true; } - @Override - public String GetUCommandPath() { - return "accept"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java index e0be2d0..50a29e1 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java @@ -54,9 +54,4 @@ public class CCommand extends UCommandBase { return true; } - @Override - public String GetUCommandPath() { - return "c"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java b/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java index 2ebc393..2e10e17 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java @@ -1,25 +1,13 @@ package buttondevteam.chat.commands.ucmds; -import buttondevteam.lib.chat.TBMCCommandBase; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.OptionallyPlayerCommandBase; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; -public abstract class UCommandBase extends TBMCCommandBase { +@CommandClass(modOnly = false, path = "u") +@OptionallyPlayerCommandClass(playerOnly = false) +public abstract class UCommandBase extends OptionallyPlayerCommandBase { public abstract String[] GetHelpText(String alias); - @Override - public String GetCommandPath() { - return "u " + GetUCommandPath(); - } - - public abstract String GetUCommandPath(); - - @Override - public boolean GetPlayerOnly() { - return true; - } - - @Override - public boolean GetModOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java index 97bec7b..9169762 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java @@ -1,25 +1,11 @@ package buttondevteam.chat.commands.ucmds.admin; import buttondevteam.chat.commands.ucmds.UCommandBase; +import buttondevteam.lib.chat.CommandClass; +@CommandClass(modOnly = true) public abstract class AdminCommandBase extends UCommandBase { public abstract String[] GetHelpText(String alias); - @Override - public String GetUCommandPath() { - return "admin " + GetAdminCommandPath(); - } - - @Override - public boolean GetPlayerOnly() { - return false; // Allow admin commands in console - } - - public abstract String GetAdminCommandPath(); - - @Override - public boolean GetModOnly() { - return true; - } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java index 8cd99db..0ae61e8 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java @@ -13,11 +13,6 @@ public class DebugCommand extends AdminCommandBase { "Toggles debug mode, which prints debug messages to the console." }; } - @Override - public String GetAdminCommandPath() { - return "debug"; - } - @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled.")); diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java index ea09149..241c0a1 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java @@ -40,9 +40,4 @@ public class PlayerInfoCommand extends AdminCommandBase { return true; } - @Override - public String GetAdminCommandPath() { - return "playerinfo"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/SaveCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/SaveCommand.java index aad95c3..552d1b6 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/SaveCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/SaveCommand.java @@ -20,9 +20,4 @@ public class SaveCommand extends AdminCommandBase { return true; } - @Override - public String GetAdminCommandPath() { - return "save"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/SetFlairCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/SetFlairCommand.java index 80d405b..e932138 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/SetFlairCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/SetFlairCommand.java @@ -68,9 +68,4 @@ public class SetFlairCommand extends AdminCommandBase { return true; } - @Override - public String GetAdminCommandPath() { - return "setflair"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java index e90f40b..1cfde5a 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java @@ -39,9 +39,4 @@ public class UpdatePlugin extends AdminCommandBase { } } - @Override - public String GetAdminCommandPath() { - return "updateplugin"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java index 547e5e3..be359b2 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AddCommand.java @@ -34,9 +34,4 @@ public class AddCommand extends AnnounceCommandBase { return true; } - @Override - public String GetAnnounceCommandPath() { - return "add"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AnnounceCommandBase.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AnnounceCommandBase.java index ac9a70d..c721891 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/AnnounceCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/AnnounceCommandBase.java @@ -1,25 +1,13 @@ package buttondevteam.chat.commands.ucmds.announce; import buttondevteam.chat.commands.ucmds.UCommandBase; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; +@CommandClass(modOnly = true) +@OptionallyPlayerCommandClass(playerOnly = false) public abstract class AnnounceCommandBase extends UCommandBase { public abstract String[] GetHelpText(String alias); - @Override - public String GetUCommandPath() { - return "announce " + GetAnnounceCommandPath(); - } - - public abstract String GetAnnounceCommandPath(); - - @Override - public boolean GetPlayerOnly() { - return false; - } - - @Override - public boolean GetModOnly() { - return true; - } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java index d0ffdef..42b3ada 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/EditCommand.java @@ -42,9 +42,4 @@ public class EditCommand extends AnnounceCommandBase { return true; } - @Override - public String GetAnnounceCommandPath() { - return "edit"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/ListCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/ListCommand.java index e5bc6e5..079e2a2 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/ListCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/ListCommand.java @@ -25,9 +25,4 @@ public class ListCommand extends AnnounceCommandBase { return true; } - @Override - public String GetAnnounceCommandPath() { - return "list"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/RemoveCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/RemoveCommand.java index f6f544c..3e4cda1 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/RemoveCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/RemoveCommand.java @@ -27,9 +27,4 @@ public class RemoveCommand extends AnnounceCommandBase { return true; } - @Override - public String GetAnnounceCommandPath() { - return "remove"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java index 86fdb8d..fe488d6 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/announce/SetTimeCommand.java @@ -30,9 +30,4 @@ public class SetTimeCommand extends AnnounceCommandBase { return true; } - @Override - public String GetAnnounceCommandPath() { - return "settime"; - } - } From 8f69e40d8b151e26361ec7a36bfff1b7de9a5221 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 28 Apr 2017 16:00:05 +0200 Subject: [PATCH 2/6] Removed http error post and continued cmds --- src/main/java/buttondevteam/chat/PluginMain.java | 3 ++- .../chat/commands/ucmds/AcceptCommand.java | 2 +- .../chat/commands/ucmds/CCommand.java | 2 ++ .../chat/commands/ucmds/HelpCommand.java | 16 ++++------------ .../chat/commands/ucmds/IgnoreCommand.java | 9 ++++----- .../chat/commands/ucmds/InfoCommand.java | 12 ++---------- .../chat/commands/ucmds/OpmeCommand.java | 8 +++----- 7 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index e1d3363..87c740d 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -168,7 +168,8 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. errorcount++; if (errorcount >= 10) { errorcount = 0; - TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e); + if (!e.getMessage().contains("Server returned HTTP response code")) + TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e); } } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java index 69cca30..a588b6c 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/AcceptCommand.java @@ -15,7 +15,7 @@ import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import buttondevteam.lib.player.TBMCPlayer; @CommandClass(modOnly = false) -@OptionallyPlayerCommandClass(playerOnly = false) +@OptionallyPlayerCommandClass(playerOnly = true) public class AcceptCommand extends UCommandBase { @Override diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java index 50a29e1..1a61844 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java @@ -8,6 +8,8 @@ import buttondevteam.chat.PluginMain; import buttondevteam.lib.chat.*; import buttondevteam.lib.player.TBMCPlayer; +@CommandClass(modOnly = false) +@OptionallyPlayerCommandClass(playerOnly = true) public class CCommand extends UCommandBase { @Override diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java index 4f62fc6..8be549e 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java @@ -6,9 +6,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; +@CommandClass(modOnly = false) public final class HelpCommand extends UCommandBase { @Override @@ -35,8 +37,8 @@ public final class HelpCommand extends UCommandBase { ArrayList text = new ArrayList(); text.add("§6---- Command list ----"); for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) - if (!cmd.GetModOnly() || PluginMain.permission.has(sender, "tbmc.admin")) - if (!cmd.GetPlayerOnly() || sender instanceof Player) + if (!cmd.getClass().getAnnotation(CommandClass.class).modOnly() || PluginMain.permission.has(sender, "tbmc.admin")) + if (!cmd.isPlayerOnly() || sender instanceof Player) if (!cmd.GetCommandPath().contains(" ")) text.add("/" + cmd.GetCommandPath()); else { @@ -79,14 +81,4 @@ public final class HelpCommand extends UCommandBase { return true; } - - @Override - public String GetUCommandPath() { - return "help"; - } - - @Override - public boolean GetPlayerOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java index b93f59c..9e333db 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/IgnoreCommand.java @@ -5,8 +5,12 @@ import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.FlairStates; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import buttondevteam.lib.player.TBMCPlayer; +@CommandClass(modOnly = false) +@OptionallyPlayerCommandClass(playerOnly = true) public final class IgnoreCommand extends UCommandBase { @Override @@ -38,9 +42,4 @@ public final class IgnoreCommand extends UCommandBase { return true; } - @Override - public String GetUCommandPath() { - return "ignore"; - } - } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java index 3303884..4a61d4a 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java @@ -3,10 +3,12 @@ package buttondevteam.chat.commands.ucmds; import org.bukkit.command.CommandSender; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.TBMCPlayerBase; +@CommandClass(modOnly = false) public class InfoCommand extends UCommandBase { @Override @@ -18,11 +20,6 @@ public class InfoCommand extends UCommandBase { }; } - @Override - public String GetUCommandPath() { - return "info"; - } - @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length == 0) @@ -44,9 +41,4 @@ public class InfoCommand extends UCommandBase { } return true; } - - @Override - public boolean GetPlayerOnly() { - return false; - } } diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java index 9be3239..adc2096 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java @@ -2,6 +2,9 @@ package buttondevteam.chat.commands.ucmds; import org.bukkit.command.CommandSender; +import buttondevteam.lib.chat.CommandClass; + +@CommandClass(modOnly = false) public class OpmeCommand extends UCommandBase { @Override @@ -15,9 +18,4 @@ public class OpmeCommand extends UCommandBase { return true; } - @Override - public String GetUCommandPath() { - return "opme"; - } - } From 9e1bd49cd045d56efab089dd4dfe6a61f7a214df Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 30 Apr 2017 00:33:57 +0200 Subject: [PATCH 3/6] Moved and improved Channel stuff and removed old stuff Removed tons of lines Also reduced unlol effect duration a few days ago, commiting now --- .../buttondevteam/chat/ChatProcessing.java | 129 +++--------------- .../java/buttondevteam/chat/PluginMain.java | 40 ++---- .../chat/commands/OOCCommand.java | 2 - .../chat/commands/UnlolCommand.java | 2 +- .../chat/listener/PlayerListener.java | 91 +++--------- 5 files changed, 46 insertions(+), 218 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 2cb3b89..c2439a4 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -23,6 +23,7 @@ import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.formatting.*; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerBase; @@ -122,125 +123,31 @@ public class ChatProcessing { return true; } DebugCommand.SendDebugMessage(jsonstr); - if (channel.equals(Channel.TownChat) || channel.equals(Channel.NationChat)) { - if (player == null) { - sender.sendMessage("§cYou are not a player!"); - return true; - } - for (Player p : Bukkit.getOnlinePlayers()) { - try { - Resident resident = PluginMain.Instance.TU.getResidentMap().get(p.getName().toLowerCase()); - if (resident != null && !resident.getName().equals(player.getName()) - && resident.getModes().contains("spy")) - Bukkit.getPlayer(resident.getName()).sendMessage(String.format("[SPY-%s] - %s: %s", - channel.DisplayName, player.getDisplayName(), message)); - } catch (Exception e) { - } - } - } + try { - if (channel.equals(Channel.TownChat)) { - Town town = null; - try { - final Resident resident = PluginMain.Instance.TU.getResidentMap() - .get(player.getName().toLowerCase()); - if (resident != null && resident.hasTown()) - town = resident.getTown(); - } catch (NotRegisteredException e) { - } - if (town == null) { - player.sendMessage("§cYou aren't in a town or an error occured."); - return true; - } - int index = PluginMain.Instance.Towns.indexOf(town); - if (index < 0) { - PluginMain.Instance.Towns.add(town); - index = PluginMain.Instance.Towns.size() - 1; - } - Objective obj = PluginMain.SB.getObjective("town"); - for (Player p : Bukkit.getOnlinePlayers()) { - try { - if (town.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName()))) - obj.getScore(p.getName()).setScore(index); + if (channel.filteranderrormsg != null) { + Objective obj = PluginMain.SB.getObjective(channel.ID); + RecipientTestResult result = channel.filteranderrormsg.apply(player); + if (result.errormessage != null) + player.sendMessage("§c" + result.errormessage); + else + for (Player p : Bukkit.getOnlinePlayers()) { + if (p == player) + continue; + result = channel.filteranderrormsg.apply(p); + if (result.errormessage == null) + obj.getScore(p.getName()).setScore(result.score); else obj.getScore(p.getName()).setScore(-1); - } catch (Exception e) { - obj.getScore(p.getName()).setScore(-1); } - } PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_town=%d,score_town_min=%d] %s", index, index, jsonstr)); - } else if (channel.equals(Channel.NationChat)) { - Town town = null; - try { - final Resident resident = PluginMain.Instance.TU.getResidentMap() - .get(player.getName().toLowerCase()); - if (resident != null && resident.hasTown()) - town = resident.getTown(); - } catch (NotRegisteredException e) { - } - if (town == null) { - player.sendMessage("§cYou aren't in a town or an error occured."); - return true; - } - Nation nation = null; - try { - nation = town.getNation(); - } catch (NotRegisteredException e) { - } - if (nation == null) { - player.sendMessage("§cYour town isn't in a nation or an error occured."); - return true; - } - int index = PluginMain.Instance.Nations.indexOf(nation); - if (index < 0) { - PluginMain.Instance.Nations.add(nation); - index = PluginMain.Instance.Nations.size() - 1; - } - Objective obj = PluginMain.SB.getObjective("nation"); - for (Player p : Bukkit.getOnlinePlayers()) { - try { - if (nation.getResidents().stream().anyMatch(r -> r.getName().equalsIgnoreCase(p.getName()))) - obj.getScore(p.getName()).setScore(index); - else - obj.getScore(p.getName()).setScore(-1); - } catch (Exception e) { - } - } - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_nation=%d,score_nation_min=%d] %s", index, index, jsonstr)); - } else if (channel.equals(Channel.AdminChat)) { - if (player != null && !player.isOp()) { - player.sendMessage("§cYou need to be an OP to use this channel."); - return true; - } - Objective obj = PluginMain.SB.getObjective("admin"); - for (Player p : Bukkit.getOnlinePlayers()) { - if (p.isOp()) - obj.getScore(p.getName()).setScore(1); - else - obj.getScore(p.getName()).setScore(0); - } - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_admin=%d,score_admin_min=%d] %s", 1, 1, jsonstr)); - } else if (channel.equals(Channel.ModChat)) { - if (player != null && !PluginMain.permission.playerInGroup(player, "mod")) { - player.sendMessage("§cYou need to be a mod to use this channel."); - return true; - } - Objective obj = PluginMain.SB.getObjective("mod"); - for (Player p : Bukkit.getOnlinePlayers()) { - if (PluginMain.permission.playerInGroup(p, "mod")) - obj.getScore(p.getName()).setScore(1); - else - obj.getScore(p.getName()).setScore(0); - } - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_mod=%d,score_mod_min=%d] %s", 1, 1, jsonstr)); + String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, result.score, jsonstr)); } else PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format("tellraw @a %s", jsonstr)); - } catch (Exception e) { + } catch ( + + Exception e) { TBMCCoreAPI.SendException("An error occured while sending a chat message!", e); player.sendMessage("§cAn error occured while sending the message."); return true; diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 87c740d..c43b2d3 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -47,11 +47,13 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. // https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/ public static PluginMain Instance; public static ConsoleCommandSender Console; - public static Scoreboard SB; public final static String FlairThreadURL = "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/"; - public TownyUniverse TU; - public ArrayList Towns; - public ArrayList Nations; + + public static Scoreboard SB; + public static TownyUniverse TU; + public static ArrayList Towns; + public static ArrayList Nations; + /** *

* This variable is used as a cache for flair state checking when reading the flair thread. @@ -72,37 +74,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. Console = this.getServer().getConsoleSender(); LoadFiles(); - SB = PluginMain.Instance.getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...] - if (SB.getObjective("town") == null) - SB.registerNewObjective("town", "dummy"); - if (SB.getObjective("nation") == null) - SB.registerNewObjective("nation", "dummy"); - if (SB.getObjective("admin") == null) - SB.registerNewObjective("admin", "dummy"); - if (SB.getObjective("mod") == null) - SB.registerNewObjective("mod", "dummy"); + SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...] TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse(); - Towns = new ArrayList(TU.getTownsMap().values()); - Nations = new ArrayList(TU.getNationsMap().values()); + Towns = new ArrayList(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed + Nations = new ArrayList(TU.getNationsMap().values()); // Same here but with nations setupChat(); setupEconomy(); setupPermissions(); - Runnable r = new Runnable() { - public void run() { - FlairGetterThreadMethod(); - } - }; - Thread t = new Thread(r); - t.start(); - r = new Runnable() { - public void run() { - AnnouncerThread.Run(); - } - }; - t = new Thread(r); - t.start(); + new Thread(() -> FlairGetterThreadMethod()).start(); + new Thread(() -> AnnouncerThread.Run()).start(); } public Boolean stop = false; diff --git a/src/main/java/buttondevteam/chat/commands/OOCCommand.java b/src/main/java/buttondevteam/chat/commands/OOCCommand.java index 3bfd2c2..c85151f 100644 --- a/src/main/java/buttondevteam/chat/commands/OOCCommand.java +++ b/src/main/java/buttondevteam/chat/commands/OOCCommand.java @@ -1,12 +1,10 @@ package buttondevteam.chat.commands; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.PlayerCommandBase; -import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; @CommandClass(modOnly = false) diff --git a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java index 2fc79f0..9e7c187 100644 --- a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java @@ -28,7 +28,7 @@ public final class UnlolCommand extends TBMCCommandBase { if (Lastlol != null) { if (Lastlol instanceof Player) ((Player) Lastlol) - .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false)); + .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false)); String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + (Lastlolornot ? " unlolled " : " unlaughed ") + (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName()); diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index fcaceb4..1c03829 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -1,37 +1,23 @@ package buttondevteam.chat.listener; -import java.util.ArrayList; +import java.util.*; import java.util.Map.Entry; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; -import java.util.UUID; - -import com.palmergames.bukkit.towny.Towny; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; +import org.bukkit.event.*; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerChatTabCompleteEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.*; import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.help.HelpTopic; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import buttondevteam.chat.ChatPlayer; -import buttondevteam.chat.ChatProcessing; -import buttondevteam.chat.PluginMain; +import buttondevteam.chat.*; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.ChatChannelRegisterEvent; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; @@ -39,13 +25,6 @@ import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownBlock; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.war.eventwar.War; -import com.palmergames.bukkit.towny.object.WorldCoord; import com.vexsoftware.votifier.model.Vote; import com.vexsoftware.votifier.model.VotifierEvent; @@ -86,7 +65,7 @@ public class PlayerListener implements Listener { if (index == -1) { cmd = event.getMessage().substring(1); for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.Command)) { + if (cmd.equalsIgnoreCase(channel.ID)) { if (mp.CurrentChannel.equals(channel)) mp.CurrentChannel = Channel.GlobalChat; else @@ -99,7 +78,7 @@ public class PlayerListener implements Listener { } else { cmd = event.getMessage().substring(1, index); for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.Command)) { + if (cmd.equalsIgnoreCase(channel.ID)) { event.setCancelled(true); Channel c = mp.CurrentChannel; mp.CurrentChannel = channel; @@ -119,42 +98,7 @@ public class PlayerListener implements Listener { } } } - if (cmd.equalsIgnoreCase("sethome")) { // TODO: Move out? - TownyUniverse tu = PluginMain.Instance.TU; - try { - TownBlock tb = WorldCoord.parseWorldCoord(event.getPlayer()).getTownBlock(); - if (tb.hasTown()) { - Town town = tb.getTown(); - if (town.hasNation()) { - Resident res = tu.getResidentMap().get(event.getPlayer().getName()); - if (res != null && res.hasTown()) { - Town town2 = res.getTown(); - if (town2.hasNation()) { - if (town.getNation().getEnemies().contains(town2.getNation())) { - event.getPlayer().sendMessage("§cYou cannot set homes in enemy territory."); - event.setCancelled(true); - return; - } - } - } - } - } - } catch (NotRegisteredException e) { - return; - } - } else if (cmd.equalsIgnoreCase("home") || cmd.equalsIgnoreCase("tpa") || cmd.equalsIgnoreCase("tp")) { - String currentWorld = event.getPlayer().getLocation().getWorld().getName(); - Location currentLocation = event.getPlayer().getLocation(); - TownyUniverse universe = Towny.getPlugin(Towny.class).getTownyUniverse(); - if (TownyUniverse.isWarTime()) { - War war = universe.getWarEvent(); - if (war.isWarZone( - new WorldCoord(currentWorld, currentLocation.getBlockX(), currentLocation.getBlockZ()))) { - event.getPlayer().sendMessage("§cError: You can't teleport out of a war zone!"); - event.setCancelled(true); - } - } - } else if (cmd.toLowerCase().startsWith("un")) { + if (cmd.toLowerCase().startsWith("un")) { for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) { if (ht.getName().equalsIgnoreCase("/" + cmd)) return; @@ -175,15 +119,6 @@ public class PlayerListener implements Listener { } } } - if (cmd.equalsIgnoreCase("f")) { - String[] args = event.getMessage().substring(index + 1).split(" "); - if (args.length > 1) { - if (args[0].toLowerCase().equals("enemy") && args[1].equalsIgnoreCase("newhaven")) { - event.setCancelled(true); - event.getPlayer().sendMessage("§cYou are not allowed to set New Haven as your enemy faction."); - } - } - } } @EventHandler @@ -274,7 +209,7 @@ public class PlayerListener implements Listener { if (index == -1) { cmd = event.getCommand(); for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.Command)) { + if (cmd.equalsIgnoreCase(channel.ID)) { if (ConsoleChannel.equals(channel)) ConsoleChannel = Channel.GlobalChat; else @@ -287,7 +222,7 @@ public class PlayerListener implements Listener { } else { cmd = event.getCommand().substring(0, index); for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.Command)) { + if (cmd.equalsIgnoreCase(channel.ID)) { Channel c = ConsoleChannel; ConsoleChannel = channel; TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, Bukkit.getConsoleSender(), @@ -349,4 +284,10 @@ public class PlayerListener implements Listener { TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex); } } + + @EventHandler + public void onChannelRegistered(ChatChannelRegisterEvent e) { + if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet + PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy"); + } } From 07fccda8d3ca871530ac37fcf92aac09dfa6dc79 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 6 May 2017 19:55:04 +0200 Subject: [PATCH 4/6] Chat channels probably done, needs testing --- .../buttondevteam/chat/AnnouncerThread.java | 5 +- .../buttondevteam/chat/ChatProcessing.java | 43 +++++--------- .../java/buttondevteam/chat/PluginMain.java | 59 ++++++++++++++++++- .../chat/listener/PlayerListener.java | 2 +- 4 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/main/java/buttondevteam/chat/AnnouncerThread.java b/src/main/java/buttondevteam/chat/AnnouncerThread.java index 85980a9..b1b11da 100644 --- a/src/main/java/buttondevteam/chat/AnnouncerThread.java +++ b/src/main/java/buttondevteam/chat/AnnouncerThread.java @@ -2,10 +2,11 @@ package buttondevteam.chat; import org.bukkit.Bukkit; -public class AnnouncerThread { +public class AnnouncerThread implements Runnable { private static int AnnounceMessageIndex = 0; - public static void Run() { + @Override + public void run() { while (!PluginMain.Instance.stop) { try { Thread.sleep(PluginMain.AnnounceTime); diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index c2439a4..f641229 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -13,17 +13,12 @@ import org.bukkit.scoreboard.Objective; import com.earth2me.essentials.Essentials; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Nation; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.Town; - import buttondevteam.chat.commands.UnlolCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.formatting.*; +import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel; -import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerBase; @@ -83,8 +78,10 @@ public class ChatProcessing { .registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create(); } - // Returns e.setCancelled for custom event - public static boolean ProcessChat(Channel channel, CommandSender sender, String message) { + public static boolean ProcessChat(TBMCChatEvent e) { + Channel channel = e.getChannel(); + CommandSender sender = e.getSender(); + String message = e.getMessage(); long processstart = System.nanoTime(); if (PluginMain.essentials == null) PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials")); @@ -127,28 +124,20 @@ public class ChatProcessing { try { if (channel.filteranderrormsg != null) { Objective obj = PluginMain.SB.getObjective(channel.ID); - RecipientTestResult result = channel.filteranderrormsg.apply(player); - if (result.errormessage != null) - player.sendMessage("§c" + result.errormessage); - else - for (Player p : Bukkit.getOnlinePlayers()) { - if (p == player) - continue; - result = channel.filteranderrormsg.apply(p); - if (result.errormessage == null) - obj.getScore(p.getName()).setScore(result.score); - else - obj.getScore(p.getName()).setScore(-1); - } - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, result.score, jsonstr)); + int score; + obj.getScore(player.getUniqueId().toString()).setScore(score = e.getMCScore(player)); + for (Player p : Bukkit.getOnlinePlayers()) { + if (player == p) + continue; + obj.getScore(p.getUniqueId().toString()).setScore(e.getMCScore(p)); + } + PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format( + "tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr)); } else PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format("tellraw @a %s", jsonstr)); - } catch ( - - Exception e) { - TBMCCoreAPI.SendException("An error occured while sending a chat message!", e); + } catch (Exception ex) { + TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex); player.sendMessage("§cAn error occured while sending the message."); return true; } diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index c43b2d3..b6c864f 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -5,6 +5,7 @@ import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -17,7 +18,10 @@ import org.htmlcleaner.TagNode; import buttondevteam.chat.commands.YeehawCommand; import buttondevteam.chat.listener.PlayerListener; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.player.TBMCPlayerBase; import com.earth2me.essentials.Essentials; @@ -25,7 +29,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Nation; +import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownyUniverse; @@ -54,6 +60,9 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public static ArrayList Towns; public static ArrayList Nations; + public static Channel TownChat; + public static Channel NationChat; + /** *

* This variable is used as a cache for flair state checking when reading the flair thread. @@ -79,12 +88,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. Towns = new ArrayList(TU.getTownsMap().values()); // Creates a snapshot of towns, new towns will be added when needed Nations = new ArrayList(TU.getNationsMap().values()); // Same here but with nations + TBMCChatAPI.RegisterChatChannel( + TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); + TBMCChatAPI.RegisterChatChannel( + NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); + setupChat(); setupEconomy(); setupPermissions(); new Thread(() -> FlairGetterThreadMethod()).start(); - new Thread(() -> AnnouncerThread.Run()).start(); + new Thread(new AnnouncerThread()).start(); } public Boolean stop = false; @@ -306,4 +320,47 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. return (economy != null); } + + /** + * Return the error message for the message sender if they can't send it and the score + */ + private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) { + if (!(sender instanceof Player)) + return new RecipientTestResult("§cYou are not a player!"); + try { + Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase()); + if (resident != null && resident.getModes().contains("spy")) + return null; + /* + * p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message)); + */ + Town town = null; + if (resident != null && resident.hasTown()) + town = resident.getTown(); + if (town == null) + return new RecipientTestResult("You aren't in a town."); + Nation nation = null; + int index = -1; + if (nationchat) { + if (town.hasNation()) + nation = town.getNation(); + if (nation == null) + return new RecipientTestResult("Your town isn't in a nation."); + index = PluginMain.Nations.indexOf(nation); + if (index < 0) { + PluginMain.Nations.add(nation); + index = PluginMain.Nations.size() - 1; + } + } else { + index = PluginMain.Towns.indexOf(town); + if (index < 0) { + PluginMain.Towns.add(town); + index = PluginMain.Towns.size() - 1; + } + } + return new RecipientTestResult(index); + } catch (NotRegisteredException e) { + return new RecipientTestResult("You (probably) aren't knwon by Towny! (Not in a town)"); + } + } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 1c03829..2664777 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -274,7 +274,7 @@ public class PlayerListener implements Listener { try { if (e.isCancelled()) return; - e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage())); + e.setCancelled(ChatProcessing.ProcessChat(e)); } catch (Exception ex) { for (Player p : Bukkit.getOnlinePlayers()) p.sendMessage("§c!§r[" From 28aeb355734e8a79edb7703126d811827aa45a90 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 7 May 2017 01:09:39 +0200 Subject: [PATCH 5/6] Fixed channels a lot Made Console be able to send messages --- src/main/java/buttondevteam/chat/ChatProcessing.java | 9 +++------ .../buttondevteam/chat/commands/ChatonlyCommand.java | 10 +++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index f641229..84282a2 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -124,12 +124,9 @@ public class ChatProcessing { try { if (channel.filteranderrormsg != null) { Objective obj = PluginMain.SB.getObjective(channel.ID); - int score; - obj.getScore(player.getUniqueId().toString()).setScore(score = e.getMCScore(player)); + int score = -1; for (Player p : Bukkit.getOnlinePlayers()) { - if (player == p) - continue; - obj.getScore(p.getUniqueId().toString()).setScore(e.getMCScore(p)); + obj.getScore(p.getUniqueId().toString()).setScore(score = e.getMCScore(p)); } PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format( "tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr)); @@ -138,7 +135,7 @@ public class ChatProcessing { String.format("tellraw @a %s", jsonstr)); } catch (Exception ex) { TBMCCoreAPI.SendException("An error occured while sending a chat message!", ex); - player.sendMessage("§cAn error occured while sending the message."); + sender.sendMessage("§cAn error occured while sending the message."); return true; } PluginMain.Instance.getServer().getConsoleSender().sendMessage(String.format("%s <%s> %s", channelidentifier, diff --git a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java b/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java index a79e878..e85c7d3 100644 --- a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java @@ -1,14 +1,15 @@ package buttondevteam.chat.commands; import org.bukkit.GameMode; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import buttondevteam.chat.ChatPlayer; -import buttondevteam.lib.chat.TBMCCommandBase; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.PlayerCommandBase; import buttondevteam.lib.player.TBMCPlayer; -public final class ChatonlyCommand extends TBMCCommandBase { //TODO: Add annotation +@CommandClass(modOnly = false) +public final class ChatonlyCommand extends PlayerCommandBase { @Override public String[] GetHelpText(String alias) { @@ -20,8 +21,7 @@ public final class ChatonlyCommand extends TBMCCommandBase { //TODO: Add annotat } @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - Player player = (Player) sender; + public boolean OnCommand(Player player, String alias, String[] args) { ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); p.ChatOnly = true; player.setGameMode(GameMode.SPECTATOR); From 3e1df267cff079dd760059bf6d7e7b7ceb2f8563 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 14 May 2017 01:16:54 +0200 Subject: [PATCH 6/6] Reduced errors and CMDS WORK - EH --- .../java/buttondevteam/chat/PluginMain.java | 19 ++++++++----------- .../appendtext/AppendTextCommandBase.java | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index b6c864f..ffac187 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -40,6 +40,7 @@ import java.lang.String; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -149,25 +150,21 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. } PlayersWithFlairs.add(ign); // Don't redownload even if flair isn't accepted } - try { - Thread.sleep(10); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); } } catch (Exception e) { errorcount++; if (errorcount >= 10) { errorcount = 0; - if (!e.getMessage().contains("Server returned HTTP response code")) + if (!e.getMessage().contains("Server returned HTTP response code") + && !(e instanceof UnknownHostException)) TBMCCoreAPI.SendException("Error while getting flairs from Reddit!", e); } } + try { + Thread.sleep(10000); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } } } diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java index bcf62d0..5b0c1eb 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java @@ -11,7 +11,7 @@ import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayer; -@CommandClass(modOnly = false) +@CommandClass(modOnly = false, excludeFromPath = true) public abstract class AppendTextCommandBase extends TBMCCommandBase { public abstract String[] GetHelpText(String alias);