Need help with my stoplag plugin

Discussion in 'Plugin Development' started by ZderKi, Jan 27, 2019.

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

    ZderKi

    I was going to make this custom essential like plugin but i need a little help with this stoplag command... i've been googling it for a while but didnt find anything or i didnt understand it...

    I dont know how to make it wait for 30seconds when i've already used "this" in my main... here's the code:


    Code:
    
    public class StopLag implements CommandExecutor {
      
        private Main plguin;
      
        public StopLag(Main plugin) {
            this.plguin = plugin;
            plugin.getCommand("stoplag").setExecutor(this);
        }
      
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          
            Player player = (Player) sender;
          
            BukkitRunnable task = new BukkitRunnable() {
                @Override
                public void run() {
                  
                    Bukkit.broadcastMessage(ChatColor.DARK_RED + "RELOADING SERVER! ALL ITEMS AND DROPS WILL BE CLEARED IN 30S!");
                  
                }
            };
            // Run the task on this plugin in 3 seconds (60 ticks)
            task.runTaskLater(this, 20 * 3);
          
          
              
      
          
                for(Entity e : player.getWorld().getEntities()){
                    e.remove();
                    }
              
              
              
                for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                  
                        p.kickPlayer(ChatColor.RED + "Server is now in mainteance mode, rejoin after 10 seconds");
                  
                }
              
                Bukkit.getServer().reload();
              
              
          
          
          
          
          
        return false;
        }
    
      
        }
    

    But this is my main where i already am using "this" as i said in the beginning


    Code:
    public class Main extends JavaPlugin {
    
        @Override
        public void onEnable() {
            saveDefaultConfig();
            new FlyCommand(this);
            new HealCommand(this);
            new FeedCommand(this);
            new HealFeedCommand(this);
            new PingTester(this);
            new FbCommand(this);
            new GmCommand(this);
            new ACommand(this);
            new SCommand(this);
            new CCommand(this);
            new PInfoCommand(this);
            new HomeCommand(this);
            new StopLag(this);
            //new SpCommand(this);
        }
    
    
    Also i just wanted to say im just a beginner at java coding so yeah...

    Please help.
     
  2. Offline

    KarimAKL

    @ZderKi For the first piece of code replace 'this' with 'plugin' at the 'task.runTaskLater(this, 20 * 3);' line.
     
  3. Offline

    ZderKi

    "plugin cannot be resolved to a variable"
     
  4. Offline

    KarimAKL

    @ZderKi My bad, didn't see that you typed it wrong. 'plguin' is what you've called the instance of your main class.
     
  5. Offline

    ZderKi

    Wdym i typed it wrong? my Main class is the second thing... anyways how do i fix it tho?
     
  6. Offline

    timtower Administrator Administrator Moderator

    private Main plguin;
    So you can't use plugin as a variable, you need to use plguin or fix the typo.
     
  7. Offline

    ZderKi

    OOOOH I see it now... lol im a fkin idiot xd
     
Thread Status:
Not open for further replies.

Share This Page