From 8c34f039e895d83b770767e9394fe0ef8e3e1e01 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 16:33:47 -0800 Subject: [PATCH 1/6] Util - add method checks --- .../com/shanebeestudios/vf/api/util/Util.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/shanebeestudios/vf/api/util/Util.java b/src/main/java/com/shanebeestudios/vf/api/util/Util.java index 75e8739..532f98b 100644 --- a/src/main/java/com/shanebeestudios/vf/api/util/Util.java +++ b/src/main/java/com/shanebeestudios/vf/api/util/Util.java @@ -6,6 +6,8 @@ import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; +import java.lang.reflect.Method; + public class Util { private static final String PREFIX = "&7[&bVirtual&3Furnace&7] "; @@ -108,4 +110,24 @@ public static boolean classExists(final String className) { } } + // Copied from SkriptLang/Skript + public static boolean methodExists(Class c, String methodName, Class... paramTypes) { + try { + c.getDeclaredMethod(methodName, paramTypes); + return true; + } catch (NoSuchMethodException | SecurityException ignore) { + return false; + } + } + + // Copied from SkriptLang/Skript + public static boolean methodExists(Class c, String methodName, Class[] paramTypes, Class returnType) { + try { + Method m = c.getDeclaredMethod(methodName, paramTypes); + return m.getReturnType() == returnType; + } catch (NoSuchMethodException | SecurityException ignore) { + return false; + } + } + } From 98cda2919146d179d531228df815b8c8dbc4383c Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 16:35:36 -0800 Subject: [PATCH 2/6] build.gradle - update Paper API --- build.gradle | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 925ba12..5b675fe 100644 --- a/build.gradle +++ b/build.gradle @@ -10,13 +10,12 @@ plugins { } compileJava { - sourceCompatibility = '17' - targetCompatibility = '17' options.encoding = 'UTF-8' } // VirtualFurnace version version = '1.0.0' +def oldestJava = 17 repositories { mavenCentral() @@ -28,12 +27,16 @@ repositories { dependencies { // Paper - compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") // bStats implementation(group: 'org.bstats', name: 'bstats-bukkit', version: '3.0.2') } +tasks.withType(JavaCompile).configureEach { + options.compilerArgs += ['-source', '' + oldestJava, '-target', '' + oldestJava] +} + build { tasks.withType(JavaCompile).tap { configureEach { From 1c68d5858b0872d78a0584d9bc5d7f7d1dd5e632 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 16:39:55 -0800 Subject: [PATCH 3/6] Fix some deprecated/broken things --- .../shanebeestudios/vf/api/FurnaceManager.java | 15 ++++++++++++--- .../vf/api/builder/ItemBuilder.java | 12 +++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java index c557ba4..6cc0fff 100644 --- a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java +++ b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java @@ -5,6 +5,7 @@ import com.shanebeestudios.vf.api.util.Util; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -33,6 +34,12 @@ @SuppressWarnings({"unused", "UnusedReturnValue"}) public class FurnaceManager { + private static final boolean HAS_GLINT = Util.methodExists(ItemMeta.class, "getEnchantmentGlintOverride"); + @SuppressWarnings({"deprecation", "DataFlowIssue"}) + private static final @NotNull Enchantment SHARPNESS = Registry.ENCHANTMENT.get(NamespacedKey.minecraft("sharpness")); + @SuppressWarnings({"deprecation", "DataFlowIssue"}) + private static final @NotNull Enchantment INFINITY = Registry.ENCHANTMENT.get(NamespacedKey.minecraft("infinity")); + private final VirtualFurnaceAPI virtualFurnaceAPI; private File furnaceFile; private FileConfiguration furnaceConfig; @@ -229,10 +236,12 @@ public ItemStack createItemWithFurnace(@NotNull String name, @NotNull FurnacePro ItemMeta meta = item.getItemMeta(); assert meta != null; if (glowing) { - if (item.getType() == Material.ARROW) { - meta.addEnchant(Enchantment.DAMAGE_ALL, 1, true); + if (HAS_GLINT) { + meta.setEnchantmentGlintOverride(true); + } else if (item.getType() == Material.ARROW) { + meta.addEnchant(SHARPNESS, 1, true); } else { - meta.addEnchant(Enchantment.ARROW_INFINITE, 1, true); + meta.addEnchant(INFINITY, 1, true); } meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } diff --git a/src/main/java/com/shanebeestudios/vf/api/builder/ItemBuilder.java b/src/main/java/com/shanebeestudios/vf/api/builder/ItemBuilder.java index 6ec06f2..0ab6f0b 100644 --- a/src/main/java/com/shanebeestudios/vf/api/builder/ItemBuilder.java +++ b/src/main/java/com/shanebeestudios/vf/api/builder/ItemBuilder.java @@ -20,6 +20,16 @@ @SuppressWarnings("unused") public class ItemBuilder { + private static final ItemFlag HIDE_POTIONS; + + static { + if (Util.isRunningMinecraft(1, 20, 5)) { + HIDE_POTIONS = ItemFlag.HIDE_ADDITIONAL_TOOLTIP; + } else { + HIDE_POTIONS = ItemFlag.valueOf("HIDE_POTION_EFFECTS"); + } + } + final ItemStack itemStack; final ItemMeta itemMeta; @@ -161,7 +171,7 @@ public ItemBuilder hideUnbreakable() { * @return This ItemBuilder */ public ItemBuilder hidePotionEffects() { - itemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + itemMeta.addItemFlags(HIDE_POTIONS); return this; } From deecbbd0767666007404302349956338456be79c Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 16:59:39 -0800 Subject: [PATCH 4/6] Big updates for API - add a method to remove a machine - change a bunch of things from Furnace to Machine --- .../shanebeestudios/vf/VirtualFurnace.java | 1 - .../vf/api/FurnaceListener.java | 7 +- .../vf/api/FurnaceManager.java | 127 +++++++++++++----- .../vf/api/VirtualFurnaceAPI.java | 20 +-- .../{FurnaceTick.java => MachineTick.java} | 12 +- .../vf/command/FurnaceCommand.java | 30 ++--- 6 files changed, 125 insertions(+), 72 deletions(-) rename src/main/java/com/shanebeestudios/vf/api/task/{FurnaceTick.java => MachineTick.java} (80%) diff --git a/src/main/java/com/shanebeestudios/vf/VirtualFurnace.java b/src/main/java/com/shanebeestudios/vf/VirtualFurnace.java index e4f7c6d..77cfa67 100644 --- a/src/main/java/com/shanebeestudios/vf/VirtualFurnace.java +++ b/src/main/java/com/shanebeestudios/vf/VirtualFurnace.java @@ -6,7 +6,6 @@ import com.shanebeestudios.vf.api.VirtualFurnaceAPI; import com.shanebeestudios.vf.api.recipe.Fuel; import com.shanebeestudios.vf.api.recipe.FurnaceRecipe; -import com.shanebeestudios.vf.api.task.FurnaceTick; import com.shanebeestudios.vf.api.util.Util; import com.shanebeestudios.vf.command.FurnaceCommand; import org.bukkit.Bukkit; diff --git a/src/main/java/com/shanebeestudios/vf/api/FurnaceListener.java b/src/main/java/com/shanebeestudios/vf/api/FurnaceListener.java index 0ee3c59..8b6b8dd 100644 --- a/src/main/java/com/shanebeestudios/vf/api/FurnaceListener.java +++ b/src/main/java/com/shanebeestudios/vf/api/FurnaceListener.java @@ -3,6 +3,7 @@ import com.shanebeestudios.vf.api.chunk.VirtualChunk; import com.shanebeestudios.vf.api.event.machine.FurnaceExtractEvent; import com.shanebeestudios.vf.api.machine.Furnace; +import com.shanebeestudios.vf.api.machine.Machine; import com.shanebeestudios.vf.api.recipe.Fuel; import com.shanebeestudios.vf.api.tile.Tile; import org.bukkit.Chunk; @@ -40,10 +41,10 @@ private void onClickFurnace(PlayerInteractEvent event) { ItemStack hand = event.getItem(); Player player = event.getPlayer(); if (hand != null) { - Furnace furnace = this.furnaceManager.getFurnaceFromItemStack(hand); - if (furnace != null) { + Machine machine = this.furnaceManager.getMachineFromItemStack(hand); + if (machine != null) { event.setCancelled(true); - furnace.openInventory(player); + machine.openInventory(player); return; } } diff --git a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java index 6cc0fff..ed64b3d 100644 --- a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java +++ b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java @@ -1,6 +1,7 @@ package com.shanebeestudios.vf.api; import com.shanebeestudios.vf.api.machine.Furnace; +import com.shanebeestudios.vf.api.machine.Machine; import com.shanebeestudios.vf.api.property.FurnaceProperties; import com.shanebeestudios.vf.api.util.Util; import org.bukkit.Material; @@ -19,16 +20,18 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; import java.util.function.Consumer; /** - * Manager for {@link Furnace Furnaces} + * Manager for {@link Machine Machines} *

