Fixes, added opening on inventory open event, added really really really ugly way to be able to put ingredients in any order
This commit is contained in:
1 parent
57b5cfdb22
commit
b054264e65
5 files changed
+115
-56
No files matched your search
@@ -2,7 +2,6 @@ package com.artillexstudios.axsmithing;
|
||||
|
||||
import com.artillexstudios.axsmithing.command.AxSmithingCommand;
|
||||
import com.artillexstudios.axsmithing.command.AxSmithingTabComplete;
|
||||
import com.artillexstudios.axsmithing.dependency.DependencyManager;
|
||||
import com.artillexstudios.axsmithing.gui.SmithingTable;
|
||||
import com.artillexstudios.axsmithing.gui.impl.SmithingTable_V1_16;
|
||||
import com.artillexstudios.axsmithing.gui.impl.SmithingTable_V1_20;
|
||||
|
||||
@@ -165,26 +165,36 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
ItemStack finalAddition = addition;
|
||||
ItemStack finalBase = base;
|
||||
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
inv.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
Recipe recipe = recipeIterator.next();
|
||||
boolean successful = checkRecipe(inv, finalBase, finalAddition);
|
||||
|
||||
if (recipe instanceof SmithingRecipe smithingRecipe) {
|
||||
boolean test1 = smithingRecipe.getBase().getItemStack().getType() == finalBase.getType();
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
boolean test2 = smithingRecipe.getAddition().getItemStack().getType() == finalAddition.getType();
|
||||
|
||||
if (test1 && test2) {
|
||||
ItemStack item = smithingRecipe.getResult();
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inv.setItem(outputSlot, item);
|
||||
break;
|
||||
} else {
|
||||
inv.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
if (!successful) {
|
||||
checkRecipe(inv, finalAddition, finalBase);
|
||||
}
|
||||
}, 0L);
|
||||
}
|
||||
|
||||
private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) {
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
Recipe recipe = recipeIterator.next();
|
||||
|
||||
if (recipe instanceof SmithingRecipe smithingRecipe) {
|
||||
boolean test1 = smithingRecipe.getBase().test(finalBase);
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
boolean test2 = smithingRecipe.getAddition().test(finalAddition);
|
||||
|
||||
if (test1 && test2) {
|
||||
ItemStack item = smithingRecipe.getResult();
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
} else {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,8 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
} else {
|
||||
event.getInventory().getItem(templateSlot).setAmount(amount);
|
||||
}
|
||||
|
||||
((Player) event.getWhoClicked()).updateInventory();
|
||||
}
|
||||
|
||||
if (event.getInventory().getItem(itemSlot) != null) {
|
||||
@@ -104,6 +106,8 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
} else {
|
||||
event.getInventory().getItem(itemSlot).setAmount(amount);
|
||||
}
|
||||
|
||||
((Player) event.getWhoClicked()).updateInventory();
|
||||
}
|
||||
|
||||
if (event.getInventory().getItem(upgradeSlot) != null) {
|
||||
@@ -113,6 +117,8 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
} else {
|
||||
event.getInventory().getItem(upgradeSlot).setAmount(amount);
|
||||
}
|
||||
|
||||
((Player) event.getWhoClicked()).updateInventory();
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -198,50 +204,73 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
ItemStack finalAddition = addition;
|
||||
ItemStack finalBase = base;
|
||||
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
inv.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
Recipe recipe = recipeIterator.next();
|
||||
// Very very very ugly solution, but I guess, it works!
|
||||
boolean successful = checkRecipe(inv, finalBase, finalAddition, finalTemplate);
|
||||
if (!successful) {
|
||||
successful = checkRecipe(inv, finalBase, finalTemplate, finalAddition);
|
||||
}
|
||||
if (!successful) {
|
||||
successful = checkRecipe(inv, finalTemplate, finalBase, finalAddition);
|
||||
}
|
||||
if (!successful) {
|
||||
successful = checkRecipe(inv, finalTemplate, finalAddition, finalBase);
|
||||
}
|
||||
if (!successful) {
|
||||
successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate);
|
||||
}
|
||||
if (!successful) {
|
||||
checkRecipe(inv, finalAddition, finalTemplate, finalBase);
|
||||
}
|
||||
|
||||
if (recipe instanceof SmithingTrimRecipe trimRecipe) {
|
||||
boolean test1 = trimRecipe.getTemplate().test(finalTemplate);
|
||||
boolean test2 = trimRecipe.getBase().test(finalBase);
|
||||
boolean test3 = trimRecipe.getAddition().test(finalAddition);
|
||||
}, 0L);
|
||||
}
|
||||
|
||||
if (test1 && test2 && test3) {
|
||||
ItemStack clone = finalBase.clone();
|
||||
ItemMeta meta = clone.getItemMeta();
|
||||
if (meta instanceof ArmorMeta armorMeta) {
|
||||
ArmorTrim trim = armorTrim(finalAddition, finalTemplate);
|
||||
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
Recipe recipe = recipeIterator.next();
|
||||
|
||||
armorMeta.setTrim(trim);
|
||||
clone.setItemMeta(armorMeta);
|
||||
}
|
||||
if (recipe instanceof SmithingTrimRecipe trimRecipe) {
|
||||
boolean test1 = trimRecipe.getTemplate().test(finalTemplate);
|
||||
boolean test2 = trimRecipe.getBase().test(finalBase);
|
||||
boolean test3 = trimRecipe.getAddition().test(finalAddition);
|
||||
|
||||
inv.setItem(outputSlot, clone);
|
||||
break;
|
||||
} else {
|
||||
inv.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
if (test1 && test2 && test3) {
|
||||
ItemStack clone = finalBase.clone();
|
||||
ItemMeta meta = clone.getItemMeta();
|
||||
if (meta instanceof ArmorMeta armorMeta) {
|
||||
ArmorTrim trim = armorTrim(finalAddition, finalTemplate);
|
||||
|
||||
armorMeta.setTrim(trim);
|
||||
clone.setItemMeta(armorMeta);
|
||||
}
|
||||
}
|
||||
|
||||
if (recipe instanceof SmithingTransformRecipe transformRecipe) {
|
||||
boolean test1 = transformRecipe.getTemplate().getItemStack().getType() == finalTemplate.getType();
|
||||
boolean test2 = transformRecipe.getBase().getItemStack().getType() == finalBase.getType();
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
boolean test3 = transformRecipe.getAddition().getItemStack().getType() == finalAddition.getType();
|
||||
|
||||
if (test1 && test2 && test3) {
|
||||
ItemStack item = transformRecipe.getResult();
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inv.setItem(outputSlot, item);
|
||||
break;
|
||||
} else {
|
||||
inv.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
inventory.setItem(outputSlot, clone);
|
||||
return true;
|
||||
} else {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}, 0L);
|
||||
|
||||
if (recipe instanceof SmithingTransformRecipe transformRecipe) {
|
||||
boolean test1 = transformRecipe.getTemplate().test(finalTemplate);
|
||||
boolean test2 = transformRecipe.getBase().test(finalBase);
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
boolean test3 = transformRecipe.getAddition().test(finalAddition);
|
||||
|
||||
if (test1 && test2 && test3) {
|
||||
ItemStack item = transformRecipe.getResult();
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
} else {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -5,10 +5,13 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -36,4 +39,22 @@ public class InteractListener implements Listener {
|
||||
event.getPlayer().closeInventory();
|
||||
AxSmithingPlugin.getSmithingTableImpl().open(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpenEvent(@NotNull final InventoryOpenEvent event) {
|
||||
if (event.getInventory().getType() != InventoryType.SMITHING) return;
|
||||
|
||||
if (AxSmithingPlugin.is1_20()) {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= ProtocolVersion.v1_20.getVersion() && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != ProtocolVersion.v1_20.getVersion()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.getPlayer().closeInventory();
|
||||
AxSmithingPlugin.getSmithingTableImpl().open((Player) event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class ItemBuilder {
|
||||
replacements.forEach((key, value) -> message.set(message.get().replace(key, value)));
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(StringUtils.format(String.valueOf(message)));
|
||||
meta.setDisplayName(StringUtils.format(message.get()));
|
||||
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user