Search in sources :

Example 1 with Title

use of com.mraof.minestuck.util.Title 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)

Example 2 with Title

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

the class MessageType method createMessage.

private static ITextComponent createMessage(EntityConsort consort, EntityPlayer player, String unlocalizedMessage, String[] args, boolean consortPrefix) {
    String s = EntityList.getEntityString(consort);
    if (s == null) {
        s = "generic";
    }
    Object[] obj = new Object[args.length];
    SburbConnection c = SburbHandler.getConnectionForDimension(consort.homeDimension);
    Title title = c == null ? null : MinestuckPlayerData.getData(c.getClientIdentifier()).title;
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("playerNameLand")) {
            if (c != null)
                obj[i] = c.getClientIdentifier().getUsername();
            else
                obj[i] = "Player name";
        } else if (args[i].equals("playerName")) {
            obj[i] = player.getName();
        } else if (args[i].equals("landName")) {
            World world = consort.getServer().getWorld(consort.homeDimension);
            if (world != null && consort.world.provider instanceof WorldProviderLands) {
                ChunkProviderLands chunkProvider = (ChunkProviderLands) world.provider.createChunkGenerator();
                ITextComponent aspect1 = new TextComponentTranslation("land." + chunkProvider.aspect1.getNames()[chunkProvider.nameIndex1]);
                ITextComponent aspect2 = new TextComponentTranslation("land." + chunkProvider.aspect2.getNames()[chunkProvider.nameIndex2]);
                if (chunkProvider.nameOrder)
                    obj[i] = new TextComponentTranslation("land.format", aspect1, aspect2);
                else
                    obj[i] = new TextComponentTranslation("land.format", aspect2, aspect1);
            } else
                obj[i] = "Land name";
        } else if (args[i].equals("playerTitleLand")) {
            if (title != null)
                obj[i] = title.asTextComponent();
            else
                obj[i] = "Player title";
        } else if (args[i].equals("playerClassLand")) {
            if (title != null)
                obj[i] = title.getHeroClass().asTextComponent();
            else
                obj[i] = "Player class";
        } else if (args[i].equals("playerAspectLand")) {
            if (title != null)
                obj[i] = title.getHeroAspect().asTextComponent();
            else
                obj[i] = "Player aspect";
        } else if (args[i].equals("consortSound")) {
            obj[i] = new TextComponentTranslation("consort.sound." + s);
        } else if (args[i].equals("consortType")) {
            obj[i] = new TextComponentTranslation("entity." + s + ".name");
        } else if (args[i].equals("consortTypes")) {
            obj[i] = new TextComponentTranslation("entity." + s + ".plural.name");
        } else if (args[i].equals("playerTitle")) {
            PlayerIdentifier identifier = IdentifierHandler.encode(player);
            if (MinestuckPlayerData.getTitle(identifier) != null)
                obj[i] = MinestuckPlayerData.getTitle(identifier).asTextComponent();
            else
                obj[i] = player.getName();
        } else if (args[i].equals("denizen")) {
            if (title != null)
                obj[i] = new TextComponentTranslation("denizen." + MinestuckPlayerData.getData(c.getClientIdentifier()).title.getHeroAspect().toString() + ".name");
            else
                obj[i] = "Denizen";
        } else if (args[i].startsWith("nbtItem:")) {
            NBTTagCompound nbt = consort.getMessageTagForPlayer(player);
            ItemStack stack = new ItemStack(nbt.getCompoundTag(args[i].substring(8)));
            if (!stack.isEmpty())
                obj[i] = new TextComponentTranslation(stack.getUnlocalizedName() + ".name");
            else
                obj[i] = "Item";
        }
    }
    TextComponentTranslation message = new TextComponentTranslation("consort." + unlocalizedMessage, obj);
    if (consortPrefix) {
        message.getStyle().setColor(consort.getConsortType().getColor());
        TextComponentTranslation entity = new TextComponentTranslation("entity." + s + ".name");
        return new TextComponentTranslation("chat.type.text", entity, message);
    } else
        return message;
}
Also used : ChunkProviderLands(com.mraof.minestuck.world.lands.gen.ChunkProviderLands) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Title(com.mraof.minestuck.util.Title) World(net.minecraft.world.World) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) WorldProviderLands(com.mraof.minestuck.world.WorldProviderLands) ItemStack(net.minecraft.item.ItemStack) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection)

Example 3 with Title

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

the class SessionHandler method createDataTag.

/**
 * Creates data to be used for the data checker
 */
