Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Change Player Name Source code
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;
public class ChangePlayerName extends JavaPlugin {
Logger log = Logger.getLogger("Minecraft");
public void onDisable() { + "disabled!");
public void onEnable() { + "enabled!");
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!(sender instanceof CraftPlayer)) {
sender.sendMessage("You are not an in-game player!");
return false;
if (sender.hasPermission("changename.change")) {
EntityPlayer player = (EntityPlayer) ((CraftPlayer) sender).getHandle();
Player senderplayer = (Player) sender;
if (args.length > 0) {
sender.sendMessage("You are now discuised as " + args[0] + "!");
setPlayerName(player, args[0]);
} else {
sender.sendMessage("Wrong usage! /changename <name>");
return true;
} else {
sender.sendMessage("Nope, can't do that!");
return false;
//thanks to Lahwran for this code :D
public void setPlayerName(EntityPlayer player, String newname) {
WorldServer world = (WorldServer);
EntityTracker tracker = world.tracker;
tracker.untrackEntity(player); = newname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment