Prevent players from breaking shops while they are conversing, Fixes #7
This commit is contained in:
parent
e4d4ebb8b4
commit
e49906fc75
|
|
@ -23,10 +23,12 @@ public class MessageConfig extends AbstractConfiguration {
|
|||
public static String SHOP_ALREADY_EXISTS = "<red>This block is already a Shop</red>";
|
||||
public static String NO_SHOP_CREATE_PERMISSION = "<red>You don't have permission to create shops.</red>";
|
||||
public static String SHOP_LIMIT_REACHED = "<red>You cannot create this shop as you already have reached the limit (<limit>).</red>";
|
||||
public static String BREAK_SHOP_WHILE_CONVERSING = "<red>You can not break shop signs while editing them.</red>";
|
||||
|
||||
void loadErrorMessages() {
|
||||
SHOP_ALREADY_EXISTS = getString("errors.shop-already-exists", SHOP_ALREADY_EXISTS);
|
||||
NO_SHOP_CREATE_PERMISSION = getString("errors.no-shop-create-permission", NO_SHOP_CREATE_PERMISSION);
|
||||
SHOP_LIMIT_REACHED = getString("errors.shop-limit-reached", SHOP_LIMIT_REACHED);
|
||||
BREAK_SHOP_WHILE_CONVERSING = getString("errors.break-shop-while-conversing", BREAK_SHOP_WHILE_CONVERSING);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.playershops.listener;
|
||||
|
||||
import com.alttd.playershops.PlayerShops;
|
||||
import com.alttd.playershops.config.MessageConfig;
|
||||
import com.alttd.playershops.handler.ShopHandler;
|
||||
import com.alttd.playershops.shop.PlayerShop;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -14,6 +15,7 @@ import org.bukkit.block.data.BlockData;
|
|||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
|
@ -99,8 +101,9 @@ public class ShopListener extends EventListener {
|
|||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onSignBlockBreak(BlockBreakEvent event) {
|
||||
if(!this.isRegistered)
|
||||
if (!this.isRegistered)
|
||||
return;
|
||||
|
||||
// this is going to be heavy, add a cache shopsignlocation <-> Shop?
|
||||
Block block = event.getBlock();
|
||||
|
||||
|
|
@ -120,7 +123,14 @@ public class ShopListener extends EventListener {
|
|||
if (shop == null)
|
||||
return;
|
||||
|
||||
if (!shopHandler.canPlayerBreakShop(event.getPlayer(), shop)) {
|
||||
Player player = event.getPlayer();
|
||||
if (!shopHandler.canPlayerBreakShop(player, shop)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.isConversing()) { // TODO enhance method to check if the conversation is about this shop
|
||||
player.sendMiniMessage(MessageConfig.BREAK_SHOP_WHILE_CONVERSING, null);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user