public static NBTTagCompound createDataTag(MinecraftServer server) {
    NBTTagCompound nbt = new NBTTagCompound();
    NBTTagList sessionList = new NBTTagList();
    nbt.setTag("sessions", sessionList);
    int nameIndex = 1;
    for (int i = 0; i < sessions.size(); i++) {
        Session session = sessions.get(i);
        NBTTagList connectionList = new NBTTagList();
        Set<PlayerIdentifier> playerSet = new HashSet<PlayerIdentifier>();
        for (SburbConnection c : session.connections) {
            if (c.isMain)
                playerSet.add(c.getClientIdentifier());
            NBTTagCompound connectionTag = new NBTTagCompound();
            connectionTag.setString("client", c.getClientIdentifier().getUsername());
            connectionTag.setString("clientId", c.getClientIdentifier().getString());
            if (!c.getServerIdentifier().equals(IdentifierHandler.nullIdentifier))
                connectionTag.setString("server", c.getServerIdentifier().getUsername());
            connectionTag.setBoolean("isMain", c.isMain);
            connectionTag.setBoolean("isActive", c.isActive);
            if (c.isMain) {
                connectionTag.setInteger("clientDim", c.enteredGame ? c.clientHomeLand : 0);
                if (c.enteredGame && DimensionManager.isDimensionRegistered(c.clientHomeLand)) {
                    LandAspectRegistry.AspectCombination aspects = MinestuckDimensionHandler.getAspects(c.clientHomeLand);
                    IChunkGenerator chunkGen = server.getWorld(c.clientHomeLand).provider.createChunkGenerator();
                    if (chunkGen instanceof ChunkProviderLands) {
                        ChunkProviderLands landChunkGen = (ChunkProviderLands) chunkGen;
                        if (landChunkGen.nameOrder) {
                            connectionTag.setString("aspect1", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
                            connectionTag.setString("aspect2", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
                        } else {
                            connectionTag.setString("aspect1", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
                            connectionTag.setString("aspect2", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
                        }
                    }
                    Title title = MinestuckPlayerData.getTitle(c.getClientIdentifier());
                    connectionTag.setByte("class", title == null ? -1 : (byte) title.getHeroClass().ordinal());
                    connectionTag.setByte("aspect", title == null ? -1 : (byte) title.getHeroAspect().ordinal());
                } else if (session.predefinedPlayers.containsKey(c.getClientIdentifier())) {
                    PredefineData data = session.predefinedPlayers.get(c.getClientIdentifier());
                    if (data.title != null) {
                        connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
                        connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
                    }
                    if (data.landTerrain != null)
                        connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
                    if (data.landTitle != null)
                        connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
                }
            }
            connectionList.appendTag(connectionTag);
        }
        for (Map.Entry<PlayerIdentifier, PredefineData> entry : session.predefinedPlayers.entrySet()) {
            if (playerSet.contains(entry.getKey()))
                continue;
            NBTTagCompound connectionTag = new NBTTagCompound();
            connectionTag.setString("client", entry.getKey().getUsername());
            connectionTag.setString("clientId", entry.getKey().getString());
            connectionTag.setBoolean("isMain", true);
            connectionTag.setBoolean("isActive", false);
            connectionTag.setInteger("clientDim", 0);
            PredefineData data = entry.getValue();
            if (data.title != null) {
                connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
                connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
            }
            if (data.landTerrain != null)
                connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
            if (data.landTitle != null)
                connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
            connectionList.appendTag(connectionTag);
        }
        NBTTagCompound sessionTag = new NBTTagCompound();
        if (session.name != null)
            sessionTag.setString("name", session.name);
        sessionTag.setTag("connections", connectionList);
        sessionList.appendTag(sessionTag);
    }
    return nbt;
}
Also used : ChunkProviderLands(com.mraof.minestuck.world.lands.gen.ChunkProviderLands) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Title(com.mraof.minestuck.util.Title) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) LandAspectRegistry(com.mraof.minestuck.world.lands.LandAspectRegistry) NBTTagList(net.minecraft.nbt.NBTTagList)

Example 4 with Title

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

the class PlayerDataPacket method execute.

@Override
public void execute(EntityPlayer player) {
    if (type == COLOR) {
        if (i1 == -2) {
            ColorCollector.playerColor = -1;
            ColorCollector.displaySelectionGui = true;
        } else
            ColorCollector.playerColor = i1;
    } else if (type == TITLE) {
        MinestuckPlayerData.title = new Title(EnumClass.getClassFromInt(i1), EnumAspect.getAspectFromInt(i2));
    } else if (type == ECHELADDER) {
        int prev = MinestuckPlayerData.rung;
        MinestuckPlayerData.rung = i1;
        MinestuckPlayerData.rungProgress = f;
        if (!b)
            for (prev++; prev <= i1; prev++) {
                String s = I18n.canTranslate("echeladder.rung" + prev) ? I18n.translateToLocal("echeladder.rung" + prev) : String.valueOf(prev + 1);
                player.sendMessage(new TextComponentString("You reached rung " + s + '!'));
            }
        else
            GuiEcheladder.animatedRung = GuiEcheladder.lastRung = i1;
    } else if (type == BOONDOLLAR) {
        MinestuckPlayerData.boondollars = i1;
    } else if (type == TITLE_SELECT) {
        Title title;
        if (i1 >= 0 && i1 < 12 && i2 >= 0 && i2 < 12)
            title = new Title(EnumClass.getClassFromInt(i1), EnumAspect.getAspectFromInt(i2));
        else
            title = null;
        if (player.world.isRemote) {
            FMLClientHandler.instance().showGuiScreen(new GuiTitleSelector(title));
        } else {
            SburbHandler.titleSelected(player, title);
        }
    }
}
Also used : GuiTitleSelector(com.mraof.minestuck.client.gui.GuiTitleSelector) Title(com.mraof.minestuck.util.Title) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Title (com.mraof.minestuck.util.Title)4 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 GuiTitleSelector (com.mraof.minestuck.client.gui.GuiTitleSelector)1 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)1 EnumAspect (com.mraof.minestuck.util.EnumAspect)1 EnumClass (com.mraof.minestuck.util.EnumClass)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 LandAspectRegistry (com.mraof.minestuck.world.lands.LandAspectRegistry)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 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 World (net.minecraft.world.World)1 IChunkGenerator (net.minecraft.world.gen.IChunkGenerator)1