-
Notifications
You must be signed in to change notification settings - Fork 6
/
ServerEventCommand.java
73 lines (67 loc) · 2.85 KB
/
ServerEventCommand.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
package com.denizenscript.clientizen.scripts.commands;
import com.denizenscript.clientizen.network.NetworkManager;
import com.denizenscript.clientizen.network.packets.FireEventPacketOut;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
import com.denizenscript.denizencore.scripts.commands.generator.ArgName;
import com.denizenscript.denizencore.scripts.commands.generator.ArgPrefixed;
import com.denizenscript.denizencore.utilities.text.StringHolder;
import java.util.HashMap;
import java.util.Map;
public class ServerEventCommand extends AbstractCommand {
// <--[command]
// @Name CustomEvent
// @Syntax serverevent [id:<id>] (data:<map>)
// @Required 1
// @Maximum 2
// @Short Sends the server an event.
// @Group core
//
// @Description
// Sends the server the client is currently connected to an event, potentially including extra data.
//
// Input is an ID (an identifier to be used by the server to recognize the event, choose a constant name to use), and an optional MapTag of context data.
//
// Note that the server must be running Depenizen with the Clientizen Bridge enabled to receive events.
//
// @Tags
// None
//
// @Usage
// Use to send the server an event with the id "something_happened"
// - serverevent id:something_happened
//
// @Usage
// Use to send the server an event with the id "user" and supply a context map of basic data.
// - serverevent id:user data:[name=Aya;message=Hello]
//
// @Usage
// Use to send the server an event with the id "something_happened" and supply a context map of more interesting data.
// - definemap context:
// Denizen: scripting
// food: waffle
// loaded_entities: <client.loaded_entities.size>
// - customevent id:something_happened context:<[context]>
//
// -->
public ServerEventCommand() {
setName("serverevent");
setSyntax("serverevent [id:<id>] (data:<map>)");
setRequiredArguments(1, 2);
autoCompile();
}
public static void autoExecute(ScriptEntry scriptEntry,
@ArgPrefixed @ArgName("id") String id,
@ArgDefaultNull @ArgPrefixed @ArgName("data") MapTag dataInput) {
Map<String, String> data = new HashMap<>();
if (dataInput != null) {
for (Map.Entry<StringHolder, ObjectTag> entry : dataInput.map.entrySet()) {
data.put(entry.getKey().str, entry.getValue().savable());
}
}
NetworkManager.send(new FireEventPacketOut(id, data));
}
}