Class: MinecraftApi
- Inherits:
-
Object
- Object
- MinecraftApi
- Defined in:
- lib/minecraft_api.rb
Instance Attribute Summary collapse
-
#camera ⇒ Object
readonly
Returns the value of attribute camera.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Instance Method Summary collapse
- #close ⇒ Object
-
#drain ⇒ Object
The other api’s have a method like this I haven’t seen it be invoked yet.
-
#initialize(host = 'localhost', port = 4711) ⇒ MinecraftApi
constructor
A new instance of MinecraftApi.
- #send(data) ⇒ Object
- #send_and_receive(data) ⇒ Object
Constructor Details
#initialize(host = 'localhost', port = 4711) ⇒ MinecraftApi
Returns a new instance of MinecraftApi.
14 15 16 17 18 19 |
# File 'lib/minecraft_api.rb', line 14 def initialize(host = 'localhost', port = 4711) @socket = TCPSocket.new host, port @world = World.new(self) @camera = Camera.new(self) @player = Player.new(self) end |
Instance Attribute Details
#camera ⇒ Object (readonly)
Returns the value of attribute camera.
11 12 13 |
# File 'lib/minecraft_api.rb', line 11 def camera @camera end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
12 13 14 |
# File 'lib/minecraft_api.rb', line 12 def player @player end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
10 11 12 |
# File 'lib/minecraft_api.rb', line 10 def world @world end |
Instance Method Details
#close ⇒ Object
39 40 41 |
# File 'lib/minecraft_api.rb', line 39 def close @socket.close end |
#drain ⇒ Object
The other api’s have a method like this I haven’t seen it be invoked yet. Perhaps it is not needed
23 24 25 26 27 |
# File 'lib/minecraft_api.rb', line 23 def drain() while @socket.ready? puts "DRAINING DATA FROM SOCKET [#{@socket.gets}]" end end |
#send(data) ⇒ Object
29 30 31 32 |
# File 'lib/minecraft_api.rb', line 29 def send(data) drain() @socket.puts "#{data}" end |
#send_and_receive(data) ⇒ Object
34 35 36 37 |
# File 'lib/minecraft_api.rb', line 34 def send_and_receive(data) send(data) @socket.gets.chomp end |