From c0917a1ab637ebe09cadaa12785f8aeeaf6d1d45 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 10 May 2021 11:58:37 +0200 Subject: [PATCH] Switched to proper Crafting-mechanics --- .../ruakij/LinkedBeaconTeleporters/Main.java | 4 +-- .../LinkedBeaconTeleporterItem.java | 4 +-- .../LinkedBeaconTeleporterManager.java | 33 +++++++++++++++-- .../listener/OnCraftItemEvent.java | 27 ++++++++++++++ .../listener/OnPrepareItemCraftEvent.java | 36 ------------------- .../listener/OnCraftItemEvent.java | 29 +++++++++++++++ .../listener/OnPrepareItemCraftEvent.java | 31 ---------------- 7 files changed, 90 insertions(+), 74 deletions(-) create mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnCraftItemEvent.java delete mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java create mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCraftItemEvent.java delete mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnPrepareItemCraftEvent.java diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java index 0c6b8d7..9d3739f 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java @@ -3,7 +3,7 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager; import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnBlockBreak; import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnBlockPlace; -import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnPrepareItemCraftEvent; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.listener.OnCraftItemEvent; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -33,7 +33,7 @@ public class Main extends JavaPlugin { PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.registerEvents(new OnBlockBreak(), this); pluginManager.registerEvents(new OnBlockPlace(), this); - pluginManager.registerEvents(new OnPrepareItemCraftEvent(), this); + pluginManager.registerEvents(new OnCraftItemEvent(), this); loadConfigs(); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java index ebbf75b..f57fe1c 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java @@ -17,7 +17,7 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { // Create a new LinkedBeaconTeleporter super(); - this.item = Main.lbtManager.getItemStackFromLbtItem(this); + this.item = Main.lbtManager.getItemStackFromData(this.teleporterId); } public LinkedBeaconTeleporterItem(String teleporterId, ItemStack item) { super(teleporterId); @@ -27,7 +27,7 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { public LinkedBeaconTeleporterItem(String teleporterId){ super(teleporterId); - this.item = Main.lbtManager.getItemStackFromLbtItem(this); + this.item = Main.lbtManager.getItemStackFromData(teleporterId); } public ItemStack item(){ diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java index f6d6afc..16dd218 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -2,11 +2,14 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Function; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; import java.util.*; @@ -31,6 +34,9 @@ public class LinkedBeaconTeleporterManager { Main.config.getStringList("item.lore") ); + // Construct & add crafting-receipes + constructAndAddRecipes(); + // Load teleporters for(String teleporterId : Main.data.getKeys(false)){ ConfigurationSection teleportersData = Main.data.getConfigurationSection(teleporterId); @@ -116,8 +122,29 @@ public class LinkedBeaconTeleporterManager { return lbtItem; } + void constructAndAddRecipes(){ + // Create result-item + ItemStack item = getItemStackFromData("-"); + item.setAmount(2); + + // Create recipe + ShapelessRecipe recipe = new ShapelessRecipe( + new NamespacedKey(Main.plugin, "linked_beacon_teleporter") + , item); + recipe.addIngredient(2, Material.BEACON); + Bukkit.addRecipe(recipe); + + // Empty recipe to reset beacon + ShapelessRecipe recipe2 = new ShapelessRecipe( + new NamespacedKey(Main.plugin, "linked_beacon_teleporter_reset"), + new ItemStack(Material.BEACON) + ); + recipe2.addIngredient(1, Material.BEACON); + Bukkit.addRecipe(recipe2); + } + // Conversion-methods - public ItemStack getItemStackFromLbtItem(LinkedBeaconTeleporterItem lbtItem){ + public ItemStack getItemStackFromData(String teleporterId){ ItemStack item = new ItemStack(Material.BEACON); ItemMeta itemMeta = item.getItemMeta(); @@ -126,10 +153,10 @@ public class LinkedBeaconTeleporterManager { List lore = Main.config.getStringList("item.lore"); // Replace parameters - name = name.replace("%id%", lbtItem.teleporterId); + name = name.replace("%id%", teleporterId); for(int i=0; i