Creating configuration files & 60 second timer to tp

Discussion in 'Plugin Development' started by nehuskerfan2, Jun 10, 2012.

  1. Offline

    nehuskerfan2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I am trying to get a configuration file to be generated if it doesn't exist, I tried:

    Code:java
    1.  
    2. @Override
    3. public void onEnable() {
    4. System.out.println("[COPS]" + pdfFile.getVersion() + " has been enabled.");
    5. configFile=new File("plugins" + File .separator + "Cops" + File .separator + "config.yml");
    6. if(!configFile.exists()){
    7. try {
    8. configFile.createNewFile();
    9. System.out.println("[COPS] Created config.yml in 'Plugins/Cops/'!");
    10. } catch (IOException e) {
    11. e.printStackTrace();
    12. }
    13. }
    14. }
    15.  

    Oh by the way, it throws an error when it enables, saying its out of date. Any fix on that? Do I need to use loggers?

    Now, I'm trying to make it so a player has to teleport to the requested player in 60 seconds. Not sure how to do it. But here is the source code so you know where to put it.
    Code:java
    1.  
    2. // /cops call
    3. if (args[0].equalsIgnoreCase("call") && sender.hasPermission("cops.call")){
    4. System.out.println(sender.getName() + ": /cops call");
    5. sender.sendMessage(ChatColor.BLUE + "911 Police Department, contacting local enforcement.");
    6. for(Player playerCop : this.getServer().getOnlinePlayers()){
    7. if(playerCop.hasPermission("cops.cop")){
    8. playerCop.sendMessage(ChatColor.BOLD + "" + sender.getName() + " called for police!");
    9. playerCop.sendMessage(ChatColor.DARK_GREEN + "Would you like to teleport to " + ChatColor.GOLD + sender.getName() + ChatColor.DARK_GREEN + "?");
    10. playerCop.sendMessage(ChatColor.GOLD + "/cops tpaccept" + ChatColor.DARK_GREEN + " or " + ChatColor.GOLD + "/cops tpdecline");
    11. }
    12. }
    13. }
    14.  
  2. Offline

    nehuskerfan2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I don't want to edit the syntax since it will delete the spaces.
    I have every command surrounded by an if ((sender instanceof player))
  3. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    No that's not what the error says, the error is pointing you to the line where the error is, read: http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/
    Also, you should use getLogger().info() (or just store getLogger() in onEnable() ), that will automatically add the plugin name to the log.
    You also don't need to print enabled messages, bukkit does that, and you adding another one fills the console with repeatitive and pointless info.
    Still, you're complicating yourself with checking for config and stuff... you don't need to do any of that, just use getConfig() and it will create/load the file and get the stuff you need, it does that the first time it's called, if you want to reload the config use reloadConfig() and if you want to save, just use saveConfig().

    About the 2nd issue, use a task, read here: http://wiki.bukkit.org/Scheduler_Programming
  4. Offline

    nehuskerfan2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  5. Offline

    nehuskerfan2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Okay, well, I also need help making another configuration file, where it will generate it like <server directory>\plugins\Cops\<file>.yml
  6. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)

Share This Page