This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
AnnounceCommand.java
65 lines (57 loc) · 2.06 KB
/
AnnounceCommand.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
package com.denizenscript.denizen2sponge.commands.server;
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.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
public class AnnounceCommand extends AbstractCommand {
// <--[command]
// @Name announce
// @Arguments <message>
// @Short announces a message to all online players.
// @Updated 2017/09/25
// @Group Server
// @Minimum 1
// @Maximum 1
// @Description
// Announces a message to all online players.
// @Example
// # This example announces to all players that the server is being shut down.
// - announce "Shutting down the server!"
// -->
@Override
public String getName() {
return "announce";
}
@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) {
AbstractTagObject message = entry.getArgumentObject(queue, 0);
Text text;
if (message instanceof FormattedTextTag) {
text = ((FormattedTextTag) message).getInternal();
}
else {
text = Denizen2Sponge.parseColor(message.toString());
}
Sponge.getServer().getBroadcastChannel().send(text);
if (queue.shouldShowGood()) {
queue.outGood("Announcing to all players: " + ColorSet.emphasis + message.debug());
}
}
}