Two Problems

Discussion in 'Plugin Development' started by ZodiacTheories, Jul 19, 2014.

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

    ZodiacTheories

    Hi, I get no error, but when a Player joins, nothing appears in the config.

    Code:java
    1. package org.zodiactheories.pandorm;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7.  
    8. public class JoinEvent implements Listener {
    9.  
    10. @EventHandler
    11. public void onJoin(PlayerJoinEvent e) {
    12. Player p = e.getPlayer();
    13. LevelMethods.setLevel(p, 0);
    14. LevelMethods.setPoints(p, 0);
    15. if (!Core.getInstance().getConfig().contains("players." + p.getName() + ".points")) {
    16. Core.getInstance().getConfig().createSection("players." + p.getName() + ".points");
    17. }
    18. Core.getInstance().getConfig().set("players." + p.getName(), ".level" + LevelMethods.getLevel(p));
    19. Core.getInstance().getConfig().set("players..level.points", LevelMethods.getPoints(p));
    20. }
    21. }


    And I have registered my events.

    My second problem is that when the king is thesamster8, nothing is broadcasted when I am killed by the environment:

    Code:java
    1. @EventHandler
    2. public void onDeath(EntityDamageEvent e) {
    3. Entity ent = e.getEntity();
    4. if(ent instanceof Player) {
    5. Player p = (Player) e.getEntity();
    6. if(p.getName().equals(Core.getInstance().getConfig().getString("king"))) {
    7. if(p.getHealth() <=0) {
    8. Bukkit.broadcastMessage(Core.getInstance().PREFIX + ChatColor.RED + " The king has died of natural causes!");
    9. Core.getInstance().getConfig().set("king", "There is no king!");
    10. }
    11. }
    12. }
    13. }
    14.  

    Thanks
     
  2. Offline

    artish1

    ZodiacTheories
    You might need to put saveConfig(); after setting a few variables for them to show up inside the config file itself physically.

    And for your second problem i would instead do PlayerDeathEvent instead of EntityDamageEvent... and then check if the player is the king... and then broadcast your message :)

    Edit: don't forget to double check up on everything, as when your coding, even when saving and getting variables from the configs, they must be case sensitive and have correct spelling
     
  3. ZodiacTheories
    You aren't actually writing the changes in the file to disk. You've just changed them in memory. As for your second problem, try just using "isDead()".
     
  4. Offline

    ZodiacTheories

    artish1 The Gaming Grunts

    Now, I have two more problems.

    1.

    This is what I get in my config:

    Code:
    players:
      thesamster8:
        points: {}
      level:
        points: 0
    With this:

    Code:java
    1. package org.zodiactheories.pandorm;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7.  
    8. public class JoinEvent implements Listener {
    9.  
    10. @EventHandler
    11. public void onJoin(PlayerJoinEvent e) {
    12. Player p = e.getPlayer();
    13. LevelMethods.setLevel(p, 0);
    14. LevelMethods.setPoints(p, 0);
    15. if (!Core.getInstance().getConfig().contains("players." + p.getName() + ".level" + ".points")) {
    16. Core.getInstance().getConfig().createSection("players." + p.getName() + ".level" + ".points");
    17. Core.getInstance().saveConfig();
    18. Core.getInstance().reloadConfig();
    19. }
    20. Core.getInstance().getConfig().set("players." + p.getName(), ".level" + LevelMethods.getLevel(p));
    21. Core.getInstance().getConfig().set("players..level.points", LevelMethods.getPoints(p));
    22. Core.getInstance().saveConfig();
    23. Core.getInstance().reloadConfig();
    24. }
    25. }


    How would I change it to

    Code:
    players:
      thesamster8:
        level: 0
        points: 0
      
    Whenever a Player joins?

    2:

    There is no king string in the config, here is the code:

    Code:java
    1. @Override
    2. public void onEnable() {
    3. getConfig().options().copyDefaults(true);
    4. saveConfig();
    5. getServer().getPluginManager().registerEvents(new JoinEvent(), this);
    6. getServer().getPluginManager().registerEvents(new King(), this);
    7. getServer().getPluginManager().registerEvents(new Update(), this);
    8. getCommand("king").setExecutor(new King());
    9. getCommand("level").setExecutor(new King());
    10. getCommand("reloadconfig").setExecutor(new Commands());
    11. instance = this;
    12. if(!getConfig().contains("king")) {
    13. getConfig().addDefault("king", null);
    14. }
    15. }
    16. }
    17.  


    Thanks
     
  5. Offline

    Plugers11

    ZodiacTheories
    I think this is bad : Core.getInstance().getConfig().set("players..level.points", LevelMethods.getPoints(p));
     
  6. Offline

    ZodiacTheories

    Plugers11

    Huh? Could you please use proper formatting
     
  7. Offline

    fireblast709

    ZodiacTheories create a section "players.<name>", and set "players.<name>.level" and "players.<name>.points". Secondly, null is the same as removing it. So adding a default with null is the same as not adding the default
     
  8. Offline

    ZodiacTheories

    fireblast709

    Oh, thanks, I will go and test

    fireblast709

    The king string still doesn't appear:

    Code:java
    1. @Override
    2. public void onEnable() {
    3. getConfig().options().copyDefaults(true);
    4. saveConfig();
    5. getServer().getPluginManager().registerEvents(new JoinEvent(), this);
    6. getServer().getPluginManager().registerEvents(new King(), this);
    7. getServer().getPluginManager().registerEvents(new Update(), this);
    8. getCommand("king").setExecutor(new King());
    9. getCommand("level").setExecutor(new King());
    10. getCommand("reloadconfig").setExecutor(new Commands());
    11. instance = this;
    12. if(!getConfig().contains("king")) {
    13. getConfig().addDefault("king", "There is currently no king!");
    14. }
    15. }
    16. }


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

    fireblast709

    ZodiacTheories move the copyDefaults and saveConfig lines below the addDefault
     
  10. Offline

    ZodiacTheories

    fireblast709

    Derp.

    Now I have just one more problem. When I join, the config looks like this:

    Code:
    king: There is currently no king!
    players:
      thesamster8:
        points: {}
      level:
        points: 0
    
    JoinEvent:

    Code:java
    1. package org.zodiactheories.pandorm;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7.  
    8. public class JoinEvent implements Listener {
    9.  
    10. @EventHandler
    11. public void onJoin(PlayerJoinEvent e) {
    12. Player p = e.getPlayer();
    13. //if(!p.hasPlayedBefore) {
    14. if(!Core.getInstance().getConfig().contains("players." + p.getName())) {
    15. Core.getInstance().getConfig().createSection("players." + p.getName());
    16. Core.getInstance().getConfig().set("players." + p.getName() + ".level", 0);
    17. Core.getInstance().getConfig().set("players." + p.getName() + ".level" + ".points", 0);
    18. Core.getInstance().saveConfig();
    19. }
    20. }
    21. }
    22.  


    How would I remove the points: {} thing under thesamster8?

    Thanks
     
  11. Offline

    fireblast709

    ZodiacTheories
     
  12. Offline

    ZodiacTheories

    fireblast709

    Haven't I done that in the post above? If not, I don't really understand what you mean
     
  13. Offline

    fireblast709

    ZodiacTheories not level.points, just points. Also you might need to remove the old data to get it set again
     
  14. Offline

    ZodiacTheories

    fireblast709

    Code:java
    1. Core.getInstance().getConfig().set("players." + p.getName() + "points", 0);


    This does this:

    Code:
      thesamster8:
        level: 0
        thesamster8points: 0
     
  15. Offline

    fireblast709

  16. Offline

    ZodiacTheories

Thread Status:
Not open for further replies.

Share This Page