Search in sources :

Example 1 with MainScoreboardManager

use of com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager in project buildinggame by stefvanschie.

the class MainScoreboardWorldChange method onWorldChange.

/**
 * Handles the main scoreboard for players switching worlds
 *
 * @param e an event representing a player who switched between worlds
 * @see PlayerChangedWorldEvent
 * @since 3.1.1
 */
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent e) {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    var player = e.getPlayer();
    MainScoreboardManager manager = MainScoreboardManager.getInstance();
    if (!config.getBoolean("scoreboards.main.enable"))
        return;
    if (config.getStringList("scoreboards.main.worlds.enable").contains(player.getWorld().getName()))
        // show scoreboard and other stuff
        manager.register(player);
    else if (config.getStringList("scoreboards.main.worlds.enable").contains(e.getFrom().getName())) {
        // show scoreboard and other stuff
        manager.remove(player);
        player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
    }
}
Also used : MainScoreboardManager(com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MainScoreboardManager (com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 EventHandler (org.bukkit.event.EventHandler)1