Search in sources :

Example 11 with CommandException

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());
}
Also used : Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 12 with CommandException

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");
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) CapabilityDivination(com.bewitchment.common.core.capability.divination.CapabilityDivination) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException)

Example 13 with CommandException

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));
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 14 with CommandException

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);
}
Also used : Arrays(java.util.Arrays) Blocks(net.minecraft.init.Blocks) OreSpawn(com.mcmoddev.orespawn.OreSpawn) ChunkPos(net.minecraft.util.math.ChunkPos) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) ICommand(net.minecraft.command.ICommand) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) OreDictionary(net.minecraftforge.oredict.OreDictionary) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) ResourceLocation(net.minecraft.util.ResourceLocation) Chunk(net.minecraft.world.chunk.Chunk) LinkedList(java.util.LinkedList) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString) Chunk(net.minecraft.world.chunk.Chunk) LinkedList(java.util.LinkedList) TextComponentString(net.minecraft.util.text.TextComponentString) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 15 with CommandException

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());
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IQuest(betterquesting.api.questing.IQuest) UUID(java.util.UUID) CommandException(net.minecraft.command.CommandException)

Aggregations

CommandException (net.minecraft.command.CommandException)70 WrongUsageException (net.minecraft.command.WrongUsageException)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 ICommandSender (net.minecraft.command.ICommandSender)18 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)18 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)15 TextComponentString (net.minecraft.util.text.TextComponentString)15 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 BlockPos (net.minecraft.util.math.BlockPos)11 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)10 RCCommands (ivorius.reccomplex.commands.RCCommands)9 RCP (ivorius.reccomplex.commands.parameters.RCP)8 List (java.util.List)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7 Parameters (ivorius.mcopts.commands.parameters.Parameters)6