Skip to content

Commit

Permalink
Add action_msg()
Browse files Browse the repository at this point in the history
Moved from the CHNaughty extension.
  • Loading branch information
PseudoKnight committed Jan 3, 2025
1 parent 300752c commit 7c28a76
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/Echoes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends CREThrowable>[] 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 {
Expand Down

0 comments on commit 7c28a76

Please sign in to comment.