MinusKube / Netherboard

Scoreboard API for your Minecraft Sponge and Bukkit Plugins, supporting all versions from 1.7 to 1.19.
Apache License 2.0
77 stars 21 forks source link

Animated Scoreboard #10

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi, how could I make an animated scoreboard using your API?

MinusKube commented 4 years ago

Hello, you must run a scheduler every X ticks and simply call the set method inside it with the line number and the String.

There is currently no utility class for doing some String animations easily, but it's planned for later.

ghost commented 4 years ago

I think I rushed too much, I don't even get a static scoreboard, I followed the steps of github and I can't make a scoreboard with this api, I'm currently at 1.12.2

ghost commented 4 years ago

This is my code

@EventHandler

public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer();

BPlayerBoard board = Netherboard.instance().createBoard(player, "My Scoreboard");
board.set("Hola", 1);
board.get(1);

}

MinusKube commented 4 years ago

Your code seems correct, check if your listener is correctly registered, if your plugin is correctly exported, if you don't have any error in the console, and things like that

ghost commented 4 years ago

My plugin is exported correctly, I don't receive errors, and my listener is registered

ghost commented 4 years ago

it just doesn't show anything upon entering

ghost commented 4 years ago

Ok, I solved it, I just had to put depend: Netherboard and put the pl to my server, how could I use the api correctly and not have to put Netherboard.jar in my plugins folder?

MinusKube commented 4 years ago

You can copy the core and bukkit modules to your code, or include them inside your jar using Maven/Gradle

ghost commented 4 years ago

Regarding the animated scoreboard, would this code be good?

`package miniprueba;

import fr.minuskube.netherboard.Netherboard; import fr.minuskube.netherboard.bukkit.BPlayerBoard; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler;

public class ScoreBoard implements Listener{

private final MiniPrueba plugin;
public ScoreBoard(MiniPrueba plugin){
    this.plugin = plugin;
}

@EventHandler
public void Sb(Player p) {

BPlayerBoard board = Netherboard.instance().getBoard(p);
board.set("Hola", 1);
board.get(1);
board.setName("Skere");
    }
public void R(){
    BukkitScheduler sc = Bukkit.getScheduler();
    sc.scheduleSyncRepeatingTask(plugin, new Runnable(){

        @Override
        public void run() {
          for(Player p : Bukkit.getOnlinePlayers()){
              Sb(p);
          }
        }
    }, 0L, 05L
    );
}
}

`

MinusKube commented 4 years ago

If you create the Scoreboard on PlayerJoinEvent and make sure to call the method R(), this should work

ghost commented 4 years ago

Yes, it worked, now how would it make the score lively? Sorry if I ask a lot of questions I am learning little by little ... Code: ` package miniprueba;

import fr.minuskube.netherboard.Netherboard; import fr.minuskube.netherboard.bukkit.BPlayerBoard; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler;

public class ScoreBoard implements Listener{

private final MiniPrueba plugin;
public ScoreBoard(MiniPrueba plugin){
    this.plugin = plugin;
}

public void Sb(Player p) {

BPlayerBoard board = Netherboard.instance().createBoard(p, "Skere");
board.set("Hola", 1);
board.get(1);
board.setName("Skere");
    }
@EventHandler
public void R(PlayerJoinEvent e){
    BukkitScheduler sc = Bukkit.getScheduler();
    sc.scheduleSyncRepeatingTask(plugin, new Runnable(){

        @Override
        public void run() {
            Bukkit.getOnlinePlayers().stream().forEach((p) -> {
                Sb(p);
            });
        }
    }, 0L, 05L
    );
}
}`
ghost commented 4 years ago

.

MinusKube commented 4 years ago

Firstly you must only create the scoreboard once, not each time the scheduler is called, and then in your Sb method you just do whatever you want in it and you'll be able to make animations, edit the texts, etc...

ghost commented 4 years ago

So I would have to remove the method where I have created the scoreboard of the run () method?

ghost commented 4 years ago

.

MinusKube commented 4 years ago

You must create the scoreboard (createBoard) only once at the beginning of the PlayerJoinEvent, then, inside your scheduler, you get the board (getBoard) and you set the lines (set)

ghost commented 4 years ago

`package miniprueba;

import fr.minuskube.netherboard.Netherboard; import fr.minuskube.netherboard.bukkit.BPlayerBoard; import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitScheduler;

public class ScoreBoard implements Listener{

private final MiniPrueba plugin;
public ScoreBoard(MiniPrueba plugin){
    this.plugin = plugin;
}
@EventHandler
 public void Sb(PlayerJoinEvent e) {
 Player p = e.getPlayer();
BPlayerBoard board = Netherboard.instance().createBoard(p, "Skere");
        board.get(1);
        board.set("Hola", 1);
        board.get(1);
        board.setName("Skere");

    BukkitScheduler sc = Bukkit.getScheduler();
    sc.scheduleSyncRepeatingTask(plugin, new Runnable(){
    @Override
    public void run(){
        BPlayerBoard boardget = Netherboard.instance().getBoard(p);
    boardget.set("Holanda", 1);
        boardget.get(1);
            }
        }, 0, 5L);

    }

}`

Ok. It is assumed that now I would have to change the text of the score, but how do I get it back to the text of the previous score?

ghost commented 4 years ago

.