Player in onEnable

Discussion in 'Plugin Development' started by CactusComboPvP, Aug 23, 2014.

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

    CactusComboPvP

    Hi, I have a question. How can I declare a player in onenable?
    I am using something like this
    Code:java
    1. if (this.settings.getData().getInt("stats." + p.getName() + ".fcredits") < 0) {
    2. this.settings.getData().set("stats." + p.getName() + ".fcredits", Integer.valueOf(0));
    3. }
    4. this.settings.saveData();
    5. p.kickPlayer(ChatColor.RED + "The server was reloaded!");


    So I need to have a player, how can I do that?
     
  2. Offline

    unon1100

    Why do you need a player? Also, there are rarely players on as the plugin enables (unless you're reloading, which you should never do)
     
  3. Offline

    CactusComboPvP

    unon1100
    I need it though, for the event I am doing,
    So please help me out as I need to reset the stats as soon as the server starts in the config.
    I need it for config
    1. if (this.settings.getData().getInt("stats." + p.getName() + ".fcredits") < 0) {
    2. this.settings.getData().set("stats." + p.getName() + ".fcredits", Integer.valueOf(0));
    3. }
    S
     
  4. Offline

    unon1100

    getConfig().getKeys(boolean deep);

    Play around with that a bit.
     
  5. Offline

    CactusComboPvP

    unon1100

    I am confused I need to define p as a player
     
  6. Offline

    teej107

  7. Offline

    unon1100

    teej107 He is wondering how to clear stats when the server starts, there aren't online players when the server starts

    CactusComboPvP Player objects only represent players that are currently online. There aren't any players that are online when the server is starting. Instead what you should do is use getConfig().getConfigurationSection("stats").getKeys(false);
    That method will return a set of every player name in the config.
     
  8. Offline

    CactusComboPvP

    unon1100
    Yes but it is personal stats for everyone
    look at this line:
    Code:java
    1. if (this.settings.getData().getInt("stats." + p.getName() + ".fcredits") < 0)
    2. this.settings.getData().set("stats." + p.getName() + ".fcredits", Integer.valueOf(0));{
     
  9. Offline

    stormneo7

    How're you getting the names/uuids of the players?
    Do you have a list or what?...
     
  10. Offline

    CactusComboPvP

    unon1100 stormneo7
    It works as a /join command. When they join, it puts there name in the config yml file.

    I found a code like this:
    Code:java
    1. Entity e = (localObject = Bukkit.getOnlinePlayers()).length; for (Entity localEntity1 = 0; localEntity1 < e; localEntity1++) { Player player = localObject[localEntity1];
    2. Player p = player;


    But it gives me errors

    Anything?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  11. Offline

    xTrollxDudex

    1) Learn programming logic
    2) ???
    3) Profit
     
    ZodiacTheories likes this.
  12. Offline

    AronTheGamer

    getServer().getPlayer( playerUsername ) or getServer().getPlayer( playerUuid )
     
Thread Status:
Not open for further replies.

Share This Page