Мой табло НЕ РАБОТАЕТ [Minecraft Bukkit Dev] - PullRequest
0 голосов
/ 14 февраля 2020

Итак, моя цель - создать простое табло для каждого игрока, который присоединяется к серверу. Я поставил setScoreboard(); на PlayerJoinEvent, но когда я присоединяюсь к серверу, табло не появляется.

Так вот, что я делаю.

Основной класс:

package can.evilestvirus.board;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;

public class Board extends JavaPlugin implements Listener {

    public HashMap<Player, ScoreboardManager> sb = new HashMap<>();

    public static Board instance;

    public static Board getInstance(){
        return instance;
    }

    @Override
    public void onEnable() {
        instance = this;
        new ScoreboardRunnable().runTaskTimer(this, 0L, 20L);
        getServer().getPluginManager().registerEvents(this, this);
        super.onEnable();
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event){
        Player player = event.getPlayer();
        ScoreboardManager board = new ScoreboardManager(player);
        board.refresh();
        board.setScoreboard();
    }
}

Мой ScoreboardManager:

package can.evilestvirus.board;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

import java.util.Random;

public class ScoreboardManager implements org.bukkit.scoreboard.ScoreboardManager {

    public Scoreboard scoreboard;
    public Objective objective;
    public String name = "scoreboard";

    public Player player;

    public ScoreboardManager(Player player){
        this.player = player;
        this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
        this.name = "sb." + new Random().nextInt(99999);
        this.objective = scoreboard.registerNewObjective(name, "dummy");
        objective.setDisplayName("ScoreBoard");
        objective.setDisplaySlot(DisplaySlot.SIDEBAR);

        if(Board.getInstance().sb.containsKey(player)) return;

        Board.getInstance().sb.put(player, this);
    }

    @Override
    public Scoreboard getMainScoreboard() {

        return scoreboard;
    }

    @Override
    public Scoreboard getNewScoreboard() {
        return null;
    }

    public void refresh() {

    }

    public void sendLine(){
        objective.getScore("§4➤ §6§lJoueur: " + player.getDisplayName()).setScore(0);

    }

    public void setScoreboard(){
        player.setScoreboard(scoreboard);
    }
}

Это мое табло refre sh класс:

package can.evilestvirus.board;

import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.Map.Entry;

public class ScoreboardRunnable extends BukkitRunnable {

    @Override
    public void run() {
        for(Entry<Player, ScoreboardManager> scoreboard: Board.getInstance().sb.entrySet()){
            ScoreboardManager board = scoreboard.getValue();
            board.refresh();
        }
    }
}
...