WorldGuard API Help?

Discussion in 'Plugin Development' started by lx3krypticx, Sep 12, 2012.

  1. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hey guys so I'm trying to make a plugin where when I type /start it takes all from an array and it sets that one player as owner. Here is what I have.

    Code:
        WorldGuardPlugin worldGuard = this.getWorldGuard();
    This is where an error is showing.

    And here is getting worldguard

    Code:
        public WorldGuardPlugin getWorldGuard() {
            Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
            if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
                return null;
            }
            return (WorldGuardPlugin) plugin;
        }
       
        public void ChooseRegions(){
            for (int i=0; i<24; i++) {
                if (Bukkit.getOnlinePlayers().length > i) {
                    if (joined.toArray()[i] != null) {
                        if(this.worldGuard != null){
                        Player player = (Player)joined.toArray()[i];
                    DefaultDomain owner = new DefaultDomain();
                    player.sendMessage(ChatColor.RED + "You Are Slot: " + i);
                    owner.addPlayer(player.getName());
                    ProtectedRegion region = worldGuard.getRegionManager(Bukkit.getWorld("world")).getRegion("R" + i);
                    region.setOwners(owner);
                }
                }
            }
        }
        }
  2. Offline

    Slipswhitley

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can i please see the entire source code ?
  3. Offline

    Slipswhitley

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Also have you added world guard to your Java build path?
  4. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes I have added worldguard to my build path. I'll PM you my source.
  5. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  6. Offline

    MrMag518

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    What error are you getting and at which line?

    Please show us the stack-trace.
  7. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  8. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  9. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Based on the stack trace i can only assume that world guard loads after your plugin, there-fore causing a null pointer when you try to get world guard in onEnable() (assuming)

    in your plugin.yml add

    Code:
    softdepend: [WorldGuard]
    or

    Code:
    depend: [WorldGuard]
  10. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  11. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can i see this line?
    Code:
    at LavaisWatery.BuildOff.BuildOff.getWorldGuard(BuildOff.java:426)
  12. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
  13. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Anyone know what's wrong with that line?
  14. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Did you add softdepend: [WorldGuard]


    to your plugin.yml?
  15. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yeah I did :O

    Code:
    name: Build_Off
    version: 1.0
    main: LavaisWatery.BuildOff.BuildOff
    description: >
    softdepend: [WorldGuard]
    commands:
      start:
        description:
      create:
        description:
      checkassigned:
        description:
      gm:
        description:
      test:
        description: test command
      ci:
        description:
      settheme:
        description:
      whitelisted:
        description:
      hat:
        description:
      alive:
        description:
      gamemaker:
        description:
      gamemakerremove:
        description:
      theme:
        description: Check The Theme!
      buildoff:
        description: All Commands Accessed By Regular Players
      createblock:
        description:
      fighttime:
        description:
      killallplayers:
        description:
      setspectate:
        description:
      spectate:
        description: Spectate The Game!
  16. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  17. Offline

    Sabersamus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Try depend: [WorldGuard]


    Idk if it will help, but it ups the priority
  18. Offline

    lx3krypticx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I figured it out. :) Thanks

Share This Page