remove lobby system
This commit is contained in:
parent
dca9c7bfb6
commit
04f3f6b448
@ -5,6 +5,8 @@ import eu.mhsl.craftattack.worldmuseum.commands.GcCommand;
|
|||||||
import eu.mhsl.craftattack.worldmuseum.commands.TeleportCommand;
|
import eu.mhsl.craftattack.worldmuseum.commands.TeleportCommand;
|
||||||
import eu.mhsl.craftattack.worldmuseum.listener.ChunkUnloading;
|
import eu.mhsl.craftattack.worldmuseum.listener.ChunkUnloading;
|
||||||
import eu.mhsl.craftattack.worldmuseum.listener.ClickListener;
|
import eu.mhsl.craftattack.worldmuseum.listener.ClickListener;
|
||||||
|
import eu.mhsl.craftattack.worldmuseum.util.Config;
|
||||||
|
import eu.mhsl.craftattack.worldmuseum.worlds.World;
|
||||||
import eu.mhsl.craftattack.worldmuseum.worlds.WorldManager;
|
import eu.mhsl.craftattack.worldmuseum.worlds.WorldManager;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
@ -26,7 +28,6 @@ import java.util.List;
|
|||||||
public class Main {
|
public class Main {
|
||||||
static int PORT = 25565;
|
static int PORT = 25565;
|
||||||
static String IP = "0.0.0.0";
|
static String IP = "0.0.0.0";
|
||||||
static List<InstanceContainer> worlds = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Initialization
|
// Initialization
|
||||||
@ -34,27 +35,17 @@ public class Main {
|
|||||||
MinecraftServer minecraftServer = MinecraftServer.init();
|
MinecraftServer minecraftServer = MinecraftServer.init();
|
||||||
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//temp
|
//temp
|
||||||
MinecraftServer.getSchedulerManager().scheduleTask(new TablistUpdateTask(), TaskSchedule.tick(20), TaskSchedule.tick(20));
|
MinecraftServer.getSchedulerManager().scheduleTask(new TablistUpdateTask(), TaskSchedule.tick(20), TaskSchedule.tick(20));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//load eu.mhsl.craftattack.worldmuseum.worlds / configExample file
|
//load eu.mhsl.craftattack.worldmuseum.worlds / configExample file
|
||||||
WorldManager.getInstance().loadWorlds();
|
WorldManager worldManager = WorldManager.getInstance();
|
||||||
|
worldManager.loadWorlds();
|
||||||
// Create starting-instance / world
|
|
||||||
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
|
|
||||||
instanceContainer.setBlock(0,0,0,Block.STONE);
|
|
||||||
|
|
||||||
|
//load main config
|
||||||
|
Config config = Config.getInstance();
|
||||||
|
config.loadConfig();
|
||||||
|
World startworld = config.getStart_world();
|
||||||
|
|
||||||
// Add an event callback to specify the spawning instance (and the spawn position)
|
// Add an event callback to specify the spawning instance (and the spawn position)
|
||||||
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
|
||||||
@ -70,20 +61,20 @@ public class Main {
|
|||||||
|
|
||||||
globalEventHandler.addListener(PlayerLoginEvent.class, event -> {
|
globalEventHandler.addListener(PlayerLoginEvent.class, event -> {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
event.setSpawningInstance(instanceContainer);
|
event.setSpawningInstance(startworld);
|
||||||
player.setRespawnPoint(new Pos(0.5,2,0.5));
|
player.setRespawnPoint(startworld.getSpawn());
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i< WorldManager.getInstance().getWorlds().size(); i++) {
|
// for (int i = 0; i< WorldManager.getInstance().getWorlds().size(); i++) {
|
||||||
if (WorldManager.getInstance().getWorlds().get(i).isEnabled()) {
|
// if (WorldManager.getInstance().getWorlds().get(i).isEnabled()) {
|
||||||
player.getInventory().setItemStack(i, WorldManager.getInstance().getWorlds().get(i).getItem());
|
// player.getInventory().setItemStack(i, WorldManager.getInstance().getWorlds().get(i).getItem());
|
||||||
} else {
|
// } else {
|
||||||
System.out.println("Es gibt nicht aktivierte Welten!");
|
// System.out.println("Es gibt nicht aktivierte Welten!");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -13,7 +13,6 @@ public class TeleportCommand extends Command {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
var playerArgument = ArgumentType.Entity("Spieler").onlyPlayers(true);
|
var playerArgument = ArgumentType.Entity("Spieler").onlyPlayers(true);
|
||||||
var number = ArgumentType.Integer("Kordinaten");
|
|
||||||
|
|
||||||
addSyntax(((sender, context) -> {
|
addSyntax(((sender, context) -> {
|
||||||
Player targetPlayer = (Player) context.get(playerArgument).find(sender).get(0);
|
Player targetPlayer = (Player) context.get(playerArgument).find(sender).get(0);
|
||||||
|
3
src/main/java/eu/mhsl/craftattack/worldmuseum/default_config.json
Executable file
3
src/main/java/eu/mhsl/craftattack/worldmuseum/default_config.json
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"start_world": "world"
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package eu.mhsl.craftattack.worldmuseum.util;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import eu.mhsl.craftattack.worldmuseum.worlds.World;
|
||||||
|
import eu.mhsl.craftattack.worldmuseum.worlds.WorldManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
private static Config instance;
|
||||||
|
private World start_world;
|
||||||
|
public static Config getInstance() {
|
||||||
|
if (instance == null) instance = new Config();
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
public void loadConfig() {
|
||||||
|
checkConfig();
|
||||||
|
try {
|
||||||
|
JsonObject config = (JsonObject) JsonParser.parseReader(new FileReader("config.json"));
|
||||||
|
Iterator iterator = WorldManager.getInstance().getWorlds().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
World w = (World) iterator.next();
|
||||||
|
if (!w.getName().equals(config.get("start_world").getAsString())) continue;
|
||||||
|
this.start_world = w;
|
||||||
|
}
|
||||||
|
if (start_world == null) {
|
||||||
|
System.out.println("no starting world set");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private String default_config = "{\n" +
|
||||||
|
" \"start_world\": \"world\"\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
private void checkConfig() {
|
||||||
|
try {
|
||||||
|
File checkfile = new File("./config.json");
|
||||||
|
if (checkfile.createNewFile()) {
|
||||||
|
FileWriter fileWriter = new FileWriter("config.json");
|
||||||
|
fileWriter.write(default_config);
|
||||||
|
fileWriter.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getStart_world() {
|
||||||
|
return start_world;
|
||||||
|
}
|
||||||
|
}
|
@ -76,6 +76,11 @@ public class World extends InstanceContainer {
|
|||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,12 @@ public class WorldManager {
|
|||||||
List<File> worldFolders = getFolderNames(saveDirectory);
|
List<File> worldFolders = getFolderNames(saveDirectory);
|
||||||
for (File f: worldFolders
|
for (File f: worldFolders
|
||||||
) {
|
) {
|
||||||
worlds.add(new World(f));
|
World w = new World(f);
|
||||||
|
if (w.isEnabled()) {
|
||||||
|
worlds.add(w);
|
||||||
|
} else {
|
||||||
|
System.out.println("Es gibt eine nicht aktivierte Welt: " + f.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user