Module: Minecraft::Commands

Includes:
Data
Included in:
Extensions
Defined in:
lib/minecraft/commands.rb

Overview

Contains all the methods for console commands executed by a connected player.

Constant Summary

Constants included from Data

Data::DATA_VALUE_HASH, Data::ITEM_BUCKETS, Data::KITS, Data::TIME, Data::TIME_QUOTES, Data::WOOL_COLOURS

Instance Method Summary collapse

Instance Method Details

#addtimer(user, *args) ⇒ Object

Note:

ops: hop

Adds a timer to the requesting users timers, the item and frequency in seconds of the timer should be specified. If the timer already exists for that item, the frequency is re-assigned. If the frequency is unspecified, it will default to 30.

Examples:

addtimer("basicxman", "cobblestone")
addtimer("basicxman", "arrow", "10")

Parameters:

  • user (String)

    The requesting user.

  • args

    item, frequency



529
530
531
532
533
534
535
536
# File 'lib/minecraft/commands.rb', line 529

def addtimer(user, *args)
  item, duration = items_arg(30, args)
  item = resolve_item(item)
  return @server.puts "say Timer was not added." if item.nil?
  @timers[user] ||= {}
  @timers[user][item] = duration
  say("Timer added for #{user}.  Giving item id #{item} every #{duration} seconds.")
end

#board(user, target_user = nil) ⇒ Object

Note:

ops: none

Checks a users points or displays the leaderboard.

Examples:

board("basicxman")
board("basicxman", "mike_n_7")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String) (defaults to: nil)

    The user to check points of.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/minecraft/commands.rb', line 228

def board(user, target_user = nil)
  if target_user.nil?
    leaderboard = {}
    @userpoints.each do |u, p|
      leaderboard[p] ||= []
      leaderboard[p] << u
    end
    num_to_display = 5
    leaderboard.keys.sort.reverse.each do |points|
      leaderboard[points].each do |u|
        return unless num_to_display >= 1
        @server.puts "say #{u}: #{points}"
        num_to_display -= 1
      end
    end
  else
    if @userpoints.has_key? target_user
      @server.puts "say #{u}: #{@userpoints[u]}"
    end
  end
end

#cancelvote(user, target_user) ⇒ Object

Note:

ops: op

Cancels a kickvote initiation for a specific user.

Examples:

cancelvote("basicxman", "blizzard4U")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The user which currently has a kickvote.



295
296
297
298
299
300
301
302
# File 'lib/minecraft/commands.rb', line 295

def cancelvote(user, target_user)
  if @userkickvotes.has_key? target_user
    @userkickvotes.delete(target_user)
    say("#{user} has cancelled the kickvote on #{target_user}.")
  else
    say("There is no kickvote against #{target_user} dummy.")
  end
end

#dawnObject

Note:

ops: op

Changes to dawn.

Examples:

dawn()


85
86
87
# File 'lib/minecraft/commands.rb', line 85

def dawn()
  change_time(:dawn)
end

#dayObject

Note:

ops: op

Changes to day.

Examples:

day()


103
104
105
# File 'lib/minecraft/commands.rb', line 103

def day()
  change_time(:day)
end

#dehop(user, target_user) ⇒ Object

Note:

ops: op

De-half-ops the target user.

Examples:

dehop("basicxman", "blizzard4U")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The target user to be de-hop’ed.



349
350
351
352
# File 'lib/minecraft/commands.rb', line 349

def dehop(user, target_user)
  @hops.reject! { |u| u == target_user.downcase }
  @server.puts "#{target_user} has been de-hoped, thanks #{user}!"
end

#deltimer(user, *args) ⇒ Object

Note:

ops: hop

Deletes a timer from the requesting user.

Examples:

deltimer("basicxman", "cobblestone")

Parameters:

  • user (String)

    The requesting user.

  • args

    item



545
546
547
548
549
550
551
552
553
554
# File 'lib/minecraft/commands.rb', line 545

def deltimer(user, *args)
  item = args.join(" ")
  item = resolve_item(item)
  if @timers.has_key? user
    @timers[user].delete item
    @server.puts "say #{item} timer is deleted."
  else
    @server.puts "say #{item} timer did not exist."
  end
