Solved Accessing a file from other plugin problem

Discussion in 'Plugin Development' started by Max8801, Feb 18, 2016.

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

    Max8801

    Hey guys,
    I am writing a chat manager and I need to get a boolean value from a file from a different plugin in order to check if the person who tries to chat is muted or not. I am also accessing another file from the same plugin to check if globalmute is activated or not and this one works fine. It seems like the plugin has problems getting the boolean of the first file. Down below you can see some of my code and some screenshots. I checked the spelling of the directories/file names etc. more than 10 times and they are absolutely correct.
    Please help me.
    Regards, Max

    Code:
    //Loading the file configuration of the first file
    
    File file = new File("plugins/RSystem", "mutes.dat");
            FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    
    //Cheking if the player is muted
    
    String uuid = p.getUniqueId().toString();
      
    if(cfg.getBoolean("Mute." + uuid + ".muted") == true | cfg.getBoolean("Mute." + uuid + ".tempmuted") == true){
    
    }else{
    //send message in chat
    }
    
    //Same thing with the globalmute file, except this one works
    
    File mute = new File("plugins/RSystem", "globalmute.yml");
            FileConfiguration mutecfg = YamlConfiguration.loadConfiguration(mute);
    
    if(mutecfg.getBoolean("Mute") == true) {
              
          
    }else{
    //send message in chat
    }
    
    [​IMG]
    Prints message from the other plugin (which means the player is muted) and the message that the player sent, although he is muted

    [​IMG]
    mutes file in plugins directory + path

    [​IMG]

    inside the mutes file (the UUID is mine)

    push
     
    Last edited: Feb 18, 2016
  2. Offline

    Zombie_Striker

    @Max8801
    If you want plugins accessing other plugins, you should think about making an API. Until then, you should instead use the following :
    Code:
    Plugin p = Bukkit.getPluginManager().getPlugin("NAME");
    if(p != null)
     p.getConfig().....
     
  3. Offline

    nuno1212sss

    @Zombie_Striker He's trying to read a file, not the plugin variables. Do a few debugs and change the
    Code:
    if(mutecfg.getBoolean("Mute") == true) {
              
          
    }else{
    //send message in chat
    }
    to if (!mutecfg.getBoolean("Mute")
     
  4. Offline

    Xerox262

    @nuno1212sss @Zombie_Striker is right though, if you just load the file and the plugin doesn't save it's files everytime it makes a change then you wont get the correct data, you need to get the edited version that is loaded in memory by the plugin through getting the plugin config files.
     
  5. Offline

    Max8801

    That part is working fine. The problem is the part with the UUID Mute System.
     
  6. Offline

    Xerox262

    @Max8801 Ah, That would be because your boolean is "Mute.{UUID HERE}.muted" not just "Mute". However like I said, assuming you want to do this with a plugin that doesn't save after every change (Which most big plugins do, as it would be ridiculous to push that much data every time a single change is made) in the future you will need to get the plugin and get the files through said plugin.
     
  7. Offline

    Max8801

    I have now added the save method after every change just for testing purposes and it still does not work. I really can't imagine why it does work for the GlobalMute file but not for the Mute file...
     
  8. Offline

    Zombie_Striker

    @Max8801
    Please post the current code and current config.
     
  9. Offline

    Xerox262

    @Max8801 Read the very start of my last post. You're checking the wrong boolean.
     
  10. Offline

    Max8801

    @Zombie_Striker

    Code:
    Mute:
      6777a834134b40e08b211c5388e6bb50:
        muted: false
        tempmuted: false
        time:
          start: -1
          end: -1
        reason: ''
    
    Code:
    //The part where it checks if the player is muted/ globalmute is on
    
    File file = new File("plugins/RSystem", "mutes.dat");
            FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
            File mute = new File("plugins/RSystem", "config.yml");
            FileConfiguration mutecfg = YamlConfiguration.loadConfiguration(mute);
      
            String uuid = p.getUniqueId().toString();
          
            if(!cfg.getBoolean("Mute." + uuid + ".muted") & !cfg.getBoolean("Mute." + uuid + ".tempmuted")){
              
          
                if(mutecfg.getBoolean("Mute") == true & !p.hasPermission("System.globalmute")) {
                  
              
                }else{
    }
    
    
    }
    
    
    
     
  11. Offline

    Xerox262

    @Max8801 You need to remove the - in the uuid, last time I checked toString() doesn't remove them, I could've swore that trim() did however I tried recently and it didn't.
     
  12. Offline

    Max8801

    @Xerox262 Thanks a lot. I added the replace() method at the end of the string. I totally forgot that getUniqueId() returns the untrimmed UUID.
     
Thread Status:
Not open for further replies.

Share This Page