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
/
PlayerJoinsScriptEvent.java
88 lines (73 loc) · 2.62 KB
/
PlayerJoinsScriptEvent.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
package com.denizenscript.denizen2sponge.events.player;
import com.denizenscript.denizen2core.events.ScriptEvent;
import com.denizenscript.denizen2core.tags.AbstractTagObject;
import com.denizenscript.denizen2sponge.Denizen2Sponge;
import com.denizenscript.denizen2sponge.tags.objects.FormattedTextTag;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import java.util.HashMap;
public class PlayerJoinsScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// player chats
//
// @Updated 2016/10/18
//
// @Cancellable false
//
// @Triggers when a player successfully joins the server.
//
// @Context
// player (PlayerTag) returns the player that joined.
// message (FormattedTextTag) returns the message that will be broadcast to the server.
//
// @Determinations
// None.
// -->
@Override
public String getName() {
return "PlayerJoins";
}
@Override
public boolean couldMatch(ScriptEventData data) {
return data.eventPath.startsWith("player joins");
}
@Override
public boolean matches(ScriptEventData data) {
return true;
}
public PlayerTag player;
public FormattedTextTag message;
public ClientConnectionEvent.Join internal;
@Override
public HashMap<String, AbstractTagObject> getDefinitions(ScriptEventData data) {
HashMap<String, AbstractTagObject> defs = super.getDefinitions(data);
defs.put("player", player);
defs.put("message", message);
return defs;
}
@Override
public void enable() {
Sponge.getEventManager().registerListeners(Denizen2Sponge.instance, this);
}
@Override
public void disable() {
Sponge.getEventManager().unregisterListeners(this);
}
@Listener
public void onJoin(ClientConnectionEvent.Join evt, @Root Player player) {
PlayerJoinsScriptEvent event = (PlayerJoinsScriptEvent) clone();
event.internal = evt;
event.player = new PlayerTag(player);
event.message = new FormattedTextTag(evt.getMessage());
event.run();
}
@Override
public void applyDetermination(boolean errors, String determination, AbstractTagObject value) {
super.applyDetermination(errors, determination, value);
}
}