9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-28 03:19:25 +00:00

Fixed armor set crafting

This commit is contained in:
Auxilor
2021-01-20 18:04:57 +00:00
parent a231b74c20
commit 9fe3cbd53a
7 changed files with 65 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ import com.willfp.ecoarmor.sets.util.PotionEffectListener;
import com.willfp.ecoarmor.upgrades.advanced.AdvancementShardListener;
import com.willfp.ecoarmor.upgrades.crystal.CrystalListener;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import com.willfp.ecoarmor.util.DiscoverRecipeListener;
import lombok.Getter;
import org.bukkit.event.Listener;
@@ -132,7 +133,8 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
new CrystalListener(this),
new AdvancementShardListener(this),
new PotionEffectListener(this),
new EffectiveDurabilityListener(this)
new EffectiveDurabilityListener(this),
new DiscoverRecipeListener(this)
);
}

View File

@@ -235,13 +235,14 @@ public class ArmorSet {
}
itemStack.setItemMeta(meta);
RecipePartUtils.registerLookup("ecoarmor:set_" + name.toLowerCase() + "_" + pieceName, s -> new ComplexRecipePart(test -> {
if (ArmorSlot.getSlot(test) != ArmorSlot.getSlot(itemStack)) {
return false;
}
return Objects.equals(this, ArmorUtils.getSetOnItem(test));
}, itemStack));
if (!advanced) {
RecipePartUtils.registerLookup("ecoarmor:set_" + name.toLowerCase() + "_" + pieceName, s -> new ComplexRecipePart(test -> {
if (ArmorSlot.getSlot(test) != ArmorSlot.getSlot(itemStack)) {
return false;
}
return Objects.equals(this, ArmorUtils.getSetOnItem(test));
}, itemStack));
}
constructRecipe(slot, itemStack);

View File

@@ -50,7 +50,11 @@ public enum ArmorSlot {
* @return The slot, or null.
*/
@Nullable
public static ArmorSlot getSlot(@NotNull final ItemStack itemStack) {
public static ArmorSlot getSlot(@Nullable final ItemStack itemStack) {
if (itemStack == null) {
return null;
}
Material material = itemStack.getType();
String name = material.name().toLowerCase();

View File

@@ -74,7 +74,7 @@ public class AdvancementShardListener extends PluginDependent implements Listene
ArmorUtils.setAdvanced(current, true);
event.getWhoClicked().setItemOnCursor(null);
event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR));
event.setCancelled(true);
}

View File

@@ -66,7 +66,7 @@ public class CrystalListener extends PluginDependent implements Listener {
ArmorUtils.setTier(current, tier);
event.getWhoClicked().setItemOnCursor(null);
event.getWhoClicked().setItemOnCursor(new ItemStack(Material.AIR));
event.setCancelled(true);
}

View File

@@ -0,0 +1,46 @@
package com.willfp.ecoarmor.util;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
public class DiscoverRecipeListener extends PluginDependent implements Listener {
/**
* Register listener.
*
* @param plugin Talismans.
*/
public DiscoverRecipeListener(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Unlock all recipes on player join.
*
* @param event The event to listen for.
*/
@EventHandler
public void onJoin(@NotNull final PlayerJoinEvent event) {
Player player = event.getPlayer();
if (this.getPlugin().getConfigYml().getBool("discover-recipes")) {
Bukkit.getServer().recipeIterator().forEachRemaining(recipe -> {
if (recipe instanceof ShapedRecipe) {
NamespacedKey key = ((ShapedRecipe) recipe).getKey();
if (key.getNamespace().equals("ecoarmor")) {
if (!key.getKey().contains("displayed")) {
player.discoverRecipe(key);
}
}
}
});
}
}
}

View File

@@ -3,6 +3,7 @@
# by Auxilor
#
discover-recipes: true # If all recipes should be automatically discovered.
# Effects are passive abilities that happen when wearing a full set with the effect present.
effects: