Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

  • Author

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;
	}

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).

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.