You can get an instance of this class from {@link VirtualFurnaceAPI#getFurnaceManager()}

*/ @SuppressWarnings({"unused", "UnusedReturnValue"}) @@ -41,35 +44,52 @@ public class FurnaceManager { private static final @NotNull Enchantment INFINITY = Registry.ENCHANTMENT.get(NamespacedKey.minecraft("infinity")); private final VirtualFurnaceAPI virtualFurnaceAPI; - private File furnaceFile; - private FileConfiguration furnaceConfig; - private final Map furnaceMap; + private File machineFile; + private FileConfiguration machineConfig; + private final Map machineMap; private final NamespacedKey key; FurnaceManager(VirtualFurnaceAPI virtualFurnaceAPI) { this.virtualFurnaceAPI = virtualFurnaceAPI; - this.furnaceMap = new HashMap<>(); + this.machineMap = new HashMap<>(); this.key = new NamespacedKey(virtualFurnaceAPI.getJavaPlugin(), "furnaceID"); loadFurnaceConfig(); } /** - * Get a collection of all {@link Furnace}s + * Get a collection of all {@link Furnace Furnaces} * * @return Collection of all furnaces + * @deprecated Use {@link #getAllMachines()} instead */ + @Deprecated public Collection getAllFurnaces() { - return Collections.unmodifiableCollection(this.furnaceMap.values()); + List furnaces = new ArrayList<>(); + for (Machine value : this.machineMap.values()) { + if (value instanceof Furnace furnace) { + furnaces.add(furnace); + } + } + return furnaces; + } + + /** + * Get a collection of all {@link Machine Machines} + * + * @return Collection of all machines + */ + public Collection getAllMachines() { + return Collections.unmodifiableCollection(this.machineMap.values()); } /** - * Get a {@link Furnace} by ID + * Get a {@link Machine} by ID * - * @param uuid ID of furnace to grab - * @return Furnace from ID (null if a furnace with this ID does not exist) + * @param uuid ID of machine to grab + * @return Machine from ID (null if a machine with this ID does not exist) */ - public Furnace getByID(@NotNull UUID uuid) { - return this.furnaceMap.get(uuid); + public Machine getByID(@NotNull UUID uuid) { + return this.machineMap.get(uuid); } /** @@ -123,7 +143,7 @@ public Furnace createFurnace(@NotNull String name, @NotNull FurnaceProperties fu if (function != null) { function.accept(furnace); } - this.furnaceMap.put(furnace.getUniqueID(), furnace); + this.machineMap.put(furnace.getUniqueID(), furnace); saveFurnace(furnace, true); return furnace; } @@ -238,12 +258,14 @@ public ItemStack createItemWithFurnace(@NotNull String name, @NotNull FurnacePro if (glowing) { if (HAS_GLINT) { meta.setEnchantmentGlintOverride(true); - } else if (item.getType() == Material.ARROW) { - meta.addEnchant(SHARPNESS, 1, true); } else { - meta.addEnchant(INFINITY, 1, true); + if (item.getType() == Material.ARROW) { + meta.addEnchant(SHARPNESS, 1, true); + } else { + meta.addEnchant(INFINITY, 1, true); + } + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); } Furnace furnace; if (function == null) { @@ -261,8 +283,27 @@ public ItemStack createItemWithFurnace(@NotNull String name, @NotNull FurnacePro * * @param itemStack ItemStack to grab furnace from * @return Furnace if the ItemStack has one assigned to it else null + * @deprecated Use {@link #getMachineFromItemStack(ItemStack)} instead */ + @Deprecated public Furnace getFurnaceFromItemStack(@NotNull ItemStack itemStack) { + ItemMeta meta = itemStack.getItemMeta(); + if (meta != null && meta.getPersistentDataContainer().has(this.key, PersistentDataType.STRING)) { + String u = meta.getPersistentDataContainer().get(this.key, PersistentDataType.STRING); + if (u == null) return null; + Machine machine = getByID(UUID.fromString(u)); + if (machine instanceof Furnace furnace) return furnace; + } + return null; + } + + /** + * Get a {@link Machine} from an {@link ItemStack} + * + * @param itemStack ItemStack to grab machine from + * @return Machine if the ItemStack has one assigned to it else null + */ + public Machine getMachineFromItemStack(@NotNull ItemStack itemStack) { ItemMeta meta = itemStack.getItemMeta(); if (meta != null && meta.getPersistentDataContainer().has(this.key, PersistentDataType.STRING)) { String u = meta.getPersistentDataContainer().get(this.key, PersistentDataType.STRING); @@ -273,64 +314,76 @@ public Furnace getFurnaceFromItemStack(@NotNull ItemStack itemStack) { } private void loadFurnaceConfig() { - if (this.furnaceFile == null) { - this.furnaceFile = new File(this.virtualFurnaceAPI.getJavaPlugin().getDataFolder(), "furnaces.yml"); + if (this.machineFile == null) { + this.machineFile = new File(this.virtualFurnaceAPI.getJavaPlugin().getDataFolder(), "furnaces.yml"); } - if (!furnaceFile.exists()) { + if (!machineFile.exists()) { this.virtualFurnaceAPI.getJavaPlugin().saveResource("furnaces.yml", false); } - this.furnaceConfig = YamlConfiguration.loadConfiguration(this.furnaceFile); + this.machineConfig = YamlConfiguration.loadConfiguration(this.machineFile); loadFurnaces(); } void loadFurnaces() { - ConfigurationSection section = this.furnaceConfig.getConfigurationSection("furnaces"); + ConfigurationSection section = this.machineConfig.getConfigurationSection("furnaces"); if (section != null) { for (String string : section.getKeys(true)) { if (section.get(string) instanceof Furnace furnace) { - this.furnaceMap.put(UUID.fromString(string), (Furnace) section.get(string)); + this.machineMap.put(UUID.fromString(string), furnace); } } } - Util.log("Loaded: &b" + this.furnaceMap.size() + "&7 furnaces"); + Util.log("Loaded: &b" + this.machineMap.size() + "&7 furnaces"); } /** - * Save a furnace to YAML storage + * Save a machine to YAML storage *

NOTE: If choosing not to save to file, this change will not take effect * in the YAML file, this may be useful for saving a large batch and saving file at the * end of the batch change, use {@link #saveConfig()} to save all changes to file

* - * @param furnace Furnace to save + * @param machine Machine to save * @param saveToFile Whether to save to file */ - public void saveFurnace(@NotNull Furnace furnace, boolean saveToFile) { - this.furnaceConfig.set("furnaces." + furnace.getUniqueID(), furnace); + public void saveFurnace(@NotNull Machine machine, boolean saveToFile) { + this.machineConfig.set("furnaces." + machine.getUniqueID(), machine); if (saveToFile) saveConfig(); } /** - * Remove a furnace from YAML storage + * Remove a machine from YAML storage *

NOTE: If choosing not to save to file, this change will not take effect - * in the YAML file, this may be useful it removing a large batch and saving file at the + * in the YAML file, this may be useful if removing a large batch and saving file at the * end of the batch change, use {@link #saveConfig()} to save all changes to file

* - * @param furnace Furnace to remove + * @param machine Machine to remove * @param saveToFile Whether to save changes to file */ - public void removeFurnaceFromConfig(@NotNull Furnace furnace, boolean saveToFile) { - this.furnaceConfig.set("furnaces." + furnace.getUniqueID(), null); + public void removeFurnaceFromConfig(@NotNull Machine machine, boolean saveToFile) { + this.machineConfig.set("furnaces." + machine.getUniqueID(), null); if (saveToFile) saveConfig(); } + /** + * Remove a {@link Machine} + *

This will remove from memory and from file (if saving is true) + * + * @param machine Machine to remove + * @param saveToFile Whether to save to file + */ + public void removeMachine(@NotNull Machine machine, boolean saveToFile) { + this.machineMap.remove(machine.getUniqueID()); + removeFurnaceFromConfig(machine, saveToFile); + } + /** * Save all furnaces to file */ public void saveAll() { - for (Furnace furnace : this.furnaceMap.values()) { - saveFurnace(furnace, false); + for (Machine machine : this.machineMap.values()) { + saveFurnace(machine, false); } saveConfig(); } @@ -341,7 +394,7 @@ public void saveAll() { @SuppressWarnings("CallToPrintStackTrace") public void saveConfig() { try { - furnaceConfig.save(furnaceFile); + machineConfig.save(machineFile); } catch (ConcurrentModificationException ignore) { // TODO figure out a proper way to handle this exception and figure out why its happening } catch (IOException e) { @@ -351,7 +404,7 @@ public void saveConfig() { void shutdown() { saveAll(); - furnaceMap.clear(); + machineMap.clear(); } } diff --git a/src/main/java/com/shanebeestudios/vf/api/VirtualFurnaceAPI.java b/src/main/java/com/shanebeestudios/vf/api/VirtualFurnaceAPI.java index 0699d42..b7a84fa 100644 --- a/src/main/java/com/shanebeestudios/vf/api/VirtualFurnaceAPI.java +++ b/src/main/java/com/shanebeestudios/vf/api/VirtualFurnaceAPI.java @@ -2,7 +2,7 @@ import com.shanebeestudios.vf.api.machine.Furnace; import com.shanebeestudios.vf.api.property.FurnaceProperties; -import com.shanebeestudios.vf.api.task.FurnaceTick; +import com.shanebeestudios.vf.api.task.MachineTick; import com.shanebeestudios.vf.api.task.TileTick; import com.shanebeestudios.vf.api.tile.FurnaceTile; import com.shanebeestudios.vf.api.util.Util; @@ -34,7 +34,7 @@ public class VirtualFurnaceAPI { private RecipeManager recipeManager; private FurnaceManager furnaceManager; private TileManager tileManager; - private FurnaceTick furnaceTick; + private MachineTick machineTick; private TileTick tileTick; /** @@ -62,7 +62,7 @@ public VirtualFurnaceAPI(@NotNull JavaPlugin javaPlugin, boolean disableMetrics) this.recipeManager = null; this.furnaceManager = null; this.tileManager = null; - this.furnaceTick = null; + this.machineTick = null; this.tileTick = null; Util.error("&cFailed to initialize VirtualFurnaceAPI"); Util.error("&7 - Bukkit version: &b" + Bukkit.getBukkitVersion() + " &7is not supported!"); @@ -76,8 +76,8 @@ public VirtualFurnaceAPI(@NotNull JavaPlugin javaPlugin, boolean disableMetrics) this.furnaceManager = new FurnaceManager(this); this.tileManager = new TileManager(this); this.tileManager.load(); - this.furnaceTick = new FurnaceTick(this); - this.furnaceTick.start(); + this.machineTick = new MachineTick(this); + this.machineTick.start(); this.tileTick = new TileTick(this); this.tileTick.start(); Bukkit.getPluginManager().registerEvents(new FurnaceListener(this), javaPlugin); @@ -90,9 +90,9 @@ public VirtualFurnaceAPI(@NotNull JavaPlugin javaPlugin, boolean disableMetrics) * This should be used in a plugin's {@link Plugin#onDisable() onDisable()} method

*/ public void disableAPI() { - this.furnaceTick.cancel(); + this.machineTick.cancel(); this.tileTick.cancel(); - this.furnaceTick = null; + this.machineTick = null; this.tileTick = null; this.furnaceManager.shutdown(); this.tileManager.shutdown(); @@ -107,7 +107,7 @@ public void disableAPI() { *

This is good to use in your onDisable() method, to prevent tasks still running on server shutdown/reload

*/ public void disableFurnaceTick() { - this.furnaceTick.cancel(); + this.machineTick.cancel(); } /** @@ -161,8 +161,8 @@ public TileManager getTileManager() { * * @return Instance of furnace tick */ - public FurnaceTick getFurnaceTick() { - return furnaceTick; + public MachineTick getFurnaceTick() { + return machineTick; } /** diff --git a/src/main/java/com/shanebeestudios/vf/api/task/FurnaceTick.java b/src/main/java/com/shanebeestudios/vf/api/task/MachineTick.java similarity index 80% rename from src/main/java/com/shanebeestudios/vf/api/task/FurnaceTick.java rename to src/main/java/com/shanebeestudios/vf/api/task/MachineTick.java index 6347a24..584d52f 100644 --- a/src/main/java/com/shanebeestudios/vf/api/task/FurnaceTick.java +++ b/src/main/java/com/shanebeestudios/vf/api/task/MachineTick.java @@ -2,15 +2,15 @@ import com.shanebeestudios.vf.api.FurnaceManager; import com.shanebeestudios.vf.api.VirtualFurnaceAPI; -import com.shanebeestudios.vf.api.machine.Furnace; +import com.shanebeestudios.vf.api.machine.Machine; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; /** - * Timer for ticking furnaces + * Timer for ticking {@link Machine Machines} */ -public class FurnaceTick extends BukkitRunnable { +public class MachineTick extends BukkitRunnable { private final FurnaceManager furnaceManager; private final VirtualFurnaceAPI virtualFurnaceAPI; @@ -18,7 +18,7 @@ public class FurnaceTick extends BukkitRunnable { private int id; private boolean running; - public FurnaceTick(VirtualFurnaceAPI virtualFurnaceAPI) { + public MachineTick(VirtualFurnaceAPI virtualFurnaceAPI) { this.virtualFurnaceAPI = virtualFurnaceAPI; this.furnaceManager = virtualFurnaceAPI.getFurnaceManager(); this.tick = 0; @@ -33,11 +33,11 @@ public void start() { public void run() { running = true; try { - for (Furnace furnace : furnaceManager.getAllFurnaces()) { + for (Machine machine : furnaceManager.getAllMachines()) { if (!running) { return; } - furnace.tick(); + machine.tick(); } } catch (Exception ignore) { } diff --git a/src/main/java/com/shanebeestudios/vf/command/FurnaceCommand.java b/src/main/java/com/shanebeestudios/vf/command/FurnaceCommand.java index ea68f3f..dbdd406 100644 --- a/src/main/java/com/shanebeestudios/vf/command/FurnaceCommand.java +++ b/src/main/java/com/shanebeestudios/vf/command/FurnaceCommand.java @@ -1,11 +1,13 @@ package com.shanebeestudios.vf.command; -import com.shanebeestudios.vf.api.FurnaceManager; import com.shanebeestudios.vf.VirtualFurnace; +import com.shanebeestudios.vf.api.FurnaceManager; import com.shanebeestudios.vf.api.TileManager; +import com.shanebeestudios.vf.api.machine.Furnace; +import com.shanebeestudios.vf.api.machine.Machine; import com.shanebeestudios.vf.api.property.FurnaceProperties; -import com.shanebeestudios.vf.debug.Debug; import com.shanebeestudios.vf.api.util.Util; +import com.shanebeestudios.vf.debug.Debug; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -16,7 +18,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -import com.shanebeestudios.vf.api.machine.Furnace; import java.util.UUID; @@ -34,8 +35,7 @@ public FurnaceCommand(VirtualFurnace plugin) { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) { - if (sender instanceof Player) { - Player player = ((Player) sender); + if (sender instanceof Player player) { if (args.length >= 1) { switch (args[0]) { case "new": @@ -51,14 +51,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N case "open": if (args.length == 2) { UUID uuid = UUID.fromString(args[1]); - Furnace furnace1 = this.furnaceManager.getByID(uuid); - if (furnace1 != null) { - furnace1.openInventory(player); + Machine machine = this.furnaceManager.getByID(uuid); + if (machine != null) { + machine.openInventory(player); } else { player.sendMessage("FURNACE NOT FOUND!"); } } else { - sender.sendMessage("Please enter an ID of a furnace to open"); + sender.sendMessage("Please enter an ID of a machine to open"); } break; case "item": @@ -82,7 +82,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N assert smokerMeta != null; smokerMeta.setDisplayName(Util.getColString(smokerName)); smokerItem.setItemMeta(smokerMeta); - player.getInventory().addItem(this.furnaceManager.createItemWithFurnace(smokerName, FurnaceProperties.SMOKER,smokerItem, true)); + player.getInventory().addItem(this.furnaceManager.createItemWithFurnace(smokerName, FurnaceProperties.SMOKER, smokerItem, true)); ItemStack fastItem = new ItemStack(Material.BLAST_FURNACE); String fastName = "&6Fast Food"; @@ -102,9 +102,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N break; case "id": ItemStack item = player.getInventory().getItemInMainHand(); - Furnace furnace = this.furnaceManager.getFurnaceFromItemStack(item); - if (furnace != null) { - player.sendMessage("Portable furnace ID: " + furnace.getUniqueID().toString()); + Machine machine = this.furnaceManager.getMachineFromItemStack(item); + if (machine != null) { + player.sendMessage("Portable machine ID: " + machine.getUniqueID().toString()); } else { player.sendMessage("This item has no ID!"); } @@ -129,14 +129,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N debug.loadDebugTiles(amount); break; case "check": - int furnaces = furnaceManager.getAllFurnaces().size(); + int machines = furnaceManager.getAllMachines().size(); int tiles = tileManager.getAllTiles().size(); int chunks = tileManager.getChunks().size(); int loadedChunks = tileManager.getLoadedChunks().size(); Util.log("&dCheck:"); Util.log(" - Chunks: &b" + loadedChunks + "/" + chunks); Util.log(" - Tiles: &a" + tiles); - Util.log(" - Furnaces: &c" + furnaces); + Util.log(" - Machines: &c" + machines); } } From d8352184bb07de7a20351fc00a888b60df54f66f Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 17:02:35 -0800 Subject: [PATCH 5/6] gradle.yml - update java version --- .github/workflows/gradle.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1e5f34e..69fd595 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,9 +9,9 @@ name: Java CI with Gradle on: push: - branches: ['**'] + branches: [ '**' ] pull_request: - branches: ['**'] + branches: [ '**' ] permissions: contents: read @@ -23,17 +23,17 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 + - name: Set up JDK 21 + uses: actions/setup-java@v4.2.1 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Build with Gradle - uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 + uses: gradle/actions/setup-gradle@v3 with: arguments: build - name: Upload a Build Artifact - uses: actions/upload-artifact@v3.1.2 + uses: actions/upload-artifact@master with: # Artifact name name: VirtualFurnace-Artifact From 7e7ee473d4bddc2533772fb1177febfcffb0d1b4 Mon Sep 17 00:00:00 2001 From: ShaneBeee Date: Thu, 26 Dec 2024 17:05:22 -0800 Subject: [PATCH 6/6] Prepare for release of 1.1.0 --- build.gradle | 2 +- src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 5b675fe..141c435 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ compileJava { } // VirtualFurnace version -version = '1.0.0' +version = '1.1.0' def oldestJava = 17 repositories { diff --git a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java index ed64b3d..fa3de3d 100644 --- a/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java +++ b/src/main/java/com/shanebeestudios/vf/api/FurnaceManager.java @@ -62,7 +62,7 @@ public class FurnaceManager { * @return Collection of all furnaces * @deprecated Use {@link #getAllMachines()} instead */ - @Deprecated + @Deprecated(since = "1.1.0") public Collection getAllFurnaces() { List furnaces = new ArrayList<>(); for (Machine value : this.machineMap.values()) { @@ -285,7 +285,7 @@ public ItemStack createItemWithFurnace(@NotNull String name, @NotNull FurnacePro * @return Furnace if the ItemStack has one assigned to it else null * @deprecated Use {@link #getMachineFromItemStack(ItemStack)} instead */ - @Deprecated + @Deprecated(since = "1.1.0") public Furnace getFurnaceFromItemStack(@NotNull ItemStack itemStack) { ItemMeta meta = itemStack.getItemMeta(); if (meta != null && meta.getPersistentDataContainer().has(this.key, PersistentDataType.STRING)) {