v1.2
This commit is contained in:
@@ -1,9 +1,55 @@
|
||||
package com.kasetoatz.superBow;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Multiplier {
|
||||
public int item;
|
||||
public int book;
|
||||
|
||||
public static final Map<Enchantment, Multiplier> multipliers = Map.ofEntries(
|
||||
Map.entry(Enchantment.PROTECTION, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.FIRE_PROTECTION, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.FEATHER_FALLING, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.BLAST_PROTECTION, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.PROJECTILE_PROTECTION, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.THORNS, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.RESPIRATION, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.DEPTH_STRIDER, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.AQUA_AFFINITY, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.SHARPNESS, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.SMITE, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.BANE_OF_ARTHROPODS, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.KNOCKBACK, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.FIRE_ASPECT, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.LOOTING, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.EFFICIENCY, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.SILK_TOUCH, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.UNBREAKING, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.FORTUNE, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.POWER, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.PUNCH, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.FLAME, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.INFINITY, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.LUCK_OF_THE_SEA, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.LURE, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.FROST_WALKER, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.MENDING, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.IMPALING, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.RIPTIDE, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.LOYALTY, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.CHANNELING, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.MULTISHOT, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.PIERCING, new Multiplier(1, 1)),
|
||||
Map.entry(Enchantment.QUICK_CHARGE, new Multiplier(2, 1)),
|
||||
Map.entry(Enchantment.SWEEPING_EDGE, new Multiplier(4, 2)),
|
||||
Map.entry(Enchantment.SWIFT_SNEAK, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.SOUL_SPEED, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.BINDING_CURSE, new Multiplier(8, 4)),
|
||||
Map.entry(Enchantment.VANISHING_CURSE, new Multiplier(8, 4))
|
||||
);
|
||||
|
||||
public Multiplier(int item, int book)
|
||||
{
|
||||
this.item = item;
|
||||
|
@@ -16,6 +16,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.kasetoatz.superBow.Multiplier.multipliers;
|
||||
|
||||
public final class SuperBow extends JavaPlugin implements Listener
|
||||
{
|
||||
@Override
|
||||
@@ -26,52 +28,32 @@ public final class SuperBow extends JavaPlugin implements Listener
|
||||
|
||||
public Map<Enchantment, Integer> getEnchants(ItemStack item)
|
||||
{
|
||||
Map<Enchantment, Integer> enchants = Map.of();
|
||||
if (item.getType() == Material.ENCHANTED_BOOK)
|
||||
if (item.getItemMeta() instanceof EnchantmentStorageMeta meta)
|
||||
{
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta();
|
||||
if (meta != null)
|
||||
{
|
||||
enchants = meta.getStoredEnchants();
|
||||
}
|
||||
return meta.getStoredEnchants();
|
||||
}
|
||||
else
|
||||
{
|
||||
enchants = item.getEnchantments();
|
||||
}
|
||||
return enchants;
|
||||
return item.getEnchantments();
|
||||
}
|
||||
|
||||
public int getPenalty(ItemStack item)
|
||||
{
|
||||
if (item.getType() == Material.BOW)
|
||||
if (item.getItemMeta() instanceof Repairable meta)
|
||||
{
|
||||
Repairable meta = (Repairable)item.getItemMeta();
|
||||
if (meta != null)
|
||||
{
|
||||
return (int)Math.pow(2, meta.getRepairCost()) - 1;
|
||||
}
|
||||
return (int)Math.pow(2, meta.getRepairCost()) - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int calculateCost(ItemStack target, ItemStack sacrifice, boolean renamed, boolean repair)
|
||||
{
|
||||
Map<Enchantment, Multiplier> multipliers = Map.of(
|
||||
Enchantment.UNBREAKING, new Multiplier(2, 1),
|
||||
Enchantment.POWER, new Multiplier(1, 1),
|
||||
Enchantment.PUNCH, new Multiplier(4, 2),
|
||||
Enchantment.FLAME, new Multiplier(4, 2),
|
||||
Enchantment.INFINITY, new Multiplier(8, 4),
|
||||
Enchantment.MENDING, new Multiplier(4, 2)
|
||||
);
|
||||
|
||||
AtomicInteger cost = new AtomicInteger();
|
||||
getEnchants(sacrifice).forEach((enchant, level) -> {
|
||||
if (!enchant.canEnchantItem(new ItemStack(Material.BOW)))
|
||||
if (!isValidEnchant(target, enchant))
|
||||
{
|
||||
return;
|
||||
}
|
||||
boolean conflict = getEnchants(target).keySet().stream().anyMatch(e -> (enchant == Enchantment.MENDING && e == Enchantment.INFINITY) || (enchant == Enchantment.INFINITY && e == Enchantment.MENDING) || enchant.conflictsWith(e));
|
||||
boolean conflict = getEnchants(target).keySet().stream().anyMatch(e -> !((enchant == Enchantment.MENDING && e == Enchantment.INFINITY) || (enchant == Enchantment.INFINITY && e == Enchantment.MENDING)) && enchant.conflictsWith(e));
|
||||
if (conflict)
|
||||
{
|
||||
cost.getAndIncrement();
|
||||
@@ -83,6 +65,7 @@ public final class SuperBow extends JavaPlugin implements Listener
|
||||
{
|
||||
multiplier = multipliers.get(enchant).book;
|
||||
}
|
||||
Enchantment test = Enchantment.PROTECTION;
|
||||
int targetLevel = getEnchants(target).getOrDefault(enchant, 0);
|
||||
if (targetLevel == level)
|
||||
{
|
||||
@@ -106,6 +89,11 @@ public final class SuperBow extends JavaPlugin implements Listener
|
||||
return cost.get();
|
||||
}
|
||||
|
||||
private boolean isValidEnchant(ItemStack item, Enchantment enchant)
|
||||
{
|
||||
return enchant.canEnchantItem(new ItemStack(item.getType())) || item.getType() == Material.ENCHANTED_BOOK;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAnvilPrepare(PrepareAnvilEvent event)
|
||||
{
|
||||
@@ -113,7 +101,7 @@ public final class SuperBow extends JavaPlugin implements Listener
|
||||
ItemStack left = inv.getItem(0);
|
||||
ItemStack right = inv.getItem(1);
|
||||
|
||||
if (left == null || right == null || left.getType() != Material.BOW)
|
||||
if (left == null || right == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -125,7 +113,20 @@ public final class SuperBow extends JavaPlugin implements Listener
|
||||
{
|
||||
ItemStack result = left.clone();
|
||||
boolean repair = false;
|
||||
result.addUnsafeEnchantments(getEnchants(right));
|
||||
getEnchants(right).forEach((enchant, level) -> {
|
||||
if (isValidEnchant(left, enchant))
|
||||
{
|
||||
if (result.getItemMeta() instanceof EnchantmentStorageMeta meta)
|
||||
{
|
||||
meta.addStoredEnchant(enchant, level, true);
|
||||
result.setItemMeta(meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.addUnsafeEnchantment(enchant, level);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (right.getType() == Material.BOW)
|
||||
{
|
||||
int maxDamage = result.getType().getMaxDurability();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
name: SuperBow
|
||||
version: '1.1'
|
||||
version: '1.2'
|
||||
main: com.kasetoatz.superBow.SuperBow
|
||||
api-version: '1.21'
|
||||
|
Reference in New Issue
Block a user