Add support for Shelf item logging (#833)
* add shelf logging * bump supported version to 1.21.11 * cleanup * Update pom.xml Remove project branch definition from properties. * fix incorrect instanceof check --------- Co-authored-by: Intelli <6790859+Intelli@users.noreply.github.com>
This commit is contained in:
parent
0f0ceccb7b
commit
7386f4bd50
4 changed files with 90 additions and 1 deletions
|
|
@ -366,8 +366,18 @@ public class BukkitAdapter implements BukkitInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShelf(Material material){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> copperChestMaterials() {
|
||||
return EMPTY_SET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> shelfMaterials() {
|
||||
return EMPTY_SET;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,17 @@ public interface BukkitInterface {
|
|||
*/
|
||||
boolean isChiseledBookshelf(Material material);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a material is a shelf of any wood kind.
|
||||
*
|
||||
* @param material
|
||||
* The material to check
|
||||
* @return true if the material is a shelf, false otherwise
|
||||
*/
|
||||
boolean isShelf(Material material);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a material is a bookshelf book.
|
||||
*
|
||||
|
|
@ -441,4 +452,6 @@ public interface BukkitInterface {
|
|||
|
||||
Set<Material> copperChestMaterials();
|
||||
|
||||
Set<Material> shelfMaterials();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ import net.coreprotect.model.BlockGroup;
|
|||
* - Registry handling for named objects
|
||||
* - Updated interaction blocks
|
||||
*/
|
||||
public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
||||
public class Bukkit_v1_21 extends Bukkit_v1_20 {
|
||||
|
||||
public static Set<Material> COPPER_CHESTS = new HashSet<>(Arrays.asList());
|
||||
public static Set<Material> SHELVES = new HashSet<>(Arrays.asList());
|
||||
|
||||
/**
|
||||
* Initializes the Bukkit_v1_21 adapter with 1.21-specific block groups and mappings.
|
||||
|
|
@ -37,6 +38,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
|||
BlockGroup.INTERACT_BLOCKS.addAll(copperChestMaterials());
|
||||
BlockGroup.CONTAINERS.addAll(copperChestMaterials());
|
||||
BlockGroup.UPDATE_STATE.addAll(copperChestMaterials());
|
||||
BlockGroup.CONTAINERS.addAll(shelfMaterials());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,6 +113,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
|||
return ((Keyed) value).getKey().toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a registry value from a key string and class.
|
||||
* Used for deserializing registry objects.
|
||||
|
|
@ -177,6 +180,11 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShelf(Material material) {
|
||||
return SHELVES.contains(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> copperChestMaterials() {
|
||||
if (COPPER_CHESTS.isEmpty()) {
|
||||
|
|
@ -198,4 +206,16 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
|||
|
||||
return COPPER_CHESTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Material> shelfMaterials() {
|
||||
if (SHELVES.isEmpty()) {
|
||||
Material shelf = Material.getMaterial("OAK_SHELF");
|
||||
if (shelf != null) {
|
||||
SHELVES.addAll(Tag.WOODEN_SHELVES.getValues());
|
||||
}
|
||||
}
|
||||
|
||||
return SHELVES;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ import org.bukkit.block.Jukebox;
|
|||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.Bisected.Half;
|
||||
import org.bukkit.block.data.SideChaining.ChainPart;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.block.data.type.Bed.Part;
|
||||
import org.bukkit.block.data.type.Cake;
|
||||
import org.bukkit.block.data.type.Shelf;
|
||||
import org.bukkit.entity.EnderCrystal;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -37,6 +39,7 @@ import org.bukkit.inventory.BlockInventoryHolder;
|
|||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
|
|
@ -465,6 +468,49 @@ public final class PlayerInteractListener extends Queue implements Listener {
|
|||
InventoryChangeListener.inventoryTransaction(player.getName(), blockState.getLocation(), null);
|
||||
}
|
||||
}
|
||||
} else if (BukkitAdapter.ADAPTER.isShelf(type) ){
|
||||
BlockData blockState = block.getBlockData();
|
||||
if (blockState instanceof Shelf){
|
||||
Shelf shelf = (Shelf) blockState;
|
||||
|
||||
// ignore clicking on the back face
|
||||
if (event.getBlockFace() != shelf.getFacing()){
|
||||
return;
|
||||
}
|
||||
|
||||
if (shelf.getSideChain() == ChainPart.UNCONNECTED){
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), block.getLocation(), null);
|
||||
} else {
|
||||
Block center = block;
|
||||
Vector direction = shelf.getFacing().getDirection();
|
||||
|
||||
if (shelf.getSideChain() == ChainPart.LEFT){
|
||||
center = center.getRelative(direction.getBlockZ(), 0, -direction.getBlockX());
|
||||
} else if (shelf.getSideChain() == ChainPart.RIGHT){
|
||||
center = center.getRelative(-direction.getBlockZ(), 0, direction.getBlockX());
|
||||
}
|
||||
|
||||
BlockData centerBlockData = center.getBlockData();
|
||||
if (centerBlockData instanceof Shelf){
|
||||
// log center
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), center.getLocation(), null);
|
||||
|
||||
if (((Shelf)centerBlockData).getSideChain() != ChainPart.CENTER){
|
||||
// if it's not the center it's just a chain of 2
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), block.getLocation(), null);
|
||||
} else {
|
||||
Block left = center.getRelative(-direction.getBlockZ(), 0, direction.getBlockX());
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), left.getLocation(), null);
|
||||
|
||||
Block right = center.getRelative(direction.getBlockZ(), 0, -direction.getBlockX());
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), right.getLocation(), null);
|
||||
}
|
||||
} else {
|
||||
// fallback if invalid block is found just log clicked shelf
|
||||
InventoryChangeListener.inventoryTransaction(player.getName(), block.getLocation(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (BukkitAdapter.ADAPTER.isDecoratedPot(type)) {
|
||||
BlockState blockState = block.getState();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue