minecraft 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ Overview
2
+ --------
3
+
4
+ This is a deployment and console wrapper for Minecraft which allows for more
5
+ convenient administration of a Minecraft server.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ gem install minecraft
11
+
12
+ This will install the Minecraft extension library and binary, the Minecraft
13
+ server jarfile will be downloaded from http://minecraft.net when the binary is
14
+ ran for the first time.
15
+
16
+ Usage
17
+ -----
18
+
19
+ mkdir ~/MinecraftServer
20
+ cd ~/MinecraftServer
21
+ minecraft
22
+
23
+ minecraft -h
24
+
25
+ Current Features
26
+ ----------------
27
+
28
+ - !give <item> <quantity>
29
+ - Give the user an item with a quantity of up to 2560 (by default Minecraft
30
+ will cap at 64).
31
+ - Use the item ID or item name. http://minecraftwiki.net/wiki/Data_values
32
+ - !tp <target_user>
33
+ - !nom
34
+ - !kit
35
+ - Diamond
36
+ - Gold armour
37
+ - Armour
38
+ - Ranged
39
+ - Nether
40
+ - Portal
41
+
42
+ TODO
43
+ ----
44
+
45
+ - Improved error handling.
46
+ - Log time users have spent on the server.
47
+ - !give timers (give user A an item every X seconds).
48
+
49
+ Contributors
50
+ ------------
51
+
52
+ Forks are welcomed, pull requests will be prompty reviewed!
53
+
54
+ - Ian Horsman
55
+
56
+ Notice
57
+ ------
58
+
59
+ Minecraft is copyright of Mojang AB and developed by Markus Persson (@notch).
@@ -1,6 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "slop"
4
+ require "net/http"
3
5
  require "minecraft"
4
6
 
5
- server = Minecraft::Server.new("java -Xmx1024M -Xms512M -jar minecraft_server.jar nogui")
6
- server.sin.puts("save-on")
7
+ def minecraft_exit
8
+ if $opts.tempmobs?
9
+ puts "[+] Restoring previous mob state."
10
+ Minecraft::Tools.toggle_mobs
11
+ end
12
+ exit!
13
+ end
14
+
15
+ trap("SIGINT") { minecraft_exit }
16
+
17
+ $opts = Slop.parse :help => true do
18
+ banner "Usage: minecraft [options]"
19
+
20
+ on :n, :no_run, "Don't run the Minecraft server instance."
21
+ on :u, :update, "Download the latest version of the Minecraft server jarfile."
22
+ on :s, :min_memory, "Specify the minimum amount of memory to allocate.", :optional => true
23
+ on :x, :max_memory, "Specify the maximum amount of memory to allocate.", :optional => true
24
+ on :no_auto_save, "Disable auto save."
25
+ on :m, :tempmobs, "Temporarily toggles mobs."
26
+ end
27
+
28
+ if $opts.update?
29
+ Minecraft::Tools.download_minecraft
30
+ end
31
+
32
+ if $opts.tempmobs?
33
+ puts "[+] Temporarily toggling mobs."
34
+ Minecraft::Tools.toggle_mobs
35
+ end
36
+
37
+ unless $opts.no_run?
38
+ Minecraft::Tools.check_jarfile
39
+ command = Minecraft::Tools.command($opts)
40
+ puts "[+] #{command}"
41
+ server = Minecraft::Server.new(command)
42
+ server.sin.puts("save-on") unless $opts.no_auto_save?
43
+ end
@@ -1,3 +1,4 @@
1
+ require "minecraft/tools"
1
2
  require "minecraft/data"
2
3
  require "minecraft/extensions"
3
4
  require "minecraft/server"
@@ -1,250 +1,250 @@
1
1
  module Minecraft
2
- module Data
3
- KITS = {
4
- :diamond => [276, 277, 278, 279, 293],
5
- :garmour => [314, 315, 316, 317],
6
- :armour => [310, 311, 312, 313],
7
- :ranged => [261, [262, 640]],
8
- :nether => [261, [262, 320], [348, 128], 278, 276],
9
- :portal => [[49, 10], 259]
10
- }
2
+ module Data
3
+ KITS = {
4
+ :diamond => [276, 277, 278, 279, 293],
5
+ :garmour => [314, 315, 316, 317],
6
+ :armour => [310, 311, 312, 313],
7
+ :ranged => [261, [262, 640]],
8
+ :nether => [261, [262, 320], [348, 128], 278, 276],
9
+ :portal => [[49, 10], 259]
10
+ }
11
11
 
