craftbelt 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/craftbelt.gemspec +4 -1
- data/lib/craftbelt.rb +2 -1
- data/lib/craftbelt/env.rb +85 -0
- data/lib/craftbelt/{minecraft_instance.rb → instance.rb} +1 -1
- data/lib/craftbelt/settings.rb +33 -0
- data/lib/craftbelt/version.rb +1 -1
- data/spec/craftbelt/minecraft_instance_spec.rb +4 -1
- metadata +18 -3
- data/lib/craftbelt/minecraft_settings.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 128b56aa947e03ee596507823f0519b1f643e6d5
|
4
|
+
data.tar.gz: 57c37312109f8fa2d776069cf3a4bbcf20afb8a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbdfb6c929c475fd719168150a61cbbe622f4dd4cf9629acc46e6a10ea3298d87ab1a7bc047240562d064ef67ce9029f1f6a9cc46126f319c87514e337302bc3
|
7
|
+
data.tar.gz: c311fccb03bf66699167d2ea4de5460291812f42274e7d180d79ae0d61baa7825c9b76015f6e0e5ad26a0b94b3ef8614dd6a2ca30f07b970f2d26d91362cfeaf
|
data/craftbelt.gemspec
CHANGED
@@ -16,7 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
|
18
18
|
gem.add_dependency 'nbtfile'
|
19
|
-
|
19
|
+
|
20
|
+
%w(rspec fakefs).each do |dep|
|
21
|
+
gem.add_development_dependency dep
|
22
|
+
end
|
20
23
|
|
21
24
|
gem.files = %w(
|
22
25
|
Gemfile
|
data/lib/craftbelt.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'craftbelt/instance'
|
2
|
+
|
3
|
+
module Craftbelt
|
4
|
+
class Env
|
5
|
+
attr_reader :build_dir, :instance, :settings
|
6
|
+
|
7
|
+
def initialize(instance_dir, build_dir, extra_settings={})
|
8
|
+
@instance = Craftbelt::Instance.new(instance_dir)
|
9
|
+
@build_dir = build_dir
|
10
|
+
vals = data[:settings].merge(
|
11
|
+
"name" => data[:name],
|
12
|
+
"enable-white-list" => whitelist?,
|
13
|
+
"level-name" => (instance.level_paths.first || 'level')
|
14
|
+
).merge(extra_settings)
|
15
|
+
|
16
|
+
@settings = Settings.new(schema, vals)
|
17
|
+
end
|
18
|
+
|
19
|
+
def data
|
20
|
+
@data ||= begin
|
21
|
+
data_text = ENV['DATA']
|
22
|
+
if !data_text
|
23
|
+
data_text = File.read(File.expand_path(ENV['DATAFILE']))
|
24
|
+
end
|
25
|
+
|
26
|
+
JSON.parse(data_text, symbolize_names: true)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def schema
|
31
|
+
@schema ||= begin
|
32
|
+
JSON.parse(File.read("#{@build_dir}/funpack.json"))['schema']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def access
|
37
|
+
@access ||= begin
|
38
|
+
# TODO remove when access policies are standard
|
39
|
+
data[:access] || {
|
40
|
+
whitelist: (data['settings']['whitelist'] || '').split
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def whitelist?
|
46
|
+
!!access[:whitelist]
|
47
|
+
end
|
48
|
+
|
49
|
+
def write_player_files
|
50
|
+
File.write('ops.txt', player_list(data[:settings][:ops]))
|
51
|
+
File.write('white-list.txt', player_list(access[:whitelist] || ''))
|
52
|
+
File.write('banned-players.txt', player_list(access[:blacklist] || ''))
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_templates(templates)
|
56
|
+
templates.each do |src, dest|
|
57
|
+
`mkdir -p #{File.dirname(dest)}`
|
58
|
+
File.write(dest, erb(File.read("#{@build_dir}/templates/#{src}")))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO remove this when players are passed as an array
|
63
|
+
def player_list(player_setting)
|
64
|
+
if player_setting.is_a? Array
|
65
|
+
player_setting.join("\n")
|
66
|
+
else
|
67
|
+
player_setting
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def ram
|
72
|
+
(ENV['RAM'] || 1024).to_i
|
73
|
+
end
|
74
|
+
|
75
|
+
def field(name)
|
76
|
+
settings.field(name)
|
77
|
+
end
|
78
|
+
alias_method :f, :field
|
79
|
+
|
80
|
+
def erb(template)
|
81
|
+
ERB.new(template).result(binding)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'brock'
|
2
|
+
|
3
|
+
module Craftbelt
|
4
|
+
class Settings
|
5
|
+
attr_reader :schema, :values
|
6
|
+
|
7
|
+
def initialize(definitions, values={})
|
8
|
+
@schema = Brock::Schema.new(definitions)
|
9
|
+
@values = values
|
10
|
+
end
|
11
|
+
|
12
|
+
def field(name)
|
13
|
+
field = schema.fields.find{|f| f.name.to_sym == name.to_sym }
|
14
|
+
|
15
|
+
value = values[name]
|
16
|
+
if value.nil?
|
17
|
+
value = values[name.to_sym]
|
18
|
+
end
|
19
|
+
|
20
|
+
raise "Unknown field: #{name}" if field.nil? and value.nil?
|
21
|
+
|
22
|
+
if field
|
23
|
+
if value.nil?
|
24
|
+
field.default
|
25
|
+
else
|
26
|
+
field.parse_param(value)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/craftbelt/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'craftbelt/
|
2
|
+
require 'craftbelt/instance'
|
3
|
+
require 'fakefs'
|
3
4
|
|
4
5
|
module Craftbelt
|
5
6
|
describe MinecraftInstance do
|
@@ -12,6 +13,8 @@ module Craftbelt
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
16
|
+
before { FileUtils.mkdir_p('tmp/server') }
|
17
|
+
|
15
18
|
subject { MinecraftInstance.new('.') }
|
16
19
|
|
17
20
|
context 'single player world' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: craftbelt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Newman
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fakefs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Useful Minecraft utilities
|
42
56
|
email:
|
43
57
|
- dave@minefold.com
|
@@ -48,8 +62,9 @@ files:
|
|
48
62
|
- Gemfile
|
49
63
|
- README.md
|
50
64
|
- craftbelt.gemspec
|
51
|
-
- lib/craftbelt/
|
52
|
-
- lib/craftbelt/
|
65
|
+
- lib/craftbelt/env.rb
|
66
|
+
- lib/craftbelt/instance.rb
|
67
|
+
- lib/craftbelt/settings.rb
|
53
68
|
- lib/craftbelt/version.rb
|
54
69
|
- lib/craftbelt.rb
|
55
70
|
- spec/craftbelt/minecraft_instance_spec.rb
|
@@ -1,59 +0,0 @@
|
|
1
|
-
class MinecraftSettings
|
2
|
-
attr_reader :build_dir, :instance, :settings
|
3
|
-
|
4
|
-
def initialize(build_dir)
|
5
|
-
@build_dir = build_dir
|
6
|
-
@instance = Craftbelt::MinecraftInstance.new('.')
|
7
|
-
end
|
8
|
-
|
9
|
-
def data
|
10
|
-
@data ||= begin
|
11
|
-
data_text = ENV['DATA']
|
12
|
-
if !data_text
|
13
|
-
data_text = File.read(File.expand_path(ENV['DATAFILE']))
|
14
|
-
end
|
15
|
-
|
16
|
-
JSON.parse(data_text, symbolize_names: true)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def settings
|
21
|
-
@settings ||= begin
|
22
|
-
# TODO remove when access policies are standard
|
23
|
-
access = data[:access] || {
|
24
|
-
whitelist: (data['settings']['whitelist'] || '').split
|
25
|
-
}
|
26
|
-
|
27
|
-
schema = JSON.parse(File.read("#{@build_dir}/funpack.json"))['schema']
|
28
|
-
|
29
|
-
Settings.new(schema, data[:settings].merge(
|
30
|
-
"name" => data[:name],
|
31
|
-
"enable-white-list" => data[:access],
|
32
|
-
"level-name" => (@instance.level_paths.first || 'level')
|
33
|
-
)
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def write_player_files
|
39
|
-
File.write('ops.txt', player_list(data[:settings][:ops]))
|
40
|
-
File.write('white-list.txt', player_list(data[:settings][:whitelist]))
|
41
|
-
File.write('banned-players.txt', player_list(data[:settings][:blacklist]))
|
42
|
-
end
|
43
|
-
|
44
|
-
def write_templates(templates)
|
45
|
-
templates.each do |src, dest|
|
46
|
-
`mkdir -p #{File.dirname(dest)}`
|
47
|
-
File.write(dest, settings.erb(File.read("#{@build_dir}/templates/#{src}")))
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# TODO remove this when players are passed as an array
|
52
|
-
def player_list(player_setting)
|
53
|
-
if player_setting.is_a? Array
|
54
|
-
player_setting.join("\n")
|
55
|
-
else
|
56
|
-
player_setting || ''
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|