Skip to content

Commit 93f1643

Browse files
authored
feat: optomize
1 parent 72338e2 commit 93f1643

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

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)