end

#disco(user) ⇒ Object

Note:

ops: op

Toggles disco.

Examples:

disco("basicxman")

Parameters:

  • user (String)

    The requesting user.



140
141
142
143
144
145
146
147
148
149
# File 'lib/minecraft/commands.rb', line 140

def disco(user)
  @disco ||= false
  if @disco
    @server.puts "say Disco ends."
    @disco = false
  else
    say("#{user} has requested disco, s/he likely can't actually dance.")
    @disco = true
  end
end

#disturb(user, target_user) ⇒ Object

Note:

ops: op

Removes somebody from the DND list.

Examples:

disturb("basicxman", "mike_n_7")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The target user.



175
176
177
178
# File 'lib/minecraft/commands.rb', line 175

def disturb(user, target_user)
  say("#{target_user} is being disturbed by #{user}!")
  @userdnd.reject! { |u| u == target_user.downcase }
end

#dnd(user) ⇒ Object

Note:

ops: none

Stops users from disturbing you.

Examples:

dnd("basicxman")

Parameters:

  • user (String)

    The requesting user.



157
158
159
160
161
162
163
164
165
166
# File 'lib/minecraft/commands.rb', line 157

def dnd(user)
  user.downcase!
  if @userdnd.include? user
    say("#{user} is ready to be disturbed. *cough*")
    @userdnd.reject! { |u| u == user }
  else
    say("#{user} does not wish to be disturbed.")
    @userdnd << user
  end
end

#duskObject

Note:

ops: op

Changes to dusk.

Examples:

dusk()


94
95
96
# File 'lib/minecraft/commands.rb', line 94

def dusk()
  change_time(:dusk)
end

#eveningObject

Note:

ops: op

Changes to evening.

Examples:

evening()


130
131
132
# File 'lib/minecraft/commands.rb', line 130

def evening()
  change_time(:evening)
end

#finished(user, *args) ⇒ Object

Note:

ops: none

Removes an item from the todo list.

Examples:

finished("basicxman", "foo")
finished("basicxman", "2")

Parameters:

  • user (String)

    The requesting user.

  • args

    The item.



684
685
686
687
688
689
690
691
692
693
694
# File 'lib/minecraft/commands.rb', line 684

def finished(user, *args)
  item = args.join(" ")
  if item.to_i.to_s == item
    index = item.to_i - 1
  else
    index = @todo_items.find_index(item)
  end
  return @server.puts "say Item does not exist." if index.nil? or @todo_items[index].nil?
  @todo_items.slice! index
  @server.puts "say Hurray!"
end

#give(user, *args) ⇒ Object

Note:

ops: hop

Note:

all: is putting out.

Give command takes an item name or numeric id and a quantifier. If a quantifier is not specified then the quantity defaults to 1. Items will try to resolved if they are not an exact match.

Examples:

give("basicxman", "cobblestone")
give("basicxman", "cobblestone", "9m")
give("basicxman", "flint", "and", "steel", "1")
give("basicxman", "4")

Parameters:

  • user (String)

    Target user of the command.



366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/minecraft/commands.rb', line 366

def give(user, *args)
  item, quantity = items_arg(1, args)
  # For coloured wools/dyes.
  if WOOL_COLOURS.include? item
    (quantity / 64.0).ceil.times { kit(user, item) }
    item = 35
  else
    item = resolve_item(item)
  end

  construct_give(user, item, quantity)
end

#help(user, command = nil) ⇒ Object

Note:

ops: none

Prints the available commands for the user.

Examples:

help("basicxman")

Parameters:

  • user (String)

    The requesting user.



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/minecraft/commands.rb', line 625

def help(user, command = nil)
  unless command.nil?
    return @server.puts "say #{command} does not exist." unless @commands.has_key? command.to_sym
    command_signature(command.to_sym)
    say(@commands[command.to_sym][:help])
    return
  end

  commands = @commands.keys.inject([]) { |arr, key|
    priv = @commands[key][:ops]
    if is_op? user
      arr << key
    elsif is_hop? user
      priv == :op ? arr : arr << key
    else
      priv == :none ? arr << key : arr
    end
  }.map { |s| "!" + s.to_s }
  say(commands.join(", "))
end

