Added inventory transaction logging for chiseled bookshelves

This commit is contained in:
Intelli 2023-07-08 14:55:24 -06:00
parent d7d53bf9e2
commit 7e97e12969
5 changed files with 50 additions and 3 deletions

View File

@ -30,6 +30,7 @@ public class BukkitAdapter implements BukkitInterface {
public static final int BUKKIT_V1_17 = 17;
public static final int BUKKIT_V1_18 = 18;
public static final int BUKKIT_V1_19 = 19;
public static final int BUKKIT_V1_20 = 20;
public static void loadAdapter() {
switch (ConfigHandler.SERVER_VERSION) {
@ -48,8 +49,10 @@ public class BukkitAdapter implements BukkitInterface {
BukkitAdapter.ADAPTER = new Bukkit_v1_18();
break;
case BUKKIT_V1_19:
default:
BukkitAdapter.ADAPTER = new Bukkit_v1_19();
case BUKKIT_V1_20:
default:
BukkitAdapter.ADAPTER = new Bukkit_v1_20();
}
}

View File

@ -0,0 +1,17 @@
package net.coreprotect.bukkit;
import java.util.Arrays;
import java.util.HashSet;
import org.bukkit.Material;
import net.coreprotect.model.BlockGroup;
public class Bukkit_v1_20 extends Bukkit_v1_19 implements BukkitInterface {
public Bukkit_v1_20() {
BlockGroup.CONTAINERS = new HashSet<>(Arrays.asList(Material.JUKEBOX, Material.DISPENSER, Material.CHEST, Material.FURNACE, Material.BREWING_STAND, Material.TRAPPED_CHEST, Material.HOPPER, Material.DROPPER, Material.ARMOR_STAND, Material.ITEM_FRAME, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX, Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.BARREL, Material.BLAST_FURNACE, Material.SMOKER, Material.LECTERN, Material.CHISELED_BOOKSHELF));
BlockGroup.UPDATE_STATE = new HashSet<>(Arrays.asList(Material.TORCH, Material.WALL_TORCH, Material.REDSTONE_WIRE, Material.RAIL, Material.POWERED_RAIL, Material.DETECTOR_RAIL, Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER, Material.LEVER, Material.REDSTONE_TORCH, Material.REDSTONE_WALL_TORCH, Material.GLOWSTONE, Material.JACK_O_LANTERN, Material.REPEATER, Material.REDSTONE_LAMP, Material.BEACON, Material.COMPARATOR, Material.DAYLIGHT_DETECTOR, Material.REDSTONE_BLOCK, Material.HOPPER, Material.CHEST, Material.TRAPPED_CHEST, Material.ACTIVATOR_RAIL, Material.SOUL_TORCH, Material.SOUL_WALL_TORCH, Material.SHROOMLIGHT, Material.RESPAWN_ANCHOR, Material.CRYING_OBSIDIAN, Material.TARGET, Material.SMALL_AMETHYST_BUD, Material.MEDIUM_AMETHYST_BUD, Material.LARGE_AMETHYST_BUD, Material.AMETHYST_CLUSTER, Material.CAVE_VINES, Material.CAVE_VINES_PLANT, Material.GLOW_LICHEN, Material.LIGHT, Material.LAVA_CAULDRON, Material.CHISELED_BOOKSHELF));
}
}

View File

@ -1716,7 +1716,27 @@ public class Rollback extends Queue {
modifiedArmor = addedItem ? setArmor : modifiedArmor;
}
if (!addedItem) {
addedItem = (inventory.addItem(itemstack).size() == 0);
if (type.name().equals("CHISELED_BOOKSHELF")) {
ItemStack[] inventoryContents = inventory.getStorageContents();
int i = 0;
for (ItemStack stack : inventoryContents) {
if (stack == null) {
inventoryContents[i] = itemstack;
addedItem = true;
break;
}
i++;
}
if (addedItem) {
inventory.setStorageContents(inventoryContents);
}
else {
addedItem = (inventory.addItem(itemstack).size() == 0);
}
}
else {
addedItem = (inventory.addItem(itemstack).size() == 0);
}
}
if (!addedItem && isPlayerInventory) {
PlayerInventory playerInventory = (PlayerInventory) inventory;

View File

@ -37,6 +37,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.BlockInventoryHolder;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@ -666,6 +667,12 @@ public final class PlayerInteractListener extends Queue implements Listener {
}
}
}
else if (type.name().equals("CHISELED_BOOKSHELF")) {
BlockState blockState = block.getState();
if (blockState instanceof BlockInventoryHolder) {
InventoryChangeListener.inventoryTransaction(player.getName(), blockState.getLocation(), null);
}
}
else if (type == Material.DRAGON_EGG) {
clickedDragonEgg(player, block);
}

View File

@ -862,7 +862,7 @@ public class Util extends Queue {
if (type == null) {
return -1;
}
return getEntityId(type.name(), true);
}