Is this possible? I would really like to extend it to use in my plugin as a unique type of player which has extra methods along with the ones in the Player class.
Is it possible to access the event or location of initially constructing the player event, so we can have it load from the new Player class? I'm interested in this, bu have no clue where I would have the opportunity to start it.
The instantiation of the Player Object happens somewhere between the PlayerPreLoginEvent and PlayerLoginEvent. But I'm pretty sure you would've to alter the bukkit code to create your own, new Player-object. I just took a look at the bukkit documentation and Player ist an interface. So forget anything i said Just create a new Interface public interface NewPlayer extends Player { //Add your new methods here } If u then want to use your new Player interface just cast the normal Player to your interface e.g. NewPlayer player = (NewPlayer) getServer().getPlayer("somePlayer"); I hope this helps greetings maxp0wer EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You can't do that. Example: Code: - Interface A - Class CraftA implements A This is mainly how CraftBukkit works. You can cast CraftA, which is 'related' to A, to the interface A. What happens when you put a custom interface there? Code: - Interface A - Interface CustomA extends A - Class CraftA implements A Now, CraftA isn't related to CustomA => you can't cast it to CustomA.
casting a parent to a child, stupid >.< thx darkman for the brain correction Hypothatical: does it work if you decompile bukkit, add an interface which inherits HumanEntity, Conversable, CommandSender, OfflinePlayer, PluginMessageRecipient then alter the Player class so inherits from your new interface and compile it again. Just thinking maybe I'm terribly wrong greetings maxp0wer EDIT by Moderator: merged posts, please use the edit button instead of double posting.
But if you want standard plugins to work with your edited version of the API you have to make non breaking changes. And if you make a plugin based on your modified API don't expect it to work on vanilla Bukkit servers.
"interconnecting" an interface with correct inheritance shouldn't affect other plugins i guess. Your new Interface would have only the information it gets from the parent classes. So you wouldn't have the full functionality of the player interface though.
Just extend Player and override the methods you want to and add the ones you want too Code: public class CustomPlayer extends Player{ methods methods } then just use the CustomPlayer object instead of a Player object
You can always use some kind of wrapper, like so Code: public class CustomPlayer { private Player player; private static Map<String, CustomPlayer> customplayers = new HashMap<String, CustomPlayer>(); private CustomPlayer(Player player) { this.player = player; customplayers.put(player.getName(), this); } // Return a running instance (or create a new one) public static CustomPlayer getInstanceOfPlayer(Player player) { if(!customplayers.containsKey(player.getName()) { return new CustomPlayer(player); } else if(customplayers.containsKey(player.getName()) { return customplayers.get(player.getName()); } else { } } // Your special (non-static) methods defined here: public String getSpecialName() { if(player.getName().equalsIgnoreCase("notch")) { return ChatColor.GREEN + player.getName(); } return player.getName(); } } Usage: Code: Player player = blub; CustomPlayer cplayer = CustomPlayer.getInstanceOfPlayer(player); Bukkit.broadcastMessage(cplayer.getSpecialName()); I don't actually know if it's allowed to have private constructors, but huh
You need to use the EntityPlayer NMS class, which frequently changes. And you'll also have to use CraftBukkit as your resource. In addition, you'll need to access a couple of private methods and other things. After that, you can make a class that extends CraftPlayer.