Exemplo n.º 1
0
        public string PlotSetBiome(Player player, int biomeId = 1)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (!_plotManager.HasClaim(coords, player))
            {
                return("You don't own this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("No plot found.");
            }

            var bbox = PlotManager.GetBoundingBoxForPlot(plot.Coordinates);

            PlotWorldGenerator.SetBiome(player.Level, bbox, (byte)biomeId);

            Task.Run(() =>
            {
                player.CleanCache();
                player.ForcedSendChunks(() => { player.SendMessage($"Resent chunks."); });
            });

            return($"Set biome on plot {plot.Coordinates} to {biomeId}");
        }
Exemplo n.º 2
0
        public string PlotVisit(Player player, string username)
        {
            PlotPlayer plotPlayer = _plotManager.GetPlotPlayer(username);

            if (plotPlayer == null)
            {
                return("Sorry, that user is homeless.");
            }

            PlotCoordinates coords = (PlotCoordinates)plotPlayer.Home;

            if (coords == null)
            {
                return("Sorry, player is homeless.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("Sorry, we lost his home. Maybe ask an admin to find it again!");
            }

            int height = player.Level.GetHeight((BlockCoordinates)plotPlayer.Home);

            if (plotPlayer.Home.Y < height)
            {
                plotPlayer.Home.Y = height + 2;
            }
            player.Teleport(plotPlayer.Home);

            return($"Moved you to plot {plot.Coordinates.X},{plot.Coordinates.Z}. Home of {username}");
        }
Exemplo n.º 3
0
        public static BoundingBox GetBoundingBoxForPlot(PlotCoordinates coords)
        {
            var     offset = ConvertToBlockCoordinates(coords);
            Vector3 to     = (Vector3)offset + (Vector3) new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 1, PlotWorldGenerator.PlotDepth - 1);

            return(new BoundingBox(offset, to).GetAdjustedBoundingBox());
        }
Exemplo n.º 4
0
        public bool CanBuild(PlotCoordinates coords, Player player)
        {
            if (player == null)
            {
                return(false);
            }

            Plot plot = null;

            if (_plots.ContainsKey(coords))
            {
                plot = _plots[coords];
            }

            if (plot == null)
            {
                return(false);
            }

            if (Equals(plot.Owner, player.ClientUuid) || plot.AllowedPlayers.Contains(player.ClientUuid))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public string PlotHome(Player player)
        {
            PlotPlayer plotPlayer = _plotManager.GetOrAddPlotPlayer(player);

            if (plotPlayer == null)
            {
                return("Sorry, you don't exist.");
            }

            PlotCoordinates coords = (PlotCoordinates)plotPlayer.Home;

            if (coords == null)
            {
                return("Sorry, you are homeless.");
            }
            if (!_plotManager.HasClaim(coords, player))
            {
                return("Sorry, you don't own your home. Did the bank claim it?");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("Sorry, we lost your home. Ask an admin to find it again!");
            }

            int height = player.Level.GetHeight((BlockCoordinates)plotPlayer.Home);

            if (plotPlayer.Home.Y < height)
            {
                plotPlayer.Home.Y = height + 2;
            }
            player.Teleport(plotPlayer.Home);

            return($"Moved to your home plot {plot.Coordinates.X},{plot.Coordinates.Z}");
        }
Exemplo n.º 6
0
        public VanillaCommands.SimpleResponse PlotClaim(Player player)
        {
            PlotCoordinates coords = PlotManager.ConvertToPlotCoordinates(player.KnownPosition);

            if (coords == null)
            {
                return new VanillaCommands.SimpleResponse()
                       {
                           Body = "Not able to claim plot at this position."
                       }
            }
            ;

            Plot plot;

            if (!_plotManager.TryClaim(coords, player, out plot))
            {
                return new VanillaCommands.SimpleResponse()
                       {
                           Body = "Not able to claim plot at this position."
                       }
            }
            ;

            return(new VanillaCommands.SimpleResponse($"Claimed plot {plot.Coordinates.X}:{plot.Coordinates.Z} at {coords}"));
        }
Exemplo n.º 7
0
        private string ClaimPlot(Player player, PlotCoordinates coords)
        {
            var bbox   = PlotManager.GetBoundingBoxForPlot(coords);
            var center = bbox.Max - (bbox.Max - bbox.Min) / 2;
            int height = player.Level.GetHeight(center);

            player.Teleport(new PlayerLocation(center.X, height + 3, center.Z));

            return($"Claimed plot {coords.X},{coords.Z}");
        }
Exemplo n.º 8
0
        public bool TryClaim(PlotCoordinates coords, Player player, out Plot plot)
        {
            plot = null;
            if (_plots.ContainsKey(coords))
            {
                plot = _plots[coords];
            }

            if (plot != null)
            {
                return(false);
            }

            plot = new Plot()
            {
                Coordinates = coords
            };
            _plots.Add(coords, plot);


            var offset  = ConvertToBlockCoordinates(coords);
            int xOffset = offset.X;
            int zOffset = offset.Z;

            player.Level.SetBlock(new GoldBlock {
                Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset)
            });
            player.Level.SetBlock(new EmeraldBlock
            {
                Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset) + new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 1, PlotWorldGenerator.PlotDepth - 1)
            });


            Vector3     to   = (Vector3)offset + (Vector3) new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 256, PlotWorldGenerator.PlotDepth - 1);
            BoundingBox bbox = new BoundingBox(offset, to).GetAdjustedBoundingBox();


            Log.Error($"BBOX={bbox}, Min={bbox.Min}, Max={bbox.Max}");

            for (int x = (int)bbox.Min.X; x <= (int)bbox.Max.X; x++)
            {
                for (int z = (int)bbox.Min.Z; z <= (int)bbox.Max.Z; z++)
                {
                    player.Level.SetAir(x, PlotWorldGenerator.PlotHeight, z);
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool TryClaim(PlotCoordinates coords, Player player, out Plot plot)
        {
            plot = null;
            if (_plots.ContainsKey(coords))
            {
                plot = _plots[coords];
            }

            if (plot != null)
            {
                return(false);
            }

            plot = new Plot()
            {
                Coordinates = coords
            };
            _plots.Add(coords, plot);


            var offset  = ConvertToBlockCoordinates(coords);
            int xOffset = offset.X;
            int zOffset = offset.Z;

            player.Level.SetBlock(new GoldBlock {
                Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset)
            });
            player.Level.SetBlock(new EmeraldBlock
            {
                Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset) + new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 1, PlotWorldGenerator.PlotDepth - 1)
            });


            var         to   = offset + new BlockCoordinates(PlotWorldGenerator.PlotWidth, 0, PlotWorldGenerator.PlotDepth);
            BoundingBox bbox = BoundingBox.CreateFromPoints(new List <Vector3> {
                offset, to
            });

            for (int x = (int)bbox.Min.X; x < bbox.Max.X; x++)
            {
                for (int z = (int)bbox.Min.Z; z < bbox.Min.Z; z++)
                {
                    player.Level.SetAir(x, PlotWorldGenerator.PlotHeight, z);
                }
            }

            return(true);
        }
Exemplo n.º 10
0
        private void LevelOnBlockPlace(object sender, BlockPlaceEventArgs e)
        {
            PlotCoordinates coords = (PlotCoordinates)e.TargetBlock.Coordinates;

            if (coords == null)
            {
                e.Cancel = true;
            }
            else
            {
                if (e.Player != null)
                {
                    e.Cancel = !_plotManager.CanBuild(coords, e.Player);
                }
            }
        }
Exemplo n.º 11
0
		//public static PlotCoordinates ConvertToPlotCoordinates(PlayerLocation location)
		//{
		//	return ConvertToPlotCoordinates((BlockCoordinates) location);
		//}

		//public static PlotCoordinates ConvertToPlotCoordinates(BlockCoordinates coords)
		//{
		//	if (PlotWorldGenerator.IsXRoad(coords.X, true) || PlotWorldGenerator.IsZRoad(coords.Z, true)) return null;

		//	int plotX = coords.X/PlotWorldGenerator.PlotAreaWidth + (Math.Sign(coords.X));
		//	int plotZ = coords.Z/PlotWorldGenerator.PlotAreaDepth + (Math.Sign(coords.Z));

		//	return new PlotCoordinates(plotX, plotZ);
		//}

		public static BlockCoordinates ConvertToBlockCoordinates(PlotCoordinates plotCoordinates)
		{
			var xFactor = plotCoordinates.X > 0 ? plotCoordinates.X - 1 : Math.Abs(plotCoordinates.X);
			var zFactor = plotCoordinates.Z > 0 ? plotCoordinates.Z - 1 : Math.Abs(plotCoordinates.Z);

			int xOffset = xFactor*PlotWorldGenerator.PlotAreaWidth;
			int zOffset = zFactor*PlotWorldGenerator.PlotAreaDepth;
			xOffset *= Math.Sign(plotCoordinates.X);
			zOffset *= Math.Sign(plotCoordinates.Z);
			/*if (xOffset < 0)*/
			xOffset += PlotWorldGenerator.RoadWidth;
			/*if (zOffset < 0) */
			zOffset += PlotWorldGenerator.RoadWidth;

			return new BlockCoordinates(xOffset, 0, zOffset);
		}
Exemplo n.º 12
0
        public string PlotRemovePlayer(Player player, string username)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (coords == null)
            {
                return("No plot found.");
            }
            if (!_plotManager.HasClaim(coords, player))
            {
                return("You don't own this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("No plot found.");
            }

            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);
            }

            List <UUID> builders = new List <UUID>(plot.AllowedPlayers);

            if (!builders.Contains(plotPlayer.Xuid))
            {
                return("Player does not exist on this plot.");
            }

            builders.Remove(plotPlayer.Xuid);
            plot.AllowedPlayers = builders.ToArray();

            if (!_plotManager.UpdatePlot(plot))
            {
                return("Not able to update this plot.");
            }

            return($"Removed player {username} from plot {plot.Coordinates}");
        }
Exemplo n.º 13
0
        public string PlotVisit(Player player, int x, int z)
        {
            PlotCoordinates coords = new PlotCoordinates(x, z);

            if (x == 0 || z == 0)
            {
                return($"No plot at this location {coords.X},{coords.Z}.");
            }

            var bbox   = PlotManager.GetBoundingBoxForPlot(coords);
            var center = bbox.Max - (bbox.Max - bbox.Min) / 2;
            int height = player.Level.GetHeight(center);

            player.Teleport(new PlayerLocation(center.X, height + 3, center.Z));

            return($"Moved you to plot {coords.X},{coords.Z}.");
        }
Exemplo n.º 14
0
        public BlockCoordinates ConvertToBlockCoordinates(PlotCoordinates plotCoordinates)
        {
            int xOffset = (Math.Abs(plotCoordinates.X) - 1) * PlotWorldGenerator.PlotAreaWidth + PlotWorldGenerator.RoadWidth;
            int zOffset = (Math.Abs(plotCoordinates.Z) - 1) * PlotWorldGenerator.PlotAreaDepth + PlotWorldGenerator.RoadWidth;

            xOffset *= Math.Sign(plotCoordinates.X);
            zOffset *= Math.Sign(plotCoordinates.Z);
            if (xOffset < 0)
            {
                xOffset -= PlotWorldGenerator.PlotWidth;
            }
            if (zOffset < 0)
            {
                zOffset -= PlotWorldGenerator.PlotDepth;
            }

            return(new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight, zOffset));
        }
Exemplo n.º 15
0
        public string PlotClaim(Player player)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (coords == null)
            {
                return("Not able to claim plot at this position.");
            }

            Plot plot;

            if (!_plotManager.TryClaim(coords, player, out plot))
            {
                return("Not able to claim plot at this position.");
            }

            return($"Claimed plot {plot.Coordinates.X},{plot.Coordinates.Z} at {coords}");
        }
Exemplo n.º 16
0
        public bool HasClaim(PlotCoordinates coords, Player player)
        {
            if (player == null)
            {
                return(false);
            }

            Plot plot = null;

            if (_plots.ContainsKey(coords))
            {
                plot = _plots[coords];
            }

            if (plot != null && Equals(plot.Owner, player.ClientUuid))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 17
0
        public string PlotDelete(Player player, bool force = false)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (!force && !_plotManager.HasClaim(coords, player))
            {
                return("Not able to reset plot at this position.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot) && !force)
            {
                return("Not able to delete plot at this position.");
            }
            if (plot != null && !_plotManager.Delete(plot))
            {
                return("Not able to delete plot at this position.");
            }

            PlotWorldGenerator.ResetBlocks(player.Level, PlotManager.GetBoundingBoxForPlot(coords), true);

            return($"Deleted plot {coords.X},{coords.Z}.");
        }
Exemplo n.º 18
0
        public string PlotClear(Player player)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (coords == null)
            {
                return("Not able to reset plot at this position.");
            }

            if (!_plotManager.HasClaim(coords, player))
            {
                return("Not able to reset plot at this position.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("Not able to reset plot at this position.");
            }

            PlotWorldGenerator.ResetBlocks(player.Level, PlotManager.GetBoundingBoxForPlot(plot.Coordinates));

            return($"Reset plot {plot.Coordinates.X},{plot.Coordinates.Z}.");
        }
Exemplo n.º 19
0
        public string PlotSetTitle(Player player, string title = null)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (!_plotManager.HasClaim(coords, player))
            {
                return("You don't own this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("No plot found.");
            }

            plot.Title = title;

            if (!_plotManager.UpdatePlot(plot))
            {
                return("Not able to update this plot.");
            }

            return($"Set title on plot {plot.Coordinates} to {title}");
        }
Exemplo n.º 20
0
        public string PlotSetDescription(Player player, string description = null)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (!_plotManager.HasClaim(coords, player))
            {
                return("You don't own this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("No plot found.");
            }

            plot.Description = description;

            if (!_plotManager.UpdatePlot(plot))
            {
                return("Not able to update this plot.");
            }

            return($"Set description on plot {plot.Coordinates} to {description}");
        }
Exemplo n.º 21
0
        public bool TryGetPlot(PlotCoordinates coords, out Plot plot)
        {
            plot = null;

            if (coords == null)
            {
                return(false);
            }
            if (coords.X == 0 || coords.Z == 0)
            {
                return(false);
            }

            if (!_plots.ContainsKey(coords))
            {
                return(false);
            }

            plot = _plots[coords];

            return(true);
        }
Exemplo n.º 22
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}");
        }
