GithubHelp home page GithubHelp logo

utils's People

Contributors

dominilk01 avatar manered avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

utils's Issues

Automatic pagination for menus

Will be automatically handled, and calculated.

There should be the following methods for it:

/* Setting the menu pagination buttons */
MenuBuilder menu = new MenuBuilder("Yet Another Manered Utility", 54)
    .setPaginationButtons(
        48, new ItemBuilder(Material.SPECTRAL_ARROW).setName("Previous Page"),
        50, new ItemBuilder(Material.SPECTRAL_ARROW).setName("Next Page")
    );

/* Opening the menu, starts at page 1 and ends at a auto-calculated last page. */
/* If the page is not defined, the method will open the 1st page */
menu.open(player, 1);
menu.nextPage(player);

menu.previousPage(player);

Command Builder

So what we have now for the CommandBuilder class is quite literally nothing important, it is basically the exact same as the CommandExecutor class.

So, I was thinking of something like this:

  1. Without Arguments:
CommandBuilder cmd = new CommandBuilder("test")
    .setPermission("test.command")
    .setUsage("Correct Usage: /<command>")
    .setDescription("This command is a test. This is also shown in /help testcommand")
    .setShortDescription("This is a short description shown in /help testcommand")
    .setAliases("testcommand")
    .addAlias("testing")
    .setExecutor((CommandSender sender, CommandArguments args) -> {
        sender.sendMessage("Just some random implementation.");
        return;
    })
    .register();
  1. With Arguments:
CommandBuilder cmd = new CommandBuilder("broadcast")
    .setArguments(new JoinedStringArgument(0)) // Special characters can be used and can have spaces.
    .setPermission("broadcast.command")
    .setUsage("Correct Usage: /<command> <message>")
    .setDescription("Broadcasts the message set in the arguments of the command.")
    .setShortDescription("Broadcasts a message.")
    .setAliases("bc")
    .addAlias("broadcastmsg")
    .setExecutor((CommandSender sender, CommandArguments args) -> {
        if (args.get(0) == null) {
            sender.sendMessage("Correct Usage: /broadcast <message>")
            return true;
        }

        Bukkit.broadcastMessage("BROADCAST: " + args.get(0));
        return true;
    })
    .register();

Scoreboard System

example usage:

public final class ExamplePlugin extends JavaPlugin implements Listener {

    private final Map<Player, CustomScoreboard> scoreboards = new HashMap<>();

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);

        /* Refreshes all scoreboards every 1 second */
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
            for (CustomScoreboard scoreboard : this.scoreboards.values()) {
                refreshScoreboard(scoreboard);
            }
        }, 0, 20L);
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();

        CustomScoreboard scoreboard = new CustomScoreboard(player);

        scoreboard.setTitle(ColorUtils.color("<#ff0000>Scoreboard API"));

        this.scoreboards.put(player, scoreboard);
    }

    @EventHandler
    public void onLeave(PlayerQuitEvent event) {
        Player player = event.getPlayer();

        CustomScoreboard scoreboard = this.scoreboards.remove(player);

        if (scoreboard != null) {
            scoreboard.delete();
        }
    }

    public void refreshScoreboard(CustomScoreboard scoreboard) {
        Player player = scoreboard.getPlayer();
        Spark spark = SparkProvider.get();

        // Get the TPS statistic (will be null on platforms that don't have ticks!)
        DoubleStatistic<StatisticWindow.TicksPerSecond> tps = spark.tps();

        double lastTps = tps.poll(StatisticWindow.TicksPerSecond.SECONDS_5);

        scoreboard.setLines(
                ScoreboardUtils.emptyLine(),
                "Ping: " + player.getPing() + "ms",
                "TPS: " + lastTps,
                ScoreboardUtils.emptyLine()
        );
    }
}

or:

CustomScoreboard scoreboard = new CustomScoreboard(player)
  .setTitle("Hello!")
  .setLines("test", "")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.