Skip to content

Commit

Permalink
do not allow sign editing for chest shops
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokkonaut committed Jun 14, 2023
1 parent 581df4c commit ab9f497
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<version>1.20-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/Acrobot/Breeze/Utils/BlockUtil.java
Expand Up @@ -51,6 +51,7 @@ public class BlockUtil {
CONTAINERS.add(Material.BARREL);
CONTAINERS.addAll(SHULKER_BOXES);

SIGN_EDIT_MATERIALS.add(Material.HONEYCOMB);
SIGN_EDIT_MATERIALS.add(Material.INK_SAC);
SIGN_EDIT_MATERIALS.add(Material.GLOW_INK_SAC);
SIGN_EDIT_MATERIALS.add(Material.BLACK_DYE);
Expand Down
Expand Up @@ -9,6 +9,8 @@
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.block.sign.SignSide;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
Expand All @@ -21,6 +23,12 @@ public class SignCreate implements Listener {
@EventHandler
public static void onSignChange(SignChangeEvent event) {
Block signBlock = event.getBlock();
if (event.getSide() == Side.BACK) {
if (ChestShopSign.isValid(signBlock)) {
event.setCancelled(true);
}
return;
}
String[] line = StringUtil.stripColourCodes(event.getLines());

if (!BlockUtil.isSign(signBlock)) {
Expand All @@ -44,5 +52,12 @@ public static void onSignChange(SignChangeEvent event) {

ShopCreatedEvent postEvent = new ShopCreatedEvent(preEvent.getPlayer(), preEvent.getSign(), uBlock.findConnectedChest(preEvent.getSign()), preEvent.getSignLines());
ChestShop.callEvent(postEvent);

// clear back side
Sign sign = (Sign) signBlock.getState();
SignSide signSide = sign.getSide(Side.BACK);
for (byte i = 0; i < 4; ++i) {
signSide.setLine(i, "");
}
}
}
Expand Up @@ -90,6 +90,7 @@ public static void onInteract(PlayerInteractEvent event) {
if ((action == LEFT_CLICK_BLOCK || action == RIGHT_CLICK_BLOCK) && event.getHand() == EquipmentSlot.HAND) {
showShopInfo(player, sign);
}
event.setCancelled(true);
return;
}

Expand All @@ -99,14 +100,15 @@ public static void onInteract(PlayerInteractEvent event) {
}
if (ownShop && (!Properties.ALLOW_OWN_SHOP_TRANSACTIONS || player.isSneaking())) {
if (!Properties.ALLOW_SIGN_CHEST_OPEN || player.isSneaking() || player.isInsideVehicle() || player.getGameMode() == GameMode.CREATIVE) {
event.setCancelled(true);
return;
}

if (!Properties.ALLOW_LEFT_CLICK_DESTROYING || action != LEFT_CLICK_BLOCK) {
event.setCancelled(true);
showChestGUI(player, sign);
}

event.setCancelled(true);
return;
}

Expand Down

0 comments on commit ab9f497

Please sign in to comment.