Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb210a0

Browse files
committed
Optimize some code and fix bungee compiler
1 parent bb9e71a commit eb210a0

6 files changed

Lines changed: 40 additions & 55 deletions

File tree

bungee/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ repositories {
1515
name 'sonatype'
1616
url 'https://oss.sonatype.org/content/repositories/snapshots/'
1717
}
18+
maven {
19+
url 'https://libraries.minecraft.net/'
20+
}
1821
}
1922

2023
dependencies {
2124
api project(':common')
2225
implementation 'org.bstats:bstats-bungeecord-lite:1.7'
23-
compileOnly 'net.md-5:bungeecord-api:1.20-R0.1-SNAPSHOT'
24-
compileOnly 'net.md-5:bungeecord-chat:1.20-R0.1-SNAPSHOT'
26+
compileOnly 'net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT'
27+
compileOnly 'net.md-5:bungeecord-chat:1.21-R0.1-SNAPSHOT'
2528
compileOnly 'com.github.minecrafter:RedisBungee:master'
2629
}
2730

common/src/com/elikill58/negativity/api/packets/nms/PacketSerializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ public BlockPosition readBlockPositionShort() {
270270
return new BlockPosition(x, y, z);
271271
}
272272

273+
public Vector readDoubleVector() {
274+
return new Vector(readDouble(), readDouble(), readDouble());
275+
}
276+
273277
public Vector readVector() {
274278
return new Vector(readFloat(), readFloat(), readFloat());
275279
}

common/src/com/elikill58/negativity/api/packets/packet/playout/NPacketPlayOutExplosion.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class NPacketPlayOutExplosion implements NPacketPlayOut, LocatedPacket {
1515

1616
public double x, y, z, strength;
1717
public Vector vec;
18-
public List<BlockPosition> positions;
1918

2019
public NPacketPlayOutExplosion() {
2120

@@ -32,16 +31,23 @@ public void read(PacketSerializer serializer, Version version) {
3231
this.y = serializer.readFloat();
3332
this.z = serializer.readFloat();
3433
}
35-
this.strength = serializer.readFloat();
36-
int i = serializer.readVarInt();
37-
this.positions = new ArrayList<>(i);
38-
for (int b = 0; b < i; b++) {
39-
int posX = (int) (serializer.readByte() + x);
40-
int posY = (int) (serializer.readByte() + y);
41-
int posZ = (int) (serializer.readByte() + z);
42-
this.positions.add(new BlockPosition(posX, posY, posZ));
34+
if(version.isNewerOrEquals(Version.V1_21_8)) {
35+
this.vec = serializer.readDoubleVector();
36+
// serializer.readVarInt(); // particle ID
37+
// then particle data
38+
// final particle sound
39+
} else {
40+
this.strength = serializer.readFloat();
41+
int i = serializer.readVarInt();
42+
List<BlockPosition> positions = new ArrayList<>(i); // positions of explosions
43+
for (int b = 0; b < i; b++) {
44+
int posX = (int) (serializer.readByte() + x);
45+
int posY = (int) (serializer.readByte() + y);
46+
int posZ = (int) (serializer.readByte() + z);
47+
positions.add(new BlockPosition(posX, posY, posZ));
48+
}
49+
this.vec = serializer.readVector();
4350
}
44-
this.vec = serializer.readVector();
4551
}
4652

4753
@Override

common/src/com/elikill58/negativity/universal/Version.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public enum Version {
3333
V1_21("1.21", 21, Version1_21::new, 767),
3434
V1_21_3("1.21.3", 21.3, Version1_21_3::new, 768),
3535
V1_21_4("1.21.4", 21.4, Version1_21_4::new, 769),
36-
V1_21_6("1.21.6", 21.6, Version1_21_6::new, 770, 771),
37-
V1_21_8("1.21.8", 21.8, Version1_21_8::new, 772, 773),
36+
V1_21_5("1.21.5", 21.5, Version1_21_6::new, 770),
37+
V1_21_6("1.21.6", 21.6, Version1_21_6::new, 771),
38+
V1_21_8("1.21.8", 21.8, Version1_21_8::new, 772),
39+
V1_21_10("1.21.10", 21.10, Version1_21_8::new, 773),
3840
HIGHER("higher", 42, VersionUnknown::new, 774, 1000);
3941

4042
private final double power;

spigot/src/com/elikill58/negativity/spigot/SubPlatform.java

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
11
package com.elikill58.negativity.spigot;
22

3-
import java.util.concurrent.Callable;
3+
import com.elikill58.negativity.universal.utils.ReflectionUtils;
44

55
public enum SubPlatform {
66

7-
CRAFTBUKKIT("CraftBukkit", () -> {
8-
try {
9-
Class.forName("org.spigotmc.SpigotConfig");
10-
return false;
11-
} catch (ClassNotFoundException e) {
12-
return true;
13-
}
14-
}),
15-
SPIGOT("Spigot", () -> false),
16-
FOLIA("Folia", () -> {
17-
try {
18-
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
19-
return true;
20-
} catch (ClassNotFoundException e) {}
21-
return false;
22-
}),
23-
PAPER("Paper", () -> {
24-
try {
25-
Class.forName("com.destroystokyo.paper.PaperVersionFetcher");
26-
return true;
27-
} catch (ClassNotFoundException e) {}
28-
return false;
29-
}),
30-
MOHIST("Mohist", () -> {
31-
try {
32-
Class.forName("com.mohistmc.MohistMC");
33-
return true;
34-
} catch (ClassNotFoundException e) {}
35-
return false;
36-
});
7+
CRAFTBUKKIT("CraftBukkit", ReflectionUtils.isClassExist("org.spigotmc.SpigotConfig")),
8+
SPIGOT("Spigot", false),
9+
FOLIA("Folia", ReflectionUtils.isClassExist("io.papermc.paper.threadedregions.RegionizedServer")),
10+
PAPER("Paper", ReflectionUtils.isClassExist("com.destroystokyo.paper.PaperVersionFetcher")),
11+
MOHIST("Mohist", ReflectionUtils.isClassExist("com.mohistmc.MohistMC"));
3712

3813
private final String name;
39-
private final Callable<Boolean> isThis;
14+
private final boolean isThis;
4015

41-
private SubPlatform(String name, Callable<Boolean> isThis) {
16+
private SubPlatform(String name, boolean isThis) {
4217
this.name = name;
4318
this.isThis = isThis;
4419
}
@@ -48,12 +23,7 @@ public String getName() {
4823
}
4924

5025
public boolean isThis() {
51-
try {
52-
return isThis != null && isThis.call();
53-
} catch (Exception e) {
54-
e.printStackTrace();
55-
return false;
56-
}
26+
return isThis;
5727
}
5828

5929
public static SubPlatform getSubPlatform() {

spigot/src/com/elikill58/negativity/spigot/nms/SpigotVersionAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public double getAverageTps() {
109109
for (long m : array)
110110
l += m;
111111
return l / array.length;
112-
} else {
112+
} else if (tps instanceof double[]) {
113113
double[] array = (double[]) tps;
114114
double l = 0L;
115115
for (double m : array)
@@ -118,8 +118,8 @@ public double getAverageTps() {
118118
}
119119
} catch (Exception e) {
120120
e.printStackTrace();
121-
return 0;
122121
}
122+
return 0;
123123
}
124124

125125
public abstract String getTpsFieldName();

0 commit comments

Comments
 (0)