diff --git a/data/plugins/areas/wilderness.rb b/data/plugins/areas/wilderness.rb index 746c5e4f..5e97dc0f 100644 --- a/data/plugins/areas/wilderness.rb +++ b/data/plugins/areas/wilderness.rb @@ -1,35 +1,35 @@ require 'java' java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.message.impl.OpenOverlayMessage' java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.message.impl.OpenOverlayMessage' +# Constants constants related to the wilderness +module WildernessConstants -private + # The wilderness level overlay interface id + OVERLAY_INTERFACE_ID = 197 -MIN_X = 2945 -MIN_Y = 3522 -MAX_X = 3390 -MAX_Y = 3972 + # The wilderness level string id + LEVEL_STRING_ID = 199 -OVERLAY_INTERFACE_ID = 197 -LEVEL_STRING_ID = 199 +end declare_attribute(:wilderness_level, 0, :transient) # Determines the wilderness level for the specified player's position def wilderness_level(player) - return (player.position.y - (MIN_Y - 1) / 8).ceil + return ((player.position.y - 3520) / 8).ceil end area_action :wilderness_level do on_entry do |player| player.wilderness_level = wilderness_level(player) - player.interface_set.open_overlay(OVERLAY_INTERFACE_ID) - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) - show_action(ATTACK_ACTION) + player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + show_action(player, ATTACK_ACTION) end while_in do |player| @@ -37,16 +37,17 @@ area_action :wilderness_level do updated = wilderness_level(player) if (current != updated) player.wilderness_level = updated - player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) + player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}")) end end on_exit do |player| player.wilderness_level = 0 - player.interface_set.close() # TODO: Will this cause issues with other potentially open interfaces? - hide_action(ATTACK_ACTION) + player.interface_set.close() + player.send(OpenOverlayMessage.new(-1)) + hide_action(player, ATTACK_ACTION) end end -area :name => :wilderness, :coordinates => [ MIN_X, MIN_Y, MAX_X, MAX_Y, 0 ], :actions => :wilderness_level \ No newline at end of file +area :name => :wilderness, :coordinates => [ 2945, 3522, 3390, 3972, 0 ], :actions => :wilderness_level \ No newline at end of file diff --git a/data/plugins/navigation/door/door.rb b/data/plugins/navigation/door/door.rb index 7ee1af49..8d27002d 100644 --- a/data/plugins/navigation/door/door.rb +++ b/data/plugins/navigation/door/door.rb @@ -18,7 +18,7 @@ class OpenDoorAction < DistancedAction end def equals(other) - return (get_class == other.get_class && @position == other.position) + return (get_class == other.get_class && @door_object == other.door_object) end end diff --git a/data/plugins/navigation/door/util.rb b/data/plugins/navigation/door/util.rb index 33d35725..cd1fb4a4 100644 --- a/data/plugins/navigation/door/util.rb +++ b/data/plugins/navigation/door/util.rb @@ -88,7 +88,7 @@ module DoorUtil # Gets the door object at the given position, if it exists. def self.get_door_object(position, object_id) game_objects = $world.sector_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT) - game_objects.each { |game_object| return game_object if game_object.get_id == object_id } + game_objects.each { |game_object| return game_object if game_object.id == object_id } return nil end diff --git a/data/plugins/player-action/player-action.rb b/data/plugins/player-action/player-action.rb index 46144a49..edd914e4 100644 --- a/data/plugins/player-action/player-action.rb +++ b/data/plugins/player-action/player-action.rb @@ -3,6 +3,8 @@ require 'java' java_import 'org.apollo.game.message.impl.SetPlayerActionMessage' java_import 'org.apollo.game.model.entity.Player' + + class PlayerAction attr_reader :slot, :primary, :name @@ -24,7 +26,7 @@ FOLLOW_ACTION = PlayerAction.new(:fifth, true, 'Follow') # Shows multiple context menu action for the specified player def show_actions(player, *actions) - raise 'Must specify at least one action to show' if actions.nil? + raise 'Must specify at least one action' if actions.nil? actions.each do |action| player.add_action(action) @@ -39,7 +41,7 @@ end # Hides a context menu action for the specified player def hide_action(player, action) - show_action(player, PlayerAction.new('null', action.slot, action.primary)) + show_action(player, PlayerAction.new(action.slot, action.primary, 'null')) end class Player diff --git a/src/org/apollo/game/model/area/collision/CollisionMatrix.java b/src/org/apollo/game/model/area/collision/CollisionMatrix.java index 28f58106..420863cb 100644 --- a/src/org/apollo/game/model/area/collision/CollisionMatrix.java +++ b/src/org/apollo/game/model/area/collision/CollisionMatrix.java @@ -161,7 +161,8 @@ public final class CollisionMatrix { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)).toString(); + return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)) + .toString(); } /** @@ -209,8 +210,9 @@ public final class CollisionMatrix { * @throws ArrayIndexOutOfBoundsException If the specified coordinate pair does not fit in this matrix. */ private int indexOf(int x, int y) { + Preconditions.checkElementIndex(x, width, "X coordinate must be [0, " + width + "), received " + x + "."); + Preconditions.checkElementIndex(y, length, "Y coordinate must be [0, " + length + "), received " + y + "."); int index = y * width + x; - Preconditions.checkElementIndex(index, matrix.length, "Index out of bounds."); return index; } diff --git a/src/org/apollo/net/ApolloHandler.java b/src/org/apollo/net/ApolloHandler.java index 3a3a8065..78b029e6 100644 --- a/src/org/apollo/net/ApolloHandler.java +++ b/src/org/apollo/net/ApolloHandler.java @@ -100,4 +100,9 @@ public final class ApolloHandler extends ChannelInboundHandlerAdapter { } } + @Override + public void channelReadComplete(ChannelHandlerContext ctx) { + ctx.flush(); + } + } \ No newline at end of file diff --git a/src/org/apollo/net/JagGrabChannelInitializer.java b/src/org/apollo/net/JagGrabChannelInitializer.java index ca2980d9..ae860c85 100644 --- a/src/org/apollo/net/JagGrabChannelInitializer.java +++ b/src/org/apollo/net/JagGrabChannelInitializer.java @@ -14,6 +14,8 @@ import java.nio.charset.Charset; import org.apollo.net.codec.jaggrab.JagGrabRequestDecoder; import org.apollo.net.codec.jaggrab.JagGrabResponseEncoder; +import com.google.common.base.Charsets; + /** * A {@link ChannelInitializer} for the JAGGRAB protocol. * @@ -29,7 +31,7 @@ public final class JagGrabChannelInitializer extends ChannelInitializer response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA); response.writeLong(0); response.writeLong(serverSeed); - ctx.channel().writeAndFlush(response); + ctx.channel().write(response); setState(LoginDecoderState.LOGIN_HEADER); } @@ -210,7 +210,7 @@ public final class LoginDecoder extends StatefulFrameDecoder ByteBuf buffer = ctx.alloc().buffer(1); buffer.writeByte(response); - ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE); + ctx.write(buffer).addListener(ChannelFutureListener.CLOSE); } } \ No newline at end of file diff --git a/src/org/apollo/net/session/LoginSession.java b/src/org/apollo/net/session/LoginSession.java index 754f1b99..61584ecc 100644 --- a/src/org/apollo/net/session/LoginSession.java +++ b/src/org/apollo/net/session/LoginSession.java @@ -107,7 +107,7 @@ public final class LoginSession extends Session { } } - ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged)); + ChannelFuture future = channel.write(new LoginResponse(status, rights, flagged)); destroy(); diff --git a/src/org/apollo/update/OnDemandRequestWorker.java b/src/org/apollo/update/OnDemandRequestWorker.java index 7a28a0a8..949549d8 100644 --- a/src/org/apollo/update/OnDemandRequestWorker.java +++ b/src/org/apollo/update/OnDemandRequestWorker.java @@ -57,7 +57,7 @@ public final class OnDemandRequestWorker extends RequestWorker worker : workers) { - service.submit(worker); - } - } catch (Exception ex) { - System.err.println("Error adding request workers - " + ex.getMessage()); + } catch (FileNotFoundException reason) { + logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason); } + + workers.forEach(service::submit); } /** * Stops the threads in the pool. */ public void stop() { - for (RequestWorker worker : workers) { - worker.stop(); - } - + workers.forEach(RequestWorker::stop); service.shutdownNow(); }