Skip to content

Commit

Permalink
changed a couple of failure cases to return nil, message instead of…
Browse files Browse the repository at this point in the history
… `false, message`, for consistency
  • Loading branch information
fnuecke committed Feb 12, 2014
1 parent 4f9dbf3 commit b931bae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/li/cil/oc/server/component/AbstractBus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AbstractBus(val device: IBusDevice) extends ManagedComponent with IBusDriv
busInterface.sendAllPackets()
result(true)
}
else result(false, "not enough energy")
else result(Unit, "not enough energy")
}

@Callback(direct = true, doc = """function():number -- The maximum packet size that can be sent over the bus.""")
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/li/cil/oc/server/component/GraphicsCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class GraphicsCard extends ManagedComponent {
def bind(context: Context, args: Arguments): Array[AnyRef] = {
val address = args.checkString(0)
node.network.node(address) match {
case null => result(false, "invalid address")
case null => result(Unit, "invalid address")
case node: Node if node.host.isInstanceOf[Buffer] =>
screenAddress = Option(address)
screenInstance = Some(node.host.asInstanceOf[Buffer])
Expand All @@ -66,7 +66,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.background = 0x000000
result(true)
})
case _ => result(false, "not a screen")
case _ => result(Unit, "not a screen")
}
}

Expand Down Expand Up @@ -166,7 +166,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.set(x, y, value)
result(true)
}
else result(false)
else result(Unit, "not enough energy")
})
}

Expand All @@ -182,7 +182,7 @@ abstract class GraphicsCard extends ManagedComponent {
s.copy(x, y, w, h, tx, ty)
result(true)
}
else result(false)
else result(Unit, "not enough energy")
})
}

Expand All @@ -200,7 +200,7 @@ abstract class GraphicsCard extends ManagedComponent {
result(true)
}
else {
result(false)
result(Unit, "not enough energy")
}
})
else throw new Exception("invalid fill value")
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/li/cil/oc/server/component/InternetCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class InternetCard extends ManagedComponent {
}
val address = args.checkString(0)
if (!Settings.get.httpEnabled) {
return result(false, "http requests are unavailable")
return result(Unit, "http requests are unavailable")
}
val post = if (args.isString(1)) Option(args.checkString(1)) else None
this.synchronized {
if (request.isDefined || queue.isDefined) {
return result(false, "already busy with another request")
return result(Unit, "already busy with another request")
}
scheduleRequest(address, post)
}
Expand Down Expand Up @@ -137,7 +137,9 @@ class InternetCard extends ManagedComponent {
def connect(context: Context, args: Arguments): Array[AnyRef] = {
val address = args.checkString(0)
val port = if (args.count > 1) args.checkInteger(1) else -1
if (!Settings.get.tcpEnabled) return result(false, "tcp connections are unavailable")
if (!Settings.get.tcpEnabled) {
return result(Unit, "tcp connections are unavailable")
}
if (connections.size >= Settings.get.maxConnections) {
throw new IOException("too many open connections")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
val player = context.player
val stack = player.inventory.getStackInSlot(context.selectedSlot)
if (stack == null) throw new IllegalArgumentException("selected slot is empty")
if (!TileEntityFurnace.isItemFuel(stack)) return result(false, "selected slot does not contain fuel")
if (!TileEntityFurnace.isItemFuel(stack)) {
return result(Unit, "selected slot does not contain fuel")
}
inventory match {
case Some(existingStack) =>
if (!existingStack.isItemEqual(stack) ||
!ItemStack.areItemStackTagsEqual(existingStack, stack)) {
return result(false, "different fuel type already queued")
return result(Unit, "different fuel type already queued")
}
val space = existingStack.getMaxStackSize - existingStack.stackSize
if (space <= 0) {
return result(false, "queue is full")
return result(Unit, "queue is full")
}
val moveCount = math.min(stack.stackSize, math.min(space, count))
existingStack.stackSize += moveCount
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/li/cil/oc/server/component/robot/Robot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
val sneaky = args.isBoolean(2) && args.checkBoolean(2)
val stack = player.robotInventory.selectedItemStack
if (stack == null || stack.stackSize == 0) {
return result(false, "nothing selected")
return result(Unit, "nothing selected")
}

for (side <- sides) {
Expand Down Expand Up @@ -494,16 +494,16 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
if (robot.isAnimatingMove) {
// This shouldn't really happen due to delays being enforced, but just to
// be on the safe side...
result(false, "already moving")
result(Unit, "already moving")
}
else {
val (something, what) = blockContent(robot.player(direction), direction)
if (something) {
result(false, what)
result(Unit, what)
}
else {
if (!robot.computer.node.tryChangeBuffer(-Settings.get.robotMoveCost)) {
result(false, "not enough energy")
result(Unit, "not enough energy")
}
else if (robot.move(direction)) {
context.pause(Settings.get.moveDelay)
Expand All @@ -512,7 +512,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
}
else {
robot.computer.node.changeBuffer(Settings.get.robotMoveCost)
result(false, "impossible move")
result(Unit, "impossible move")
}
}
}
Expand All @@ -529,7 +529,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
result(true)
}
else {
result(false, "not enough energy")
result(Unit, "not enough energy")
}
}

Expand Down

0 comments on commit b931bae

Please sign in to comment.