diff --git a/pom.xml b/pom.xml index d84021b..a8ec772 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,6 @@ 3.0.0 compile - 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 2ff449e..7f87c33 100644 --- a/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java +++ b/src/main/java/nl/martenm/servertutorialplus/points/ServerTutorialPoint.java @@ -37,11 +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 String messageActionbar; + protected double actionbarShowAfter; + protected double actionbarHideAfter; protected PlayerTitle titleInfo; protected PlayerSound soundInfo; protected List pointionEffects; @@ -89,6 +93,7 @@ public void run() { @Override public void stop() { if(timerTask != null) timerTask.cancel(); + if (actionbarRunnable != null) actionbarRunnable.cancel(); } }; } @@ -151,9 +156,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 (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, messageActionbar))); + } 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 +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"); + 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"); @@ -263,7 +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_actionBar); + 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); @@ -352,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;