Skip to content

Commit 83b9559

Browse files
committed
downgrade to Java 8, fix AddonProtocols in 1.8
1 parent 626dda6 commit 83b9559

File tree

20 files changed

+121
-39
lines changed

20 files changed

+121
-39
lines changed

api/src/main/java/net/labymod/serverapi/api/AbstractProtocolService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void afterPacketSent(
125125
// NO-OP
126126
}
127127

128-
protected enum Side {
128+
public enum Side {
129129
CLIENT(Direction.CLIENTBOUND),
130130
SERVER(Direction.SERVERBOUND),
131131
;

api/src/main/java/net/labymod/serverapi/api/Protocol.java

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public Protocol(
7171
this.protocolSide = protocolService.getSide();
7272
this.packets = new HashSet<>();
7373
this.awaitingResponses = new HashSet<>();
74+
75+
if (this.identifier.toString().length() > 20) {
76+
this.protocolService.logger().warn("The identifier of the protocol " + this.identifier + " "
77+
+ "is longer than 20 characters. This will cause issues with 1.8 & 1.12.2 users.");
78+
}
7479
}
7580

7681
/**
@@ -302,7 +307,8 @@ private ProtocolPacket getProtocolPacketById(int id) {
302307
}
303308

304309
private void handlePacket(ProtocolPacket protocolPacket, UUID sender, Packet packet) {
305-
if (packet instanceof IdentifiablePacket identifiablePacket) {
310+
if (packet instanceof IdentifiablePacket) {
311+
IdentifiablePacket identifiablePacket = (IdentifiablePacket) packet;
306312
AwaitingResponse responsePacket = null;
307313
for (AwaitingResponse awaitingResponse : this.awaitingResponses) {
308314
if (awaitingResponse.recipient.equals(sender)
@@ -355,7 +361,8 @@ private void sendPacketInternal(
355361
packet.write(writer);
356362
this.protocolService.send(this.identifier, recipient, writer);
357363
if (responseClass != null && responseCallback != null
358-
&& packet instanceof IdentifiablePacket identifiablePacket) {
364+
&& packet instanceof IdentifiablePacket) {
365+
IdentifiablePacket identifiablePacket = (IdentifiablePacket) packet;
359366
synchronized (this.awaitingResponses) {
360367
this.awaitingResponses.add(new AwaitingResponse(
361368
recipient,
@@ -370,14 +377,79 @@ private void sendPacketInternal(
370377
this.protocolService.afterPacketSent(this, packet, recipient);
371378
}
372379

373-
private record AwaitingResponse(
374-
UUID recipient,
375-
IdentifiablePacket initialPacket,
376-
int identifier,
377-
Class responseClass,
378-
Predicate responseCallback
379-
) {
380+
private final class AwaitingResponse {
381+
382+
private final UUID recipient;
383+
private final IdentifiablePacket initialPacket;
384+
private final int identifier;
385+
private final Class responseClass;
386+
private final Predicate responseCallback;
387+
388+
private AwaitingResponse(
389+
UUID recipient,
390+
IdentifiablePacket initialPacket,
391+
int identifier,
392+
Class responseClass,
393+
Predicate responseCallback
394+
) {
395+
this.recipient = recipient;
396+
this.initialPacket = initialPacket;
397+
this.identifier = identifier;
398+
this.responseClass = responseClass;
399+
this.responseCallback = responseCallback;
400+
}
401+
402+
public UUID recipient() {
403+
return this.recipient;
404+
}
380405

406+
public IdentifiablePacket initialPacket() {
407+
return this.initialPacket;
408+
}
409+
410+
public int identifier() {
411+
return this.identifier;
412+
}
413+
414+
public Class responseClass() {
415+
return this.responseClass;
416+
}
417+
418+
public Predicate responseCallback() {
419+
return this.responseCallback;
420+
}
421+
422+
@Override
423+
public boolean equals(Object obj) {
424+
if (obj == this) {
425+
return true;
426+
}
427+
if (obj == null || obj.getClass() != this.getClass()) {
428+
return false;
429+
}
430+
AwaitingResponse that = (AwaitingResponse) obj;
431+
return Objects.equals(this.recipient, that.recipient) &&
432+
Objects.equals(this.initialPacket, that.initialPacket) &&
433+
this.identifier == that.identifier &&
434+
Objects.equals(this.responseClass, that.responseClass) &&
435+
Objects.equals(this.responseCallback, that.responseCallback);
436+
}
437+
438+
@Override
439+
public int hashCode() {
440+
return Objects.hash(this.recipient, this.initialPacket, this.identifier, this.responseClass,
441+
this.responseCallback);
442+
}
443+
444+
@Override
445+
public String toString() {
446+
return "AwaitingResponse[" +
447+
"recipient=" + this.recipient + ", " +
448+
"initialPacket=" + this.initialPacket + ", " +
449+
"identifier=" + this.identifier + ", " +
450+
"responseClass=" + this.responseClass + ", " +
451+
"responseCallback=" + this.responseCallback + ']';
452+
}
381453
}
382454

383455
private static class ProtocolPacket {

api/src/main/java/net/labymod/serverapi/api/ProtocolRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected ProtocolRegistry() {
5757
public void registerProtocol(@NotNull Protocol protocol) {
5858
Objects.requireNonNull(protocol, "Protocol cannot be null");
5959
this.protocols.add(protocol);
60+
System.out.println("Registered protocol: " + protocol.identifier());
6061

6162
for (Consumer<Protocol> registerListener : this.registerListeners) {
6263
registerListener.accept(protocol);

api/src/main/java/net/labymod/serverapi/api/model/component/ServerAPIBaseComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ public boolean equals(Object o) {
186186
return true;
187187
}
188188

189-
if (!(o instanceof ServerAPIBaseComponent<?> that)) {
189+
if (!(o instanceof ServerAPIBaseComponent<?>)) {
190190
return false;
191191
}
192192

193+
ServerAPIBaseComponent<?> that = (ServerAPIBaseComponent<?>) o;
193194
return Objects.equals(this.textColor, that.textColor) && Objects.equals(
194195
this.decorations, that.decorations) && Objects.equals(this.children, that.children);
195196
}

api/src/main/java/net/labymod/serverapi/api/model/component/ServerAPITextComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ public boolean equals(Object o) {
6060
return true;
6161
}
6262

63-
if (!(o instanceof ServerAPITextComponent that)) {
63+
if (!(o instanceof ServerAPITextComponent)) {
6464
return false;
6565
}
6666

6767
if (!super.equals(o)) {
6868
return false;
6969
}
7070

71+
ServerAPITextComponent that = (ServerAPITextComponent) o;
7172
return Objects.equals(this.text, that.text);
7273
}
7374

api/src/main/java/net/labymod/serverapi/api/payload/io/PayloadWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ public void writeOptionalString(@Nullable String value) {
187187
public void writeComponent(@NotNull ServerAPIComponent component) {
188188
byte id = 0;
189189
Consumer<PayloadWriter> dataWriter = null;
190-
if (component instanceof ServerAPITextComponent textComponent) {
190+
if (component instanceof ServerAPITextComponent) {
191+
ServerAPITextComponent textComponent = (ServerAPITextComponent) component;
191192
if (!textComponent.getText().isEmpty()) {
192193
id = 1;
193194
dataWriter = writer -> writer.writeString(textComponent.getText());

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ subprojects {
6262
}
6363

6464
java {
65-
sourceCompatibility = JavaVersion.VERSION_17
66-
targetCompatibility = JavaVersion.VERSION_17
65+
sourceCompatibility = JavaVersion.VERSION_1_8
66+
targetCompatibility = JavaVersion.VERSION_1_8
6767
}
6868

6969
fun adjustArchiveFileName(property: Property<String>) {

core/src/main/java/net/labymod/serverapi/core/AbstractLabyModProtocolService.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public final LabyModProtocol labyModProtocol() {
121121
* class loader returned by {@link #getIntegrationClassLoader()} is used.
122122
*/
123123
protected void loadLabyModProtocolIntegrations(@Nullable ClassLoader classLoader) {
124-
System.out.println("Loading LabyMod Protocol Integrations...");
125124
ServiceLoader<LabyModProtocolIntegration> serviceLoader;
126125
if (classLoader == null) {
127126
serviceLoader = ServiceLoader.load(
@@ -132,24 +131,14 @@ protected void loadLabyModProtocolIntegrations(@Nullable ClassLoader classLoader
132131
serviceLoader = ServiceLoader.load(LabyModProtocolIntegration.class, classLoader);
133132
}
134133

135-
int found = 0;
136134
for (LabyModProtocolIntegration labyModProtocolIntegration : serviceLoader) {
137135
try {
138-
System.out.println(
139-
"Loading LabyModProtocolIntegration: " + labyModProtocolIntegration.getClass()
140-
.getName());
141136
labyModProtocolIntegration.initialize(this);
142137
this.integrations.add(labyModProtocolIntegration);
143-
System.out.println(
144-
"Loaded LabyModProtocolIntegration: " + labyModProtocolIntegration.getClass()
145-
.getName());
146-
found++;
147138
} catch (Exception e) {
148139
e.printStackTrace();
149140
}
150141
}
151-
152-
System.out.println("Found and loaded" + found + " Integrations.");
153142
}
154143

155144
/**

core/src/main/java/net/labymod/serverapi/core/AddonProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public AddonProtocol(
4848
) {
4949
super(
5050
protocolService,
51-
PayloadChannelIdentifier.create("labymod", "neo/addon/" + namespace)
51+
PayloadChannelIdentifier.create("labymod", namespace)
5252
);
5353
Objects.requireNonNull(namespace, "Namespace cannot be null");
5454
this.namespace = namespace;

core/src/main/java/net/labymod/serverapi/core/model/display/EconomyDisplay.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ public boolean equals(Object o) {
108108
return true;
109109
}
110110

111-
if (!(o instanceof EconomyDisplay that)) {
111+
if (!(o instanceof EconomyDisplay)) {
112112
return false;
113113
}
114114

115+
EconomyDisplay that = (EconomyDisplay) o;
115116
return this.visible == that.visible && Double.compare(this.balance, that.balance) == 0
116117
&& Objects.equals(this.key, that.key) && Objects.equals(this.iconUrl, that.iconUrl)
117118
&& Objects.equals(this.decimalFormat, that.decimalFormat);
@@ -150,10 +151,11 @@ public boolean equals(Object o) {
150151
return true;
151152
}
152153

153-
if (!(o instanceof DecimalFormat that)) {
154+
if (!(o instanceof DecimalFormat)) {
154155
return false;
155156
}
156157

158+
DecimalFormat that = (DecimalFormat) o;
157159
return Double.compare(this.divisor, that.divisor) == 0 && Objects.equals(this.format,
158160
that.format);
159161
}

0 commit comments

Comments
 (0)