Skip to content

Commit abc7eb4

Browse files
committed
Change how it handle versions
Spigot has change how versions is formatted. Added also one more item for versions below 1.13.
1 parent db68364 commit abc7eb4

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

src/main/java/org/brokenarrow/menu/library/NMS/UpdateTittleContainers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void update(Player p, String title) {
4242
} else if (ServerVersion.atLeast(ServerVersion.v1_18_0)) {
4343
convertFieldNames("9;a", "18;b", "27;c", "36;d", "45;e", "54;f", "5;p");
4444
if (nmsData == null)
45-
nmsData = new NmsData(ServerVersion.equals(ServerVersion.v1_18_2) ? "bV" : "bW", "j",
45+
nmsData = new NmsData(ServerVersion.atLeast(ServerVersion.v1_18_2) ? "bV" : "bW", "j",
4646
"a", "a");
4747
loadNmsClasses1_18();
4848
updateInventory(p, title, inventory, nmsData);

src/main/java/org/brokenarrow/menu/library/utility/Item/ConvertToItemStack.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public ItemStack createStack(final String item, int amount) {
135135
if (item.equals("SMOOTH_STONE_SLAB")) {
136136
return new ItemStack(Material.valueOf("STEP"), amount);
137137
}
138+
if (item.startsWith("GOLDEN_")) {
139+
Material material = Material.getMaterial("GOLD" + item.substring(item.indexOf("_")));
140+
return new ItemStack(material == null ? Material.AIR : material, amount);
141+
}
138142
if (item.equals("CLOCK")) {
139143
return new ItemStack(Material.valueOf("WATCH"), amount);
140144

src/main/java/org/brokenarrow/menu/library/utility/ServerVersion.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
import org.bukkit.plugin.Plugin;
44

55
public enum ServerVersion {
6-
v1_18_2(18.2),
7-
v1_18_1(18.1),
8-
v1_18_0(18.0),
9-
v1_17(17.0),
10-
v1_16(16.0),
11-
v1_15(15.0),
12-
v1_14(14.0),
13-
v1_13(13.0),
14-
v1_12(12.0),
15-
v1_11(11.0),
16-
v1_10(10.0),
17-
v1_9(9.0),
18-
v1_8(8.0),
19-
v1_7(7.0),
20-
v1_6(6.0),
21-
v1_5(5.0),
22-
v1_4(4.0),
23-
v1_3_AND_BELOW(3.0);
6+
v1_19((float) 19.0),
7+
v1_18_2((float) 18.2),
8+
v1_18_1((float) 18.1),
9+
v1_18_0((float) 18.0),
10+
v1_17((float) 17.0),
11+
v1_16((float) 16.0),
12+
v1_15((float) 15.0),
13+
v1_14((float) 14.0),
14+
v1_13((float) 13.0),
15+
v1_12((float) 12.0),
16+
v1_11((float) 11.0),
17+
v1_10((float) 10.0),
18+
v1_9((float) 9.0),
19+
v1_8((float) 8.0),
20+
v1_7((float) 7.0),
21+
v1_6((float) 6.0),
22+
v1_5((float) 5.0),
23+
v1_4((float) 4.0),
24+
v1_3_AND_BELOW((float) 3.0);
2425

2526
private final double version;
2627
private static double currentServerVersion;
@@ -46,11 +47,27 @@ public static double serverVersion(ServerVersion version) {
4647
}
4748

4849
public static void setServerVersion(Plugin plugin) {
49-
String[] version = plugin.getServer().getBukkitVersion().split("\\.");
50-
if (version[1].startsWith("18"))
51-
currentServerVersion = Double.parseDouble(version[1] + "." + version[2].substring(0, version[2].lastIndexOf("-")));
50+
String[] strings = plugin.getServer().getBukkitVersion().split("\\.");
51+
String firstNumber;
52+
String secondNumber;
53+
String firstString = strings[1];
54+
if (firstString.contains("-")) {
55+
firstNumber = firstString.substring(0, firstString.lastIndexOf("-"));
56+
57+
secondNumber = firstString.substring(firstString.lastIndexOf("-") + 1);
58+
int index = secondNumber.toUpperCase().indexOf("R");
59+
if (index >= 0)
60+
secondNumber = secondNumber.substring(index + 1);
61+
} else {
62+
String secondString = strings[2];
63+
firstNumber = firstString;
64+
secondNumber = secondString.substring(0, secondString.lastIndexOf("-"));
65+
}
66+
float version = Float.parseFloat(firstNumber + "." + secondNumber);
67+
if (version < 18)
68+
currentServerVersion = Math.floor(version);
5269
else
53-
currentServerVersion = Double.parseDouble(version[1]);
70+
currentServerVersion = version;
5471
}
5572

5673
public double getVersion() {
@@ -61,7 +78,7 @@ public static double getCurrentServerVersion() {
6178
return currentServerVersion;
6279
}
6380

64-
ServerVersion(double version) {
81+
ServerVersion(final float version) {
6582
this.version = version;
6683

6784
}

0 commit comments

Comments
 (0)