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;
}
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()));
}
}
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();
}
}
}
}
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;
}
Aggregations