Search in sources :

Example 21 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier 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());
}
Also used : Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 22 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SburbHandler method shouldEnterNow.

public static boolean shouldEnterNow(EntityPlayer player) {
    if (!MinestuckConfig.playerSelectedTitle)
        return true;
    PlayerIdentifier identifier = IdentifierHandler.encode(player);
    Session s = getPlayerSession(identifier);
    if (s != null && s.predefinedPlayers.containsKey(identifier) && s.predefinedPlayers.get(identifier).title != null || MinestuckPlayerData.getTitle(identifier) != null)
        return true;
    titleSelectionMap.put(player, new Vec3d(player.posX, player.posY, player.posZ));
    MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(MinestuckPacket.Type.PLAYER_DATA, PlayerDataPacket.TITLE_SELECT), player);
    return false;
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) Vec3d(net.minecraft.util.math.Vec3d)

Example 23 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SburbHandler method titleSelected.

public static void titleSelected(EntityPlayer player, Title title) {
    if (MinestuckConfig.playerSelectedTitle && titleSelectionMap.containsKey(player)) {
        PlayerIdentifier identifier = IdentifierHandler.encode(player);
        Session s = getPlayerSession(identifier);
        if (s == null)
            if (singleSession)
                s = sessions.get(0);
            else
                s = new Session();
        if (title == null)
            generateTitle(identifier);
        else {
            for (SburbConnection c : s.connections) if (c.enteredGame() && title.equals(MinestuckPlayerData.getTitle(c.getClientIdentifier()))) {
                // Title is already used
                MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(MinestuckPacket.Type.PLAYER_DATA, PlayerDataPacket.TITLE_SELECT, title.getHeroClass(), title.getHeroAspect()), player);
                return;
            }
            for (PredefineData data : s.predefinedPlayers.values()) if (title.equals(data.title)) {
                MinestuckChannelHandler.sendToPlayer(MinestuckPacket.makePacket(MinestuckPacket.Type.PLAYER_DATA, PlayerDataPacket.TITLE_SELECT, title.getHeroClass(), title.getHeroAspect()), player);
                return;
            }
            MinestuckPlayerData.setTitle(identifier, title);
            MinestuckPlayerTracker.updateTitle(player);
        }
        Vec3d pos = titleSelectionMap.remove(player);
        player.setPosition(pos.x, pos.y, pos.z);
        MinestuckItems.cruxiteApple.onArtifactActivated(player.world, player);
    } else
        Debug.warnf("%s tried to select a title without entering.", player.getName());
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) Vec3d(net.minecraft.util.math.Vec3d)

Example 24 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class Session method write.

/**
 * Writes this session to an nbt tag.
 * Note that this will only work as long as <code>SkaianetHandler.connections</code> remains unmodified.
 * @return An NBTTagCompound representing this session.
 */
NBTTagCompound write() {
    NBTTagCompound nbt = new NBTTagCompound();
    if (isCustom())
        nbt.setString("name", name);
    NBTTagList list = new NBTTagList();
    for (SburbConnection c : connections) list.appendTag(c.write());
    nbt.setTag("connections", list);
    NBTTagList predefineList = new NBTTagList();
    for (Map.Entry<PlayerIdentifier, PredefineData> entry : predefinedPlayers.entrySet()) predefineList.appendTag(entry.getKey().saveToNBT(entry.getValue().write(), "player"));
    nbt.setTag("predefinedPlayers", predefineList);
    nbt.setBoolean("locked", locked);
    nbt.setInteger("skaiaId", skaiaId);
    nbt.setInteger("derseId", derseId);
    nbt.setInteger("prospitId", prospitId);
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Example 25 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class Session method checkIfCompleted.

/**
 * Checks if the variable completed should be true or false.
 */
void checkIfCompleted() {
    if (connections.isEmpty() || SessionHandler.singleSession) {
        completed = false;
        return;
    }
    PlayerIdentifier start = connections.get(0).getClientIdentifier();
    PlayerIdentifier current = start;
    main: while (true) {
        for (SburbConnection c : connections) {
            if (!c.enteredGame) {
                completed = false;
                return;
            }
            if (c.getServerIdentifier().equals(current)) {
                current = c.getClientIdentifier();
                if (start.equals(current)) {
                    completed = true;
                    return;
                } else
                    continue main;
            }
        }
        completed = false;
        return;
    }
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Aggregations

PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)27 TextComponentString (net.minecraft.util.text.TextComponentString)7 CommandException (net.minecraft.command.CommandException)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 Style (net.minecraft.util.text.Style)3 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)2 TileEntityComputer (com.mraof.minestuck.tileentity.TileEntityComputer)2 Title (com.mraof.minestuck.util.Title)2 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 UserListOpsEntry (net.minecraft.server.management.UserListOpsEntry)2 Vec3d (net.minecraft.util.math.Vec3d)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 Modus (com.mraof.minestuck.inventory.captchalouge.Modus)1 Echeladder (com.mraof.minestuck.util.Echeladder)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 LandAspectRegistry (com.mraof.minestuck.world.lands.LandAspectRegistry)1