Solved WorldEdit saving and loading selections from config

Discussion in 'Plugin Development' started by Machine Maker, Apr 17, 2016.

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

    Machine Maker

    I am trying to save and load worldedit selections from a config file. I succesfully saved the max point and the min point and the world, but trying to reconstruct the selection in a PlayerMoveEvent class has proven difficult.
    Code:
    package com.x1machinemaker1x.areafly;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    
    import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
    import com.sk89q.worldedit.bukkit.selections.Selection;
    
    @SuppressWarnings("unused")
    public class PlayerMove implements Listener {
     
        private AreaFly plugin;
     
        public PlayerMove(AreaFly pl) {
            plugin = pl;
        }
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
         
            List<String> configAreas = plugin.getConfig().getStringList("areas");
            if (configAreas.isEmpty()) {
                return;
            }
     
            //List<CuboidSelection> areas = new ArrayList<CuboidSelection>();
            CuboidSelection foo = null;
             
            for (String area : configAreas) {
                World world = Bukkit.getServer().getWorld(plugin.getConfig().getString(area + ".World"));
                Location point1 = new Location(world, plugin.getConfig().getDouble(area + ".Location1.X"), plugin.getConfig().getDouble(area + ".Location1.Y"), plugin.getConfig().getDouble(area + ".Location1.Z"));
                Location point2 = new Location(world, plugin.getConfig().getDouble(area + ".Location2.X"), plugin.getConfig().getDouble(area + ".Location2.Y"), plugin.getConfig().getDouble(area + ".Location2.X"));
                CuboidSelection selection = new CuboidSelection(world, point1, point2);
                foo = selection;
                //areas.add(selection);
            }
            //e.getPlayer().sendMessage(String.valueOf(foo));
            if (foo.contains(e.getTo())) {
                e.getPlayer().sendMessage("Hi");
            }
    //        for (CuboidSelection area : areas) {
    //            if (area.contains(e.getTo())) {
    //                e.getPlayer().sendMessage("HAHAHAH");
    //            }
    //        }
        }
    
    }
    
     
    Last edited: Apr 18, 2016
  2. Offline

    mcdorli

    1.: You don't own the x1machinemakerx1.com domain, use me.username instead.
    2.: Any errors?
     
  3. Offline

    Machine Maker

    No, I'm not getting any errors.
     
  4. Offline

    Lordloss

    Please use senseful variable names.

    And please put that stuff inside java code tags, its completely unreadable.
     
  5. Offline

    Machine Maker

    Sorry that variable name was just me testing. Please ignore it.
     
  6. Offline

    Zombie_Striker

    If an entire class is unused, then you should just delete it.

    This is replacing the Z value with the X Value. Is this what you want?

    Please remove all the comments. They are very distracting.
     
  7. Offline

    Machine Maker

    Wow. That was it. Thanks so much!!!
     
Thread Status:
Not open for further replies.

Share This Page