This commit is contained in:
Minecon724 2024-12-16 20:30:56 +01:00
parent a4cdc28b57
commit 49224629c7
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 5 additions and 3 deletions

View file

@ -24,6 +24,7 @@ public class ItemStorage {
public static void init(MusicPlugin plugin) { public static void init(MusicPlugin plugin) {
INSTANCE = new ItemStorage(); INSTANCE = new ItemStorage();
INSTANCE.directory = new File(plugin.getDataFolder(), "storage"); INSTANCE.directory = new File(plugin.getDataFolder(), "storage");
INSTANCE.directory.mkdir();
} }
static ItemStorage getInstance() { static ItemStorage getInstance() {
@ -31,7 +32,7 @@ public class ItemStorage {
} }
public PortableMediaPlayer getPortableMediaPlayer(int id) throws IOException { public PortableMediaPlayer getPortableMediaPlayer(int id) throws IOException {
var file = new File(directory, HexFormat.of().toHexDigits(id)); var file = new File(directory, HexFormat.of().toHexDigits(id) + ".pmpdata.bin");
if (!file.exists()) return null; if (!file.exists()) return null;
@ -43,7 +44,7 @@ public class ItemStorage {
var premium = buffer.get() == 1; var premium = buffer.get() == 1;
var eb = new byte[Byte.toUnsignedInt(buffer.get())]; var eb = new byte[buffer.get() & 0xFF];
buffer.get(eb); buffer.get(eb);
var engraving = new String(eb, StandardCharsets.UTF_8); var engraving = new String(eb, StandardCharsets.UTF_8);
@ -51,7 +52,7 @@ public class ItemStorage {
} }
public void savePortableMediaPlayer(PortableMediaPlayer player) throws IOException { public void savePortableMediaPlayer(PortableMediaPlayer player) throws IOException {
var file = new File(directory, HexFormat.of().toHexDigits(player.id)); var file = new File(directory, HexFormat.of().toHexDigits(player.id) + ".pmpdata.bin");
Files.write(file.toPath(), getData(player)); Files.write(file.toPath(), getData(player));
} }

View file

@ -50,6 +50,7 @@ public class PortableMediaPlayer {
var is = new ItemStack(Material.IRON_INGOT); var is = new ItemStack(Material.IRON_INGOT);
var meta = is.getItemMeta(); var meta = is.getItemMeta();
meta.setItemName("Portable music player");
meta.addEnchant(Enchantment.UNBREAKING, 1, false); meta.addEnchant(Enchantment.UNBREAKING, 1, false);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.getPersistentDataContainer().set(namespacedKey, PersistentDataType.INTEGER, id); meta.getPersistentDataContainer().set(namespacedKey, PersistentDataType.INTEGER, id);