Created
September 1, 2011 15:10
-
-
Save jmurth1234/1186367 to your computer and use it in GitHub Desktop.
Ok, here is code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package net.rymate.ChangeName; | |
import java.util.logging.Logger; | |
import net.minecraft.server.EntityPlayer; | |
import net.minecraft.server.EntityTracker; | |
import net.minecraft.server.WorldServer; | |
import org.bukkit.ChatColor; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandSender; | |
import org.bukkit.craftbukkit.entity.CraftPlayer; | |
import org.bukkit.entity.Player; | |
import org.bukkit.plugin.java.JavaPlugin; | |
/** | |
* | |
* @author rymate | |
*/ | |
public class ChangePlayerName extends JavaPlugin { | |
Logger log = Logger.getLogger("Minecraft"); | |
public void onDisable() { | |
log.info(this.getDescription().getMain() + "disabled!"); | |
} | |
public void onEnable() { | |
log.info(this.getDescription().getMain() + "enabled!"); | |
} | |
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { | |
if (args[0].equalsIgnoreCase("changename")) { | |
if (!(sender instanceof CraftPlayer)) { | |
sender.sendMessage("You are not an in-game player!"); | |
return false; | |
} | |
EntityPlayer player = (EntityPlayer) ((CraftPlayer) sender).getHandle(); | |
if (args.length > 1) { | |
setPlayerName(player, args[1]); | |
sender.sendMessage("Your name has been changed to " + args[1]); | |
return true; | |
} | |
return true; | |
} | |
return true; | |
} | |
//thanks to Lahwran for this code :D | |
public void setPlayerName(EntityPlayer player, String newname) { | |
WorldServer world = (WorldServer) player.world; | |
EntityTracker tracker = world.tracker; | |
tracker.untrackEntity(player); | |
player.name = newname; | |
tracker.track(player); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment