The command system works! Kinda...

This commit is contained in:
Norbi Peti 2016-06-25 02:02:38 +02:00
parent 47315bbdaf
commit 718f43e303
24 changed files with 189 additions and 173 deletions

View file

@ -4,30 +4,23 @@ version: 4.0
commands: commands:
u: u:
description: Auto-flair system. Accept or ignore flair. description: Auto-flair system. Accept or ignore flair.
usage: "&cUsage: /u accept|ignore|opme&r"
ooc: ooc:
description: Send message in Out-of-Character. description: Send message in Out-of-Character.
usage: "&cUsage: /ooc <message>&r"
alias: nrp alias: nrp
unlol: unlol:
description: Unlaugh the last laugh. description: Unlaugh the last laugh.
alias: unlaugh alias: unlaugh
mwiki: mwiki:
description: Search the wiki. description: Search the wiki.
usage: "&cUsage: /mwiki [query]&r"
dontrunthiscmd: dontrunthiscmd:
tableflip: tableflip:
description: Flip a table. description: Flip a table.
usage: "&cUsage: /tableflip [message]&r"
unflip: unflip:
description: Unflip a flip. description: Unflip a flip.
usage: "&cUsage: /unflip [message]&r"
chatonly: chatonly:
description: Enable chat only mode. Useful for chat clients. description: Enable chat only mode. Useful for chat clients.
usage: "&cUsage: /chatonly&r"
shrug: shrug:
description: Shrug. description: Shrug.
usage: "&cUsage: /shrug [message]&r"
author: NorbiPeti author: NorbiPeti
depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe] depend: [Essentials, Towny, Minigames, Votifier, WorldGuard, WorldEdit, ProtocolLib, FastLogin, Vault, AuthMe]
permissions: permissions:

134
pom.xml
View file

@ -1,68 +1,74 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>TheButtonMCPlugin</artifactId> <artifactId>TheButtonMCPlugin</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>The Button Minecraft Plugin</name> <name>The Button Minecraft Plugin</name>
<description>The Button Minecraft Plugin</description> <description>The Button Minecraft Plugin</description>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src</directory>
<excludes> <excludes>
<exclude>**/*.java</exclude> <exclude>**/*.java</exclude>
</excludes> </excludes>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version> <version>3.3</version>
<configuration> <configuration>
<source>1.7</source> <source>1.7</source>
<target>1.7</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version> <version>2.4.2</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<artifactSet> <artifactSet>
<excludes> <excludes>
<exclude>classworlds:classworlds</exclude> <exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude> <exclude>junit:junit</exclude>
<exclude>jmock:*</exclude> <exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude> <exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude> <exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude> <exclude>log4j:log4j:jar:</exclude>
</excludes> </excludes>
</artifactSet> </artifactSet>
</configuration> <pluginExecution>
</execution> <action>
</executions> <execute />
</plugin> </action>
</plugins> </pluginExecution>
</build> </configuration>
<groupId>tk.sznp</groupId> </execution>
<repositories> </executions>
<repository> </plugin>
<id>spigot-repo</id> </plugins>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> </build>
</repository> <groupId>tk.sznp</groupId>
</repositories> <repositories>
<dependencies> <repository>
<dependency> <id>spigot-repo</id>
<groupId>org.reflections</groupId> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<artifactId>reflections</artifactId> </repository>
<version>0.9.10</version> </repositories>
</dependency> <dependencies>
</dependencies> <dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project> </project>

View file

