use of net.minecraft.command.CommandException in project Minestuck by mraof.
the class SessionHandler method connectByCommand.
public static void connectByCommand(ICommandSender sender, ICommand command, PlayerIdentifier client, PlayerIdentifier server) throws CommandException {
Session sc = getPlayerSession(client), ss = getPlayerSession(server);
if (singleSession) {
int i = (sc == null ? 1 : 0) + (ss == null ? 1 : 0);
sc = ss = sessions.get(0);
if (MinestuckConfig.forceMaxSize && sc.getPlayerList().size() + i > maxSize)
throw new CommandException("computer.singleSessionFull");
} else {
if (sc == null && ss == null) {
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString("Neither player is part of a session. Creating new session..."));
sc = ss = new Session();
sessions.add(sc);
} else if (sc == null) {
if (ss.locked)
throw new CommandException("The server session is locked, and can no longer be modified!");
if (MinestuckConfig.forceMaxSize && ss.getPlayerList().size() + 1 > maxSize)
throw new CommandException("computer.serverSessionFull");
sc = ss;
} else if (ss == null) {
if (sc.locked)
throw new CommandException("The client session is locked, and can no longer be modified!");
if (MinestuckConfig.forceMaxSize && sc.getPlayerList().size() + 1 > maxSize)
throw new CommandException("computer.clientSessionFull");
ss = sc;
}
}
SburbConnection cc = SkaianetHandler.getMainConnection(client, true), cs = SkaianetHandler.getMainConnection(server, false);
if (cc != null && cc == cs)
throw new CommandException("Those players are already connected!");
if (sc != ss) {
String merge = merge(sc, ss, null);
if (merge != null)
throw new CommandException(merge);
}
if (cs != null) {
if (cs.isActive)
SkaianetHandler.closeConnection(server, cs.getClientIdentifier(), false);
cs.serverIdentifier = IdentifierHandler.nullIdentifier;
if (sender.sendCommandFeedback())
sender.sendMessage(new TextComponentString(server.getUsername() + "'s old client player " + cs.getClientIdentifier().getUsername() + " is now without a server player.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
}
if (cc != null && cc.isActive)
SkaianetHandler.closeConnection(client, cc.getServerIdentifier(), true);
SburbConnection connection = SkaianetHandler.getConnection(client, server);
if (cc == null) {
if (connection != null)
cc = connection;
else {
cc = new SburbConnection();
SkaianetHandler.connections.add(cc);
cc.clientIdentifier = client;
cc.serverIdentifier = server;
sc.connections.add(cc);
SburbHandler.onConnectionCreated(cc);
}
cc.isMain = true;
} else {
if (connection != null && connection.isActive) {
SkaianetHandler.connections.remove(connection);
sc.connections.remove(connection);
cc.client = connection.client;
cc.server = connection.server;
cc.serverIdentifier = server;
} else
cc.serverIdentifier = server;
}
SkaianetHandler.updateAll();
CommandBase.notifyCommandListener(sender, command, "commands.sburbServer.success", client.getUsername(), server.getUsername());
}
use of net.minecraft.command.CommandException in project Bewitchment by Um-Mitternacht.
the class CommandFortuneActivator method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (sender instanceof EntityPlayer) {
CapabilityDivination dc = ((EntityPlayer) sender).getCapability(CapabilityDivination.CAPABILITY, null);
if (dc.getFortune() != null) {
if (dc.isActive()) {
throw new CommandException("commands.enable_fortune.error.already_active");
}
dc.setActive();
sender.sendMessage(new TextComponentTranslation("commands.enable_fortune.success"));
} else {
throw new CommandException("commands.enable_fortune.error.no_fortune");
}
} else {
throw new CommandException("commands.error.no_console");
}
}
use of net.minecraft.command.CommandException in project OreSpawn by MinecraftModDevelopmentMods.
the class AddOreCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!(sender instanceof EntityPlayer)) {
throw new CommandException("Only players can use this command");
}
EntityPlayer player = (EntityPlayer) sender;
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
if (stack == null) {
throw new CommandException("You have no item in your main hand");
} else if (!(stack.getItem() instanceof ItemBlock)) {
throw new CommandException("The item in your main hand isn't a block");
} else if (args.length < 2) {
throw new CommandException(this.getUsage(sender));
}
String file = args[0];
@SuppressWarnings("deprecation") IBlockState state = Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getItemDamage());
String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText();
JsonParser p = new JsonParser();
JsonElement parsed = mergeDefaults(p.parse(rawData), state);
OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed);
OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file));
}
use of net.minecraft.command.CommandException in project OreSpawn by MinecraftModDevelopmentMods.
the class ClearChunkCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!(sender instanceof EntityPlayer)) {
throw new CommandException("Only players can use this command");
}
EntityPlayer player = (EntityPlayer) sender;
Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(player.getPosition());
ChunkPos chunkPos = chunk.getPos();
List<IBlockState> blocks;
boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false;
List<String> blockNames = new LinkedList<>();
getBlocks(args, blockNames);
blocks = blockNames.stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList());
blocks.addAll(OreSpawn.API.getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList()));
List<IBlockState> overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream().map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(bl -> bl.getDefaultState()).collect(Collectors.toList());
clearBlocks(chunkPos, blocks, overburden, flagClassic, player);
player.sendStatusMessage(new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true);
}
use of net.minecraft.command.CommandException in project BetterQuesting by Funwayguy.
the class QuestCommandComplete method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
UUID uuid = null;
if (args.length >= 3) {
uuid = this.findPlayerID(server, sender, args[2]);
if (uuid == null) {
throw this.getException(command);
}
} else {
uuid = this.findPlayerID(server, sender, sender.getName());
}
String pName = uuid == null ? "NULL" : NameCache.INSTANCE.getName(uuid);
try {
int id = Integer.parseInt(args[1].trim());
IQuest quest = QuestDatabase.INSTANCE.getValue(id);
quest.setComplete(uuid, 0);
int done = 0;
if (// Preliminary check
!quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
for (ITask task : quest.getTasks().getAllValues()) {
task.setComplete(uuid);
done += 1;
if (quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
// Only complete enough quests to claim the reward
break;
}
}
}
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.complete", new TextComponentTranslation(quest.getUnlocalisedName()), pName));
} catch (Exception e) {
throw getException(command);
}
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
}
Aggregations