Solved [WorldGuard7.0-beta02][MC1.13.2] - WorldGuard.getInstance() not available?!

Discussion in 'Spigot Plugin Development' started by ChrissWalters, Jan 11, 2019.

  1. Hi there,

    in my following post i refer to:

    http://worldguard.enginehub.org/en/latest/developer/dependency/ AND
    http://worldguard.enginehub.org/en/latest/developer/regions/managers/

    I am usining the latest Spigot 1.13.2 version, latest WorldEdit (7.0-beta:4) and the latest WorldGuard (7.0-beta-02) version.

    I am working on a command, to set a selected region from worldedit to a private zone (plot or sth. like that) for a player.

    Right on the beginning, i get stuck on the fact, that

    Code (Text):
     RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
     
    is not working, because ".getInstance()..." seems to be not accessable over the WorldGuard.jar (java ee ide says "the method getInstance() is undefined for the type WorldGuardPlugin.

    I got my main here for you:

    Code (Text):
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;

    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import com.sk89q.worldguard.protection.regions.RegionContainer;

    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {
            System.out.println("Plugin Test activated");
        }

        @Override
        public void onDisable() {

            System.out.println("Plugin Test stopped");

        }

        public 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;
        }

        public WorldEditPlugin getWorldEdit() {
            Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");

            // WorldEdit may not be loaded
            if (plugin == null || !(plugin instanceof WorldEditPlugin)) {
                return null; // Maybe you want throw an exception instead
            }

            return (WorldEditPlugin) plugin;
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

            if (sender instanceof Player) {

                if (label.equalsIgnoreCase("area")) {

                    WorldGuardPlugin WorldGuard = getWorldGuard();
                 
                    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();


    /////////////    [...]



                }

            }

            return false;
        }

    }
     


    I hope, someone here can help me, I die trying to solve that problem, now for more than 24 h... o_O

    With best regards,

    Chris
     
    #1 ChrissWalters, Jan 11, 2019
    Last edited: Feb 6, 2019
  2. That line is your problem. Remove it. You're trying to use a method in the WorldGuard class from a WorldGuardPlugin object named WorldGuard. This is also one reason why variables should be named in camelCase, otherwise they can easily be confused for class names.
     
  3. Yeah, thats a point, but I also did this before:

    Code (Text):
    RegionContainer  container = getWorldGuard().getInstance().getPlatform().getRegionContainer();
    this should be the same, but it also wont work...

    Michey, I had a short look on that code, but a) I am not really shure what its doing o_O and b) i don´t know, if it´s the answer for my problem ... I will try it..
     
  4. change this
    Code (Java):
    getWorldGuard().getInstance()
    to this
    Code (Java):
    WorldGuard.getInstance()
    i told you to simply remove a line, but you did that and edited another.
     
  5. Why you trying to call the method getInstance() on the worldgaurdplugin if it doesn't excists?

    if you look at the docs, you will see that you don't need the getInstance() methode and that your WorldGaurd variable is already the instance of a WorldGaurdPlugin

    Edit:
    Sorry i was looking at the wrong version of the plugin, in the documentation you used they use the methode getInstance(), but if you look at the source code on line 119 the methode you need is called getInst() so try using this methode instead.
     
    #6 x313, Jan 14, 2019
    Last edited: Jan 14, 2019
  6. WorldGuardPlugin and WorldGuard are separate classes. One has the method #getInstance, the other doesn't. OP is trying to use the one that doesn't, which is what is provided by his getWorldGuard() method.
     
  7. I already edited my post. xd
     
  8. I am sorry, if I get you wrong, but in my original posting, I already had

    Code (Java):
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
    this in my code.
     
    #9 ChrissWalters, Jan 14, 2019
    Last edited: Jan 14, 2019
  9. Did you try WorldGuard.getInst() already?
     
  10. Damn it!!! You was so wright :p:cool: I hat a mental wall in my head! I get what you mean!

    I had to delete these " WorldGuardPlugin WorldGuard = getWorldGuard(); " and called WorldGuard from "com.sk89q.worldguard.WorldGuard". Maaan i am an idiot :ROFLMAO:

    Now

    Code (Text):
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
     
    totally works :cool::)

    Thank you all.

    @x313: it is .getInstance() ;)
     

Share This Page