12
- DATA_VALUE_HASH = {
13
- "glass" => "20",
14
- "purple wool" => "35",
15
- "obsidian" => "49",
16
- "redstone ore" => "73",
17
- "stone" => "1",
18
- "lapis lazuli ore" => "21",
19
- "blue wool" => "35",
20
- "torch" => "50",
21
- "glowing redstone ore" => "74",
22
- "grass" => "2",
23
- "lapis lazuli block" => "22",
24
- "brown wool" => "35",
25
- "fire" => "51",
26
- "dirt" => "3",
27
- "dispenser" => "23",
28
- "dark green wool" => "35",
29
- "monster spawner" => "52",
30
- "cobblestone" => "4",
31
- "sandstone" => "24",
32
- "red wool" => "35",
33
- "wooden stairs" => "53",
34
- "stone button" => "77",
35
- "wooden plank" => "5",
36
- "note block" => "25",
37
- "black wool" => "35",
38
- "chest" => "54",
39
- "snow" => "78",
40
- "sapling" => "6",
41
- "bed" => "355",
42
- "yellow flower" => "37",
43
- "redstone wire" => "55",
44
- "ice" => "79",
45
- "spruce sapling" => "6",
46
- "powered rail" => "27",
47
- "red rose" => "38",
48
- "diamond ore" => "56",
49
- "snow block" => "80",
50
- "birch sapling" => "6",
51
- "detector rail" => "28",
52
- "brown mushroom" => "39",
53
- "diamond block" => "57",
54
- "cactus" => "81",
55
- "bedrock" => "7",
56
- "sticky piston" => "29",
57
- "red mushroom" => "40",
58
- "crafting table" => "58",
59
- "clay block" => "82",
60
- "water" => "8",
61
- "cobweb" => "30",
62
- "gold block" => "41",
63
- "crops " => "59",
64
- "sugar cane" => "338",
65
- "stationary water" => "9",
66
- "tall grass" => "31",
67
- "iron block" => "42",
68
- "farmland " => "60",
69
- "jukebox" => "84",
70
- "lava" => "10",
71
- "dead shrubs" => "32",
72
- "double stone slab" => "43",
73
- "furnace " => "61",
74
- "fence" => "85",
75
- "stationary lava " => "11",
76
- "piston" => "33",
77
- "double sandstone slab" => "43",
78
- "burning furnace" => "62",
79
- "pumpkin" => "86",
80
- "sand" => "12",
81
- "white wool" => "35",
82
- "double wooden slab" => "43",
83
- "sign post" => "63",
84
- "netherrack" => "87",
85
- "gravel" => "13",
86
- "orange wool" => "35",
87
- "double cobblestone slab" => "43",
88
- "wooden door" => "324",
89
- "soul sand" => "88",
90
- "gold ore" => "14",
91
- "magenta wool" => "35",
92
- "stone slab" => "44",
93
- "ladder" => "65",
94
- "glowstone" => "89",
95
- "glowstone block" => "89",
96
- "iron ore" => "15",
97
- "light blue wool" => "35",
98
- "sandstone slab" => "44",
99
- "rails" => "66",
100
- "portal" => "90",
101
- "coal ore" => "16",
102
- "yellow wool" => "35",
103
- "wooden slab" => "44",
104
- "cobblestone stairs" => "67",
105
- "jack-o-lantern" => "91",
106
- "jack o lantern" => "91",
107
- "oak wood" => "17",
108
- "light green wool" => "35",
109
- "cobblestone slab" => "44",
110
- "wall sign" => "68",
111
- "cake block" => "92",
112
- "pine wood" => "17",
113
- "pink wool" => "35",
114
- "brick block" => "45",
115
- "lever" => "69",
116
- "birch wood" => "17",
117
- "gray wool" => "35",
118
- "tnt" => "46",
119
- "stone pressure plate" => "70",
120
- "leaves" => "18",
121
- "light gray wool" => "35",
122
- "bookshelf" => "47",
123
- "iron door" => "330",
124
- "locked chest" => "95",
125
- "sponge" => "19",
126
- "cyan wool" => "35",
127
- "moss stone" => "48",
128
- "wooden pressure plate" => "72",
129
- "trapdoor" => "96",
130
- "iron shovel" => "256",
131
- "stick" => "280",
132
- "chainmail boots" => "305",
133
- "lapis lazuli" => "351",
134
- "iron pickaxe" => "257",
135
- "bowl" => "281",
136
- "iron helmet" => "306",
137
- "redstone" => "331",
138
- "purple dye" => "351",
139
- "iron axe" => "258",
140
- "mushroom soup" => "282",
141
- "iron chestplate" => "307",
142
- "snowball" => "332",
143
- "cyan dye" => "351",
144
- "flint and steel" => "259",
145
- "gold sword" => "283",
146
- "iron leggings" => "308",
147
- "boat" => "333",
148
- "light gray dye" => "351",
149
- "apple" => "260",
150
- "gold shovel" => "284",
151
- "iron boots" => "309",
152
- "leather" => "334",
153
- "gray dye" => "351",
154
- "bow" => "261",
155
- "gold pickaxe" => "285",
156
- "diamond helmet" => "310",
157
- "milk" => "335",
158
- "pink dye" => "351",
159
- "arrow" => "262",
160
- "gold axe" => "286",
161
- "diamond chestplate" => "311",
162
- "clay brick" => "336",
163
- "lime dye" => "351",
164
- "coal" => "263",
165
- "string" => "287",
166
- "diamond leggings" => "312",
167
- "clay balls" => "337",
168
- "dandelion yellow" => "351",
169
- "charcoal" => "263",
170
- "feather" => "288",
171
- "diamond boots" => "313",
172
- "light blue dye" => "351",
173
- "diamond" => "264",
174
- "gunpowder" => "289",
175
- "gold helmet" => "314",
176
- "paper" => "339",
177
- "magenta dye" => "351",
178
- "iron ingot" => "265",
179
- "wooden hoe" => "290",
180
- "gold chestplate" => "315",
181
- "book" => "340",
182
- "orange dye" => "351",
183
- "gold ingot" => "266",
184
- "stone hoe" => "291",
185
- "gold leggings" => "316",
186
- "slimeball" => "341",
187
- "bone meal" => "351",
188
- "iron sword" => "267",
189
- "iron hoe" => "292",
190
- "gold boots" => "317",
191
- "storage minecart" => "342",
192
- "bone" => "352",
193
- "wooden sword" => "268",
194
- "diamond hoe" => "293",
195
- "flint" => "318",
196
- "powered minecart" => "343",
197
- "sugar" => "353",
198
- "wooden shovel" => "269",
199
- "gold hoe" => "294",
200
- "raw porkchop" => "319",
201
- "egg" => "344",
202
- "cake" => "354",
203
- "wooden pickaxe" => "270",
204
- "seeds" => "295",
205
- "cooked porkchop" => "320",
206
- "compass" => "345",
207
- "wooden axe" => "271",
208
- "wheat" => "296",
209
- "paintings" => "321",
210
- "fishing rod" => "346",
211
- "redstone repeater" => "356",
212
- "stone sword" => "272",
213
- "bread" => "297",
214
- "golden apple" => "322",
215
- "clock" => "347",
216
- "cookie" => "357",
217
- "stone shovel" => "273",
218
- "leather helmet" => "298",
219
- "sign" => "323",
220
- "glowstone dust" => "348",
221
- "map" => "358",
222
- "stone pickaxe" => "274",
223
- "leather chestplate" => "299",
224
- "raw fish" => "349",
225
- "shears" => "359",
226
- "stone axe" => "275",
227
- "leather leggings" => "300",
228
- "bucket" => "325",
229
- "cooked fish" => "350",
230
- "gold music disc" => "2256",
231
- "diamond sword" => "276",
232
- "leather boots" => "301",
233
- "water bucket" => "326",
234
- "ink sac" => "351",
235
- "green music disc" => "2257",
236
- "diamond shovel" => "277",
237
- "chainmail helmet" => "302",
238
- "lava bucket" => "327",
239
- "rose red" => "351",
240
- "diamond pickaxe" => "278",
241
- "chainmail chestplate" => "303",
242
- "minecart" => "328",
243
- "cactus green" => "351",
244
- "diamond axe" => "279",
245
- "chainmail leggings" => "304",
246
- "saddle" => "329",
247
- "cocoa beans" => "351"
248
- }
249
- end
12
+ DATA_VALUE_HASH = {
13
+ "glass" => "20",
14
+ "purple wool" => "35",
15
+ "obsidian" => "49",
16
+ "redstone ore" => "73",
17
+ "stone" => "1",
18
+ "lapis lazuli ore" => "21",
19
+ "blue wool" => "35",
20
+ "torch" => "50",
21
+ "glowing redstone ore" => "74",
22
+ "grass" => "2",
23
+ "lapis lazuli block" => "22",
24
+ "brown wool" => "35",
25
+ "fire" => "51",
26
+ "dirt" => "3",
27
+ "dispenser" => "23",
28
+ "dark green wool" => "35",
29
+ "monster spawner" => "52",
30
+ "cobblestone" => "4",
31
+ "sandstone" => "24",
32
+ "red wool" => "35",
33
+ "wooden stairs" => "53",
34
+ "stone button" => "77",
35
+ "wooden plank" => "5",
36
+ "note block" => "25",
37
+ "black wool" => "35",
38
+ "chest" => "54",
39
+ "snow" => "78",
40
+ "sapling" => "6",
41
+ "bed" => "355",
42
+ "yellow flower" => "37",
43
+ "redstone wire" => "55",
44
+ "ice" => "79",
45
+ "spruce sapling" => "6",
46
+ "powered rail" => "27",
47
+ "red rose" => "38",
48
+ "diamond ore" => "56",
49
+ "snow block" => "80",
50
+ "birch sapling" => "6",
51
+ "detector rail" => "28",
52
+ "brown mushroom" => "39",
53
+ "diamond block" => "57",
54
+ "cactus" => "81",
55
+ "bedrock" => "7",
56
+ "sticky piston" => "29",
57
+ "red mushroom" => "40",
58
+ "crafting table" => "58",
59
+ "clay block" => "82",
60
+ "water" => "8",
61
+ "cobweb" => "30",
62
+ "gold block" => "41",
63
+ "crops " => "59",
64
+ "sugar cane" => "338",
65
+ "stationary water" => "9",
66
+ "tall grass" => "31",
67
+ "iron block" => "42",
68
+ "farmland " => "60",
69
+ "jukebox" => "84",
70
+ "lava" => "10",
71
+ "dead shrubs" => "32",
72
+ "double stone slab" => "43",
73
+ "furnace " => "61",
74
+ "fence" => "85",
75
+ "stationary lava " => "11",
76
+ "piston" => "33",
77
+ "double sandstone slab" => "43",
78
+ "burning furnace" => "62",
79
+ "pumpkin" => "86",
80
+ "sand" => "12",
81
+ "white wool" => "35",
82
+ "double wooden slab" => "43",
83
+ "sign post" => "63",
84
+ "netherrack" => "87",
85
+ "gravel" => "13",
86
+ "orange wool" => "35",
87
+ "double cobblestone slab" => "43",
88
+ "wooden door" => "324",
89
+ "soul sand" => "88",
90
+ "gold ore" => "14",
91
+ "magenta wool" => "35",
92
+ "stone slab" => "44",
93
+ "ladder" => "65",
94
+ "glowstone" => "89",
95
+ "glowstone block" => "89",
96
+ "iron ore" => "15",
97
+ "light blue wool" => "35",
98
+ "sandstone slab" => "44",
99
+ "rails" => "66",
100
+ "portal" => "90",
101
+ "coal ore" => "16",
102
+ "yellow wool" => "35",
103
+ "wooden slab" => "44",
104
+ "cobblestone stairs" => "67",
105
+ "jack-o-lantern" => "91",
106
+ "jack o lantern" => "91",
107
+ "oak wood" => "17",
108
+ "light green wool" => "35",
109
+ "cobblestone slab" => "44",
110
+ "wall sign" => "68",
111
+ "cake block" => "92",
112
+ "pine wood" => "17",
113
+ "pink wool" => "35",
114
+ "brick block" => "45",
115
+ "lever" => "69",
116
+ "birch wood" => "17",
117
+ "gray wool" => "35",
118
+ "tnt" => "46",
119
+ "stone pressure plate" => "70",
120
+ "leaves" => "18",
121
+ "light gray wool" => "35",
122
+ "bookshelf" => "47",
123
+ "iron door" => "330",
124
+ "locked chest" => "95",
125
+ "sponge" => "19",
126
+ "cyan wool" => "35",
127
+ "moss stone" => "48",
128
+ "wooden pressure plate" => "72",
129
+ "trapdoor" => "96",
130
+ "iron shovel" => "256",
131
+ "stick" => "280",
132
+ "chainmail boots" => "305",
133
+ "lapis lazuli" => "351",
134
+ "iron pickaxe" => "257",
135
+ "bowl" => "281",
136
+ "iron helmet" => "306",
137
+ "redstone" => "331",
138
+ "purple dye" => "351",
139
+ "iron axe" => "258",
140
+ "mushroom soup" => "282",
141
+ "iron chestplate" => "307",
142
+ "snowball" => "332",
143
+ "cyan dye" => "351",
144
+ "flint and steel" => "259",
145
+ "gold sword" => "283",
146
+ "iron leggings" => "308",
147
+ "boat" => "333",
148
+ "light gray dye" => "351",
149
+ "apple" => "260",
150
+ "gold shovel" => "284",
151
+ "iron boots" => "309",
152
+ "leather" => "334",
153
+ "gray dye" => "351",
154
+ "bow" => "261",
155
+ "gold pickaxe" => "285",
156
+ "diamond helmet" => "310",
157
+ "milk" => "335",
158
+ "pink dye" => "351",
159
+ "arrow" => "262",
160
+ "gold axe" => "286",
161
+ "diamond chestplate" => "311",
162
+ "clay brick" => "336",
163
+ "lime dye" => "351",
164
+ "coal" => "263",
165
+ "string" => "287",
166
+ "diamond leggings" => "312",
167
+ "clay balls" => "337",
168
+ "dandelion yellow" => "351",
169
+ "charcoal" => "263",
170
+ "feather" => "288",
171
+ "diamond boots" => "313",
172
+ "light blue dye" => "351",
173
+ "diamond" => "264",
174
+ "gunpowder" => "289",
175
+ "gold helmet" => "314",
176
+ "paper" => "339",
177
+ "magenta dye" => "351",
178
+ "iron ingot" => "265",
179
+ "wooden hoe" => "290",
180
+ "gold chestplate" => "315",
181
+ "book" => "340",
182
+ "orange dye" => "351",
183
+ "gold ingot" => "266",
184
+ "stone hoe" => "291",
185
+ "gold leggings" => "316",
186
+ "slimeball" => "341",
187
+ "bone meal" => "351",
188
+ "iron sword" => "267",
189
+ "iron hoe" => "292",
190
+ "gold boots" => "317",
191
+ "storage minecart" => "342",
192
+ "bone" => "352",
193
+ "wooden sword" => "268",
194
+ "diamond hoe" => "293",
195
+ "flint" => "318",
196
+ "powered minecart" => "343",
197
+ "sugar" => "353",
198
+ "wooden shovel" => "269",
199
+ "gold hoe" => "294",
200
+ "raw porkchop" => "319",
201
+ "egg" => "344",
202
+ "cake" => "354",
203
+ "wooden pickaxe" => "270",
204
+ "seeds" => "295",
205
+ "cooked porkchop" => "320",
206
+ "compass" => "345",
207
+ "wooden axe" => "271",
208
+ "wheat" => "296",
209
+ "paintings" => "321",
210
+ "fishing rod" => "346",
211
+ "redstone repeater" => "356",
212
+ "stone sword" => "272",
213
+ "bread" => "297",
214
+ "golden apple" => "322",
215
+ "clock" => "347",
216
+ "cookie" => "357",
217
+ "stone shovel" => "273",
218
+ "leather helmet" => "298",
219
+ "sign" => "323",
220
+ "glowstone dust" => "348",
221
+ "map" => "358",
222
+ "stone pickaxe" => "274",
223
+ "leather chestplate" => "299",
224
+ "raw fish" => "349",
225
+ "shears" => "359",
226
+ "stone axe" => "275",
227
+ "leather leggings" => "300",
228
+ "bucket" => "325",
229
+ "cooked fish" => "350",
230
+ "gold music disc" => "2256",
231
+ "diamond sword" => "276",
232
+ "leather boots" => "301",
233
+ "water bucket" => "326",
234
+ "ink sac" => "351",
235
+ "green music disc" => "2257",
236
+ "diamond shovel" => "277",
237
+ "chainmail helmet" => "302",
238
+ "lava bucket" => "327",
239
+ "rose red" => "351",
240
+ "diamond pickaxe" => "278",
241
+ "chainmail chestplate" => "303",
242
+ "minecart" => "328",
243
+ "cactus green" => "351",
244
+ "diamond axe" => "279",
245
+ "chainmail leggings" => "304",
246
+ "saddle" => "329",
247
+ "cocoa beans" => "351"
248
+ }
249
+ end
250
250
  end
@@ -1,72 +1,153 @@
1
1
  module Minecraft
2
- class Extensions
3
- include Data
4
-
5
- def process(line)
6
- puts line
7
- return info_command(line) if line.index "INFO"
8
- end
9
-
10
- def info_command(line)
11
- line.gsub! /^.*?\[INFO\]\s+/, ''
12
- match_data = line.match /^\<(.*?)\>\s+!(.*?)$/
13
- return if match_data.nil?
14
-
15
- user = match_data[1]
16
- args = match_data[2].split(" ")
17
- return send(args.slice!(0), user, *args)
18
- end
19
-
20
- def method_missing(sym, *args)
21
- if DATA_VALUE_HASH.has_key? sym.downcase
22
- give(args.first, sym, args.last)
23
- else
24
- puts "Invalid command given."
25
- end
26
- end
27
-
28
- def give(user, *args)
29
- if args.length == 1
30
- quantity = 1
31
- item = args.first
32
- else
33
- quantity = args.last.to_i || 1
34
- item = args[0..-2].join(" ")
35
- end
36
- item = (item.to_i.to_s == item) ? item.to_i : DATA_VALUE_HASH[item.downcase]
37
-
38
- return quantify(user, item, quantity)
39
- end
40
-
41
- def kit(user, group)
42
- ret = ""
43
- KITS[group.to_sym].each do |item|
44
- if item.is_a? Array
45
- ret += quantify(user, item.first, item.last)
46
- else
47
- ret += "give #{user} #{item} 1\n"
48
- end
49
- end
50
- return ret.chop
51
- end
52
-
53
- def tp(user, target)
54
- "tp #{user} #{target}"
55
- end
56
-
57
- def nom(user)
58
- "give #{user} 322 1"
59
- end
60
-
61
- def quantify(user, item, quantity)
62
- return "give #{user} #{item} #{quantity}" if quantity <= 64
63
-
64
- quantity = 2560 if quantity > 2560
65
- full_quantity = (quantity / 64.0).floor
66
- sub_quantity = quantity % 64
67
- ret = "give #{user} #{item} 64\n" * full_quantity
68
- ret += "give #{user} #{item} #{sub_quantity}"
69
- return ret
70
- end
71
- end
2
+ class Extensions
3
+ include Data
4
+
5
+ def initialize
6
+ @ops = File.readlines("ops.txt").map { |s| s.chop }
7
+ @users = []
8
+ end
9
+
10
+ def process(line)
11
+ puts line
12
+ return info_command(line) if line.index "INFO"
13
+ end
14
+
15
+ def info_command(line)
16
+ line.gsub! /^.*?\[INFO\]\s+/, ''
17
+ meta_check(line)
18
+ match_data = line.match /^\<(.*?)\>\s+!(.*?)$/
19
+ return if match_data.nil?
20
+
21
+ user = match_data[1]
22
+ args = match_data[2].split(" ")
23
+ return send(args.slice!(0), user, *args)
24
+ end
25
+
26
+ def meta_check(line)
27
+ return if check_ops(line)
28
+ return if check_join_part(line)
29
+ end
30
+
31
+ def check_ops(line)
32
+ user = line.split(" ").last
33
+ if line.index "De-opping"
34
+ @ops.reject! { |u| u == user }
35
+ return true
36
+ elsif line.index "Opping"
37
+ @ops << user
38
+ return true
39
+ end
40
+ end
41
+
42
+ def check_join_part(line)
43
+ user = line.split(" ").first
44
+ if line.index "lost connection"
45
+ @users.reject! { |u| u == user }
46
+ return true
47
+ elsif line.index "logged in"
48
+ @users << user
49
+ return true
50
+ end
51
+ end
52
+
53
+ def method_missing(sym, *args)
54
+ if DATA_VALUE_HASH.has_key? sym.downcase
55
+ give(args.first, sym, args.last)
56
+ else
57
+ puts "Invalid command given."
58
+ end
59
+ end
60
+
61
+ def giveall(user, *args)
62
+ return privilege_error(user, "giveall") unless is_op? user
63
+ ret = "say #{user} is putting out!\n"
64
+ @users.each do |u|
65
+ ret += mc_give(u, *args)
66
+ end
67
+
68
+ return ret
69
+ end
70
+
71
+ def give(user, *args)
72
+ return privilege_error(user, "give") unless is_op? user
73
+ return mc_give(user, *args)
74
+ end
75
+
76
+ def mc_give(user, *args)
77
+ if args.length == 1
78
+ quantity = 1
79
+ item = args.first
80
+ else
81
+ quantity = args.last.to_i || 1
82
+ item = args[0..-2].join(" ")
83
+ end
84
+ item = (item.to_i.to_s == item) ? item.to_i : DATA_VALUE_HASH[item.downcase]
85
+
86
+ return quantify(user, item, quantity)
87
+ end
88
+
89
+ def kit(user, group)
90
+ return privilege_error(user, "kit") unless is_op? user
91
+ return "say #{group} is not a valid kit." unless KITS.has_key? group.to_sym
92
+ ret = ""
93
+
94
+ KITS[group.to_sym].each do |item|
95
+ if item.is_a? Array
96
+ ret += quantify(user, item.first, item.last)
97
+ else
98
+ ret += "give #{user} #{item} 1\n"
99
+ end
100
+ end
101
+ return ret.chop
102
+ end
103
+
104
+ def tp(user, target)
105
+ "tp #{user} #{target}"
106
+ end
107
+
108
+ def tpall(user)
109
+ return privilege_error(user, "tpall", "Wow, #{user} actually tried to pull that...") unless is_op? user
110
+ ret = "say #{user} is teleporting all users to their location.\n"
111
+ @users.each do |u|
112
+ ret += tp(u, user)
113
+ end
114
+ return ret
115
+ end
116
+
117
+ def nom(user)
118
+ return privilege_error(user, "nom", "No noms for you!") unless is_op? user
119
+ "give #{user} 322 1"
120
+ end
121
+
122
+ def help(*args)
123
+ <<-eof
124
+ say !tp target_user
125
+ say !tpall
126
+ say !kit kit_name
127
+ say !give item quantity
128
+ say !giveall item quantity
129
+ say !nom
130
+ say /help
131
+ eof
132
+ end
133
+
134
+ def quantify(user, item, quantity)
135
+ return "give #{user} #{item} #{quantity}" if quantity <= 64
136
+
137
+ quantity = 2560 if quantity > 2560
138
+ full_quantity = (quantity / 64.0).floor
139
+ sub_quantity = quantity % 64
140
+ ret = "give #{user} #{item} 64\n" * full_quantity
141
+ ret += "give #{user} #{item} #{sub_quantity}"
142
+ return ret
143
+ end
144
+
145
+ def is_op?(user)
146
+ @ops.include? user
147
+ end
148
+
149
+ def privilege_error(user, command, suffix = "S/he must be humiliated!")
150
+ "say #{user} is not an op, cannot use !#{command}. #{suffix}"
151
+ end
152
+ end
72
153
  end
@@ -1,22 +1,22 @@
1
1
  require "open3"
2
2
 
3
3
  module Minecraft
4
- class Server
5
- attr_accessor :sin
4
+ class Server
5
+ attr_accessor :sin
6
6
 
7
- def initialize(command)
8
- @extensions = Extensions.new
9
- @sin, @sout, @serr = Open3.popen3(command)
10
- threads = []
11
- threads << Thread.new { loop { process(@sout.gets) } }
12
- threads << Thread.new { loop { process(@serr.gets) } }
13
- threads << Thread.new { loop { @sin.puts gets } }
14
- threads.each(&:join)
15
- end
7
+ def initialize(command)
8
+ @extensions = Extensions.new
9
+ @sin, @sout, @serr = Open3.popen3(command)
10
+ threads = []
11
+ threads << Thread.new { loop { process(@sout.gets) } }
12
+ threads << Thread.new { loop { process(@serr.gets) } }
13
+ threads << Thread.new { loop { @sin.puts gets } }
14
+ threads.each(&:join)
15
+ end
16
16
 
17
- def process(line)
18
- result = @extensions.process(line)
19
- @sin.puts(result) unless result.nil?
20
- end
21
- end
17
+ def process(line)
18
+ result = @extensions.process(line)
19
+ @sin.puts(result) unless result.nil?
20
+ end
21
+ end
22
22
  end
