Method: Minecraft::Extensions#initialize

Defined in:
lib/minecraft/extensions.rb

#initialize(server, opts) ⇒ Extensions

New Extensions instance.

Parameters:

  • server (IO)

    The standard input pipe of the server process.

  • opts (Slop)

    Command line options from Slop.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/minecraft/extensions.rb', line 13

def initialize(server, opts)
  @ops = File.readlines("ops.txt").map { |s| s.chomp } if File.exists? "ops.txt"
  get_json :hops, []
  get_json :useruptime
  get_json :timers
  get_json :usershortcuts
  get_json :userlog
  get_json :userpoints
  get_json :userdnd, []
  get_json :memos
  get_json :todo_items, []
  get_json :command_history
  @users = []
  @counter = 0
  @logon_time = {}
  @server = server
  @userkickvotes = {}
  @last_kick_vote = nil
  load_server_properties

  @ic = Iconv.new("UTF-8//IGNORE", "UTF-8")

  opts.to_hash.each { |k, v| instance_variable_set("@#{k}", v) }
  @vote_expiration ||= 300
  @vote_threshold  ||= 5
  @rules           ||= "No rules specified."

  # Initialize the set of commands.
  @commands = {}
  commands = Minecraft::Commands.public_instance_methods
  @command_info = File.read(method(commands.first).source_location.first).split(/$/)
  @enums = [ :ops ]
  commands.each do |sym|
    next if sym.to_s.end_with? "all"
    meth = method(sym)
    src_b, src_e = get_comment_range(meth.source_location.last)

    @commands[sym] = {
      :help => "",
      :params => meth.parameters
    }
    parse_comments(src_b, src_e, sym)
    @commands.delete sym if @commands[sym][:ops].nil?
  end
end