fredoduquartier Posted April 9, 2014 Posted April 9, 2014 hello all, I was trying to make a command to get colored chat in smp and i found a command, the problem is I cant get it work: the command that is used in original minecraft code this.mcServer.getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromTranslationWithSubstitutions("multiplayer.player.left", new Object[] {this.playerEntity.getTranslatedEntityName()}).setColor(EnumChatFormatting.YELLOW)); but i try using this command that does not work: FMLServerHandler.instance().getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromTranslationKey("multiplayer.player.left").setColor(EnumChatFormatting.YELLOW)); i think it is due to server because it works in normal minecraft, so it should be related to the main mod class? it might also be that i use it as a command: package updatecheck.common.commands; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.server.FMLServerHandler; import updatecheck.common.StringModif; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.network.NetServerHandler; import net.minecraft.src.ModLoader; import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.EnumChatFormatting; public class CCC extends CommandBase{ @Override public String getCommandName() { // TODO Auto-generated method stub return "CC"; } @Override public String getCommandUsage(ICommandSender icommandsender) { // TODO Auto-generated method stub return "colour your chat messages!"; } @Override public void processCommand(ICommandSender icommandsender, String[] astring) { StringModif f = new StringModif(); ChatMessageComponent s = new ChatMessageComponent(); Object o = astring[0]; //s = FMLServerHandler.instance().getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromTranslationKey("multiplayer.player.left").setColor(EnumChatFormatting.YELLOW)); } } I hope someone can help me. Quote
fredoduquartier Posted April 9, 2014 Author Posted April 9, 2014 found it out just this: MinecraftServer.getServer().getConfigurationManager().sendChatMsg(etc...) Quote
fredoduquartier Posted April 9, 2014 Author Posted April 9, 2014 but there is still an oher problem: when i try to vary the text, it does not show anything, anyone an idea?: package updatecheck.common.commands; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.server.FMLServerHandler; import updatecheck.common.StringModif; import updatecheck.common.UpdateCheckMod; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.network.NetServerHandler; import net.minecraft.server.MinecraftServer; import net.minecraft.src.ModLoader; import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.EnumChatFormatting; public class CCC extends CommandBase{ @Override public String getCommandName() { // TODO Auto-generated method stub return "CC"; } @Override public String getCommandUsage(ICommandSender icommandsender) { // TODO Auto-generated method stub return "colour your chat messages!"; } @Override public void processCommand(ICommandSender icommandsender, String[] astring) { StringModif f = new StringModif(); ChatMessageComponent s = new ChatMessageComponent(); s=f.editstring2(astring[astring.length-1]); //s = MinecraftServer.getServer().getConfigurationManager().sendChatMsg(s); //UpdateCheckMod.instance. } } public ChatMessageComponent editstring2(String s){ String[] sa = s.split("#"); int j = sa.length; int i; ChatMessageComponent q = new ChatMessageComponent(); //q=q.addText(""); String[] o = new String[j]; for (i = 0; i < j; i++){ if(sa[i].equals("BLACK")){ q=q.setColor(cf.BLACK); }else if(sa[i].equals("BLUE")){ q=q.setColor(cf.BLUE); }else if(sa[i].equals("RANDOM")){ q=q.setColor(cf.OBFUSCATED); }else if(sa[i].equals("STHROUGH")){ q=q.setColor(cf.STRIKETHROUGH); }else if(sa[i].equals("LBLUE")){ q=q.setColor(cf.AQUA); }else if(sa[i].equals("BOLD")){ q=q.setColor(cf.BOLD); }else if(sa[i].equals("GOLD")){ q=q.setColor(cf.GOLD); }else if(sa[i].equals("GRAY")){ q=q.setColor(cf.GRAY); }else if(sa[i].equals("GREEN")){ q=q.setColor(cf.GREEN); }else if(sa[i].equals("ITALIC")){ q=q.setColor(cf.ITALIC); }else if(sa[i].equals("LPURPLE")){ q=q.setColor(cf.LIGHT_PURPLE); }else if(sa[i].equals("RED")){ q=q.setColor(cf.RED); }else if(sa[i].equals("UNDERL")){ q=q.setColor(cf.UNDERLINE); }else if(sa[i].equals("WHITE")){ q=q.setColor(cf.WHITE); }else if(sa[i].equals("YELLOW")){ q=q.setColor(cf.YELLOW); }else if(sa[i].equals("DBLUE")){ q=q.setColor(cf.DARK_BLUE); }else if(sa[i].equals("DGRAY")){ q=q.setColor(cf.DARK_GRAY); }else if(sa[i].equals("DGREEN")){ q=q.setColor(cf.DARK_GREEN); }else if(sa[i].equals("DRED")){ q=q.setColor(cf.DARK_RED); }else if(sa[i].equals("DPURPLE")){ q=q.setColor(cf.DARK_PURPLE); }else if(sa[i].equals("RESET")){ q=q.setColor(cf.RESET); }else if(sa[i]== null){ }else{ q.addText(o[i]); } } //q=q+o[i]; return q; } Quote
GotoLink Posted April 9, 2014 Posted April 9, 2014 1\ Check the null values first. 2\ Don't make objects if you don't use them. 3\ You can get enum values from String. 4\ String[] o = new String[j]; Is void at initialization. 5\ The "command usage" is the help given to the player. Add some meaningful info here (parameters, expected values, etc). Quote
fredoduquartier Posted April 14, 2014 Author Posted April 14, 2014 thanks, it worked! i forgot to change the o string to sa string Quote
Recommended Posts
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.