Skip to content

Instantly share code, notes, and snippets.

Embed
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;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class ChangeName extends JavaPlugin {
Logger log = Logger.getLogger("Minecraft");
public void onDisable() {
log.info(this.getDescription().getName() + "disabled!");
}
public void onEnable() {
log.info(this.getDescription().getName() + "enabled!");
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (!(sender instanceof CraftPlayer)) {
sender.sendMessage("You are not a craftplayer!");
return true;
}
if (sender.hasPermission("changename.change")) {
CraftPlayer player = (CraftPlayer) sender;
if (args.length > 0) {
log.info("Player "+player.getName()+" changing name to "+args[0]);
sender.sendMessage("\u00a7eYou are now disguised as " + args[0] + "!");
PluginManager pm = getServer().getPluginManager();
pm.callEvent(new PlayerQuitEvent(player, "changing name"));
player.setDisplayName(args[0]);
setPlayerName(player.getHandle(), args[0]);
pm.callEvent(new PlayerJoinEvent(player, "changing name"));
} else {
sender.sendMessage("\u00a7eWrong usage! /changename <name>");
}
return true;
} else {
sender.sendMessage("\u00a7eYou do not have necessary permission to change your name.");
return true;
}
}
/**
* Set an EntityPlayer's name and update it to other clients
* @param player entityplayer to change name of
* @param newname name to set to
* @author lahwran
*/
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);
}
}
@jkmanye
Copy link

jkmanye commented Aug 31, 2020

Wow...
but had you been tested it?

@maxichrome
Copy link

maxichrome commented Feb 12, 2021

Wow...
but had you been tested it?

I'm sure you figured it out by now but this was made 2 months before Minecraft 1.0 came out, so it's safe to say it does not work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment