Search in sources :

Example 6 with Style

use of net.minecraft.util.text.Style in project minecolonies by Minecolonies.

the class ListCitizensCommand method drawPageSwitcher.

/**
 * Draws the page switcher at the bottom.
 *
 * @param sender   the sender.
 * @param page     the page number.
 * @param count    number of citizens.
 * @param halfPage the halfPage.
 * @param colonyId the colony id.
 */
private static void drawPageSwitcher(@NotNull final ICommandSender sender, final int page, final int count, final int halfPage, final int colonyId) {
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (count / CITIZENS_ON_PAGE) + halfPage);
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, prevPage))));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, nextPage))));
    final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
    final ITextComponent endLine = new TextComponentString(PAGE_LINE);
    sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 7 with Style

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

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

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

use of net.minecraft.util.text.Style in project Random-Things by lumien231.

the class RTCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        return;
    }
    if (args[0].equals("setBiomeCrystal")) {
        if (args.length == 2 && sender instanceof EntityPlayer) {
            String biomeName = args[1];
            EntityPlayer player = (EntityPlayer) sender;
            ItemStack equipped = player.getHeldItemMainhand();
            if (equipped != null && equipped.getItem() instanceof ItemBiomeCrystal) {
                if (equipped.getTagCompound() == null) {
                    equipped.setTagCompound(new NBTTagCompound());
                }
                equipped.getTagCompound().setString("biomeName", args[1]);
            }
        }
    } else if (args[0].equals("generateBiomeCrystalChests")) {
        if (sender instanceof EntityPlayer) {
            List<ResourceLocation> biomeIds = new ArrayList<>(Biome.REGISTRY.getKeys());
            int modX = 0;
            while (!biomeIds.isEmpty()) {
                sender.getEntityWorld().setBlockState(sender.getPosition().add(modX, 0, 0), Blocks.CHEST.getDefaultState());
                IInventory inventory = (IInventory) sender.getEntityWorld().getTileEntity(sender.getPosition().add(modX, 0, 0));
                for (int i = 0; i < 27; i++) {
                    if (!biomeIds.isEmpty()) {
                        ResourceLocation next = biomeIds.remove(biomeIds.size() - 1);
                        ItemStack crystal = new ItemStack(ModItems.biomeCrystal);
                        crystal.setTagCompound(new NBTTagCompound());
                        crystal.getTagCompound().setString("biomeName", next.toString());
                        inventory.setInventorySlotContents(i, crystal);
                    }
                }
                modX += 2;
            }
        }
    } else if (args[0].equals("tpFilter")) {
        if (sender instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) sender;
            ItemStack held;
            if ((held = player.getHeldItemMainhand()) != null && held.getItem() == ModItems.positionFilter) {
                BlockPos pos = ItemPositionFilter.getPosition(held);
                player.connection.setPlayerLocation(pos.getX(), pos.getY() + 150, pos.getZ(), player.rotationYaw, player.rotationPitch);
            }
        }
    } else if (args[0].equals("testSlimeSpawn")) {
        BlockPos pos = sender.getPosition();
        World world = sender.getEntityWorld();
        if (pos != null && world != null) {
            EntitySlime slime = new EntitySlime(world);
            slime.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), 0F, 0F);
            sender.sendMessage(new TextComponentString(slime.getCanSpawnHere() + ""));
        }
    } else if (args[0].equals("notify") && args.length == 5) {
        String title = args[1];
        String body = args[2];
        String itemName = args[3];
        String player = args[4];
        EntityPlayerMP playerEntity = server.getPlayerList().getPlayerByUsername(player);
        ItemStack itemStack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
        MessageNotification message = new MessageNotification(title, body, itemStack);
        PacketHandler.INSTANCE.sendTo(message, playerEntity);
    } else if (args[0].equals("fireplaces")) {
        FlooNetworkHandler handler = FlooNetworkHandler.get(sender.getEntityWorld());
        List<FlooFireplace> firePlaces = handler.getFirePlaces();
        sender.sendMessage(new TextComponentString("Floo Fireplaces in Dimension " + sender.getEntityWorld().provider.getDimension()).setStyle(new Style().setUnderlined(true)));
        sender.sendMessage(new TextComponentString(""));
        for (FlooFireplace firePlace : firePlaces) {
            String name = firePlace.getName();
            UUID creator = firePlace.getCreatorUUID();
            String ownerName = null;
            if (creator != null) {
                GameProfile profile = server.getPlayerProfileCache().getProfileByUUID(creator);
                if (profile != null) {
                    ownerName = profile.getName();
                }
            }
            BlockPos pos = firePlace.getLastKnownPosition();
            sender.sendMessage(new TextComponentString((name == null ? "<Unnamed>" : name) + " | " + String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()) + (ownerName != null ? " | " + ownerName : "")));
        }
    } else if (args[0].equals("festival")) {
        FestivalHandler handler = FestivalHandler.get(sender.getEntityWorld());
        List<EntityVillager> villagerList = sender.getEntityWorld().getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB(sender.getPosition()).grow(50));
        if (!villagerList.isEmpty()) {
            EntityVillager villager = villagerList.get(0);
            int success = handler.addFestival(villager);
            if (success == 2) {
                sender.sendMessage(new TextComponentTranslation("command.festival.scheduled"));
            } else {
                sender.sendMessage(new TextComponentTranslation("command.festival.failed"));
            }
        } else {
            sender.sendMessage(new TextComponentTranslation("command.festival.novillager"));
        }
    } else if (args[0].equals("ancientFurnace")) {
        WorldGenAncientFurnace.pattern.place(sender.getEntityWorld(), sender.getPosition(), 3);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) MessageNotification(lumien.randomthings.network.messages.MessageNotification) World(net.minecraft.world.World) ResourceLocation(net.minecraft.util.ResourceLocation) FlooNetworkHandler(lumien.randomthings.handler.floo.FlooNetworkHandler) EntityVillager(net.minecraft.entity.passive.EntityVillager) Style(net.minecraft.util.text.Style) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) IInventory(net.minecraft.inventory.IInventory) FestivalHandler(lumien.randomthings.handler.festival.FestivalHandler) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntitySlime(net.minecraft.entity.monster.EntitySlime) ItemBiomeCrystal(lumien.randomthings.item.ItemBiomeCrystal) TextComponentString(net.minecraft.util.text.TextComponentString) GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) FlooFireplace(lumien.randomthings.handler.floo.FlooFireplace)

Aggregations

Style (net.minecraft.util.text.Style)51 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)30 TextComponentString (net.minecraft.util.text.TextComponentString)21 ITextComponent (net.minecraft.util.text.ITextComponent)17 ClickEvent (net.minecraft.util.text.event.ClickEvent)10 BlockPos (net.minecraft.util.math.BlockPos)9 CommandException (net.minecraft.command.CommandException)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 ItemStack (net.minecraft.item.ItemStack)4 World (net.minecraft.world.World)4 Colony (com.minecolonies.coremod.colony.Colony)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 GameProfile (com.mojang.authlib.GameProfile)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 HoverEvent (net.minecraft.util.text.event.HoverEvent)2 Biome (net.minecraft.world.biome.Biome)2 FluidStack (net.minecraftforge.fluids.FluidStack)2