/
SubCreatedEvent.java
150 lines (135 loc) · 3.55 KB
/
SubCreatedEvent.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package net.ME1312.SubServers.Client.Sponge.Event;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Common.Network.API.SubServer;
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
import net.ME1312.SubServers.Client.Sponge.SubAPI;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.impl.AbstractEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Server Created Event
*/
public class SubCreatedEvent extends AbstractEvent implements SubEvent {
private UUID player;
private boolean success;
private boolean update;
private String host;
private String name;
private String template;
private Version version;
private int port;
/**
* Server Created Event
*
* @param player Player Creating
* @param host Potential Host
* @param name Server Name
* @param template Server Type
* @param version Server Version
* @param port Server Port Number
*/
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
Util.nullpo(host, name, template);
this.player = player;
this.success = success;
this.update = update;
this.host = host;
this.name = name;
this.template = template;
this.version = version;
this.port = port;
}
/**
* Get the Host the SubServer runs on
*
* @return Host
*/
public String getHost() {
return host;
}
/**
* Get if SubCreator was being run in update mode
*
* @return Update Mode Status
*/
public boolean wasUpdate() {
return update;
}
/**
* Get if the operation was a success
*
* @return Success Status
*/
public boolean wasSuccessful() {
return success;
}
/**
* Get the Server that's being updated
*
* @param callback Updating Server
*/
public void getServer(Consumer<SubServer> callback) {
if (!update && !success) {
try {
callback.accept(null);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.printStackTrace();
}
} else {
SubAPI.getInstance().getSubServer(name, callback);
}
}
/**
* Get the name the SubServer used
*
* @return SubServer Name
*/
public String getName() {
return name;
}
/**
* Get the Template that was used
*
* @return Server Template
*/
public String getTemplate() {
return template;
}
/**
* Get the Version the Server used
*
* @return Server Version
*/
public Version getVersion() {
return version;
}
/**
* Get the Port the Server used
*
* @return Port Number
*/
public int getPort() {
return port;
}
/**
* Gets the player that triggered the Event
*
* @return The Player that triggered this Event or null if Console
*/
public UUID getPlayer() { return player; }
/**
* Gets the cause of this Event
*
* @deprecated Use simplified methods where available
* @return The player UUID who triggered this event
*/
@Override
@Deprecated
public Cause getCause() {
return Cause.builder().append(player).build(getContext());
}
}