Skip to content
Permalink
Browse files

Enforce types of both signs when getting the block count.

  • Loading branch information...
me4502 committed May 7, 2019
1 parent 08d4255 commit a35b840bdd52e76ea51b7040f0edd47a4b2f8f8d
Showing with 6 additions and 25 deletions.
  1. +6 −25 src/main/java/com/sk89q/craftbook/mechanics/area/simple/CuboidToggleMechanic.java
@@ -27,6 +27,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* A class that can be a mechanic that toggles a cuboid. This is basically either Door or Bridge.
@@ -241,7 +242,7 @@ public static int getBlocks(ChangedSign s, ChangedSign other) {
int curBlocks = 0;
try {
curBlocks = Integer.parseInt(s.getLine(0).split(",")[0]);
if(other != null) {
if(other != null && Objects.equals(getStoredType(other), getStoredType(s))) {
try {
curBlocks += Integer.parseInt(other.getLine(0).split(",")[0]);
setBlocks(s, curBlocks);
@@ -260,31 +261,11 @@ public static boolean hasEnoughBlocks(ChangedSign s, ChangedSign other) {
return s.getLine(0).split(",")[0].equalsIgnoreCase("infinite") || getBlocks(s, other) > 0;
}

public BlockData getStoredType(Block block) {
Block farBlock = getFarSign(block);
if (farBlock == null) {
return null;
public static BlockData getStoredType(ChangedSign sign) {
if (sign.getLine(0).contains(",")) {
return BlockSyntax.getBukkitBlock(sign.getLine(0).split(",")[1]);
}

ChangedSign closeSign = CraftBookBukkitUtil.toChangedSign(block);
ChangedSign farSign = CraftBookBukkitUtil.toChangedSign(farBlock);

BlockData type = null;

if (closeSign.getLine(0).contains(",")) {
type = BlockSyntax.getBukkitBlock(closeSign.getLine(0).split(",")[1]);
}
if (farSign.getLine(0).contains(",")) {
if (type != null) {
return null;
} else {
closeSign.setLine(0, closeSign.getLine(0) + ',' + farSign.getLine(0).split(",")[1]);
type = BlockSyntax.getBukkitBlock(farSign.getLine(0).split(",")[1]);
closeSign.update(false);
}
}

return type;
return null;
}

/**

0 comments on commit a35b840

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