Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read description #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 42 additions & 47 deletions src/main/java/org/mcsg/survivalgames/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@
import org.mcsg.survivalgames.commands.Spectate;
import org.mcsg.survivalgames.commands.SubCommand;
import org.mcsg.survivalgames.commands.Teleport;
import org.mcsg.survivalgames.commands.Test;
import org.mcsg.survivalgames.commands.Vote;



public class CommandHandler implements CommandExecutor {
private Plugin plugin;
private HashMap < String, SubCommand > commands;
private HashMap < String, Integer > helpinfo;
private MessageManager msgmgr = MessageManager.getInstance();
private final Plugin plugin;
private final HashMap<String, SubCommand> commands;
private final HashMap<String, Integer> helpinfo;
private final MessageManager msgmgr = MessageManager.getInstance();

public CommandHandler(Plugin plugin) {
this.plugin = plugin;
commands = new HashMap < String, SubCommand > ();
helpinfo = new HashMap < String, Integer > ();
commands = new HashMap<String, SubCommand>();
helpinfo = new HashMap<String, Integer>();
loadCommands();
loadHelpInfo();
}

private void loadCommands() {
commands.put("createarena", new CreateArena());
commands.put("join", new Join());
Expand All @@ -72,14 +70,16 @@ private void loadCommands() {
commands.put("list", new ListPlayers());
commands.put("tp", new Teleport());
commands.put("reload", new Reload());
commands.put("test", new Test());

// commands.put("test", new Test());
// commands.put("sponsor", new Sponsor());
}

private void loadHelpInfo() {
//you can do this by iterating thru the hashmap from a certian index btw instead of using a new hashmap,
//plus, instead of doing three differnet ifs, just iterate thru and check if the value == the page
// you can do this by iterating thru the hashmap from a certian index
// btw instead of using a new hashmap,
// plus, instead of doing three differnet ifs, just iterate thru and
// check if the value == the page
helpinfo.put("createarena", 3);
helpinfo.put("join", 1);
helpinfo.put("addwall", 3);
Expand All @@ -99,41 +99,40 @@ private void loadHelpInfo() {
helpinfo.put("leavequeue", 1);
helpinfo.put("list", 1);
commands.put("reload", new Reload());

//helpinfo.put("sponsor", 1);
// helpinfo.put("sponsor", 1);
}

@Override
public boolean onCommand(CommandSender sender, Command cmd1, String commandLabel, String[] args) {
PluginDescriptionFile pdfFile = plugin.getDescription();
if (!(sender instanceof Player)) {
msgmgr.logMessage(PrefixType.WARNING, "Only in-game players can use SurvivalGames commands! ");
return true;
}

Player player = (Player) sender;

if (SurvivalGames.config_todate == false) {
msgmgr.sendMessage(PrefixType.WARNING, "The config file is out of date. Please tell an administrator to reset the config.", player);
return true;
}

if (SurvivalGames.dbcon == false) {
msgmgr.sendMessage(PrefixType.WARNING, "Could not connect to server. Plugin disabled.", player);
return true;
}

if (cmd1.getName().equalsIgnoreCase("survivalgames")) {
if (args == null || args.length < 1) {
if ((args == null) || (args.length < 1)) {
msgmgr.sendMessage(PrefixType.INFO, "Version " + pdfFile.getVersion() + " by Double0negative", player);
msgmgr.sendMessage(PrefixType.INFO, "Type /sg help <player | staff | admin> for command information", player);
return true;
}
if (args[0].equalsIgnoreCase("help")) {
if (args.length == 1) {
help(player, 1);
}
else {
} else {
if (args[1].toLowerCase().startsWith("player")) {
help(player, 1);
return true;
Expand All @@ -145,18 +144,17 @@ public boolean onCommand(CommandSender sender, Command cmd1, String commandLabel
if (args[1].toLowerCase().startsWith("admin")) {
help(player, 3);
return true;
}
else {
} else {
msgmgr.sendMessage(PrefixType.WARNING, args[1] + " is not a valid page! Valid pages are Player, Staff, and Admin.", player);
}
}
return true;
}
String sub = args[0];
Vector < String > l = new Vector < String > ();
Vector<String> l = new Vector<String>();
l.addAll(Arrays.asList(args));
l.remove(0);
args = (String[]) l.toArray(new String[0]);
args = l.toArray(new String[0]);
if (!commands.containsKey(sub)) {
msgmgr.sendMessage(PrefixType.WARNING, "Command doesn't exist.", player);
msgmgr.sendMessage(PrefixType.INFO, "Type /sg help for command information", player);
Expand All @@ -166,15 +164,15 @@ public boolean onCommand(CommandSender sender, Command cmd1, String commandLabel
commands.get(sub).onCommand(player, args);
} catch (Exception e) {
e.printStackTrace();
msgmgr.sendFMessage(PrefixType.ERROR, "error.command", player, "command-["+sub+"] "+Arrays.toString(args));
msgmgr.sendFMessage(PrefixType.ERROR, "error.command", player, "command-[" + sub + "] " + Arrays.toString(args));
msgmgr.sendMessage(PrefixType.INFO, "Type /sg help for command information", player);
}
return true;
}
return false;
}

public void help (Player p, int page) {
public void help(Player p, int page) {
if (page == 1) {
p.sendMessage(ChatColor.BLUE + "------------ " + msgmgr.pre + ChatColor.DARK_AQUA + " Player Commands" + ChatColor.BLUE + " ------------");
}
Expand All @@ -184,25 +182,22 @@ public void help (Player p, int page) {
if (page == 3) {
p.sendMessage(ChatColor.BLUE + "------------ " + msgmgr.pre + ChatColor.DARK_AQUA + " Admin Commands" + ChatColor.BLUE + " ------------");
}

for (String command : commands.keySet()) {
try{
try {
if (helpinfo.get(command) == page) {

msgmgr.sendMessage(PrefixType.INFO, commands.get(command).help(p), p);
}
}catch(Exception e){}
} catch (Exception e) {
}
}
/*for (SubCommand v : commands.values()) {
if (v.permission() != null) {
if (p.hasPermission(v.permission())) {
msgmgr.sendMessage(PrefixType.INFO1, v.help(p), p);
} else {
msgmgr.sendMessage(PrefixType.WARNING, v.help(p), p);
}
} else {
msgmgr.sendMessage(PrefixType.INFO, v.help(p), p);
}
}*/
/*
* for (SubCommand v : commands.values()) { if (v.permission() != null)
* { if (p.hasPermission(v.permission())) {
* msgmgr.sendMessage(PrefixType.INFO1, v.help(p), p); } else {
* msgmgr.sendMessage(PrefixType.WARNING, v.help(p), p); } } else {
* msgmgr.sendMessage(PrefixType.INFO, v.help(p), p); } }
*/
}
}
Loading