Trying to Make a Bossbar executor
DontActLikeMe opened this issue ยท 10 comments
Hi wysohn, so this just comes down to my inexperience of dealing with making executors. I've tried many things to make a bossbar executor and i have not gotten it to work at any avail. This is the code i have so far, the issue im having is retrieving the BarColor and BarStyle Types. This is just my last attempt at it. I'm essentially trying to make a bossbar that acts as a loading bar when your standing in an area. Kinda like a progress bar on capturing the area.
function BOSSBAR(args) { if (args.length == 1) { var BarColor = ('org.bukkit.boss.BarColor'); var BarStyle = ('org.bukkit.boss.BarStyle'); var title = args[0]; var bar = Bukkit.createBossBar(title,BarColor.valueOf(BLUE),BarStyle.valueOf(SOLID)); bar.setVisible(true); } }
function BOSSBAR(args) {
if (args.length == 1) {
var BarColor = ('org.bukkit.boss.BarColor');
var BarStyle = ('org.bukkit.boss.BarStyle');
var title = args[0];
var bar = Bukkit.createBossBar(title, BarColor.valueOf(BLUE), BarStyle.valueOf(SOLID));
bar.setVisible(true);
}
}
I think you got the most of the important points, yet if you look at the documentation, you have a method called setProgress() in the BossBar interface
So basically, all you need to do is use that method to change the progress.
But this can be a little bit difficult as you have to keep the reference of the BossBar, but it will just get destroyed when the Trigger execution ends.
One possible solution is using the Scheduler.
It can be a little bit tricky; you can look at how @soliddanii implemented the scheduler in the Executor here
He used the runTask method in the plugin, but in your case, you may want to use the scheduler directly.
BukkitScheduler
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
run: function() {
//TODO bar.setProgress(); perhaps
}
}, 20);
The runTaskLater method has capability of running some task after specific amount of ticks passed, and all you need to do is just change that tick (20 part) to variable.
That way you can change the progress per defined ticks.
You will need some plan to make that happen!
Tell me if you are stuck :)
I think you have to use java.lang.Runnable instead of BukkitRunnable.
I can't see why it shouldn't work as it is, but just give a try if Runnable works
So i decided to try and run a TaskTimer to iterate through the bar and load it up.Before i get to the complicated part of detecting players etc lol i just want to get a loading bar to work. So i tried just using numbers like you did above but its calling my numbers int,instead of long so i tried casting it to long. This is the error that i get:
06.11 18:03:13 [Server] WARN Caused by: java.lang.NoSuchMethodException: None of the fixed arity signatures [(org.bukkit.plugin.Plugin, org.bukkit.scheduler.BukkitRunnable, long, long), (org.bukkit.plugin.Plugin, java.lang.Runnable, long, long)] of method org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.runTaskTimer match the argument types [io.github.wysohn.triggerreactor.bukkit.main.JavaPluginBridge, org.bukkit.scheduler.BukkitRunnable$$NashornJavaAdapter, java.lang.Long, java.lang.Long]
Here is the code i have so far:
function BOSSBAR(args) {
if (args.length == 2) {
var title = args[0];
var BarColor;
var BarStyle;
var BarColor = Java.type('org.bukkit.boss.BarColor');
var color = BarColor.valueOf(args[1]);
var BarStyle = Java.type('org.bukkit.boss.BarStyle')
var style = BarStyle.valueOf("SOLID");
var bar = Bukkit.createBossBar(title, color, style);
bar.setProgress(0.0);
bar.addPlayer(player.getPlayer());
bar.setVisible(true);
var i = 0.2;
var x = 10;
var y = 40;
var Runnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
thisid = Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
run: function() {
bar.setProgress(i.doubleValue());
i = i + 0.2;
if (i == 1.0) {
Bukkit.getScheduler().cancelTask(thisid)
}
}
}, x.longValue(), y.longValue());
}
}
Ok, the problem wasn't on your side but on my side
Sorry about that
So basically, the 'plugin' wan't really the Plugin instance.
It was the bridge that connects abstract instance with the actual plugin instance.
I will update it so the bridge can be treated as Plugin
Your code works like a charm, except this error:
[17:14:25] [Server thread/WARN]: [TriggerReactor] Task #66 for TriggerReactor v1.3.3 generated an exception
java.lang.IllegalArgumentException: Progress must be between 0.0 and 1.0 (1.2)
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:191) ~[spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at org.bukkit.craftbukkit.v1_12_R1.boss.CraftBossBar.setProgress(CraftBossBar.java:123) ~[spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at jdk.nashorn.internal.scripts.Script$Recompilation$116$764$^eval_.BOSSBAR$run(:20) ~[?:?]
at org.bukkit.scheduler.BukkitRunnable$$NashornJavaAdapter.run(Unknown Source) ~[?:?]
at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:353) [spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-93e20b3-31d3159]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_77]
That's gonna be your work though xD
I did that and still recieve the same error.I will try other things while awaiting your response.
Hi,
It's been a while; how are you doing?
I'm wondering if you want to contribute to the project by submitting this BOSSBAR executor. I'm planning to make one, and i realized you worked on it earlier
I will put you in the contributor to credit your work
Also, make a pull request instead of giving me the code
So that way you can be part of contributors in github