Permalink
Browse files

If using enforce type - set the sign type upon right click.

  • Loading branch information...
me4502 committed Nov 29, 2016
1 parent efb36f0 commit b3c4eef48bf98fe92c28aaf5c8e011e503dbc6c8
Showing with 33 additions and 28 deletions.
  1. +33 −28 src/main/java/com/sk89q/craftbook/mechanics/area/simple/Gate.java
@@ -62,9 +62,9 @@
/**
* Toggles the gate closest to a location.
*
- * @param player
- * @param pt
- * @param smallSearchSize
+ * @param player The player
+ * @param block The base block
+ * @param smallSearchSize Small or large search radius
* @param close null to toggle, true to close, false to open
*
* @return true if a gate was found and blocks were changed; false otherwise.
@@ -84,7 +84,7 @@ public boolean toggleGates(LocalPlayer player, Block block, boolean smallSearchS
for (int x1 = x - 1; x1 <= x + 1; x1++) {
for (int y1 = y - 2; y1 <= y + 1; y1++) {
for (int z1 = z - 1; z1 <= z + 1; z1++) {
- if (recurseColumn(player, BukkitUtil.toChangedSign(block), block.getWorld().getBlockAt(x1, y1, z1), visitedColumns, close, smallSearchSize)) {
+ if (recurseColumn(player, BukkitUtil.toChangedSign(block), block.getWorld().getBlockAt(x1, y1, z1), visitedColumns, close, true)) {
foundGate = true;
}
}
@@ -95,7 +95,7 @@ public boolean toggleGates(LocalPlayer player, Block block, boolean smallSearchS
for (int x1 = x - searchRadius; x1 <= x + searchRadius; x1++) {
for (int y1 = y - searchRadius; y1 <= y + searchRadius*2; y1++) {
for (int z1 = z - searchRadius; z1 <= z + searchRadius; z1++) {
- if (recurseColumn(player, BukkitUtil.toChangedSign(block), block.getWorld().getBlockAt(x1, y1, z1), visitedColumns, close, smallSearchSize)) {
+ if (recurseColumn(player, BukkitUtil.toChangedSign(block), block.getWorld().getBlockAt(x1, y1, z1), visitedColumns, close, false)) {
foundGate = true;
}
}
@@ -126,7 +126,7 @@ private boolean recurseColumn(LocalPlayer player, ChangedSign sign, Block block,
if (!isValidGateBlock(sign, smallSearchSize, new ItemInfo(block), true)) return false;
- CraftBookPlugin.logDebugMessage("Found a possible gate column at " + block.getX() + ":" + block.getY() + ":" + block.getZ(), "gates.search");
+ CraftBookPlugin.logDebugMessage("Found a possible gate column at " + block.getX() + ':' + block.getY() + ':' + block.getZ(), "gates.search");
int x = block.getX();
int z = block.getZ();
@@ -144,7 +144,7 @@ private boolean recurseColumn(LocalPlayer player, ChangedSign sign, Block block,
if (close == null)
close = !isValidGateBlock(sign, smallSearchSize, new ItemInfo(block.getWorld().getBlockAt(x, column.getStartingY() - 1, z)), true);
- CraftBookPlugin.logDebugMessage("Valid column at " + block.getX() + ":" + block.getY() + ":" + block.getZ() + " is being " + (close ? "closed" : "opened"), "gates.search");
+ CraftBookPlugin.logDebugMessage("Valid column at " + block.getX() + ':' + block.getY() + ':' + block.getZ() + " is being " + (close ? "closed" : "opened"), "gates.search");
CraftBookPlugin.logDebugMessage("Column Top: " + column.getStartingY() + " End: " + column.getEndingY(), "gates.search");
// Recursively go to connected fence blocks of the same level
// and 'close' or 'open' them
@@ -155,7 +155,7 @@ private boolean recurseColumn(LocalPlayer player, ChangedSign sign, Block block,
* Actually does the closing/opening. Also recurses to nearby columns.
*
* @param player The player.
- * @param signBlock The sign block.
+ * @param sign The sign block.
* @param block The top point of the gate.
* @param close To open or close.
* @param visitedColumns Previously searched columns.
@@ -171,7 +171,7 @@ private boolean toggleColumn(LocalPlayer player, ChangedSign sign, Block block,
else
item = new ItemInfo(Material.AIR, 0);
- CraftBookPlugin.logDebugMessage("Setting column at " + block.getX() + ":" + block.getY() + ":" + block.getZ() + " to " + item.toString(), "gates.search");
+ CraftBookPlugin.logDebugMessage("Setting column at " + block.getX() + ':' + block.getY() + ':' + block.getZ() + " to " + item.toString(), "gates.search");
for (Vector bl : column.getRegion()) {
@@ -206,15 +206,15 @@ private boolean toggleColumn(LocalPlayer player, ChangedSign sign, Block block,
else if (close && canPassThrough(sign, smallSearchSize, blo) && isValidGateBlock(sign, smallSearchSize, item, true) && !item.isSame(blo))
removeBlocks(sign, 1);
blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);
- } else if (close && !hasEnoughBlocks(sign, otherSign) && isValidGateBlock(sign, smallSearchSize, item, true))
+ } else if (!hasEnoughBlocks(sign, otherSign) && isValidGateBlock(sign, smallSearchSize, item, true))
if (player != null) {
player.printError("mech.not-enough-blocks");
return false;
}
} else
blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);
- CraftBookPlugin.logDebugMessage("Set block " + bl.getX() + ":" + bl.getY() + ":" + bl.getZ() + " to " + item.toString(), "gates.search");
+ CraftBookPlugin.logDebugMessage("Set block " + bl.getX() + ':' + bl.getY() + ':' + bl.getZ() + " to " + item.toString(), "gates.search");
recurseColumn(player, sign, blo.getRelative(1, 0, 0), visitedColumns, close, smallSearchSize);
recurseColumn(player, sign, blo.getRelative(-1, 0, 0), visitedColumns, close, smallSearchSize);
@@ -237,7 +237,7 @@ else if (close && canPassThrough(sign, smallSearchSize, blo) && isValidGateBlock
/**
* Raised when a block is right clicked.
*
- * @param event
+ * @param event SignClickEvent
*/
@EventHandler(priority = EventPriority.HIGH)
public void onRightClick(SignClickEvent event) {
@@ -270,6 +270,11 @@ public void onRightClick(SignClickEvent event) {
amount = Math.min(5, event.getPlayer().getItemInHand().getAmount());
addBlocks(sign, amount);
+ if (enforceType) {
+ sign.setLine(0, player.getHeldItemInfo().toString());
+ sign.update(false);
+ }
+
if (!(event.getPlayer().getGameMode() == GameMode.CREATIVE))
if (event.getPlayer().getItemInHand().getAmount() <= amount)
event.getPlayer().setItemInHand(null);
@@ -343,7 +348,7 @@ public void onSignChange(SignChangeEvent event) {
}
// get the material that this gate should toggle and verify it
String line0 = event.getLine(0).trim();
- if (line0 != null && !line0.isEmpty()) {
+ if (!line0.isEmpty()) {
if (!isValidGateBlock(new ItemInfo(line0))) {
player.printError("Line 1 needs to be a valid block id.");
SignUtil.cancelSign(event);
@@ -365,7 +370,7 @@ else if (!event.getLine(3).equalsIgnoreCase("infinite"))
}
// get the material that this gate should toggle and verify it
String line0 = event.getLine(0).trim();
- if (line0 != null && !line0.isEmpty()) {
+ if (!line0.isEmpty()) {
if (!isValidGateBlock(new ItemInfo(line0))) {
player.printError("mech.gate.valid-item");
SignUtil.cancelSign(event);
@@ -389,7 +394,7 @@ public boolean isValidGateBlock(ItemInfo block) {
/**
* Checks if a block can be used in gate.
*
- * @param signBlock The sign block.
+ * @param sign The sign block.
* @param smallSearchSize Search small or large.
* @param block The block to check.
* @param check Should search.
@@ -483,8 +488,8 @@ public ItemInfo getGateBlock(ChangedSign sign, boolean smallSearchSize) {
for (int x1 = x - 1; x1 <= x + 1; x1++) {
for (int y1 = y - 2; y1 <= y + 1; y1++) {
for (int z1 = z - 1; z1 <= z + 1; z1++) {
- if (getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), smallSearchSize) != null) {
- gateBlock = new ItemInfo(getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), smallSearchSize));
+ if (getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), true) != null) {
+ gateBlock = new ItemInfo(getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), true));
}
}
}
@@ -493,15 +498,15 @@ public ItemInfo getGateBlock(ChangedSign sign, boolean smallSearchSize) {
for (int x1 = x - searchRadius; x1 <= x + searchRadius; x1++) {
for (int y1 = y - searchRadius; y1 <= y + searchRadius*2; y1++) {
for (int z1 = z - searchRadius; z1 <= z + searchRadius; z1++) {
- if (getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), smallSearchSize) != null) {
- gateBlock = new ItemInfo(getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), smallSearchSize));
+ if (getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), false) != null) {
+ gateBlock = new ItemInfo(getFirstBlock(sign, sign.getSign().getBlock().getWorld().getBlockAt(x1, y1, z1), false));
}
}
}
}
}
- if(enforceType && gateBlock != null && gateBlock.getType() != Material.AIR && sign != null) {
+ if(enforceType && gateBlock != null && gateBlock.getType() != Material.AIR) {
sign.setLine(0, gateBlock.toString());
sign.update(false);
}
@@ -546,7 +551,7 @@ public int getBlocks(ChangedSign s, ChangedSign other) {
if (s.getLine(3).equalsIgnoreCase("infinite") || other != null && other.getLine(3).equalsIgnoreCase("infinite"))
return 0;
- int curBlocks = 0;
+ int curBlocks;
try {
curBlocks = Integer.parseInt(s.getLine(3));
if(other != null && other.getLine(0).equals(s.getLine(0))) {
@@ -669,13 +674,13 @@ public int hashCode() {
}
}
- boolean allowRedstone;
- boolean limitColumns;
- int columnLimit;
- List<ItemInfo> blocks;
- boolean enforceType;
- int columnHeight;
- int searchRadius;
+ private boolean allowRedstone;
+ private boolean limitColumns;
+ private int columnLimit;
+ private List<ItemInfo> blocks;
+ private boolean enforceType;
+ private int columnHeight;
+ private int searchRadius;
@Override
public void loadConfiguration (YAMLProcessor config, String path) {

0 comments on commit b3c4eef

Please sign in to comment.