Skip to content

Commit

Permalink
Undid new mojang code, reverted back to release's version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonty800 committed Jul 24, 2013
1 parent 526d5d0 commit 113c161
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 363 deletions.
34 changes: 19 additions & 15 deletions fCraft/Commands/BuildingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,24 @@ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
static void Door ( Player player, Command cmd ) {
string option = cmd.Next();
if ( option == null ) {
int MaxNumberOfDoorsPerPlayer = 5;
if ( DoorHandler.GetPlayerOwnedDoorsNumber( player.World, player ) >= MaxNumberOfDoorsPerPlayer ) {
player.Message( "You cannot place any more doors, a player can have a maximum of {0} doors per world",
MaxNumberOfDoorsPerPlayer );
return;
}
Door door = new Door();
player.SelectionStart( 2, DoorAdd, door, CdDoor.Permissions );
player.Message( "Door: Place a block or type /mark to use your location." );
player.Message( "Door: Place a block or type /Mark to use your location." );
return;
} else if ( option.ToLower().Equals( "remove" ) || option.ToLower().Equals( "rd" ) ) {
string doorName = cmd.Next();

if ( doorName == null ) {
player.Message( "No door name specified." );
} else {
if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
bool found = false;
Door doorFound = null;

lock ( player.World.Map.Doors.SyncRoot ) {
foreach ( Door door in player.World.Map.Doors ) {
if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
Expand All @@ -185,7 +189,6 @@ static void Door ( Player player, Command cmd ) {
break;
}
}

if ( !found ) {
player.Message( "Could not find door by name {0}.", doorName );
} else {
Expand All @@ -199,13 +202,11 @@ static void Door ( Player player, Command cmd ) {
}
} else if ( option.ToLower().Equals( "info" ) ) {
string doorName = cmd.Next();

if ( doorName == null ) {
player.Message( "No door name specified." );
} else {
if ( player.World.Map.Doors != null && player.World.Map.Doors.Count > 0 ) {
bool found = false;

lock ( player.World.Map.Doors.SyncRoot ) {
foreach ( Door door in player.World.Map.Doors ) {
if ( door.Name.ToLower().Equals( doorName.ToLower() ) ) {
Expand All @@ -216,7 +217,6 @@ static void Door ( Player player, Command cmd ) {
}
}
}

if ( !found ) {
player.Message( "Could not find door by name {0}.", doorName );
}
Expand Down Expand Up @@ -245,7 +245,6 @@ static void Door ( Player player, Command cmd ) {
}
}


static void DoorTestCallback ( Player player, Vector3I[] marks, object tag ) {
Vector3I Pos = marks[0]; Door door = fCraft.Doors.DoorHandler.GetDoor( Pos, player );
if ( door == null ) {
Expand All @@ -260,10 +259,10 @@ static void DoorAdd ( Player player, Vector3I[] marks, object tag ) {
int ex = Math.Max( marks[0].X, marks[1].X );
int sy = Math.Min( marks[0].Y, marks[1].Y );
int ey = Math.Max( marks[0].Y, marks[1].Y );
int sh = Math.Min( marks[0].Z, marks[1].Z );
int eh = Math.Max( marks[0].Z, marks[1].Z );
int sz = Math.Min( marks[0].Z, marks[1].Z );
int ez = Math.Max( marks[0].Z, marks[1].Z );

int volume = ( ex - sx + 1 ) * ( ey - sy + 1 ) * ( eh - sh + 1 );
int volume = ( ex - sx + 1 ) * ( ey - sy + 1 ) * ( ez - sz + 1 );
if ( volume > 30 ) {
player.Message( "Doors are only allowed to be {0} blocks", 30 );
return;
Expand All @@ -285,7 +284,7 @@ static void DoorAdd ( Player player, Vector3I[] marks, object tag ) {
List<Vector3I> blocks = new List<Vector3I>();
for ( int x = sx; x < ex; x++ ) {
for ( int y = sy; y < ey; y++ ) {
for ( int z = sh; z < eh; z++ ) {
for ( int z = sz; z < ez; z++ ) {
if ( player.CanPlace( player.World.Map, new Vector3I( x, y, z ), Block.Wood, BlockChangeContext.Manual ) != CanPlaceResult.Allowed ) {
player.Message( "Cannot add a door to world {0}&S: Build permissions in this area replied with 'denied'.",
player.World.ClassyName );
Expand All @@ -295,13 +294,18 @@ static void DoorAdd ( Player player, Vector3I[] marks, object tag ) {
}
}
}

Door door = new Door( player.World.Name,
blocks.ToArray(),
fCraft.Doors.Door.GenerateName( player.World ),
player.ClassyName );
door.Range = new DoorRange( sx, ex, sy, ey, sh, eh );

door.Range = new DoorRange( sx, ex, sy, ey, sz, ez );
foreach ( Vector3I v in DoorHandler.GetInstance().GetAffectedBlocks( door ) ) {
if ( DoorHandler.GetInstance().GetDoor( player.World, v) != null ) {
player.Message( "You can not build a door inside a door, U MAD BRO?" );
player.World.Map.DoorID--;
return;
}
}
DoorHandler.CreateDoor( door, player.World );
Logger.Log( LogType.UserActivity, "{0} created door {1} (on world {2})", player.Name, door.Name, player.World.Name );
player.Message( "Door created on world {0}&S with name {1}", player.World.ClassyName, door.Name );
Expand Down
2 changes: 1 addition & 1 deletion fCraft/Commands/WorldCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static void Init () {
CommandManager.RegisterCommand( CdPhysics );
CommandManager.RegisterCommand( CdWorldSet );
CommandManager.RegisterCommand( CdMessageBlock );
CommandManager.RegisterCommand( CdFeed );
//CommandManager.RegisterCommand( CdFeed );
Player.JoinedWorld += FeedSettings.PlayerJoiningWorld;
Player.PlacingBlock += FeedSettings.PlayerPlacingBlock;
}
Expand Down
1 change: 1 addition & 0 deletions fCraft/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public static bool DoesNameExist ( World world, String name ) {

return false;
}


public void Remove ( Player requester ) {
NormalBrush brush = new NormalBrush( Block.Air, Block.Air );
Expand Down
36 changes: 28 additions & 8 deletions fCraft/Doors/DoorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public static void PlayerPlacedDoor ( object sender, Events.PlayerPlacingBlockEv
if ( e.Map.Doors == null ) return;
if ( e.Map.World != null ) {
if ( e.Map != null ) {
if ( e.Context != BlockChangeContext.Manual ) {
if ( e.Map.Doors.Count > 0 ) {
lock ( e.Map.Doors.SyncRoot ) {
foreach ( Door door in e.Map.Doors ) {
if ( e.Map == null ) break;
if ( door.IsInRange( e.Coords ) ) {
e.Result = CanPlaceResult.Revert;
}
if ( e.Map.Doors.Count > 0 ) {
lock ( e.Map.Doors.SyncRoot ) {
foreach ( Door door in e.Map.Doors ) {
if ( e.Map == null ) break;
if ( door.IsInRange( e.Coords ) ) {
e.Result = CanPlaceResult.Revert;
}
}
}
Expand Down Expand Up @@ -107,6 +105,28 @@ public static Door GetDoor ( Vector3I Coords, Player player ) {
return Door;
}

public Vector3I[] GetAffectedBlocks ( Door door ) {
Vector3I[] temp = new Vector3I[] { };
List<Vector3I> temp2 = new List<Vector3I>();
for(int x = door.Range.Xmin; x < door.Range.Xmax; x++)
for ( int y = door.Range.Ymin; y < door.Range.Ymax; y++ )
for ( int z = door.Range.Zmin; z < door.Range.Zmax; z++ ) {
temp2.Add( new Vector3I( x, y, z ) );
}
temp = temp2.ToArray();
return temp;
}

public static int GetPlayerOwnedDoorsNumber ( World world, Player player ) {
int Number = 0;
foreach ( Door door in world.Map.Doors ) {
if ( door.Creator == player.Name ) {
Number++;
}
}
return Number;
}

public Door GetDoor ( World world, Vector3I block ) {
Door Door = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion fCraft/Network/Heartbeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void Send800CraftNetBeat()
{
Logger.LogToConsole("" + ex);
}*/
} catch ( Exception e ) {
} catch ( Exception ) {
//do nothing, server is probably down and host doesnt care
}
}
Expand Down
Loading

0 comments on commit 113c161

Please sign in to comment.