public override void StartServerSide(ICoreServerAPI api) { base.StartServerSide(api); this.sapi = api; api.RegisterCommand("nexttempstorm", "", "Tells you the amount of days until the next storm", onCmdNextStorm, Privilege.controlserver); serverChannel = api.Network.RegisterChannel("temporalstability") .RegisterMessageType(typeof(TemporalStormRunTimeData)) ; api.Event.SaveGameLoaded += () => { bool prepNextStorm = sapi.WorldManager.SaveGame.IsNew; // Init old saves if (!sapi.World.Config.HasAttribute("temmporalStability")) { string playstyle = sapi.WorldManager.SaveGame.PlayStyle; if (playstyle == "surviveandbuild" || playstyle == "wildernesssurvival") { sapi.WorldManager.SaveGame.WorldConfiguration.SetBool("temmporalStability", true); } } if (!sapi.World.Config.HasAttribute("temporalStorms")) { string playstyle = sapi.WorldManager.SaveGame.PlayStyle; if (playstyle == "surviveandbuild" || playstyle == "wildernesssurvival") { sapi.WorldManager.SaveGame.WorldConfiguration.SetString("temporalStorms", playstyle == "surviveandbuild" ? "sometimes" : "often"); } } byte[] bytedata = sapi.WorldManager.SaveGame.GetData("temporalStormData"); if (bytedata != null) { try { data = SerializerUtil.Deserialize <TemporalStormRunTimeData>(bytedata); } catch (Exception) { api.World.Logger.Notification("Failed loading temporal storm data, will initialize new data set"); data = new TemporalStormRunTimeData(); prepNextStorm = true; } } else { data = new TemporalStormRunTimeData(); prepNextStorm = true; } LoadNoise(); if (prepNextStorm) { prepareNextStorm(); } }; api.Event.OnTrySpawnEntity += Event_OnTrySpawnEntity; api.Event.GameWorldSave += Event_GameWorldSave; api.Event.PlayerJoin += Event_PlayerJoin; api.Event.PlayerNowPlaying += Event_PlayerNowPlaying; api.Event.RegisterGameTickListener(onTempStormTick, 2000); }
private void onServerData(TemporalStormRunTimeData data) { this.data = data; }