Skip to content

Commit ae53005

Browse files
committed
Merge branch 'master' of https://github.com/MasivoSMP/BreweryX
2 parents 1374ad4 + 2395f14 commit ae53005

8 files changed

Lines changed: 36 additions & 31 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ plugins {
3838
}
3939

4040
group = "com.dre.brewery"
41-
version = "3.6.4"
41+
version = "3.6.5"
4242
val langVersion: Int = 21
4343
val encoding: String = "UTF-8"
4444

src/main/java/com/dre/brewery/Barrel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,12 @@ public static class BarrelCheck extends UniversalRunnable {
597597
public void run() {
598598
barrels.keySet()
599599
.forEach(worldUuid -> {
600+
// Folia doesn't fire 'WorldUnloadEvent' but Canvas does.
601+
if (MinecraftVersion.isFolia() && !MinecraftVersion.isCanvas() && Bukkit.getWorld(worldUuid) == null) {
602+
barrels.remove(worldUuid); // remove this world and assume that it was unloaded on Folia servers
603+
return;
604+
}
605+
600606
int counter = checkCounters.computeIfAbsent(worldUuid, ignored -> -1);
601607

602608
List<Barrel> worldBarrels = barrels.get(worldUuid);

src/main/java/com/dre/brewery/BreweryPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ public void onDisable() {
281281
// save Data to Disk
282282
if (dataManager != null) dataManager.exit(true, false);
283283

284-
BSealer.unregisterRecipe();
285-
286284
PlaceholderAPIHook placeholderAPIHook = PlaceholderAPIHook.PLACEHOLDERAPI;
287285
if (placeholderAPIHook.isEnabled()) {
288286
placeholderAPIHook.getInstance().unregister();

src/main/java/com/dre/brewery/integration/Hook.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.bukkit.plugin.Plugin;
3030
import org.jetbrains.annotations.ApiStatus;
3131
import org.jetbrains.annotations.Contract;
32+
import org.jetbrains.annotations.Nullable;
3233

3334
@Getter
3435
@Setter
@@ -55,7 +56,8 @@ public class Hook {
5556
private final String name;
5657
@ApiStatus.Internal
5758
private boolean enabled;
58-
private boolean checked;
59+
@ApiStatus.Internal
60+
protected boolean checked;
5961

6062
public Hook(String name) {
6163
this.name = name;
@@ -78,7 +80,7 @@ public boolean isEnabled() {
7880
}
7981

8082
@Contract
81-
public Plugin getPlugin() {
83+
public @Nullable Plugin getPlugin() {
8284
if (isEnabled()) {
8385
Plugin plugin = Bukkit.getPluginManager().getPlugin(name);
8486
if (plugin == null) {

src/main/java/com/dre/brewery/recipe/BRecipe.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.dre.brewery.configuration.files.CustomItemsFile;
3030
import com.dre.brewery.configuration.files.Lang;
3131
import com.dre.brewery.configuration.sector.capsule.ConfigRecipe;
32-
import com.dre.brewery.integration.Hook;
3332
import com.dre.brewery.integration.PlaceholderAPIHook;
3433
import com.dre.brewery.utility.BUtil;
3534
import com.dre.brewery.utility.Logging;
@@ -254,13 +253,9 @@ public static IngredientResult loadIngredientVerbose(String item) {
254253

255254

256255
// Check if this is a Plugin Item
257-
String[] pluginItem = matParts[0].split(":");
256+
String[] pluginItem = matParts[0].split(":", 2);
258257
if (pluginItem.length > 1) {
259-
StringBuilder itemId = new StringBuilder();
260-
for (int i = 1; i < pluginItem.length; i++) { // Append all but the first part to include namespaces.
261-
itemId.append(pluginItem[i]);
262-
}
263-
RecipeItem custom = PluginItem.fromConfig(pluginItem[0], itemId.toString());
258+
RecipeItem custom = PluginItem.fromConfig(pluginItem[0], pluginItem[1]);
264259
if (custom != null) {
265260
custom.setAmount(amount);
266261
custom.makeImmutable();
@@ -312,8 +307,11 @@ public static IngredientResult loadIngredientVerbose(String item) {
312307
}
313308

314309
public sealed interface IngredientResult {
315-
record Success(RecipeItem ingredient) implements IngredientResult {}
316-
record Error(IngredientError error, String invalidPart) implements IngredientResult {}
310+
record Success(RecipeItem ingredient) implements IngredientResult {
311+
}
312+
313+
record Error(IngredientError error, String invalidPart) implements IngredientResult {
314+
}
317315
}
318316

319317
@AllArgsConstructor
@@ -420,6 +418,7 @@ public int allowedTimeDiff(int time) {
420418

421419
/**
422420
* Gets the <strong>primary</strong> barrel type out of all supported.
421+
*
423422
* @return the barrel type
424423
* @see #getBarrelTypes() for the full list
425424
*/
@@ -486,6 +485,7 @@ public boolean isMissingIngredients(List<Ingredient> list) {
486485
}
487486
return false;
488487
}
488+
489489
public List<RecipeItem> getMissingIngredients(List<Ingredient> list) {
490490
List<RecipeItem> missing = new ArrayList<>();
491491
for (RecipeItem rItem : ingredients) {

src/main/java/com/dre/brewery/storage/serialization/BukkitSerialization.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static Inventory fromBase64(String data) throws IOException {
136136
return null;
137137
}
138138
try {
139-
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getDecoder().decode(data));
139+
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getMimeDecoder().decode(data));
140140
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
141141
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
142142

@@ -169,7 +169,7 @@ public static ItemStack[] itemStackArrayFromBase64(String data) {
169169
}
170170

171171
try {
172-
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getDecoder().decode(data));
172+
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getMimeDecoder().decode(data));
173173
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
174174
ItemStack[] items = new ItemStack[dataInput.readInt()];
175175

src/main/java/com/dre/brewery/storage/serialization/SQLDataSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public String serialize(Object object) {
3939
}
4040

4141
public <T> T deserialize(String data, Class<T> type) {
42-
return gson.fromJson(new String(Base64.getDecoder().decode(data)), type);
42+
return gson.fromJson(new String(Base64.getMimeDecoder().decode(data)), type);
4343
}
4444

4545
public <T> T deserialize(String data, Class<T> type, T defaultValue) {

src/main/java/com/dre/brewery/utility/MinecraftVersion.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import org.bukkit.Bukkit;
2626
import org.jetbrains.annotations.Nullable;
2727

28+
import java.util.Arrays;
29+
import java.util.regex.Matcher;
30+
import java.util.regex.Pattern;
31+
2832
/**
2933
* Enum for major Minecraft versions where Brewery needs
3034
* to handle things differently.
@@ -55,8 +59,10 @@ public enum MinecraftVersion {
5559
V1_21_11("1.21.11"),
5660
UNKNOWN("Unknown");
5761

62+
private static final Pattern VERSION_PATTERN = Pattern.compile("^([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?");
5863

59-
private @Getter static final boolean isFolia = MinecraftVersion.checkFolia();
64+
private @Getter static final boolean isFolia = ClassUtil.exists("io.papermc.paper.threadedregions.RegionizedServer");
65+
private @Getter static final boolean isCanvas = ClassUtil.exists("io.canvasmc.canvas.Config"); // Popular Folia fork
6066
private @Getter static final boolean useNBT = NBTUtil.initNbt();
6167

6268
private final String[] versions;
@@ -91,12 +97,14 @@ public static MinecraftVersion get(String major, String minor, @Nullable String
9197
public static MinecraftVersion getIt() {
9298
String rawVersion = Bukkit.getVersion();
9399
String rawVersionParsed = rawVersion.substring(rawVersion.indexOf("(MC: ") + 5, rawVersion.indexOf(")"));
94-
String[] versionSplit = rawVersionParsed.split("\\.");
95-
96-
Preconditions.checkState(versionSplit.length == 3 || versionSplit.length == 2, "Unexpected Minecraft version format: " + rawVersionParsed);
97100

101+
Matcher matcher = VERSION_PATTERN.matcher(rawVersionParsed);
102+
if (!matcher.find()) {
103+
throw new IllegalStateException("Could not parse Minecraft version from: " + rawVersion);
104+
}
105+
Preconditions.checkState(matcher.groupCount() == 3 || matcher.groupCount() == 2, "Unexpected Minecraft version format: " + rawVersionParsed);
98106

99-
return get(versionSplit[0], versionSplit[1], versionSplit[2]);
107+
return get(matcher.group(1), matcher.group(2), matcher.group(3));
100108
}
101109

102110
public boolean isOrLater(MinecraftVersion version) {
@@ -110,13 +118,4 @@ public boolean isOrEarlier(MinecraftVersion version) {
110118
public String getVersion() {
111119
return versions[0];
112120
}
113-
114-
private static boolean checkFolia() {
115-
try {
116-
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
117-
return true;
118-
} catch (ClassNotFoundException ignored) {
119-
return false;
120-
}
121-
}
122121
}

0 commit comments

Comments
 (0)