Defining a player to check without a event..

Discussion in 'Plugin Development' started by mug561, Aug 17, 2014.

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

    mug561

    Just read the code:
    Code:java
    1. public void xptimer(){
    2. Player player = what do i put here?;
    3. float currentXP = player.getExp();
    4. if(mage.contains(player))
    5. if(currentXP <= 0.90){
    6. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    7.  
    8. @Override
    9. public void run() {
    10. if(player.getExp() <= 0.89){
    11. player.setExp((float) (player.getExp() + 0.1));
    12. }
    13. }
    14.  
    15. },60L,60L);
    16. }

    so im wondering how do i get a player to see if they're on the list, and have enough XP,
    i have other methods that define a player, but player and static dont go together...
     
  2. Offline

    excusemyluck

    Pass a player variable though your method. That will also kill your second line: "Player player = ....".
     
  3. Offline

    bennie3211

    just loop trought the list in your methode?
     
  4. Offline

    mug561

    excusemyluck Tried it, it doesnt find me... no xp regeneration...
    Code:java
    1. public void xptimer(final Player player){
    2. float currentXP = player.getExp();
    3. if(mage.contains(player))
    4. if(currentXP <= 0.90){
    5. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    6.  
    7. @Override
    8. public void run() {
    9. if(player.getExp() <= 0.89){
    10. player.setExp((float) (player.getExp() + 0.1));
    11. }
    12. }
    13.  
    14. },60L,60L);
    15. }
    16.  





    bennie3211 what do you mean?
     
  5. Offline

    Garris0n

    Well, first, you should probably stop using the static keyword, as it's pretty obvious you don't know how to do so.

    Second, how should we know what to put there? You need a player. Which player? Your question makes absolutely no sense.
     
  6. Offline

    mug561

    Garris0n any player.. that is in the list mage, and is at 90% xp to the next level..

    and as far as static goes, this is what i know: static lets you share a variable in teh same class with multiple methods... player is a variable.. but i cannot make it static, only final, which is not what i need... so im wondering if thers a way to share the same player variable between multiple methods in the same class...
     
  7. Offline

    Garris0n

    Then schedule something that loops through all online players constantly and finds the ones that fit your credentials.

    Also, you need to make the scheduler you posted earlier cancel itself...
     
  8. Offline

    mug561

    Garris0n and how would this be done? (Im a noob at bukkit coding..) (im talking about loop through all online players) i'd assume this would be accomplished through a for loop
     
  9. Offline

    _LB

    Just use an enhanced for loop on the return value of getServer().getOnlinePlayers()?
     
  10. Offline

    mug561

    _LB a for loop.. with what parameters, i dont know what gets all online players..
     
  11. Offline

    fireblast709

    Sorry to disappoint you, but you obviously do not know what static means. What you describe there is the functionality of a member variable (a variable declared in the class body).

    What is supposed to trigger the xptimer method in the first place? Can you show us that code?

    [edit] Wrongly worded. 'Class member' should be member variable.
     
    Garris0n likes this.
  12. Offline

    _LB

    Code:java
    1. for(Player p : getServer().getOnlinePlayers())
    2. {
    3. //
    4. }
     
Thread Status:
Not open for further replies.

Share This Page