Search in sources :

Example 1 with CommandException

use of org.bukkit.command.CommandException in project Minigames by AddstarMC.

the class CreateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        Player player = (Player) sender;
        String mgmName = args[0];
        if (MinigameUtils.sanitizeYamlString(mgmName) == null) {
            throw new CommandException("Name is not valid for use in a Config.");
        }
        if (!plugin.getMinigameManager().hasMinigame(mgmName)) {
            MinigameType type = MinigameType.SINGLEPLAYER;
            if (args.length >= 2) {
                if (MinigameType.hasValue(args[1].toUpperCase())) {
                    type = MinigameType.valueOf(args[1].toUpperCase());
                } else {
                    MessageManager.sendMessage(player, MinigameMessageType.ERROR, null, "command.createMinigame.noName", args[1]);
                }
            }
            Minigame mgm = new Minigame(mgmName, type, player.getLocation());
            MessageManager.sendMessage(player, MinigameMessageType.INFO, null, "command.create.success", args[0]);
            List<String> mgs = null;
            if (plugin.getConfig().contains("minigames")) {
                mgs = plugin.getConfig().getStringList("minigames");
            } else {
                mgs = new ArrayList<>();
            }
            mgs.add(mgmName);
            plugin.getConfig().set("minigames", mgs);
            plugin.saveConfig();
            mgm.saveMinigame();
            plugin.getMinigameManager().addMinigame(mgm);
        } else {
            MessageManager.sendMessage(sender, MinigameMessageType.ERROR, null, "command.create.nameexists");
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) CommandException(org.bukkit.command.CommandException) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 2 with CommandException

use of org.bukkit.command.CommandException in project Glowstone by GlowstoneMC.

the class RconHandler method handleCommand.

private void handleCommand(ChannelHandlerContext ctx, String payload, int requestId) {
    if (!loggedIn) {
        sendResponse(ctx, FAILURE, TYPE_COMMAND, "");
        return;
    }
    try {
        RemoteServerCommandEvent event = EventFactory.getInstance().callEvent(new RemoteServerCommandEvent(commandSender, payload));
        if (event.isCancelled()) {
            return;
        }
        rconServer.getServer().dispatchCommand(commandSender, event.getCommand());
        String message = commandSender.flush();
        if (!rconServer.getServer().useRconColors()) {
            message = ChatColor.stripColor(message);
        }
        sendLargeResponse(ctx, requestId, message);
    } catch (CommandException e) {
        sendLargeResponse(ctx, requestId, String.format("Error executing: %s (%s)", payload, e.getMessage()));
    }
}
Also used : RemoteServerCommandEvent(org.bukkit.event.server.RemoteServerCommandEvent) CommandException(org.bukkit.command.CommandException)

Example 3 with CommandException

use of org.bukkit.command.CommandException in project RedProtect by FabioZumbi12.

the class RPUtil method initMysql.

private static void initMysql() throws Exception {
    for (World world : Bukkit.getWorlds()) {
        String url = "jdbc:mysql://" + RPConfig.getString("mysql.host") + "/";
        String reconnect = "?autoReconnect=true";
        String tableName = RPConfig.getString("mysql.table-prefix") + world.getName();
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e2) {
            RedProtect.get().logger.severe("Couldn't find the driver for MySQL! com.mysql.jdbc.Driver.");
            return;
        }
        PreparedStatement st = null;
        try {
            if (!checkTableExists(tableName)) {
                // create db
                Connection con = DriverManager.getConnection(url + RPConfig.getString("mysql.db-name") + reconnect, RPConfig.getString("mysql.user-name"), RPConfig.getString("mysql.user-pass"));
                st = con.prepareStatement("CREATE TABLE `" + tableName + "` (name varchar(20) PRIMARY KEY NOT NULL, leaders longtext, admins longtext, members longtext, maxMbrX int, minMbrX int, maxMbrZ int, minMbrZ int, centerX int, centerZ int, minY int, maxY int, date varchar(10), wel longtext, prior int, world varchar(100), value Long not null, tppoint mediumtext, flags longtext, candelete tinyint(1)) CHARACTER SET utf8 COLLATE utf8_general_ci");
                st.executeUpdate();
                st.close();
                st = null;
                RedProtect.get().logger.info("Created table: " + tableName + "!");
            }
            addNewColumns(tableName);
        } catch (CommandException e3) {
            RedProtect.get().logger.severe("Couldn't connect to mysql! Make sure you have mysql turned on and installed properly, and the service is started.");
            throw new Exception("Couldn't connect to mysql!");
        } catch (SQLException e) {
            e.printStackTrace();
            RedProtect.get().logger.severe("There was an error while parsing SQL, redProtect will still with actual DB setting until you change the connection options or check if a Mysql service is running. Use /rp reload to try again");
        } finally {
            if (st != null) {
                st.close();
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) CommandException(org.bukkit.command.CommandException) World(org.bukkit.World) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) CommandException(org.bukkit.command.CommandException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 4 with CommandException

use of org.bukkit.command.CommandException in project Fusion by GummyPvP.

the class BukkitCommand method tabComplete.

@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");
    List<String> completions = null;
    try {
        if (completer != null) {
            completions = completer.onTabComplete(sender, this, alias, args);
        }
        if (completions == null && executor instanceof TabCompleter) {
            completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
        }
    } catch (Throwable ex) {
        StringBuilder message = new StringBuilder();
        message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
        for (String arg : args) {
            message.append(arg).append(' ');
        }
        message.deleteCharAt(message.length() - 1).append("' in plugin ").append(owningPlugin.getDescription().getFullName());
        throw new CommandException(message.toString(), ex);
    }
    if (completions == null) {
        return super.tabComplete(sender, alias, args);
    }
    return completions;
}
Also used : TabCompleter(org.bukkit.command.TabCompleter) CommandException(org.bukkit.command.CommandException)

Aggregations

CommandException (org.bukkit.command.CommandException)4 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 World (org.bukkit.World)1 TabCompleter (org.bukkit.command.TabCompleter)1 Player (org.bukkit.entity.Player)1 RemoteServerCommandEvent (org.bukkit.event.server.RemoteServerCommandEvent)1