Skip to content
Permalink
Browse files

Support other signs types (May have a performance hit until we ditch …

…1.13 support)
  • Loading branch information...
me4502 committed Aug 17, 2019
1 parent a42a298 commit 933cb4778aaf7eeb07189d86ce18a9f4d5873c5e
@@ -335,7 +335,7 @@ private void makeItSo(CraftBookPlayer player, Block destination, BlockFace shift
int foundFree = 0;
boolean foundGround = false;
for (int i = 0; i < 5; i++) {
if (!floor.getType().isSolid() || floor.getType() == Material.WALL_SIGN) {
if (!floor.getType().isSolid() || SignUtil.isWallSign(floor)) {
foundFree++;
} else {
foundGround = true;
@@ -33,7 +33,7 @@
private static boolean isValidWallSign(Block b) {

// Must be Wall Sign
if (b == null || b.getType() != Material.WALL_SIGN) return false;
if (b == null || !SignUtil.isWallSign(b)) return false;
ChangedSign s = CraftBookBukkitUtil.toChangedSign(b);

return s.getLine(1).equalsIgnoreCase("[X]");
@@ -65,16 +65,17 @@ public boolean testBlock(Block switchBlock, BlockFace eventFace, Player player)

for(BlockFace face : LocationUtil.getDirectFaces()) {
testBlock = switchBlock.getRelative(face);
if(testBlock.getType() == Material.WALL_SIGN) {
if(SignUtil.isWallSign(testBlock)) {
s = CraftBookBukkitUtil.toChangedSign(testBlock);
break;
}
}
} else {
BlockFace face = eventFace.getOppositeFace();
testBlock = switchBlock.getRelative(face);
if(testBlock.getType() == Material.WALL_SIGN)
if(SignUtil.isWallSign(testBlock)) {
s = CraftBookBukkitUtil.toChangedSign(testBlock);
}
}

if(s == null)
@@ -40,7 +40,7 @@ public void onRightClick(SignClickEvent event) {

if(!EventUtil.passesFilter(event)) return;

if(event.getClickedBlock().getType() != Material.WALL_SIGN) return;
if(!SignUtil.isWallSign(event.getClickedBlock())) return;
if(event.getAction() != Action.RIGHT_CLICK_BLOCK) return;

ChangedSign sign = event.getSign();
@@ -253,7 +253,7 @@ public Block getFarSign(Block trigger) {
// i = settings.maxLength is actually the farthest place we're
// allowed to find the distal signpost

if (otherSide.getType() == Material.SIGN) {
if (SignUtil.isSign(otherSide)) {
String otherSignText = CraftBookBukkitUtil.toChangedSign(otherSide).getLine(1);
if (isApplicableSign(otherSignText))
break;
@@ -95,7 +95,7 @@ private boolean isCauldron(Block block) {
boolean found = false;
for(BlockFace face : faces) {
Block sign = block.getRelative(face);
if(sign.getType() == Material.WALL_SIGN) {
if(SignUtil.isWallSign(sign)) {
ChangedSign s = CraftBookBukkitUtil.toChangedSign(sign);
if(s.getLine(1).equals("[Cauldron]")) {
found = true;
@@ -91,7 +91,7 @@ public void disable() {
public Object[] setupIC(Block block, boolean create) {

// if we're not looking at a wall sign, it can't be an IC.
if (block.getType() != Material.WALL_SIGN) return null;
if (!SignUtil.isWallSign(block)) return null;
ChangedSign sign = CraftBookBukkitUtil.toChangedSign(block);

// detect the text on the sign to see if it's any kind of IC at all.
@@ -214,15 +214,15 @@ public void onBlockRedstoneChange(final SourcedBlockRedstoneEvent event) {
// abort if the current did not change
if (event.getNewCurrent() == event.getOldCurrent()) return;

if (block.getType() == Material.WALL_SIGN) {
if (SignUtil.isWallSign(block)) {
final Block source = event.getSource();
// abort if the sign is the source or the block the sign is attached to
if (SignUtil.getBackBlock(block).equals(source) || block.equals(source)) return;


Runnable runnable = () -> {

if (block.getType() != Material.WALL_SIGN) return;
if (!SignUtil.isWallSign(block)) return;
try {
ChipState chipState = ((ICFamily) icData[1]).detect(BukkitAdapter.adapt(source.getLocation()), CraftBookBukkitUtil.toChangedSign(block));
int cnt = 0;
@@ -406,7 +406,7 @@ else if(event.getLine(1).equalsIgnoreCase("[mc0421]"))
} else
suffix = "";

if (block.getType() != Material.WALL_SIGN) {
if (!SignUtil.isWallSign(block)) {
player.printError("Only wall signs are used for ICs.");
SignUtil.cancelSign(event);
return;
@@ -484,7 +484,7 @@ else if(event.getLine(1).equalsIgnoreCase("[mc0421]"))
return;
}

if (block.getType() != Material.WALL_SIGN) {
if (!SignUtil.isWallSign(block)) {
player.printError("Only wall signs are used for ICs.");
SignUtil.cancelSign(event);
return;
@@ -84,12 +84,12 @@ public void trigger(ChipState chip) {
if (!chip.getInput(0)) return;
Block left = SignUtil.getLeftBlock(CraftBookBukkitUtil.toSign(getSign()).getBlock());
ChangedSign effectSign = null;
if (left.getType() == Material.WALL_SIGN)
if (SignUtil.isWallSign(left))
effectSign = CraftBookBukkitUtil.toChangedSign(left);

Block right = SignUtil.getRightBlock(CraftBookBukkitUtil.toSign(getSign()).getBlock());
ChangedSign armourSign = null;
if (right.getType() == Material.WALL_SIGN)
if (SignUtil.isWallSign(right))
armourSign = CraftBookBukkitUtil.toChangedSign(right);

for (int i = 0; i < amount; i++) {
@@ -162,15 +162,15 @@ else if (data[0].equalsIgnoreCase("r")) {
}
}
if (upwards == null) {
if (CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0).getType() == Material.WALL_SIGN) {
if (SignUtil.isWallSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0))) {
effectSign = CraftBookBukkitUtil.toChangedSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0));
upwards = true;
} else if (CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0).getType() == Material.WALL_SIGN) {
} else if (SignUtil.isWallSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0))) {
effectSign = CraftBookBukkitUtil.toChangedSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0));
upwards = false;
} else break;
} else {
if (CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0).getType() == Material.WALL_SIGN)
if (SignUtil.isWallSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0)))
effectSign = CraftBookBukkitUtil
.toChangedSign(CraftBookBukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0));
else break;
@@ -68,9 +68,9 @@ public void onSignChange(SignChangeEvent event) {
if(ProtectionUtil.shouldUseProtection()) {
Block pistonBlock = null;

if (event.getBlock().getType() == Material.WALL_SIGN) {
if (SignUtil.isWallSign(event.getBlock())) {
pistonBlock = SignUtil.getBackBlock(event.getBlock());
} else if (event.getBlock().getType() == Material.SIGN) {
} else if (SignUtil.isStandingSign(event.getBlock())) {
if (isPiston(event.getBlock().getRelative(BlockFace.DOWN))) {
pistonBlock = event.getBlock().getRelative(BlockFace.DOWN);
} else if (isPiston(event.getBlock().getRelative(BlockFace.UP))) {
@@ -113,11 +113,11 @@ private static ChangedSign getSignOnPiston(Block block) {
for(BlockFace face : LocationUtil.getDirectFaces()) {
if(face == facing || !SignUtil.isSign(block.getRelative(face)))
continue;
if(block.getRelative(face).getType() != Material.SIGN && (face == BlockFace.UP || face == BlockFace.DOWN))
if(!SignUtil.isStandingSign(block.getRelative(face)) && (face == BlockFace.UP || face == BlockFace.DOWN))
continue;
else if (block.getRelative(face).getType() == Material.SIGN && face != BlockFace.UP && face != BlockFace.DOWN)
else if (SignUtil.isStandingSign(block.getRelative(face)) && face != BlockFace.UP && face != BlockFace.DOWN)
continue;
if(block.getRelative(face).getType() != Material.SIGN && !SignUtil.getBackBlock(block.getRelative(face)).getLocation().equals(block.getLocation()))
if(!SignUtil.isStandingSign(block.getRelative(face)) && !SignUtil.getBackBlock(block.getRelative(face)).getLocation().equals(block.getLocation()))
continue;
ChangedSign sign = CraftBookBukkitUtil.toChangedSign(block.getRelative(face));
if(sign != null && sign.getLine(1).equalsIgnoreCase("[Pipe]"))
@@ -270,7 +270,7 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS

Block off = bl.getRelative(x, y, z);

if (!isValidPipeBlock(off.getType())) continue;
if (!isValidPipeBlock(off)) continue;

if (visitedPipes.contains(off.getLocation().toVector())) continue;
visitedPipes.add(off.getLocation().toVector());
@@ -281,7 +281,7 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
searchQueue.add(off);
} else if (off.getType() == Material.GLASS_PANE || ItemUtil.isStainedGlassPane(off.getType())) {
Block offsetBlock = off.getRelative(x, y, z);
if (!isValidPipeBlock(offsetBlock.getType())) continue;
if (!isValidPipeBlock(offsetBlock)) continue;
if (visitedPipes.contains(offsetBlock.getLocation().toVector())) continue;
if(ItemUtil.isStainedGlassPane(off.getType())) {
if((ItemUtil.isStainedGlass(bl.getType())
@@ -302,15 +302,19 @@ private void searchNearbyPipes(Block block, Set<Vector> visitedPipes, List<ItemS
}
}

private static boolean isValidPipeBlock(Material typeId) {
return typeId == Material.GLASS
|| ItemUtil.isStainedGlass(typeId)
|| typeId == Material.PISTON
|| typeId == Material.STICKY_PISTON
|| typeId == Material.WALL_SIGN
|| typeId == Material.DROPPER
|| typeId == Material.GLASS_PANE
|| ItemUtil.isStainedGlassPane(typeId);
private static boolean isValidPipeBlock(Block block) {
switch (block.getType()) {
case GLASS:
case PISTON:
case STICKY_PISTON:
case DROPPER:
case GLASS_PANE:
return true;
default:
return ItemUtil.isStainedGlass(block.getType())
|| ItemUtil.isStainedGlassPane(block.getType())
|| SignUtil.isWallSign(block);
}
}

private void startPipe(Block block, List<ItemStack> items, boolean request) {
@@ -17,6 +17,8 @@
package com.sk89q.craftbook.util;

import com.sk89q.craftbook.bukkit.util.CraftBookBukkitUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockCategory;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -52,9 +54,35 @@
*/
public final class SignUtil {

private static BlockCategory SIGNS_CATEGORY;
private static BlockCategory STANDING_SIGNS_CATEGORY;
private static BlockCategory WALL_SIGNS_CATEGORY;

static {
SIGNS_CATEGORY = BlockCategory.REGISTRY.get("minecraft:signs");
STANDING_SIGNS_CATEGORY = BlockCategory.REGISTRY.get("minecraft:standing_signs");
WALL_SIGNS_CATEGORY = BlockCategory.REGISTRY.get("minecraft:wall_signs");
}

public static boolean isSign(Block block) {
if (SIGNS_CATEGORY != null) {
return SIGNS_CATEGORY.contains(BukkitAdapter.asBlockType(block.getType()));
}
return isStandingSign(block) || isWallSign(block);
}

return block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN;
public static boolean isStandingSign(Block block) {
if (STANDING_SIGNS_CATEGORY != null) {
return STANDING_SIGNS_CATEGORY.contains(BukkitAdapter.asBlockType(block.getType()));
}
return block.getType() == Material.SIGN;
}

public static boolean isWallSign(Block block) {
if (WALL_SIGNS_CATEGORY != null) {
return WALL_SIGNS_CATEGORY.contains(BukkitAdapter.asBlockType(block.getType()));
}
return block.getType() == Material.WALL_SIGN;
}

/**

0 comments on commit 933cb47

Please sign in to comment.
You can’t perform that action at this time.