Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
407ccca5e0 | ||
|
|
82de602d47 | ||
|
|
b0873112af | ||
|
|
3a0b81b7de | ||
|
|
5142b9ce92 | ||
|
|
9403a1cbcb | ||
|
|
e4ebea354d | ||
|
|
d32b31f1e5 | ||
|
|
384657f1dc |
@@ -1,9 +1,11 @@
|
|||||||
package com.willfp.eco.core.integrations.customitems;
|
package com.willfp.eco.core.integrations.customitems;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.integrations.Integration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper class for custom item integrations.
|
* 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.
|
* Register all the custom items for a specific plugin into eco.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ public final class Items {
|
|||||||
|
|
||||||
TestableItem item = null;
|
TestableItem item = null;
|
||||||
|
|
||||||
|
int stackAmount = 1;
|
||||||
|
|
||||||
String[] split = args[0].toLowerCase().split(":");
|
String[] split = args[0].toLowerCase().split(":");
|
||||||
|
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
@@ -92,27 +94,50 @@ public final class Items {
|
|||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Legacy id:amount format
|
||||||
|
This has been superceded by id amount
|
||||||
|
*/
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
Material material = Material.getMaterial(split[0].toUpperCase());
|
Material material = Material.getMaterial(split[0].toUpperCase());
|
||||||
if (material == null || material == Material.AIR) {
|
if (material == null || material == Material.AIR) {
|
||||||
return new EmptyTestableItem();
|
return new EmptyTestableItem();
|
||||||
}
|
}
|
||||||
item = new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
item = new MaterialTestableItem(material);
|
||||||
|
stackAmount = Integer.parseInt(split[1]);
|
||||||
} else {
|
} else {
|
||||||
item = part;
|
item = part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Legacy namespace:id:amount format
|
||||||
|
This has been superceded by namespace:id amount
|
||||||
|
*/
|
||||||
if (split.length == 3) {
|
if (split.length == 3) {
|
||||||
CustomItem part = REGISTRY.get(NamespacedKeyUtils.create(split[0], split[1]));
|
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();
|
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<>();
|
Map<Enchantment, Integer> requiredEnchantments = new HashMap<>();
|
||||||
|
|
||||||
@@ -125,10 +150,6 @@ public final class Items {
|
|||||||
requiredEnchantments.put(enchantment, level);
|
requiredEnchantments.put(enchantment, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requiredEnchantments.isEmpty()) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack example = item.getItem();
|
ItemStack example = item.getItem();
|
||||||
|
|
||||||
if (example.getItemMeta() instanceof EnchantmentStorageMeta storageMeta) {
|
if (example.getItemMeta() instanceof EnchantmentStorageMeta storageMeta) {
|
||||||
@@ -141,41 +162,49 @@ public final class Items {
|
|||||||
example.setItemMeta(meta);
|
example.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ModifiedTestableItem(
|
if (!requiredEnchantments.isEmpty()) {
|
||||||
item,
|
item = new ModifiedTestableItem(
|
||||||
itemStack -> {
|
item,
|
||||||
if (!itemStack.hasItemMeta()) {
|
itemStack -> {
|
||||||
return false;
|
if (!itemStack.hasItemMeta()) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
|
|
||||||
if (meta instanceof EnchantmentStorageMeta storageMeta) {
|
if (meta instanceof EnchantmentStorageMeta storageMeta) {
|
||||||
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
|
for (Map.Entry<Enchantment, Integer> entry : requiredEnchantments.entrySet()) {
|
||||||
if (!storageMeta.hasStoredEnchant(entry.getKey())) {
|
if (!storageMeta.hasStoredEnchant(entry.getKey())) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (storageMeta.getStoredEnchantLevel(entry.getKey()) < entry.getValue()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (storageMeta.getStoredEnchantLevel(entry.getKey()) < entry.getValue()) {
|
} else {
|
||||||
return false;
|
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;
|
return true;
|
||||||
},
|
},
|
||||||
example
|
example
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stackAmount == 1) {
|
||||||
|
return item;
|
||||||
|
} else {
|
||||||
|
return new TestableStack(item, stackAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class EcoMenu(
|
|||||||
|
|
||||||
fun handleClose(event: InventoryCloseEvent) {
|
fun handleClose(event: InventoryCloseEvent) {
|
||||||
onClose.handle(event, this)
|
onClose.handle(event, this)
|
||||||
|
MenuHandler.unregisterMenu(event.inventory)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getRows(): Int {
|
override fun getRows(): Int {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ dependencies {
|
|||||||
compileOnly 'com.willfp:Oraxen:e1f4003d8d'
|
compileOnly 'com.willfp:Oraxen:e1f4003d8d'
|
||||||
compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0'
|
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
|
// CombatLogX V10 + NewbieHelper Expansion
|
||||||
compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT'
|
compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT'
|
||||||
|
|||||||
@@ -98,16 +98,65 @@ public class ShapedRecipeListener extends PluginDependent<EcoPlugin> implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getPlugin().getScheduler().runLater(() -> {
|
boolean isStackedRecipe = false;
|
||||||
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 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));
|
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
|
@EventHandler
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.willfp.eco.spigot.eventlisteners.*
|
|||||||
import com.willfp.eco.spigot.gui.GUIListener
|
import com.willfp.eco.spigot.gui.GUIListener
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.*
|
import com.willfp.eco.spigot.integrations.anticheat.*
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.*
|
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.customitems.CustomItemsOraxen
|
||||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl
|
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl
|
||||||
import com.willfp.eco.spigot.integrations.shop.ShopShopGuiPlus
|
import com.willfp.eco.spigot.integrations.shop.ShopShopGuiPlus
|
||||||
@@ -111,6 +112,7 @@ abstract class EcoSpigotPlugin : EcoPlugin(
|
|||||||
|
|
||||||
// Custom Items
|
// Custom Items
|
||||||
IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) },
|
IntegrationLoader("Oraxen") { CustomItemsManager.register(CustomItemsOraxen()) },
|
||||||
|
IntegrationLoader("ItemsAdder") { CustomItemsManager.register(CustomItemsItemsAdder()) },
|
||||||
|
|
||||||
// Shop
|
// Shop
|
||||||
IntegrationLoader("ShopGuiPlus") { ShopManager.register(ShopShopGuiPlus()) },
|
IntegrationLoader("ShopGuiPlus") { ShopManager.register(ShopShopGuiPlus()) },
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,4 +23,8 @@ class CustomItemsOraxen : CustomItemsWrapper {
|
|||||||
).register()
|
).register()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPluginName(): String {
|
||||||
|
return "Oraxen"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@ softdepend:
|
|||||||
- mcMMO
|
- mcMMO
|
||||||
- CombatLogX
|
- CombatLogX
|
||||||
- ShopGuiPlus
|
- ShopGuiPlus
|
||||||
|
- ItemsAdder
|
||||||
|
- Oraxen
|
||||||
libraries:
|
libraries:
|
||||||
- org.reflections:reflections:0.9.12
|
- org.reflections:reflections:0.9.12
|
||||||
- org.apache.maven:maven-artifact:3.0.3
|
- org.apache.maven:maven-artifact:3.0.3
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 6.6.1
|
version = 6.6.3
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user