Place signs can fire sign triggers

This commit is contained in:
Daniel Saukel 2020-02-03 19:24:12 +01:00
parent ea963f8a9b
commit 054e7d9ae9
3 changed files with 35 additions and 7 deletions

View File

@ -38,7 +38,7 @@ public class PlaceSign extends DSign {
@Override
public void onInit() {
getGameWorld().addGameBlock(new PlaceableBlock(plugin, getSign().getBlock(), lines[1], lines[2]));
getGameWorld().addGameBlock(new PlaceableBlock(plugin, getGameWorld(), getSign().getBlock(), lines[1], lines[2]));
getSign().getBlock().setType(VanillaItem.AIR.getMaterial());
}

View File

@ -565,7 +565,15 @@ public class DGameWorld extends DInstanceWorld {
}
GameRuleProvider rules = game.getRules();
if (!rules.canPlaceBlocks() && !PlaceableBlock.canBuildHere(block, block.getFace(against), caliburn.getExItem(hand), this)) {
PlaceableBlock placeableBlock = null;
for (PlaceableBlock gamePlaceableBlock : placeableBlocks) {
if (gamePlaceableBlock.canPlace(block, caliburn.getExItem(hand))) {
placeableBlock = gamePlaceableBlock;
break;
}
}
if (!rules.canPlaceBlocks() && placeableBlock == null) {
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = player.getLocation();
if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
@ -581,6 +589,9 @@ public class DGameWorld extends DInstanceWorld {
return true;
}
if (placeableBlock != null) {
placeableBlock.onPlace();
}
Set<ExItem> whitelist = rules.getPlaceWhitelist();
if (whitelist == null || whitelist.contains(VanillaItem.get(block.getType()))) {

View File

@ -18,7 +18,9 @@ package de.erethon.dungeonsxl.world.block;
import de.erethon.caliburn.item.ExItem;
import de.erethon.commons.misc.BlockUtil;
import de.erethon.commons.misc.NumberUtil;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.trigger.SignTrigger;
import de.erethon.dungeonsxl.world.DGameWorld;
import java.util.HashSet;
import java.util.Set;
@ -31,13 +33,17 @@ import org.bukkit.event.block.BlockBreakEvent;
*/
public class PlaceableBlock extends GameBlock {
// Variables
private DGameWorld gameWorld;
private Set<ExItem> materials = new HashSet<>();
private Set<BlockFace> faces = new HashSet<>();
private int triggerId = -1;
public PlaceableBlock(DungeonsXL plugin, Block block, String ids, String directions) {
public PlaceableBlock(DungeonsXL plugin, DGameWorld gameWorld, Block block, String ids, String args) {
super(plugin, block);
this.gameWorld = gameWorld;
for (String id : ids.split(",")) {
ExItem item = plugin.getCaliburn().getExItem(id);
if (item != null) {
@ -46,8 +52,13 @@ public class PlaceableBlock extends GameBlock {
}
faces.add(BlockFace.SELF);
for (String direction : directions.split(",")) {
faces.add(BlockUtil.lettersToBlockFace(direction));
for (String arg : args.split(",")) {
int id = NumberUtil.parseInt(arg, -1);
if (id != -1) {
triggerId = id;
} else {
faces.add(BlockUtil.lettersToBlockFace(arg));
}
}
}
@ -57,11 +68,17 @@ public class PlaceableBlock extends GameBlock {
return false;
}
public void onPlace() {
if (triggerId != -1) {
SignTrigger.getById(triggerId, gameWorld).onTrigger(true);
}
}
public boolean canPlace(Block toPlace, ExItem material) {
return faces.contains(toPlace.getFace(block)) && (materials.isEmpty() || materials.contains(material));
}
public static boolean canBuildHere(Block block, BlockFace blockFace, ExItem material, DGameWorld gameWorld) {
public static boolean canBuildHere(Block block, ExItem material, DGameWorld gameWorld) {
for (PlaceableBlock gamePlaceableBlock : gameWorld.getPlaceableBlocks()) {
if (gamePlaceableBlock.canPlace(block, material)) {
return true;