Merge pull request #494 from Scavenger3/tile

Check for invalid place style.
This commit is contained in:
Lucas Nicodemus 2013-07-11 09:42:09 -07:00
commit 033ffc67a9
2 changed files with 22 additions and 4 deletions

View file

@ -251,6 +251,8 @@ namespace TShockAPI
[Description("The path of the directory where logs should be written into.")] public string LogPath = "tshock"; [Description("The path of the directory where logs should be written into.")] public string LogPath = "tshock";
[Description("Prevents players from placing tiles with an invalid style.")] public bool PreventInvalidPlaceStyle = true;
/// <summary> /// <summary>
/// Reads a configuration file from a given path /// Reads a configuration file from a given path
/// </summary> /// </summary>

View file

@ -88,13 +88,18 @@ namespace TShockAPI
/// Did the tile get destroyed successfully. /// Did the tile get destroyed successfully.
/// </summary> /// </summary>
public bool Fail { get; set; } public bool Fail { get; set; }
/// <summary>
/// Used when a tile is placed to denote a subtype of tile. (e.g. for tile id 21: Chest = 0, Gold Chest = 1)
/// </summary>
public byte Style { get; set; }
} }
/// <summary> /// <summary>
/// TileEdit - called when a tile is placed or destroyed /// TileEdit - called when a tile is placed or destroyed
/// </summary> /// </summary>
public static HandlerList<TileEditEventArgs> TileEdit; public static HandlerList<TileEditEventArgs> TileEdit;
private static bool OnTileEdit(TSPlayer ply, int x, int y, byte type, byte editType, bool fail) private static bool OnTileEdit(TSPlayer ply, int x, int y, byte type, byte editType, bool fail, byte style)
{ {
if (TileEdit == null) if (TileEdit == null)
return false; return false;
@ -106,7 +111,8 @@ namespace TShockAPI
Y = y, Y = y,
Type = type, Type = type,
EditType = editType, EditType = editType,
Fail = fail Fail = fail,
Style = style
}; };
TileEdit.Invoke(null, args); TileEdit.Invoke(null, args);
return args.Handled; return args.Handled;
@ -1678,8 +1684,9 @@ namespace TShockAPI
var tileX = args.Data.ReadInt32(); var tileX = args.Data.ReadInt32();
var tileY = args.Data.ReadInt32(); var tileY = args.Data.ReadInt32();
var tiletype = args.Data.ReadInt8(); var tiletype = args.Data.ReadInt8();
var fail = args.Data.ReadBoolean(); var fail = tiletype == 1;
if (OnTileEdit(args.Player, tileX, tileY, tiletype, type, fail)) var style = args.Data.ReadInt8();
if (OnTileEdit(args.Player, tileX, tileY, tiletype, type, fail, style))
return true; return true;
if (!TShock.Utils.TileValid(tileX, tileY)) if (!TShock.Utils.TileValid(tileX, tileY))
return false; return false;
@ -1843,6 +1850,15 @@ namespace TShockAPI
args.Player.SendTileSquare(tileX, tileY); args.Player.SendTileSquare(tileX, tileY);
return true; return true;
} }
if (type == 1 && TShock.Config.PreventInvalidPlaceStyle && ((tiletype == 4 && style > 8) ||
(tiletype == 13 && style > 4) || (tiletype == 15 && style > 1) || (tiletype == 21 && style > 6) ||
(tiletype == 82 && style > 5) || (tiletype == 91 && style > 3) || (tiletype == 105 && style > 42) ||
(tiletype == 135 && style > 3) || (tiletype == 139 && style > 12) || (tiletype == 144 && style > 2) ||
(tiletype == 149 && style > 2)))
{
args.Player.SendTileSquare(tileX, tileY);
return true;
}
} }
if (TShock.CheckIgnores(args.Player)) if (TShock.CheckIgnores(args.Player))