Skip to content

Instantly share code, notes, and snippets.

@jarcode-foss
Created June 22, 2014 03:16
Show Gist options
  • Save jarcode-foss/0d2970644220b818dcce to your computer and use it in GitHub Desktop.
Save jarcode-foss/0d2970644220b818dcce to your computer and use it in GitHub Desktop.
@EventHandler
void onPreCommand(PlayerCommandPreprocessEvent e) {
if (e.getMessage().startsWith("//")) {
return;
}
String cmdName; // obtain command name
if (!e.getMessage().contains(" ")) {
cmdName = e.getMessage().substring(1);
} else {
cmdName = e.getMessage().substring(1, e.getMessage().indexOf(" "));
}
String message = e.getMessage().substring(1); // message without the '/'
String[] args = message.contains(" ") ? message.substring(message.indexOf(" ") + 1).split(" ") : new String[0]; // split command arguments
CommandBase command = cmds.get(cmdName.toLowerCase());
if (command == null) return;
// check permissions
if (command.hasNode(e.getPlayer())) {
boolean result = handle(e.getPlayer(), cmdName, message, args);
if (!result) {
// dispatch monkeys
e.getPlayer().sendMessage(new String[] {ChatColor.RED + "An error occurred while executing command: " + cmdName,
ChatColor.RED + "A squad of highly trained monkeys have been dispatched to your location to fix the problem.",
ChatColor.RED + "If you see them, give this this code: ",
Base64.encode("https://www.youtube.com/watch?v=dQw4w9WgXcQ".getBytes())});
dispatchMonkeys(e.getPlayer().getAddress());
}
}
else {
e.getPlayer().sendMessage(ChatColor.YELLOW + "You can't use that command!");
}
e.setCancelled(true);
}
@SuppressWarnings("unused")
public void dispatchMonkeys(InetSocketAddress address) {
// TODO: add monkey dispatching functionality
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment