From 2cc349b51b19f87a8938a053d779b84c5febb99a Mon Sep 17 00:00:00 2001 From: Nicolai Date: Sun, 21 Apr 2024 11:41:57 +0200 Subject: [PATCH 1/4] Added MineDown support, show and hide after options to actionbar --- pom.xml | 11 +++++++ .../points/ServerTutorialPoint.java | 31 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index d84021b..bf1acc8 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,11 @@ jitpack.io https://jitpack.io + + + minebench-repo + https://repo.minebench.de/ + @@ -77,6 +82,12 @@ compile + + de.themoep + minedown + 1.7.1-SNAPSHOT + compile + diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 2ff449e..2229f63 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -1,6 +1,7 @@ package nl.martenm.servertutorialplus.points; import com.cryptomorin.xseries.messages.Titles; +import de.themoep.minedown.MineDown; import nl.martenm.servertutorialplus.ServerTutorialPlus; import nl.martenm.servertutorialplus.helpers.Config; import nl.martenm.servertutorialplus.helpers.PluginUtils; @@ -42,6 +43,8 @@ public abstract class ServerTutorialPoint{ protected List commands; protected List fireworks; protected String message_actionBar; + protected double actionbar_show_after; + protected double actionbar_hide_after; protected PlayerTitle titleInfo; protected PlayerSound soundInfo; protected List pointionEffects; @@ -151,9 +154,23 @@ protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer, boole //endregion //region actionbar - if (message_actionBar != null) { - //NeedsReflection.sendActionBar(player, PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar)); - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar))); + if (message_actionBar != null && actionbar_hide_after > actionbar_show_after) { + new BukkitRunnable() { + final double showAfterTicks = actionbar_show_after * 20; + final double hideAfterTicks = actionbar_hide_after * 20; + int ticksPassed = 0; + @Override + public void run() { + if (ticksPassed >= showAfterTicks && ticksPassed < hideAfterTicks) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, + new MineDown(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar)).toComponent()); + } else if (ticksPassed > hideAfterTicks || ticksPassed > time * 20) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("")); + this.cancel(); + } + ticksPassed += 2; + } + }.runTaskTimer(plugin, 0, 2); } //endregion @@ -197,7 +214,9 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { message_chat = tutorialSaves.getStringList("tutorials." + ID + ".points." + i + ".messages"); commands = tutorialSaves.getStringList("tutorials." + ID + ".points." + i + ".commands"); - message_actionBar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar"); + message_actionBar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar.message"); + actionbar_show_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.show-after", 0); + actionbar_hide_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.hide-after", -1); lockPlayer = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locplayer"); lockView = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".locview"); flying = tutorialSaves.getBoolean("tutorials." + ID + ".points." + i + ".setFly"); @@ -263,7 +282,9 @@ public void saveData(Config tutorialSaves, String key, String i){ tutorialSaves.set("tutorials." + key + ".points." + i + ".locplayer", lockPlayer); tutorialSaves.set("tutorials." + key + ".points." + i + ".locview", lockView); tutorialSaves.set("tutorials." + key + ".points." + i + ".messages", message_chat); - tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar", message_actionBar); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.message", message_actionBar); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.show-after", actionbar_show_after); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.hide-after", actionbar_hide_after); tutorialSaves.set("tutorials." + key + ".points." + i + ".commands", commands); if(flying) tutorialSaves.set("tutorials." + key + ".points." + i + ".setFly", flying); From 085cd3be444c3aa012275d46695f500ea0a23cf2 Mon Sep 17 00:00:00 2001 From: Nicolai Date: Sun, 21 Apr 2024 21:17:54 +0200 Subject: [PATCH 2/4] Fixed default hide-after --- .../martenm/servertutorialplus/points/ServerTutorialPoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 2229f63..04b5fac 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -216,7 +216,7 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { message_actionBar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar.message"); actionbar_show_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.show-after", 0); - actionbar_hide_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.hide-after", -1); + actionbar_hide_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.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"); From 474979cf00bab26f2f25ec5f80ee094d342988b0 Mon Sep 17 00:00:00 2001 From: Nicolai Date: Sun, 21 Apr 2024 21:22:28 +0200 Subject: [PATCH 3/4] Removed MineDown support (didn't work) --- pom.xml | 12 ------------ .../points/ServerTutorialPoint.java | 3 +-- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index bf1acc8..a8ec772 100644 --- a/pom.xml +++ b/pom.xml @@ -25,11 +25,6 @@ jitpack.io https://jitpack.io - - - minebench-repo - https://repo.minebench.de/ - @@ -81,13 +76,6 @@ 3.0.0 compile - - - de.themoep - minedown - 1.7.1-SNAPSHOT - compile - diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 04b5fac..626ca20 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -1,7 +1,6 @@ package nl.martenm.servertutorialplus.points; import com.cryptomorin.xseries.messages.Titles; -import de.themoep.minedown.MineDown; import nl.martenm.servertutorialplus.ServerTutorialPlus; import nl.martenm.servertutorialplus.helpers.Config; import nl.martenm.servertutorialplus.helpers.PluginUtils; @@ -163,7 +162,7 @@ protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer, boole public void run() { if (ticksPassed >= showAfterTicks && ticksPassed < hideAfterTicks) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, - new MineDown(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar)).toComponent()); + new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar))); } else if (ticksPassed > hideAfterTicks || ticksPassed > time * 20) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("")); this.cancel(); From e5bd82a8f32ffcb5b93d75de818dee5837a12f25 Mon Sep 17 00:00:00 2001 From: Nicolai Date: Mon, 22 Apr 2024 22:37:03 +0200 Subject: [PATCH 4/4] Added command to adjust actionbar attributes --- .../commands/sub/tutorials/InfoCommand.java | 2 +- .../points/ServerTutorialPoint.java | 47 ++++++++++++------- .../points/custom/CheckPoint.java | 4 +- .../points/editor/args/ActionbarArg.java | 31 +++++++++--- 4 files changed, 57 insertions(+), 27 deletions(-) diff --git a/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/InfoCommand.java b/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/InfoCommand.java index d79ca0c..f15d339 100644 --- a/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/InfoCommand.java +++ b/src/main/java/nl/martenm/servertutorialplus/commands/sub/tutorials/InfoCommand.java @@ -81,7 +81,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String //Time sender.sendMessage(" " + ChatColor.GREEN + Lang.TIME + ": " + ChatColor.YELLOW + point.getTime() + " " + Lang.SECONDS); //Actionbar - if(point.getMessage_actionBar() != null && !point.getMessage_actionBar().equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Actionbar: " + ChatColor.YELLOW + point.getMessage_actionBar()); + if(point.getMessageActionbar() != null && !point.getMessageActionbar().equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Actionbar: " + ChatColor.YELLOW + point.getMessageActionbar()); //Title if(point.getTitleInfo() != null){ if(!point.getTitleInfo().title.equalsIgnoreCase("")) sender.sendMessage(" " + ChatColor.GREEN + "Title: " + ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', point.getTitleInfo().title)); diff --git a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java index 626ca20..7f87c33 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -37,13 +37,15 @@ public abstract class ServerTutorialPoint{ protected ServerTutorialPlus plugin; protected PointType type; + protected BukkitTask actionbarRunnable = null; + protected Location loc; protected List message_chat; protected List commands; protected List fireworks; - protected String message_actionBar; - protected double actionbar_show_after; - protected double actionbar_hide_after; + protected String messageActionbar; + protected double actionbarShowAfter; + protected double actionbarHideAfter; protected PlayerTitle titleInfo; protected PlayerSound soundInfo; protected List pointionEffects; @@ -91,6 +93,7 @@ public void run() { @Override public void stop() { if(timerTask != null) timerTask.cancel(); + if (actionbarRunnable != null) actionbarRunnable.cancel(); } }; } @@ -153,16 +156,16 @@ protected void playDefault(Player player, OldValuesPlayer oldValuesPlayer, boole //endregion //region actionbar - if (message_actionBar != null && actionbar_hide_after > actionbar_show_after) { - new BukkitRunnable() { - final double showAfterTicks = actionbar_show_after * 20; - final double hideAfterTicks = actionbar_hide_after * 20; + if (messageActionbar != null && actionbarHideAfter > actionbarShowAfter) { + actionbarRunnable = new BukkitRunnable() { + final double showAfterTicks = actionbarShowAfter * 20; + final double hideAfterTicks = actionbarHideAfter * 20; int ticksPassed = 0; @Override public void run() { if (ticksPassed >= showAfterTicks && ticksPassed < hideAfterTicks) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, - new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar))); + new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, messageActionbar))); } else if (ticksPassed > hideAfterTicks || ticksPassed > time * 20) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("")); this.cancel(); @@ -213,9 +216,9 @@ public void readSaveData(Config tutorialSaves, String ID, String i) { message_chat = tutorialSaves.getStringList("tutorials." + ID + ".points." + i + ".messages"); commands = tutorialSaves.getStringList("tutorials." + ID + ".points." + i + ".commands"); - message_actionBar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar.message"); - actionbar_show_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.show-after", 0); - actionbar_hide_after = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.hide-after", time); + messageActionbar = tutorialSaves.getString("tutorials." + ID + ".points." + i + ".actionbar.message"); + actionbarShowAfter = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.show-after", 0); + actionbarHideAfter = tutorialSaves.getDouble("tutorials." + ID + ".points." + i + ".actionbar.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"); @@ -281,9 +284,9 @@ public void saveData(Config tutorialSaves, String key, String i){ tutorialSaves.set("tutorials." + key + ".points." + i + ".locplayer", lockPlayer); tutorialSaves.set("tutorials." + key + ".points." + i + ".locview", lockView); tutorialSaves.set("tutorials." + key + ".points." + i + ".messages", message_chat); - tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.message", message_actionBar); - tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.show-after", actionbar_show_after); - tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.hide-after", actionbar_hide_after); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.message", messageActionbar); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.show-after", actionbarShowAfter); + tutorialSaves.set("tutorials." + key + ".points." + i + ".actionbar.hide-after", actionbarHideAfter); tutorialSaves.set("tutorials." + key + ".points." + i + ".commands", commands); if(flying) tutorialSaves.set("tutorials." + key + ".points." + i + ".setFly", flying); @@ -372,12 +375,20 @@ public void setLoc(Location loc) { this.loc = loc; } - public String getMessage_actionBar() { - return message_actionBar; + public String getMessageActionbar() { + return messageActionbar; + } + + public void setMessageActionbar(String message_actionBar) { + this.messageActionbar = message_actionBar; + } + + public void setActionbarShowAfter(double actionbarShowAfter) { + this.actionbarShowAfter = actionbarShowAfter; } - public void setMessage_actionBar(String message_actionBar) { - this.message_actionBar = message_actionBar; + public void setActionbarHideAfter(double actionbarHideAfter) { + this.actionbarHideAfter = actionbarHideAfter; } public PlayerTitle getTitleInfo() { diff --git a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java index 0d844b4..c374f44 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/custom/CheckPoint.java @@ -138,9 +138,9 @@ public void run() { } if (repeatActionbar) { - if (message_actionBar != null) { + if (messageActionbar != null) { //NeedsReflection.sendActionBar(player, PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar)); - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, message_actionBar))); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(PluginUtils.replaceVariables(plugin.placeholderAPI, player, messageActionbar))); } } } diff --git a/src/main/java/nl/martenm/servertutorialplus/points/editor/args/ActionbarArg.java b/src/main/java/nl/martenm/servertutorialplus/points/editor/args/ActionbarArg.java index 7dd7a1b..5e32c57 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/editor/args/ActionbarArg.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/editor/args/ActionbarArg.java @@ -20,26 +20,45 @@ public ActionbarArg() { @Override public boolean run(ServerTutorial serverTutorial, ServerTutorialPoint point, CommandSender sender, String[] args) { if(args.length < 1){ - sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

actionbar "); + sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

actionbar "); return false; } switch (args[0]) { case "clear": - point.setMessage_actionBar(null); + point.setMessageActionbar(null); break; - case "set": + case "message": if (args.length < 2) { sender.sendMessage(Lang.ERROR_ATLEAST_ONE_WORD.toString()); return false; } String message = StringUtils.join(args, ' ', 1, args.length); - point.setMessage_actionBar(message); + point.setMessageActionbar(message); + break; + case "show-after": + double showAfter; + try { + showAfter = Double.parseDouble(args[1]); + } catch (NumberFormatException e) { + sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString()); + return false; + } + point.setActionbarShowAfter(showAfter); + break; + case "hide-after": + double hideAfter; + try { + hideAfter = Double.parseDouble(args[1]); + } catch (NumberFormatException e) { + sender.sendMessage(Lang.ERROR_INVALID_NUMBNER.toString()); + return false; + } + point.setActionbarHideAfter(hideAfter); break; - default: - sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

actionbar "); + sender.sendMessage(Lang.WRONG_COMMAND_FORMAT + "/st editpoint

actionbar "); return false; } return true;