Block editing of shop signs that user can't destroy (BUKKIT-1293)

This commit is contained in:
Phoenix616 2019-07-08 17:21:21 +01:00
parent 481e2bdf9e
commit 6c5e5ece81
1 changed files with 16 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
@ -13,6 +14,9 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import static com.Acrobot.ChestShop.Permission.OTHER_NAME_DESTROY;
import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE;
/**
* @author Acrobot
*/
@ -21,17 +25,26 @@ public class SignCreate implements Listener {
@EventHandler(ignoreCancelled = true)
public static void onSignChange(SignChangeEvent event) {
Block signBlock = event.getBlock();
String[] line = StringUtil.stripColourCodes(event.getLines());
if (!BlockUtil.isSign(signBlock)) {
return;
}
if (!ChestShopSign.isValidPreparedSign(line)) {
Sign sign = (Sign) signBlock.getState();
if (ChestShopSign.isValid(sign) && !NameManager.canUseName(event.getPlayer(), OTHER_NAME_DESTROY, StringUtil.stripColourCodes(sign.getLine(NAME_LINE)))) {
event.setCancelled(true);
sign.update();
return;
}
PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), (Sign) signBlock.getState(), line);
String[] lines = StringUtil.stripColourCodes(event.getLines());
if (!ChestShopSign.isValidPreparedSign(lines)) {
return;
}
PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), sign, lines);
ChestShop.callEvent(preEvent);
for (byte i = 0; i < event.getLines().length; ++i) {