static void Player_PlacingBlock(object sender, Events.PlayerPlacingBlockEventArgs e)
{
try {
if (e.Player.World.Map.Portals != null && e.Player.World.Map.Portals.Count > 0 && e.Context != BlockChangeContext.Portal)
{
lock (e.Player.World.Map.Portals.SyncRoot) {
foreach (Portal portal in e.Player.World.Map.Portals)
{
if (portal.IsInRange(e.Coords))
{
e.Result = CanPlaceResult.Revert;
e.Player.Message("You can not place a block inside portal: " + portal.Name);
return;
}
}
}
}
if (e.NewBlock == Block.Red)
{
if (e.Context == BlockChangeContext.Manual)
{
if (e.Player.PortalCache.Name != null)
{
if (e.Player.PortalCache.AffectedBlocks != null)
{
if (e.Player.PortalCache.AffectedBlocks.Contains(e.Coords)) //stop output being inside the unfinished portal
{
e.Result = CanPlaceResult.Revert;
e.Player.Message("You can not place a block inside a portal");
return;
}
e.Player.PortalCache.DesiredOutputX = e.Coords.ToPlayerCoords().X;
e.Player.PortalCache.DesiredOutputY = e.Coords.ToPlayerCoords().Y;
e.Player.PortalCache.DesiredOutputZ = (e.Coords.Z + 2) * 32;
e.Player.PortalCache.DesiredOutputR = e.Player.Position.R;
e.Player.PortalCache.DesiredOutputL = e.Player.Position.L;
e.Player.PortalCache.Name = Portal.GenerateName(e.Player.PortalCache.World, true);
string oldWorld = e.Player.PortalCache.World;
e.Player.PortalCache.World = e.Player.World.Name;
PortalHandler.CreatePortal(e.Player.PortalCache, WorldManager.FindWorldExact(oldWorld), true);
e.Player.Message(" Portal finalized: Exit point at {0} on world {1}", e.Coords.ToString(), e.Player.World.ClassyName);
e.Player.PortalCache = new Portal();
e.Result = CanPlaceResult.Revert;
}
}
}
}
} catch (Exception ex) {
Logger.Log(LogType.Error, "PortalHandler.Player_PlacedBlock: " + ex);
}
}