manered / utils Goto Github PK
View Code? Open in Web Editor NEWLibrary for most of my projects.
License: MIT License
Library for most of my projects.
License: MIT License
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);
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:
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();
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();
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", "")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.