Esempio n. 1
0
        protected override void EntityInit(CompoundTag nbt)
        {
            base.EntityInit(nbt);

            this.Attributes.AddAttribute(EntityAttribute.HUNGER);
            this.Attributes.AddAttribute(EntityAttribute.SATURATION);
            this.Attributes.AddAttribute(EntityAttribute.EXHAUSTION);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE);
            this.Attributes.AddAttribute(EntityAttribute.EXPERIENCE_LEVEL);

            this.SetFlag(DATA_FLAGS, DATA_FLAG_BREATHING);
            this.SetFlag(DATA_FLAGS, DATA_FLAG_CAN_CLIMB);

            this.Inventory = new PlayerInventory(this);
            this.Inventory.LoadNBT(nbt);

            this.World = World.GetWorld(nbt.GetString("World")) ?? World.GetMainWorld();

            this.SpawnX = nbt.GetInt("SpawnX");
            this.SpawnY = nbt.GetInt("SpawnY");
            this.SpawnZ = nbt.GetInt("SpawnZ");

            this.AdventureSettingsEntry = new AdventureSettingsEntry();

            this.GameMode = GameModeExtention.FromIndex(nbt.GetInt("PlayerGameType"));
        }
Esempio n. 2
0
        private void LoadData()
        {
            string path = $"{Server.ExecutePath}\\players\\{this.Name}.dat";

            if (!File.Exists(path))
            {
                PlayerCreateDataEventArgs playerCreateDataEvent = new PlayerCreateDataEventArgs(this);
                PlayerEvents.OnPlayerCreateData(playerCreateDataEvent);

                this.RegisterData();
            }
            else
            {
                this.NamedTag = NBTIO.ReadGZIPFile(path, NBTEndian.BIG_ENDIAN);
            }

            this.Inventory = new PlayerInventory(this);

            this.gameMode = GameModeExtention.FromIndex(this.NamedTag.GetInt("PlayerGameMode"));
        }
Esempio n. 3
0
        public override bool OnExecute(CommandSender sender, string command, params string[] args)
        {
            if (args.Length < 1)
            {
                this.SendLengthErrorMessage(sender, command, args, args.Length);
                return(false);
            }
            else if (args.Length < 2)
            {
                if (!sender.IsPlayer)
                {
                    this.SendLengthErrorMessage(sender, command, args, args.Length);
                    return(false);
                }

                int gamemode = 0;
                if (!int.TryParse(args[0], out gamemode))
                {
                    if (args[0] == "s" || args[0] == "survival")
                    {
                        gamemode = 0;
                    }
                    else if (args[0] == "c" || args[0] == "creative")
                    {
                        gamemode = 1;
                    }
                    else if (args[0] == "a" || args[0] == "adventure")
                    {
                        gamemode = 2;
                    }
                    else
                    {
                        sender.SendMessage(new TranslationContainer(TextFormat.RED, "commands.gamemode.fail.invalid", args[0]));
                        return(false);
                    }
                }

                if (gamemode < 0 || 3 < gamemode)
                {
                    sender.SendMessage(new TranslationContainer(TextFormat.RED, "commands.gamemode.fail.invalid", gamemode));
                    return(false);
                }

                Player player = (Player)sender;
                player.GameMode = GameModeExtention.FromIndex(gamemode);
                player.SendMessage(new TranslationContainer("commands.gamemode.success.self", player.GameMode.GetGameModeString()));
                Server.Instance.BroadcastMessageAndLoggerSend(new TranslationContainer("commands.gamemode.success.other", player.GameMode.GetGameModeString(), player.Name));
            }
            else
            {
                int gamemode = 0;
                if (!int.TryParse(args[0], out gamemode))
                {
                    if (args[0] == "s" || args[0] == "survival")
                    {
                        gamemode = 0;
                    }
                    else if (args[0] == "c" || args[0] == "creative")
                    {
                        gamemode = 1;
                    }
                    else if (args[0] == "a" || args[0] == "adventure")
                    {
                        gamemode = 2;
                    }
                    else
                    {
                        sender.SendMessage(new TranslationContainer(TextFormat.RED, "commands.gamemode.fail.invalid", args[0]));
                        return(false);
                    }
                }

                if (gamemode < 0 || 3 < gamemode)
                {
                    sender.SendMessage(new TranslationContainer(TextFormat.RED, "commands.gamemode.fail.invalid", gamemode));
                    return(false);
                }

                if (args[1] == "@e")
                {
                    this.SendTargetNotPlayerMessage(sender);
                    return(false);
                }

                Player[] players = this.GetPlayerFromSelector(args[1], sender);
                if (players == null)
                {
                    this.SendNoTargetMessage(sender);
                    return(false);
                }

                for (int i = 0; i < players.Length; ++i)
                {
                    players[i].GameMode = GameModeExtention.FromIndex(gamemode);
                    players[i].SendMessage(new TranslationContainer("commands.gamemode.success.self", players[i].GameMode.GetGameModeString()));
                    Server.Instance.BroadcastMessageAndLoggerSend(new TranslationContainer("commands.gamemode.success.other", players[i].GameMode.GetGameModeString(), players[i].Name));
                }

                //TODO: need send message at op
            }
            return(true);
        }