Change project and repo name

This commit is contained in:
Norbi Peti 2016-06-23 01:38:35 +02:00
parent 838fa9fe03
commit 71bd4e6606
27 changed files with 1112 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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 + " <message>" };
}
@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;
}
}

View file

@ -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<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>();
public static HashMap<String, TBMCCommandBase> 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();
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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 + " <message> or just /" + alias };
}
@Override
public String GetAppendedText() {
return "¯\\_(ツ)_/¯";
}
@Override
public String GetCommandName() {
return "shrug";
}
}

View file

@ -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 + " <message> or just /" + alias };
}
@Override
public String GetAppendedText() {
return "(╯°□°)╯︵ ┻━┻";
}
@Override
public String GetCommandName() {
return "tableflip";
}
}

View file

@ -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 + " <message> or just /" + alias };
}
@Override
public String GetAppendedText() {
return "┬─┬ ( ゜-゜ノ)";
}
@Override
public String GetCommandName() {
return "unflip";
}
}

View file

@ -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 <username> 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 <username>");
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";
}
}

View file

@ -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 <subcommand> for more info",
"Alternatively, you can do /u help <commandname> 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";
}
}

View file

@ -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 <username> 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";
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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)
}
}

View file

@ -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();
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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 <player>" };
}
@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";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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 <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [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";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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";
}
}

View file

@ -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();
}

View file

@ -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 <index>");
return true;
}
PluginMain.AnnounceMessages.remove(Integer.parseInt(args[0]));
return true;
}
@Override
public String GetAnnounceCommandName() {
return "remove";
}
}