#history(user) ⇒ Object

Note:

ops: none

Prints the last three commands executed.

Examples:

history("basicxman")

Parameters:

  • user (String)

    The requesting user.



725
726
727
728
729
730
731
732
733
# File 'lib/minecraft/commands.rb', line 725

def history(user)
  user = user.downcase
  return say("No command history found.") if not @command_history.has_key? user or @command_history[user].length == 0

  i = [@command_history[user].length, 3].min * -1
  @command_history[user][i, 3].reverse.each_with_index do |command, index|
    say("#{index + 1}. #{command.join(" ")}")
  end
end

#hop(user, target_user) ⇒ Object

Note:

ops: op

Gives half-op privileges to the target user.

Examples:

hop("basicxman", "blizzard4U")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The target user to be hop’ed.



337
338
339
340
# File 'lib/minecraft/commands.rb', line 337

def hop(user, target_user)
  @hops << target_user.downcase unless @hops.include? target_user.downcase
  @server.puts "#{target_user} is now a hop, thanks #{user}!"
end

#kickvote(user, target_user = nil) ⇒ Object

Note:

ops: none

Initiates or votes for a specific user to be kicked, since half-ops and regular connected players cannot kick users they can initiate a vote instead.

succeeds.

Examples:

kickvote("basicxman", "blizzard4U")
kickvote("basicxman")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String) (defaults to: nil)

    The target user to be kicked if the vote



261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/minecraft/commands.rb', line 261

def kickvote(user, target_user = nil)
  return @server.puts "say No user #{target_user} exists." unless @users.include? target_user
  return vote(user) if target_user.nil?
  unless submit_vote(user, target_user)
    @userkickvotes[target_user] = {
      :tally => kick_influence(user),
      :votes => [user],
      :start => Time.now
    }
    @last_kick_vote = target_user
    say("A kickvote has been initiated for #{target_user}.")
    say("To vote enter !kickvote #{target_user}.")
  end
end

#kickvotes(user) ⇒ Object

Note:

ops: op

Displays all current kickvote initiations.

Examples:

kickvotes("basicxman")

Parameters:

  • user (String)

    The requesting user.



310
311
312
313
314
# File 'lib/minecraft/commands.rb', line 310

def kickvotes(user)
  @userkickvotes.each do |target_user, data|
    say("#{target_user}: #{data[:tally]} #{data[:votes]}")
  end
end

#kit(user, group) ⇒ Object

Note:

ops: hop

Note:

all: is providing kits to all.

Kit command takes a group name and gives the contents of the kit to the target user.

Examples:

give("basicxman", "diamond")

Parameters:

  • user (String)

    Target user of the command.

  • group (String)

    Label of the kit.



388
389
390
391
392
393
394
395
396
# File 'lib/minecraft/commands.rb', line 388

def kit(user, group)
  KITS[group.to_sym].each do |item|
    if item.is_a? Array
      @server.puts construct_give(user, item.first, item.last)
    else
      @server.puts "give #{user} #{item} 1"
    end
  end
end

#kitlistObject

Note:

ops: none

Prints the list of available kits to the connected players.

Examples:

kitlist()


651
652
653
# File 'lib/minecraft/commands.rb', line 651

def kitlist()
  say("Kits: #{KITS.keys.join(", ")}")
end

#last(user, history = 1) ⇒ Object

Note:

ops: none

Executes a command from a users history.

Examples:

last("basicxman")
last("basicxman", "2")

Parameters:

  • user (String)

    The requesting user.

  • history (Integer) (defaults to: 1)

    The number of commands to look back.



704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/minecraft/commands.rb', line 704

def last(user, history = 1)
  user, history = user.downcase, history.to_i
  if not @command_history.has_key? user or @command_history[user].length < history
    return say("No command found.")
  end

  command = @command_history[user][-history]
  t = @command_history[user].length
  call_command(user, command.first, *command[1..-1])

  # process_history_addition() will not add the same command twice in a
  # row, so only slice if the command history length has changed.
  @command_history[user].slice! -1 unless @command_history[user].length == t
end

#list(user) ⇒ Object

Note:

ops: none

Lists the currently connecting players, noting which is the requesting user and which users are ops.

Examples:

