Skip to content

Commit 96120fb

Browse files
authored
Merge pull request TuffNetwork#2 from TuffNetwork/inspird-dev
optomize
2 parents 6b0fefb + b6602ef commit 96120fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+616
-571208
lines changed

src/main/java/net/potato/tuff/ChunkSectionKey.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,65 @@
33
import java.util.Objects;
44
import java.util.UUID;
55

6-
// formats stuff to be good boy strings
7-
86
public final class ChunkSectionKey {
9-
private final UUID playerId;
10-
private final String worldName;
11-
private final int cx;
12-
private final int cz;
13-
private final int sectionY;
7+
private final UUID p;
8+
private final String w;
9+
private final int x;
10+
private final int z;
11+
private final int y;
1412

15-
public ChunkSectionKey(UUID playerId, String worldName, int cx, int cz, int sectionY) {
16-
this.playerId = playerId;
17-
this.worldName = worldName;
18-
this.cx = cx;
19-
this.cz = cz;
20-
this.sectionY = sectionY;
13+
public ChunkSectionKey(UUID p, String w, int x, int z, int y) {
14+
this.p = p;
15+
this.w = w;
16+
this.x = x;
17+
this.z = z;
18+
this.y = y;
2119
}
2220

23-
public UUID playerId() {
24-
return playerId;
21+
public UUID p() {
22+
return p;
2523
}
2624

27-
public String worldName() {
28-
return worldName;
25+
public String w() {
26+
return w;
2927
}
3028

31-
public int cx() {
32-
return cx;
29+
public int x() {
30+
return x;
3331
}
3432

35-
public int cz() {
36-
return cz;
33+
public int z() {
34+
return z;
3735
}
3836

39-
public int sectionY() {
40-
return sectionY;
37+
public int y() {
38+
return y;
4139
}
4240

4341
@Override
44-
public boolean equals(Object obj) {
45-
if (obj == this) return true;
46-
if (obj == null || obj.getClass() != this.getClass()) return false;
47-
var that = (ChunkSectionKey) obj;
48-
return Objects.equals(this.playerId, that.playerId) &&
49-
Objects.equals(this.worldName, that.worldName) &&
50-
this.cx == that.cx &&
51-
this.cz == that.cz &&
52-
this.sectionY == that.sectionY;
42+
public boolean equals(Object o) {
43+
if (o == this) return true;
44+
if (o == null || o.getClass() != this.getClass()) return false;
45+
var t = (ChunkSectionKey) o;
46+
return Objects.equals(p, t.p) &&
47+
Objects.equals(w, t.w) &&
48+
x == t.x &&
49+
z == t.z &&
50+
y == t.y;
5351
}
5452

5553
@Override
5654
public int hashCode() {
57-
return Objects.hash(playerId, worldName, cx, cz, sectionY);
55+
return Objects.hash(p, w, x, z, y);
5856
}
5957

6058
@Override
6159
public String toString() {
6260
return "ChunkSectionKey[" +
63-
"playerId=" + playerId + ", " +
64-
"worldName=" + worldName + ", " +
65-
"cx=" + cx + ", " +
66-
"cz=" + cz + ", " +
67-
"sectionY=" + sectionY + ']';
61+
"p=" + p + ", " +
62+
"w=" + w + ", " +
63+
"x=" + x + ", " +
64+
"z=" + z + ", " +
65+
"y=" + y + ']';
6866
}
69-
}
67+
}

src/main/java/net/potato/tuff/LegacyBlockIdManager.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,42 @@
22

33
import org.bukkit.Material;
44
import org.bukkit.plugin.Plugin;
5-
6-
import java.util.HashSet;
7-
import java.util.Set;
5+
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
86

97
public class LegacyBlockIdManager {
108

11-
private static final short[] ID_CACHE = new short[Material.values().length];
12-
private static final Set<String> unmappedBlocks = new HashSet<>();
13-
private static boolean initialized = false;
9+
private static final short[] IC = new short[Material.values().length];
10+
private static final ObjectOpenHashSet<String> UB = new ObjectOpenHashSet<>();
11+
private static boolean I = false;
1412

15-
public static void initialize(Plugin plugin) {
16-
if (initialized) return;
13+
public static void initialize(Plugin p) {
14+
if (I) return;
1715

18-
for (Material material : Material.values()) {
19-
if (!material.isBlock()) {
20-
ID_CACHE[material.ordinal()] = 0; // Air
16+
for (Material m : Material.values()) {
17+
if (!m.isBlock()) {
18+
IC[m.ordinal()] = 0;
2119
continue;
2220
}
2321

24-
String blockName = material.name().toLowerCase();
25-
int id = LegacyBlockIds.BLOCK_ID_MAP.getOrDefault(blockName, -1);
26-
int meta = LegacyBlockIds.BLOCK_META_MAP.getOrDefault(blockName, 0);
22+
String bn = m.name().toLowerCase();
23+
int id = LegacyBlockIds.BLOCK_ID_MAP.getOrDefault(bn, -1);
24+
int mt = LegacyBlockIds.BLOCK_META_MAP.getOrDefault(bn, 0);
2725

2826
if (id == -1) {
2927
id = 1;
30-
if (unmappedBlocks.add(blockName)) {
31-
plugin.getLogger().warning("Unmapped block: " + blockName + ". Defaulting to stone (ID=1).");
28+
if (UB.add(bn)) {
29+
p.getLogger().warning("Unmapped block: " + bn + ". Defaulting to stone (ID=1).");
3230
}
3331
}
3432

35-
ID_CACHE[material.ordinal()] = (short) ((id & 0xFFF) | ((meta & 0xF) << 12));
33+
IC[m.ordinal()] = (short) ((id & 0xFFF) | ((mt & 0xF) << 12));
3634
}
3735

38-
initialized = true;
39-
plugin.getLogger().info("Legacy Block ID cache initialized successfully.");
36+
I = true;
37+
p.getLogger().info("Legacy Block ID cache initialized successfully.");
4038
}
4139

42-
public static short getLegacyShort(Material material) {
43-
return ID_CACHE[material.ordinal()];
40+
public static short getLegacyShort(Material m) {
41+
return IC[m.ordinal()];
4442
}
45-
}
43+
}

0 commit comments

Comments
 (0)