Configuration

Discussion in 'Plugin Development' started by FlareLine, Oct 2, 2013.

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

    FlareLine

    Just need someone to check if I am approaching this correctly please...
    Code:java
    1. package dev.flareline.ipcheck;
    2.  
    3. import java.io.File;
    4. import java.util.ArrayList;
    5.  
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class IPCMain extends JavaPlugin implements Listener {
    14.  
    15. public static ArrayList<String> OnlinePlayers = new ArrayList<String>();
    16.  
    17. @Override
    18. public void onEnable() {
    19.  
    20. getServer().getPluginManager().registerEvents(new IPCMain(), this);
    21.  
    22. // Start Configuration
    23.  
    24. File ConfigFile = new File("/config.yml");
    25. if (!ConfigFile.exists()) {
    26. this.saveDefaultConfig();
    27. getLogger().info("Default Config Saved.");
    28. } else {
    29. getLogger().info("Config File Exists.");
    30. }
    31.  
    32. // End Configuration
    33.  
    34. }
    35.  
    36. @EventHandler(priority = EventPriority.HIGHEST)
    37. public void onPlayerJoin(PlayerJoinEvent event, Player player) {
    38.  
    39. this.getConfig().set("playerlogs." + player.getName(), null);
    40. String address = (String) this.getConfig().get("playerlogs." + player.getName());
    41. this.saveConfig();
    42.  
    43. if(!(player.getAddress().equals(address))){
    44. player.kickPlayer("Player has already Logged-in from another address!");
    45. }
    46. else {
    47. this.getConfig().set("playerlogs." + player.getName(), player.getAddress());
    48. this.saveConfig();
    49. }
    50.  
    51. }
    52.  
    53. @Override
    54. public void onDisable() {
    55.  
    56. }
    57.  
    58. }
    59.  
     
  2. Offline

    CodenameTitan

    Code:
      File ConfigFile = new File("/config.yml");
            if (!ConfigFile.exists()) {
                this.saveDefaultConfig();
                getLogger().info("Default Config Saved.");
            } else {
                getLogger().info("Config File Exists.");
            }
    All this is not needed! The java "saveDefaultConfig()" will check if it exists and if it dosn't it will create it.
     
  3. Offline

    FlareLine

    CodenameTitan Could that be the reason it is not logging on PlayerJoin?
     
  4. Offline

    CodenameTitan

    FlareLine Maybe. Look at the wiki. There is a full rtutorial on it.
     
  5. Offline

    Plo124

    FlareLine To use the getConfig() method in your onEnable(), do
    Code:java
    1. this.getConfig().options().copyDefaults(true);

    Then you can save the config with this.saveConfig();
    And you can do this.getConfig() in eclipse, and press " . " to see all the possible ways to access the data.
     
  6. Offline

    FlareLine

    Plo124 Wouldn't this save thee defaults from the JAR every time the plugin is enabled?
     
  7. Offline

    Plo124

  8. Offline

    FlareLine

    Plo124 Do I need to make a null address before setting a value to it in the config?
     
Thread Status:
Not open for further replies.

Share This Page