Plugin cleanup.

This commit is contained in:
Major-
2013-11-07 22:59:55 +00:00
parent 003aa082a2
commit 751b0ead4b
6 changed files with 25 additions and 50 deletions
+7 -7
View File
@@ -61,7 +61,7 @@ end
# A ScheduledTask which executes a Proc object with one argument (itself). # A ScheduledTask which executes a Proc object with one argument (itself).
class ProcScheduledTask < ScheduledTask class ProcScheduledTask < ScheduledTask
def initialize(delay, immediate, block) def initialize(delay, immediate, block)
super delay, immediate super(delay, immediate)
@block = block @block = block
end end
@@ -127,7 +127,7 @@ def on_button(args, proc)
id = args[0].to_i id = args[0].to_i
on :event, :button do |ctx, player, event| on :event, :button do |ctx, player, event|
proc.call player if event.widget_id == id proc.call(player) if event.widget_id == id
end end
end end
@@ -137,13 +137,13 @@ end
def on_event(args, proc) def on_event(args, proc)
raise "event must have one argument" unless args.length == 1 raise "event must have one argument" unless args.length == 1
evt = args[0] event = args[0]
if evt.is_a? Symbol if event.is_a? Symbol
class_name = evt.to_s.camelize.concat("Event") class_name = event.to_s.camelize.concat("Event")
evt = Java::JavaClass.for_name("org.apollo.game.event.impl.".concat(class_name)) event = Java::JavaClass.for_name("org.apollo.game.event.impl.".concat(class_name))
end end
$ctx.add_last_event_handler(evt, ProcEventHandler.new(proc)) $ctx.add_last_event_handler(event, ProcEventHandler.new(proc))
end end
# Defines an action to be taken upon a command. # Defines an action to be taken upon a command.
+4 -14
View File
@@ -1,6 +1,5 @@
require 'java' require 'java'
java_import 'org.apollo.game.model.def.NpcDefinition'
java_import 'org.apollo.game.model.Npc' java_import 'org.apollo.game.model.Npc'
java_import 'org.apollo.game.model.World' java_import 'org.apollo.game.model.World'
java_import 'org.apollo.game.model.Position' java_import 'org.apollo.game.model.Position'
@@ -9,8 +8,7 @@ blacklist = []
on :command, :spawn, RIGHTS_ADMIN do |player, command| on :command, :spawn, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
id = args[0].to_i unless [1, 3].include? args.length and (id = args[0].to_i) > -1
unless [1, 3].include? args.length and id > -1
player.send_message("Invalid syntax - ::spawn [npc id] [x] [y]") player.send_message("Invalid syntax - ::spawn [npc id] [x] [y]")
return return
end end
@@ -20,27 +18,19 @@ on :command, :spawn, RIGHTS_ADMIN do |player, command|
return return
end end
definition = NpcDefinition.lookup(id)
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(definition, position)) World.world.register(Npc.new(id, position))
end end
on :command, :mass, RIGHTS_ADMIN do |player, command| on :command, :mass, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless args.length == 2 unless args.length == 2 and (id = args[0].to_i) > -1 and (1..5).include? (range = args[1].to_i)
player.send_message("Invalid syntax - ::spawn [npc id] [range (1-5)]") player.send_message("Invalid syntax - ::spawn [npc id] [range (1-5)]")
return return
end end
id = args[0].to_i
range = args[1].to_i
unless (id > -1 and (1..5).include? range)
return player.send_message("Invalid syntax - ::spawn [npc id] [range (1-5)]")
end
if blacklist.include? id if blacklist.include? id
player.send_message("Sorry, that npc is blacklisted!") player.send_message("Sorry, that npc is blacklisted!")
return return
@@ -55,7 +45,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(NpcDefinition.lookup(id), Position.new(x, y, center_position.height))) World.world.register(Npc.new(id, Position.new(x, y, center_position.height)))
end end
end end
player.send_message("Mass spawning npcs with id #{id}.") player.send_message("Mass spawning npcs with id #{id}.")
+2 -16
View File
@@ -11,15 +11,7 @@ end
on :command, :level, RIGHTS_ADMIN do |player, command| on :command, :level, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless args.length == 2 unless args.length == 2 and (0..20).include? (skill = args[0].to_i) and (1..99).include? (level = args[1].to_i)
player.send_message("Invalid syntax - ::level [skill id] [level]")
return
end
skill = args[0].to_i
level = args[1].to_i
unless (0..20).include? skill and (1..99).include? level
player.send_message("Invalid syntax - ::level [skill id] [level]") player.send_message("Invalid syntax - ::level [skill id] [level]")
return return
end end
@@ -30,18 +22,12 @@ end
on :command, :xp, RIGHTS_ADMIN do |player, command| on :command, :xp, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless args.length == 2 unless args.length == 2 and (0..20).include? (skill = args[0].to_i)
player.send_message("Invalid syntax - ::xp [skill id] [experience]") player.send_message("Invalid syntax - ::xp [skill id] [experience]")
return return
end end
skill = args[0].to_i
experience = args[1].to_i experience = args[1].to_i
unless (0..20).include? skill
player.send_message("Invalid syntax - ::xp [skill id] [experience]")
return
end
player.skill_set.add_experience(skill, experience) player.skill_set.add_experience(skill, experience)
end end
+3 -3
View File
@@ -2,19 +2,19 @@ require 'java'
java_import 'org.apollo.game.model.Position' java_import 'org.apollo.game.model.Position'
on :command, :pos, RIGHTS_MOD do |player, command| on :command, :pos, RIGHTS_MOD do |player, command|
player.send_message "You are at: " + player.position.to_s player.send_message("You are at: #{player.position}")
end end
on :command, :tele, RIGHTS_ADMIN do |player, command| on :command, :tele, RIGHTS_ADMIN do |player, command|
args = command.arguments args = command.arguments
unless (2..3).include? args.length unless (2..3).include? args.length
player.send_message "Invalid syntax - ::tele [x] [y] [optional-z]" player.send_message("Invalid syntax - ::tele [x] [y] [optional-z]")
return return
end end
x = args[0].to_i x = args[0].to_i
y = args[1].to_i y = args[1].to_i
z = args.length == 3 ? args[2].to_i : 0 z = args.length == 3 ? args[2].to_i : player.position.height
player.teleport Position.new(x, y, z) player.teleport Position.new(x, y, z)
end end
+4 -5
View File
@@ -78,7 +78,6 @@ public final class World {
/** /**
* The command dispatcher. * The command dispatcher.
*/ */
// TODO: better place than here?
private final CommandDispatcher dispatcher = new CommandDispatcher(); private final CommandDispatcher dispatcher = new CommandDispatcher();
/** /**
@@ -92,20 +91,21 @@ public final class World {
private final CharacterRepository<Player> playerRepository = new CharacterRepository<Player>( private final CharacterRepository<Player> playerRepository = new CharacterRepository<Player>(
WorldConstants.MAXIMUM_PLAYERS); WorldConstants.MAXIMUM_PLAYERS);
/**
* The {@link PluginManager}.
*/
// TODO: better place than here!! // TODO: better place than here!!
private PluginManager pluginManager; private PluginManager pluginManager;
/** /**
* The scheduler. * The scheduler.
*/ */
// TODO: better place than here?
private final Scheduler scheduler = new Scheduler(); private final Scheduler scheduler = new Scheduler();
/** /**
* Creates the world. * Creates the world.
*/ */
private World() { private World() {
} }
/** /**
@@ -246,12 +246,11 @@ public final class World {
if (success) { if (success) {
logger.info("Registered player: " + player + " [online=" + playerRepository.size() + "]"); logger.info("Registered player: " + player + " [online=" + playerRepository.size() + "]");
return RegistrationStatus.OK; return RegistrationStatus.OK;
} else { }
logger.warning("Failed to register player (server full): " + player + " [online=" + playerRepository.size() logger.warning("Failed to register player (server full): " + player + " [online=" + playerRepository.size()
+ "]"); + "]");
return RegistrationStatus.WORLD_FULL; return RegistrationStatus.WORLD_FULL;
} }
}
/** /**
* Schedules a new task. * Schedules a new task.
@@ -414,7 +414,7 @@ public final class ItemDefinition {
description = "Swap this note at any bank for " + prefix + " " + name + "."; description = "Swap this note at any bank for " + prefix + " " + name + ".";
stackable = true; stackable = true;
} else { } else {
throw new IllegalStateException(); throw new IllegalStateException("Item cannot be noted.");
} }
} }