Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39d0e36e72 | ||
|
|
f5bdb77c0e | ||
|
|
b06b4e7156 | ||
|
|
05c131cbff | ||
|
|
e3b71c2141 | ||
|
|
7c52af372f | ||
|
|
2b51eef478 |
No files matched your search
+2
-3
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axsmithing'
|
||||
version = '1.4'
|
||||
version = '1.7'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -28,7 +28,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation 'net.byteflux:libby-bukkit:1.2.0'
|
||||
implementation 'com.artillexstudios.axapi:axapi:1.4.10'
|
||||
implementation 'com.artillexstudios.axapi:axapi:1.4.39'
|
||||
implementation 'org.bstats:bstats-bukkit:3.0.2'
|
||||
compileOnly 'com.google.code.gson:gson:2.10.1'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT'
|
||||
@@ -50,7 +50,6 @@ shadowJar {
|
||||
relocate("net.byteflux.libby", "com.artillexstudios.axsmithing.libs.libby")
|
||||
relocate("org.bstats", "com.artillexstudios.axsmithing.libs.bstats")
|
||||
relocate("com.artillexstudios.axapi", "com.artillexstudios.axsmithing.libs.axapi")
|
||||
minimize()
|
||||
}
|
||||
|
||||
build {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.artillexstudios.axsmithing.utils.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
@@ -195,7 +196,7 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
addition = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
if (base == null || addition.getType().isAir()) {
|
||||
if (base == null || base.getType().isAir()) {
|
||||
base = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
@@ -210,16 +211,13 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
boolean successful = checkRecipe(inv, finalBase, finalAddition);
|
||||
|
||||
if (!successful) {
|
||||
checkRecipe(inv, finalAddition, finalBase);
|
||||
successful = checkRecipe(inv, finalAddition, finalBase);
|
||||
}
|
||||
|
||||
return successful;
|
||||
}
|
||||
|
||||
private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) {
|
||||
if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
|
||||
@@ -247,6 +245,12 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ItemStack it;
|
||||
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
|
||||
@@ -108,7 +108,6 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_20)) return;
|
||||
|
||||
if ((event.getSlot() == upgradeSlot || event.getSlot() == itemSlot || event.getSlot() == templateSlot) && event.getInventory().getItem(outputSlot) != null) {
|
||||
event.getInventory().setItem(outputSlot, null);
|
||||
if (checkRecipes(event.getInventory(), event.getInventory().getItem(templateSlot), event.getInventory().getItem(itemSlot), event.getInventory().getItem(upgradeSlot))) {
|
||||
event.getInventory().setItem(outputSlot, null);
|
||||
}
|
||||
@@ -234,15 +233,21 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
addition = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
if (base == null || addition.getType().isAir()) {
|
||||
if (base == null || base.getType().isAir()) {
|
||||
base = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
if (template == null || addition.getType().isAir()) {
|
||||
if (!needNetheriteTemplate) {
|
||||
if (template == null || template.getType().isAir()) {
|
||||
template = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
if (!needNetheriteTemplate && !hasTemplate(addition, base, template)) {
|
||||
if (template.getType().isAir()) {
|
||||
template = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
|
||||
} else {
|
||||
template = new ItemStack(Material.AIR);
|
||||
} else if (base.getType().isAir()) {
|
||||
base = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
|
||||
} else if (addition.getType().isAir()) {
|
||||
addition = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,21 +275,43 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate);
|
||||
}
|
||||
if (!successful) {
|
||||
checkRecipe(inv, finalAddition, finalTemplate, finalBase);
|
||||
successful = checkRecipe(inv, finalAddition, finalTemplate, finalBase);
|
||||
}
|
||||
|
||||
return successful;
|
||||
}
|
||||
|
||||
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
|
||||
if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) {
|
||||
return false;
|
||||
private boolean hasTemplate(ItemStack item1, ItemStack item2, ItemStack item3) {
|
||||
if (isTemplate(item1)) {
|
||||
return true;
|
||||
} else if (isTemplate(item2)) {
|
||||
return true;
|
||||
} else {
|
||||
return isTemplate(item3);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTemplate(ItemStack item) {
|
||||
return switch (item.getType()) {
|
||||
case COAST_ARMOR_TRIM_SMITHING_TEMPLATE, SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, EYE_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, HOST_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
RIB_ARMOR_TRIM_SMITHING_TEMPLATE, SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, TIDE_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
VEX_ARMOR_TRIM_SMITHING_TEMPLATE, WARD_ARMOR_TRIM_SMITHING_TEMPLATE,
|
||||
WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE, NETHERITE_UPGRADE_SMITHING_TEMPLATE -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
Recipe recipe = recipeIterator.next();
|
||||
|
||||
if (recipe instanceof SmithingTrimRecipe trimRecipe) {
|
||||
if (finalBase == null || finalAddition == null || finalTemplate == null) return false;
|
||||
boolean test1 = trimRecipe.getTemplate().test(finalTemplate);
|
||||
boolean test2 = trimRecipe.getBase().test(finalBase);
|
||||
boolean test3 = trimRecipe.getAddition().test(finalAddition);
|
||||
@@ -299,6 +326,11 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
clone.setItemMeta(armorMeta);
|
||||
}
|
||||
|
||||
ItemStack it;
|
||||
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == clone.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inventory.setItem(outputSlot, clone);
|
||||
return true;
|
||||
} else {
|
||||
@@ -329,6 +361,12 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack it;
|
||||
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
|
||||
@@ -4,15 +4,43 @@ import com.artillexstudios.axapi.scheduler.Scheduler;
|
||||
import com.artillexstudios.axapi.utils.Version;
|
||||
import com.artillexstudios.axsmithing.AxSmithingPlugin;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
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;
|
||||
|
||||
public class InteractListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEvent(@NotNull final PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) return;
|
||||
if (event.getClickedBlock().getType() != Material.SMITHING_TABLE) return;
|
||||
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return;
|
||||
if (!AxSmithingPlugin.getConfiguration().getBoolean("listen-to-interact-event")) return;
|
||||
|
||||
if (AxSmithingPlugin.is1_20()) {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= Version.v1_20_1.protocolId && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_1.protocolId && Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_2.protocolId) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
event.setUseInteractedBlock(Event.Result.DENY);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.getPlayer().closeInventory();
|
||||
AxSmithingPlugin.getSmithingTableImpl().open(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpenEvent(@NotNull final InventoryOpenEvent event) {
|
||||
if (event.getInventory().getType() != InventoryType.SMITHING) return;
|
||||
|
||||
@@ -43,9 +43,11 @@ menu:
|
||||
- 14
|
||||
material: air
|
||||
|
||||
listen-to-interact-event: true
|
||||
|
||||
messages:
|
||||
prefix: "&#AA3428&lAxSmithing &7» "
|
||||
no-permission: "&cYou do not have permission to do this!"
|
||||
reload: "&aPlugin reloaded in %time%ms!"
|
||||
|
||||
config-version: 1
|
||||
config-version: 2
|
||||
Reference in new issue
Block a user