list("basicxman")

Parameters:

  • user (String)

    The requesting user.



503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/minecraft/commands.rb', line 503

def list(user)
  l = @users.inject("") do |s, u|
    pre, suf = "", ""
    if u == user
      pre = "["
      suf = "]"
    end
    pre = pre + "@" if is_op? u
    pre = pre + "%" if is_hop? u
    s + "#{", " unless s.empty?}#{pre}#{u}#{suf}"
  end

  say(l)
end

#memo(user, target_user, *args) ⇒ Object

Note:

ops: none

Adds a memo for the specified user.

Examples:

memo("basicxman", "mike_n_7", "Hi!")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The target user.

  • args

    The memo.



39
40
41
42
43
44
45
46
47
48
# File 'lib/minecraft/commands.rb', line 39

def memo(user, target_user, *args)
  target_user = target_user.downcase
  if @memos.has_key? target_user and @memos[target_user].length == 5
    return @server.puts "say #{target_user} has too many memos already!"
  end

  @memos[target_user] ||= []
  @memos[target_user] << [user, args.join(" ")]
  say "Memo for #{target_user} added. Will be printed next time s/he logs in."
end

#morningObject

Note:

ops: op

Changes to morning.

Examples:

morning()


121
122
123
# File 'lib/minecraft/commands.rb', line 121

def morning()
  change_time(:morning)
end

#nightObject

Note:

ops: op

Changes to night.

Examples:

night()


112
113
114
# File 'lib/minecraft/commands.rb', line 112

def night()
  change_time(:night)
end

#nom(user) ⇒ Object

Note:

ops: hop

Note:

all: is providing noms to all.

Gives a golden apple to the specified user.

Examples:

nom("basicxman")

Parameters:

  • user (String)

    Target user.



427
428
429
# File 'lib/minecraft/commands.rb', line 427

def nom(user)
  @server.puts "give #{user} 322 1"
end

#om(user, *args) ⇒ Object

Note:

ops: hop

Note:

all: is noming everybody, gross.

Gives multiple golden apples to the specified user.

Examples:

om("basicxman", "nom", "nom", "nom")

Parameters:

  • user (String)

    Target user.

  • args

    noms!



439
440
441
# File 'lib/minecraft/commands.rb', line 439

def om(user, *args)
  args.length.times { nom(user) }
end

#points(user, target_user, num_points = 1) ⇒ Object

Note:

ops: none

Gives a user a specific amount of points, the quantity is capped depending on the privileges of the user.

Examples:

points("basicxman", "mike_n_7")
points("basicxman", "mike_n_7", "50")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String)

    The target user to give points to.

  • points (Integer)

    Quantity of points to give.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/minecraft/commands.rb', line 200

def points(user, target_user, num_points = 1)
  target_user = target_user.downcase
  num_points = num_points.to_i
  if user.downcase == target_user
    say("Did you just try to give yourself points? Sure, minus twenty.")
    @userpoints[target_user] ||= 0
    @userpoints[target_user] -= 20
    return
  elsif num_points < 0
    @server.puts "say Subtracting points? For shame."
    @userpoints[user] ||= 0
    @userpoints[user] -= num_points
    return
  end
  num_points = [num_points, cap_points(user)].min
  @userpoints[target_user] ||= 0
  @userpoints[target_user] += num_points
  say("#{user} has given #{target_user} #{num_points} points for a total of #{@userpoints[target_user]}.")
end

#printdndObject

Note:

ops: op

Prints the users who do not wish to be disturbed.

Examples:

printdnd()

Parameters:

  • user (String)

    The requesting user.



186
187
188
# File 'lib/minecraft/commands.rb', line 186

def printdnd()
  @server.puts "say #{@userdnd.join(", ")}"
end

#printtimeObject

Note:

ops: op

Prints the current value of the counter (seconds since server initialized).

Examples:

printtimer()


578
579
580
# File 'lib/minecraft/commands.rb', line 578

def printtime()
  @server.puts "say Timer is at #{@counter}."
end

#printtimer(user) ⇒ Object

Note:

ops: hop

Prints the requesting users current timers.

Examples:

printtimer("basicxman")

Parameters:

  • user (String)

    The requesting user.



