Overriding Methods in Player class

Discussion in 'Spigot Plugin Development' started by Leniency, Dec 16, 2016.

Thread Status:
Not open for further replies.
  1. How would i go about overriding and adding methods to the Player class. I was thinking about making a custom player class that extends Player and doing it there, but I thought that it might not work due to casting and the way you have to register custom entities in spigot. If someone could tell me a way to do this, I would appreciate it.
  2. a9e


    Use a player wrapper.

    Code (Text):
    public class Profile {

      private Player player;

      public Profile(Player player) {
        this.player = player;

      public Player getPlayer() {
        return player;

    You can add variables to your wrapper related to a player, manipulate them, etc.
    This is pretty much common sense, but hopefully this will set you on the right track nonetheless.
  3. Yea I thought about this, but it won't really help me much as I want to be able to create a custom palyer class instead of using the way you showed above. I am only going to be adding a few methods. Otherwise it would be kinda useless to just be getting the player for every method I want to use.
  4. a9e


    You wouldn't be able to cast a player to your custom player object without modifying other aspects. It's much more logical to use a wrapper, there are already discussions regarding this exact topic on these forums.

    Take a look at this and this.
    #4 a9e, Dec 16, 2016
    Last edited: Dec 16, 2016
  5. Okay, the casting part is what I wanted to know. Thanks.
Thread Status:
Not open for further replies.