|
| 1 | +package me.devnatan.inventoryframework.runtime |
| 2 | + |
| 3 | +import me.devnatan.inventoryframework.ViewFrame |
| 4 | +import me.devnatan.inventoryframework.runtime.command.GamemodeCommand |
| 5 | +import me.devnatan.inventoryframework.runtime.command.IFExampleCommand |
| 6 | +import me.devnatan.inventoryframework.runtime.view.Failing |
| 7 | +import me.devnatan.inventoryframework.runtime.view.ScheduledView |
| 8 | +import me.devnatan.inventoryframework.runtime.view.SimplePagination |
| 9 | +import net.minestom.server.MinecraftServer |
| 10 | +import net.minestom.server.coordinate.Pos |
| 11 | +import net.minestom.server.entity.PlayerSkin |
| 12 | +import net.minestom.server.event.player.AsyncPlayerConfigurationEvent |
| 13 | +import net.minestom.server.event.player.PlayerSkinInitEvent |
| 14 | +import net.minestom.server.event.player.PlayerSpawnEvent |
| 15 | +import net.minestom.server.instance.LightingChunk |
| 16 | +import net.minestom.server.instance.block.Block |
| 17 | +import net.minestom.server.inventory.TransactionOption |
| 18 | +import net.minestom.server.item.ItemStack |
| 19 | +import net.minestom.server.item.Material |
| 20 | + |
| 21 | +class SampleServer { |
| 22 | + init { |
| 23 | + val server = MinecraftServer.init() |
| 24 | + val instanceManager = MinecraftServer.getInstanceManager() |
| 25 | + |
| 26 | + // Create word filled with quartz blocks up to height 50 |
| 27 | + val instance = instanceManager.createInstanceContainer() |
| 28 | + instance.setGenerator { |
| 29 | + it.modifier().fillHeight(it.absoluteStart().blockY(), 50, Block.QUARTZ_BLOCK) |
| 30 | + } |
| 31 | + instance.setChunkSupplier(::LightingChunk) |
| 32 | + |
| 33 | + val handler = MinecraftServer.getGlobalEventHandler() |
| 34 | + |
| 35 | + handler.addListener(AsyncPlayerConfigurationEvent::class.java) { event -> |
| 36 | + event.spawningInstance = instance |
| 37 | + event.player.respawnPoint = Pos(0.0, 53.0, 0.0) |
| 38 | + } |
| 39 | + handler.addListener(PlayerSkinInitEvent::class.java) { event -> |
| 40 | + event.skin = PlayerSkin.fromUsername(event.player.username) |
| 41 | + } |
| 42 | + handler.addListener(PlayerSpawnEvent::class.java) { event -> |
| 43 | + event.player.inventory.addItemStacks(ExampleUtil.getRandomItems(20), TransactionOption.ALL) |
| 44 | + event.player.inventory.addItemStack(ItemStack.of(Material.OAK_PLANKS, 64), TransactionOption.ALL) |
| 45 | + } |
| 46 | + |
| 47 | + val viewFrame = |
| 48 | + ViewFrame.create(handler) |
| 49 | + .with( |
| 50 | + Failing(), |
| 51 | + SimplePagination(), |
| 52 | + ScheduledView(), |
| 53 | + ) |
| 54 | + .register() |
| 55 | + |
| 56 | + MinecraftServer.getCommandManager().register( |
| 57 | + IFExampleCommand(viewFrame), |
| 58 | + GamemodeCommand(viewFrame), |
| 59 | + ) |
| 60 | + |
| 61 | + server.start("0.0.0.0", 25565) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +fun main() { |
| 66 | + SampleServer() |
| 67 | +} |
0 commit comments