mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 08:40:08 +00:00
Prevent IndexOutOfBoundsException when using the item command.
This commit is contained in:
@@ -1,18 +1,24 @@
|
|||||||
require 'java'
|
require 'java'
|
||||||
|
|
||||||
|
# Adds the specified item to the player's own inventory.
|
||||||
on :command, :item, RIGHTS_ADMIN do |player, command|
|
on :command, :item, RIGHTS_ADMIN do |player, command|
|
||||||
args = command.arguments
|
args = command.arguments
|
||||||
if (1..2).include? args.length
|
if (1..2).include? args.length
|
||||||
id = args[0].to_i
|
id = args[0].to_i
|
||||||
amount = args.length == 2 ? args[1].to_i : 1
|
amount = args.length == 2 ? args[1].to_i : 1
|
||||||
|
if (id < 0 || id >= ItemDefinition.count)
|
||||||
|
player.send_message('The item id you specified is out of bounds!')
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
player.inventory.add(id, amount)
|
player.inventory.add(id, amount)
|
||||||
else
|
else
|
||||||
player.send_message "Syntax: ::item [id] [amount=1]"
|
player.send_message('Syntax: ::item [id] [amount=1]')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on :command, :remove, RIGHTS_ADMIN do |player, command|
|
# Removes the specified item from the player's own inventory.
|
||||||
|
on :command, :remove, RIGHTS_MOD do |player, command|
|
||||||
args = command.arguments
|
args = command.arguments
|
||||||
if (1..2).include? args.length
|
if (1..2).include? args.length
|
||||||
id = args[0].to_i
|
id = args[0].to_i
|
||||||
@@ -20,10 +26,11 @@ on :command, :remove, RIGHTS_ADMIN do |player, command|
|
|||||||
|
|
||||||
player.inventory.remove(id, amount)
|
player.inventory.remove(id, amount)
|
||||||
else
|
else
|
||||||
player.send_message "Syntax: ::remove [id] [amount=1]"
|
player.send_message('Syntax: ::remove [id] [amount=1]')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clears the player's own inventory.
|
||||||
on :command, :empty, RIGHTS_MOD do |player, command|
|
on :command, :empty, RIGHTS_MOD do |player, command|
|
||||||
player.inventory.clear
|
player.inventory.clear
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user