2
2
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
3
3
* Copyright (C) 2012 Kristian S. Stangeland
4
4
*
5
- * This program is free software; you can redistribute it and/or modify it under the terms of the
6
- * GNU General Public License as published by the Free Software Foundation; either version 2 of
5
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
6
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of
7
7
* the License, or (at your option) any later version.
8
8
*
9
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
11
* See the GNU General Public License for more details.
12
12
*
13
- * You should have received a copy of the GNU General Public License along with this program;
14
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
13
+ * You should have received a copy of the GNU General Public License along with this program;
14
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
15
15
* 02111-1307 USA
16
16
*/
17
17
18
18
package com .comphenix .protocol .events ;
19
19
20
- import java .io .IOException ;
21
- import java .io .ObjectInputStream ;
22
- import java .io .ObjectOutputStream ;
23
- import java .io .Serializable ;
24
- import java .lang .reflect .Constructor ;
25
- import java .lang .reflect .InvocationTargetException ;
26
- import java .lang .reflect .Method ;
27
- import java .util .Map ;
28
- import java .util .UUID ;
29
- import java .util .concurrent .ConcurrentHashMap ;
30
-
31
20
import com .comphenix .protocol .reflect .accessors .Accessors ;
32
21
import com .comphenix .protocol .reflect .accessors .MethodAccessor ;
33
22
import com .comphenix .protocol .utility .ByteBuddyFactory ;
34
-
35
- import org .bukkit .*;
36
- import org .bukkit .entity .EntityType ;
37
- import org .bukkit .entity .Player ;
38
- import org .bukkit .profile .PlayerProfile ;
39
-
23
+ import com .comphenix .protocol .utility .Util ;
40
24
import net .bytebuddy .description .ByteCodeElement ;
41
25
import net .bytebuddy .description .modifier .Visibility ;
42
26
import net .bytebuddy .dynamic .loading .ClassLoadingStrategy ;
46
30
import net .bytebuddy .implementation .MethodCall ;
47
31
import net .bytebuddy .implementation .MethodDelegation ;
48
32
import net .bytebuddy .implementation .bind .annotation .AllArguments ;
49
- import net .bytebuddy .implementation .bind .annotation .Origin ;
50
33
import net .bytebuddy .implementation .bind .annotation .FieldValue ;
34
+ import net .bytebuddy .implementation .bind .annotation .Origin ;
51
35
import net .bytebuddy .implementation .bind .annotation .RuntimeType ;
52
36
import net .bytebuddy .matcher .ElementMatcher ;
53
37
import net .bytebuddy .matcher .ElementMatchers ;
38
+ import org .bukkit .*;
39
+ import org .bukkit .entity .EntityType ;
40
+ import org .bukkit .entity .Player ;
41
+ import org .bukkit .profile .PlayerProfile ;
42
+ import org .jetbrains .annotations .NotNull ;
43
+
44
+ import java .io .IOException ;
45
+ import java .io .ObjectInputStream ;
46
+ import java .io .ObjectOutputStream ;
47
+ import java .io .Serializable ;
48
+ import java .lang .reflect .Constructor ;
49
+ import java .lang .reflect .InvocationTargetException ;
50
+ import java .lang .reflect .Method ;
51
+ import java .util .Map ;
52
+ import java .util .UUID ;
53
+ import java .util .concurrent .ConcurrentHashMap ;
54
54
55
55
/**
56
56
* Represents a player object that can be serialized by Java.
57
- *
57
+ *
58
58
* @author Kristian
59
59
*/
60
60
class SerializedOfflinePlayer implements OfflinePlayer , Serializable {
@@ -65,7 +65,7 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
65
65
private static final long serialVersionUID = -2728976288470282810L ;
66
66
67
67
private transient Location bedSpawnLocation ;
68
-
68
+
69
69
// Relevant data about an offline player
70
70
private String name ;
71
71
private UUID uuid ;
@@ -76,6 +76,8 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
76
76
private boolean playedBefore ;
77
77
private boolean online ;
78
78
private boolean whitelisted ;
79
+ private long lastLogin ;
80
+ private long lastSeen ;
79
81
80
82
private static final Constructor <?> proxyPlayerConstructor = setupProxyPlayerConstructor ();
81
83
@@ -85,9 +87,10 @@ class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
85
87
public SerializedOfflinePlayer () {
86
88
// Do nothing
87
89
}
88
-
90
+
89
91
/**
90
92
* Initialize this serializable offline player from another player.
93
+ *
91
94
* @param offline - another player.
92
95
*/
93
96
public SerializedOfflinePlayer (OfflinePlayer offline ) {
@@ -100,8 +103,14 @@ public SerializedOfflinePlayer(OfflinePlayer offline) {
100
103
this .playedBefore = offline .hasPlayedBefore ();
101
104
this .online = offline .isOnline ();
102
105
this .whitelisted = offline .isWhitelisted ();
106
+
107
+ // TODO needs to be reflectively obtained
108
+ if (Util .isUsingFolia ()) {
109
+ // this.lastSeen = offline.getLastSeen();
110
+ // this.lastLogin = offline.getLastLogin();
111
+ }
103
112
}
104
-
113
+
105
114
@ Override
106
115
public boolean isOp () {
107
116
return operator ;
@@ -122,49 +131,74 @@ public Location getBedSpawnLocation() {
122
131
return bedSpawnLocation ;
123
132
}
124
133
134
+ // @Override
135
+ public long getLastLogin () {
136
+ return lastLogin ;
137
+ }
138
+
139
+ // @Override
140
+ public long getLastSeen () {
141
+ return lastSeen ;
142
+ }
143
+
125
144
// TODO do we need to implement this?
126
-
127
- public void incrementStatistic (Statistic statistic ) throws IllegalArgumentException { }
128
145
129
- public void decrementStatistic (Statistic statistic ) throws IllegalArgumentException { }
146
+ public void incrementStatistic (Statistic statistic ) throws IllegalArgumentException {
147
+ }
148
+
149
+ public void decrementStatistic (Statistic statistic ) throws IllegalArgumentException {
150
+ }
130
151
131
- public void incrementStatistic (Statistic statistic , int i ) throws IllegalArgumentException { }
152
+ public void incrementStatistic (Statistic statistic , int i ) throws IllegalArgumentException {
153
+ }
132
154
133
- public void decrementStatistic (Statistic statistic , int i ) throws IllegalArgumentException { }
155
+ public void decrementStatistic (Statistic statistic , int i ) throws IllegalArgumentException {
156
+ }
134
157
135
- public void setStatistic (Statistic statistic , int i ) throws IllegalArgumentException { }
158
+ public void setStatistic (Statistic statistic , int i ) throws IllegalArgumentException {
159
+ }
136
160
137
161
public int getStatistic (Statistic statistic ) throws IllegalArgumentException {
138
162
return 0 ;
139
163
}
140
164
141
- public void incrementStatistic (Statistic statistic , Material material ) throws IllegalArgumentException { }
165
+ public void incrementStatistic (Statistic statistic , Material material ) throws IllegalArgumentException {
166
+ }
142
167
143
- public void decrementStatistic (Statistic statistic , Material material ) throws IllegalArgumentException { }
168
+ public void decrementStatistic (Statistic statistic , Material material ) throws IllegalArgumentException {
169
+ }
144
170
145
171
public int getStatistic (Statistic statistic , Material material ) throws IllegalArgumentException {
146
172
return 0 ;
147
173
}
148
174
149
- public void incrementStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException { }
175
+ public void incrementStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException {
176
+ }
150
177
151
- public void decrementStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException { }
178
+ public void decrementStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException {
179
+ }
152
180
153
- public void setStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException { }
181
+ public void setStatistic (Statistic statistic , Material material , int i ) throws IllegalArgumentException {
182
+ }
154
183
155
- public void incrementStatistic (Statistic statistic , EntityType entityType ) throws IllegalArgumentException { }
184
+ public void incrementStatistic (Statistic statistic , EntityType entityType ) throws IllegalArgumentException {
185
+ }
156
186
157
- public void decrementStatistic (Statistic statistic , EntityType entityType ) throws IllegalArgumentException { }
187
+ public void decrementStatistic (Statistic statistic , EntityType entityType ) throws IllegalArgumentException {
188
+ }
158
189
159
190
public int getStatistic (Statistic statistic , EntityType entityType ) throws IllegalArgumentException {
160
191
return 0 ;
161
192
}
162
193
163
- public void incrementStatistic (Statistic statistic , EntityType entityType , int i ) throws IllegalArgumentException { }
194
+ public void incrementStatistic (Statistic statistic , EntityType entityType , int i ) throws IllegalArgumentException {
195
+ }
164
196
165
- public void decrementStatistic (Statistic statistic , EntityType entityType , int i ) { }
197
+ public void decrementStatistic (Statistic statistic , EntityType entityType , int i ) {
198
+ }
166
199
167
- public void setStatistic (Statistic statistic , EntityType entityType , int i ) { }
200
+ public void setStatistic (Statistic statistic , EntityType entityType , int i ) {
201
+ }
168
202
169
203
@ Override
170
204
public Location getLastDeathLocation () {
@@ -187,15 +221,15 @@ public UUID getUniqueId() {
187
221
}
188
222
189
223
@ Override
190
- public PlayerProfile getPlayerProfile () {
224
+ public @ NotNull PlayerProfile getPlayerProfile () {
191
225
return null ;
192
226
}
193
227
194
228
@ Override
195
229
public String getName () {
196
230
return name ;
197
231
}
198
-
232
+
199
233
@ Override
200
234
public boolean hasPlayedBefore () {
201
235
return playedBefore ;
@@ -209,7 +243,7 @@ public boolean isBanned() {
209
243
public void setBanned (boolean banned ) {
210
244
this .banned = banned ;
211
245
}
212
-
246
+
213
247
@ Override
214
248
public boolean isOnline () {
215
249
return online ;
@@ -227,14 +261,14 @@ public void setWhitelisted(boolean whitelisted) {
227
261
228
262
private void writeObject (ObjectOutputStream output ) throws IOException {
229
263
output .defaultWriteObject ();
230
-
264
+
231
265
// Serialize the bed spawn location
232
266
output .writeUTF (bedSpawnLocation .getWorld ().getName ());
233
267
output .writeDouble (bedSpawnLocation .getX ());
234
268
output .writeDouble (bedSpawnLocation .getY ());
235
269
output .writeDouble (bedSpawnLocation .getZ ());
236
270
}
237
-
271
+
238
272
private void readObject (ObjectInputStream input ) throws ClassNotFoundException , IOException {
239
273
input .defaultReadObject ();
240
274
@@ -246,7 +280,7 @@ private void readObject(ObjectInputStream input) throws ClassNotFoundException,
246
280
input .readDouble ()
247
281
);
248
282
}
249
-
283
+
250
284
private World getWorld (String name ) {
251
285
try {
252
286
// Try to get the world at least
@@ -256,7 +290,7 @@ private World getWorld(String name) {
256
290
return null ;
257
291
}
258
292
}
259
-
293
+
260
294
@ Override
261
295
public Player getPlayer () {
262
296
try {
@@ -266,11 +300,12 @@ public Player getPlayer() {
266
300
return getProxyPlayer ();
267
301
}
268
302
}
269
-
303
+
270
304
/**
271
305
* Retrieve a player object that implements OfflinePlayer by referring to this object.
272
306
* <p>
273
307
* All other methods cause an exception.
308
+ *
274
309
* @return Proxy object.
275
310
*/
276
311
public Player getProxyPlayer () {
@@ -285,8 +320,7 @@ public Player getProxyPlayer() {
285
320
}
286
321
}
287
322
288
- private static Constructor <? extends Player > setupProxyPlayerConstructor ()
289
- {
323
+ private static Constructor <? extends Player > setupProxyPlayerConstructor () {
290
324
final Method [] offlinePlayerMethods = OfflinePlayer .class .getMethods ();
291
325
final String [] methodNames = new String [offlinePlayerMethods .length ];
292
326
for (int idx = 0 ; idx < offlinePlayerMethods .length ; ++idx )
@@ -321,9 +355,9 @@ public Object intercept(
321
355
});
322
356
323
357
final InvocationHandlerAdapter throwException = InvocationHandlerAdapter .of ((obj , method , args ) -> {
324
- throw new UnsupportedOperationException (
358
+ throw new UnsupportedOperationException (
325
359
"The method " + method .getName () + " is not supported for offline players." );
326
- });
360
+ });
327
361
328
362
return ByteBuddyFactory .getInstance ()
329
363
.createSubclass (PlayerUnion .class , ConstructorStrategy .Default .NO_CONSTRUCTORS )
@@ -354,7 +388,6 @@ public Object intercept(
354
388
* This interface extends both OfflinePlayer and Player (in that order) so that the class generated by ByteBuddy
355
389
* looks at OfflinePlayer's methods first while still being a Player.
356
390
*/
357
- private interface PlayerUnion extends OfflinePlayer , Player
358
- {
391
+ private interface PlayerUnion extends OfflinePlayer , Player {
359
392
}
360
393
}
0 commit comments