Search in sources :

Example 76 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Minestuck by mraof.

the class SburbHandler method managePredefinedSession.

public static void managePredefinedSession(MinecraftServer server, ICommandSender sender, ICommand command, String sessionName, String[] playerNames, boolean finish) throws CommandException {
    Session session = sessionsByName.get(sessionName);
    if (session == null) {
        if (finish && playerNames.length == 0)
            throw new CommandException("Couldn't find session with that name. Aborting the finalizing process.", sessionName);
        if (singleSession)
            throw new CommandException("Not allowed to create new sessions when global session is active. Use \"%s\" as session name for global session access.", GLOBAL_SESSION_NAME);
        if (sender.sendCommandFeedback())
            sender.sendMessage(new TextComponentString("Couldn't find session with that name, creating a new session..."));
        session = new Session();
        session.name = sessionName;
        sessions.add(session);
        sessionsByName.put(session.name, session);
    }
    if (session.locked)
        throw new CommandException("That session may no longer be modified.");
    int handled = 0;
    boolean skipFinishing = false;
    for (String playerName : playerNames) {
        if (playerName.startsWith("!")) {
            playerName = playerName.substring(1);
            PlayerIdentifier identifier;
            try {
                identifier = IdentifierHandler.getForCommand(server, sender, playerName);
            } catch (CommandException c) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString(String.format(c.getMessage(), c.getErrorObjects())));
                continue;
            }
            if (!session.containsPlayer(identifier)) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString("Failed to remove player \"" + playerName + "\": Player isn't in session.").setStyle(new Style().setColor(TextFormatting.RED)));
                continue;
            }
            if (session.predefinedPlayers.remove(identifier) == null) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString("Failed to remove player \"" + playerName + "\": Player isn't registered with the session.").setStyle(new Style().setColor(TextFormatting.RED)));
                continue;
            }
            handled++;
            if (session.containsPlayer(identifier)) {
                split(session);
                session = sessionsByName.get(sessionName);
                if (session.containsPlayer(identifier)) {
                    if (sender.sendCommandFeedback())
                        sender.sendMessage(new TextComponentString("Removed player \"" + playerName + "\", but they are still part of a connection in the session and will therefore be part of the session unless the connection is discarded.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
                    skipFinishing = true;
                    continue;
                }
            }
        } else {
            PlayerIdentifier identifier;
            try {
                identifier = IdentifierHandler.getForCommand(server, sender, playerName);
            } catch (CommandException c) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString(String.format(c.getMessage(), c.getErrorObjects())));
                continue;
            }
            if (session.predefinedPlayers.containsKey(identifier)) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": Player is already registered with session.").setStyle(new Style().setColor(TextFormatting.RED)));
                continue;
            }
            Session playerSession = getPlayerSession(identifier);
            if (playerSession != null) {
                if (merge(session, playerSession, null) != null) {
                    if (sender.sendCommandFeedback())
                        sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": Can't merge with the session that the player is already in.").setStyle(new Style().setColor(TextFormatting.RED)));
                    continue;
                }
            } else if (MinestuckConfig.forceMaxSize && session.getPlayerList().size() + 1 > maxSize) {
                if (sender.sendCommandFeedback())
                    sender.sendMessage(new TextComponentString("Failed to add player \"" + playerName + "\": The session can't accept more players with the current configurations.").setStyle(new Style().setColor(TextFormatting.RED)));
                continue;
            }
            session.predefinedPlayers.put(identifier, new PredefineData());
            handled++;
        }
    }
    if (playerNames.length > 0)
        CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.addSuccess", handled, playerNames.length);
/*if(finish)
			if(!skipFinishing && handled == playerNames.length)
			{
				SburbHandler.finishSession(sender, command, session);
				
			} else throw new CommandException("Skipping to finalize the session due to one or more issues while adding players.");*/
}
Also used : Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 77 with TextComponentString

use of net.minecraft.util.text.TextComponentString 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 78 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Minestuck by mraof.

the class ItemCruxiteArtifact method onArtifactActivated.

public void onArtifactActivated(World world, EntityPlayer player) {
    try {
        if (!world.isRemote && player.world.provider.getDimension() != -1) {
            if (!SburbHandler.shouldEnterNow(player))
                return;
            SburbConnection c = SkaianetHandler.getMainConnection(IdentifierHandler.encode(player), true);
            if (c == null || !c.enteredGame() || !MinestuckConfig.stopSecondEntry && !MinestuckDimensionHandler.isLandDimension(player.world.provider.getDimension())) {
                if (c != null && c.enteredGame()) {
                    World newWorld = player.getServer().getWorld(c.getClientDimension());
                    if (newWorld == null) {
                        return;
                    }
                    BlockPos pos = newWorld.provider.getRandomizedSpawnPoint();
                    Teleport.teleportEntity(player, c.getClientDimension(), null, pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
                    return;
                }
                int destinationId = LandAspectRegistry.createLand(player);
                if (// Something bad happened further down and the problem should be written in the server console
                destinationId == -1) {
                    player.sendMessage(new TextComponentString("Something went wrong during entry. More details in the server console."));
                    return;
                }
                if (!Teleport.teleportEntity(player, destinationId, this)) {
                    Debug.warn("Was not able to teleport player " + player.getName() + " into the medium! Likely caused by mod collision.");
                    player.sendMessage(new TextComponentString("Was not able to teleport you into the medium! Likely caused by mod collision."));
                } else
                    MinestuckPlayerTracker.sendLandEntryMessage(player);
            }
        }
    } catch (Exception e) {
        Debug.logger.error("Exception when " + player.getName() + " tried to enter their land.", e);
        player.sendMessage(new TextComponentString("[Minestuck] Something went wrong during entry. " + (Minestuck.isServerRunning ? "Check the console for the error message." : "Notify the server owner about this.")).setStyle(new Style().setColor(TextFormatting.RED)));
    }
}
Also used : Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SburbConnection(com.mraof.minestuck.network.skaianet.SburbConnection) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 79 with TextComponentString

use of net.minecraft.util.text.TextComponentString 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)

