Solved String to player

Discussion in 'Plugin Development' started by 8jy89hui, Nov 29, 2014.

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

    8jy89hui

    Does anyone know a way to convert a string to a player from within the PLAYER metheods not using Bukkit.getPlayer()? Currently I am creating a subtype of player called CastPlayer but bukkit.getPlayer() returns a player and if I cast that to CastPlayer I get the error org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer cannot be cast to Types.CastPlayer . Does anyone know a way to make this work: CastPlayer SavedPlayer = Bukkit.getPlayer(args[0]);
     
  2. Offline

    timtower Administrator Administrator Moderator

    8jy89hui What kind of player do you need then? How does that CastPlayer class look like?
     
  3. Offline

    8jy89hui

    This is the code for CastPlayer
    Code:java
    1. package Types;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5.  
    6. public abstract class CastPlayer implements Player{
    7. Player player;
    8. public static int SteamCount;
    9. public static Team Team;
    10. public static int Mana;
    11. public static boolean isHero;
    12. public CastPlayer(int SteamCount, Team Team, int Mana, boolean isHero) {
    13. this.player=player;
    14. this.SteamCount=SteamCount;
    15. this.Team=Team;
    16. this.Mana=Mana;
    17. this.isHero=isHero;
    18. }
    19. public int GetSteamCount(CastPlayer x){
    20. return this.SteamCount;
    21. }
    22. public Team GetTeam(CastPlayer x){
    23. return this.Team;
    24. }
    25. public int GetMana(CastPlayer x){
    26. return this.Mana;
    27. }
    28. public boolean isHero(CastPlayer x){
    29. return this.isHero;
    30. }
    31. public Player GetPlayer(){
    32. return this.player;
    33. }
    34. /*public CastPlayer PlayerToCastPlayer(Player x){
    35.   String Name = x.getName();
    36.   String[] PLetters = Name.split("");
    37.   Player[] OPL = Bukkit.getOnlinePlayers();
    38.   for (int xx = 0; xx<OPL.length; xx++){
    39.   String[] CPLetters = OPL[xx].getName().split("");
    40.   if (OPL[xx].equals(PLetters)){
    41.   CastPlayer CP = OPL[xx];
    42.   }
    43.   }
    44.  
    45.   return CP;
    46.   }*/
    47. }
    48.  
     
  4. Offline

    timtower Administrator Administrator Moderator

    8jy89hui Besides the fact that you never set the player in the method, and your getMana methods etc require an argument without using it.
    I think that you need to redesign this method.
    Make a function to get a CastPlayer from somebody, don't make it an abstract class though, you don't need that.
     
  5. Offline

    8jy89hui

    Im sorry im pretty new to this :p, what do you mean by "Make a function to get a CastPlayer from somebody"?
     
  6. Offline

    timtower Administrator Administrator Moderator

    8jy89hui Currently your player variable isn't set, nor do you have any kind of storage as far as I know.
    Make a function in your main class or something like: getCastPlayer(Player p), that method will set the player variable, load all the other fields etc.
    And you probably don't want CastPlayer to implement Player
     
  7. Offline

    8jy89hui

    If CastPlayer implements Player then I get to use all the player methods though ? Or is there another way to do that
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    8jy89hui

    What do you mean? Where should I place that code? (Sorry still tring to understand bukkit)
     
  10. Offline

    timtower Administrator Administrator Moderator

    This would be a start:
    Code:java
    1. package Types;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5.  
    6. public abstract class CastPlayer{
    7. private Player player;
    8. private int SteamCount;
    9. private Team Team;
    10. private int Mana;
    11. private boolean isHero;
    12. public CastPlayer(Player player, int SteamCount, Team Team, int Mana, boolean isHero) {
    13. this.player=player;
    14. this.SteamCount=SteamCount;
    15. this.Team=Team;
    16. this.Mana=Mana;
    17. this.isHero=isHero;
    18. }
    19. public int GetSteamCount(){
    20. return this.SteamCount;
    21. }
    22. public Team GetTeam(){
    23. return this.Team;
    24. }
    25. public int GetMana(){
    26. return this.Mana;
    27. }
    28. public boolean isHero(){
    29. return this.isHero;
    30. }
    31. public Player GetPlayer(){
    32. return this.player;
    33. }
    34. }
    35.  
     
  11. Offline

    8jy89hui

    Thanks I understand all that but how would I get all the player methods? Im just trying to create a different type of player ?
     
  12. Offline

    timtower Administrator Administrator Moderator

    8jy89hui If you do that then you must be able to get your type of player instead of the regular player, all plugins will return the regular player. And casting this isn't easy either.
    So lets start with this: why are you trying to make a new type of player?
     
  13. Offline

    8jy89hui

    I am trying to create a new type of player so that I can store individual variables for each player without having to use a hashmap for each variable (like mana and steamcount)
     
  14. Offline

    timtower Administrator Administrator Moderator

    8jy89hui You don't need to implement player for that.
    A class with those variables and an UUID will do fine as well. And then 1 hashmap where you can call map.get(player.getUniqueUid()).getMana
     
  15. Offline

    8jy89hui

    Wait... is it possible to go and modify the craftbukkit.jar so that I can add a method that returns CastPlayer and add the class CastPlayer into the actual Jar instead of using plugins?

    ahh that makes sense Ill try that

    EDIT by TImtower: merged posts
     
  16. Offline

    timtower Administrator Administrator Moderator

    8jy89hui Bit of a hassle for 1 plugin isn't it? You won't get support for it on here at least.
     
  17. Offline

    mythbusterma

    8jy89hui

    In short: no.

    In long: the method to do so is far more complicated than you could comprehend.
     
  18. Offline

    8jy89hui

    Yeah im building a custom plugin for my friends server but I think I will just go with your idea so that updating is easier
     
Thread Status:
Not open for further replies.

Share This Page