1.15.2 Plugin in separate file?

Discussion in 'Spigot Plugin Development' started by Riku32, Mar 19, 2020.

Thread Status:
Not open for further replies.
  1. So I have this code in the Events class which will make all players that join in the future and all current players invisible to the online player

    Code (Java):
    public class Events implements Listener {
        @EventHandler
        public void onjoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();

            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
                @Override
                public void run() {
                    for(Player online : Bukkit.getOnlinePlayers()){
                        player.hidePlayer(online);
                    }
                }
            }, 10);
        }
    }
     
    However, the "Plugin" in scheduleSyncDelayedTask apparently can only be used properly in the Main class, which looks like this

    Code (Java):
    public final class Main extends JavaPlugin {


        @Override
        public void onEnable() {
            this.getServer().getPluginManager().registerEvents(new Events(), this);
        }

        @Override
        public void onDisable() {
            // Nothing for now
        }

    }
     
    So how would I pass "Plugin" from the main class to the Events class and make this work properly
     
  2. drives_a_ford

    Moderator

  3. Solved it with

    public static Plugin instance;
    instance = this;
     
Thread Status:
Not open for further replies.