Example 80 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project OpenModularTurrets by OpenModularTurretsTeam.

the class BlockTurretBase method onBlockActivated.

@SuppressWarnings("ConstantConditions")
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
        ItemStack heldItem = player.getHeldItemMainhand();
        TurretBase base = (TurretBase) world.getTileEntity(pos);
        if (player.isSneaking() && OMTConfigHandler.isAllowBaseCamo() && heldItem == ItemStack.EMPTY) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(state);
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        }
        Block heldItemBlock = null;
        if (heldItem != ItemStack.EMPTY) {
            heldItemBlock = Block.getBlockFromItem(heldItem.getItem());
        }
        if (!player.isSneaking() && OMTConfigHandler.isAllowBaseCamo() && heldItem != ItemStack.EMPTY && heldItem.getItem() instanceof ItemBlock && heldItemBlock.isNormalCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && Block.getBlockFromItem(heldItem.getItem()).isOpaqueCube(heldItemBlock.getStateFromMeta(heldItem.getMetadata())) && !(Block.getBlockFromItem(heldItem.getItem()) instanceof BlockTurretBase)) {
            if (base != null) {
                if (player.getUniqueID().toString().equals(base.getOwner())) {
                    base.setCamoState(heldItemBlock.getStateFromMeta(heldItem.getItemDamage()));
                    world.notifyBlockUpdate(pos, state, state, 3);
                } else {
                    addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
                }
            }
        } else if (player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStack.EMPTY && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2) {
            ((UsableMetaItem) player.getHeldItemMainhand().getItem()).setDataStored(player.getHeldItemMainhand(), base.writeMemoryCardNBT());
        } else if (!player.isSneaking() && base != null && player.getHeldItemMainhand() != ItemStack.EMPTY && player.getHeldItemMainhand().getItem() instanceof UsableMetaItem && player.getHeldItemMainhand().getItemDamage() == 2 && ((UsableMetaItem) player.getHeldItemMainhand().getItem()).hasDataStored(player.getHeldItemMainhand())) {
            base.readMemoryCardNBT(((UsableMetaItem) player.getHeldItemMainhand().getItem()).getDataStored(player.getHeldItemMainhand()));
        } else if (!player.isSneaking() && base != null) {
            TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(player, base);
            if (trustedPlayer != null && trustedPlayer.canOpenGUI) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
                return true;
            } else if (PlayerUtil.isPlayerOwner(player, base)) {
                world.notifyBlockUpdate(pos, state, state, 6);
                player.openGui(OpenModularTurrets.instance, base.getTier(), world, pos.getX(), pos.getY(), pos.getZ());
            } else {
                addChatMessage(player, new TextComponentString(safeLocalize("status.ownership")));
            }
        }
    }
    return true;
}
Also used : TrustedPlayer(omtteam.omlib.util.TrustedPlayer) UsableMetaItem(omtteam.openmodularturrets.items.UsableMetaItem) TurretBase(omtteam.openmodularturrets.tileentity.TurretBase) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) Block(net.minecraft.block.Block) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) IHasItemBlock(omtteam.omlib.api.IHasItemBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemBlockTurretBase(omtteam.openmodularturrets.items.blocks.ItemBlockTurretBase) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)343 EntityPlayer (net.minecraft.entity.player.EntityPlayer)79 ItemStack (net.minecraft.item.ItemStack)68 BlockPos (net.minecraft.util.math.BlockPos)60 ITextComponent (net.minecraft.util.text.ITextComponent)48 TileEntity (net.minecraft.tileentity.TileEntity)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)35 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)32 Colony (com.minecolonies.coremod.colony.Colony)26 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)26 IBlockState (net.minecraft.block.state.IBlockState)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 Style (net.minecraft.util.text.Style)21 IColony (com.minecolonies.api.colony.IColony)19 ClickEvent (net.minecraft.util.text.event.ClickEvent)19 Entity (net.minecraft.entity.Entity)18 Block (net.minecraft.block.Block)17 World (net.minecraft.world.World)17 ArrayList (java.util.ArrayList)16 ActionResult (net.minecraft.util.ActionResult)13