Posted September 15, 201411 yr Hey I am using this code: mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + finalstring)); And it paint only the first line: How do I fix this?
September 16, 201411 yr Your best bet is to take the string you want to send, and String.split(" "), and add your formatting between each word. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr an example from some of my code (the string is already split into params[]): String msg = ""; for(int i = 0; i < params.length; i++){ msg += params[i]; msg += " "; msg += EnumChatFormatting.GRAY.toString() + EnumChatFormatting.ITALIC.toString(); } I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr String[] stringList = message.split(" +"); // string broken into words String formatting = EnumChatFormatting.GRAY.toString() + EnumChatFormatting.ITALIC.toString(); // formatting codes resultString = formatting + String.join(" " + formatting, stringList); // result with formatting between words -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
September 16, 201411 yr Author String[] stringList = String.split(" +",message); // string broken into words String formatting = EnumChatFormatting.GRAY.toString() + EnumChatFormatting.ITALIC.toString(); // formatting codes resultString = formatting + String.join(" " + formatting, stringList); // result with formatting between words "The method join(String, String[]) is undefined for the type String" 1410831192] an example from some of my code (the string is already split into params[]): String msg = ""; for(int i = 0; i < params.length; i++){ msg += params[i]; msg += " "; msg += EnumChatFormatting.GRAY.toString() + EnumChatFormatting.ITALIC.toString(); } It doesnt work It does split the word but the color doesn't work I did this: String[] stringList = msg.split(" "); for(int i = 0; i < stringList.length; i++){ finalstring += stringList[i]; finalstring += " "; finalstring += EnumChatFormatting.AQUA.toString() + EnumChatFormatting.ITALIC.toString();
September 16, 201411 yr Well you certainly have to adapt the concepts for your own usage... are you saying you got it fixed or that it still does not work? I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Author Well you certainly have to adapt the concepts for your own usage... are you saying you got it fixed or that it still does not work? I said it doesnt work: It doesnt work It does split the word but the color doesn't work
September 16, 201411 yr For complete clarity, can you please post the entire method containing the lines in question? Then we can make specific edits instead of theoretical ones and get you squared away. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Author For complete clarity, can you please post the entire method containing the lines in question? Then we can make specific edits instead of theoretical ones and get you squared away. else{ String[] stringList = msg.split(" "); for(int i = 0; i < stringList.length; i++){ finalstring += stringList[i]; finalstring += " "; finalstring += EnumChatFormatting.AQUA; } e.setCanceled(true); mc.thePlayer.addChatMessage(new ChatComponentText(finalstring)); } All the class: package com.TealNerd.SnitchCensor; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import net.minecraft.client.Minecraft; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class ChatFilter { Minecraft mc = Minecraft.getMinecraft(); public String msg; public String finalstring =""; private Pattern snitch = Pattern.compile("\\[[-0-9]* [0-9]* [-0-9]*\\]"); private Pattern user = Pattern.compile("([a-zA-Z0-9_]+?) entered snitch at"); public String username; protected boolean isEnemy = false; public Matcher snitchMatcher; public Matcher usernameMatcher; private String modDir = mc.mcDataDir + "/mods/SnitchCensor/"; public File bounties = new File(modDir, "perps.txt"); private Pattern name = Pattern.compile("\\\"name\\\":\\\"([A-Za-z0-9_]+?)\\\""); boolean hasBounty = false; { } @SubscribeEvent public void onChat(ClientChatReceivedEvent e) throws IOException{ msg = e.message.getUnformattedText(); Matcher snitchMatcher = snitch.matcher(msg); Matcher usernameMatcher = user.matcher(msg); if(SnitchCensor.custom){ if(snitchMatcher.find()){ if(usernameMatcher.find()){ username = usernameMatcher.group(1); } String dir = mc.mcDataDir + "/mods/RadarBro/"; File enemies = new File(dir, "EnemyList.txt"); Scanner input = new Scanner(enemies); while(input.hasNext()){ String nextLine = input.nextLine(); if(nextLine.equals(username)){ isEnemy = true; }else{ isEnemy = false; } } input.close(); String contents; Scanner in = new Scanner(bounties); contents = readFile(bounties); Matcher nameMatcher = name.matcher(contents); while(nameMatcher.find()) { if(nameMatcher.group(1).equals(username)) { hasBounty = true; break; } else { hasBounty = false; } } in.close(); if(isEnemy){ if(SnitchCensor.isEnabled){ e.setCanceled(true); finalstring = snitchMatcher.replaceAll("[**** ** ****]"); mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + finalstring)); }else{ e.setCanceled(true); finalstring = msg; mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + finalstring)); } }else if(hasBounty){ if(SnitchCensor.isEnabled){ e.setCanceled(true); finalstring = snitchMatcher.replaceAll("[**** ** ****]"); mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + finalstring)); }else{ e.setCanceled(true); finalstring = msg; mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + finalstring)); } }else{ if(SnitchCensor.isEnabled){ String[] stringList = msg.split(" "); for(int i = 0; i < stringList.length; i++){ finalstring += stringList[i]; finalstring += " "; finalstring += EnumChatFormatting.AQUA; } e.setCanceled(true); finalstring = snitchMatcher.replaceAll("[**** ** ****]"); mc.thePlayer.addChatMessage(new ChatComponentText(finalstring)); mc.thePlayer.addChatMessage(new ChatComponentText(stringList[stringList.length-1])); }else{ String[] stringList = msg.split(" "); e.setCanceled(true); mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + finalstring)); } } } }else if(SnitchCensor.isEnabled){ e.setCanceled(true); finalstring = snitchMatcher.replaceAll("[**** ** ****]"); mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + finalstring)); }else{ e.setCanceled(true); finalstring = msg; mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA + finalstring)); } } String readFile(File file) throws IOException { BufferedReader br = new BufferedReader(new FileReader(file)); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append("\n"); line = br.readLine(); } return sb.toString(); } finally { br.close(); } } }
September 16, 201411 yr First off put the chat formatting line at the beginning of your loop, before you add the split string. Also I see you made an edit to your post... maybe comment out the snitch replace method thing to see if it is what causes you problems. I personally am having browser issues trying to view your entire class on my mobile device or I could get more in depth I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr One more thing... add .toString () at the end of the chat formatting. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Author One more thing... add .toString () at the end of the chat formatting. Thx its working now! btw I have another question: I want to make a mod for multiplayer that msg the player every time a player join or leave the server. How do I identify when a new player join or leave the server?
September 16, 201411 yr Well it would be wise to post the question in a new thread, but you will have to hook an EntityPlayer event... is this something you are familiar with? You can most likely find a 5 minute tutorial video on the subject and theforge github references every event you can subscribe to. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Also, I see you are new to the boards; dont be afraid to click that thank you button in the corner if anyone wasof help to you! I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Author Well it would be wise to post the question in a new thread, but you will have to hook an EntityPlayer event... is this something you are familiar with? You can most likely find a 5 minute tutorial video on the subject and theforge github references every event you can subscribe to. I am new with Forge. I am just trying to make a simple mod for a server I am playing on. I know only basic java so I am having hard time doing it. If u know any other mod that does what I want it can really help me
September 16, 201411 yr If you are new to forge but interested in learning more, then subscribing to events and maybe writing a custom save file should be within your scope/a good learning experience and easy enough to find basic outlines and tutorials about them. My first thoughts on your approach would be as follows: create a static String[] to store currently online player names. subscribe to the EntityJoinWorldEvent https://github.com/MinecraftForge/MinecraftForge/blob/master/src/main/java/net/minecraftforge/event/entity/EntityJoinWorldEvent.java and add that player to the list, and also broadcast any messages to any other players on that list. You'll be using a lot of World.getPlayerEntityByName() and null checks. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Don't store the names, but the UUIDs, because there's gonna be name-change support and that will mess up your names. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
September 16, 201411 yr Don't store the names, but the UUIDs, because there's gonna be name-change support and that will mess up your names. This is pretty wise, especially if you plan on your server almost never restarting. Unless you are saving this list to file, it will clear out every time you restart the server. Edit: Although if you remove a player from the list every time you find a null, it will be self-cleaning anyway, and the "new name" (when that feature comes available) will be used the next time that individual player logs in. So if all you are using this list for is notifying players of login, you will only run into issues for one specific player, during the specific session in which they changed their name. If you want a list for more sophisticated and long-term uses, then you should most definitely take larsgerrits' advice. If it were me I would start simple and work up, since it's pretty much all stilla challenge for you. I'll need help, and I'll give help. Just ask, you know I will!
September 16, 201411 yr Author Don't store the names, but the UUIDs, because there's gonna be name-change support and that will mess up your names. This is pretty wise, especially if you plan on your server almost never restarting. Unless you are saving this list to file, it will clear out every time you restart the server. Edit: Although if you remove a player from the list every time you find a null, it will be self-cleaning anyway, and the "new name" (when that feature comes available) will be used the next time that individual player logs in. So if all you are using this list for is notifying players of login, you will only run into issues for one specific player, during the specific session in which they changed their name. If you want a list for more sophisticated and long-term uses, then you should most definitely take larsgerrits' advice. If it were me I would start simple and work up, since it's pretty much all stilla challenge for you. I am not making this mod for the server- this is a bukkit server and I am not the owner Is it going to work if the mod isnt install on the server?
September 16, 201411 yr Don't store the names, but the UUIDs, because there's gonna be name-change support and that will mess up your names. This is pretty wise, especially if you plan on your server almost never restarting. Unless you are saving this list to file, it will clear out every time you restart the server. Edit: Although if you remove a player from the list every time you find a null, it will be self-cleaning anyway, and the "new name" (when that feature comes available) will be used the next time that individual player logs in. So if all you are using this list for is notifying players of login, you will only run into issues for one specific player, during the specific session in which they changed their name. If you want a list for more sophisticated and long-term uses, then you should most definitely take larsgerrits' advice. If it were me I would start simple and work up, since it's pretty much all stilla challenge for you. I am not making this mod for the server- this is a bukkit server and I am not the owner Is it going to work if the mod isnt install on the server? That's a big no. It will work in single player. Or if you are the server, any client who also has the mod will be able to log in and it will work. If it is installed on the server a client can not log in unless they have it installed also. Simple as that. EnumChatFormatting.RED + String1 + EnumChatFormatting.RESET + String2 ? Issue already solved, and that's not it... I'll need help, and I'll give help. Just ask, you know I will!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.