Module: Minecraft::Commands
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
Instance Method Summary collapse
-
#addtimer(user, *args) ⇒ Object
Adds a timer to the requesting users timers, the item and frequency in seconds of the timer should be specified.
-
#board(user, target_user = nil) ⇒ Object
Checks a users points or displays the leaderboard.
-
#cancelvote(user, target_user) ⇒ Object
Cancels a kickvote initiation for a specific user.
-
#dawn ⇒ Object
Changes to dawn.
-
#day ⇒ Object
Changes to day.
-
#dehop(user, target_user) ⇒ Object
De-half-ops the target user.
-
#deltimer(user, *args) ⇒ Object
Deletes a timer from the requesting user.
-
#disco(user) ⇒ Object
Toggles disco.
-
#disturb(user, target_user) ⇒ Object
Removes somebody from the DND list.
-
#dnd(user) ⇒ Object
Stops users from disturbing you.
-
#dusk ⇒ Object
Changes to dusk.
-
#evening ⇒ Object
Changes to evening.
-
#finished(user, *args) ⇒ Object
Removes an item from the todo list.
-
#give(user, *args) ⇒ Object
Give command takes an item name or numeric id and a quantifier.
-
#help(user, command = nil) ⇒ Object
Prints the available commands for the user.
-
#hop(user, target_user) ⇒ Object
Gives half-op privileges to the target user.
-
#kickvote(user, target_user = nil) ⇒ Object
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.
-
#kickvotes(user) ⇒ Object
Displays all current kickvote initiations.
-
#kit(user, group) ⇒ Object
Kit command takes a group name and gives the contents of the kit to the target user.
-
#kitlist ⇒ Object
Prints the list of available kits to the connected players.
-
#list(user) ⇒ Object
Lists the currently connecting players, noting which is the requesting user and which users are ops.
-
#memo(user, target_user, *args) ⇒ Object
Adds a memo for the specified user.
-
#morning ⇒ Object
Changes to morning.
-
#night ⇒ Object
Changes to night.
-
#nom(user) ⇒ Object
Gives a golden apple to the specified user.
-
#om(user, *args) ⇒ Object
Gives multiple golden apples to the specified user.
-
#points(user, target_user, num_points = 1) ⇒ Object
Gives a user a specific amount of points, the quantity is capped depending on the privileges of the user.
-
#printdnd ⇒ Object
Prints the users who do not wish to be disturbed.
-
#printtime ⇒ Object
Prints the current value of the counter (seconds since server initialized).
-
#printtimer(user) ⇒ Object
Prints the requesting users current timers.
-
#property(user, key = nil) ⇒ Object
Outputs the current value of a server property.
-
#roulette(user) ⇒ Object
Kicks a random person, the requesting user has a higher cance of being picked.
-
#rules ⇒ Object
Will print the server rules to all connected players.
-
#s(user, *args) ⇒ Object
Adds a shortcut for the user with a given label.
-
#shortcuts(user) ⇒ Object
Prints the requested users shortcuts.
-
#stop(user) ⇒ Object
Stops all timers for a user.
-
#todo(user, *args) ⇒ Object
Adds or prints the current todo list items.
-
#tp(user, target) ⇒ Object
Teleports the current user to the target user.
-
#tpall(user) ⇒ Object
Teleports all users to the target user.
-
#uptime(user, target_user = nil) ⇒ Object
Checks the current uptime of the current or target user.
-
#vote(user) ⇒ Object
Votes for the last initiated kickvote.
-
#warptime(user, time_change = nil) ⇒ Object
Allows a user to specify a periodic (once every ten seconds) time change.
-
#welcome(user, *args) ⇒ Object
Changes or appends to the welcome message.
Instance Method Details
#addtimer(user, *args) ⇒ Object
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.
525 526 527 528 529 530 531 532 |
# File 'lib/minecraft/commands.rb', line 525 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 @server.puts "say Timer added for #{user}. Giving item id #{item} every #{duration} seconds." end |
#board(user, target_user = nil) ⇒ Object
ops: none
Checks a users points or displays the leaderboard.
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
ops: op
Cancels a kickvote initiation for a specific user.
295 296 297 298 299 300 301 302 |
# File 'lib/minecraft/commands.rb', line 295 def cancelvote(user, target_user) if @kickvotes.has_key? target_user @kickvotes.delete(target_user) @server.puts "say #{user} has cancelled the kickvote on #{target_user}." else @server.puts "say There is no kickvote against #{target_user} dummy." end end |
#dawn ⇒ Object
ops: op
Changes to dawn.
85 86 87 |
# File 'lib/minecraft/commands.rb', line 85 def dawn() change_time(:dawn) end |
#day ⇒ Object
ops: op
Changes to day.
103 104 105 |
# File 'lib/minecraft/commands.rb', line 103 def day() change_time(:day) end |
#dehop(user, target_user) ⇒ Object
ops: op
De-half-ops the target user.
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
ops: hop
Deletes a timer from the requesting user.
541 542 543 544 545 546 547 548 549 550 |
# File 'lib/minecraft/commands.rb', line 541 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
ops: op
Toggles disco.
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 @server.puts "say #{user} has requested disco, s/he likely can't actually dance." @disco = true end end |
#disturb(user, target_user) ⇒ Object
ops: op
Removes somebody from the DND list.
175 176 177 178 |
# File 'lib/minecraft/commands.rb', line 175 def disturb(user, target_user) @server.puts "say #{target_user} is being disturbed by #{user}!" @userdnd.reject! { |u| u == target_user.downcase } end |
#dnd(user) ⇒ Object
ops: none
Stops users from disturbing you.
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 @server.puts "say #{user} is ready to be disturbed. *cough*" @userdnd.reject! { |u| u == user } else @server.puts "say #{user} does not wish to be disturbed." @userdnd << user end end |
#dusk ⇒ Object
ops: op
Changes to dusk.
94 95 96 |
# File 'lib/minecraft/commands.rb', line 94 def dusk() change_time(:dusk) end |
#evening ⇒ Object
ops: op
Changes to evening.
130 131 132 |
# File 'lib/minecraft/commands.rb', line 130 def evening() change_time(:evening) end |
#finished(user, *args) ⇒ Object
ops: none
Removes an item from the todo list.
680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/minecraft/commands.rb', line 680 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
ops: hop
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.
366 367 368 369 370 371 |
# File 'lib/minecraft/commands.rb', line 366 def give(user, *args) item, quantity = items_arg(1, args) item = resolve_item(item) construct_give(user, item, quantity) end |
#help(user, command = nil) ⇒ Object
ops: none
Prints the available commands for the user.
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/minecraft/commands.rb', line 621 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 |
#hop(user, target_user) ⇒ Object
ops: op
Gives half-op privileges to the target user.
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
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.
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) @kickvotes[target_user] = { :tally => kick_influence(user), :votes => [user], :start => Time.now } @last_kick_vote = target_user @server.puts "say A kickvote has been initiated for #{target_user}." @server.puts "say To vote enter !kickvote #{target_user}." end end |
#kickvotes(user) ⇒ Object
ops: op
Displays all current kickvote initiations.
310 311 312 313 314 |
# File 'lib/minecraft/commands.rb', line 310 def kickvotes(user) @kickvotes.each do |target_user, data| @server.puts "say #{target_user}: #{data[:tally]} #{data[:votes].map { |u| u[0] + u[-1] }.join(", ")}" end end |
#kit(user, group) ⇒ Object
ops: hop
all: is providing kits to all.
Kit command takes a group name and gives the contents of the kit to the target user.
382 383 384 385 386 387 388 389 390 |
# File 'lib/minecraft/commands.rb', line 382 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 |
#kitlist ⇒ Object
ops: none
Prints the list of available kits to the connected players.
647 648 649 |
# File 'lib/minecraft/commands.rb', line 647 def kitlist() @server.puts "say Kits: #{KITS.keys.join(", ")}" end |
#list(user) ⇒ Object
ops: none
Lists the currently connecting players, noting which is the requesting user and which users are ops.
499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/minecraft/commands.rb', line 499 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 @server.puts "say #{l}" end |
#memo(user, target_user, *args) ⇒ Object
ops: none
Adds a memo for the specified user.
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 |
#morning ⇒ Object
ops: op
Changes to morning.
121 122 123 |
# File 'lib/minecraft/commands.rb', line 121 def morning() change_time(:morning) end |
#night ⇒ Object
ops: op
Changes to night.
112 113 114 |
# File 'lib/minecraft/commands.rb', line 112 def night() change_time(:night) end |
#nom(user) ⇒ Object
ops: hop
all: is providing noms to all.
Gives a golden apple to the specified user.
421 422 423 |
# File 'lib/minecraft/commands.rb', line 421 def nom(user) @server.puts "give #{user} 322 1" end |
#om(user, *args) ⇒ Object
ops: hop
all: is noming everybody, gross.
Gives multiple golden apples to the specified user.
433 434 435 |
# File 'lib/minecraft/commands.rb', line 433 def om(user, *args) args.length.times { nom(user) } end |
#points(user, target_user, num_points = 1) ⇒ Object
ops: none
Gives a user a specific amount of points, the quantity is capped depending on the privileges of the user.
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 @server.puts "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 @server.puts "say #{user} has given #{target_user} #{num_points} points for a total of #{@userpoints[target_user]}." end |
#printdnd ⇒ Object
Prints the users who do not wish to be disturbed.
@note: ops: op
186 187 188 |
# File 'lib/minecraft/commands.rb', line 186 def printdnd() @server.puts "say #{@userdnd.join(", ")}" end |
#printtime ⇒ Object
ops: op
Prints the current value of the counter (seconds since server initialized).
574 575 576 |
# File 'lib/minecraft/commands.rb', line 574 def printtime() @server.puts "say Timer is at #{@counter}." end |
#printtimer(user) ⇒ Object
ops: hop
Prints the requesting users current timers.
558 559 560 561 562 563 564 565 566 |
# File 'lib/minecraft/commands.rb', line 558 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
ops: op
Outputs the current value of a server property.
445 446 447 448 449 450 451 452 453 |
# File 'lib/minecraft/commands.rb', line 445 def property(user, key = nil) if key.nil? (@server_properties.length / 3.0).ceil.times do |n| @server.puts "say #{@server_properties.keys[n * 3, 3].join(", ")}" end else @server.puts "say #{key} is currently #{@server_properties[key]}" if @server_properties.include? key end end |
#roulette(user) ⇒ Object
ops: op
Kicks a random person, the requesting user has a higher cance of being picked.
323 324 325 326 327 328 |
# File 'lib/minecraft/commands.rb', line 323 def roulette(user) users = @users + [user] * 3 picked_user = users.sample @server.puts "say #{user} has requested a roulette kick, s/he has a higher chance of being kicked." @server.puts "kick #{picked_user}" end |
#rules ⇒ Object
ops: none
Will print the server rules to all connected players.
488 489 490 |
# File 'lib/minecraft/commands.rb', line 488 def rules() @server.puts "say #{@rules}" end |
#s(user, *args) ⇒ Object
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.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/minecraft/commands.rb', line 588 def s(user, *args) shortcut_name = args.slice! 0 if args.length == 0 unless @shortcuts.has_key? user and @shortcuts[user].has_key? shortcut_name return kit(user, shortcut_name) if KITS.include? shortcut_name.to_sym @server.puts "say #{shortcut_name} is not a valid shortcut for #{user}." end return call_command(user, @shortcuts[user][shortcut_name].first, *@shortcuts[user][shortcut_name][1..-1]) if args.length == 0 end command_string = args @shortcuts[user] ||= {} @shortcuts[user][shortcut_name] = command_string @server.puts "say Shortcut labelled #{shortcut_name} for #{user} has been added." end |
#shortcuts(user) ⇒ Object
ops: hop
Prints the requested users shortcuts.
610 611 612 613 |
# File 'lib/minecraft/commands.rb', line 610 def shortcuts(user) labels = @shortcuts[user].keys.join(", ") if @shortcuts.has_key? user @server.puts "say Shortcuts for #{user}: #{labels}." end |
#stop(user) ⇒ Object
ops: hop
Stops all timers for a 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
ops: none
Adds or prints the current todo list items.
659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'lib/minecraft/commands.rb', line 659 def todo(user, *args) if args.length == 0 @todo_items.each_with_index do |item, index| @server.puts "say #{index + 1}. #{item}" end return end item = args.join(" ") @todo_items << item @server.puts "say Added item." end |
#tp(user, target) ⇒ Object
ops: hop
all: is teleporting all users to their location.
Teleports the current user to the target user.
400 401 402 403 |
# File 'lib/minecraft/commands.rb', line 400 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.
410 411 412 |
# File 'lib/minecraft/commands.rb', line 410 def tpall(user) @users.each { |u| tp(u, user) unless @userdnd.include? u.downcase } end |
#uptime(user, target_user = nil) ⇒ Object
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.
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/minecraft/commands.rb', line 465 def uptime(user, target_user = nil) target_user ||= user unless @users.include? target_user if @userlog.has_key? target_user @server.puts "say #{target_user} has #{format_uptime(@userlog[target_user])} minutes of logged time." else @server.puts "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 @server.puts "say #{target_user} has been online for #{format_uptime(time_spent)} minutes.#{total}" end |
#vote(user) ⇒ Object
ops: none
Votes for the last initiated kickvote.
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
ops: op
Allows a user to specify a periodic (once every ten seconds) time change.
positive) every ten seconds.
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
ops: op
Changes or appends to the welcome message. Use !welcome + foo to add foo.
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 ("basicxman") end |