diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b2b2e85..c2ae7cb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,14 @@ - + + + + + + + + + + @@ -28,6 +38,7 @@ + @@ -50,29 +61,29 @@ - + - - + + - - + + - - + + - - + + - - + + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index a44b0bd..2d42108 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,12 @@ 1.16.1-R0.1-SNAPSHOT provided + + org.jetbrains + annotations + RELEASE + compile + diff --git a/src/main/java/dev/coomware/Chainmail.java b/src/main/java/dev/coomware/Chainmail.java index bc69f70..5b0498e 100644 --- a/src/main/java/dev/coomware/Chainmail.java +++ b/src/main/java/dev/coomware/Chainmail.java @@ -3,13 +3,24 @@ package dev.coomware; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.Server; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.plugin.java.JavaPlugin; public class Chainmail extends JavaPlugin { + public static Chainmail plugin; + public Server server; + + @Override + public void onLoad() { + plugin = this; + server = getServer(); + } + @Override public void onEnable() { + new CheaperChains(this); newRecipes(); Bukkit.getLogger().info("Successfully added new recipes for chainmail armor."); Bukkit.getLogger().info("This plugin was made by CoomWare."); @@ -23,9 +34,11 @@ public class Chainmail extends JavaPlugin { private void newRecipes() { //New namespaced keys for identification for each new recipe. NamespacedKey key1 = new NamespacedKey(this, "chain_helmet_recipe"); + NamespacedKey key1a = new NamespacedKey(this, "chain_helmet_alternate"); NamespacedKey key2 = new NamespacedKey(this, "chaim_chest_recipe"); NamespacedKey key3 = new NamespacedKey(this, "chain_pants_recipe"); NamespacedKey key4 = new NamespacedKey(this, "chain_boots_recipe"); + NamespacedKey key4a = new NamespacedKey(this, "chain_boots_alternate"); //Define the final item to create ItemStack helmet = new ItemStack(Material.CHAINMAIL_HELMET); @@ -35,19 +48,25 @@ public class Chainmail extends JavaPlugin { //Initialize new recipe instances ShapedRecipe chelm = new ShapedRecipe(key1, helmet); + ShapedRecipe chelmA = new ShapedRecipe(key1a, helmet); ShapedRecipe cchest = new ShapedRecipe(key2, chest); ShapedRecipe cpants = new ShapedRecipe(key3, pants); ShapedRecipe cboots = new ShapedRecipe(key4, boots); + ShapedRecipe cbootsA = new ShapedRecipe(key4a, boots); //Define the shape of the recipes chelm.shape("ccc","cac","aaa"); + chelmA.shape("aaa","ccc","cac"); cchest.shape("cac","ccc","ccc"); cpants.shape("ccc","cac","cac"); cboots.shape("aaa","cac","cac"); + cbootsA.shape("cac","cac","aaa"); //Helmet chelm.setIngredient('c', Material.CHAIN); chelm.setIngredient('a', Material.AIR); + chelmA.setIngredient('c', Material.CHAIN); + chelmA.setIngredient('a', Material.AIR); //Chestplate cchest.setIngredient('c', Material.CHAIN); cchest.setIngredient('a', Material.AIR); @@ -57,11 +76,15 @@ public class Chainmail extends JavaPlugin { //Boots cboots.setIngredient('c', Material.CHAIN); cboots.setIngredient('a', Material.AIR); + cbootsA.setIngredient('c', Material.CHAIN); + cbootsA.setIngredient('a', Material.AIR); //Add all the new recipes to the server :) - getServer().addRecipe(chelm); - getServer().addRecipe(cchest); - getServer().addRecipe(cpants); - getServer().addRecipe(cboots); + server.addRecipe(chelm); + server.addRecipe(chelmA); + server.addRecipe(cchest); + server.addRecipe(cpants); + server.addRecipe(cboots); + server.addRecipe(cbootsA); } } diff --git a/src/main/java/dev/coomware/CheaperChains.java b/src/main/java/dev/coomware/CheaperChains.java new file mode 100644 index 0000000..370de70 --- /dev/null +++ b/src/main/java/dev/coomware/CheaperChains.java @@ -0,0 +1,33 @@ +package dev.coomware; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.inventory.Recipe; +import org.jetbrains.annotations.NotNull; + +public class CheaperChains implements Listener { + //Initializer + public CheaperChains(@NotNull Chainmail plugin) { + plugin.server.getPluginManager().registerEvents(this, plugin); + } + + //This event priority should make the condition guaranteed + @EventHandler(priority = EventPriority.HIGHEST) + public void chainCraftEvent(@NotNull PrepareItemCraftEvent e) { + //Check to make sure the return value isn't just a repaired item + if (e.isRepair()) { return; } + + final Recipe recipe = e.getRecipe(); + + //Check to make sure the recipe actually exists + if (recipe == null) { return; } + + //If the result of the recipe is chains, set the amount to give to 3 + if (recipe.getResult().getType() == Material.CHAIN) { + recipe.getResult().setAmount(3); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7ce2557..b12a29f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Chainmail main: dev.coomware.Chainmail -version: 1.0.0-FINAL +version: 1.1.0 description: Plugin which adds a recipe for chainmail armor using chains. author: CoomWare api-version: 1.16 \ No newline at end of file diff --git a/target/Chainmail.jar b/target/Chainmail.jar index 11920b1..c7e9a74 100644 Binary files a/target/Chainmail.jar and b/target/Chainmail.jar differ diff --git a/target/classes/dev/coomware/Chainmail.class b/target/classes/dev/coomware/Chainmail.class index 26b9901..8784587 100644 Binary files a/target/classes/dev/coomware/Chainmail.class and b/target/classes/dev/coomware/Chainmail.class differ diff --git a/target/classes/dev/coomware/CheaperChains.class b/target/classes/dev/coomware/CheaperChains.class new file mode 100644 index 0000000..473a7f9 Binary files /dev/null and b/target/classes/dev/coomware/CheaperChains.class differ diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 7ce2557..b12a29f 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,6 +1,6 @@ name: Chainmail main: dev.coomware.Chainmail -version: 1.0.0-FINAL +version: 1.1.0 description: Plugin which adds a recipe for chainmail armor using chains. author: CoomWare api-version: 1.16 \ No newline at end of file diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 63f1324..0e7e51e 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1 +1,2 @@ dev\coomware\Chainmail.class +dev\coomware\CheaperChains.class