Skip to content

Commit 7c28a76

Browse files
committed
Add action_msg()
Moved from the CHNaughty extension.
1 parent 300752c commit 7c28a76

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/main/java/com/laytonsmith/abstraction/MCPlayer.java

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye
8686

8787
void sendTitle(String title, String subtitle, int fadein, int stay, int fadeout);
8888

89+
void sendActionMessage(String message);
90+
8991
void setAllowFlight(boolean flight);
9092

9193
void setCompassTarget(MCLocation l);

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCWeather;
4444
import com.laytonsmith.commandhelper.CommandHelperPlugin;
4545
import com.laytonsmith.core.Static;
46+
import net.md_5.bungee.api.chat.BaseComponent;
4647
import org.bukkit.Location;
4748
import org.bukkit.Material;
4849
import org.bukkit.Note;
@@ -351,6 +352,12 @@ public void sendTitle(String title, String subtitle, int fadein, int stay, int f
351352
p.sendTitle(title, subtitle, fadein, stay, fadeout);
352353
}
353354

355+
@Override
356+
public void sendActionMessage(String message) {
357+
BaseComponent txt = net.md_5.bungee.api.chat.TextComponent.fromLegacy(message);
358+
p.spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR, txt);
359+
}
360+
354361
@Override
355362
public void setAllowFlight(boolean flight) {
356363
p.setAllowFlight(flight);

src/main/java/com/laytonsmith/core/functions/Echoes.java

+47
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,53 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
315315
}
316316
}
317317

318+
@api(environments = {CommandHelperEnvironment.class})
319+
public static class action_msg extends AbstractFunction {
320+
321+
public String getName() {
322+
return "action_msg";
323+
}
324+
325+
public Integer[] numArgs() {
326+
return new Integer[]{1, 2};
327+
}
328+
329+
public String docs() {
330+
return "void {[player], message} Sends a message to the action bar above the hot bar.";
331+
}
332+
333+
public Construct exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
334+
MCPlayer player;
335+
String message;
336+
if(args.length == 2) {
337+
player = Static.GetPlayer(args[0], t);
338+
message = args[1].val();
339+
} else {
340+
player = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
341+
Static.AssertPlayerNonNull(player, t);
342+
message = args[0].val();
343+
}
344+
player.sendActionMessage(message);
345+
return CVoid.VOID;
346+
}
347+
348+
public Class<? extends CREThrowable>[] thrown() {
349+
return new Class[]{CREPlayerOfflineException.class, CRELengthException.class};
350+
}
351+
352+
public boolean isRestricted() {
353+
return true;
354+
}
355+
356+
public Boolean runAsync() {
357+
return false;
358+
}
359+
360+
public MSVersion since() {
361+
return MSVersion.V3_3_5;
362+
}
363+
}
364+
318365
@api
319366
@seealso({colorize.class})
320367
public static class color extends AbstractFunction implements Optimizable {

0 commit comments

Comments
 (0)