Solved Acessing player wrappers easily.

Discussion in 'Plugin Development' started by Lightspeed, Mar 25, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Lightspeed

    Now lets say NO MATTER where in my code I want to be able to convert the normal Player to my custom PlayerWrapper class with the same amount of code hopefully like a simply cast inside a command.

    I have this class called "Server" basically the server manager(Wrappers more server stuff not plugin stuff like the class "Bukkit").

    Now the problem is I really HATE using static so I thought maybe something like `LPlayer lp = new SPlayer(player)` but, thats impossible to have(I think).

    I'm simply just stuck here with another one of my threads with really bad grammer.
    Any ideas?

    My stackoverflow account has been question banned from when I had little java knowledge so I can't ask more simple things there and tried to use bukkit players with it.
     
  2. Offline

    Zombie_Striker

    @Lightspeed
    What you want to do is create your custom player class which will contain all the fields and methods you need. Inside that class, you will create a static Map, where the keys are the Player objects and the custom class would be the value. When you need to get the custom class instance associated with a player, get the class from the Map by using "Map.get(Player)".
    Unless you can edit the base bukkit code that creates the player object, and instead tell it to create your custom player class, there is no way for you to cast like that.
    There is no reason to "hate" the static modifier. You just need to know when to use it.
     
  3. Offline

    Lightspeed

    @Zombie_Striker So this would able to to do somthing like> "LPlayer lp = LPlayer.fetch(player);"
    I like the idea of this if I'm right and know java(Hopefully XD) ;-;

    I did try to use reflection to set bukkits players to my custom player but, It's final so I can't extend it >:C
     
  4. Offline

    Zombie_Striker

    Correct. What you would need to do is create a static method that returns an "LPlayer" object associated with that player. From there, it would return the LPlayer from the Map. Just note that if it does not exist/ the object is not in the map , the method will return a null object.
     
  5. Offline

    Lightspeed

    @Zombie_Striker Ok thanks I now understand what they mean by the class owns the varible/method(Static things).

    Not the instance . . .the class itself . . . yes I finally got it. XD

    This will do perfectly too! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page