How can I create this list?

Discussion in 'Plugin Development' started by football70500, Aug 3, 2015.

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


    Well basically I want to use
    2. getConfig().set("Players." + target.getName() + ".Frozen", true;
    when I /freeze a player

    But I don't know how to register this in my onEnable. How would I go about this?
  2. Offline


    You would execute it, after you executed your command.
  3. Offline


    So on my onEnable I don't have to create anything in my config?
    (I create my config file in my OnEnable)
  4. Offline


    If you created the config all you have to do is retrieve that value with and the set value getConfig.("dsas", value)
  5. Offline


    @football70500 In your onEnable(), call saveDefaultConfig. Make sure to include a config.yml in your plugin, even if it's blank. After that, just do what you do normally. Just make sure to test whether the key exists before getting it. Setting's fine.
  6. Offline


  7. Offline


    Okay so i make a config which is the default config.yml file, loadDefaultConfig and in that config file, I have

            Frozen: true
  8. @football70500 To set this value do something like this:

    Player targetPlayer = Bukkit.getPlayer( args[0] ) //Assuming it's /freeze <player>
    getConfig().set( "Players." + targetPlayer.getName() + ".Frozen", true );
    Then I assume you already have an event to check when the Player moves if they are frozen? I was also thinking that it would be great practice to use UUID's. And also probably a reason for why the target is being frozen. And then you unfreeze them remove them from the config file to reduce space.
  9. Offline


    @pie_flavor do I save the default config before or after I set up all my strings?

    2. @Override
    3. public void onEnable() {
    4. getLogger().info("cFreeze is now enabled!");
    5. getConfig().addDefault("cFreeze.FreezeMessage",
    6. new String("&9You have been frozen!"));
    7. getConfig().addDefault("cFreeze.UnfreezeMessage",
    8. new String("&9You are no longer frozen!"));
    9. getConfig().addDefault("cFreeze.DamagerMessage",
    10. new String("&cYou cant hit a player while they are frozen!"));
    11. getConfig().addDefault("cFreeze.MoveAttemptMessage",
    12. new String("&9You cant move when you are frozen!"));
    13. getConfig().addDefault("cFreeze.LogMessage",
    14. new String("&c%player has logged while frozen!"));
    15. getConfig()
    16. .addDefault("cFreeze.SpamLoggerMessage", new String("false"));
    17. getConfig()
    18. .addDefault(
    19. "cFreeze.LockedMessage",
    20. new String(
    21. "&dThe server is currently frozen by an administrator, you should be able to connect in a few minutes."));
    22. getConfig().addDefault("cFreeze.BanMessage",
    23. new String("&aYou have been banned for logging while frozen!"));
    24. getConfig().addDefault("cFreeze.JoinFrozenServerMessage",
    25. new String("&eThe server is currently frozen!"));
    26. getConfig().addDefault("cFreeze.frozen", new String("false"));
    27. getConfig().addDefault("cFreeze.LockServer", new String("false"));
    28. getConfig().addDefault("cFreeze.BanLogger", new String("false"));
    29. getServer().getPluginManager().registerEvents(this, this);
    30. getConfig().options().copyDefaults(true);
    31. saveConfig();
    32. }

    Also, how would I check if Players.<name>.Frozen is true?

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


  11. Offline


    @football70500 Dude, you don't need all that stuff. Just write it in the config.yml inside your jar, and it will be automatically copied over when you do saveDefaultConfig().
    Also: Why are you doing new String()? new String("Hello") is exactly the same as "Hello".
  12. Offline


  13. Offline


  14. Offline


    Sure. Great job. :) One thing though is that most things in there could be shortened extremely easily, for example:

    You do not need to use new String(""), you can simply do "". (As said above)

    You asked how to get a boolean from a config when it was in a link that someone already posted.

    You used new String("false") and new String("true"), which is incorrect. You should simply use true or false because using getBoolean possibly would not work because it is a string not a boolean.

    I personally take all of the information above and then put links pointing to the correct place where you should be looking, In this case to java tutorials.
Thread Status:
Not open for further replies.

Share This Page