562
563
564
565
566
567
568
569
570
# File 'lib/minecraft/commands.rb', line 562

def printtimer(user)
  unless @timers.has_key? user || @timers[user].length == 0
    @server.puts "say No timers have been added for #{user}."
    return
  end
  @timers[user].each do |item, frequency|
    @server.puts "say #{item} every #{frequency} seconds."
  end
end

#property(user, key = nil) ⇒ Object

Note:

ops: op

Outputs the current value of a server property.

Examples:

property("basicxman", "spawn-monsters")
property("basicxman")

Parameters:

  • user (String)

    The requesting user.

  • key (String) (defaults to: nil)

    The server property requested.



451
452
453
454
455
456
457
# File 'lib/minecraft/commands.rb', line 451

def property(user, key = nil)
  if key.nil?
    say(@server_properties.keys.join(", "))
  else
    say ("#{key} is currently #{@server_properties[key]}") if @server_properties.include? key
  end
end

#roulette(user) ⇒ Object

Note:

ops: op

Kicks a random person, the requesting user has a higher cance of being picked.

Examples:

roulette("basicxman")

Parameters:

  • user (String)

    The requesting user.



323
324
325
326
327
328
# File 'lib/minecraft/commands.rb', line 323

def roulette(user)
  users = @users + [user] * 3
  picked_user = users.sample
  say("#{user} has requested a roulette kick, s/he has a higher chance of being kicked.")
  @server.puts "kick #{picked_user}"
end

#rulesObject

Note:

ops: none

Will print the server rules to all connected players.

Examples:

rules()


492
493
494
# File 'lib/minecraft/commands.rb', line 492

def rules()
  say(@rules)
end

#s(user, *args) ⇒ Object

Note:

ops: hop

Adds a shortcut for the user with a given label. Shortcuts can only be given for custom commands. If only a label is given, the shortcut is executed.

Examples:

s("basicxman", "cobble", "give", "cobblestone", "64")
s("basicxman", "mike", "tp", "mike_n_7")

Parameters:

  • user (String)

    The requesting user.

  • args

    label, command array



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/minecraft/commands.rb', line 592

def s(user, *args)
  shortcut_name = args.slice! 0
  if args.length == 0
    unless @usershortcuts.has_key? user and @usershortcuts[user].has_key? shortcut_name
      return kit(user, shortcut_name) if KITS.include? shortcut_name.to_sym
      return say("#{shortcut_name} is not a valid shortcut for #{user}.")
    end
    return call_command(user, @usershortcuts[user][shortcut_name].first, *@usershortcuts[user][shortcut_name][1..-1]) if args.length == 0
  end

  command_string = args
  @usershortcuts[user] ||= {}
  @usershortcuts[user][shortcut_name] = command_string
  say("Shortcut labelled #{shortcut_name} for #{user} has been added.")
end

#shortcuts(user) ⇒ Object

Note:

ops: hop

Prints the requested users shortcuts.

Examples:

shortcuts("basicxman")

Parameters:

  • user (String)

    The requesting user.



614
615
616
617
# File 'lib/minecraft/commands.rb', line 614

def shortcuts(user)
  labels = @usershortcuts[user].keys.join(", ") if @usershortcuts.has_key? user
  say("Shortcuts for #{user}: #{labels}.")
end

#stop(user) ⇒ Object

Note:

ops: hop

Stops all timers for a user.

Examples:

stop("basicxman")

Parameters:

  • user (String)

    The requesting user.



56
57
58
59
# File 'lib/minecraft/commands.rb', line 56

def stop(user)
  @timers.delete user
  @server.puts "say #{user} has stopped all his/her timers."
end

#todo(user, *args) ⇒ Object

Note:

ops: none

Adds or prints the current todo list items.

Examples:

todo("basicxman", "foo")
todo("basicxman")

Parameters:

  • user (String)

    The requesting user.

  • args

    The item.



663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/minecraft/commands.rb', line 663

def todo(user, *args)
  if args.length == 0
    @todo_items.each_with_index do |item, index|
      say("say #{index + 1}. #{item}")
    end
    return
  end

  item = args.join(" ")
  @todo_items << item
  @server.puts "say Added item."
end

