Search in sources :

Example 31 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project SpongeCommon by SpongePowered.

the class MixinNetHandlerHandshakeTCP method onProcessHandshakeStart.

@Inject(method = "processHandshake", at = @At(value = "HEAD"), cancellable = true)
public void onProcessHandshakeStart(C00Handshake packetIn, CallbackInfo ci) {
    if (SpongeImpl.getGlobalConfig().getConfig().getBungeeCord().getIpForwarding() && packetIn.getRequestedState().equals(EnumConnectionState.LOGIN)) {
        // ignore any extra data
        String[] split = packetIn.ip.split("\00\\|", 2)[0].split("\00");
        if (split.length == 3 || split.length == 4) {
            packetIn.ip = split[0];
            ((IMixinNetworkManager) this.networkManager).setRemoteAddress(new InetSocketAddress(split[1], ((InetSocketAddress) this.networkManager.getRemoteAddress()).getPort()));
            ((IMixinNetworkManager) this.networkManager).setSpoofedUUID(UUIDTypeAdapter.fromString(split[2]));
            if (split.length == 4) {
                ((IMixinNetworkManager) this.networkManager).setSpoofedProfile(gson.fromJson(split[3], Property[].class));
            }
        } else {
            TextComponentString chatcomponenttext = new TextComponentString("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
            this.networkManager.sendPacket(new SPacketDisconnect(chatcomponenttext));
            this.networkManager.closeChannel(chatcomponenttext);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) TextComponentString(net.minecraft.util.text.TextComponentString) IMixinNetworkManager(org.spongepowered.common.interfaces.IMixinNetworkManager) SPacketDisconnect(net.minecraft.network.login.server.SPacketDisconnect) TextComponentString(net.minecraft.util.text.TextComponentString) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 32 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project SpongeCommon by SpongePowered.

the class SpongeTexts method fixActionBarFormatting.

public static ITextComponent fixActionBarFormatting(ITextComponent component) {
    if (!component.getSiblings().isEmpty()) {
        List<ITextComponent> children = component.getSiblings();
        for (int i = 0; i < children.size(); i++) {
            children.set(i, fixActionBarFormatting(children.get(i)));
        }
    }
    TextComponentString result = new TextComponentString(((IMixinTextComponent) component).getLegacyFormatting());
    result.appendSibling(component);
    return result;
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 33 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Charset by CharsetMC.

the class SubCommandHelp method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    if (args.length >= 1) {
        SubCommand command = (getSide() == Side.CLIENT ? CommandCharset.CLIENT : CommandCharset.SERVER).SUB_COMMAND_MAP.get(args[0].toLowerCase());
        if (command != null && sender.canUseCommand(getPermissionLevel(), "charset") && (command.getSide() == Side.SERVER || (sender.getEntityWorld() != null && sender.getEntityWorld().isRemote))) {
            String[] usage = command.getUsage().split("\n");
            for (int i = 0; i < usage.length; i++) {
                sender.sendMessage(new TextComponentString(usage[i]));
            }
        } else {
            sender.sendMessage(new TextComponentTranslation("commands.generic.parameter.invalid", args[0]).setStyle(new Style().setColor(TextFormatting.RED)));
        }
    } else {
        for (SubCommand command : (getSide() == Side.CLIENT ? CommandCharset.CLIENT : CommandCharset.SERVER).SUB_COMMANDS) {
            if (sender.canUseCommand(getPermissionLevel(), "charset") && (command.getSide() == Side.SERVER || (sender.getEntityWorld() != null && sender.getEntityWorld().isRemote))) {
                String[] usage = command.getUsage().split("\n");
                if (usage.length > 0) {
                    String name = TextFormatting.BOLD + command.getName() + TextFormatting.RESET;
                    if (command.getAliases().size() > 0) {
                        name += " (" + CommandCharset.COMMAS.join(command.getAliases()) + ")";
                    }
                    sender.sendMessage(new TextComponentString("- " + name + ": " + usage[0]));
                    for (int i = 1; i < usage.length; i++) {
                        sender.sendMessage(new TextComponentString(usage[i]));
                    }
                }
            }
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 34 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Charset by CharsetMC.

the class SubCommandHand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    Entity e = sender.getCommandSenderEntity();
    if (e instanceof EntityPlayer) {
        ItemStack stack = ((EntityPlayer) e).getHeldItemMainhand();
        if (stack.isEmpty()) {
            sender.sendMessage(new TextComponentString(TextFormatting.RED + "Empty hand!"));
            return;
        }
        if (args.length > 0 && "ore".equalsIgnoreCase(args[0])) {
            Collection<String> names = new ArrayList<>();
            for (int id : OreDictionary.getOreIDs(stack)) {
                String name = OreDictionary.getOreName(id);
                names.add(name);
            }
            sender.sendMessage(new TextComponentString("Ores: [" + CommandCharset.COMMAS.join(names) + "]"));
        } else if (args.length > 0 && "material".equalsIgnoreCase(args[0])) {
            ItemMaterial material = ItemMaterialRegistry.INSTANCE.getMaterialIfPresent(stack);
            if (material == null) {
                sender.sendMessage(new TextComponentString(TextFormatting.RED + "Not a material!"));
            } else {
                sender.sendMessage(new TextComponentString(TextFormatting.GREEN + material.getId()));
                sender.sendMessage(new TextComponentString("[" + CommandCharset.COMMAS.join(material.getTypes()) + "]"));
                for (Map.Entry<String, ItemMaterial> entry : material.getRelations().entrySet()) {
                    sender.sendMessage(new TextComponentString("-> " + entry.getKey() + ": " + entry.getValue().getId()));
                }
            }
        } else {
            sender.sendMessage(new TextComponentString(TextFormatting.YELLOW + stack.toString() + " " + TextFormatting.GRAY + "(" + stack.getItem().getRegistryName() + ")"));
            if (stack.hasTagCompound()) {
                sender.sendMessage(new TextComponentString(stack.getTagCompound().toString()));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 35 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project Charset by CharsetMC.

the class CharsetTransportCarts method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
    if (event.getTarget() instanceof EntityMinecart && !event.getTarget().getEntityWorld().isRemote && event.getItemStack().getItem() == itemLinker) {
        EntityMinecart cart = (EntityMinecart) event.getTarget();
        if (linkMap.containsKey(event.getEntityPlayer())) {
            EntityMinecart cartOther = linkMap.remove(event.getEntityPlayer());
            Linkable link = linker.get(cart);
            Linkable linkOther = linker.get(cartOther);
            if (event.getEntityPlayer().isSneaking()) {
                if (linker.unlink(link, linkOther)) {
                    event.getEntityPlayer().sendMessage(new TextComponentString("dev_unlinked2"));
                } else {
                    event.getEntityPlayer().sendMessage(new TextComponentString("dev_unlink2_failed"));
                }
            } else {
                if (link.next == null && linkOther.previous == null) {
                    linker.link(link, linkOther);
                    event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked2"));
                } else if (link.previous == null && linkOther.next == null) {
                    linker.link(linkOther, link);
                    event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked2"));
                } else {
                    event.getEntityPlayer().sendMessage(new TextComponentString("dev_link2_failed"));
                }
            }
        } else {
            linkMap.put(event.getEntityPlayer(), cart);
            event.getEntityPlayer().sendMessage(new TextComponentString("dev_linked1"));
        }
        event.setCanceled(true);
    }
}
Also used : Linkable(pl.asie.charset.module.transport.carts.link.Linkable) EntityMinecart(net.minecraft.entity.item.EntityMinecart) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

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