Add world as a global variable for plugins.

This commit is contained in:
Major-
2014-08-08 04:42:36 +01:00
parent 9469ebe297
commit 44b8972fb3
10 changed files with 19 additions and 18 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ on :event, :second_object_action do |ctx, player, event|
end
on :event, :second_npc_action do |ctx, player, event|
npc = World.world.npc_repository.get(event.index)
npc = $world.npc_repository.get(event.index)
if BANKER_NPCS.include?(npc.id)
player.start_action(BankAction.new(player, npc.position))
ctx.break_handler_chain
+2 -2
View File
@@ -119,9 +119,9 @@ def schedule(*args, &block)
raise 'Invalid combination of arguments.' unless (1..2).include?(args.length)
delay = args[0]
immediate = args.length == 2 ? args[1] : false
World.world.schedule(ProcScheduledTask.new(delay, immediate, block))
$world.schedule(ProcScheduledTask.new(delay, immediate, block))
elsif args.length == 1
World.world.schedule(args[0])
$world.schedule(args[0])
else
raise 'Invalid combination of arguments.'
end
@@ -14,7 +14,7 @@ on :event, :add_friend do |ctx, player, event|
player_username = player.username
player.add_friend(friend_username)
friend = World.world.get_player(friend_username)
friend = $world.get_player(friend_username)
if friend == nil # the friend the player added is offline
player.send(SendFriendEvent.new(friend_username, 0))
@@ -33,8 +33,8 @@ on :event, :remove_friend do |ctx, player, event|
player_username = player.username
player.remove_friend(friend_username)
if (World.world.is_player_online(friend_username))
friend = World.world.get_player(friend_username)
if ($world.is_player_online(friend_username))
friend = $world.get_player(friend_username)
friend.send(SendFriendEvent.new(player_username, 0)) if (friend.friends_with(player_username) && player.friend_privacy != PrivacyState::ON)
end
end
@@ -45,7 +45,7 @@ on :login do |player|
player.send(IgnoreListEvent.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
username = player.username
world = World.world
world = $world
iterator = player.friend_usernames.iterator # Iterate the player's friend list and notify the player that they are online if they are
while iterator.has_next
friend_username = iterator.next
@@ -70,7 +70,7 @@ end
def update_friends(player, world=0)
privacy = player.friend_privacy
iterator = World.world.player_repository.iterator
iterator = $world.player_repository.iterator
username = player.username
while iterator.has_next
@@ -5,7 +5,7 @@ java_import 'org.apollo.game.model.World'
java_import 'org.apollo.game.model.setting.PrivacyState'
on :event, :private_message do |ctx, player, event|
friend = World.world.get_player(event.username)
friend = $world.get_player(event.username)
friend.send(ForwardPrivateMessageEvent.new(player.username, player.privilege_level, event.compressed_message)) if interaction_permitted(player, friend)
end
+1 -1
View File
@@ -7,5 +7,5 @@ java_import 'org.apollo.game.model.entity.Player'
on :command, :broadcast, RIGHTS_ADMIN do |player, command|
message = command.arguments.to_a.join(" ")
broadcast = "[Broadcast] #{player.get_username.capitalize}: #{message}"
World.world.player_repository.each { |player| player.send_message(broadcast) }
$world.player_repository.each { |player| player.send_message(broadcast) }
end
+4 -4
View File
@@ -22,7 +22,7 @@ on :command, :spawn, RIGHTS_ADMIN do |player, command|
position = args.length == 1 ? player.position : Position.new(args[1].to_i, args[2].to_i, player.position.height)
World.world.register(Npc.new(id, position))
$world.register(Npc.new(id, position))
end
# Mass spawns npcs around the player.
@@ -48,7 +48,7 @@ on :command, :mass, RIGHTS_ADMIN do |player, command|
for x in minX..maxX do
for y in minY..maxY do
World.world.register(Npc.new(id, Position.new(x, y, z)))
$world.register(Npc.new(id, Position.new(x, y, z)))
end
end
player.send_message("Mass spawning npcs with id #{id}.")
@@ -56,9 +56,9 @@ end
# Unregisters all npcs from the world npc repository.
on :command, :clearnpcs, RIGHTS_ADMIN do |player, command|
iterator = World.world.npc_repository.iterator
iterator = $world.npc_repository.iterator
while iterator.has_next
World.world.unregister(iterator.next)
$world.unregister(iterator.next)
end
player.send_message('Unregistered all npcs from the world.')
end
+1 -2
View File
@@ -7,9 +7,8 @@ java_import 'org.apollo.game.model.area.SectorCoordinates'
java_import 'org.apollo.game.model.area.SectorRepository'
java_import 'org.apollo.game.model.def.ItemDefinition'
# :transient :recurrent
def spawn_npc(hash)
def spawn_item(hash)
raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an item' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_key?(:x) && hash.has_key?(:y)
z = hash.delete(:z)
+1 -1
View File
@@ -32,7 +32,7 @@ end
# Spawns the specified npc and applies the properties in the hash.
def spawn(npc, hash)
World.world.register(npc)
$world.register(npc)
unless hash.empty?
hash = decode_hash(npc.position, hash) # Use npc.position here because sector registry events (called by World.register) can be hooked
apply_decoded_hash(npc, hash) # into and someone might do something daft like move the npc immediately after it gets spawned.
+1 -1
View File
@@ -12,5 +12,5 @@
# function. The rest of the mining plugin rounds the base respawn times in
# pulses down where appropriate.
def respawn_pulses(base, players)
base - players * base / (World.world.player_repository.size * 2)
base - players * base / ($world.player_repository.size * 2)
end
@@ -5,6 +5,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apollo.game.model.World;
import org.jruby.embed.ScriptingContainer;
/**
@@ -53,6 +54,7 @@ public final class RubyPluginEnvironment implements PluginEnvironment {
@Override
public void setContext(PluginContext context) {
container.put("$ctx", context);
container.put("$world", World.getWorld());
}
}