コード例 #1
0
ファイル: PlotterPlugin.cs プロジェクト: apieceofcaken/MiNET
        private void OnTicking(object sender, PlayerEventArgs e)
        {
            var player = e.Player;
            var level  = player.Level;

            if (level.Dimension == Dimension.Overworld)
            {
                PlotterPluginStore store = player.Store <PlotterPluginStore>();

                if (_plotManager.TryGetPlot((PlotCoordinates)player.KnownPosition, out Plot plot))
                {
                    if (store.CurrentPlot != plot)
                    {
                        player.SendSetTime(plot.Time);
                        player.SendSetDownfall(plot.Downfall);

                        if (plot.Owner.Equals(player.ClientUuid) || plot.AllowedPlayers.Contains(player.ClientUuid))
                        {
                            if (player.IsWorldImmutable)
                            {
                                player.IsWorldImmutable = false;
                                player.SendAdventureSettings();
                            }
                        }
                        else
                        {
                            if (!player.IsWorldImmutable)
                            {
                                player.IsWorldImmutable = true;
                                player.SendAdventureSettings();
                            }
                        }

                        string plotName        = string.IsNullOrEmpty(plot.Title) ? $"{plot.Coordinates.X},{plot.Coordinates.Z}" : plot.Title;
                        string plotDescription = string.IsNullOrEmpty(plot.Description) ? "" : $"{ChatColors.Aqua}{plot.Description}\n";
                        player.SendTitle(null, TitleType.Clear);
                        player.SendTitle(null, TitleType.AnimationTimes, 6, 6, 3 * 10);
                        player.SendTitle($"{plotDescription}{ChatColors.White}Owner is {_plotManager.GetPlotPlayer(plot.Owner).Username}", TitleType.SubTitle);
                        player.SendTitle($"{ChatColors.Gold}This is plot {plotName}", TitleType.Title);
                        store.CurrentPlot = plot;
                    }
                }
                else
                {
                    store.CurrentPlot = null;
                    if (!player.IsWorldImmutable)
                    {
                        player.IsWorldImmutable = true;
                        player.SendSetDownfall(0);
                        player.SendAdventureSettings();
                        player.SendSetTime();
                    }
                }
            }
        }
コード例 #2
0
        public string PlotSetOwner(Player player, string username)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (coords == null)
            {
                return("Not able to set owner for this plot.");
            }
            if (!_plotManager.HasClaim(coords, player))
            {
                return("Not able to set owner for this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("Not able to set owner for this plot.");
            }

            var plotPlayer = _plotManager.GetPlotPlayer(username);

            if (plotPlayer == null)
            {
                var newOwnerPlayer = player.Level.GetSpawnedPlayers().FirstOrDefault(p => p.Username.Equals(username, StringComparison.InvariantCultureIgnoreCase));
                if (newOwnerPlayer == null)
                {
                    return($"Found no player with the name {username}");
                }

                plotPlayer = _plotManager.GetOrAddPlotPlayer(newOwnerPlayer);
            }

            plot.Owner = plotPlayer.Xuid;
            if (!_plotManager.UpdatePlot(plot))
            {
                return("Not able to set owner for this plot.");
            }

            return($"Set new owner to {username}");
        }