Saving and loading WorldEdit selection to YAML

Discussion in 'Spigot Plugin Development' started by Sensonic, May 6, 2017.

  1. Hello! I have a few variables of the WE Selection class stored in my plugin. But i would like to use them after the plugin has closed/restarted. It would therefor require me to save the Selection vars to a YAML file, and then load them in again in the onEnable.

    I've tried for hours and i can't figure it out.
    Code (Text):
        private Selection sboss;
        private Selection s1;
        private Selection s2;
        private Selection s3;
        private Selection s4;
    I hope you guys will be able to help me. Thanks!
  2. Save the max point and min point? If it's a cuboid

    Sent from my iPhone using Tapatalk
  3. But then I have the same issue, I don't know how.
  4. getConfig#set

    Sent from my iPhone using Tapatalk
  5. This works, and then how do i get it? I can't do getConfig().getString() or something, because it isn't a string.
  6. Perhaps something along the lines of

    Code (Text):
    WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");

    Selection selection = worldEditPlugin.getSelection(getConfig().get("path"));
  7. I actually changed the type, i now need just a Location, not a Selection. How would i do this??
    I need org.bukkit.Location, but getConfig().get("path") returns java.lang.Object
  8. Im not sure how you saved it... if you save a location you only need to save the World name, x y and z values. Possibly pitch and yaw as well.
    Once you do that you can load it with
    Code (Text):
    Location location = new Location(worldName, X, Y, Z);
  9. I saved it like this:
    Code (Text):
                                s2 = getWorldEdit().getSelection(p);
                                Location min = s2.getMinimumPoint();
                                Location max = s2.getMaximumPoint();
                                total2 = min.add(max).multiply(0.5).add(0, 10, 0);
                                getConfig().set("2", total2);
  10. And I presume total2 is a Location ?
  11. Yes correct. I just saved it using getConfig.set("1", total2)
    But i need to know how to load it back in after restart
  12. Well in that case, you can save the world name etc... like I previously mentioned.
    Location#getBlockX etc...

    however, if you want to have it saved like that, then try
    Code (Text):
    Location location = getConfig().get("2");
  13. That returns an Object, not a Location... :/
  14. My apologies, cast it...
    You should learn Java, seriously you would benefit and not have to ask such basic questions.

    Code (Text):
    Location location = (Location) getConfig().get("2");

    Sent from my iPhone using Tapatalk
  15. You're completely right, thanks dude.
  16. Not a problem

    Sent from my iPhone using Tapatalk