Solved Save Config

Discussion in 'Spigot Plugin Development' started by fangshenghan, Feb 1, 2020.

  1. I'm making a plugin.
    1.I want to read the config of other plugin.Like read groupmanager's config.
    2.how can my plugin get server's world level name?
    Thanks.(Smile)
     
  2. Google is your friend:
    1
    2
    3

    Not here to spoonfeed when there are a multitude of threads online.
    Code (Text):

    List<World> worlds = Bukkit.getWorlds();
    String world = worlds.get(0).getName(); //Overworld
    String nether = worlds.get(1).getName();
    String end = worlds.get(2).getName();
     
    Found online, haven't checked if it works but try it, as you have not shown any effort or attempts you've made so far (not saying you haven't tried, you just haven't shown you've tried).
     
    • Agree Agree x 2
  3. In your class where you need it enter:

    Code (Java):
    File file = new File(getDataFolder().getDataFolder().toString().replace("ENTER YOUR FOLDER ex. AuthMe", "");
    FileConfiguration config = YamlConfiguration.loadConfiguration(file);
     
  4. Yop, Bukkit.getWorlds().get(0) works. Add .getName() to get the name
     
    • Like Like x 1
  5. I have another problem.
    I have the player's name such as Bob, I want to check does Bob have permission 'perm.perm'.
    How can i do it?
     
  6. Bukkit.getPlayer("Bob").hasPermission("perm.perm")
    if the player is online it's gonna return null though
     
    • Agree Agree x 1
  7. md_5

    Administrator Developer

    Bukkit.getPlayer
    Player.hasPermission
     
    • Agree Agree x 1
  8. [13:26:34 WARN]: Exception in thread "Timer-5"
    [13:26:34 WARN]: java.lang.NullPointerException
    [13:26:34 WARN]: at cn.sharkmc.GUI.PlayerRanks$1.run(PlayerRanks.java:42)
    [13:26:34 WARN]: at java.util.TimerThread.mainLoop(Unknown Source)
    [13:26:34 WARN]: at java.util.TimerThread.run(Unknown Source)


    for(String player : Main.cfgm.getPlayers().getConfigurationSection("Players").getKeys(false)) {
    List list = new ArrayList(Main.cfgm.getPlayers().getConfigurationSection("Players." + player + ".ranks").getKeys(false));
    for(int i = list.size() - 1;i >= 0;i--) {
    if(!Main.cfgm.getPlayers().getString("Players." + player + ".ranks." + list.get(i)).equals("expired")) {
    if(!Bukkit.getPlayer("Bob").hasPermission("perm.admin")) {
    Bukkit.getConsoleSender().sendMessage(Utils.Chat("noooooo"));
    }
    //System.out.println(list.get(i));
    }
    }
    }



    I'm making a storage that save player name, and i want to check the player has permission "perm.admin".
     
  9. Show us that line PlayerRanks.java:42
     
  10. if(!Bukkit.getPlayer("Bob").hasPermission("perm.admin")) {
    The player is not online
    I made a timer task to check the permission
     
  11. ...
    So you need to use Bukkit.getOfflinePlayer()
    Why did you make a timer task????
     
  12. md_5

    Administrator Developer

    You can't check permissions of offline players via Bukkit.
    You need something like Vault
     
    • Like Like x 1
  13. Strahan

    Benefactor

    You shouldn't make a compound statement when the secondary operation hangs off something that could be invalid. If "Bob" isn't online, the return from getPlayer will be null and when you try to hasPermission on that, the plugin pukes.
     
  14. Oh thanks
     
  15. I write a playername in the storage(storage.yml),but how can i remove it?
     
    #15 fangshenghan, Feb 2, 2020
    Last edited: Feb 2, 2020
  16. FrostedSnowman

    Resource Staff

    Set the path's value to null
     
    • Agree Agree x 1
  17. How can i make this???
    permissions:
    - bw.cmd
    - bw.setup
    - bw.vip
    - cjm.basic
    - essentials,ban
    - essentials.ban
    - essentials.ban.*
    - essentials.ban.notify
    - essentials.ban.others
     
  18. FrostedSnowman

    Resource Staff

    Create a string list, set the path's value as the list.
     
  19. thanks