@@ -0,0 +1,32 @@
1
+ module Minecraft
2
+ module Tools
3
+ def self.check_jarfile
4
+ download_minecraft unless File.exists? "minecraft_server.jar"
5
+ end
6
+
7
+ def self.download_minecraft
8
+ url = get_minecraft_page
9
+ puts "[+] Downloading Minecraft server..."
10
+ `wget http://minecraft.net/#{url} -O minecraft_server.jar -q`
11
+ end
12
+
13
+ def self.get_minecraft_page
14
+ page = Net::HTTP.get("www.minecraft.net", "/download.jsp")
15
+ data = page.match /\"([0-9a-zA-Z_\/]*minecraft_server\.jar\?v=[0-9]+)/
16
+ data[1]
17
+ end
18
+
19
+ def self.command(opts)
20
+ "java -Xmx#{opts[:max_memory] || "1024M"} -Xms#{opts[:min_memory] || "1024M"} -jar minecraft_server.jar nogui"
21
+ end
22
+
23
+ def self.toggle_mobs
24
+ content = File.read("server.properties")
25
+ state = content.match(/spawn\-monsters=(true|false)/)[1]
26
+ new_state = state == "true" ? "false" : "true"
27
+ content.gsub! "spawn-monsters=#{state}", "spawn-monsters=#{new_state}"
28
+
29
+ File.open("server.properties", "w") { |f| f.print content }
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Minecraft
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -11,9 +11,11 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Minecraft server wrapper and deployment."
12
12
  s.description = "A server console wrapper and other Minecraft deployment tools."
13
13
 
14
- s.homepage = "http://github.com/basicxman/minecraft"
14
+ s.homepage = "http://github.com/basicxman/minecraft"
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'slop'
19
21
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: minecraft
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Horsman
@@ -12,8 +12,18 @@ cert_chain: []
12
12
 
13
13
  date: 2011-08-13 00:00:00 -04:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: slop
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
17
27
  description: A server console wrapper and other Minecraft deployment tools.
18
28
  email:
19
29
  - self@andrewhorsman.net
@@ -26,12 +36,14 @@ extra_rdoc_files: []
26
36
  files:
27
37
  - .gitignore
28
38
  - Gemfile
39
+ - README.md
29
40
  - Rakefile
30
41
  - bin/minecraft
31
42
  - lib/minecraft.rb
32
43
  - lib/minecraft/data.rb
33
44
  - lib/minecraft/extensions.rb
34
45
  - lib/minecraft/server.rb
46
+ - lib/minecraft/tools.rb
35
47
  - lib/minecraft/version.rb
36
48
  - minecraft.gemspec
37
49
  has_rdoc: true