WorldGuard API creating a region

Discussion in 'Plugin Help/Development/Requests' started by DamnHippo, Mar 23, 2015.

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

    DamnHippo

    Hello,

    I'm trying to make a region plugin using the WorldGuard API, I'm trying to make it when you type /plot new it make's a 50x50 plot. No matter what i've tried I just can't seem to get it working. Below is my region's command class.

    Code:
          public Map<CommandSender, Integer> viewTaskList = new HashMap<CommandSender, Integer>();
          Logger log = Logger.getLogger("Minecraft");
          public WorldGuardPlugin worldGuard;
          public WorldEditPlugin worldEdit;
    
    
          public static BlockVector convertToSk89qBV(Location location)
          {
              return (new BlockVector(location.getX(), location.getY(), location.getZ()));
          }
          @Override
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                if(cmd.getName().equalsIgnoreCase("plot"))
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    WorldEditPlugin we = this.getWorldEdit();
                    LocalSession session = we.getSession(player);
                    try {
                        com.sk89q.worldedit.regions.Region sel = session.getSelection(session.getSelectionWorld());
                        Vector ex1 = null;
                        Vector ex2 = null;
        
                        //Please also check that code :)
        
                        if (args.length > 0) {
                            if (args[0].equalsIgnoreCase("new")){
                                Location loc1 = player.getLocation();
                                Location loc2 = player.getLocation();
                                loc1.setX(loc1.getX() + 25);
                                loc2.setX(loc2.getX() - 25);
                                  loc1.setY(loc1.getY() + 255);
                                loc2.setY(loc2.getY() - 0);
                                loc1.setZ(loc1.getY() + 25);
                                loc2.setZ(loc2.getY() - 25);
                               //that expand 24 up and 21 down?
                                ex1 = new Vector(0, 24, 0);
                                ex2 = new Vector(0, -21, 0);
                                BlockVector bvMin = convertToSk89qBV(loc1);
                                BlockVector bvMax = convertToSk89qBV(loc2);
                                
                                // define a region
                                ProtectedCuboidRegion reg = new ProtectedCuboidRegion(player.getName(), bvMin, bvMax);
                                ProtectedCuboidRegion region = new ProtectedCuboidRegion(
                                        "plot_" + player.getName(),
                                        new BlockVector(convertToSk89qBV(loc1)),
                                        new BlockVector(convertToSk89qBV(loc1))
                                        );
                                DefaultDomain owners = new DefaultDomain();
                                owners.addPlayer(getWorldGuard().wrapPlayer(player));
                                region.setOwners(owners);
                               
                                getWorldGuard().getRegionManager(player.getWorld()).addRegion(region);
                                // define a region
    
        
                        // and... what next? :P
        
                       return true;
                            }
                        }
                    } catch (IncompleteRegionException e) {
                        player.sendMessage("§cError!");
                        return true;
                   
                    }
                } else {
                    sender.sendMessage(ChatColor.DARK_RED + "Nope...");
                    return true;
                }
                return false;
            }
                   
        
    
    private WorldGuardPlugin getWorldGuard() {
    Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    
    // WorldGuard may not be loaded
    if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
      return null; // Maybe you want throw an exception instead
    }
    
    return (WorldGuardPlugin) plugin;
    }
    
    private WorldEditPlugin getWorldEdit() {
      Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
      
    // WorldGuard may not be loaded
    if (plugin == null || !(plugin instanceof WorldEditPlugin)) {
      return null; // Maybe you want throw an exception instead
    }
    
    return (WorldEditPlugin) plugin;
    }
    }
     
  2. Offline

    mrCookieSlime

    Moved to Plugin Developement.
     
  3. Offline

    DamnHippo

  4. Offline

    mrCookieSlime

    @DamnHippo
    You posted it in Plugin Requests.
    And this does not look like you are looking for someone to make a Plugin for you ^^
     
    DamnHippo likes this.
  5. I had to do this before as well, which was not easy, but look at the sourcecode for WorldEdit and look at the copy command, You have to use the same methods they used to select and copy to a clipboard for making a selection.
     
  6. Offline

    DamnHippo

  7. @DamnHippo it does! :D You see, if your trying to copy a plot, from plotme, you can hook into plotme, get whatever plot you need, get one top corner, and the direct opposite bottom corner, and copy the plot <3 I belive i still have the method around here somewhere for whenever i did it :)
     
  8. Offline

    nlthijs48

    @DamnHippo What is exactly not working with your code? You are creating a CuboidRegion and adding it to WorldGuard, that should be everything that is required. You can check my code in AreaShop to see how I do it, but it looks like you already have working code.

    If you have a stacktrace or a specific problem with regions then you can ask me, I have some experience with the WorldGuard API and can probably help you.
     
  9. Offline

    DamnHippo

    @nlthijs48 thank's for the response, when I type /plot new I wan't it to define a 50x50 region so a 25 block radius from the player's location. Here is the stack trace.

    Code:
    24.03 16:47:37 [Server] INFO We are planning an update. Stay tuned for more information!
    24.03 16:46:59 [Server] INFO ... 15 more
    24.03 16:46:59 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at me.DamnHippo.Galaxy.ZoneCommands.onCommand(ZoneCommands.java:90) ~[?:?]
    24.03 16:46:59 [Server] INFO Caused by: java.lang.NoSuchMethodError: com.sk89q.worldedit.LocalSession.getSelectionWorld()Lcom/sk89q/worldedit/world/World;
    24.03 16:46:59 [Server] INFO at java.lang.Thread.run(Unknown Source) [?:1.7.0_51]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_51]
    24.03 16:46:59 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_51]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1133) [spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.3-R0.1-b373.jar:git-Spigot-ea179b3-6e0120a]
    24.03 16:46:59 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'plot' in plugin GalaxyCore v1.0.0
    24.03 16:46:59 [Server] ERROR null
     
  10. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
  11. Offline

    nlthijs48

    @DamnHippo What is the version of WorldEdit you are using to compile your plugin, and what is the version you use on your test server? Because it looks like those don't match.
     
Thread Status:
Not open for further replies.

Share This Page