Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package iwcs.pony;
- import java.io.IOException;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.entity.Player;
- import ru.tehkode.permissions.bukkit.PermissionsEx;
- import iwcs.pony.Main;
- import iwcs.pony.Database;
- public class Util {
- private Main Main = new Main();
- private Database Database = new Database();
- //Variables
- //Importing
- private Logger console = Main.console;
- //Own
- public String[] errors = { //MaxError 11
- "Called when config file existed but could not be loaded." + ChatColor.GRAY + " (public void iwcs.pony.Main.onEnable(), IOException or InvalidConfigurationException)",
- "Called when player or permission is not specified when checking for permissions. Most probably an internal error." + ChatColor.GRAY + " (public void iwcs.pony.Util.hasPerm(Player pony, String permission, boolean byDefault), some argument is null)",
- "Called when the plugin has not initialized correctly, reload it." + ChatColor.GRAY + " (public boolean iwcs.pony.Util.hasPerm(Player pony, String permission, boolean byDefault), iwcs.Main.permissionPlugin == 0)",
- "Called when player not specified when sending \"Insufficient permissions\" to someone. Most probably an internal error." + ChatColor.GRAY + " (public void iwcs.pony.Util.noPerm(Player pony), pony == null)",
- "Called when database file existed but could not be loaded." + ChatColor.GRAY + " (public void iwcs.pony.Main.onEnable(), IOException or InvalidConfigurationException)",
- "Called when player's race in the database is unknown." + ChatColor.GRAY + " (public String iwcs.pony.Database.getRace(Player pony), value in database doesn't make any sence)",
- "Called when database could not be saved due to IOException." + ChatColor.GRAY + " (public void iwcs.pony.Database.save(), IOException)",
- "Called when player not specified when saving him to database." + ChatColor.GRAY + " (public void iwcs.pony.Database.save(Player pony, String newValue), pony == null)",
- "Called when the new race is null or unknown when changing race." + ChatColor.GRAY + " (public void iwcs.pony.Database.setRace(Player pony, String newRace), newRace doesn't make any sence)",
- "Called when the race of the command sender is unknown. One of the errors you'll actually see sometimes. :)" + ChatColor.GRAY + " (private void iwcs.pony.Main.commandPony(CommandSender sender, String[] args), public String iwcs.pony.Database.getPony(Player pony) returned \"unset\" or \"unpresent\")",
- "Called when the race of the requested player is unknown. One of the errors you'll actually see sometimes. :)" + ChatColor.GRAY + " (private void iwcs.pony.Main.commandPlgn(CommandSender sender, String[] args), public String config.getString(args[1]) returned \"unset\" or \"unpresent\")",
- };
- public void throwException(Exception exception, int errorNumber) {
- console.info("Uups! I've just caught " + ((exception !=null) ? exception.toString() : "unknown exception") + "!");
- console.info("To see details, type /ponyplgn gerror " + errorNumber);
- if (!(exception == null)) {exception.printStackTrace();} else {console.info("Unspecified exception");}
- double random = Math.random();
- if (random < 0.33) {
- console.info("Derp-derp-derp!");
- } else if (random < 0.66) {
- console.info("Muffin!");
- } else {
- console.info("I'm a cross-eyed pegasus!");
- }
- }
- public String gerror(int errorNumber) {
- if (errorNumber > -1 && errorNumber < errors.length) {
- return "Error #" + errorNumber + ": " + errors[errorNumber];
- } else {
- return "Such error doesn't exist";
- }
- }
- public void help(int command, CommandSender sender) {
- if (command == 0) {
- if (sender instanceof Player) {
- sender.sendMessage(Main.helpForPony);
- } else {
- for (int i = 0; i < Main.helpForPony.length; i++) {
- console.info(Main.helpForPony[i]);
- }
- }
- } else if (command == 1) {
- if (sender instanceof Player) {
- sender.sendMessage(Main.helpForPlgn);
- } else {
- for (int i = 0; i < Main.helpForPlgn.length; i++) {
- console.info(Main.helpForPlgn[i]);
- }
- }
- } else if (command == 2) {
- if (sender instanceof Player) {
- sender.sendMessage(Main.helpForCast);
- } else {
- console.info("This command can only be sent by a player");
- }
- } else {
- throw new IllegalArgumentException();
- }
- }
- public boolean hasPerm(Player pony, String permission, boolean byDefault) {
- if (pony == null || permission == null) {
- throwException(new NullPointerException(), 1); //* * * ERROR 1 * * *
- return false;
- } else {
- switch (Main.permissionPlugin) {
- case 1:
- return PermissionsEx.getUser(pony).has(permission);
- case 2:
- return pony.hasPermission(permission);
- case 3:
- if (byDefault | pony.isOp()) {
- return true;
- } else {
- return false;
- }
- default:
- throwException(new IllegalArgumentException(), 2); //* * * ERROR 2 * * *
- return false;
- }
- }
- }
- public void noPerm(Player pony) {
- if (pony != null) {
- pony.sendMessage(ChatColor.GRAY + "Insufficient permissions");
- } else {
- throwException(new NullPointerException(), 3); //* * * ERROR 3 * * *
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement