diff --git a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java index f8321fc5f..98c424a2c 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java @@ -86,6 +86,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye void sendTitle(String title, String subtitle, int fadein, int stay, int fadeout); + void sendActionMessage(String message); + void setAllowFlight(boolean flight); void setCompassTarget(MCLocation l); diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java index 730e09d1e..064dbb6ac 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java @@ -43,6 +43,7 @@ import com.laytonsmith.abstraction.enums.bukkit.BukkitMCWeather; import com.laytonsmith.commandhelper.CommandHelperPlugin; import com.laytonsmith.core.Static; +import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Note; @@ -351,6 +352,12 @@ public void sendTitle(String title, String subtitle, int fadein, int stay, int f p.sendTitle(title, subtitle, fadein, stay, fadeout); } + @Override + public void sendActionMessage(String message) { + BaseComponent txt = net.md_5.bungee.api.chat.TextComponent.fromLegacy(message); + p.spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR, txt); + } + @Override public void setAllowFlight(boolean flight) { p.setAllowFlight(flight); diff --git a/src/main/java/com/laytonsmith/core/functions/Echoes.java b/src/main/java/com/laytonsmith/core/functions/Echoes.java index 000f0d518..0216119e0 100644 --- a/src/main/java/com/laytonsmith/core/functions/Echoes.java +++ b/src/main/java/com/laytonsmith/core/functions/Echoes.java @@ -315,6 +315,53 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi } } + @api(environments = {CommandHelperEnvironment.class}) + public static class action_msg extends AbstractFunction { + + public String getName() { + return "action_msg"; + } + + public Integer[] numArgs() { + return new Integer[]{1, 2}; + } + + public String docs() { + return "void {[player], message} Sends a message to the action bar above the hot bar."; + } + + public Construct exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException { + MCPlayer player; + String message; + if(args.length == 2) { + player = Static.GetPlayer(args[0], t); + message = args[1].val(); + } else { + player = environment.getEnv(CommandHelperEnvironment.class).GetPlayer(); + Static.AssertPlayerNonNull(player, t); + message = args[0].val(); + } + player.sendActionMessage(message); + return CVoid.VOID; + } + + public Class[] thrown() { + return new Class[]{CREPlayerOfflineException.class, CRELengthException.class}; + } + + public boolean isRestricted() { + return true; + } + + public Boolean runAsync() { + return false; + } + + public MSVersion since() { + return MSVersion.V3_3_5; + } + } + @api @seealso({colorize.class}) public static class color extends AbstractFunction implements Optimizable {