Skip to content

Commit 9121bc4

Browse files
authored
Feat support 1.21.6 and change to JSON format (#43)
* feat: 1.21.6 support feat: convert nbt into readable json binary * feat: moved from binary format to json fix: giveUnsueableContent is now saving after the payer recived there items * feat: update UpdateSystem form Orebfuscator chore: remove unused class * fix: #3 linking multiply items at the same time
1 parent 4596272 commit 9121bc4

File tree

41 files changed

+2305
-749
lines changed

Some content is hidden

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

41 files changed

+2305
-749
lines changed

.github/workflows/buildtools.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ checkVersion "1.20.6" "21"
3535
checkVersion "1.21" "21"
3636
checkVersion "1.21.3" "21"
3737
checkVersion "1.21.4" "21"
38-
checkVersion "1.21.5" "21"
38+
checkVersion "1.21.5" "21"
39+
checkVersion "1.21.6" "21"

zip-api/src/main/java/net/imprex/zip/api/ZIPHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public interface ZIPHandler {
1616
ZIPBackpackType getBackpackType(ItemStack item);
1717

1818
boolean isBackpack(ItemStack item);
19+
20+
ZIPUniqueId getUniqueId(ItemStack item);
1921
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.imprex.zip.common;
2+
3+
public class BPConstants {
4+
5+
public static final int VERSION = 2;
6+
public static final int INVENTORY_VERSION = 2;
7+
8+
public static final String KEY_VERSION = "version";
9+
10+
public static final String KEY_ID = "id";
11+
public static final String KEY_TYPE_RAW = "typeRaw";
12+
public static final String KEY_INVENTORY = "inventory";
13+
14+
public static final String KEY_INVENTORY_VERSION = "version";
15+
public static final String KEY_INVENTORY_DATA_VERSION = "dataVersion";
16+
public static final String KEY_INVENTORY_ITEMS = "items";
17+
public static final String KEY_INVENTORY_ITEMS_SIZE = "itemsSize";
18+
public static final String KEY_INVENTORY_SLOT = "ZIPslot";
19+
}
Lines changed: 22 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1+
/**
2+
* @author Imprex-Development
3+
* @see <a href="https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/MinecraftVersion.java">MinecraftVersion.java</a>
4+
*/
15
package net.imprex.zip.common;
26

37
import java.util.ArrayList;
48
import java.util.List;
5-
import java.util.Objects;
69
import java.util.regex.Matcher;
710
import java.util.regex.Pattern;
811

912
import org.bukkit.Bukkit;
1013

11-
/**
12-
* @author Imprex-Development
13-
* @see https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/MinecraftVersion.java
14-
*/
15-
public final class MinecraftVersion implements Comparable<MinecraftVersion> {
14+
public final class MinecraftVersion {
1615

1716
private static final class NmsMapping {
1817

1918
private static final List<NmsMapping> MAPPINGS = new ArrayList<>();
2019

2120
static {
21+
MAPPINGS.add(new NmsMapping("1.21.6", "v1_21_R5"));
2222
MAPPINGS.add(new NmsMapping("1.21.5", "v1_21_R4"));
2323
MAPPINGS.add(new NmsMapping("1.21.4", "v1_21_R3"));
2424
MAPPINGS.add(new NmsMapping("1.21.3", "v1_21_R2"));
2525
MAPPINGS.add(new NmsMapping("1.21", "v1_21_R1"));
2626
MAPPINGS.add(new NmsMapping("1.20.5", "v1_20_R4"));
2727
}
2828

29-
public static String get(MinecraftVersion version) {
29+
public static String get(Version version) {
3030
for (NmsMapping mapping : MAPPINGS) {
3131
if (version.isAtOrAbove(mapping.version)) {
3232
if (mapping.version.minor() != version.minor()) {
33-
System.out.println(String.format("Using nms mapping with mismatched minor versions: %s - %s",
33+
ZIPLogger.warn(String.format("Using nms mapping with mismatched minor versions: %s - %s",
3434
mapping.version, version));
3535
}
3636

@@ -41,19 +41,17 @@ public static String get(MinecraftVersion version) {
4141
throw new RuntimeException("Can't get nms package version for minecraft version: " + version);
4242
}
4343

44-
private final MinecraftVersion version;
44+
private final Version version;
4545
private final String nmsVersion;
4646

4747
public NmsMapping(String version, String nmsVersion) {
48-
this.version = new MinecraftVersion(version);
48+
this.version = Version.parse(version);
4949
this.nmsVersion = nmsVersion;
5050
}
5151
}
5252

53-
private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(?:\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?");
5453
private static final Pattern PACKAGE_PATTERN = Pattern.compile("org\\.bukkit\\.craftbukkit\\.(v\\d+_\\d+_R\\d+)");
55-
56-
private static final MinecraftVersion CURRENT_VERSION = new MinecraftVersion(Bukkit.getBukkitVersion());
54+
private static final Version CURRENT_VERSION = Version.parse(Bukkit.getBukkitVersion());
5755

5856
private static String NMS_VERSION;
5957

@@ -72,118 +70,35 @@ public static String nmsVersion() {
7270
return NMS_VERSION;
7371
}
7472

73+
public static Version current() {
74+
return CURRENT_VERSION;
75+
}
76+
7577
public static int majorVersion() {
76-
return CURRENT_VERSION.major;
78+
return CURRENT_VERSION.major();
7779
}
7880

7981
public static int minorVersion() {
80-
return CURRENT_VERSION.minor;
82+
return CURRENT_VERSION.minor();
8183
}
8284

8385
public static int patchVersion() {
84-
return CURRENT_VERSION.patch;
86+
return CURRENT_VERSION.patch();
8587
}
8688

8789
public static boolean isAbove(String version) {
88-
return CURRENT_VERSION.isAbove(new MinecraftVersion(version));
90+
return CURRENT_VERSION.isAbove(Version.parse(version));
8991
}
9092

9193
public static boolean isAtOrAbove(String version) {
92-
return CURRENT_VERSION.isAtOrAbove(new MinecraftVersion(version));
94+
return CURRENT_VERSION.isAtOrAbove(Version.parse(version));
9395
}
9496

9597
public static boolean isAtOrBelow(String version) {
96-
return CURRENT_VERSION.isAtOrBelow(new MinecraftVersion(version));
98+
return CURRENT_VERSION.isAtOrBelow(Version.parse(version));
9799
}
98100

99101
public static boolean isBelow(String version) {
100-
return CURRENT_VERSION.isBelow(new MinecraftVersion(version));
101-
}
102-
103-
private final int major;
104-
private final int minor;
105-
private final int patch;
106-
107-
public MinecraftVersion(String version) {
108-
Matcher matcher = VERSION_PATTERN.matcher(version);
109-
110-
if (!matcher.find()) {
111-
throw new IllegalArgumentException("can't parse minecraft version: " + version);
112-
}
113-
114-
this.major = Integer.parseInt(matcher.group("major"));
115-
this.minor = Integer.parseInt(matcher.group("minor"));
116-
117-
String patch = matcher.group("patch");
118-
if (patch != null) {
119-
this.patch = Integer.parseInt(patch);
120-
} else {
121-
this.patch = 0;
122-
}
123-
}
124-
125-
public int major() {
126-
return this.major;
127-
}
128-
129-
public int minor() {
130-
return this.minor;
131-
}
132-
133-
public int patch() {
134-
return this.patch;
135-
}
136-
137-
public boolean isAbove(MinecraftVersion version) {
138-
return this.compareTo(version) > 0;
139-
}
140-
141-
public boolean isAtOrAbove(MinecraftVersion version) {
142-
return this.compareTo(version) >= 0;
143-
}
144-
145-
public boolean isAtOrBelow(MinecraftVersion version) {
146-
return this.compareTo(version) <= 0;
147-
}
148-
149-
public boolean isBelow(MinecraftVersion version) {
150-
return this.compareTo(version) < 0;
151-
}
152-
153-
@Override
154-
public int compareTo(MinecraftVersion other) {
155-
int major = Integer.compare(this.major, other.major);
156-
if (major != 0) {
157-
return major;
158-
}
159-
160-
int minor = Integer.compare(this.minor, other.minor);
161-
if (minor != 0) {
162-
return minor;
163-
}
164-
165-
return Integer.compare(this.patch, other.patch);
166-
}
167-
168-
@Override
169-
public int hashCode() {
170-
return Objects.hash(major, minor, patch);
171-
}
172-
173-
@Override
174-
public boolean equals(Object obj) {
175-
if (this == obj) {
176-
return true;
177-
}
178-
if (!(obj instanceof MinecraftVersion)) {
179-
return false;
180-
}
181-
MinecraftVersion other = (MinecraftVersion) obj;
182-
return major == other.major && minor == other.minor && patch == other.patch;
183-
}
184-
185-
@Override
186-
public String toString() {
187-
return String.format("%s.%s.%s", this.major, this.minor, this.patch);
102+
return CURRENT_VERSION.isBelow(Version.parse(version));
188103
}
189104
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @author Imprex-Development
3+
* @see <a href="https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/Version.java">Version.java</a>
4+
*/
5+
package net.imprex.zip.common;
6+
7+
import java.io.IOException;
8+
import java.util.Objects;
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
12+
import com.google.gson.TypeAdapter;
13+
import com.google.gson.stream.JsonReader;
14+
import com.google.gson.stream.JsonWriter;
15+
16+
public record Version(int major, int minor, int patch) implements Comparable<Version> {
17+
18+
private static final Pattern VERSION_PATTERN = Pattern.compile("(?<major>\\d+)(?:\\.(?<minor>\\d+))?(?:\\.(?<patch>\\d+))?");
19+
20+
public static Version parse(String version) {
21+
Matcher matcher = VERSION_PATTERN.matcher(version);
22+
23+
if (!matcher.find()) {
24+
throw new IllegalArgumentException("can't parse version: " + version);
25+
}
26+
27+
int major = Integer.parseInt(matcher.group("major"));
28+
29+
String minorGroup = matcher.group("minor");
30+
int minor = minorGroup != null
31+
? Integer.parseInt(minorGroup)
32+
: 0;
33+
34+
String patchGroup = matcher.group("patch");
35+
int patch = patchGroup != null
36+
? Integer.parseInt(patchGroup)
37+
: 0;
38+
39+
return new Version(major, minor, patch);
40+
}
41+
42+
public boolean isAbove(Version version) {
43+
return this.compareTo(version) > 0;
44+
}
45+
46+
public boolean isAtOrAbove(Version version) {
47+
return this.compareTo(version) >= 0;
48+
}
49+
50+
public boolean isAtOrBelow(Version version) {
51+
return this.compareTo(version) <= 0;
52+
}
53+
54+
public boolean isBelow(Version version) {
55+
return this.compareTo(version) < 0;
56+
}
57+
58+
@Override
59+
public int compareTo(Version other) {
60+
int major = Integer.compare(this.major, other.major);
61+
if (major != 0) {
62+
return major;
63+
}
64+
65+
int minor = Integer.compare(this.minor, other.minor);
66+
if (minor != 0) {
67+
return minor;
68+
}
69+
70+
return Integer.compare(this.patch, other.patch);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(major, minor, patch);
76+
}
77+
78+
@Override
79+
public boolean equals(Object obj) {
80+
if (this == obj) {
81+
return true;
82+
}
83+
if (!(obj instanceof Version)) {
84+
return false;
85+
}
86+
Version other = (Version) obj;
87+
return major == other.major && minor == other.minor && patch == other.patch;
88+
}
89+
90+
@Override
91+
public String toString() {
92+
return String.format("%s.%s.%s", this.major, this.minor, this.patch);
93+
}
94+
95+
public static final class Json extends TypeAdapter<Version> {
96+
97+
@Override
98+
public void write(JsonWriter out, Version value) throws IOException {
99+
out.value(value.toString());
100+
}
101+
102+
@Override
103+
public Version read(JsonReader in) throws IOException {
104+
return Version.parse(in.nextString());
105+
}
106+
}
107+
}

zip-plugin/src/main/java/net/imprex/zip/util/ZIPLogger.java renamed to zip-common/src/main/java/net/imprex/zip/common/ZIPLogger.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.imprex.zip.util;
1+
package net.imprex.zip.common;
22

33
import java.util.logging.Level;
44
import java.util.logging.Logger;
@@ -16,6 +16,10 @@ public static void setVerbose(boolean verbose) {
1616
ZIPLogger.verbose = verbose;
1717
}
1818

19+
public static void log(Level level, String message) {
20+
ZIPLogger.logger.log(level, LOG_PREFIX + message);
21+
}
22+
1923
public static void debug(String message) {
2024
if (ZIPLogger.verbose) {
2125
ZIPLogger.logger.log(Level.FINE, LOG_DEBUG_PREFIX + message);
@@ -30,6 +34,10 @@ public static void warn(String message) {
3034
ZIPLogger.logger.log(Level.WARNING, LOG_PREFIX + message);
3135
}
3236

37+
public static void warn(String message, Throwable throwable) {
38+
ZIPLogger.logger.log(Level.WARNING, LOG_PREFIX + message, throwable);
39+
}
40+
3341
public static void error(String message, Throwable throwable) {
3442
ZIPLogger.logger.log(Level.SEVERE, LOG_PREFIX + message, throwable);
3543
}

zip-nms/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
<module>zip-nms-v1_21_R2</module>
2424
<module>zip-nms-v1_21_R3</module>
2525
<module>zip-nms-v1_21_R4</module>
26+
<module>zip-nms-v1_21_R5</module>
2627
</modules>
2728
</project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.imprex.zip.nms.api;
2+
3+
import java.util.List;
4+
5+
public record ItemStackContainerResult(int containerSize, List<ItemStackWithSlot> items) {
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.imprex.zip.nms.api;
2+
3+
import org.bukkit.inventory.ItemStack;
4+
5+
public record ItemStackWithSlot(int slot, ItemStack item) {
6+
}

0 commit comments

Comments
 (0)