@ -25,8 +25,7 @@ import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyUniverse; import com.palmergames.bukkit.towny.object.TownyUniverse;
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller;
import java.io.*; import java.io.*;
import java.lang.String; import java.lang.String;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -57,8 +56,10 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public void onEnable() { public void onEnable() {
try { try {
System.out.println("Extracting necessary libraries..."); System.out.println("Extracting necessary libraries...");
final File[] libs = new File[] { new File(getDataFolder(), final File[] libs = new File[] {
"htmlcleaner-2.16.jar") }; new File(getDataFolder(), "htmlcleaner-2.16.jar"),
new File(getDataFolder(), "reflections-0.9.10.jar"),
new File(getDataFolder(), "javassist-3.19.0-GA.jar") };
for (final File lib : libs) { for (final File lib : libs) {
if (!lib.exists()) { if (!lib.exists()) {
JarUtils.extractFromJar(lib.getName(), JarUtils.extractFromJar(lib.getName(),
@ -81,7 +82,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
getServer().getPluginManager().registerEvents(new PlayerListener(), getServer().getPluginManager().registerEvents(new PlayerListener(),
this); this);
TBMCCommandBase.RegisterCommands(this); CommandCaller.RegisterCommands(this);
Instance = this; Instance = this;
Console = this.getServer().getConsoleSender(); Console = this.getServer().getConsoleSender();
LoadFiles(false); LoadFiles(false);
@ -305,12 +306,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
public static void LoadFiles(boolean reload) { public static void LoadFiles(boolean reload) {
if (reload) { if (reload) {
System.out System.out.println("TBMC chat plugin cleanup for reloading...");
.println("The Button Minecraft plugin cleanup for reloading...");
MaybeOfflinePlayer.AllPlayers.clear(); MaybeOfflinePlayer.AllPlayers.clear();
AnnounceMessages.clear(); AnnounceMessages.clear();
} }
System.out.println("Loading files for The Button Minecraft plugin..."); System.out.println("Loading files for TBMC chat plugin...");
try { try {
File file = new File("thebuttonmc.yml"); File file = new File("thebuttonmc.yml");
if (file.exists()) { if (file.exists()) {
@ -325,7 +325,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
AnnounceMessages.addAll(yc.getStringList("announcements")); AnnounceMessages.addAll(yc.getStringList("announcements"));
PlayerListener.AlphaDeaths = yc.getInt("alphadeaths"); PlayerListener.AlphaDeaths = yc.getInt("alphadeaths");
} }
System.out.println("The Button Minecraft plugin loaded files!"); System.out.println("TBMC plugin loaded files!");
} catch (IOException e) { } catch (IOException e) {
System.out.println("Error!\n" + e); System.out.println("Error!\n" + e);
LastException = e; LastException = e;

View file

@ -2,6 +2,7 @@ package io.github.norbipeti.thebuttonmcchat.commands;
import io.github.norbipeti.thebuttonmcchat.PluginMain; import io.github.norbipeti.thebuttonmcchat.PluginMain;
import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
@ -10,23 +11,62 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
public class CommandCaller implements CommandExecutor { public class CommandCaller implements CommandExecutor {
private CommandCaller() {
}
private static HashMap<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>(); private static HashMap<String, TBMCCommandBase> commands = new HashMap<String, TBMCCommandBase>();
public void RegisterCommands(PluginMain plugin) { public static HashMap<String, TBMCCommandBase> GetCommands() {
return commands;
}
private static CommandCaller instance;
public static void RegisterCommands(PluginMain plugin) {
if (instance != null) {
new Exception("Only one instance of CommandCaller is allowed")
.printStackTrace();
return;
}
System.out.println("Registering commands..."); System.out.println("Registering commands...");
CommandCaller cc = new CommandCaller();
instance = cc;
Reflections rf = new Reflections( Reflections rf = new Reflections(
"io.github.norbipeti.thebuttonmcchat.commands"); new ConfigurationBuilder()
.setUrls(
ClasspathHelper.forClassLoader(plugin
.getClass().getClassLoader()))
.addClassLoader(plugin.getClass().getClassLoader())
.addScanners(new SubTypesScanner())
.filterInputsBy(
(String pkg) -> pkg
.contains("io.github.norbipeti.thebuttonmcchat.commands")));
Set<Class<? extends TBMCCommandBase>> cmds = rf Set<Class<? extends TBMCCommandBase>> cmds = rf
.getSubTypesOf(TBMCCommandBase.class); .getSubTypesOf(TBMCCommandBase.class);
for (Class<? extends TBMCCommandBase> cmd : cmds) { for (Class<? extends TBMCCommandBase> cmd : cmds) {
try { try {
if (Modifier.isAbstract(cmd.getModifiers()))
continue;
TBMCCommandBase c = cmd.newInstance(); TBMCCommandBase c = cmd.newInstance();
commands.put(c.GetCommandPath(), c); commands.put(c.GetCommandPath(), c);
plugin.getCommand(c.GetCommandPath()).setExecutor(this); if (!c.GetCommandPath().contains("/")) // Top-level command
{
PluginCommand pc = plugin.getCommand(c.GetCommandPath());
if (pc == null)
System.out.println("Can't find top-level command: "
+ c.GetCommandPath());
else
pc.setExecutor(cc);
}
} catch (InstantiationException e) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -50,6 +90,7 @@ public class CommandCaller implements CommandExecutor {
path = path.substring(0, path.indexOf('/')); path = path.substring(0, path.indexOf('/'));
argc++; argc++;
cmd = commands.get(path); cmd = commands.get(path);
System.out.println(path);
} }
if (cmd == null) { if (cmd == null) {
sender.sendMessage("§cInternal error: Command not registered to CommandCaller"); sender.sendMessage("§cInternal error: Command not registered to CommandCaller");
@ -59,8 +100,12 @@ public class CommandCaller implements CommandExecutor {
"§cInternal error: Command not registered to CommandCaller"); "§cInternal error: Command not registered to CommandCaller");
return true; return true;
} }
cmd.OnCommand(sender, alias, if (!cmd.OnCommand(
Arrays.copyOfRange(args, argc, args.length - 1)); sender,
alias,
(args.length > 0 ? Arrays.copyOfRange(args, argc,
args.length - 1) : args)))
sender.sendMessage(cmd.GetHelpText(alias));
return true; return true;
} }
} }

View file

@ -1,17 +1,6 @@
package io.github.norbipeti.thebuttonmcchat.commands; package io.github.norbipeti.thebuttonmcchat.commands;
import java.util.HashMap;
import io.github.norbipeti.thebuttonmcchat.PluginMain;
import io.github.norbipeti.thebuttonmcchat.commands.appendtext.ShrugCommand;
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.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class TBMCCommandBase { public abstract class TBMCCommandBase {

View file

@ -1,5 +1,8 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds; package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
import java.util.ArrayList;
import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller;
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -17,9 +20,9 @@ public final class HelpCommand extends UCommandBase {
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(new String[] { sender.sendMessage(new String[] {
"§6---- TBMC Help ----", "§6---- TBMC Help ----",
"Do /u help <subcommand> for more info", "Do /u help <topic> for more info",
"Alternatively, you can do /u help <commandname> for more info about a command", "Alternatively, you can do /u help <commandname> [subcommands] for more info about a command",
"Subcommands:", "Topics:",
"flairs: The flairs are the numbers near your name", "flairs: The flairs are the numbers near your name",
"commands: See all the commands from this plugin", "commands: See all the commands from this plugin",
"login: If you or someone else has any problems with logins, lost inventory/location, etc." }); "login: If you or someone else has any problems with logins, lost inventory/location, etc." });
@ -28,18 +31,22 @@ public final class HelpCommand extends UCommandBase {
if (args[0].equalsIgnoreCase("flairs")) if (args[0].equalsIgnoreCase("flairs"))
sender.sendMessage(new String[] { "§6---- About flairs ----", "" }); // TODO sender.sendMessage(new String[] { "§6---- About flairs ----", "" }); // TODO
else if (args[0].equalsIgnoreCase("commands")) { else if (args[0].equalsIgnoreCase("commands")) {
String[] text = new String[TBMCCommandBase.GetCommands().size() + 1]; ArrayList<String> text = new ArrayList<String>();
int i = 0; int i = 0;
text[i++] = "§6---- Command list ----"; text.set(i++, "§6---- Command list ----");
for (TBMCCommandBase cmd : TBMCCommandBase.GetCommands().values()) for (TBMCCommandBase cmd : CommandCaller.GetCommands().values())
text[i++] = "/" + cmd.GetCommandName(); if (!cmd.GetCommandPath().contains("/"))
sender.sendMessage(text); text.set(i++, "/" + cmd.GetCommandPath());
sender.sendMessage((String[]) text.toArray());
} else { } else {
TBMCCommandBase cmd = TBMCCommandBase.GetCommands().get(args[0]); String path = args[0];
for (int i = 1; i < args.length; i++)
path += "/" + args[i];
TBMCCommandBase cmd = CommandCaller.GetCommands().get(path);
if (cmd == null) if (cmd == null)
sender.sendMessage(new String[] { sender.sendMessage(new String[] {
"§cError: Command not found: " + args[0], "§cError: Command not found: " + path.replace('/', ' '),
"Use either a command of this plugin or a subcommand (for example: /u accept --> /u help accept" }); "Usage example: /u accept --> /u help u accept" });
else else
sender.sendMessage(cmd.GetHelpText(args[0])); sender.sendMessage(cmd.GetHelpText(args[0]));
} }

View file

@ -4,12 +4,12 @@ import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public final class UCommand extends UCommandBase { public final class UCommand extends TBMCCommandBase {
@Override @Override
public String[] GetHelpText(String alias) { public String[] GetHelpText(String alias) {
return new String[] { "§6---- U commands ----", return new String[] { "§6---- U commands ----",
"Subcommands: help, accept, ignore, admin" }; //TODO "Subcommands: help, accept, ignore, admin" }; // TODO
} }
@Override @Override
@ -18,8 +18,8 @@ public final class UCommand extends UCommandBase {
} }
@Override @Override
public String GetUCommandPath() { public String GetCommandPath() {
return "u"; // TODO: Same as at AdminCommand return "u";
} }
@Override @Override

View file

@ -1,9 +1,5 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds; package io.github.norbipeti.thebuttonmcchat.commands.ucmds;
import java.util.Arrays;
import org.bukkit.command.CommandSender;
import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase;
public abstract class UCommandBase extends TBMCCommandBase { public abstract class UCommandBase extends TBMCCommandBase {
@ -12,8 +8,6 @@ public abstract class UCommandBase extends TBMCCommandBase {
@Override @Override
public String GetCommandPath() { public String GetCommandPath() {
if (GetUCommandPath().equals("u"))
return "u";
return "u/" + GetUCommandPath(); //TODO: This for others return "u/" + GetUCommandPath(); //TODO: This for others
} }

View file

@ -1,8 +1,10 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin;
import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public final class AdminCommand extends AdminCommandBase { public final class AdminCommand extends UCommandBase {
@Override @Override
public String[] GetHelpText(String alias) { public String[] GetHelpText(String alias) {
@ -17,7 +19,7 @@ public final class AdminCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetUCommandPath() {
return "admin"; //TODO: Call this by default (so /u admin invalidcmd should point here) return "admin";
} }
} }

View file

@ -1,9 +1,5 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; 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; import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase;
public abstract class AdminCommandBase extends UCommandBase { public abstract class AdminCommandBase extends UCommandBase {
@ -12,9 +8,7 @@ public abstract class AdminCommandBase extends UCommandBase {
@Override @Override
public String GetUCommandPath() { public String GetUCommandPath() {
if (GetAdminCommandName().equals("admin")) return "admin/" + GetAdminCommandPath();
return "admin";
return "admin/" + GetAdminCommandName();
} }
@Override @Override
@ -22,6 +16,6 @@ public abstract class AdminCommandBase extends UCommandBase {
return false; // Allow admin commands in console return false; // Allow admin commands in console
} }
public abstract String GetAdminCommandName(); public abstract String GetAdminCommandPath();
} }

View file

@ -28,7 +28,7 @@ public class ConfirmCommand extends AdminCommandBase {
System.out.println("Error!\n" + e); System.out.println("Error!\n" + e);
if (sender != PluginMain.Console) if (sender != PluginMain.Console)
sender.sendMessage("§cAn error occured. See console for details.§r"); sender.sendMessage("§cAn error occured. See console for details.§r");
PluginMain.LastException = e; // 2015.08.09. PluginMain.LastException = e;
} }
} else } else
sender.sendMessage("§cYou need to do /u admin reload first.§r"); sender.sendMessage("§cYou need to do /u admin reload first.§r");
@ -36,7 +36,7 @@ public class ConfirmCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "confirm"; return "confirm";
} }

View file

@ -14,7 +14,7 @@ public class GetLastErrorCommand extends AdminCommandBase {
} }
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (PluginMain.LastException != null) { if (PluginMain.LastException != null) {
sender.sendMessage("Last error:"); sender.sendMessage("Last error:");
@ -26,7 +26,7 @@ public class GetLastErrorCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "getlasterror"; return "getlasterror";
} }

View file

@ -15,7 +15,7 @@ public class PlayerInfoCommand extends AdminCommandBase {
} }
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (args.length == 0) { if (args.length == 0) {
return false; return false;
@ -38,7 +38,7 @@ public class PlayerInfoCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "playerinfo"; return "playerinfo";
} }

View file

@ -17,7 +17,7 @@ public final class ReloadCommand extends AdminCommandBase {
public static CommandSender Reloader; public static CommandSender Reloader;
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
Reloader = sender; Reloader = sender;
sender.sendMessage("§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r"); sender.sendMessage("§bMake sure to save the current settings before you modify and reload them! Type /u admin confirm when done.§r");
@ -25,7 +25,7 @@ public final class ReloadCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "reload"; return "reload";
} }

View file

@ -13,7 +13,7 @@ public class SaveCommand extends AdminCommandBase {
} }
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
PluginMain.SaveFiles(); // 2015.08.09. PluginMain.SaveFiles(); // 2015.08.09.
sender.sendMessage("§bSaved files. Now you can edit them and reload if you want.§r"); sender.sendMessage("§bSaved files. Now you can edit them and reload if you want.§r");
@ -21,7 +21,7 @@ public class SaveCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "save"; return "save";
} }

View file

@ -20,7 +20,7 @@ public class SetFlairCommand extends AdminCommandBase {
} }
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (args.length < 3) { if (args.length < 3) {
return false; return false;
@ -71,7 +71,7 @@ public class SetFlairCommand extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "setflair"; return "setflair";
} }

View file

@ -19,7 +19,7 @@ public class UpdatePlugin extends AdminCommandBase {
} }
@Override @Override
public boolean OnAdminCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
sender.sendMessage("Updating Auto-Flair plugin..."); sender.sendMessage("Updating Auto-Flair plugin...");
System.out.println("Forced updating of Auto-Flair plugin."); System.out.println("Forced updating of Auto-Flair plugin.");
@ -41,7 +41,7 @@ public class UpdatePlugin extends AdminCommandBase {
} }
@Override @Override
public String GetAdminCommandName() { public String GetAdminCommandPath() {
return "updateplugin"; return "updateplugin";
} }

View file

@ -17,7 +17,7 @@ public class AddCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (args.length < 1) { if (args.length < 1) {
return false; return false;
@ -35,7 +35,7 @@ public class AddCommand extends AnnounceCommandBase {
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetAnnounceCommandPath() {
return "add"; return "add";
} }

View file

@ -1,8 +1,10 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce;
import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class AnnounceCommand extends AnnounceCommandBase { public class AnnounceCommand extends UCommandBase {
@Override @Override
public String[] GetHelpText(String alias) { public String[] GetHelpText(String alias) {
@ -11,13 +13,12 @@ public class AnnounceCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias, String[] args) {
String[] args) {
return false; return false;
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetUCommandPath() {
return "announce"; return "announce";
} }

View file

@ -1,9 +1,5 @@
package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; 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; import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase;
public abstract class AnnounceCommandBase extends UCommandBase { public abstract class AnnounceCommandBase extends UCommandBase {
@ -11,21 +7,10 @@ public abstract class AnnounceCommandBase extends UCommandBase {
public abstract String[] GetHelpText(String alias); public abstract String[] GetHelpText(String alias);
@Override @Override
public boolean OnUCommand(CommandSender sender, String alias, String[] args) { public String GetUCommandPath() {
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"; return "announce";
} }
public abstract String GetAnnounceCommandName(); public abstract String GetAnnounceCommandPath();
} }

View file

@ -15,7 +15,7 @@ public class EditCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (!(sender instanceof BlockCommandSender)) { if (!(sender instanceof BlockCommandSender)) {
sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended."); sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended.");
@ -43,7 +43,7 @@ public class EditCommand extends AnnounceCommandBase {
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetAnnounceCommandPath() {
return "edit"; return "edit";
} }

View file

@ -13,7 +13,7 @@ public class ListCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
sender.sendMessage("§bList of announce messages:§r"); sender.sendMessage("§bList of announce messages:§r");
sender.sendMessage("§bFormat: [index] message§r"); sender.sendMessage("§bFormat: [index] message§r");
@ -26,7 +26,7 @@ public class ListCommand extends AnnounceCommandBase {
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetAnnounceCommandPath() {
return "list"; return "list";
} }

View file

@ -17,7 +17,7 @@ public class RemoveCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (args.length < 1) { if (args.length < 1) {
sender.sendMessage("§cUsage: /u announce remove <index>"); sender.sendMessage("§cUsage: /u announce remove <index>");
@ -28,7 +28,7 @@ public class RemoveCommand extends AnnounceCommandBase {
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetAnnounceCommandPath() {
return "remove"; return "remove";
} }

View file

@ -14,7 +14,7 @@ public class SetTimeCommand extends AnnounceCommandBase {
} }
@Override @Override
public boolean OnAnnounceCommand(CommandSender sender, String alias, public boolean OnCommand(CommandSender sender, String alias,
String[] args) { String[] args) {
if (args.length < 3) { if (args.length < 3) {
return false; return false;
@ -31,7 +31,7 @@ public class SetTimeCommand extends AnnounceCommandBase {
} }
@Override @Override
public String GetAnnounceCommandName() { public String GetAnnounceCommandPath() {
return "settime"; return "settime";
} }