Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Changed command structure and allowed 'sub-commands' to be called as …
Browse files Browse the repository at this point in the history
…commands.

This is one possible usage of having sub commands being actual commandExecutors.
  • Loading branch information
SagaciousZed committed Jul 15, 2012
1 parent 338be8c commit 1b54781
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/envisionred/smartexp/SmartExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import java.io.InputStream;
import java.util.logging.Logger;

import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import com.envisionred.smartexp.commands.CheckCommand;
import com.envisionred.smartexp.commands.ExpCommand;
import com.envisionred.smartexp.commands.HelpCommand;
import com.envisionred.smartexp.commands.ReloadCommand;


import MetricsDependencies.Metrics;
Expand All @@ -28,12 +32,25 @@ public void onEnable() {
if (!(new File(getDataFolder(), "blocks.yml").exists())) {
saveResource("blocks.yml", false);
}

// StartMetrics();

getServer().getPluginManager().registerEvents(new EntityListner(this), this);
getServer().getPluginManager().registerEvents(new BlockListener(this), this);


final CommandExecutor helpCommandExecutor = new CheckCommand(this);
final CommandExecutor checkCommandExecutor = new HelpCommand(this);
final CommandExecutor reloadCommandExecutor = new ReloadCommand(this);
final ExpCommand expCommand = new ExpCommand(this);
getCommand("exp").setExecutor(expCommand);

this.getCommand("exp-check").setExecutor(checkCommandExecutor);
this.getCommand("exp-help").setExecutor(helpCommandExecutor);
this.getCommand("exp-reload").setExecutor(reloadCommandExecutor);

expCommand.registerCommand("check", checkCommandExecutor);
expCommand.registerCommand("help", helpCommandExecutor);
expCommand.registerCommand("reload", reloadCommandExecutor);
this.getCommand("exp").setExecutor(expCommand);

this.getLogger().info("EnvisionRed's SmartExp Enabled :D");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class ExpCommand implements CommandExecutor {
public ExpCommand(SmartExp plugin) {
if (plugin == null) throw new IllegalArgumentException("plugin cannot be null");
this.plugin = plugin;
this.registerCommand("help", new HelpCommand(plugin));
this.registerCommand("reload", new ReloadCommand(plugin));
this.registerCommand("check", new CheckCommand(plugin));
}

public void registerCommand(String command, CommandExecutor commandExecutor) {
if (commandExecutor == null || command == null || command.isEmpty()) {
throw new IllegalArgumentException("invalid command paramters specified");
}
this.commandMap.put(command.toLowerCase(), commandExecutor);
}

Expand All @@ -48,8 +48,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
} else {
sender.sendMessage(ChatColor.GREEN + "SmartExp version " + plugin.getDescription().getVersion() + " by" + ChatColor.DARK_RED + " EnvisionRed");
sender.sendMessage(ChatColor.GREEN + "Do " + ChatColor.AQUA + "/exp help " + ChatColor.GREEN + "to see help for the plugin.");
return true;
}
return false;
}

private static final <T> T[] popArray(T[] args) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ commands:
exp:
description: Shows the version of SmartEXp
default: op
usage: See /exp-help
exp-check:
description: Check your current exp or another player
usage: /<command> [player name]
exp-help:
description: Displays
usage: /<command>
exp-reload:
description: Reloads the configuration
usage: /<command>
permissions:
SmartExp.*:
description: Allows use of all commands from SmartExp
Expand Down

0 comments on commit 1b54781

Please sign in to comment.