use of net.minecraft.command.CommandException in project Minestuck by mraof.
the class SburbHandler method predefineCheck.
private static PlayerIdentifier predefineCheck(MinecraftServer server, ICommandSender sender, String playerName, String sessionName) throws CommandException {
PlayerIdentifier identifier = IdentifierHandler.getForCommand(server, sender, playerName);
Session session = sessionsByName.get(sessionName), playerSession = getPlayerSession(identifier);
if (session == null) {
if (singleSession)
throw new CommandException("Not allowed to create new sessions when global session is active. Use \"%s\" as session name for global session access.", GLOBAL_SESSION_NAME);
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Couldn't find session with that name, creating a new session..."));
session = new Session();
session.name = sessionName;
sessions.add(session);
sessionsByName.put(session.name, session);
}
/*if(session == null)
throw new CommandException("Couldn't find session with the name %s", sessionName);*/
if (playerSession != null && session != playerSession)
throw new CommandException("The player is already in another session!");
if (playerSession == null || !session.predefinedPlayers.containsKey(identifier)) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Couldn't find session for player or player isn't registered with this session yet. Adding player to session " + sessionName));
session.predefinedPlayers.put(identifier, new PredefineData());
}
return identifier;
}
use of net.minecraft.command.CommandException in project Minestuck by mraof.
the class SburbHandler method predefineTitleLandAspect.
public static void predefineTitleLandAspect(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName, TitleLandAspect aspect) throws CommandException {
PlayerIdentifier identifier = predefineCheck(server, sender, playerName, sessionName);
Session session = sessionsByName.get(sessionName);
SburbConnection clientConnection = SkaianetHandler.getClientConnection(identifier);
PredefineData data = session.predefinedPlayers.get(identifier);
if (clientConnection != null && clientConnection.enteredGame())
throw new CommandException("You can't change your land aspects after having entered the medium.");
if (sender.sendCommandFeedback())
if (data.title == null)
sender.sendMessage(new TextComponentString("Beware that the title generated might not be suited for this land aspect.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
else if (!LandAspectRegistry.containsTitleLandAspect(data.title.getHeroAspect(), aspect))
sender.sendMessage(new TextComponentString("Beware that the title predefined isn't suited for this land aspect.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
if (data.landTerrain != null && !aspect.isAspectCompatible(data.landTerrain)) {
data.landTerrain = null;
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("The terrain aspect previously chosen isn't compatible with this land aspect, and has therefore been removed.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
}
data.landTitle = aspect;
CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.landTitleSuccess", playerName, aspect.getPrimaryName());
}
use of net.minecraft.command.CommandException in project minecolonies by Minecolonies.
the class CommandEntryPointNew method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String[] args) throws CommandException {
final BlockPos pos = null;
final ParsingResult parsingResult = getTabCompletionsAndParsingHolders(root, server, sender, args, pos);
final TreeNode<IMenu> executionTreeNode = parsingResult.getExecutionTreeNode();
if (null == executionTreeNode) {
throw new CommandException(getCommandUsage(sender, root));
}
final IMenu executionMenu = executionTreeNode.getData();
if (executionMenu.getMenuType().isNavigationMenu()) {
throw new CommandException(getCommandUsage(sender, executionTreeNode));
}
final ActionMenu actionMenu = (ActionMenu) executionMenu;
final List<ActionArgument> executionActionArgumentList = parsingResult.getExecutionActionArgumentList();
final String badArgument = parsingResult.getBadArgument();
throwCommandUsageExceptionIfRequiredArgumentsAreNotProvided(executionTreeNode, actionMenu, executionActionArgumentList, badArgument, sender);
if (sender instanceof EntityPlayer) {
final ForgePermissionNodes forgePermissionNode = actionMenu.getForgePermissionNode();
final EntityPlayer player = (EntityPlayer) sender;
if (!PermissionAPI.hasPermission(player.getGameProfile(), forgePermissionNode.getNodeName(), new PlayerContext(player))) {
// TODO: Do something if permission check fails.
// But we don't have permissions set up yet.
}
}
for (final ActionArgument executionActionArgument : executionActionArgumentList) {
if (!executionActionArgument.isValueSet()) {
throw new CommandException(getCommandUsage(sender, executionTreeNode));
}
}
final Class<? extends IActionCommand> clazz = actionMenu.getActionCommandClass();
try {
createInstanceAndExecute(server, sender, actionMenu, clazz);
} catch (final InstantiationException | IllegalAccessException e) {
final Logger log = LogManager.getLogger();
log.error("Unable to instantiate class %s for command %s ", clazz.getName(), actionMenu.getDescription(), e);
throw new CommandException("Unable to instantiate class " + clazz.getName() + " for command " + actionMenu.getDescription(), e);
}
}
use of net.minecraft.command.CommandException in project OreSpawn by MinecraftModDevelopmentMods.
the class DumpBiomesCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
JsonArray array = new JsonArray();
for (Biome biome : ForgeRegistries.BIOMES) {
array.add(new JsonPrimitive(biome.getRegistryName().toString()));
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(array);
try {
FileUtils.writeStringToFile(new File(".", "biome_dump.json"), StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8);
} catch (IOException e) {
throw new CommandException("Failed to save the json file");
}
sender.sendMessage(new TextComponentString("Done"));
}
use of net.minecraft.command.CommandException in project watson by totemo.
the class ClientCommandManager method executeCommand.
// --------------------------------------------------------------------------
/**
* @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
* java.lang.String)
*
* The JavaDocs for the interface don't currently describe the exact
* meaning of the return value. Looking at the code for
* {@link net.minecraft.src.CommandHandler} it contains a loop that
* applies a command for all players who match a particular name pattern.
* The returned value is the number of times that the command was
* successfully executed by that loop. Therefore in the case of this
* class, it returns 1 on success and 0 on error.
*/
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
try {
String[] tokens = getTokens(commandLine);
String verb = tokens[0];
ICommand command = getCommand(verb);
if (command == null) {
throw new CommandNotFoundException();
}
tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
if (command.canCommandSenderUseCommand(sender)) {
command.processCommand(sender, tokens);
return 1;
} else {
sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
}
} catch (WrongUsageException ex) {
sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
} catch (CommandException ex) {
sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
} catch (Throwable throwable) {
sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
Log.exception(Level.WARNING, "error processing command", throwable);
}
return 0;
}
Aggregations