Jump to content

[SOLVED][1.7.10]Changing name when commmand is fired and coloring string


KakesRevenge

Recommended Posts

Hello,

I have 2 questions :

1. I'm subscribing name format event for changing username when something is true ... and im changing something to true when my command is fired ... but then name format is changing only when i relog so my question is : is there a way to change it rightaway the command is pressed ?

 

2.How to color the string which will be displayed in displayname in name format event ?iv tried &6&l in lang folder but it doesnt work

 

Thx in advance :)

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

    public void onEvent(NameFormat event)

    {

        if (event.username.equalsIgnoreCase("failender"))

        {

            event.displayname = event.username+" the modder";

        }       

       

  }

 

This works for me. As for changing colors.. I dont know sorry

Maybe show some code?

Link to comment
Share on other sites

Command :

 

 

package cz.grossik.projektwow.command;

 

import net.minecraft.command.CommandBase;

import net.minecraft.command.ICommandSender;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.ChatComponentTranslation;

import cz.grossik.projektwow.ProjektWow;

import cz.grossik.projektwow.Reference;

import cz.grossik.projektwow.handler.PlayerClassHandler;

 

/**

@Author KakesRevenge

*/

 

public class Wizard extends CommandBase {

 

@Override

    public String getCommandName() {

        return "wizard";

    }

 

    @Override

    public int getRequiredPermissionLevel() {

        return 0;

    }

   

    @Override

    public String getCommandUsage(ICommandSender par1ICommandSender) {

        return "/wizard";

    }

   

    @Override

    public void processCommand(ICommandSender sender, String[] ArrayOfStr) {

    EntityPlayer player = getCommandSenderAsPlayer(sender);

        String name = player.getCommandSenderName();

        PlayerClassHandler props = PlayerClassHandler.get(player);

        int playerclass = props.CurrentClass;

       

        switch(playerclass) {

        case Reference.Unset:

        props.CurrentClass = Reference.Wizard;

        player.addChatComponentMessage(new ChatComponentText("Now you are a Wizard"));

        break;

        case Reference.Thief:

        player.addChatComponentMessage(new ChatComponentText("You are already a different class"));

        break;

        case Reference.Warrior:

        player.addChatComponentMessage(new ChatComponentText("You are already a Wizard"));

        break;

        case Reference.Wizard:

        player.addChatComponentMessage(new ChatComponentText("You are already a different class"));

        break;

        }

    } 

}     

 

 

 

NameFormatEvent

 

 

SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

    public void NamingPlayers(NameFormat event) {

PlayerClassHandler props = PlayerClassHandler.get(event.entityPlayer);

int playerclass = props.CurrentClass;

 

switch(playerclass) {

case Reference.Warrior:

event.displayname = Reference.ThiefName + event.username;

break;

case Reference.Thief:

event.displayname = Reference.ThiefName + event.username;

break;

case Reference.Wizard:

event.displayname = Reference.WizardName + event.username;

break;

}

}

 

 

The difference here is your name isnt changing

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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