default spring config
This commit is contained in:
@@ -7,10 +7,14 @@ package mc.core;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.network.Server;
|
import mc.core.network.Server;
|
||||||
import mc.core.network.StartServerException;
|
import mc.core.network.StartServerException;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -19,11 +23,17 @@ public class Main {
|
|||||||
private static ApplicationContext createContext() {
|
private static ApplicationContext createContext() {
|
||||||
final String springXml = System.getProperty("springConfig", "./spring.xml");
|
final String springXml = System.getProperty("springConfig", "./spring.xml");
|
||||||
|
|
||||||
if (Files.exists(Paths.get(springXml))) {
|
if (!Files.exists(Paths.get(springXml))) {
|
||||||
return new FileSystemXmlApplicationContext(springXml);
|
log.info("File \"{}\" not found. Get default config.", springXml);
|
||||||
} else {
|
try (FileOutputStream fos = new FileOutputStream(springXml)) {
|
||||||
return new ClassPathXmlApplicationContext("spring.xml");
|
IOUtils.copy(Main.class.getResourceAsStream("/spring.xml"), fos);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Get default spring config", e);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new FileSystemXmlApplicationContext(springXml);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
91
core/src/main/java/mc/core/embedded/FakePlayerManager.java
Normal file
91
core/src/main/java/mc/core/embedded/FakePlayerManager.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2018-06-29
|
||||||
|
*/
|
||||||
|
package mc.core.embedded;
|
||||||
|
|
||||||
|
import mc.core.Location;
|
||||||
|
import mc.core.chat.MessageType;
|
||||||
|
import mc.core.network.NetChannel;
|
||||||
|
import mc.core.network.SCPacket;
|
||||||
|
import mc.core.player.Look;
|
||||||
|
import mc.core.player.Player;
|
||||||
|
import mc.core.player.PlayerManager;
|
||||||
|
import mc.core.text.Text;
|
||||||
|
import mc.core.text.Title;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class FakePlayerManager implements PlayerManager {
|
||||||
|
public static class FakeNetChannet implements NetChannel {
|
||||||
|
@Override
|
||||||
|
public void sendKeepAlive() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTimeUpdate(long time, long age) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendChatMessage(Text text, MessageType type) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTitle(Title title) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeAndFlush(SCPacket pkt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(SCPacket pkt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final NetChannel FAKE_NET_CHANNEL = new FakeNetChannet();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player createPlayer(String name, Location defaultLocation, Look defaultLook) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void joinServer(Player player) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leftServer(Player player) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Player> getPlayer(String name) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Player> getPlayerById(int id) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Player> getPlayers() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCountOnlinePlayers() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetChannel getBroadcastChannel() {
|
||||||
|
return FAKE_NET_CHANNEL;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
core/src/main/java/mc/core/embedded/FakeServer.java
Normal file
18
core/src/main/java/mc/core/embedded/FakeServer.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2018-06-29
|
||||||
|
*/
|
||||||
|
package mc.core.embedded;
|
||||||
|
|
||||||
|
import mc.core.network.Server;
|
||||||
|
import mc.core.network.StartServerException;
|
||||||
|
|
||||||
|
public class FakeServer implements Server {
|
||||||
|
@Override
|
||||||
|
public void start() throws StartServerException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
}
|
||||||
|
}
|
||||||
20
core/src/main/resources/spring.xml
Normal file
20
core/src/main/resources/spring.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?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="playerManager" class="mc.core.embedded.FakePlayerManager"/>
|
||||||
|
|
||||||
|
<bean id="gameLoop" class="mc.core.GameLoop">
|
||||||
|
<property name="gameTimer">
|
||||||
|
<bean class="mc.core.time.TimePerTick"/>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean id="server" class="mc.core.embedded.FakeServer"/>
|
||||||
|
</beans>
|
||||||
Reference in New Issue
Block a user