Exemplo n.º 23
0
        public string PlotAuto(Player player)
        {
            BlockCoordinates coords = (BlockCoordinates)player.KnownPosition;

            int x = 0, y = 0, d = 1, m = 1;
            int i = 0;

            while (i++ < 1000)
            {
                while (2 * x * d < m)
                {
                    var current = new PlotCoordinates(x, y);
                    if (_plotManager.TryClaim(current, player, out var plot))
                    {
                        return(ClaimPlot(player, current));
                    }

                    x = x + d;
                }

                while (2 * y * d < m)
                {
                    var current = new PlotCoordinates(x, y);
                    if (_plotManager.TryClaim(current, player, out var plot))
                    {
                        return(ClaimPlot(player, current));
                    }

                    y = y + d;
                }

                d = -1 * d;
                m = m + 1;
            }

            return("Not able to claim plot at this position.");
        }
Exemplo n.º 24
0
        public string PlotSetHome(Player player)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

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

            PlotPlayer plotPlayer = _plotManager.GetOrAddPlotPlayer(player);

            plotPlayer.Home = player.KnownPosition;
            _plotManager.UpdatePlotPlayer(plotPlayer);

            return($"Set home to plot {plot.Coordinates.X},{plot.Coordinates.Z}");
        }
Exemplo n.º 25
0
        public string PlotSetDownfall(Player player, int downfall = 0)
        {
            PlotCoordinates coords = (PlotCoordinates)player.KnownPosition;

            if (!_plotManager.HasClaim(coords, player))
            {
                return("You don't own this plot.");
            }
            if (!_plotManager.TryGetPlot(coords, out Plot plot))
            {
                return("No plot found.");
            }

            plot.Downfall = downfall;

            if (!_plotManager.UpdatePlot(plot))
            {
                return("Not able to update this plot.");
            }

            player.SendSetDownfall(plot.Downfall);

            return($"Set downfall on plot {plot.Coordinates} to {downfall}");
        }
Exemplo n.º 26
0
 protected bool Equals(PlotCoordinates other)
 {
     return(X == other.X && Z == other.Z);
 }
Exemplo n.º 27
0
        public bool TryClaim(PlotCoordinates coords, Player player, out Plot plot)
        {
            plot = null;

            GetOrAddPlotPlayer(player);

            if (coords.X == 0 || coords.Z == 0)
            {
                return(false);
            }

            if (_plots.ContainsKey(coords))
            {
                plot = _plots[coords];
            }

            if (plot != null)
            {
                return(false);
            }

            plot = new Plot
            {
                Coordinates = coords,
                Owner       = player.ClientUuid,
            };

            if (!_plots.TryAdd(coords, plot))
            {
                return(false);
            }

            SaveConfig();

            var offset = ConvertToBlockCoordinates(coords);

            //int xOffset = offset.X;
            //int zOffset = offset.Z;
            //player.Level.SetBlock(new GoldBlock {Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset)});
            //player.Level.SetBlock(new EmeraldBlock
            //{
            //	Coordinates = new BlockCoordinates(xOffset, PlotWorldGenerator.PlotHeight + 2, zOffset) + new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 1, PlotWorldGenerator.PlotDepth - 1)
            //});


            Vector3     to   = (Vector3)offset + (Vector3) new BlockCoordinates(PlotWorldGenerator.PlotWidth - 1, 256, PlotWorldGenerator.PlotDepth - 1);
            BoundingBox bbox = new BoundingBox(offset, to).GetAdjustedBoundingBox();

            for (int x = (int)bbox.Min.X; x <= (int)bbox.Max.X; x++)
            {
                for (int z = (int)bbox.Min.Z; z <= (int)bbox.Max.Z; z++)
                {
                    if (player.Level.IsTransparent(new BlockCoordinates(x, PlotWorldGenerator.PlotHeight, z)))
                    {
                        player.Level.SetAir(x, PlotWorldGenerator.PlotHeight, z);
                    }
                }
            }

            return(true);
        }