From 71bd4e66068a311104ad6fe34a28dbd7bdaf7166 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 23 Jun 2016 01:38:35 +0200 Subject: [PATCH] Change project and repo name --- .../commands/ChatonlyCommand.java | 42 ++++++++ .../commands/MWikiCommand.java | 42 ++++++++ .../thebuttonmcchat/commands/OOCCommand.java | 44 +++++++++ .../commands/TBMCCommandBase.java | 65 +++++++++++++ .../commands/UnlolCommand.java | 54 +++++++++++ .../appendtext/AppendTextCommandBase.java | 32 +++++++ .../commands/appendtext/ShrugCommand.java | 23 +++++ .../commands/appendtext/TableflipCommand.java | 22 +++++ .../commands/appendtext/UnflipCommand.java | 23 +++++ .../commands/ucmds/AcceptCommand.java | 95 +++++++++++++++++++ .../commands/ucmds/HelpCommand.java | 53 +++++++++++ .../commands/ucmds/IgnoreCommand.java | 46 +++++++++ .../commands/ucmds/UCommand.java | 30 ++++++ .../commands/ucmds/UCommandBase.java | 34 +++++++ .../commands/ucmds/admin/AdminCommand.java | 23 +++++ .../ucmds/admin/AdminCommandBase.java | 44 +++++++++ .../commands/ucmds/admin/ConfirmCommand.java | 44 +++++++++ .../ucmds/admin/GetLastErrorCommand.java | 33 +++++++ .../ucmds/admin/PlayerInfoCommand.java | 45 +++++++++ .../commands/ucmds/admin/ReloadCommand.java | 32 +++++++ .../commands/ucmds/admin/SaveCommand.java | 28 ++++++ .../commands/ucmds/admin/SetFlairCommand.java | 78 +++++++++++++++ .../commands/ucmds/admin/UpdatePlugin.java | 48 ++++++++++ .../commands/ucmds/announce/AddCommand.java | 42 ++++++++ .../ucmds/announce/AnnounceCommand.java | 24 +++++ .../ucmds/announce/AnnounceCommandBase.java | 31 ++++++ .../ucmds/announce/RemoveCommand.java | 35 +++++++ 27 files changed, 1112 insertions(+) create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/GetLastErrorCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/PlayerInfoCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ReloadCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SaveCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AddCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java create mode 100644 src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/RemoveCommand.java diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java new file mode 100644 index 0000000..69f4e43 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java @@ -0,0 +1,42 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.GameMode; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public final class ChatonlyCommand extends TBMCCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[]{ + "§6---- Chat-only mode ----", + "This mode makes you invincible but unable to move, teleport or interact with the world in any way", + "It was designed for chat clients", + "Once enabled, the only way of disabling it is by relogging to the server" + }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player=(Player)sender; + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(player + .getUniqueId()); + p.ChatOnly = true; + player.setGameMode(GameMode.SPECTATOR); + player.sendMessage("§bChat-only mode enabled. You are now invincible."); + return true; + } + + @Override + public String GetCommandName() { + return "chatonly"; + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java new file mode 100644 index 0000000..2799b1d --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java @@ -0,0 +1,42 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import org.bukkit.command.CommandSender; + +public class MWikiCommand extends TBMCCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Minecraft Wiki linker ----", + "Use without parameters to get a link to the wiki", + "You can also search the wiki, for example:", + " /" + + alias + + " beacon - Provides a link that redirects to the beacon's wiki page" }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + String query = ""; + for (int i = 0; i < args.length; i++) + query += args[i]; + query = query.trim(); + if (args.length == 0) + sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/"); + else + sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/index.php?search=" + + query + "&title=Special%3ASearch&go=Go"); + return false; + } + + @Override + public String GetCommandName() { + return "mwiki"; + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java new file mode 100644 index 0000000..3b00481 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java @@ -0,0 +1,44 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public final class OOCCommand extends TBMCCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Out-of-character message ----", + "This command will put a [OCC] tag before your message indicating that you are talking out of character", + "Usage: /" + alias + " " }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + Player player = (Player) sender; + if (args.length == 0) { + return false; + } else { + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = false; + String message = ""; + for (String arg : args) + message += arg + " "; + player.chat(message.substring(0, message.length() - 1)); + MaybeOfflinePlayer.AddPlayerIfNeeded(player.getUniqueId()).RPMode = true; + } + return true; + } + + @Override + public String GetCommandName() { + return "ooc"; + } + + @Override + public boolean GetPlayerOnly() { + return true; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java new file mode 100644 index 0000000..1e1a2d0 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/TBMCCommandBase.java @@ -0,0 +1,65 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import java.util.ArrayList; +import java.util.HashMap; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; +import io.github.norbipeti.thebuttonmcchat.commands.appendtext.TableflipCommand; +import io.github.norbipeti.thebuttonmcchat.commands.appendtext.UnflipCommand; +import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommand; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public abstract class TBMCCommandBase implements CommandExecutor { + + public static void RegisterCommands(PluginMain plugin) { + TBMCCommandBase cmd = new UCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new OOCCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new UnlolCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new MWikiCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new TableflipCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new UnflipCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + cmd = new ChatonlyCommand(); + plugin.getCommand(cmd.GetCommandName()).setExecutor(cmd); + } + + private static HashMap commands = new HashMap(); + + public static HashMap GetCommands() { + return commands; + } + + public TBMCCommandBase() { + commands.put(GetCommandName(), this); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String alias, + String[] args) { + if (GetPlayerOnly() && !(sender instanceof Player)) { + sender.sendMessage("§cError: You must be a player to use this command."); + return true; + } + if (!OnCommand(sender, alias, args)) + sender.sendMessage(GetHelpText(alias)); + return true; + } + + public abstract String[] GetHelpText(String alias); + + public abstract boolean OnCommand(CommandSender sender, String alias, + String[] args); + + public abstract String GetCommandName(); + + public abstract boolean GetPlayerOnly(); +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java new file mode 100644 index 0000000..2121400 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java @@ -0,0 +1,54 @@ +package io.github.norbipeti.thebuttonmcchat.commands; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public final class UnlolCommand extends TBMCCommandBase { + + public static CommandSender Lastlol = null; + public static boolean Lastlolornot; + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Unlol/unlaugh ----", + "This command is based on a joke between NorbiPeti and Ghostise", + "It will make anyone saying one of the recognized laugh strings blind for a few seconds", + "Note that you can only unlaugh laughs that weren't unlaughed before" }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (Lastlol != null) { + if (Lastlol instanceof Player) + ((Player) Lastlol).addPotionEffect(new PotionEffect( + PotionEffectType.BLINDNESS, 10 * 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()); + for (Player pl : PluginMain.GetPlayers()) + pl.sendMessage(msg); + Bukkit.getServer().getConsoleSender().sendMessage(msg); + Lastlol = null; + } + return true; + } + + @Override + public String GetCommandName() { + return "unlol"; + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java new file mode 100644 index 0000000..45c39d0 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java @@ -0,0 +1,32 @@ +package io.github.norbipeti.thebuttonmcchat.commands.appendtext; + +import io.github.norbipeti.thebuttonmcchat.ChatProcessing; +import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; + +import org.bukkit.command.CommandSender; + +public abstract class AppendTextCommandBase extends TBMCCommandBase { + + public abstract String[] GetHelpText(String alias); + + public abstract String GetAppendedText(); + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + String msg = GetAppendedText(); + if (args.length > 0) { + msg = args[0] + " " + msg; + } else + msg = " " + msg; + ChatProcessing.ProcessChat(sender, msg); + return true; + } + + public abstract String GetCommandName(); + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java new file mode 100644 index 0000000..8460d38 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java @@ -0,0 +1,23 @@ +package io.github.norbipeti.thebuttonmcchat.commands.appendtext; + +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 }; + } + + @Override + public String GetAppendedText() { + return "¯\\_(ツ)_/¯"; + } + + @Override + public String GetCommandName() { + return "shrug"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java new file mode 100644 index 0000000..6f81d21 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java @@ -0,0 +1,22 @@ +package io.github.norbipeti.thebuttonmcchat.commands.appendtext; + +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", + "Use either /" + alias + " or just /" + alias }; + } + + @Override + public String GetAppendedText() { + return "(╯°□°)╯︵ ┻━┻"; + } + + @Override + public String GetCommandName() { + return "tableflip"; + } +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java new file mode 100644 index 0000000..259021b --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java @@ -0,0 +1,23 @@ +package io.github.norbipeti.thebuttonmcchat.commands.appendtext; + +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", + "Use either /" + alias + " or just /" + alias }; + } + + @Override + public String GetAppendedText() { + return "┬─┬ ノ( ゜-゜ノ)"; + } + + @Override + public String GetCommandName() { + return "unflip"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java new file mode 100644 index 0000000..7844921 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java @@ -0,0 +1,95 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.FlairStates; +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; +import io.github.norbipeti.thebuttonmcchat.PlayerJoinTimerTask; +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import java.util.Timer; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class AcceptCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Accept flair ----", + "Accepts a flair from Reddit", + "Use /u accept if you commented from multiple accounts" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + final Player player = (Player) sender; + MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromPlayer(player); + if (args.length < 1 && p.UserNames.size() > 1) { + player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept "); + StringBuilder sb = new StringBuilder(); + sb.append("§6Usernames:"); + for (String username : p.UserNames) + sb.append(" ").append(username); + player.sendMessage(sb.toString()); + return true; + } + if (p.FlairState.equals(FlairStates.NoComment) + || p.UserNames.size() == 0) { + player.sendMessage("§cError: You need to write your username to the reddit thread at /r/TheButtonMinecraft§r"); + return true; + } + if (args.length > 0 && !p.UserNames.contains(args[0])) { + player.sendMessage("§cError: Unknown name: " + args[0] + "§r"); + return true; + } + if (p.Working) { + player.sendMessage("§cError: Something is already in progress.§r"); + return true; + } + + if ((args.length > 0 ? args[0] : p.UserNames.get(0)).equals(p.UserName)) { + player.sendMessage("§cYou already have this user's flair.§r"); + return true; + } + if (args.length > 0) + p.UserName = args[0]; + else + p.UserName = p.UserNames.get(0); + + player.sendMessage("§bObtaining flair..."); + p.Working = true; + Timer timer = new Timer(); + PlayerJoinTimerTask tt = new PlayerJoinTimerTask() { + @Override + public void run() { + try { + PluginMain.Instance.DownloadFlair(mp); + } catch (Exception e) { + e.printStackTrace(); + player.sendMessage("Sorry, but an error occured while trying to get your flair. Please contact a mod."); + mp.Working = false; + return; + } + + if (mp.FlairState.equals(FlairStates.Commented)) { + player.sendMessage("Sorry, but your flair isn't recorded. Please ask an admin to set it for you. Also, prepare a comment on /r/thebutton, if possible."); + mp.Working = false; + return; + } + String flair = mp.GetFormattedFlair(); + mp.FlairState = FlairStates.Accepted; + PluginMain.ConfirmUserMessage(mp); + player.sendMessage("§bYour flair has been set:§r " + flair); + mp.Working = false; + } + }; + tt.mp = p; + timer.schedule(tt, 20); + return true; + } + + @Override + public String GetUCommandName() { + return "accept"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java new file mode 100644 index 0000000..15367e4 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java @@ -0,0 +1,53 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; + +import org.bukkit.command.CommandSender; + +public final class HelpCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Help ----", + "Prints out help messages for the TBMC plugin" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + if (args.length == 0) { + sender.sendMessage(new String[] { + "§6---- TBMC Help ----", + "Do /u help for more info", + "Alternatively, you can do /u help for more info about a command", + "Subcommands:", + "flairs: The flairs are the numbers near your name", + "commands: See all the commands from this plugin", + "login: If you or someone else has any problems with logins, lost inventory/location, etc." }); + return true; + } + if (args[0].equalsIgnoreCase("flairs")) + sender.sendMessage(new String[] { "§6---- About flairs ----", "" }); // TODO + else if (args[0].equalsIgnoreCase("commands")) { + String[] text = new String[TBMCCommandBase.GetCommands().size() + 1]; + int i = 0; + text[i++] = "§6---- Command list ----"; + for (TBMCCommandBase cmd : TBMCCommandBase.GetCommands().values()) + text[i++] = "/" + cmd.GetCommandName(); + sender.sendMessage(text); + } else { + TBMCCommandBase cmd = TBMCCommandBase.GetCommands().get(args[0]); + if (cmd == null) + sender.sendMessage(new String[] { + "§cError: Command not found: " + args[0], + "Use either a command of this plugin or a subcommand (for example: /u accept --> /u help accept" }); + else + sender.sendMessage(cmd.GetHelpText(args[0])); + } + return true; + } + + @Override + public String GetUCommandName() { + return "help"; + } +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java new file mode 100644 index 0000000..93fcf64 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java @@ -0,0 +1,46 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import io.github.norbipeti.thebuttonmcchat.FlairStates; +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public final class IgnoreCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Ignore flair ----", + "Stop the \"write your name in the thread\" message from showing up", + "Use /u ignore if you commented from multiple accounts" }; + } + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + final Player player = (Player) sender; + MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromPlayer(player); + if (p.FlairState.equals(FlairStates.Accepted)) { + player.sendMessage("§cYou can only ignore the \"write yoőu rname in the thread\" message."); + return true; + } + if (p.FlairState.equals(FlairStates.Commented)) { + player.sendMessage("Sorry, but your flair isn't recorded. Please ask a mod to set it for you."); + return true; + } + if (!p.FlairState.equals(FlairStates.Ignored)) { + p.FlairState = FlairStates.Ignored; + p.SetFlair(MaybeOfflinePlayer.FlairTimeNone); + p.UserName = ""; + player.sendMessage("§bYou have ignored the message. You can still use /u accept to get a flair.§r"); + } else + player.sendMessage("§cYou already ignored the message.§r"); + return true; + } + + @Override + public String GetUCommandName() { + return "ignore"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java new file mode 100644 index 0000000..fc7e54f --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java @@ -0,0 +1,30 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import org.bukkit.command.CommandSender; + +import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; + +public final class UCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- U commands ----", + "Subcommands: help, accept, ignore, admin" }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + return false; + } + + @Override + public String GetUCommandName() { + return "u"; //TODO: Same as at AdminCommand + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java new file mode 100644 index 0000000..84eac45 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java @@ -0,0 +1,34 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds; + +import java.util.Arrays; + +import org.bukkit.command.CommandSender; + +import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; + +public abstract class UCommandBase extends TBMCCommandBase { + + public abstract String[] GetHelpText(String alias); + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + return OnUCommand(sender, alias, + Arrays.copyOfRange(args, 1, args.length)); + } + + public abstract boolean OnUCommand(CommandSender sender, String alias, + String[] args); + + @Override + public String GetCommandName() { + return "u"; + } + + public abstract String GetUCommandName(); //TODO: Help for /u commands + + @Override + public boolean GetPlayerOnly() { + return true; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java new file mode 100644 index 0000000..eeaa2fd --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java @@ -0,0 +1,23 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import org.bukkit.command.CommandSender; + +public final class AdminCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Admin ----", + "These commands are for mods only.", "Subcommands: reload, " }; // TODO + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + return false; + } + + @Override + public String GetAdminCommandName() { + return "admin"; //TODO: Call this by default (so /u admin invalidcmd should point here) + } +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java new file mode 100644 index 0000000..5155f6a --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java @@ -0,0 +1,44 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import java.util.Arrays; + +import org.bukkit.command.CommandSender; + +import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase; + +public abstract class AdminCommandBase extends UCommandBase { + + public abstract String[] GetHelpText(String alias); + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { // TODO: + // Only + // mods/admins + // should + // be + // able + // to + // use + // these + if (args.length == 0) + return false; + return OnAdminCommand(sender, alias, + Arrays.copyOfRange(args, 1, args.length)); + } + + public abstract boolean OnAdminCommand(CommandSender sender, String alias, + String[] args); // TODO: Actually call subcommands + + @Override + public String GetUCommandName() { + return "admin"; + } + + @Override + public boolean GetPlayerOnly() { + return false; // Allow admin commands in console + } + + public abstract String GetAdminCommandName(); + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java new file mode 100644 index 0000000..63f2218 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java @@ -0,0 +1,44 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class ConfirmCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6--- Confirm reload ----", + "Use this after using /u admin reload and /u admin save" }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + if (ReloadCommand.Reloader == sender) { + try { + if (sender != PluginMain.Console) + PluginMain.Console + .sendMessage("§6-- Reloading The Button Minecraft plugin...§r"); + sender.sendMessage("§6-- Reloading The Button Minecraft plugin...§r"); + PluginMain.LoadFiles(true); + if (sender != PluginMain.Console) + PluginMain.Console.sendMessage("§6-- Reloading done!§r"); + sender.sendMessage("§6-- Reloading done!§r"); + } catch (Exception e) { + System.out.println("Error!\n" + e); + if (sender != PluginMain.Console) + sender.sendMessage("§cAn error occured. See console for details.§r"); + PluginMain.LastException = e; // 2015.08.09. + } + } else + sender.sendMessage("§cYou need to do /u admin reload first.§r"); + return true; + } + + @Override + public String GetAdminCommandName() { + return "confirm"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/GetLastErrorCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/GetLastErrorCommand.java new file mode 100644 index 0000000..e2fd032 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/GetLastErrorCommand.java @@ -0,0 +1,33 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class GetLastErrorCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Get last error ----", + "This command returns the last exception", + "Note that not all exceptions are recorded" }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + if (PluginMain.LastException != null) { + sender.sendMessage("Last error:"); + sender.sendMessage(PluginMain.LastException.toString()); + PluginMain.LastException = null; + } else + sender.sendMessage("There were no exceptions."); + return true; + } + + @Override + public String GetAdminCommandName() { + return "getlasterror"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/PlayerInfoCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/PlayerInfoCommand.java new file mode 100644 index 0000000..1d0fd12 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/PlayerInfoCommand.java @@ -0,0 +1,45 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.command.CommandSender; + +public class PlayerInfoCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Player info ----", + "Shows some info about the player's flair, Reddit username(s) and other data known by the plugin", + "Usage: /u admin playerinfo " }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + if (args.length == 0) { + return false; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromName(args[0]); + if (p == null) { + sender.sendMessage("§cPlayer not found: " + args[0] + + " - Currently only online players can be viewed§r"); + return true; + } + StringBuilder sb = new StringBuilder(); + sb.append("§6Usernames:"); + for (String username : p.UserNames) + sb.append(" ").append(username); + sender.sendMessage(new String[] { "Player name: " + p.PlayerName, + "User flair: " + p.GetFormattedFlair(), + "Username: " + p.UserName, "Flair state: " + p.FlairState, + sb.toString(), "FCount: " + p.FCount, "FDeaths: " + p.FDeaths }); + return true; + } + + @Override + public String GetAdminCommandName() { + return "playerinfo"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ReloadCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ReloadCommand.java new file mode 100644 index 0000000..abe26c8 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ReloadCommand.java @@ -0,0 +1,32 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import org.bukkit.command.CommandSender; + +public final class ReloadCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Reload plugin ----", + "This command allows you to reload the plugin's config", + "This isn't the same as reloading the server, and should not cause any issues with other plugins", + "Save the config by using /u admin save before you reload it", + "Because of this, you'll need to confirm the reload with /u admin confirm" }; + } + + public static CommandSender Reloader; + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + Reloader = sender; + sender.sendMessage("§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); + return true; + } + + @Override + public String GetAdminCommandName() { + return "reload"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SaveCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SaveCommand.java new file mode 100644 index 0000000..2cda245 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SaveCommand.java @@ -0,0 +1,28 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class SaveCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Save config ----", + "This command saves the config file(s)" }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + PluginMain.SaveFiles(); // 2015.08.09. + sender.sendMessage("§bSaved files. Now you can edit them and reload if you want.§r"); + return true; + } + + @Override + public String GetAdminCommandName() { + return "save"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java new file mode 100644 index 0000000..387dcd6 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/SetFlairCommand.java @@ -0,0 +1,78 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.FlairStates; +import io.github.norbipeti.thebuttonmcchat.MaybeOfflinePlayer; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SetFlairCommand extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Set flair -----", + "Set a flair for a player", + "Usage: /u admin setflair [username]", + "Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)", + "Example 2: /u admin setflair iie 0 true asde --> purple (0s)" }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + if (args.length < 3) { + return false; + } + Player p = Bukkit.getPlayer(args[0]); + if (p == null) { + sender.sendMessage("§cPlayer not found.&r"); + return true; + } + short flairtime = 0x00; + if (args[1].equalsIgnoreCase("non-presser")) + flairtime = MaybeOfflinePlayer.FlairTimeNonPresser; + else if (args[1].equalsIgnoreCase("cant-press")) + flairtime = MaybeOfflinePlayer.FlairTimeCantPress; + else if (args[1].equalsIgnoreCase("none")) + flairtime = MaybeOfflinePlayer.FlairTimeNone; + else { + try { + flairtime = Short.parseShort(args[1]); + } catch (Exception e) { + sender.sendMessage("§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage."); + return true; + } + } // TODO: Split config to per-player + boolean cheater = false; + if (args[2].equalsIgnoreCase("true")) + cheater = true; + else if (args[2].equalsIgnoreCase("false")) + cheater = false; + else { + sender.sendMessage("§cUnknown value for cheater parameter. Run without args to see usage."); + return true; + } + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AddPlayerIfNeeded(p + .getUniqueId()); + mp.SetFlair(flairtime, cheater); + mp.FlairState = FlairStates.Accepted; + if (args.length < 4) + mp.UserName = ""; + else { + mp.UserName = args[3]; + if (!mp.UserNames.contains(args[3])) + mp.UserNames.add(args[3]); + } + sender.sendMessage("§bThe flair has been set. Player: " + mp.PlayerName + + " Flair: " + mp.GetFormattedFlair() + "§r"); + return true; + } + + @Override + public String GetAdminCommandName() { + return "setflair"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java new file mode 100644 index 0000000..7ace2ab --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/UpdatePlugin.java @@ -0,0 +1,48 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.commons.io.FileUtils; +import org.bukkit.command.CommandSender; + +public class UpdatePlugin extends AdminCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Update plugin ----", + "This command downloads the latest version of the plugin from GitHub" }; + } + + @Override + public boolean OnAdminCommand(CommandSender sender, String alias, + String[] args) { + sender.sendMessage("Updating Auto-Flair plugin..."); + System.out.println("Forced updating of Auto-Flair plugin."); + URL url; + try { + url = new URL( + "https://github.com/NorbiPeti/thebuttonmcchat/raw/master/TheButtonAutoFlair.jar"); + FileUtils.copyURLToFile(url, new File( + "plugins/TheButtonAutoFlair.jar")); + sender.sendMessage("Updating done!"); + } catch (MalformedURLException e) { + System.out.println("Error!\n" + e); + PluginMain.LastException = e; + } catch (IOException e) { + System.out.println("Error!\n" + e); + PluginMain.LastException = e; + } + return true; + } + + @Override + public String GetAdminCommandName() { + return "updateplugin"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AddCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AddCommand.java new file mode 100644 index 0000000..baf0a19 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AddCommand.java @@ -0,0 +1,42 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class AddCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Add announcement ----", + "This command adds a new announcement", + "Note: Please avoid using this command, if possible", + "Instead, use the command blocks in flatworld to set announcements", + "This makes editing announcements easier" }; + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + if (args.length < 1) { + return false; + } + StringBuilder sb = new StringBuilder(); + for (int i = 2; i < args.length; i++) { + sb.append(args[i]); + if (i != args.length - 1) + sb.append(" "); + } + String finalmessage = sb.toString().replace('&', '§'); + PluginMain.AnnounceMessages.add(finalmessage); + sender.sendMessage("§bAnnouncement added. - Plase avoid using this command if possible, see /u announce add without args.§r"); + return true; + } + + @Override + public String GetAnnounceCommandName() { + return "add"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java new file mode 100644 index 0000000..f11a6ee --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java @@ -0,0 +1,24 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import org.bukkit.command.CommandSender; + +public class AnnounceCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Announce ----", + "Subcommands: add, settime, remove, list, edit" }; // TODO + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + return false; + } + + @Override + public String GetAnnounceCommandName() { + return "announce"; + } + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java new file mode 100644 index 0000000..cb9645a --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java @@ -0,0 +1,31 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import java.util.Arrays; + +import org.bukkit.command.CommandSender; + +import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase; + +public abstract class AnnounceCommandBase extends UCommandBase { + + public abstract String[] GetHelpText(String alias); + + @Override + public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + if (args.length == 0) + return false; + return OnAnnounceCommand(sender, alias, + Arrays.copyOfRange(args, 1, args.length)); //TODO: Only allow OPs and mods to use it + } + + public abstract boolean OnAnnounceCommand(CommandSender sender, + String alias, String[] args); + + @Override + public String GetUCommandName() { + return "announce"; + } + + public abstract String GetAnnounceCommandName(); + +} diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/RemoveCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/RemoveCommand.java new file mode 100644 index 0000000..3650dc5 --- /dev/null +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/RemoveCommand.java @@ -0,0 +1,35 @@ +package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; + +import io.github.norbipeti.thebuttonmcchat.PluginMain; + +import org.bukkit.command.CommandSender; + +public class RemoveCommand extends AnnounceCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { + "§6---- Remove announcement ----", + "This command removes an announcement", + "Note: Please avoid using this command, if possible", + "Instead, use the command blocks in flatworld to set announcements", + "This makes editing announcements easier" }; + } + + @Override + public boolean OnAnnounceCommand(CommandSender sender, String alias, + String[] args) { + if (args.length < 1) { + sender.sendMessage("§cUsage: /u announce remove "); + return true; + } + PluginMain.AnnounceMessages.remove(Integer.parseInt(args[0])); + return true; + } + + @Override + public String GetAnnounceCommandName() { + return "remove"; + } + +}