From 5f2b1566dea076a897fb2c5879bee391cd6a899e Mon Sep 17 00:00:00 2001 From: Major- Date: Thu, 26 Feb 2015 04:30:09 +0000 Subject: [PATCH] Make minor code improvements to bootstrap, make spawn_npc return the spawned npc. --- data/plugins/bootstrap.rb | 11 ++++++++--- data/plugins/entity/spawning/npc-spawn.rb | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/plugins/bootstrap.rb b/data/plugins/bootstrap.rb index d649532b..41224dbc 100644 --- a/data/plugins/bootstrap.rb +++ b/data/plugins/bootstrap.rb @@ -39,6 +39,7 @@ end # A CommandListener that executes a Proc object with two arguments: the player and the command. class ProcCommandListener < CommandListener + def initialize(rights, block) super(rights) @block = block @@ -47,6 +48,7 @@ class ProcCommandListener < CommandListener def execute(player, command) @block.call(player, command) end + end # A LoginListener that executes a Proc object with the player argument. @@ -75,11 +77,13 @@ class ProcLogoutListener def execute(player) @block.call(player) end + end # An MessageHandler which executes a Proc object with three arguments: the chain # context, the player and the message. class ProcMessageHandler < MessageHandler + def initialize(block, option) super() # required (with brackets!), see http://jira.codehaus.org/browse/JRUBY-679 @block = block @@ -87,14 +91,14 @@ class ProcMessageHandler < MessageHandler end def handle(ctx, player, message) - if (@option == 0 || @option == message.option) - @block.call(ctx, player, message) - end + @block.call(ctx, player, message) if (@option == 0 || @option == message.option) end + end # A ScheduledTask which executes a Proc object with one argument (itself). class ProcScheduledTask < ScheduledTask + def initialize(delay, immediate, block) super(delay, immediate) @block = block @@ -103,6 +107,7 @@ class ProcScheduledTask < ScheduledTask def execute @block.call(self) end + end # Schedules a ScheduledTask. Can be used in two ways: passing an existing diff --git a/data/plugins/entity/spawning/npc-spawn.rb b/data/plugins/entity/spawning/npc-spawn.rb index 344eabd6..f5e86397 100644 --- a/data/plugins/entity/spawning/npc-spawn.rb +++ b/data/plugins/entity/spawning/npc-spawn.rb @@ -28,6 +28,7 @@ def spawn_npc(hash) raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_keys?(:x, :y) npc = get_npc(hash) spawn(npc, hash) + npc end # Spawns the specified npc and applies the properties in the hash.