Solved Main.getPlugin() -> no arguments?

Discussion in 'Plugin Development' started by itsss, May 14, 2018.

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

    itsss

    Hello, I'm making a mini-game with use bukkit.

    I developed the code like this, but this code have a error in Main.getPlugin().

    Error: (46, 101) java: method getPlugin in class org.bukkit.plugin.java.JavaPlugin cannot be applied to given types;
    required: java.lang.Class<T>
    found: no arguments (???)
    reason: cannot infer type-variable(s) T
    (actual and formal argument lists differ in length)

    Code:
    if(0 < args.length)
                    {
                        if(args[0].equalsIgnoreCase("start")) {
                            Player player = (Player) sender;
                            World world = player.getWorld();
                            sender.sendMessage(ChatColor.AQUA + "GAME START!!");
                            player.teleport(new Location(world, 213, 4, -1865));
    
                            int left = 60 * 3;
                            new Runnable() {
                                public int taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(), this, 0L, 20L);
                                @Override
                                public void run()
                                {
                                    double x = player.getLocation().getX();
                                    double y = player.getLocation().getY();
                                    double z = player.getLocation().getZ();
    
                                    if (x == 212 && y == 4 && z == -1839) {
                                        Bukkit.broadcastMessage(ChatColor.GREEN + "YOU WIN! score:" + left);
                                        Bukkit.getScheduler().cancelTask(taskID);
                                    }
                                    if (left > 0) {
                                        left--;
                                        switch (left) {
                                            case 60 * 3:
                                                Bukkit.broadcastMessage(ChatColor.AQUA + "There are 3 minutes remaining!");
                                                break;
                                            case 60 * 2:
                                                Bukkit.broadcastMessage(ChatColor.AQUA + "There are 2 minutes remaining!");
                                                break;
                                            case 60:
                                                Bukkit.broadcastMessage(ChatColor.AQUA + "There is 1 minute remaining!");
                                                break;
                                            case 30:
                                                Bukkit.broadcastMessage(ChatColor.YELLOW + "There are 30 seconds remaining!");
                                                break;
                                            case 10:
                                                Bukkit.broadcastMessage(ChatColor.YELLOW + "There are 10 seconds remaining!");
                                                break;
                                            case 3:
                                                Bukkit.broadcastMessage(ChatColor.RED + "There are 3 seconds remaining!");
                                                break;
                                            case 2:
                                                Bukkit.broadcastMessage(ChatColor.RED + "There are 2 seconds remaining!");
                                                break;
                                            case 1:
                                                Bukkit.broadcastMessage(ChatColor.RED + "There are 1 seconds remaning!");
                                                break;
                                        }
    
                                    } else {
                                        Bukkit.getScheduler().cancelTask(taskID);
                                        Bukkit.broadcastMessage(ChatColor.RED + "GAME OVER!!!");
                                    }
                                }
                            };
                        }
                        return true;
                    }
    Does anybody know this error? If you know, Please help me. thanks!!!
     
  2. @itsss
    You have to do Main.getPlugin(Main.class)
     
  3. Offline

    timtower Administrator Administrator Moderator

    @itsss Why not use objects instead? static is often being abused by plugin developers.
     
  4. @itsss
    Yeah go with what timtower said, you can use a constructor to access your main class, thats what i do
     
  5. Offline

    itsss

Thread Status:
Not open for further replies.

Share This Page