This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
NarrateCommand.java
89 lines (81 loc) · 3.23 KB
/
NarrateCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.denizenscript.denizen2sponge.commands.player;
import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2core.tags.objects.MapTag;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.entity.living.player.Player;
public class NarrateCommand extends AbstractCommand {
// <--[command]
// @Name narrate
// @Arguments <message>
// @Short tells the most relevant player a message. Convenience helper only.
// @Updated 2017/01/31
// @Group Player
// @Minimum 1
// @Maximum 1
// @Description
// Tells the most relevant player a message.
// This is a CONVENIENCE HELPER only. The <@link command tell>Tell Command<@/link> should be preferred!
// TODO: Explain more!
// @Example
// # This example tells the current player the message "hello there!" in the chat box.
// - narrate "hello there!"
// -->
@Override
public String getName() {
return "narrate";
}
@Override
public String getArguments() {
return "<message>";
}
@Override
public int getMinimumArguments() {
return 1;
}
@Override
public int getMaximumArguments() {
return 1;
}
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
PlayerTag player = null;
if (queue.commandStack.peek().hasDefinition("player")){
AbstractTagObject ato = queue.commandStack.peek().getDefinition("player");
if (ato instanceof PlayerTag) {
player = (PlayerTag) ato;
}
}
else if (queue.commandStack.peek().hasDefinition("context")) {
AbstractTagObject ato = queue.commandStack.peek().getDefinition("context");
if (ato instanceof MapTag) {
if (((MapTag) ato).getInternal().containsKey("player")) {
AbstractTagObject plt = ((MapTag) ato).getInternal().get("player");
if (plt instanceof PlayerTag) {
player = (PlayerTag) plt;
}
}
}
}
if (player == null) {
queue.handleError(entry, "No player located to narrate to!");
return;
}
AbstractTagObject ato = entry.getArgumentObject(queue, 0);
if (queue.shouldShowGood()) {
queue.outGood("Telling " + ColorSet.emphasis + player.debug()
+ ColorSet.good + ": " + ColorSet.emphasis + ato.debug());
}
if (ato instanceof FormattedTextTag) {
player.getInternal().sendMessage(((FormattedTextTag) ato).getInternal());
}
else {
player.getInternal().sendMessage(Denizen2Sponge.parseColor(ato.toString()));
}
}
}