Question Yaml - Delete?

Discussion in 'Plugin Help/Development/Requests' started by ScorixEar, Jun 8, 2015.

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

    ScorixEar

    Hello guys and girls,
    my question is: Can I delete a part of a .yml file?
    For example:
    Code:
    File f =YamlHandler.createFile("Test.yml");
    FileConfiguration c=YamlHandler.createYamlFile(f);
    c.set("Test.Delete",1);
    //how can I delete this Test.Delete from the list?
    Thanks for your help :)
     
  2. Offline

    I Al Istannen

  3. Offline

    ScorixEar

    Haha @I Al Istannen :D
    ok next question:
    I want, that after one minute,the inquiry will be canceld. so I use TimeUnit.Minutes.wait(1);
    but i get this:
    Code:
    try {
                        TimeUnit.MINUTES.wait(1);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    Code:
    [17:56:13] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to PvPsystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.IllegalMonitorStateException
        at java.lang.Object.wait(Native Method) ~[?:1.8.0_45]
        at minecrafthaifl.pvp.command.CommandFriede.onCommandUse(CommandFriede.java:111) ~[?:?]
        at minecrafthaifl.pvp.command.CommandHandler.onCommand(CommandHandler.java:80) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [17:56:36] [Server thread/INFO]: ScorixEar issued server command: /friede ablehnen
    [17:56:36] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to PvPsystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.pvp.command.CommandFriede.onCommandUse(CommandFriede.java:84) ~[?:?]
        at minecrafthaifl.pvp.command.CommandHandler.onCommand(CommandHandler.java:80) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [17:58:37] [Server thread/INFO]: ScorixEar issued server command: /friede stop
    
    so how can i actually wait 1 minute till other things will be done. no pause or Thread.sleep, just do somthing after 1 Minute
    //Edit Ok sorry, first think, than write xD The Scheduler ^^
     
    Last edited: Jun 8, 2015
  4. Offline

    I Al Istannen

    @ScorixEar Create a new "BukkitRunnable" and call runTaskLater(). Is that what you searched? Delay in ticks of course. So 60 seconds would be (60*20)=1200 ticks.
     
  5. Offline

    ScorixEar

    Yeah, that was my edit xD I know this way ;)
    my actual question is, how can I get all Post of one Heading in a yml.
    I mean that:
    Code:
    c.set("Test.boolean.no",false);
    c.set("Test.boolean.yes",true);
    c.get("Test.boolean//???? <- how can i get all
    //in the end, there should be stand: false, true
    @I Al Istannen
     
  6. Offline

    I Al Istannen

  7. Offline

    ScorixEar

    No there are the same choices.
    This is my code:
    Code:
    p.sendMessage("§6[§aVenoria§6] §eFriedensliste:");
                    for(int i = 0;i<Pvpsystem.getInstance().getRawFriedeFile().getList(p.getUniqueId()+".Friede.Friedensabkommen").size();i++)
                    {
                        p.sendMessage("§a"+Pvpsystem.getInstance().getRawFriedeFile().getStringList(p.getUniqueId()+".Friede.Friedensabkommen").get(i));
                    }
                    if(Pvpsystem.getInstance().getRawFriedeFile().getStringList(p.getUniqueId()+".Friede.Friedensabkommen").size()==0)
                    {
                        p.sendMessage("§e Keine Friedensabkommen.");
                    }
    But the .size is always 0 and if I use the ConfigurationSection, there are for Strings also only Lists
     
  8. Offline

    I Al Istannen

    @ScorixEar Ich verstehe nicht ganz was du meinst :)
    What I use to get StringLists:

    Code:
    for(String entry : config.getStringList("Main command help")) {
      sender.sendMessage(entry);
    }
    
     
  9. Offline

    ScorixEar

    Wait, are you german or do you translate it with google :D
    Oh, that sounds logical, I use this if i want to send everybody a personal message
    Code:
    for(Player p:Bukkit.getOnlinePlayers())
    ok, now I use this:
    Code:
    p.sendMessage("§6[§aVenoria§6] §eFriedensliste:");
                    for(String s:Pvpsystem.getInstance().getRawFriedeFile().getConfigurationSection(p.getUniqueId()+".Friede.Friedensabkommen").getStringList(p.getUniqueId()+".Friede.Friedensabkommen"))
                    {
                        p.sendMessage("§a"+s);
                    }
    but it doesn't work. The Plugin thinks, there stands nothing (because there ---> Friede.Friedensabkommen.test1 stands the things, i want to know :(
    also this doesn't work:
    Code:
    for(String s:Pvpsystem.getInstance().getRawFriedeFile().getStringList(p.getUniqueId()+".Friede.Friedensabkommen"))
     
  10. Offline

    I Al Istannen

    @ScorixEar Yes I am german :)
    And, what does your FriedeFile.yml looks like? And, when you have a StringList, you just need the Path and not the ConfigurationSection. Lets look at an example:

    Code:
    key: value
      one: valueOne
      two: valueTwo
      three:
        - values
        - values
        - values
      four: valueFour
    
    If you want "one","two","three" and "four" use "getConfigurationSection("key");". That is because that will return all subkeys to "key". If you just want the "values" in "three" use getStringList("key.three") as that will return the list with the values for three.

    I hope this was understandable :)
     
  11. Offline

    ScorixEar

    Oh, I think, we should nevertheless write in english :D - I'm also german, but unskilled
    my Friede.yml:
    Code:
    UUIDoftheplayer:
       name: test
       Friede:
          Friedensabkommen:
              UUIDofplayer1: nameoftheplayer1
              UUIDofplayer2: nameoftheplayer2
              UUIDofplayer3: nameoftheplayer3
    And i want the nameoftheplayer1,2 and 3
     
  12. Offline

    I Al Istannen

    @ScorixEar Oh, I see. Yes, you would have to use ConfigurationSection. But you cant use getList in this case. So, I would suggest getting the configurationSection for "Friede.Friedensabkommen" and call "getValues(false)" on it. This will give you a map with "String" and "Object". The String is the key. In your case it will be "UUIDOfPlayerx". The value will be a String too. It is "nameofthePlayerx". Iterating over the Map's EntrySet and getting the values
    should be doable.
     
  13. Offline

    ScorixEar

    Ok thats good and now in english :D
    show me this in code, i don't get it
     
  14. Offline

    I Al Istannen

    @ScorixEar I haven't tested it though :)
    Code:
    for(Entry<String, Object> entry : config.getConfigurationSection("Friede.Friedensabkommen").getValues(false).entrySet()) {
      System.out.println("Na schön, hier ist dein Name: " + entry.getValue());
    }
    
     
  15. Offline

    ScorixEar

    Ok, I don't use maps and lists that much, so I don't know, how to do this^^

    And there are
    Code:
    [21:39:23] [Server thread/INFO]: minecrafthaifl issued server command: /friede list
    [21:39:23] [Server thread/ERROR]: Could not pass event PlayerCommandPreprocessEvent to PvPsystem v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1125) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at minecrafthaifl.pvp.command.CommandFriede.onCommandUse(CommandFriede.java:138) ~[?:?]
        at minecrafthaifl.pvp.command.CommandHandler.onCommand(CommandHandler.java:81) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-ea179b3-6e0120a]
        ... 16 more
    [21:40:16] [Server thread/INFO]: Stopping the server
    
    these erros:
    Line 138 is your for-loop

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

    I Al Istannen

    @ScorixEar Whats your code now?

    EDIT: Hey, the path must be "UUIDofPlayer.Friede.Friedensabkommen".
     
    Last edited: Jun 9, 2015
  17. Offline

    ScorixEar

    What? Why? The path to the UUID of the Player is Friede.Friedensabkommen.UUID
    where should i write this?
    my code:
    Code:
    for(Entry<String, Object> s : Pvpsystem.getInstance().getRawFriedeFile().getConfigurationSection("Friede.Friedensabkommen").getValues(false).entrySet())
                    {
                          System.out.println("§a " + s.getValue());
                    }
     
  18. Offline

    I Al Istannen

    @ScorixEar You need the path to the configuration section. In the example file you provided the layout is like this:
    "PlayersUUID"
    "Friede"
    "Friedensabkommen"
    "UUIDOfPlayer: nameOfPlayer"

    Now you want the path to Friedensabkommen. That would be "PlayersUUID.Friede.Friedensabkommen". I said it would be "Friede.Friedensabkommen", because I didn't see that first line.
     
  19. Offline

    ScorixEar

    Oh I see, what you mean. That was a blunder...
    Thanks for your dedication
     
  20. Offline

    I Al Istannen

  21. Offline

    ScorixEar

    Of course, it is you ^^

    Have you even time for another problem? I don't want to create a new Thread

    I want to implement a .yml file (permissionex.yml) from another file folder:
    Code:
    private File f=...
    private FileConfiguration fc=...
    what should stand there?
     
  22. Offline

    I Al Istannen

    @ScorixEar FileConfiguration would be "YAMLConfiguration.loadConfiguration(File f)". For the file it gets a bit trickier. At least I think so.
    You know you can get the dataFolder with "plugin.getDataFolder()". That is a folder in the "plugins" folder every time.
    So calling "file.getParentFile()" on that should return the "plugins" folder.
    From there you just need to know how the dataFolder from the plugin is named. I believe it is "PermissionsEx" for PermissionsEx.
    So get the absolute path from the plugins folder, append the name of the data folder (for example "PermisionsEx". Now you are inside the dataFolder.
    From here on you use the exact same sheme to find the folder you want. You can do it in one or to steps of course.

    In a more shematic way:
    Code:
    "plugins/YourPlugin" ==> getDataFolder
    "plugins" ==> getDataFolder.getParentFile()
    "plugins/PermissionsEx" ==> data folder from PermissionsEx
    "plugins/PermissionsEx/example.yml" ==> file "example.yml" in the PermissionsEx folder.
    
     
  23. Offline

    ScorixEar

    ok,
    I do this:
    Code:
    File f=plugin.getDataFolder().getParentFile().getAbsoluteFile().???
    How can I choose the PermissionsEx folder?
     
  24. Offline

    I Al Istannen

    @ScorixEar File f = new File(plugin.getDataFolder().getParentFile().getAbsolutePath() + File.Seperator + "PermissionsEx");
     
  25. Online

    timtower Administrator Administrator Moderator

  26. Offline

    ScorixEar

    I'm trying to make a command, that shows actually all team-members and synchronize it with the pex.yml file. @timtower
    The problem is, that the files name is "permissionsex.yml" and the folder "PermissionsEx". @I Al Istannen
    Are you shure, that this one gives me the permissionsex.yml from the folder PermissionsEx?
     
  27. Online

    timtower Administrator Administrator Moderator

    @ScorixEar Why not hook into Vault or PEX itself then instead of making a new config parser for a different plugin?
     
    I Al Istannen likes this.
  28. Offline

    I Al Istannen

    @ScorixEar And, if you use it right, yes. I just tried it. My code will just give you the folder, you will have to navigate to the file yourself. But probably Timtower is right :) Iwill go now.
     
  29. Offline

    ScorixEar

    You mean, it is more work to try to get the admins and others from pex.yml than ... ok I get it :D
    than you can close this ^^ @timtower
     
  30. Online

    timtower Administrator Administrator Moderator

    @ScorixEar Won't close this, will be closed on its own after a couple weeks.
    Well, Vault will work for all permissions plugins, not just for PEX ;)
     
Thread Status:
Not open for further replies.

Share This Page