#tp(user, target) ⇒ Object

Note:

ops: hop

Note:

all: is teleporting all users to their location.

Teleports the current user to the target user.

Examples:

tp("basicxman", "mike_n_7")

Parameters:

  • user (String)

    Current user.

  • target (String)

    User to teleport to.



406
407
408
409
# File 'lib/minecraft/commands.rb', line 406

def tp(user, target)
  return if check_dnd(target)
  @server.puts "tp #{user} #{target}"
end

#tpall(user) ⇒ Object

Teleports all users to the target user. Overrides !tpall.

Examples:

tpall("basicxman")

Parameters:

  • user (String)

    Current (target) user.



416
417
418
# File 'lib/minecraft/commands.rb', line 416

def tpall(user)
  @users.each { |u| tp(u, user) unless @userdnd.include? u.downcase }
end

#uptime(user, target_user = nil) ⇒ Object

Note:

ops: none

Checks the current uptime of the current or target user. Prints their connected uptime and their total uptime. If no target user is specified it will check the requesting user.

Examples:

uptime("basicxman")
uptime("basicxman", "mike_n_7")

Parameters:

  • user (String)

    The requesting user.

  • target_user (String) (defaults to: nil)

    The user to check.



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/minecraft/commands.rb', line 469

def uptime(user, target_user = nil)
  target_user ||= user
  unless @users.include? target_user
    if @userlog.has_key? target_user
      say("#{target_user} has #{format_uptime(@userlog[target_user])} minutes of logged time.")
    else
      say("#{target_user} Does not exist.")
    end
    return
  end

  time_spent = calculate_uptime(target_user)
  if @userlog.has_key? target_user
    total = "  Out of a total of #{format_uptime(@userlog[target_user] + time_spent)} minutes."
  end
  say("#{target_user} has been online for #{format_uptime(time_spent)} minutes.#{total}")
end

#validate_kit(group = "") ⇒ Object

Validates a kit group, if the kit cannot be found it executes the !kitlist command.



737
738
739
740
741
# File 'lib/minecraft/commands.rb', line 737

def validate_kit(group = "")
  return true if KITS.include? group.to_sym
  @server.puts "say #{group} is not a valid kit."
  kitlist
end

#vote(user) ⇒ Object

Note:

ops: none

Votes for the last initiated kickvote.

Examples:

vote("basicxman")

Parameters:

  • user (String)

    The requesting user.



282
283
284
285
286
# File 'lib/minecraft/commands.rb', line 282

def vote(user)
  unless submit_vote(user, @last_kick_vote)
    @server.puts "say No kickvote was initiated, dummy."
  end
end

#warptime(user, time_change = nil) ⇒ Object

Note:

ops: op

Allows a user to specify a periodic (once every ten seconds) time change.

positive) every ten seconds.

Examples:

warptime("basicxman", "5")
warptime("basicxman")

Parameters:

  • user (String)

    The requesting user.

  • time_change (Integer) (defaults to: nil)

    Amount of time to add (can be negative or



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/minecraft/commands.rb', line 16

def warptime(user, time_change = nil)
  if time_change.nil?
    return @server.puts "say Current rate: #{@time_change} every ten seconds." if @time_change
    return @server.puts "say No custom rate specified."
  end

  time_change = time_change.to_i
  if time_change < 0
    @time_change = [-1000, time_change].max
  else
    @time_change = [1000, time_change].min
  end
  @server.puts "say New rate: #{@time_change} every ten seconds."
end

#welcome(user, *args) ⇒ Object

Note:

ops: op

Changes or appends to the welcome message. Use !welcome + foo to add foo.

Examples:

welcome("basicxman", "Welcome", "to", "the", "server")
welcome("basicxman", "+", "%")

Parameters:

  • user (String)

    The requesting user.

  • args

    The welcome message.



69
70
71
72
73
74
75
76
77
78
# File 'lib/minecraft/commands.rb', line 69

def welcome(user, *args)
  if args.first == "+"
    @welcome_message += " " + args[1..-1].join(" ")
    @server.puts "say Appended to welcome message."
  else
    @welcome_message = args.join(" ")
    @server.puts "say Changed welcome message."
  end
  display_welcome_message("basicxman")
end