Search in sources :

Example 1 with Waystones

use of wraith.waystones.Waystones in project FabricWaystones by LordDeatHunter.

the class WaystonesEventManager method registerEvents.

public static void registerEvents() {
    ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
        if (Waystones.WAYSTONE_STORAGE == null) {
            Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
        }
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
        Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
        Waystones.WAYSTONE_STORAGE = null;
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
        Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
        Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
    });
    ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
    ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
        Config.getInstance().loadConfig();
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
            ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
        }
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player != null) {
            player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
        }
        return 1;
    })).then(CommandManager.literal("display").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player == null) {
            return 1;
        }
        Config.getInstance().print(player);
        return 1;
    }))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Waystones(wraith.waystones.Waystones) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerPlayerEvents(net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents) CommandRegistrationCallback(net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerLifecycleEvents(net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents) PacketByteBufs(net.fabricmc.fabric.api.networking.v1.PacketByteBufs) CommandManager(net.minecraft.server.command.CommandManager) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Aggregations

CommandRegistrationCallback (net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback)1 ServerPlayerEvents (net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents)1 ServerLifecycleEvents (net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents)1 PacketByteBufs (net.fabricmc.fabric.api.networking.v1.PacketByteBufs)1 ServerPlayConnectionEvents (net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents)1 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)1 PacketByteBuf (net.minecraft.network.PacketByteBuf)1 CommandManager (net.minecraft.server.command.CommandManager)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 LiteralText (net.minecraft.text.LiteralText)1 Waystones (wraith.waystones.Waystones)1 PlayerEntityMixinAccess (wraith.waystones.access.PlayerEntityMixinAccess)1