Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/net/coreprotect/bukkit/BukkitAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,18 @@ public boolean isCopperChest(Material material) {
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;
}
}
13 changes: 13 additions & 0 deletions src/main/java/net/coreprotect/bukkit/BukkitInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -441,4 +452,6 @@ public interface BukkitInterface {

Set<Material> copperChestMaterials();

Set<Material> shelfMaterials();

}
22 changes: 21 additions & 1 deletion src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
* - 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.
Expand All @@ -37,6 +38,7 @@ public Bukkit_v1_21() {
BlockGroup.INTERACT_BLOCKS.addAll(copperChestMaterials());
BlockGroup.CONTAINERS.addAll(copperChestMaterials());
BlockGroup.UPDATE_STATE.addAll(copperChestMaterials());
BlockGroup.CONTAINERS.addAll(shelfMaterials());
}

/**
Expand Down Expand Up @@ -111,6 +113,7 @@ public Object getRegistryKey(Object value) {
return ((Keyed) value).getKey().toString();
}


/**
* Gets a registry value from a key string and class.
* Used for deserializing registry objects.
Expand Down Expand Up @@ -177,6 +180,11 @@ public boolean isCopperChest(Material material) {
return false;
}

@Override
public boolean isShelf(Material material) {
return SHELVES.contains(material);
}

@Override
public Set<Material> copperChestMaterials() {
if (COPPER_CHESTS.isEmpty()) {
Expand All @@ -198,4 +206,16 @@ public Set<Material> copperChestMaterials() {

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
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;
Expand All @@ -37,6 +39,7 @@
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;
Expand Down Expand Up @@ -465,6 +468,49 @@ else if (event.getHand().equals(EquipmentSlot.OFF_HAND) && offHand != null && Bu
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();
Expand Down