Saving worldedit selections

Discussion in 'Plugin Development' started by WolfKingNick, Apr 3, 2017.

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

    WolfKingNick

    I have made a selection and gotten it with world edit just I don't know how to save it to a config can anybody help me find out what to put in the on enable to make the config work or do I just need saveDefaultconfig and how do I save the selection to it thanks
     
  2. Offline

    timtower Administrator Administrator Moderator

    @WolfKingNick What part of the selection do you want to save? You could save it to a schematic.
     
  3. Offline

    WolfKingNick

    i dont know how to save it as a schematic and the whole thing like the area i was told u save it using the min and max i need to save it in a config because im trying to make a simple minigame out of it and plan on expanding off of that
    if u need i can show u what i have so far if that might make it easier to explane?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    WolfKingNick

    Is this what u mean the file part and clipbored is confusing me slightly any advice on this
    Code:
    @EventHandler
    public boolean onCommandsetarea(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
     
        if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "The console cannot set up Welcome.");
                return true;
        }
    
     
     
        Player p = (Player) sender;
    
     
     
        if (cmd.getName().equalsIgnoreCase("welcome")) {
         
                Selection s = getWorldEdit().getSelection(p);
             
                if (s == null) {
                        sender.sendMessage(ChatColor.RED + "Make a selection!");
                        return true;
                }
             
                p.sendMessage(ChatColor.GREEN + "Area Selected");
                World world = s.getWorld();
                Location locA = s.getMaximumPoint();
                Location locB = s.getMinimumPoint();
                CuboidSelection CuboidSelection = new CuboidSelection(world, locA, locB);
                save(CuboidSelection , File);
             
        }
        return true;
     
    }
     
    Last edited: Apr 3, 2017
  6. Offline

    N00BHUN73R

  7. Offline

    WolfKingNick

    how do i use that as code tho ? im saving the area so the plugin only works in the area like u mark the area but if i make the area a schematic how would i check when a player enters the schematic or if they are in it

    I know a lot of people don't like doing this but is anybody willing to do me a favor and make a simple version of this where it just gets the simple selection and saves it from a config so I can understand it better or no?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 4, 2017
  8. Offline

    N00BHUN73R

    I'm going to assume you're making a sort of regionish plugin? In that case to save it you'd need to figure out a way to do that.. like just save the minx miny, etc.. and then to check if someone entered the region, use the PlayerMoveEvent ,do some checking and see if event.getto() == like x or z or y and not equal to event.getfrom.. I'll try and give a better example later if I can

    -- PixeLInc --
     
  9. Offline

    WolfKingNick

    From my understanding is didn't need to get x y and z for each I just needed min and max
     
  10. Offline

    Caderape2

    @WolfKingNick

    Loops all block from the minimum point to the maximum point. Then save in a file the location as a key, and the block type as a values.

    I'm not saying to do a config.set(location, block) but more something like config.set(world/x/y/z, blockType:blockData)

    Edit: so, just save the locmin and the locmax in a file ?
     
  11. Offline

    N00BHUN73R

    Yeah you're correct, I'm pretty sure you just need min max, that's what I meant.. just worded it odd.

    -- PixeLInc --
     
  12. Offline

    WolfKingNick

    Code:
    public void onEnable(){
     
        getServer().getPluginManager().registerEvents(this, this);
        Team.stopteamred();
        Team.stopteamblue();
     
     
        Bukkit.getServer().getPluginManager().registerEvents(new Excapeclass(), this);
        getCommand("Excape").setExecutor(new Excapeclass());
        pl = this;
        getConfig().options().copyDefaults(true);
        saveConfig();
        reloadConfig();
        if (!getConfig().getStringList("Excape").isEmpty()) {
            for (String Excape : getConfig().getStringList("Excape")) {
                if (Excape == null) return;
                World world = Bukkit.getWorld(getConfig().getString(Excape + ".loc.world"));
                Location locA = (Location) getConfig().get(Excape + ".loc.max");
                Location locB = (Location) getConfig().get(Excape + ".loc.min");
                CuboidSelection cS = new CuboidSelection(world, locA, locB);
                cS.contains(locA);
                cS.contains(locB);
            }
        return;
        } else return;
     
     
     
     
     
     
    
     
    }
    Code (Text):
    package me.wolfkingnick;
    
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.Main;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    i
    Code:
    package me.wolfkingnick;
    
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.Main;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    
    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldedit.bukkit.selections.Selection;
    
    public class Excapeclass implements CommandExecutor, Listener {
    
        public WorldEditPlugin getWorldEdit() {
            Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
            if (p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
            else return null;
        }
     
     
        @EventHandler
        public boolean onCommandsetarea(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
         
            if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "The console cannot set up Welcome.");
                    return true;
            }
         
         
         
            Player p = (Player) sender;
         
         
         
            if (cmd.getName().equalsIgnoreCase("Excape")) {
             
                    Selection s = getWorldEdit().getSelection(p);
                 
                    if (s == null) {
                            sender.sendMessage(ChatColor.RED + "Make a selection!");
                            return true;
                    }
                 
                 
                 
                 
                                p.sendMessage("You have set the area for koth " + ChatColor.BLUE + args[1].toUpperCase() + ChatColor.GOLD + "!");
                                List<String> Excape = Main.pl.getConfig().getStringList("Excape");
                                Excape.add(args[1].toUpperCase());
                                Main.pl.getConfig().set("Excape", Excape);
                                Main.pl.getConfig().set(args[1].toUpperCase() + ".loc.world", s.getWorld().getName());
                                Main.pl.getConfig().set(args[1].toUpperCase() + ".loc.max", s.getMaximumPoint());
                                Main.pl.getConfig().set(args[1].toUpperCase() + ".loc.min", s.getMinimumPoint());
                                Main.pl.saveConfig();
                                Main.pl.reloadConfig();
                                return true;
                         
                             
                }
    
            return true;
         
        }
    }
    
    
    The pl doesn't work any ideas?
     
Thread Status:
Not open for further replies.

Share This Page