Last active
December 18, 2015 10:59
-
-
Save fpigerre/5772681 to your computer and use it in GitHub Desktop.
Sk89q Command Framework - Main Code ripped from OresomeAdmin by @Zachoz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.ChatColor; | |
import org.bukkit.World; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.command.ConsoleCommandSender; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.PluginDescriptionFile; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import com.sk89q.bukkit.util.CommandsManagerRegistration; | |
import com.sk89q.minecraft.util.commands.*; | |
/** | |
* OresomeAdmin | OresomeCraft administation plugin | |
* | |
* @author Zach De Koning (Zachoz) | |
*/ | |
/********************************************************************** | |
* Code to use for sk89q's command framework goes below this comment! * | |
**********************************************************************/ | |
private void registerCommands() { | |
final OresomeAdmin plugin = this; | |
// Register the commands that we want to use | |
commands = new CommandsManager<CommandSender>() { | |
@Override | |
public boolean hasPermission(CommandSender player, String perm) { | |
return plugin.hasPermission(player, perm); | |
} | |
}; | |
commands.setInjector(new SimpleInjector(this)); | |
final CommandsManagerRegistration cmdRegister = new CommandsManagerRegistration(this, commands); | |
cmdRegister.register(CommandHandler.class); | |
} | |
@Override | |
public boolean onCommand(CommandSender sender, Command cmd, String label, | |
String[] args) { | |
try { | |
commands.execute(cmd.getName(), args, sender, sender); | |
} catch (CommandPermissionsException e) { | |
sender.sendMessage(ChatColor.RED + "You don't have permission."); | |
} catch (MissingNestedCommandException e) { | |
sender.sendMessage(ChatColor.RED + e.getUsage()); | |
} catch (CommandUsageException e) { | |
sender.sendMessage(ChatColor.RED + e.getMessage()); | |
sender.sendMessage(ChatColor.RED + e.getUsage()); | |
} catch (WrappedCommandException e) { | |
if (e.getCause() instanceof NumberFormatException) { | |
sender.sendMessage(ChatColor.RED + "Number expected, string received instead."); | |
} else { | |
sender.sendMessage(ChatColor.RED + "An error has occurred. See console."); | |
e.printStackTrace(); | |
} | |
} catch (CommandException e) { | |
sender.sendMessage(ChatColor.RED + e.getMessage()); | |
} | |
return true; | |
} | |
public boolean hasPermission(CommandSender sender, String perm) { | |
if (!(sender instanceof Player)) { | |
if (sender.hasPermission(perm)) { | |
return ((sender.isOp() && (opPermissions || sender instanceof ConsoleCommandSender))); | |
} | |
} | |
return hasPermission(sender, ((Player) sender).getWorld(), perm); | |
} | |
public boolean hasPermission(CommandSender sender, World world, String perm) { | |
if ((sender.isOp() && opPermissions) || sender instanceof ConsoleCommandSender || sender.hasPermission(perm)) { | |
return true; | |
} | |
return false; | |
} | |
public void checkPermission(CommandSender sender, String perm) | |
throws CommandPermissionsException { | |
if (!hasPermission(sender, perm)) { | |
throw new CommandPermissionsException(); | |
} | |
} | |
public void checkPermission(CommandSender sender, World world, String perm) | |
throws CommandPermissionsException { | |
if (!hasPermission(sender, world, perm)) { | |
throw new CommandPermissionsException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment