minecraft 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,13 @@ module Minecraft
9
9
  :ranged => [261, [262, 320]],
10
10
  :nether => [261, [262, 320], [89, 128], 278, 276],
11
11
  :portal => [[49, 14], 259],
12
- :redstone => [[331, 256], [356, 64], [69, 64], [77, 64], [70, 64]]
12
+ :redstone => [[331, 256], [356, 64], [69, 6], [77, 6], [70, 6], [76, 64], [29, 24], [4, 64]],
13
+ :circuits => [[331, 256], [356, 64], [76, 64], [4, 64]],
14
+ :cannon => [[356, 5], [331, 18], [76, 2], [4, 64], [46, 14], 77, [8, 2]],
15
+ :blacksmith => [61, [263, 16], [264, 3], [265, 32], [266, 16]],
16
+ :miner => [278, [50, 64], 277, [65, 64]],
17
+ :farmer => [293, [295, 128], 277],
18
+ :chef => [[297, 3], [296, 192], [320, 3], 357, [353, 64], 354, [350, 2]]
13
19
  }
14
20
 
15
21
  # Values for time, 0 to 24000. 0 is dawn, 12000 is dusk.
@@ -3,6 +3,7 @@ module Minecraft
3
3
  # manage custom functionality additional to default Notchian Minecraft
4
4
  # behaviour.
5
5
  class Extensions
6
+ attr_accessor :welcome_message
6
7
  include Commands
7
8
 
8
9
  # New Extensions instance.
@@ -17,6 +18,9 @@ module Minecraft
17
18
  get_json :shortcuts
18
19
  get_json :userlog
19
20
  get_json :userpoints
21
+ get_json :userdnd, []
22
+ get_json :memos
23
+ get_json :todo_items, []
20
24
  @users = []
21
25
  @counter = 0
22
26
  @logon_time = {}
@@ -30,40 +34,58 @@ module Minecraft
30
34
  @vote_threshold ||= 5
31
35
  @rules ||= "No rules specified."
32
36
 
33
- # Command set.
37
+ # Initialize the set of commands.
34
38
  @commands = {}
35
- add_command :give, :ops => :hop, :all => true, :all_message => "is putting out."
36
- add_command :tp, :ops => :hop, :all => true, :all_message => "is teleporting all users to their location."
37
- add_command :kit, :ops => :hop, :all => true, :all_message => "is providing kits to all."
38
- add_command :kitlist, :ops => :hop, :all => false
39
- add_command :help, :ops => :none, :all => false
40
- add_command :rules, :ops => :none, :all => false
41
- add_command :nom, :ops => :hop, :all => true, :all_message => "is providing noms to all."
42
- add_command :om, :ops => :hop, :all => true, :all_message => "is noming everybody, gross."
43
- add_command :list, :ops => :none, :all => false
44
- add_command :s, :ops => :hop, :all => false
45
- add_command :shortcuts, :ops => :hop, :all => false
46
- add_command :hop, :ops => :op, :all => false
47
- add_command :dehop, :ops => :op, :all => false
48
- add_command :uptime, :ops => :none, :all => false
49
- add_command :addtimer, :ops => :hop, :all => false
50
- add_command :deltimer, :ops => :hop, :all => false
51
- add_command :printtimer, :ops => :hop, :all => false
52
- add_command :printtime, :ops => :op, :all => false
53
- add_command :property, :ops => :op, :all => false
54
- add_command :morning, :ops => :op, :all => false
55
- add_command :evening, :ops => :op, :all => false
56
- add_command :day, :ops => :op, :all => false
57
- add_command :night, :ops => :op, :all => false
58
- add_command :dawn, :ops => :op, :all => false
59
- add_command :dusk, :ops => :op, :all => false
60
- add_command :roulette, :ops => :op, :all => false
61
- add_command :kickvote, :ops => :none, :all => false
62
- add_command :vote, :ops => :none, :all => false
63
- add_command :cancelvote, :ops => :op, :all => false
64
- add_command :kickvotes, :ops => :op, :all => false
65
- add_command :points, :ops => :none, :all => false
66
- add_command :board, :ops => :none, :all => false
39
+ commands = Minecraft::Commands.public_instance_methods
40
+ @command_info = File.read(method(commands.first).source_location.first).split("\n")
41
+ @enums = [ :ops ]
42
+ commands.each do |sym|
43
+ next if sym.to_s.end_with? "all"
44
+ meth = method(sym)
45
+ src_b, src_e = get_comment_range(meth.source_location.last)
46
+
47
+ @commands[sym] = {
48
+ :help => "",
49
+ :ops => :none,
50
+ :params => meth.parameters
51
+ }
52
+ parse_comments(src_b, src_e, sym)
53
+ end
54
+ end
55
+
56
+ # Parses the comments for a given command method between the two given line
57
+ # numbers. Places the results in the commands instance hash.
58
+ #
59
+ # @param [Integer] src_b Beginning comment line.
60
+ # @param [Integer] src_e Ending comment line.
61
+ # @param [Symbol] sym Method symbol.
62
+ # @example
63
+ # parse_comments(6, 13, :disco)
64
+ def parse_comments(src_b, src_e, sym)
65
+ help_done = false
66
+ (src_b..src_e).each do |n|
67
+ line = @command_info[n].strip[2..-1]
68
+ if line.nil?
69
+ help_done = true
70
+ next
71
+ elsif !help_done
72
+ @commands[sym][:help] += " " unless @commands[sym][:help].empty?
73
+ @commands[sym][:help] += line
74
+ end
75
+
76
+ if line.index("@note") == 0
77
+ key, value = line[6..-1].split(": ")
78
+ @commands[sym][key.to_sym] = @enums.include?(key.to_sym) ? value.to_sym : value
79
+ end
80
+ end
81
+ end
82
+
83
+ # Gets the line number bounds for the comments corresponding with a method
84
+ # on a given line number.
85
+ def get_comment_range(line_number)
86
+ src_e = line_number - 2
87
+ src_b = (0..src_e - 1).to_a.reverse.detect(src_e - 1) { |n| not @command_info[n] =~ /^\s+#/ } + 1
88
+ [src_b, src_e]
67
89
  end
68
90
 
69
91
  # Sets an instance variable with it's corresponding data file or a blank hash.
@@ -77,12 +99,15 @@ module Minecraft
77
99
  instance_variable_set("@#{var}", t)
78
100
  end
79
101
 
80
- # Save the user timers and shortcuts hash to a data file.
102
+ # Save instance variables to their respective JSON files.
81
103
  def save
82
104
  save_file :timers
83
105
  save_file :shortcuts
84
106
  save_file :hops
85
107
  save_file :userpoints
108
+ save_file :userdnd
109
+ save_file :memos
110
+ save_file :todo_items
86
111
  end
87
112
 
88
113
  # Save an instance hash to it's associated data file.
@@ -127,39 +152,77 @@ module Minecraft
127
152
  end
128
153
 
129
154
  is_all = @commands[root][:all] if is_all
155
+ rest_param = @commands[root][:params].count { |a| a.first == :rest }
156
+ reg_params = @commands[root][:params].count { |a| a.last != :user }
157
+
158
+ # Remove excess parameters.
159
+ args = args[0...reg_params] if args.length > reg_params and rest_param == 0
160
+
161
+ args = [user] + args unless @commands[root][:params].length == 0
130
162
  if is_all
131
- @server.puts "say #{user} #{@commands[root][:all_message]}"
163
+ @server.puts "say #{user} #{@commands[root][:all]}"
132
164
  if respond_to? command
133
- send(command, user, *args)
165
+ send(command, *args)
134
166
  else
135
- @users.each { |u| send(root, u, *args) }
167
+ @users.each { |u| send(root, u, *args[1..-1]) unless @userdnd.include? u.downcase }
136
168
  end
137
169
  else
138
- send(root, user, *args)
170
+ send(root, *args)
139
171
  end
172
+ rescue Exception => e
173
+ validate_command_entry(rest_param, reg_params, user, command, *args)
174
+ $stderr.puts "An error has occurred during a call command operation.\n#{e}"
175
+ $stderr.puts e.backtrace
140
176
  end
141
177
 
142
- # Add a command to the commands instance hash
178
+ # After an exception is caught this method should be called to find and
179
+ # print errors with the arguments specified to the command.
143
180
  #
144
- # @param [Symbol] command The command to add.
145
- # @option opts [Boolean] :all
146
- # Whether or not an all version of the command should be made available.
147
- # @option opts [Boolean] :ops
148
- # Whether or not the base command requires ops.
149
- # @option opts [String] :all_message
150
- # The message to print when the all version is used.
151
- def add_command(command, opts)
152
- @commands[command] = opts
181
+ # @param [String] user The requesting user.
182
+ # @param [String] command The requested command.
183
+ # @param args Arguments for the command.
184
+ # @example
185
+ # call_command("basicxman", "give")
186
+ def validate_command_entry(rest_param, reg_params, user, command, *args)
187
+ args.slice! 0 if args.first == user
188
+ params = @commands[command.to_sym][:params][1..-1].map { |a| [a[0], a[1].to_s.gsub("_", " ")] }
189
+ return unless args.length < reg_params
190
+
191
+ return @server.puts "say Expected at least one argument." if rest_param == 1
192
+ req_params = params.count { |a| a.first == :req }
193
+ if args.length < req_params
194
+ args.length.times { params.slice! 0 }
195
+ if params.length == 1
196
+ return @server.puts "say Expected the argument '#{params[0][1]}'"
197
+ else
198
+ temp = params.map { |a| "'#{a[1]}'" }
199
+ return @server.pust "say Expected additional arguments, #{temp.join(", ")}"
200
+ end
201
+ end
153
202
  end
154
203
 
155
204
  # Processes a line from the console.
156
205
  def process(line)
157
- puts line
206
+ puts colour(line.dup)
158
207
  return info_command(line) if line.index "INFO"
159
208
  rescue Exception => e
160
- puts "An error has occurred."
161
- puts e
162
- puts e.backtrace
209
+ $stderr.puts "An error has occurred during line processing.\n#{e}"
210
+ $stderr.puts e.backtrace
211
+ end
212
+
213
+ # Colours a server side line
214
+ def colour(line)
215
+ return line if @no_colour
216
+ line.gsub!(/^([0-9\-]{10}\s[0-9:]{8})/) { |m| "\033[0;37m#{$1}\033[0m" }
217
+ if line.index "lost connection" or line.index "logged in"
218
+ line.gsub!(/(\[INFO\]\s)(.*)/) { |m| "#{$1}\033[1;30m#{$2}\033[0m" }
219
+ elsif line.index "[INFO] CONSOLE:"
220
+ line.gsub!("CONSOLE:", "\033[1;36mCONSOLE:\033[0m")
221
+ else
222
+ line.gsub!(/(\[INFO\]\s+\<)(.*?)(\>)/) { |m| "#{$1}\033[1;34m#{$2}\033[0m#{$3}" }
223
+ line.gsub!(/(\>\s+)(!.*?)$/) { |m| "#{$1}\033[1;33m#{$2}\033[0m" }
224
+ end
225
+ return line
163
226
  end
164
227
 
165
228
  # Checks if the server needs to be saved and prints the save-all command if
@@ -183,7 +246,21 @@ module Minecraft
183
246
  def periodic
184
247
  @counter += 1
185
248
  check_save
186
- expire_kickvotes if @counter % 10 == 0
249
+ if @disco
250
+ if @counter % 2 == 0
251
+ @server.puts "time set 0"
252
+ else
253
+ @server.puts "time set 16000"
254
+ end
255
+ end
256
+
257
+ if @counter % 10 == 0
258
+ expire_kickvotes
259
+ if @time_change and @time_change != 0
260
+ @server.puts "time add #{@time_change}"
261
+ end
262
+ end
263
+
187
264
  @users.each do |user|
188
265
  next unless @timers.has_key? user
189
266
  @timers[user].each do |item, duration|
@@ -193,6 +270,20 @@ module Minecraft
193
270
  end
194
271
  end
195
272
 
273
+ # Checks the available memos for a uesr who has just logged in, prints any
274
+ # that are found.
275
+ #
276
+ # @param [String] user The user to check.
277
+ # @example
278
+ # check_memos("mike_n_7")
279
+ def check_memos(user)
280
+ user = user.downcase
281
+ return unless @memos.has_key? user
282
+
283
+ @memos[user].each { |m| say("Message from: #{m.first} - #{m.last}") }
284
+ @memos[user] = []
285
+ end
286
+
196
287
  # Removes the meta data (timestamp, INFO) from the line and then executes a
197
288
  # series of checks on the line. Grabs the user and command from the line
198
289
  # and then calls the call_command method.
@@ -201,6 +292,10 @@ module Minecraft
201
292
  def info_command(line)
202
293
  line.gsub! /^.*?\[INFO\]\s+/, ''
203
294
  return if meta_check(line)
295
+
296
+ # :foo should use the shortcut 'foo'.
297
+ line.gsub!(/^(\<.*?\>\s+):/) { |m| "#{$1}!s " }
298
+
204
299
  match_data = line.match /^\<(.*?)\>\s+!(.*?)$/
205
300
  return if match_data.nil?
206
301
 
@@ -259,6 +354,7 @@ module Minecraft
259
354
  elsif line.index "logged in"
260
355
  @users << user
261
356
  display_welcome_message(user)
357
+ check_memos(user)
262
358
  @logon_time[user] = Time.now
263
359
  return true
264
360
  end
@@ -267,7 +363,6 @@ module Minecraft
267
363
  # If a command method is called and is not specified, take in the arguments
268
364
  # here and attempt to !give the player the item. Otherwise print an error.
269
365
  def method_missing(sym, *args)
270
- return if change_time(sym)
271
366
  item, quantity = items_arg(1, [sym.to_s.downcase, args.last])
272
367
  item = resolve_item(item)
273
368
  if item and is_op? args.first
@@ -303,6 +398,19 @@ module Minecraft
303
398
  Time.now - (@logon_time[user] || 0)
304
399
  end
305
400
 
401
+ # Executes the say command with proper formatting (i.e. wrapping at sixty
402
+ # characters).
403
+ #
404
+ # @param [String] message The message to print properly.
405
+ # @example
406
+ # say("The quick brown fox jumped over the lazy dog.")
407
+ def say(message)
408
+ (message.length / 50.0).ceil.times do |n|
409
+ temp = message[(50 * n), 50]
410
+ @server.puts "say #{temp}"
411
+ end
412
+ end
413
+
306
414
  # Check if a user has op privileges.
307
415
  #
308
416
  # @param [String] user The specified user.
@@ -356,7 +464,7 @@ module Minecraft
356
464
 
357
465
  # Display a welcome message to a recently connected user.
358
466
  def display_welcome_message(user)
359
- @server.puts "say #{@welcome_message.gsub('%', user)}" unless @welcome_message.nil?
467
+ say("#{@welcome_message.gsub('%', user)}") unless @welcome_message.nil?
360
468
  end
361
469
  end
362
470
  end
@@ -36,6 +36,8 @@ module Minecraft
36
36
  # Server is stopped gracefully.
37
37
  def minecraft_exit
38
38
  puts "[+] Restoring previous mob state to #{Minecraft::Tools.toggle_mobs}." if @opts[:tempmobs]
39
+ puts "[~] The current welcome message is:"
40
+ puts @extensions.welcome_message
39
41
  puts "\n[+] Saving..."
40
42
  @extensions.save
41
43
  @threads.each(&:kill)
@@ -40,6 +40,9 @@ module Minecraft
40
40
  return new_state
41
41
  end
42
42
 
43
+ # Grabs the extension configuration file and parses it.
44
+ #
45
+ # @return [Hash] Configuration hash.
43
46
  def self.get_configuration_file
44
47
  return {} unless File.exists? "minecraft.properties"
45
48
  File.readlines("minecraft.properties").map { |l| l.split(" ") }.inject({}) do |hash, (key, *value)|
@@ -47,6 +50,12 @@ module Minecraft
47
50
  end
48
51
  end
49
52
 
53
+ # Parses a value (or set of) from a configuration file.
54
+ #
55
+ # @param [String] An array of values.
56
+ # @return [String] The string value joined together.
57
+ # @return [Boolean] Will return a boolean true if the value is blank (meant
58
+ # to be a boolean configuration flag).
50
59
  def self.config_value(value)
51
60
  return true if value.nil? or value.length == 0
52
61
  return value.join(" ")
@@ -1,5 +1,5 @@
1
1
  # Global Minecraft module.
2
2
  module Minecraft
3
3
  # Yay, keep these versions coming!
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -88,11 +88,11 @@ eof
88
88
  @ext.ops = ["basicxman"]
89
89
  @ext.hops = ["mike_n_7"]
90
90
  @ext.call_command("basicxman", "points", "Ian_zers", "1001")
91
- assert_equal 1000, @ext.userpoints["Ian_zers"]
91
+ assert_equal 1000, @ext.userpoints["ian_zers"]
92
92
  @ext.call_command("mike_n_7", "points", "Ian_zers", "501")
93
- assert_equal 1500, @ext.userpoints["Ian_zers"]
93
+ assert_equal 1500, @ext.userpoints["ian_zers"]
94
94
  @ext.call_command("blizzard4U", "points", "Ian_zers", "2")
95
- assert_equal 1501, @ext.userpoints["Ian_zers"]
95
+ assert_equal 1501, @ext.userpoints["ian_zers"]
96
96
  end
97
97
 
98
98
  sandbox_test "should not a let a user give herself points" do
@@ -175,6 +175,28 @@ eof
175
175
  assert_match "kick Ian_zers", @ext.server.string
176
176
  end
177
177
 
178
+ # Timer test.
179
+ sandbox_test "should not add a timer if the item does not exist" do
180
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
181
+ @ext.hops = ["basicxman"]
182
+ @ext.call_command("basicxman", "addtimer", "foo")
183
+ assert_nil @ext.timers["basicxman"]
184
+ assert_match "not added", @ext.server.string
185
+ end
186
+
187
+ # Stop timer test.
188
+ sandbox_test "should stop all timers" do
189
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
190
+ @ext.users = ["basicxman"]
191
+ @ext.hops = ["basicxman"]
192
+ @ext.call_command("basicxman", "addtimer", "cobblestone")
193
+ @ext.call_command("basicxman", "addtimer", "arrow")
194
+ @ext.server.string = ""
195
+ @ext.call_command("basicxman", "stop")
196
+ assert_nil @ext.timers["basicxman"]
197
+ assert_match "stopped", @ext.server.string
198
+ end
199
+
178
200
  # Time commands.
179
201
  sandbox_test "should change time with time commands" do
180
202
  @ext = Minecraft::Extensions.new(StringIO.new, {})
@@ -203,9 +225,10 @@ eof
203
225
  @ext = Minecraft::Extensions.new(StringIO.new, {})
204
226
  @ext.users = ["blizzard4U"]
205
227
  @ext.call_command("blizzard4U", "help")
206
- assert_match "rules", @ext.server.string
207
- assert_match "list", @ext.server.string
208
- refute_match "give", @ext.server.string
228
+ t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
229
+ assert_match "rules", t
230
+ assert_match "list", t
231
+ refute_match "give", t
209
232
  end
210
233
 
211
234
  sandbox_test "should display help contents for half ops" do
@@ -213,9 +236,10 @@ eof
213
236
  @ext.users = ["mike_n_7"]
214
237
  @ext.hops = ["mike_n_7"]
215
238
  @ext.call_command("mike_n_7", "help")
216
- assert_match "rules", @ext.server.string
217
- assert_match "give", @ext.server.string
218
- refute_match "morning", @ext.server.string
239
+ t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
240
+ assert_match "rules", t
241
+ assert_match "give", t
242
+ refute_match "morning", t
219
243
  end
220
244
 
221
245
  sandbox_test "should display help contents for ops" do
@@ -223,8 +247,225 @@ eof
223
247
  @ext.users = ["basicxman"]
224
248
  @ext.ops = ["basicxman"]
225
249
  @ext.call_command("basicxman", "help")
226
- assert_match "rules", @ext.server.string
227
- assert_match "give", @ext.server.string
228
- assert_match "morning", @ext.server.string
250
+ t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
251
+ assert_match "rules", t
252
+ assert_match "give", t
253
+ assert_match "morning", t
254
+ end
255
+
256
+ sandbox_test "should display help contents for a specific command" do
257
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
258
+ @ext.users = ["basicxman"]
259
+ @ext.call_command("basicxman", "help", "hop")
260
+ assert_match "privileges to the target user", @ext.server.string.gsub("\n", "")
261
+ end
262
+
263
+ sandbox_test "should display command syntaxes" do
264
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
265
+ @ext.ops = ["basicxman"]
266
+
267
+ # None
268
+ @ext.call_command("basicxman", "help", "day")
269
+ t = @ext.server.string.split("\n")
270
+ assert_equal "say !day", t[0]
271
+
272
+ # opt
273
+ @ext.server.string = ""
274
+ @ext.call_command("basicxman", "help", "warptime")
275
+ t = @ext.server.string.split("\n")
276
+ assert_equal "say !warptime", t[0]
277
+ assert_equal "say !warptime 'time change'", t[1]
278
+
279
+ # rest
280
+ @ext.server.string = ""
281
+ @ext.call_command("basicxman", "help", "welcome")
282
+ t = @ext.server.string.split("\n")
283
+ assert_equal "say !welcome 'arguments', '...'", t[0]
284
+
285
+ # req, rest
286
+ @ext.server.string = ""
287
+ @ext.call_command("basicxman", "help", "memo")
288
+ t = @ext.server.string.split("\n")
289
+ assert_equal "say !memo 'target user', 'arguments', '...'", t[0]
290
+
291
+ # req
292
+ @ext.server.string = ""
293
+ @ext.call_command("basicxman", "help", "disturb")
294
+ t = @ext.server.string.split("\n")
295
+ assert_equal "say !disturb 'target user'", t[0]
296
+
297
+ # req, opt
298
+ @ext.server.string = ""
299
+ @ext.call_command("basicxman", "help", "points")
300
+ t = @ext.server.string.split("\n")
301
+ assert_equal "say !points 'target user'", t[0]
302
+ assert_equal "say !points 'target user', 'num points'", t[1]
303
+ end
304
+
305
+ # Do not disturb testing.
306
+ sandbox_test "should not allow users in dnd to be teleported to" do
307
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
308
+ @ext.users = ["basicxman", "mike_n_7"]
309
+ @ext.hops = ["mike_n_7"]
310
+ @ext.call_command("basicxman", "dnd")
311
+ assert_equal ["basicxman"], @ext.userdnd
312
+ @ext.server.string = ""
313
+ @ext.call_command("mike_n_7", "tp", "basicxman")
314
+ assert_match "disturbed", @ext.server.string
315
+ @ext.call_command("basicxman", "dnd")
316
+ assert_equal [], @ext.userdnd
317
+ end
318
+
319
+ sandbox_test "should allow ops to use the disturb command against users" do
320
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
321
+ @ext.users = ["basicxman", "mike_n_7"]
322
+ @ext.ops = ["basicxman"]
323
+ @ext.call_command("mike_n_7", "dnd")
324
+ assert_equal ["mike_n_7"], @ext.userdnd
325
+ @ext.call_command("basicxman", "disturb", "mike_n_7")
326
+ assert_equal [], @ext.userdnd
327
+ end
328
+
329
+ # Disco.
330
+ sandbox_test "should start the disco" do
331
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
332
+ @ext.users = ["basicxman"]
333
+ @ext.ops = ["basicxman"]
334
+ @ext.call_command("basicxman", "disco")
335
+ assert_match "disco", @ext.server.string
336
+ @ext.server.string = ""
337
+ 12.times { @ext.periodic }
338
+ assert_match "time set 0", @ext.server.string
339
+ assert_match "time set 16000", @ext.server.string
340
+ end
341
+
342
+ # Teleport all.
343
+ sandbox_test "should teleport all users to an op" do
344
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
345
+ @ext.users = ["basicxman", "mike_n_7", "blizzard4U", "Ian_zers"]
346
+ @ext.ops = ["basicxman"]
347
+ @ext.call_command("basicxman", "tpall")
348
+ assert_match "mike_n_7", @ext.server.string
349
+ assert_match "blizzard4U", @ext.server.string
350
+ assert_match "Ian_zers", @ext.server.string
351
+ end
352
+
353
+ # Welcome message runtime change test.
354
+ sandbox_test "should change welcome message during runtime" do
355
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
356
+ @ext.ops = ["basicxman"]
357
+ @ext.call_command("basicxman", "welcome", "Foo bar.")
358
+ assert_equal "Foo bar.", @ext.welcome_message
359
+
360
+ @ext.call_command("basicxman", "welcome", "+", "%")
361
+ assert_equal "Foo bar. %", @ext.welcome_message
362
+ assert_match "basicxman", @ext.server.string
363
+ end
364
+
365
+ # Memos.
366
+ sandbox_test "should allow users to set memos" do
367
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
368
+ @ext.users = ["basicxman"]
369
+ @ext.call_command("basicxman", "memo", "mike_n_7", "Hi")
370
+ assert_equal ["basicxman", "Hi"], @ext.memos["mike_n_7"][0]
371
+
372
+ #@ext.check_memos("mike_n_7")
373
+ #assert_match "Hi", @ext.server.string
374
+ #assert_equal 0, @ext.memos["mike_n_7"].length
375
+ end
376
+
377
+ sandbox_test "should add and print multiple memos" do
378
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
379
+ @ext.users = ["basicxman"]
380
+ 3.times { @ext.call_command("basicxman", "memo", "mike_n_7", "Hi") }
381
+ assert_equal 3, @ext.memos["mike_n_7"].length
382
+
383
+ @ext.check_memos("mike_n_7")
384
+ assert_equal 0, @ext.memos["mike_n_7"].length
385
+ end
386
+
387
+ sandbox_test "should only allow five memos per user" do
388
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
389
+ @ext.users = ["basicxman"]
390
+ 10.times { @ext.call_command("basicxman", "memo", "mike_n_7", "Hi") }
391
+ assert_equal 5, @ext.memos["mike_n_7"].length
392
+ end
393
+
394
+ # Warping time.
395
+ sandbox_test "should warp time" do
396
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
397
+ @ext.ops = ["basicxman"]
398
+ @ext.call_command("basicxman", "warptime", "100")
399
+ 40.times { @ext.periodic }
400
+ assert_match "time add 100", @ext.server.string.gsub("\n", " ")
401
+ end
402
+
403
+ # Todo command tests.
404
+ sandbox_test "should add, list and remove global todo items" do
405
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
406
+ @ext.call_command("basicxman", "todo", "foo", "bar")
407
+ @ext.call_command("basicxman", "todo", "bar")
408
+ assert_match "Added", @ext.server.string
409
+ assert_equal "foo bar", @ext.todo_items[0]
410
+
411
+ @ext.call_command("basicxman", "todo")
412
+ assert_match "1. foo bar", @ext.server.string.split("\n")[-2]
413
+ assert_match "2. bar", @ext.server.string.split("\n")[-1]
414
+
415
+ @ext.call_command("basicxman", "finished", "foo", "bar")
416
+ @ext.call_command("basicxman", "finished", "1")
417
+ assert_match "Hurray!", @ext.server.string
418
+ assert_equal 0, @ext.todo_items.length
419
+
420
+ @ext.server.string = ""
421
+ @ext.call_command("basicxman", "finished", "2")
422
+ assert_match "not exist", @ext.server.string
423
+ @ext.server.string = ""
424
+ @ext.call_command("basicxman", "finished", "lolcats")
425
+ assert_match "not exist", @ext.server.string
426
+ end
427
+
428
+ # Remaining commands testing (should test to ensure no errors are thrown in
429
+ # the command execution).
430
+ sandbox_test "should run commands without failure" do
431
+ @ext = Minecraft::Extensions.new(StringIO.new, {})
432
+ @ext.users = ["basicxman", "mike_n_7", "blizzard4U", "Ian_zers"]
433
+ @ext.ops = ["basicxman"]
434
+ @ext.hops = ["mike_n_7"]
435
+ @ext.call_command("basicxman", "dawn")
436
+ @ext.call_command("basicxman", "dusk")
437
+ @ext.call_command("basicxman", "day")
438
+ @ext.call_command("basicxman", "night")
439
+ @ext.call_command("basicxman", "morning")
440
+ @ext.call_command("basicxman", "evening")
441
+ @ext.call_command("basicxman", "disco")
442
+ @ext.call_command("mike_n_7", "dnd")
443
+ @ext.call_command("basicxman", "printdnd")
444
+ @ext.call_command("basicxman", "disturb", "mike_n_7")
445
+ @ext.call_command("basicxman", "roulette")
446
+ @ext.call_command("basicxman", "hop", "Ian_zers")
447
+ @ext.call_command("basicxman", "dehop", "Ian_zers")
448
+ @ext.call_command("basicxman", "kit", "diamond")
449
+ @ext.call_command("basicxman", "tp", "Ian_zers")
450
+ @ext.call_command("basicxman", "tpall")
451
+ @ext.call_command("basicxman", "nom")
452
+ @ext.call_command("basicxman", "om", "nom", "nom")
453
+ @ext.call_command("basicxman", "property", "spawn-monsters")
454
+ @ext.call_command("basicxman", "property")
455
+ @ext.call_command("basicxman", "uptime")
456
+ @ext.call_command("basicxman", "uptime", "mike_n_7")
457
+ @ext.call_command("basicxman", "rules")
458
+ @ext.call_command("basicxman", "list")
459
+ @ext.call_command("basicxman", "addtimer", "cobblestone")
460
+ @ext.call_command("basicxman", "addtimer", "4", "60")
461
+ @ext.call_command("basicxman", "deltimer", "4")
462
+ @ext.call_command("basicxman", "printtimer")
463
+ @ext.call_command("basicxman", "printtime")
464
+ @ext.call_command("basicxman", "s", "foo", "give", "cobblestone")
465
+ @ext.call_command("basicxman", "s", "foo")
466
+ @ext.call_command("basicxman", "shortcuts")
467
+ @ext.call_command("basicxman", "help")
468
+ @ext.call_command("basicxman", "help", "give")
469
+ @ext.call_command("basicxman", "kitlist")
229
470
  end
230
471
  end