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);
}
}
}
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;
}
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]));
}
}
}
}
}
}
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()));
}
}
}
}
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);
}
}
Aggregations