mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Add world as a global variable for plugins.
This commit is contained in:
@@ -38,7 +38,7 @@ on :event, :second_object_action do |ctx, player, event|
|
|||||||
end
|
end
|
||||||
|
|
||||||
on :event, :second_npc_action do |ctx, player, event|
|
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)
|
if BANKER_NPCS.include?(npc.id)
|
||||||
player.start_action(BankAction.new(player, npc.position))
|
player.start_action(BankAction.new(player, npc.position))
|
||||||
ctx.break_handler_chain
|
ctx.break_handler_chain
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ def schedule(*args, &block)
|
|||||||
raise 'Invalid combination of arguments.' unless (1..2).include?(args.length)
|
raise 'Invalid combination of arguments.' unless (1..2).include?(args.length)
|
||||||
delay = args[0]
|
delay = args[0]
|
||||||
immediate = args.length == 2 ? args[1] : false
|
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
|
elsif args.length == 1
|
||||||
World.world.schedule(args[0])
|
$world.schedule(args[0])
|
||||||
else
|
else
|
||||||
raise 'Invalid combination of arguments.'
|
raise 'Invalid combination of arguments.'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ on :event, :add_friend do |ctx, player, event|
|
|||||||
player_username = player.username
|
player_username = player.username
|
||||||
|
|
||||||
player.add_friend(friend_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
|
if friend == nil # the friend the player added is offline
|
||||||
player.send(SendFriendEvent.new(friend_username, 0))
|
player.send(SendFriendEvent.new(friend_username, 0))
|
||||||
@@ -33,8 +33,8 @@ on :event, :remove_friend do |ctx, player, event|
|
|||||||
player_username = player.username
|
player_username = player.username
|
||||||
|
|
||||||
player.remove_friend(friend_username)
|
player.remove_friend(friend_username)
|
||||||
if (World.world.is_player_online(friend_username))
|
if ($world.is_player_online(friend_username))
|
||||||
friend = World.world.get_player(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)
|
friend.send(SendFriendEvent.new(player_username, 0)) if (friend.friends_with(player_username) && player.friend_privacy != PrivacyState::ON)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -45,7 +45,7 @@ on :login do |player|
|
|||||||
player.send(IgnoreListEvent.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
player.send(IgnoreListEvent.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
||||||
|
|
||||||
username = player.username
|
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
|
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
|
while iterator.has_next
|
||||||
friend_username = iterator.next
|
friend_username = iterator.next
|
||||||
@@ -70,7 +70,7 @@ end
|
|||||||
def update_friends(player, world=0)
|
def update_friends(player, world=0)
|
||||||
privacy = player.friend_privacy
|
privacy = player.friend_privacy
|
||||||
|
|
||||||
iterator = World.world.player_repository.iterator
|
iterator = $world.player_repository.iterator
|
||||||
username = player.username
|
username = player.username
|
||||||
|
|
||||||
while iterator.has_next
|
while iterator.has_next
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ java_import 'org.apollo.game.model.World'
|
|||||||
java_import 'org.apollo.game.model.setting.PrivacyState'
|
java_import 'org.apollo.game.model.setting.PrivacyState'
|
||||||
|
|
||||||
on :event, :private_message do |ctx, player, event|
|
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)
|
friend.send(ForwardPrivateMessageEvent.new(player.username, player.privilege_level, event.compressed_message)) if interaction_permitted(player, friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ java_import 'org.apollo.game.model.entity.Player'
|
|||||||
on :command, :broadcast, RIGHTS_ADMIN do |player, command|
|
on :command, :broadcast, RIGHTS_ADMIN do |player, command|
|
||||||
message = command.arguments.to_a.join(" ")
|
message = command.arguments.to_a.join(" ")
|
||||||
broadcast = "[Broadcast] #{player.get_username.capitalize}: #{message}"
|
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
|
end
|
||||||
@@ -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)
|
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
|
end
|
||||||
|
|
||||||
# Mass spawns npcs around the player.
|
# 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 x in minX..maxX do
|
||||||
for y in minY..maxY 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
|
||||||
end
|
end
|
||||||
player.send_message("Mass spawning npcs with id #{id}.")
|
player.send_message("Mass spawning npcs with id #{id}.")
|
||||||
@@ -56,9 +56,9 @@ end
|
|||||||
|
|
||||||
# Unregisters all npcs from the world npc repository.
|
# Unregisters all npcs from the world npc repository.
|
||||||
on :command, :clearnpcs, RIGHTS_ADMIN do |player, command|
|
on :command, :clearnpcs, RIGHTS_ADMIN do |player, command|
|
||||||
iterator = World.world.npc_repository.iterator
|
iterator = $world.npc_repository.iterator
|
||||||
while iterator.has_next
|
while iterator.has_next
|
||||||
World.world.unregister(iterator.next)
|
$world.unregister(iterator.next)
|
||||||
end
|
end
|
||||||
player.send_message('Unregistered all npcs from the world.')
|
player.send_message('Unregistered all npcs from the world.')
|
||||||
end
|
end
|
||||||
@@ -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.area.SectorRepository'
|
||||||
java_import 'org.apollo.game.model.def.ItemDefinition'
|
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)
|
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)
|
z = hash.delete(:z)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ end
|
|||||||
|
|
||||||
# Spawns the specified npc and applies the properties in the hash.
|
# Spawns the specified npc and applies the properties in the hash.
|
||||||
def spawn(npc, hash)
|
def spawn(npc, hash)
|
||||||
World.world.register(npc)
|
$world.register(npc)
|
||||||
unless hash.empty?
|
unless hash.empty?
|
||||||
hash = decode_hash(npc.position, hash) # Use npc.position here because sector registry events (called by World.register) can be hooked
|
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.
|
apply_decoded_hash(npc, hash) # into and someone might do something daft like move the npc immediately after it gets spawned.
|
||||||
|
|||||||
@@ -12,5 +12,5 @@
|
|||||||
# function. The rest of the mining plugin rounds the base respawn times in
|
# function. The rest of the mining plugin rounds the base respawn times in
|
||||||
# pulses down where appropriate.
|
# pulses down where appropriate.
|
||||||
def respawn_pulses(base, players)
|
def respawn_pulses(base, players)
|
||||||
base - players * base / (World.world.player_repository.size * 2)
|
base - players * base / ($world.player_repository.size * 2)
|
||||||
end
|
end
|
||||||
@@ -5,6 +5,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apollo.game.model.World;
|
||||||
import org.jruby.embed.ScriptingContainer;
|
import org.jruby.embed.ScriptingContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,6 +54,7 @@ public final class RubyPluginEnvironment implements PluginEnvironment {
|
|||||||
@Override
|
@Override
|
||||||
public void setContext(PluginContext context) {
|
public void setContext(PluginContext context) {
|
||||||
container.put("$ctx", context);
|
container.put("$ctx", context);
|
||||||
|
container.put("$world", World.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user