Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

</repositories>
<dependencies>
<!--Spigot API and NMS-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import nl.martenm.servertutorialplus.helpers.dataholders.OldValuesPlayer;
import nl.martenm.servertutorialplus.points.IPlayPoint;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

Expand Down Expand Up @@ -105,6 +107,11 @@ private void restorePlayer(boolean originalLocation){
if (originalLocation) {
player.teleport(oldValuesPlayer.getLoc());
}

BossBar bossBar = Bukkit.getBossBar(new NamespacedKey(plugin, "bossbar"));
if (bossBar != null) {
bossBar.removeAll();
}
// });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import net.md_5.bungee.api.chat.TextComponent;
import nl.martenm.servertutorialplus.points.editor.PointArg;
import nl.martenm.servertutorialplus.points.editor.args.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -42,6 +43,12 @@ public abstract class ServerTutorialPoint{
protected List<String> commands;
protected List<FireWorkInfo> fireworks;
protected String message_actionBar;
protected String bossBarTitle;
protected double bossBarProgress;
protected BarColor bossBarColor;
protected BarStyle bossBarStyle;
protected double bossBarShowAfter;
protected double bossBarHideAfter;
protected PlayerTitle titleInfo;
protected PlayerSound soundInfo;
protected List<PotionEffect> pointionEffects;
Expand Down Expand Up @@ -157,6 +164,42 @@ protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer, boole
}
//endregion

if (bossBarTitle != null && bossBarHideAfter > bossBarShowAfter) {

BossBar oldBar = Bukkit.getBossBar(new NamespacedKey(plugin, "bossbar"));
if (oldBar != null) {
oldBar.removeAll();
}

new BukkitRunnable() {
final BossBar bossBar = Bukkit.getServer().createBossBar(new NamespacedKey(plugin, "bossbar"),
ChatColor.translateAlternateColorCodes('&', bossBarTitle), bossBarColor, bossBarStyle);
final int showAfterTicks = (int) (bossBarShowAfter * 20);
final int hideAfterTicks = (int) (bossBarHideAfter * 20);
int ticksPassed = 0;
{
if (bossBarProgress > 1.0) {
bossBarProgress = 1.0;
}
if (bossBarProgress < 0.0) {
bossBarProgress = 0.0;
}
bossBar.setProgress(bossBarProgress);
}
@Override
public void run() {
if (ticksPassed >= showAfterTicks && !bossBar.getPlayers().contains(player)) {
bossBar.addPlayer(player);
}
if (ticksPassed >= hideAfterTicks || ticksPassed > time * 20) {
bossBar.removePlayer(player);
this.cancel();
}
ticksPassed += 2;
}
}.runTaskTimer(plugin, 0, 2);
}

//region commands
for (String command : commands) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), PluginUtils.replaceVariables(plugin.placeholderAPI, player, command));
Expand Down Expand Up @@ -198,9 +241,28 @@ public void readSaveData(Config tutorialSaves, String ID, String i) {
commands = tutorialSaves.getStringList("tutorials." + ID + ".points." + i + ".commands");

message_actionBar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar");
bossBarTitle = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".bossbar.title");
bossBarProgress = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".bossbar.progress", 1.0);
bossBarShowAfter = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".bossbar.show-after", 0.0);
bossBarHideAfter = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".bossbar.hide-after", time);
lockPlayer = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locplayer");
lockView = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locview");
flying = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".setFly");

try {
String bossBarStyleString = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".bossbar.style", "SOLID");
bossBarStyle = BarStyle.valueOf(bossBarStyleString.toUpperCase());
} catch (IllegalArgumentException e) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason for the 'try-catch' blocks here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, the exception IllegalArgumentException is caught when the valueOf method is called on the BarStyle enum with a string that doesn't match any of the enum constants.

bossBarStyle = BarStyle.SOLID;
}

try {
String bossBarColorString = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".bossbar.color", "WHITE");
bossBarColor = BarColor.valueOf(bossBarColorString.toUpperCase());
} catch (IllegalArgumentException e) {
bossBarColor = BarColor.WHITE;
}

/*
Fire work meta!
*/
Expand Down Expand Up @@ -267,6 +329,15 @@ public void saveData(Config tutorialSaves, String key, String i){
tutorialSaves.set("tutorials." + key + ".points." + i + ".commands", commands);
if(flying) tutorialSaves.set("tutorials." + key + ".points." + i + ".setFly", flying);

if (bossBarTitle != null) {
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.title", bossBarTitle);
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.color", bossBarColor.name());
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.style", bossBarStyle.name());
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.progress", bossBarProgress);
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.show-after", bossBarShowAfter);
tutorialSaves.set("tutorials." + key + ".points." + i + ".bossbar.hide-after", bossBarHideAfter);
}

if(titleInfo != null){
tutorialSaves.set("tutorials." + key + ".points." + i + ".title.title", titleInfo.title);
tutorialSaves.set("tutorials." + key + ".points." + i + ".title.subtitle", titleInfo.subtitle);
Expand Down