mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2025-01-16 20:41:24 +01:00
Added logging for items traded with villagers (MC 1.18+)
This commit is contained in:
parent
7bc95931d2
commit
83fc221bf2
@ -34,7 +34,7 @@ dependencies {
|
||||
compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT') {
|
||||
exclude group: 'org.bukkit'
|
||||
}
|
||||
compileOnly 'io.papermc.paper:paper-api:1.17-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
|
||||
implementation 'org.bstats:bstats-bukkit-lite:1.8'
|
||||
implementation 'com.zaxxer:HikariCP:4.0.3'
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -94,7 +94,7 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
@ -43,9 +44,11 @@ public class BukkitAdapter implements BukkitInterface {
|
||||
BukkitAdapter.ADAPTER = new Bukkit_v1_16();
|
||||
break;
|
||||
case BUKKIT_V1_17:
|
||||
BukkitAdapter.ADAPTER = new Bukkit_v1_17();
|
||||
break;
|
||||
case BUKKIT_V1_18:
|
||||
default:
|
||||
BukkitAdapter.ADAPTER = new Bukkit_v1_17();
|
||||
BukkitAdapter.ADAPTER = new Bukkit_v1_18();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -144,4 +147,9 @@ public class BukkitAdapter implements BukkitInterface {
|
||||
return Util.isAir(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,10 +13,13 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public interface BukkitInterface {
|
||||
|
||||
public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack);
|
||||
|
||||
public Material getBucketContents(Material material);
|
||||
|
||||
public Material getFrameType(Entity entity);
|
||||
|
31
src/main/java/net/coreprotect/bukkit/Bukkit_v1_18.java
Normal file
31
src/main/java/net/coreprotect/bukkit/Bukkit_v1_18.java
Normal file
@ -0,0 +1,31 @@
|
||||
package net.coreprotect.bukkit;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public class Bukkit_v1_18 extends Bukkit_v1_17 implements BukkitInterface {
|
||||
|
||||
private Boolean hasAdjust = null;
|
||||
|
||||
@Override
|
||||
public ItemStack adjustIngredient(MerchantRecipe recipe, ItemStack itemStack) {
|
||||
try {
|
||||
if (hasAdjust == null) {
|
||||
hasAdjust = true;
|
||||
MerchantRecipe.class.getMethod("adjust", ItemStack.class); // Bukkit 1.18.1+
|
||||
}
|
||||
else if (Boolean.FALSE.equals(hasAdjust)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack adjustedStack = itemStack.clone();
|
||||
recipe.adjust(adjustedStack);
|
||||
return adjustedStack;
|
||||
}
|
||||
catch (Exception e) {
|
||||
hasAdjust = false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -908,6 +908,10 @@ public class LookupCommand {
|
||||
selector = (daction == ItemLogger.ITEM_CREATE ? Selector.FIRST : Selector.SECOND);
|
||||
tag = (daction == ItemLogger.ITEM_CREATE ? Color.GREEN + "+" : Color.RED + "-");
|
||||
}
|
||||
else if (daction == ItemLogger.ITEM_SELL || daction == ItemLogger.ITEM_BUY) { // LOOKUP_TRADE
|
||||
selector = (daction == ItemLogger.ITEM_BUY ? Selector.FIRST : Selector.SECOND);
|
||||
tag = (daction == ItemLogger.ITEM_BUY ? Color.GREEN + "+" : Color.RED + "-");
|
||||
}
|
||||
else { // LOOKUP_CONTAINER
|
||||
selector = (daction == 0 ? Selector.FIRST : Selector.SECOND);
|
||||
tag = (daction == 0 ? Color.GREEN + "+" : Color.RED + "-");
|
||||
|
@ -95,6 +95,8 @@ public class ConfigHandler extends Queue {
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsBreak = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsDestroy = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsCreate = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsSell = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, List<ItemStack>> itemsBuy = new ConcurrentHashMap<>();
|
||||
public static ConcurrentHashMap<String, Object[]> hopperAbort = new ConcurrentHashMap<>();
|
||||
public static Map<String, List<ItemStack[]>> forceContainer = syncMap();
|
||||
public static Map<String, Integer> lookupType = syncMap();
|
||||
|
@ -18,7 +18,7 @@ class ItemTransactionProcess extends Queue {
|
||||
|
||||
if (ConfigHandler.loggingItem.get(loggingItemId) != null) {
|
||||
int current_chest = ConfigHandler.loggingItem.get(loggingItemId);
|
||||
if (ConfigHandler.itemsPickup.get(loggingItemId) == null && ConfigHandler.itemsDrop.get(loggingItemId) == null && ConfigHandler.itemsThrown.get(loggingItemId) == null && ConfigHandler.itemsShot.get(loggingItemId) == null && ConfigHandler.itemsBreak.get(loggingItemId) == null && ConfigHandler.itemsDestroy.get(loggingItemId) == null && ConfigHandler.itemsCreate.get(loggingItemId) == null) {
|
||||
if (ConfigHandler.itemsPickup.get(loggingItemId) == null && ConfigHandler.itemsDrop.get(loggingItemId) == null && ConfigHandler.itemsThrown.get(loggingItemId) == null && ConfigHandler.itemsShot.get(loggingItemId) == null && ConfigHandler.itemsBreak.get(loggingItemId) == null && ConfigHandler.itemsDestroy.get(loggingItemId) == null && ConfigHandler.itemsCreate.get(loggingItemId) == null && ConfigHandler.itemsSell.get(loggingItemId) == null && ConfigHandler.itemsBuy.get(loggingItemId) == null) {
|
||||
return;
|
||||
}
|
||||
if (current_chest == forceData) {
|
||||
@ -32,6 +32,8 @@ class ItemTransactionProcess extends Queue {
|
||||
ConfigHandler.itemsBreak.remove(loggingItemId);
|
||||
ConfigHandler.itemsDestroy.remove(loggingItemId);
|
||||
ConfigHandler.itemsCreate.remove(loggingItemId);
|
||||
ConfigHandler.itemsSell.remove(loggingItemId);
|
||||
ConfigHandler.itemsBuy.remove(loggingItemId);
|
||||
ConfigHandler.loggingItem.remove(loggingItemId);
|
||||
}
|
||||
else {
|
||||
|
@ -450,6 +450,8 @@ public class Lookup extends Queue {
|
||||
actionText = actionText.append(ItemLogger.ITEM_BREAK);
|
||||
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
|
||||
actionText.append(",").append(ItemLogger.ITEM_CREATE);
|
||||
actionText.append(",").append(ItemLogger.ITEM_SELL);
|
||||
actionText.append(",").append(ItemLogger.ITEM_BUY);
|
||||
actionExclude = actionText.toString();
|
||||
}
|
||||
|
||||
@ -480,6 +482,7 @@ public class Lookup extends Queue {
|
||||
actionText.append(",").append(ItemLogger.ITEM_PICKUP);
|
||||
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
|
||||
actionText.append(",").append(ItemLogger.ITEM_CREATE);
|
||||
actionText.append(",").append(ItemLogger.ITEM_BUY);
|
||||
}
|
||||
if (actionTarget == ItemLogger.ITEM_ADD) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_DROP);
|
||||
@ -488,6 +491,7 @@ public class Lookup extends Queue {
|
||||
actionText.append(",").append(ItemLogger.ITEM_SHOOT);
|
||||
actionText.append(",").append(ItemLogger.ITEM_BREAK);
|
||||
actionText.append(",").append(ItemLogger.ITEM_DESTROY);
|
||||
actionText.append(",").append(ItemLogger.ITEM_SELL);
|
||||
}
|
||||
}
|
||||
// If just looking up drops/pickups, include ender chest transactions
|
||||
|
@ -1074,8 +1074,8 @@ public class Rollback extends Queue {
|
||||
}
|
||||
|
||||
int inventoryAction = 0;
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_THROW || rowAction == ItemLogger.ITEM_SHOOT || rowAction == ItemLogger.ITEM_BREAK || rowAction == ItemLogger.ITEM_DESTROY || rowAction == ItemLogger.ITEM_CREATE) {
|
||||
inventoryAction = ((rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_CREATE) ? 1 : 0);
|
||||
if (rowAction == ItemLogger.ITEM_DROP || rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_THROW || rowAction == ItemLogger.ITEM_SHOOT || rowAction == ItemLogger.ITEM_BREAK || rowAction == ItemLogger.ITEM_DESTROY || rowAction == ItemLogger.ITEM_CREATE || rowAction == ItemLogger.ITEM_SELL || rowAction == ItemLogger.ITEM_BUY) {
|
||||
inventoryAction = ((rowAction == ItemLogger.ITEM_PICKUP || rowAction == ItemLogger.ITEM_CREATE || rowAction == ItemLogger.ITEM_BUY) ? 1 : 0);
|
||||
}
|
||||
else if (rowAction == ItemLogger.ITEM_REMOVE_ENDER || rowAction == ItemLogger.ITEM_ADD_ENDER) {
|
||||
inventoryAction = (rowAction == ItemLogger.ITEM_REMOVE_ENDER ? 1 : 0);
|
||||
|
@ -30,6 +30,8 @@ public class ItemLogger {
|
||||
public static final int ITEM_BREAK = 8;
|
||||
public static final int ITEM_DESTROY = 9;
|
||||
public static final int ITEM_CREATE = 10;
|
||||
public static final int ITEM_SELL = 11;
|
||||
public static final int ITEM_BUY = 12;
|
||||
|
||||
private ItemLogger() {
|
||||
throw new IllegalStateException("Database class");
|
||||
@ -78,6 +80,16 @@ public class ItemLogger {
|
||||
itemCreates = createList.toArray(itemCreates);
|
||||
createList.clear();
|
||||
|
||||
List<ItemStack> sellList = ConfigHandler.itemsSell.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemSells = new ItemStack[sellList.size()];
|
||||
itemSells = sellList.toArray(itemSells);
|
||||
sellList.clear();
|
||||
|
||||
List<ItemStack> buyList = ConfigHandler.itemsBuy.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemBuys = new ItemStack[buyList.size()];
|
||||
itemBuys = buyList.toArray(itemBuys);
|
||||
buyList.clear();
|
||||
|
||||
Util.mergeItems(null, itemPickups);
|
||||
Util.mergeItems(null, itemDrops);
|
||||
Util.mergeItems(null, itemThrows);
|
||||
@ -85,6 +97,8 @@ public class ItemLogger {
|
||||
Util.mergeItems(null, itemBreaks);
|
||||
Util.mergeItems(null, itemDestroys);
|
||||
Util.mergeItems(null, itemCreates);
|
||||
Util.mergeItems(null, itemSells);
|
||||
Util.mergeItems(null, itemBuys);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemPickups, ITEM_PICKUP);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemDrops, ITEM_DROP);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemThrows, ITEM_THROW);
|
||||
@ -92,6 +106,8 @@ public class ItemLogger {
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemBreaks, ITEM_BREAK);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemDestroys, ITEM_DESTROY);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemCreates, ITEM_CREATE);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemSells, ITEM_SELL);
|
||||
logTransaction(preparedStmt, batchCount, offset, user, location, itemBuys, ITEM_BUY);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -31,6 +31,7 @@ import net.coreprotect.listener.player.ArmorStandManipulateListener;
|
||||
import net.coreprotect.listener.player.CraftItemListener;
|
||||
import net.coreprotect.listener.player.FoodLevelChangeListener;
|
||||
import net.coreprotect.listener.player.InventoryChangeListener;
|
||||
import net.coreprotect.listener.player.InventoryClickListener;
|
||||
import net.coreprotect.listener.player.PlayerBucketEmptyListener;
|
||||
import net.coreprotect.listener.player.PlayerBucketFillListener;
|
||||
import net.coreprotect.listener.player.PlayerChatListener;
|
||||
@ -90,6 +91,7 @@ public final class ListenerHandler {
|
||||
pluginManager.registerEvents(new CraftItemListener(), plugin);
|
||||
pluginManager.registerEvents(new FoodLevelChangeListener(), plugin);
|
||||
pluginManager.registerEvents(new InventoryChangeListener(), plugin);
|
||||
pluginManager.registerEvents(new InventoryClickListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerBucketEmptyListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerBucketFillListener(), plugin);
|
||||
pluginManager.registerEvents(new PlayerCommandListener(), plugin);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.coreprotect.listener.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -15,13 +14,18 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.event.inventory.InventoryType.SlotType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantInventory;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
@ -29,7 +33,7 @@ import net.coreprotect.database.logger.ItemLogger;
|
||||
|
||||
public final class CraftItemListener extends Queue implements Listener {
|
||||
|
||||
protected static void playerCraftItem(Location location, String user, ItemStack itemStack, int action) {
|
||||
protected static void logCraftedItem(Location location, String user, ItemStack itemStack, int action) {
|
||||
if (!Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS || itemStack == null) {
|
||||
return;
|
||||
}
|
||||
@ -37,7 +41,17 @@ public final class CraftItemListener extends Queue implements Listener {
|
||||
String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
int itemId = getItemId(loggingItemId);
|
||||
|
||||
if (action == ItemLogger.ITEM_CREATE) {
|
||||
if (action == ItemLogger.ITEM_BUY) {
|
||||
List<ItemStack> list = ConfigHandler.itemsBuy.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
list.add(itemStack);
|
||||
ConfigHandler.itemsBuy.put(loggingItemId, list);
|
||||
}
|
||||
else if (action == ItemLogger.ITEM_SELL) {
|
||||
List<ItemStack> list = ConfigHandler.itemsSell.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
list.add(itemStack);
|
||||
ConfigHandler.itemsSell.put(loggingItemId, list);
|
||||
}
|
||||
else if (action == ItemLogger.ITEM_CREATE) {
|
||||
List<ItemStack> list = ConfigHandler.itemsCreate.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
list.add(itemStack);
|
||||
ConfigHandler.itemsCreate.put(loggingItemId, list);
|
||||
@ -52,9 +66,8 @@ public final class CraftItemListener extends Queue implements Listener {
|
||||
Queue.queueItemTransaction(user, location.clone(), time, 0, itemId);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
protected void onCraftItem(CraftItemEvent event) {
|
||||
if (event.getResult() == Result.DENY) {
|
||||
protected static void playerCraftItem(InventoryClickEvent event, boolean isTrade) {
|
||||
if (event.getResult() == Result.DENY || event.getSlotType() != SlotType.RESULT) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,17 +80,23 @@ public final class CraftItemListener extends Queue implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
CraftingInventory craftingInventory = event.getInventory();
|
||||
if (craftingInventory.getResult() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory bottomInventory = event.getView().getBottomInventory();
|
||||
if (bottomInventory.getType() != InventoryType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack addItem = event.getRecipe().getResult().clone();
|
||||
Recipe recipe = null;
|
||||
if (!isTrade && event instanceof CraftItemEvent) {
|
||||
recipe = ((CraftItemEvent) event).getRecipe();
|
||||
}
|
||||
else if (isTrade && event.getInventory() instanceof MerchantInventory) {
|
||||
recipe = ((MerchantInventory) event.getInventory()).getSelectedRecipe();
|
||||
}
|
||||
if (recipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack addItem = recipe.getResult().clone();
|
||||
int amount = addItem.getAmount();
|
||||
if (amount == 0) {
|
||||
return;
|
||||
@ -86,9 +105,34 @@ public final class CraftItemListener extends Queue implements Listener {
|
||||
int amountMultiplier = 1;
|
||||
if (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
int newMultiplier = Integer.MIN_VALUE;
|
||||
for (ItemStack item : craftingInventory.getMatrix()) {
|
||||
if (item != null && (newMultiplier == Integer.MIN_VALUE || item.getAmount() < newMultiplier)) {
|
||||
newMultiplier = item.getAmount();
|
||||
for (ItemStack item : event.getInventory().getContents()) {
|
||||
if (item != null && item.getType() != Material.AIR && !item.equals(recipe.getResult())) {
|
||||
if (isTrade) {
|
||||
int merchantAmount = newMultiplier;
|
||||
MerchantRecipe merchantRecipe = (MerchantRecipe) recipe;
|
||||
for (ItemStack ingredient : merchantRecipe.getIngredients()) {
|
||||
if (ingredient.isSimilar(item)) {
|
||||
ItemStack adjusted = BukkitAdapter.ADAPTER.adjustIngredient(merchantRecipe, ingredient);
|
||||
if (adjusted == null) {
|
||||
return;
|
||||
}
|
||||
merchantAmount = item.getAmount() / adjusted.getAmount();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int merchantUsesLeft = merchantRecipe.getMaxUses() - merchantRecipe.getUses();
|
||||
if (merchantUsesLeft < merchantAmount) {
|
||||
merchantAmount = merchantUsesLeft;
|
||||
}
|
||||
|
||||
if (newMultiplier == Integer.MIN_VALUE || merchantAmount < newMultiplier) {
|
||||
newMultiplier = merchantAmount;
|
||||
}
|
||||
}
|
||||
else if (newMultiplier == Integer.MIN_VALUE || item.getAmount() < newMultiplier) {
|
||||
newMultiplier = item.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
amountMultiplier = (newMultiplier == Integer.MIN_VALUE ? 1 : newMultiplier);
|
||||
@ -96,40 +140,57 @@ public final class CraftItemListener extends Queue implements Listener {
|
||||
int addAmount = amount * amountMultiplier;
|
||||
Inventory virtualInventory = Bukkit.createInventory(null, 36);
|
||||
virtualInventory.setStorageContents(bottomInventory.getStorageContents());
|
||||
addItem.setAmount(addAmount);
|
||||
addItem.setAmount(1);
|
||||
|
||||
HashMap<Integer, ItemStack> result = virtualInventory.addItem(addItem);
|
||||
for (ItemStack itemFailed : result.values()) {
|
||||
if (itemFailed.isSimilar(addItem)) {
|
||||
addAmount = (int) (Math.ceil((addAmount - itemFailed.getAmount()) / (double) amount) * amount);
|
||||
amountMultiplier = addAmount / amount;
|
||||
int addSuccess = 0;
|
||||
for (int i = 0; i < addAmount; i++) {
|
||||
if (!virtualInventory.addItem(addItem).isEmpty()) {
|
||||
break;
|
||||
}
|
||||
addSuccess++;
|
||||
}
|
||||
|
||||
if (addSuccess < addAmount) {
|
||||
addAmount = (int) (Math.ceil(addSuccess / (double) amount) * amount);
|
||||
amountMultiplier = addAmount / amount;
|
||||
}
|
||||
|
||||
virtualInventory.clear();
|
||||
addItem.setAmount(addAmount);
|
||||
}
|
||||
|
||||
List<ItemStack> oldItems = new ArrayList<>();
|
||||
if (event.getRecipe() instanceof ShapelessRecipe) {
|
||||
oldItems.addAll(((ShapelessRecipe) event.getRecipe()).getIngredientList());
|
||||
if (recipe instanceof ShapelessRecipe) {
|
||||
oldItems.addAll(((ShapelessRecipe) recipe).getIngredientList());
|
||||
}
|
||||
if (event.getRecipe() instanceof ShapedRecipe) {
|
||||
oldItems.addAll(((ShapedRecipe) event.getRecipe()).getIngredientMap().values());
|
||||
else if (recipe instanceof ShapedRecipe) {
|
||||
oldItems.addAll(((ShapedRecipe) recipe).getIngredientMap().values());
|
||||
}
|
||||
else if (recipe instanceof MerchantRecipe) {
|
||||
oldItems.addAll(((MerchantRecipe) recipe).getIngredients());
|
||||
}
|
||||
|
||||
if (addItem.getAmount() > 0) {
|
||||
for (ItemStack oldItem : oldItems) {
|
||||
if (oldItem == null) {
|
||||
if (oldItem == null || oldItem.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack removedItem = oldItem.clone();
|
||||
removedItem.setAmount(oldItem.getAmount() * amountMultiplier);
|
||||
playerCraftItem(player.getLocation(), player.getName(), removedItem, ItemLogger.ITEM_DESTROY);
|
||||
ItemStack removedItem = isTrade ? BukkitAdapter.ADAPTER.adjustIngredient((MerchantRecipe) recipe, oldItem) : oldItem.clone();
|
||||
if (removedItem == null) {
|
||||
return;
|
||||
}
|
||||
removedItem.setAmount(removedItem.getAmount() * amountMultiplier);
|
||||
logCraftedItem(player.getLocation(), player.getName(), removedItem, isTrade ? ItemLogger.ITEM_SELL : ItemLogger.ITEM_DESTROY);
|
||||
}
|
||||
|
||||
playerCraftItem(player.getLocation(), player.getName(), addItem, ItemLogger.ITEM_CREATE);
|
||||
logCraftedItem(player.getLocation(), player.getName(), addItem, isTrade ? ItemLogger.ITEM_BUY : ItemLogger.ITEM_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
protected void onCraftItem(CraftItemEvent event) {
|
||||
playerCraftItem(event, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.coreprotect.listener.player;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import net.coreprotect.consumer.Queue;
|
||||
|
||||
public final class InventoryClickListener extends Queue implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
protected void onVillagerTrade(InventoryClickEvent event) {
|
||||
CraftItemListener.playerCraftItem(event, true);
|
||||
}
|
||||
|
||||
}
|
@ -178,4 +178,10 @@ public final class WorldEditBlockState implements BlockState {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollidable() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user