-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ItemStackReader for 1.20.5 but still supports old ItemStackReader (will only be used if running 1.20.5 or newer)
- Loading branch information
1 parent
3f6b278
commit 6ccdc09
Showing
12 changed files
with
214 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/us/mytheria/bloblib/itemstack/ItemStackReaderMiddleman.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package us.mytheria.bloblib.itemstack; | ||
|
||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface ItemStackReaderMiddleman { | ||
@NotNull | ||
ItemStack readOrFailFast(@NotNull ConfigurationSection section); | ||
|
||
@Nullable | ||
ItemStack attempRead(@NotNull ConfigurationSection section); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/us/mytheria/bloblib/itemstack/Reader1_20_5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package us.mytheria.bloblib.itemstack; | ||
|
||
import me.anjoismysign.itemstack.ItemStackReader; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class Reader1_20_5 implements ItemStackReaderMiddleman { | ||
private static Reader1_20_5 instance; | ||
|
||
public static Reader1_20_5 getInstance() { | ||
if (instance == null) { | ||
instance = new Reader1_20_5(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack readOrFailFast(@NotNull ConfigurationSection section) { | ||
return ItemStackReader.READ_OR_FAIL_FAST(section).build(); | ||
} | ||
|
||
@Override | ||
public @Nullable ItemStack attempRead(@NotNull ConfigurationSection section) { | ||
try { | ||
return readOrFailFast(section); | ||
} catch (Throwable e) { | ||
return null; | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/us/mytheria/bloblib/utilities/MinecraftVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package us.mytheria.bloblib.utilities; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
public record MinecraftVersion(int getMajor, int getMinor) implements Comparable<MinecraftVersion> { | ||
private static MinecraftVersion running; | ||
|
||
public static MinecraftVersion getRunning() { | ||
if (running == null) { | ||
String version = Bukkit.getVersion(); | ||
String[] split = version.split("MC: "); | ||
if (split.length == 1) | ||
throw new IllegalStateException("Failed to get Minecraft version"); | ||
else { | ||
version = split[1].substring(0, split[1].length() - 1); | ||
running = MinecraftVersion.of(version); | ||
} | ||
} | ||
return running; | ||
} | ||
|
||
public static MinecraftVersion of(@NotNull String input) { | ||
Objects.requireNonNull(input, "'input' cannot be null"); | ||
String[] split = input.split("\\."); | ||
if (split.length < 2) | ||
throw new IllegalArgumentException("Invalid version format: " + input); | ||
String major; | ||
String minor; | ||
try { | ||
if (split.length > 2) { | ||
major = split[1]; | ||
minor = split[2]; | ||
int x = Integer.parseInt(major); | ||
int y = Integer.parseInt(minor); | ||
return new MinecraftVersion(x, y); | ||
} | ||
major = split[1]; | ||
minor = "0"; | ||
int x = Integer.parseInt(major); | ||
int y = Integer.parseInt(minor); | ||
return new MinecraftVersion(x, y); | ||
} catch (NumberFormatException exception) { | ||
throw exception; | ||
} | ||
} | ||
|
||
@Override | ||
public int compareTo(@NotNull MinecraftVersion other) { | ||
Objects.requireNonNull(other, "'other' cannot be null"); | ||
if (this.getMajor == other.getMajor && this.getMinor == other.getMinor) | ||
return 0; | ||
if (this.getMajor > other.getMajor) | ||
return 1; | ||
if (this.getMajor < other.getMajor) | ||
return -1; | ||
if (this.getMinor > other.getMinor) | ||
return 1; | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters