Archived
0

Merge branch 'release/limbo'

This commit is contained in:
2019-01-30 00:24:11 +03:00
119 changed files with 6465 additions and 132 deletions

View File

@@ -1,10 +1,24 @@
# Core
Ядро сервера
Ядро сервера.
Пример настройки можно посмотреть в файле `sample-config.xml`.
## Spring beans
### ConfigFromSpring
### Разное
#### CoreEventListener
Стандартный обработчик системных событий.
**Bean example:**
```xml
<bean class="mc.core.CoreEventListener"/>
```
#### ConfigFromSpring
Настройка параметров сервера через конфигурацию "спринга".
@@ -25,20 +39,36 @@
</bean>
```
### GameLoop
#### GameLoop
**Bean example:**
Доступные параметры:
* `gameTimer` - бин, управляющий ходом времени
* `percentWarnLowTps` - порог "низкого" значения TPS, в процентах
```xml
<bean id="gameLoop" class="mc.core.GameLoop">
<property name="gameTimer" ref="timeProcessor"/>
<property name="percentWarnLowTps" value="15"/>
</bean>
```
### IdleTime
#### SimpleChatProcessor
Простой обработчик чата.
**Implements:** `mc.core.chat.ChatProcessor`
**Bean example:**
```xml
<bean id="chatProcessor" class="mc.core.chat.SimpleChatProcessor" />
```
### Время
#### IdleTime
Игровое время суток застывает на указанной отметке.
@@ -55,7 +85,7 @@
</bean>
```
### TimePerTick
#### TimePerTick
Игровое время суток соответствует игровым тикам (20 tps)
@@ -72,7 +102,7 @@
</bean>
```
### RealTime
#### RealTime
Игровое время суток соответствует реальному времени

View File

@@ -1,4 +1,4 @@
version '0.1'
version '0.2'
apply plugin: 'maven'
apply plugin: 'application'

28
core/sample-config.xml Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<bean id="config" class="mc.core.embedded.ConfigFromSpring">
<property name="descriptionServer" value="MC Core - LIMBO"/>
<property name="maxPlayers" value="1"/>
</bean>
<bean id="timer" class="mc.core.time.IdleTime">
<property name="gameTime" value="1000"/>
</bean>
<bean class="mc.core.CoreEventListener"/>
<bean id="gameLoop" class="mc.core.GameLoop">
<property name="gameTimer" ref="timer"/>
<property name="percentWarnLowTps" value="15"/>
</bean>
<bean id="chatProcessor" class="mc.core.chat.SimpleChatProcessor" />
</beans>

View File

@@ -18,7 +18,7 @@ public class GameLoop extends Thread {
private TimeProcessor gameTimer;
public GameLoop() {
super();
super("Game Loop Thread");
setTps(20);
setPercentWarnLowTps(5);
}

View File

@@ -1,13 +0,0 @@
package mc.core.chat;
import mc.core.player.Player;
import java.util.Optional;
public interface CommandExecutor {
String getName();
Optional<String[]> getAliases();
Optional<String> getUsage();
String getDescription();
void execute(Player sender, String... args);
}

View File

@@ -1,90 +0,0 @@
package mc.core.chat;
import lombok.extern.slf4j.Slf4j;
import mc.core.player.Player;
import mc.core.text.Text;
import mc.core.text.TextColor;
import mc.core.text.TextTemplate;
import org.slf4j.Marker;
import org.slf4j.helpers.BasicMarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class CommanderChatProcessor extends SimpleChatProcessor {
private static final Marker COMMAND_MARKER = new BasicMarkerFactory().getMarker("Command");
private static final TextTemplate UNKNOW_COMMAND_MSG = TextTemplate.builder()
.append(Text.of("Unknown command \"", TextColor.RED))
.arg("command", TextColor.WHITE)
.append(Text.of("\"", TextColor.RED))
.build();
@Autowired
private ApplicationContext applicationContext;
private Map<String, CommandExecutor> commands = new HashMap<>();
@PostConstruct
public void init() {
Map<String, CommandExecutor> beans = applicationContext.getBeansOfType(CommandExecutor.class);
beans.values().forEach(commandExecutor -> {
log.trace("Add command \"{}\" ({})", commandExecutor.getName(), commandExecutor.getClass().getName());
if (commands.containsKey(commandExecutor.getName())) {
log.warn("Override command \"{}\"", commandExecutor.getName());
log.debug("{} -> {}",
commands.get(commandExecutor.getName()).getClass().getName(),
commandExecutor.getClass().getName()
);
}
commands.put(commandExecutor.getName(), commandExecutor);
if (commandExecutor.getAliases().isPresent()) {
Arrays.stream(commandExecutor.getAliases().get()).forEach(aliase -> {
log.trace("Add aliase \"{}\" ({})", aliase, commandExecutor.getClass().getName());
if (commands.containsKey(aliase)) {
log.warn("Override aliase \"{}\"", aliase);
log.debug("{} -> {}",
commands.get(aliase).getClass().getName(),
commandExecutor.getClass().getName()
);
}
commands.put(aliase, commandExecutor);
});
}
});
log.debug("Load {} commands", commands.size());
}
@Override
public void process(Player player, String message) {
if (message.startsWith("/")) {
log.info(COMMAND_MARKER, "<{}> {}", player.getName(), message);
int idx = message.indexOf(' ');
if (idx == -1) {
idx = message.length();
}
String command = message.substring(1, idx).toLowerCase();
if (commands.containsKey(command)) {
String[] args = message.substring(idx).split(" ");
commands.get(command).execute(player, args);
} else {
player.getChannel().sendChatMessage(
UNKNOW_COMMAND_MSG.apply("command", command),
MessageType.SYSTEM_MESSAGE);
}
} else {
super.process(player, message);
}
}
public Collection<CommandExecutor> getAllCommands() {
return commands.values();
}
}

View File

@@ -41,10 +41,6 @@ public class NibbleArray {
return isLowerNibble(idx) ? this.data[ni] & 0x0F : this.data[ni] >> 4 & 0x0F;
}
public void set(BlockLocation location, int value) {
set(location.getX(), location.getY(), location.getZ(), value);
}
public void set(int x, int y, int z, int value) {
if (value < 0) value = 0;
else if (value > 15) value = 15;

View File

@@ -1,10 +1,13 @@
package mc.core.world.block;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
@Slf4j
@@ -491,25 +494,29 @@ public enum BlockType {
this.namedId = null;
}
public static BlockType getByIdMeta(int id, int meta) {
if (id < 0) {
log.warn("Incorrect id \"{}\"", id);
return BEDROCK;
}
Stream<BlockType> stream = Arrays.stream(BlockType.values());
return stream.filter(blockType -> blockType.id == id && blockType.meta == meta)
.findFirst()
.orElseGet(() -> {
log.warn("Unknow block type: {}:{}", id, meta);
return BEDROCK;
});
}
@Getter
private final int id;
@Getter
private final int meta;
@Getter
private final String namedId;
private static final Table<Integer, Integer, BlockType> typeTable = HashBasedTable.create();
static {
Arrays.stream(BlockType.values())
.forEach(blockType -> typeTable.put(blockType.id, blockType.meta, blockType));
}
public static BlockType getByIdMeta(int id, int meta) {
if (id < 0) {
log.warn("Incorrect id \"{}\"", id);
return BEDROCK;
}
return Optional.ofNullable(typeTable.get(id, meta)).orElseGet(() -> {
log.warn("Unknow block type: {}:{}", id, meta);
return BEDROCK;
});
}
}