Search in sources :

Example 1 with EnumAspect

use of com.mraof.minestuck.util.EnumAspect in project Minestuck by mraof.

the class CommandSburbSession method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 2 || args.length < 3 && args[1].equalsIgnoreCase("add") || args.length != 4 && (args[1].equalsIgnoreCase("landTerrain") || args[1].equalsIgnoreCase("landTitle")) || args.length != 5 && args[1].equalsIgnoreCase("title") || args.length != 6 && args.length != 7 && args[1].equalsIgnoreCase("define"))
        throw new WrongUsageException(this.getUsage(sender));
    String sessionName = args[0];
    String command = args[1];
    if (command.equalsIgnoreCase("name")) {
        String playerName = args.length < 3 ? getCommandSenderAsPlayer(sender).getName() : args[2];
        SburbHandler.sessionName(server, sender, this, playerName, sessionName);
    } else if (command.equalsIgnoreCase("add")) /* || command.equalsIgnoreCase("finish")*/
    {
        String[] params = Arrays.copyOfRange(args, 2, args.length);
        // command.equalsIgnoreCase("finish"));
        SburbHandler.managePredefinedSession(server, sender, this, sessionName, params, false);
    } else if (command.equalsIgnoreCase("title")) {
        String playerName = args[2];
        String classStr = args[3], aspectStr = args[4];
        EnumClass titleClass = null;
        EnumAspect titleAspect = null;
        try // Parse class
        {
            for (EnumClass c : EnumClass.values()) if (c.name().equalsIgnoreCase(classStr)) {
                titleClass = c;
                break;
            }
            if (titleClass == null) {
                int classIndex = Integer.parseInt(classStr);
                titleClass = EnumClass.getClassFromInt(classIndex);
            }
        } catch (Exception e) {
            throw new WrongUsageException("commands.sburbSession.notClass", classStr);
        }
        try // Parse aspect
        {
            for (EnumAspect aspect : EnumAspect.values()) if (aspect.name().equalsIgnoreCase(aspectStr)) {
                titleAspect = aspect;
                break;
            }
            if (titleAspect == null) {
                int aspectIndex = Integer.parseInt(aspectStr);
                titleAspect = EnumAspect.getAspectFromInt(aspectIndex);
            }
        } catch (Exception e) {
            throw new WrongUsageException("commands.sburbSession.notAspect", aspectStr);
        }
        SburbHandler.predefineTitle(server, sender, this, playerName, sessionName, new Title(titleClass, titleAspect));
    } else if (command.equalsIgnoreCase("landTerrain")) {
        String playerName = args[2];
        TerrainLandAspect landAspect = LandAspectRegistry.fromNameTerrain(args[3].toLowerCase());
        if (landAspect == null)
            throw new CommandException("Can't find terrain land aspect by the name %s", args[3]);
        SburbHandler.predefineTerrainLandAspect(server, sender, this, playerName, sessionName, landAspect);
    } else if (command.equalsIgnoreCase("landTitle")) {
        String playerName = args[2];
        TitleLandAspect landAspect = LandAspectRegistry.fromNameTitle(args[3].toLowerCase());
        if (landAspect == null)
            throw new CommandException("Can't find title land aspect by the name %s", args[3]);
        SburbHandler.predefineTitleLandAspect(server, sender, this, playerName, sessionName, landAspect);
    } else if (command.equalsIgnoreCase("define")) {
        String playerName = args[2];
        String classStr = args[3], aspectStr = args[4];
        EnumClass titleClass = null;
        EnumAspect titleAspect = null;
        try // Parse class
        {
            for (EnumClass c : EnumClass.values()) if (c.name().equalsIgnoreCase(classStr)) {
                titleClass = c;
                break;
            }
            if (titleClass == null) {
                int classIndex = Integer.parseInt(classStr);
                titleClass = EnumClass.getClassFromInt(classIndex);
            }
        } catch (Exception e) {
            throw new WrongUsageException("commands.sburbSession.notClass", classStr);
        }
        try // Parse aspect
        {
            for (EnumAspect aspect : EnumAspect.values()) if (aspect.name().equalsIgnoreCase(aspectStr)) {
                titleAspect = aspect;
                break;
            }
            if (titleAspect == null) {
                int aspectIndex = Integer.parseInt(aspectStr);
                titleAspect = EnumAspect.getAspectFromInt(aspectIndex);
            }
        } catch (Exception e) {
            throw new WrongUsageException("commands.sburbSession.notAspect", aspectStr);
        }
        TerrainLandAspect terrainLand = null;
        TitleLandAspect titleLand = null;
        if (args.length == 7) {
            titleLand = LandAspectRegistry.fromNameTitle(args[5].toLowerCase());
            if (titleLand == null)
                throw new CommandException("Can't find title land aspect by the name %s", args[5]);
            terrainLand = LandAspectRegistry.fromNameTerrain(args[6].toLowerCase());
            if (terrainLand == null)
                throw new CommandException("Can't find terrain land aspect by the name %s", args[6]);
        } else {
            titleLand = LandAspectRegistry.fromNameTitle(args[5].toLowerCase());
            if (titleLand == null) {
                terrainLand = LandAspectRegistry.fromNameTerrain(args[5].toLowerCase());
                if (terrainLand == null)
                    throw new CommandException("Can't find any land aspect by the name %s", args[5]);
            }
        }
        SburbHandler.predefineTitle(server, sender, this, playerName, sessionName, new Title(titleClass, titleAspect));
        if (titleLand != null)
            SburbHandler.predefineTitleLandAspect(server, sender, this, playerName, sessionName, titleLand);
        if (terrainLand != null)
            SburbHandler.predefineTerrainLandAspect(server, sender, this, playerName, sessionName, terrainLand);
    } else
        throw new WrongUsageException(this.getUsage(sender));
}
Also used : TerrainLandAspect(com.mraof.minestuck.world.lands.terrain.TerrainLandAspect) WrongUsageException(net.minecraft.command.WrongUsageException) EnumClass(com.mraof.minestuck.util.EnumClass) Title(com.mraof.minestuck.util.Title) TitleLandAspect(com.mraof.minestuck.world.lands.title.TitleLandAspect) CommandException(net.minecraft.command.CommandException) EnumAspect(com.mraof.minestuck.util.EnumAspect) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Aggregations

EnumAspect (com.mraof.minestuck.util.EnumAspect)1 EnumClass (com.mraof.minestuck.util.EnumClass)1 Title (com.mraof.minestuck.util.Title)1 TerrainLandAspect (com.mraof.minestuck.world.lands.terrain.TerrainLandAspect)1 TitleLandAspect (com.mraof.minestuck.world.lands.title.TitleLandAspect)1 CommandException (net.minecraft.command.CommandException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1