Exemple #1
0
        public void GetWorldConfig()
        {
            byte[] configBytes = (sapi.WorldManager.SaveGame.GetData("ImmersionWorldGen"));
            ImmersionWorldgenConfig storedConfig = null;

            if (configBytes != null)
            {
                storedConfig = JsonUtil.FromBytes <ImmersionWorldgenConfig>(configBytes);
            }

            string wPath = Path.Combine("immersion", "worldgen.json");

            try
            {
                ImmersionWorldgenConfig config = sapi.LoadModConfig <ImmersionWorldgenConfig>(wPath);

                GenAquifers    = genAquifers = config?.genAquifers ?? true;
                GenRivers      = genRivers = config?.genRivers ?? true;
                GenPalms       = genPalms = config?.genPalms ?? true;
                GenDeepOreBits = genDeepOreBits = config?.genDeepOreBits ?? true;
            }
            catch (Exception)
            {
            }

            sapi.StoreModConfig(this, wPath);

            GenAquifers    = genAquifers = sapi.World.Config.TryGetBool("genAquifers") ?? storedConfig?.genAquifers ?? true;
            GenRivers      = genRivers = sapi.World.Config.TryGetBool("genRivers") ?? storedConfig?.genRivers ?? true;
            GenPalms       = genPalms = sapi.World.Config.TryGetBool("genPalms") ?? storedConfig?.genPalms ?? true;
            GenDeepOreBits = genDeepOreBits = sapi.World.Config.TryGetBool("genDeepOreBits") ?? storedConfig?.genDeepOreBits ?? true;

            SaveWorldConfig();
        }
Exemple #2
0
        public Task(ICoreServerAPI api) : base(api)
        {
            _api = api;
            var conf = _api.LoadOrCreateConf <Config>(_automessageFilename);

            if (conf.messages.Count == 0)
            {
                api.Logger.Warning($"Oh, i don't see any messages in automessages file. Generating default...");
                var defaultMessages = new List <string> {
                    "First message! Set messages in automessage.json!",
                    "Second message! Plugin repository <a href='http://github.com/kiriharu/kessentials'>is here</a>",
                    "Third message! I can use <font size='5' " +
                    "color='green'" +
                    " weight='bold'" + ">VTML</font>"
                };
                conf.messages = defaultMessages;
                api.StoreModConfig(conf, _automessageFilename);
            }
            else
            {
                _messages = conf.messages;
            }
            _prefix = conf.prefix;
            Timer   = conf.timer;
            _minPlayersCountToPost = conf.minPlayersCountToPost;
        }
Exemple #3
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            this.sapi = api;
            GetWorldConfig();
            api.Event.GameWorldSave += SaveWorldConfig;
            sapi.RegisterCommand("immersionconfig", "Immersion Config", "", (player, group, args) =>
            {
                string word     = args.PopWord();
                bool?state      = args.PopBool();
                bool saveGlobal = args.PopBool() ?? false;
                switch (word)
                {
                case "aquifers":
                    sapi.World.Config.SetBool("genAquifers", GenAquifers = genAquifers = state ?? !GenAquifers);
                    player.SendMessage(0, string.Format("Worldgen parameter {0} set to {1}", word, GenAquifers), EnumChatType.OwnMessage);
                    break;

                case "rivers":
                    sapi.World.Config.SetBool("genRivers", GenRivers = genRivers = state ?? !GenRivers);
                    player.SendMessage(0, string.Format("Worldgen parameter {0} set to {1}", word, GenRivers), EnumChatType.OwnMessage);
                    break;

                case "palms":
                    sapi.World.Config.SetBool("genPalms", GenPalms = genPalms = state ?? !GenPalms);
                    player.SendMessage(0, string.Format("Worldgen parameter {0} set to {1}", word, GenPalms), EnumChatType.OwnMessage);
                    break;

                case "deeporebits":
                    sapi.World.Config.SetBool("genDeepOreBits", GenDeepOreBits = genDeepOreBits = state ?? !GenDeepOreBits);
                    player.SendMessage(0, string.Format("Worldgen parameter {0} set to {1}", word, GenDeepOreBits), EnumChatType.OwnMessage);
                    break;

                default:
                    break;
                }
                if (saveGlobal)
                {
                    string wPath = Path.Combine("immersion", "worldgen.json");
                    sapi.StoreModConfig(this, wPath);
                }
                SaveWorldConfig();
            }, Privilege.controlserver);
        }
Exemple #4
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            base.StartServerSide(api);
            _coreServerApi = api;

            // Kit Config register
            LoadedKitsStorageClass = api.LoadOrCreateConf <KitsStorageClass>(KitsConfigName);

            // Kit Cooldown manager
            KitsCooldownManagerStorage = new KitCooldownManagerStorage(_coreServerApi, CooldownsConfigName);
            KitsCooldownManagerStorage.Load();
            KitsCooldownManager = KitsCooldownManagerStorage.CooldownManager;

            var kitsInstance = new Api.DefaultKits();

            if (LoadedKitsStorageClass.kits.Count == 0)
            {
                var defaultKit = kitsInstance.GetDefaultKit();
                LoadedKitsStorageClass.kits.Add(defaultKit);
                api.StoreModConfig(kitsInstance.GetLoadedKits(), KitsConfigName);
            }

            // Register commands
            api.RegisterCommand(new Commands.Kit(api, kitsInstance));
            api.RegisterCommand(new Commands.Kits(api, kitsInstance));

            // Register priveleges
            api.RegisterPrivilegeClass(typeof(Privilege));
            foreach (var kit in LoadedKitsStorageClass.kits)
            {
                api.Logger.Event($"Register {Privilege.kit}.{kit.name} kit-based permission");
                api
                .Permissions
                .RegisterPrivilege($"{Privilege.kit}.{kit.name}", $"Kit {kit.name}", true);
            }

            // Give kits on first join
            api.Event.PlayerCreate += kitsInstance.GiveFirstJoinKits;

            // Saving cooldowns to file
            api.Event.Timer(CooldownSaveTimer, 3600);
        }
