diff --git a/anvil-loader/README.MD b/anvil-loader/README.MD
index a3751b9..b6f696c 100644
--- a/anvil-loader/README.MD
+++ b/anvil-loader/README.MD
@@ -2,4 +2,4 @@
Загрузчик "ванильных" (vanilla, ["Anvil"](https://minecraft.gamepedia.com/Anvil_file_format)) карт Minecraft.
-Пример настройки можно посмотреть в файле `sample-config.xml`
+Пример настройки можно посмотреть в файле [`sample-config.groovy`](./sample-config.groovy)
diff --git a/anvil-loader/sample-config.groovy b/anvil-loader/sample-config.groovy
new file mode 100644
index 0000000..86d8ef4
--- /dev/null
+++ b/anvil-loader/sample-config.groovy
@@ -0,0 +1,18 @@
+beans {
+ xmlns([context:'http://www.springframework.org/schema/context'])
+ context.'annotation-config'()
+
+ spawnLocation(mc.core.EntityLocation) { bean ->
+ bean.constructorArgs = [ 8d/*X*/, 64d/*Y*/, 8d/*Z*/, 0f/*Yaw*/, 0f/*Pitch*/ ]
+ }
+
+ anvilChunkProvider(mc.world.anvil.AnvilChunkProvider) { bean ->
+ bean.constructorArgs = [ "path/to/minecraft/maps/New world" ]
+ }
+
+ /* В качестве хранилища, используется модуль Simple world */
+ simpleWorld(mc.world.simple.SimpleWorld) {
+ spawn = spawnLocation
+ chunkProvider = anvilChunkProvider
+ }
+}
\ No newline at end of file
diff --git a/anvil-loader/sample-config.xml b/anvil-loader/sample-config.xml
deleted file mode 100644
index e2a0636..0000000
--- a/anvil-loader/sample-config.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/core/README.MD b/core/README.MD
index 59b1fb7..6dd0136 100644
--- a/core/README.MD
+++ b/core/README.MD
@@ -2,7 +2,7 @@
Ядро сервера.
-Пример настройки можно посмотреть в файле `sample-config.xml`.
+Пример настройки можно посмотреть в файле [`sample-config.groovy`](./sample-config.groovy).
## Spring beans
@@ -14,8 +14,10 @@
**Bean example:**
-```xml
-
+```groovy
+beans {
+ coreEventListener(mc.core.CoreEventListener)
+}
```
#### ConfigFromSpring
@@ -31,12 +33,14 @@
**Bean example:**
-```xml
-
-
-
-
-
+```groovy
+beans {
+ config(mc.core.embedded.ConfigFromSpring) {
+ descriptionServer = 'MC Core - LIMBO'
+ maxPlayers = 1
+ favicon = 'icon.png'
+ }
+}
```
#### GameLoop
@@ -47,11 +51,13 @@
* `gameTimer` - бин, управляющий ходом времени
* `percentWarnLowTps` - порог "низкого" значения TPS, в процентах
-```xml
-
-
-
-
+```groovy
+beans {
+ gameLoop(mc.core.GameLoop) {
+ gameTimer = ref('timeProcessor')
+ percentWarnLowTps = 15
+ }
+}
```
#### SimpleChatProcessor
@@ -62,8 +68,10 @@
**Bean example:**
-```xml
-
+```groovy
+beans {
+ chatProcessor(mc.core.chat.SimpleChatProcessor)
+}
```
### Время
@@ -79,10 +87,12 @@
**Bean example:**
-```xml
-
-
-
+```groovy
+beans {
+ timeProcessor(mc.core.time.IdleTime) {
+ gameTime = 1000
+ }
+}
```
#### TimePerTick
@@ -96,10 +106,12 @@
**Bean example:**
-```xml
-
-
-
+```groovy
+beans {
+ timeProcessor(mc.core.time.TimePerTick) {
+ startGameTime = 1000
+ }
+}
```
#### RealTime
@@ -110,6 +122,8 @@
**Bean example:**
-```xml
-
+```groovy
+beans {
+ timeProcessor(mc.core.time.RealTime)
+}
```
diff --git a/core/build.gradle b/core/build.gradle
index dba539c..a2df22b 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -1,14 +1,22 @@
-version '0.2'
+version '0.2.1'
-apply plugin: 'maven'
apply plugin: 'application'
-mainClassName = "mc.core.Main"
+mainClassName = 'mc.core.Main'
+
+ext {
+ groovy_version = '2.5.6'
+}
dependencies {
+ /* Spring Groovy Bean Configuration */
+ compile (group: 'org.codehaus.groovy', name: 'groovy', version: groovy_version)
+ compile (group: 'org.codehaus.groovy', name: 'groovy-xml', version: groovy_version)
+
/* Components */
- compile (group: 'commons-io', name: 'commons-io', version: '2.6')
- compile (group: 'com.google.guava', name: 'guava', version: '26.0-jre')
- /* Named Binary Tags */
+ compile (group: 'commons-io', name: 'commons-io', version: '2.6')
+ compile (group: 'com.google.guava', name: 'guava', version: '26.0-jre')
+
+ /* NBT, Named Binary Tags */
compile (group: 'com.flowpowered', name: 'flow-nbt', version: '1.0.1-SNAPSHOT')
}
diff --git a/core/sample-config.groovy b/core/sample-config.groovy
new file mode 100644
index 0000000..1c52f6c
--- /dev/null
+++ b/core/sample-config.groovy
@@ -0,0 +1,26 @@
+beans {
+ xmlns([context:'http://www.springframework.org/schema/context'])
+ context.'annotation-config'()
+
+ config(mc.core.embedded.ConfigFromSpring) {
+ descriptionServer = 'MC Core - LIMBO'
+ maxPlayers = 1
+ }
+
+ playerManager(mc.core.embedded.FakePlayerManager)
+
+ timer(mc.core.time.IdleTime) {
+ gameTime = 1000
+ }
+
+ coreEventListener(mc.core.CoreEventListener)
+
+ gameLoop(mc.core.GameLoop) {
+ gameTimer = timer
+ percentWarnLowTps = 15
+ }
+
+ chatProcessor(mc.core.chat.SimpleChatProcessor)
+
+ server(mc.core.embedded.FakeServer)
+}
\ No newline at end of file
diff --git a/core/sample-config.xml b/core/sample-config.xml
deleted file mode 100644
index a32dec9..0000000
--- a/core/sample-config.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/core/src/main/java/mc/core/Main.java b/core/src/main/java/mc/core/Main.java
index 19dcbb4..244eb26 100644
--- a/core/src/main/java/mc/core/Main.java
+++ b/core/src/main/java/mc/core/Main.java
@@ -5,7 +5,7 @@ import mc.core.network.Server;
import mc.core.network.StartServerException;
import org.apache.commons.io.IOUtils;
import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.springframework.context.support.GenericGroovyApplicationContext;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -15,19 +15,20 @@ import java.nio.file.Paths;
@Slf4j
public class Main {
private static ApplicationContext createContext() {
- final String springXml = System.getProperty("springConfig", "./spring.xml");
+ final String defautlSpringConfig = "spring.groovy";
+ final String springConfig = System.getProperty("springConfig", "./" + defautlSpringConfig);
- if (!Files.exists(Paths.get(springXml))) {
- log.info("File \"{}\" not found. Get default config.", springXml);
- try (FileOutputStream fos = new FileOutputStream(springXml)) {
- IOUtils.copy(Main.class.getResourceAsStream("/spring.xml"), fos);
+ if (!Files.exists(Paths.get(springConfig))) {
+ log.info("File \"{}\" not found. Get default config.", springConfig);
+ try (FileOutputStream fos = new FileOutputStream(springConfig)) {
+ IOUtils.copy(Main.class.getResourceAsStream("/" + defautlSpringConfig), fos);
} catch (IOException e) {
log.error("Get default spring config", e);
System.exit(-1);
}
}
- return new FileSystemXmlApplicationContext(springXml);
+ return new GenericGroovyApplicationContext("file:" + springConfig);
}
public static void main(String[] args) {
diff --git a/core/src/main/resources/spring.groovy b/core/src/main/resources/spring.groovy
new file mode 100644
index 0000000..c7b51e6
--- /dev/null
+++ b/core/src/main/resources/spring.groovy
@@ -0,0 +1,14 @@
+beans {
+ xmlns([context:'http://www.springframework.org/schema/context'])
+ context.'annotation-config'()
+
+ playerManager(mc.core.embedded.FakePlayerManager)
+
+ timer(mc.core.time.TimePerTick)
+
+ gameLoop(mc.core.GameLoop) {
+ gameTimer = timer
+ }
+
+ server(mc.core.embedded.FakeServer)
+}
\ No newline at end of file
diff --git a/core/src/main/resources/spring.xml b/core/src/main/resources/spring.xml
deleted file mode 100644
index bb81a1a..0000000
--- a/core/src/main/resources/spring.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/h2_playermanager/README.MD b/h2_playermanager/README.MD
index 2f6b15c..a3ef76a 100644
--- a/h2_playermanager/README.MD
+++ b/h2_playermanager/README.MD
@@ -2,4 +2,4 @@
Хранилище данных игроков на базе [H2 Database](http://www.h2database.com/).
-Пример настройки можно посмотреть в файле `sample-config.xml`
+Пример настройки можно посмотреть в файле [`sample-config.groovy`](./sample-config.groovy)
diff --git a/h2_playermanager/sample-config.groovy b/h2_playermanager/sample-config.groovy
new file mode 100644
index 0000000..2474304
--- /dev/null
+++ b/h2_playermanager/sample-config.groovy
@@ -0,0 +1,31 @@
+def hibernateProps = new Properties()
+hibernateProps.put('hibernate.dialect', 'org.hibernate.dialect.H2Dialect')
+hibernateProps.put('hibernate.show_sql', false)
+hibernateProps.put('hibernate.hbm2ddl.auto', 'update')
+
+beans {
+ xmlns([context: 'http://www.springframework.org/schema/context'])
+ context.'annotation-config'()
+ context.'component-scan'('base-package': 'mc.core.h2db')
+
+ xmlns([jpa: 'http://www.springframework.org/schema/data/jpa'])
+ jpa.'repositories'('base-package': 'mc.core.h2db.repository')
+
+ dataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) {
+ driverClassName = 'org.h2.Driver'
+ url = 'jdbc:h2:mem:test;DB_CLOSE_DELAY=-1'
+ username = 'sa'
+ password = 's3cReT'
+ }
+
+ entityManagerFactory(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) {
+ dataSource = ref('dataSource')
+ persistenceProviderClass = 'org.hibernate.jpa.HibernatePersistenceProvider'
+ packagesToScan = 'mc.core.h2db.entity'
+ jpaProperties = hibernateProps
+ }
+
+ transactionManager(org.springframework.orm.jpa.JpaTransactionManager) {
+ entityManagerFactory = ref('entityManagerFactory')
+ }
+}
\ No newline at end of file
diff --git a/h2_playermanager/sample-config.xml b/h2_playermanager/sample-config.xml
deleted file mode 100644
index 2fe46ec..0000000
--- a/h2_playermanager/sample-config.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.hibernate.dialect.H2Dialect
- false
- update
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/proto_1.12.2_netty/README.MD b/proto_1.12.2_netty/README.MD
index 92e9638..f036b43 100644
--- a/proto_1.12.2_netty/README.MD
+++ b/proto_1.12.2_netty/README.MD
@@ -2,6 +2,6 @@
Реализация протокола на сетевом движке [Netty.IO](https://netty.io/).
-Пример настройки можно посмотреть в файле `sample-config.xml`
+Пример настройки можно посмотреть в файле [`sample-config.groovy`](./sample-config.groovy)
diff --git a/proto_1.12.2_netty/sample-config.groovy b/proto_1.12.2_netty/sample-config.groovy
new file mode 100644
index 0000000..99c2173
--- /dev/null
+++ b/proto_1.12.2_netty/sample-config.groovy
@@ -0,0 +1,18 @@
+beans {
+ xmlns([context: 'http://www.springframework.org/schema/context'])
+ context.'annotation-config'()
+ context.'component-scan'('base-package': 'mc.core.network.proto_1_12_2.netty')
+
+ /* Для логирования сетевых пакетов, можно добавить нижезакомментированный бин */
+ //'pipeline.log'(io.netty.handler.logging.LoggingHandler) { bean -> bean.scope = 'prototype' }
+ 'pipeline.decoder'(mc.core.network.proto_1_12_2.netty.PacketDecoder) { bean -> bean.scope = 'prototype' }
+ 'pipeline.postencoder'(mc.core.network.proto_1_12_2.netty.PacketPostEncoder) { bean -> bean.scope = 'prototype' }
+ 'pipeline.encoder'(mc.core.network.proto_1_12_2.netty.PacketEncoder) { bean -> bean.scope = 'prototype' }
+ 'pipeline.handler'(mc.core.network.proto_1_12_2.netty.PacketHandler) { bean -> bean.scope = 'prototype' }
+
+ server(mc.core.network.proto_1_12_2.netty.NettyServer) {
+ host = '127.0.0.1'
+ port = 25565
+ workerGroupCount = 2
+ }
+}
\ No newline at end of file
diff --git a/proto_1.12.2_netty/sample-config.xml b/proto_1.12.2_netty/sample-config.xml
deleted file mode 100644
index 0ff4b97..0000000
--- a/proto_1.12.2_netty/sample-config.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/simple_world/README.MD b/simple_world/README.MD
index 02871ed..8a6034d 100644
--- a/simple_world/README.MD
+++ b/simple_world/README.MD
@@ -4,36 +4,32 @@
## Spring bean
-```xml
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1;BEDROCK
- 2;DIRT
- 1;GRASS
-
-
-
+```groovy
+def layers = new ArrayList();
+layers.add('1;BEDROCK')
+layers.add('2;DIRT')
+layers.add('1;GRASS')
+
+beans {
+ spawnLocation(mc.core.EntityLocation) { bean ->
+ bean.constructorArgs = [ 8d/*X*/, 6d/*Y*/, 8d/*Z*/, 0f/*Yaw*/, 0f/*Pitch*/ ]
+ }
+
+ flatChunkProvider(mc.world.simple.FlatChunkProvider) {
+ layersBlock = layers
+ }
+
+ simpleWorld(mc.world.simple.SimpleWorld) {
+ spawn = ref('spawnLocation')
+ chunkProvider = ref('flatChunkProvider')
+ }
+}
```
-`spawn` - точка спавна.
+`spawn` - точка спавна
+`chunkProvider` - провайдер чанков
-При указании точки спавна, указывать шестой параметр `World` не имеет смысла,
-т.к. `SimpleWorld` всё равно перезапишет этот параметр.
-
-`layersBlock` - слои блоков.
-
-В качестве значения указывается спиток строк, каждая из которых описывает слой блоков.
-Формат строк такой: `кол-во_слоёв;тип_блока`. Порядок строк такой: сверху нижние слои, а снизу - верхние.
+У `flatChunkProvider` указан только один параметр - `layersBlock`. В качестве значения указывается спиток строк,
+каждая из которых описывает слой блоков.
+Формат строк следующий: `кол-во_слоёв;тип_блока`.
+Порядок строк следующий: сверху **нижние слои**, а снизу - **верхние**.