Compare commits

..

7 Commits
6.6.2 ... 6.6.3

Author SHA1 Message Date
Auxilor
407ccca5e0 TestableStack changes don't stop ever 2021-09-02 11:49:48 +01:00
Auxilor
82de602d47 Hopefully fixed crafting exploit 2021-09-02 10:53:14 +01:00
Auxilor
b0873112af Added ItemsAdder and Oraxen to plugin.yml 2021-09-02 10:50:40 +01:00
Auxilor
3a0b81b7de Updated to 6.6.3 2021-09-02 10:50:12 +01:00
Auxilor
5142b9ce92 More Items#lookup improvements 2021-09-02 10:46:25 +01:00
Auxilor
9403a1cbcb Marked item:amount system as legacy and replaced it with item amount 2021-09-02 10:42:29 +01:00
Auxilor
e4ebea354d Added ItemsAdder support 2021-09-02 10:35:03 +01:00
9 changed files with 164 additions and 45 deletions

View File

@@ -1,9 +1,11 @@
package com.willfp.eco.core.integrations.customitems;
import com.willfp.eco.core.integrations.Integration;
/**
* Wrapper class for custom item integrations.
*/
public interface CustomItemsWrapper {
public interface CustomItemsWrapper extends Integration {
/**
* Register all the custom items for a specific plugin into eco.
*

View File

@@ -79,6 +79,8 @@ public final class Items {
TestableItem item = null;
int stackAmount = 1;
String[] split = args[0].toLowerCase().split(":");
if (split.length == 1) {
@@ -92,27 +94,50 @@ public final class Items {
if (split.length == 2) {
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
/*
Legacy id:amount format
This has been superceded by id amount
*/
if (part == null) {
Material material = Material.getMaterial(split[0].toUpperCase());
if (material == null || material == Material.AIR) {
return new EmptyTestableItem();
}
item = new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
item = new MaterialTestableItem(material);
stackAmount = Integer.parseInt(split[1]);
} else {
item = part;
}
}
/*
Legacy namespace:id:amount format
This has been superceded by namespace:id amount
*/
if (split.length == 3) {
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
item = part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
if (part == null) {
return new EmptyTestableItem();
}
item = part;
stackAmount = Integer.parseInt(split[2]);
}
if (item == null || item instanceof EmptyTestableItem) {
boolean usingNewStackFormat = false;
if (args.length >= 2) {
try {
stackAmount = Integer.parseInt(args[1]);
usingNewStackFormat = true;
} catch (NumberFormatException ignored) {
}
}
if (item == null) {
return new EmptyTestableItem();
}
String[] enchantArgs = Arrays.copyOfRange(args, 1, args.length);
String[] enchantArgs = Arrays.copyOfRange(args, usingNewStackFormat ? 2 : 1, args.length);
Map<Enchantment, Integer> requiredEnchantments = new HashMap<>();
@@ -125,10 +150,6 @@ public final class Items {
requiredEnchantments.put(enchantment, level);
}
if (requiredEnchantments.isEmpty()) {
return item;
}
ItemStack example = item.getItem();
if (example.getItemMeta() instanceof EnchantmentStorageMeta storageMeta) {
@@ -141,41 +162,49 @@ public final class Items {
example.setItemMeta(meta);
}
return new ModifiedTestableItem(
item,
itemStack -> {
if (!itemStack.hasItemMeta()) {
return false;
}
if (!requiredEnchantments.isEmpty()) {
item = new ModifiedTestableItem(
item,
itemStack -> {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta meta = itemStack.getItemMeta();
ItemMeta meta = itemStack.getItemMeta();
assert meta != null;
assert meta != null;
if (meta instanceof EnchantmentStorageMeta storageMeta) {
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
if (!storageMeta.hasStoredEnchant(entry.getKey())) {
return false;
if (meta instanceof EnchantmentStorageMeta storageMeta) {
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
if (!storageMeta.hasStoredEnchant(entry.getKey())) {
return false;
}
if (storageMeta.getStoredEnchantLevel(entry.getKey()) < entry.getValue()) {
return false;
}
}
if (storageMeta.getStoredEnchantLevel(entry.getKey()) < entry.getValue()) {
return false;
} else {
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
if (!meta.hasEnchant(entry.getKey())) {
return false;
}
if (meta.getEnchantLevel(entry.getKey()) < entry.getValue()) {
return false;
}
}
}
} else {
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
if (!meta.hasEnchant(entry.getKey())) {
return false;
}
if (meta.getEnchantLevel(entry.getKey()) < entry.getValue()) {
return false;
}
}
}
return true;
},
example
);
return true;
},
example
);
}
if (stackAmount == 1) {
return item;
} else {
return new TestableStack(item, stackAmount);
}
}
/**

View File

@@ -22,7 +22,7 @@ dependencies {
compileOnly 'com.willfp:Oraxen:e1f4003d8d'
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.3.8'
compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7'
// CombatLogX V10 + NewbieHelper Expansion
compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT'

View File

@@ -98,16 +98,65 @@ public class ShapedRecipeListener extends PluginDependent<EcoPlugin> implements
return;
}
this.getPlugin().getScheduler().runLater(() -> {
for (int i = 0; i < 9; i++) {
ItemStack inMatrix = event.getInventory().getMatrix()[i];
TestableItem inRecipe = matched.getParts().get(i);
boolean isStackedRecipe = false;
if (inRecipe instanceof TestableStack testableStack) {
int upperBound = 64;
for (int i = 0; i < 9; i++) {
ItemStack inMatrix = event.getInventory().getMatrix()[i];
TestableItem inRecipe = matched.getParts().get(i);
if (inRecipe instanceof TestableStack testableStack) {
int max = Math.floorDiv(inMatrix.getAmount(), testableStack.getAmount());
if (max < upperBound) {
upperBound = max;
}
isStackedRecipe = true;
} else if (inMatrix != null) {
int max = inMatrix.getAmount();
if (max < upperBound) {
upperBound = max;
}
}
}
if (!isStackedRecipe) {
return;
}
int toGivePerRecipe = event.getRecipe().getResult().getAmount();
int maxStackSize = event.getRecipe().getResult().getMaxStackSize();
while (toGivePerRecipe * upperBound > maxStackSize) {
upperBound--;
}
for (int i = 0; i < 9; i++) {
ItemStack inMatrix = event.getInventory().getMatrix()[i];
TestableItem inRecipe = matched.getParts().get(i);
if (inRecipe instanceof TestableStack testableStack) {
if (event.isShiftClick()) {
int amount = inMatrix.getAmount() + 1;
for (int j = 0; j < upperBound; j++) {
amount -= testableStack.getAmount();
}
inMatrix.setAmount(amount);
} else {
inMatrix.setAmount(inMatrix.getAmount() - (testableStack.getAmount() - 1));
}
}
}, 1);
}
int finalUpperBound = upperBound;
if (event.isShiftClick()) {
ItemStack result = event.getInventory().getResult();
if (result == null) {
return;
}
result.setAmount(result.getAmount() * finalUpperBound);
event.getInventory().setResult(result);
}
}
@EventHandler

View File

@@ -20,6 +20,7 @@ import com.willfp.eco.spigot.eventlisteners.*
import com.willfp.eco.spigot.gui.GUIListener
import com.willfp.eco.spigot.integrations.anticheat.*
import com.willfp.eco.spigot.integrations.antigrief.*
import com.willfp.eco.spigot.integrations.customitems.CustomItemsItemsAdder
import com.willfp.eco.spigot.integrations.customitems.CustomItemsOraxen
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl
import com.willfp.eco.spigot.integrations.shop.ShopShopGuiPlus
@@ -111,6 +112,7 @@ abstract class EcoSpigotPlugin : EcoPlugin(
// Custom Items
IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) },
IntegrationLoader("ItemsAdder") { CustomItemsManager.register(CustomItemsItemsAdder()) },
// Shop
IntegrationLoader("ShopGuiPlus") { ShopManager.register(ShopShopGuiPlus()) },

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.spigot.integrations.customitems
import com.willfp.eco.core.integrations.customitems.CustomItemsWrapper
import com.willfp.eco.core.items.CustomItem
import com.willfp.eco.util.NamespacedKeyUtils
import dev.lone.itemsadder.api.CustomStack
import dev.lone.itemsadder.api.ItemsAdder
import org.bukkit.inventory.ItemStack
import java.util.function.Predicate
class CustomItemsItemsAdder : CustomItemsWrapper {
override fun registerAllItems() {
for (item in ItemsAdder.getAllItems()) {
val stack = item.itemStack
val id = item.id
val key = NamespacedKeyUtils.create("itemsadder", id.lowercase())
CustomItem(
key,
Predicate { test: ItemStack ->
val customStack = CustomStack.byItemStack(test) ?: return@Predicate false
customStack.id.equals(id, ignoreCase = true)
},
stack
).register()
}
}
override fun getPluginName(): String {
return "ItemsAdder"
}
}

View File

@@ -23,4 +23,8 @@ class CustomItemsOraxen : CustomItemsWrapper {
).register()
}
}
override fun getPluginName(): String {
return "Oraxen"
}
}

View File

@@ -21,6 +21,8 @@ softdepend:
- mcMMO
- CombatLogX
- ShopGuiPlus
- ItemsAdder
- Oraxen
libraries:
- org.reflections:reflections:0.9.12
- org.apache.maven:maven-artifact:3.0.3

View File

@@ -1,2 +1,2 @@
version = 6.6.2
version = 6.6.3
plugin-name = eco