WorldGuard API define region, just not working!

Discussion in 'Plugin Development' started by Murderscene, Aug 6, 2012.

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

    Murderscene

    Hello! I am trying to make WorldGuard define a region when an emerald block is placed and there is only air directly above it.

    The placing and everything works but for some reason the region is not getting defined by WorldGuard! I see no errors generated but it simply does not work. Does anyone know where I am going wrong?

    Thanks!

    Main File:
    Code:
     
    private WorldGuardPlugin getWorldGuard() {
      Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
     
      // WorldGuard may not be loaded
      if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
      logger.info("Could not load WorldGuard");
          return null; // Maybe you want throw an exception instead
      } else {
      logger.info("Loaded WorldGuard");
      }
     
      return (WorldGuardPlugin) plugin;
    }
     
    
    FULL FILE: http://pastebin.com/UMH9Aqhy


    Listener file:
    Code:
     
    @EventHandler
        public void onBlockPlace(BlockPlaceEvent event) {
            int block = event.getBlock().getTypeId();
            if (block == 133) { // Is Emerald Block
                int bx = event.getBlock().getX();
                int by = event.getBlock().getY();
                int bz = event.getBlock().getZ();
           
                Player player = event.getPlayer();
           
                World world = player.getWorld();
           
                boolean airAbove = true;
                for (int i = by+1; i<128; i=i+1) {
              if (world.getBlockAt(bx, i, bz).getTypeId() != 0) {
              airAbove = false;
              }
                }
           
                if (airAbove) {
          player.sendMessage("You placed the block!");
          logger.info("castlebasher: Block placed");
          event.getBlock().setType(Material.BOOKSHELF);
          player.setGameMode(GameMode.CREATIVE);
     
          addProtectedRegion(player, world, 0, 0, 0, 5, 0);
                }
            }
    }
     
     
    public void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay)
        {
            logger.info("castlebasher: Adding region");
            // get the region manager
            RegionManager rm = worldGuard.getRegionManager(world);
     
            // make a cuboid with two points to create a 3d cube in the world
            BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
            BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
     
            // create the protected region
            ProtectedCuboidRegion pr = new ProtectedCuboidRegion("testregion", b1, b2);
            DefaultDomain dd = new DefaultDomain();
     
            // add the player to the region
            dd.addPlayer(player.getName());
     
            // set the player as the owner
            pr.setOwners(dd);
     
            try
            {
                rm.save();
            }
            catch (Exception exp)
            { }
        }
    
    FULL FILE: http://pastebin.com/5EZY5WN3

    I thought it was because I didn't have rm.addRegion(pr);
    Although once I add that I get a huge amount of errors. Any ideas?

    Code:
    20:09:57 [SEVERE] Could not load 'plugins\castlebasher2.jar' in folder 'plugins'
     
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: com/sk
    89q/worldguard/protection/regions/ProtectedRegion
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:149)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:214)
            at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:190)
            at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigur
    ationManager.java:55)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:158)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:424)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NoClassDefFoundError: com/sk89q/worldguard/protection/regio
    ns/ProtectedRegion
            at guyk.castlebasher2.castlebasher2.<init>(castlebasher2.java:17)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:145)
            ... 8 more
    Caused by: java.lang.ClassNotFoundException: com.sk89q.worldguard.protection.reg
    ions.ProtectedRegion
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:41)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:29)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 14 more
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    Slipswhitley

    You need to have world guard and world edit installed you are getting this error either because worldguard is out of date or you have used a different worldguard version to the one specified in your Java build path
     
Thread Status:
Not open for further replies.

Share This Page