Exemple #5
0
        public override void StartServerSide(ICoreServerAPI api)
        {
            base.StartServerSide(api);

            this.sapi = api;

            api.RegisterCommand("tpimp", ConstantsCore.ModPrefix + "Import teleport schematic", "[list|paste]",
                                (IServerPlayer player, int groupId, CmdArgs args) =>
            {
                switch (args?.PopWord())
                {
                case "help":

                    player.SendMessage(groupId, "/tpimp [list|paste]", EnumChatType.CommandError);
                    break;


                case "list":

                    List <IAsset> schematics = api.Assets.GetMany(Constants.TELEPORT_SCHEMATIC_PATH);

                    if (schematics == null || schematics.Count == 0)
                    {
                        player.SendMessage(groupId, Lang.Get("Not found"), EnumChatType.CommandError);
                        break;
                    }

                    StringBuilder list = new StringBuilder();
                    foreach (var sch in schematics)
                    {
                        list.AppendLine(sch.Name.Remove(sch.Name.Length - 5));
                    }
                    player.SendMessage(groupId, list.ToString(), EnumChatType.CommandSuccess);

                    break;


                case "paste":

                    string name = args.PopWord();
                    if (name == null || name.Length == 0)
                    {
                        player.SendMessage(groupId, "/tpimp paste [name]", EnumChatType.CommandError);
                        break;
                    }

                    IAsset schema = api.Assets.TryGet($"{Constants.TELEPORT_SCHEMATIC_PATH}/{name}.json");
                    if (schema == null)
                    {
                        player.SendMessage(groupId, Lang.Get("Not found"), EnumChatType.CommandError);
                        break;
                    }

                    string error = null;

                    BlockSchematic schematic = BlockSchematic.LoadFromFile(
                        schema.Origin.OriginPath + "/" + "game" + "/" + schema.Location.Path, ref error);

                    if (error != null)
                    {
                        player.SendMessage(groupId, error, EnumChatType.CommandError);
                        break;
                    }

                    PasteSchematic(schematic, player.Entity.Pos.AsBlockPos.Add(0, -1, 0));

                    break;


                default:
                    player.SendMessage(groupId, "/tpimp [list|paste]", EnumChatType.CommandError);
                    break;
                }
            },
                                Privilege.controlserver
                                );

            api.RegisterCommand("rndtp", ConstantsCore.ModPrefix + "Teleport player to random location", "[range]",
                                (IServerPlayer player, int groupId, CmdArgs args) =>
            {
                RandomTeleport(player, (int)args.PopInt(-1));
            },
                                Privilege.tp
                                );

            api.RegisterCommand("tpnetconfig", ConstantsCore.ModPrefix + "Config for TPNet", "[shared|unbreakable]",
                                (IServerPlayer player, int groupId, CmdArgs args) =>
            {
                switch (args?.PopWord())
                {
                case "help":

                    player.SendMessage(groupId, "/tpnetconfig [shared|unbreakable]", EnumChatType.CommandError);
                    break;


                case "shared":

                    Config.Current.SharedTeleports.Val = !Config.Current.SharedTeleports.Val;
                    api.StoreModConfig <Config>(Config.Current, api.GetWorldId() + "/" + ConstantsCore.ModId);
                    player.SendMessage(groupId, Lang.Get("Shared teleports now is " + (Config.Current.SharedTeleports.Val ? "on" : "off")), EnumChatType.CommandSuccess);
                    break;


                case "unbreakable":

                    Config.Current.Unbreakable.Val = !Config.Current.Unbreakable.Val;
                    api.StoreModConfig <Config>(Config.Current, api.GetWorldId() + "/" + ConstantsCore.ModId);
                    player.SendMessage(groupId, Lang.Get("Unbreakable teleports now is " + (Config.Current.Unbreakable.Val ? "on" : "off")), EnumChatType.CommandSuccess);
                    break;


                default:
                    player.SendMessage(groupId, "/tpnetconfig [shared|unbreakable]", EnumChatType.CommandError);
                    break;
                }
            },
                                Privilege.tp
                                );
        }
Exemple #6
0
 public void Save()
 {
     _serverApi.StoreModConfig(StorageClass, _configStorage);
 }
 public void SaveConfig() => sapi.StoreModConfig(Config, "blockphysicsmod.json");
Exemple #8
0
 //-- Generate config from previous settings and implement current version config changes --//
 private static void GenerateConfig(ICoreServerAPI api, MeteorConfig previousConfig)
 {
     api.StoreModConfig <MeteorConfig>(new MeteorConfig(previousConfig), "MeteoricExpansionConfig.json");
 }