Changed how EditTile was handled so that we have enums and pass those instead of confusing bytes.
Comments should be updated to reflect new stuff.
This commit is contained in:
parent
203611706e
commit
7ea9be6e75
2 changed files with 60 additions and 37 deletions
|
|
@ -78,17 +78,17 @@ namespace TShockAPI
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Tile ID being edited.
|
/// The Tile ID being edited.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte Type { get; set; }
|
public byte EditData { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The EditType.
|
/// The EditType.
|
||||||
/// (KillTile = 0, PlaceTile = 1, KillWall = 2, PlaceWall = 3, KillTileNoItem = 4, PlaceWire = 5, KillWire = 6)
|
/// (KillTile = 0, PlaceTile = 1, KillWall = 2, PlaceWall = 3, KillTileNoItem = 4, PlaceWire = 5, KillWire = 6)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte EditType { get; set; }
|
public EditAction Action { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Did the tile get destroyed successfully.
|
/// Did the tile get destroyed successfully.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Fail { get; set; }
|
public EditType editDetail { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used when a tile is placed to denote a subtype of tile. (e.g. for tile id 21: Chest = 0, Gold Chest = 1)
|
/// Used when a tile is placed to denote a subtype of tile. (e.g. for tile id 21: Chest = 0, Gold Chest = 1)
|
||||||
|
|
@ -100,7 +100,7 @@ namespace TShockAPI
|
||||||
/// 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, byte style)
|
private static bool OnTileEdit(TSPlayer ply, int x, int y, EditAction action, EditType editDetail, byte editData, byte style)
|
||||||
{
|
{
|
||||||
if (TileEdit == null)
|
if (TileEdit == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -110,9 +110,9 @@ namespace TShockAPI
|
||||||
Player = ply,
|
Player = ply,
|
||||||
X = x,
|
X = x,
|
||||||
Y = y,
|
Y = y,
|
||||||
Type = type,
|
Action = action,
|
||||||
EditType = editType,
|
EditData = editData,
|
||||||
Fail = fail,
|
editDetail = editDetail,
|
||||||
Style = style
|
Style = style
|
||||||
};
|
};
|
||||||
TileEdit.Invoke(null, args);
|
TileEdit.Invoke(null, args);
|
||||||
|
|
@ -1679,16 +1679,39 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum EditAction
|
||||||
|
{
|
||||||
|
KillTile = 0,
|
||||||
|
PlaceTile,
|
||||||
|
KillWall,
|
||||||
|
PlaceWall,
|
||||||
|
KillTileNoItem,
|
||||||
|
PlaceWire,
|
||||||
|
KillWire,
|
||||||
|
PoundTile
|
||||||
|
}
|
||||||
|
public enum EditType
|
||||||
|
{
|
||||||
|
Fail = 0,
|
||||||
|
Type,
|
||||||
|
Slope,
|
||||||
|
}
|
||||||
private static bool HandleTile(GetDataHandlerArgs args)
|
private static bool HandleTile(GetDataHandlerArgs args)
|
||||||
{
|
{
|
||||||
var type = args.Data.ReadInt8();
|
EditAction action = (EditAction)args.Data.ReadInt8();
|
||||||
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 editData = args.Data.ReadInt8();
|
||||||
var fail = tiletype == 1;
|
EditType type = (action == EditAction.KillTile || action == EditAction.KillWall ||
|
||||||
|
action == EditAction.KillTileNoItem)
|
||||||
|
? EditType.Fail
|
||||||
|
: (action == EditAction.PlaceTile || action == EditAction.PlaceWall)
|
||||||
|
? EditType.Type
|
||||||
|
: EditType.Slope;
|
||||||
|
|
||||||
var style = args.Data.ReadInt8();
|
var style = args.Data.ReadInt8();
|
||||||
|
|
||||||
if (OnTileEdit(args.Player, tileX, tileY, tiletype, type, fail, style))
|
if (OnTileEdit(args.Player, tileX, tileY, action, type, editData, style))
|
||||||
return true;
|
return true;
|
||||||
if (!TShock.Utils.TilePlacementValid(tileX, tileY))
|
if (!TShock.Utils.TilePlacementValid(tileX, tileY))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1791,7 +1814,7 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == 2)
|
else if (action == EditAction.KillWall)
|
||||||
{
|
{
|
||||||
// If they aren't selecting an hammer, they're hacking.
|
// If they aren't selecting an hammer, they're hacking.
|
||||||
if (selectedItem.hammer == 0)
|
if (selectedItem.hammer == 0)
|
||||||
|
|
@ -1800,35 +1823,35 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == 1 || type == 3)
|
else if (action == EditAction.PlaceTile || action == EditAction.PlaceWall)
|
||||||
{
|
{
|
||||||
if (type == 1 && TShock.Config.PreventInvalidPlaceStyle && ((tiletype == 4 && style > 8) ||
|
if (action == EditAction.PlaceTile && TShock.Config.PreventInvalidPlaceStyle && ((editData == 4 && style > 8) ||
|
||||||
(tiletype == 13 && style > 4) || (tiletype == 15 && style > 1) || (tiletype == 21 && style > 6) ||
|
(editData == 13 && style > 4) || (editData == 15 && style > 1) || (editData == 21 && style > 6) ||
|
||||||
(tiletype == 82 && style > 5) || (tiletype == 91 && style > 3) || (tiletype == 105 && style > 42) ||
|
(editData == 82 && style > 5) || (editData == 91 && style > 3) || (editData == 105 && style > 42) ||
|
||||||
(tiletype == 135 && style > 3) || (tiletype == 139 && style > 12) || (tiletype == 144 && style > 2) ||
|
(editData == 135 && style > 3) || (editData == 139 && style > 12) || (editData == 144 && style > 2) ||
|
||||||
(tiletype == 149 && style > 2)))
|
(editData == 149 && style > 2)))
|
||||||
{
|
{
|
||||||
args.Player.SendTileSquare(tileX, tileY);
|
args.Player.SendTileSquare(tileX, tileY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// If they aren't selecting the item which creates the tile or wall, they're hacking.
|
// If they aren't selecting the item which creates the tile or wall, they're hacking.
|
||||||
if (tiletype != 127 && tiletype != (type == 1 ? selectedItem.createTile : selectedItem.createWall))
|
if (editData != 127 && editData != (action == EditAction.PlaceTile ? selectedItem.createTile : selectedItem.createWall))
|
||||||
{
|
{
|
||||||
args.Player.SendTileSquare(tileX, tileY);
|
args.Player.SendTileSquare(tileX, tileY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (TShock.Itembans.ItemIsBanned(selectedItem.name, args.Player) || tiletype >= (type == 1 ? Main.maxTileSets : Main.maxWallTypes))
|
if (TShock.Itembans.ItemIsBanned(selectedItem.name, args.Player) || editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes))
|
||||||
{
|
{
|
||||||
args.Player.SendTileSquare(tileX, tileY);
|
args.Player.SendTileSquare(tileX, tileY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (type == 1 && (tiletype == 29 || tiletype == 97) && TShock.Config.ServerSideInventory && TShock.Config.DisablePiggybanksOnSSI)
|
if (action == EditAction.PlaceTile && (editData == 29 || editData == 97) && TShock.Config.ServerSideInventory && TShock.Config.DisablePiggybanksOnSSI)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("You cannot place this tile because server side inventory is enabled.", Color.Red);
|
args.Player.SendMessage("You cannot place this tile because server side inventory is enabled.", Color.Red);
|
||||||
args.Player.SendTileSquare(tileX, tileY);
|
args.Player.SendTileSquare(tileX, tileY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (type == 1 && tiletype == 21)
|
if (action == EditAction.PlaceTile && editData == 21)
|
||||||
{
|
{
|
||||||
if (TShock.Utils.MaxChests())
|
if (TShock.Utils.MaxChests())
|
||||||
{
|
{
|
||||||
|
|
@ -1844,7 +1867,7 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == 5)
|
else if (action == EditAction.PlaceWire)
|
||||||
{
|
{
|
||||||
// If they aren't selecting the wrench, they're hacking.
|
// If they aren't selecting the wrench, they're hacking.
|
||||||
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 509)
|
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 509)
|
||||||
|
|
@ -1853,7 +1876,7 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type == 6)
|
else if (action == EditAction.KillWire)
|
||||||
{
|
{
|
||||||
// If they aren't selecting the wire cutter, they're hacking.
|
// If they aren't selecting the wire cutter, they're hacking.
|
||||||
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 510)
|
if (args.TPlayer.inventory[args.TPlayer.selectedItem].type != 510)
|
||||||
|
|
@ -1869,13 +1892,13 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TShock.CheckTilePermission(args.Player, tileX, tileY, tiletype, type))
|
if (TShock.CheckTilePermission(args.Player, tileX, tileY, editData, action))
|
||||||
{
|
{
|
||||||
args.Player.SendTileSquare(tileX, tileY);
|
args.Player.SendTileSquare(tileX, tileY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tiletype == 127 || Main.tileCut[tiletype]) && (type == 0 || type == 4))
|
if ((editData == 127 || Main.tileCut[editData]) && (action ==EditAction.KillTile || action == EditAction.KillTileNoItem))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1906,7 +1929,7 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( type == 1 || type == 3 ) && !args.Player.Group.HasPermission(Permissions.ignoreplacetiledetection))
|
if ( ( action == EditAction.PlaceTile || action == EditAction.PlaceWall ) && !args.Player.Group.HasPermission(Permissions.ignoreplacetiledetection))
|
||||||
{
|
{
|
||||||
args.Player.TilePlaceThreshold++;
|
args.Player.TilePlaceThreshold++;
|
||||||
var coords = new Vector2(tileX, tileY);
|
var coords = new Vector2(tileX, tileY);
|
||||||
|
|
@ -1914,7 +1937,7 @@ namespace TShockAPI
|
||||||
args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]);
|
args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == 0 || type == 4 || type == 2) && Main.tileSolid[Main.tile[tileX, tileY].type] &&
|
if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.KillWall) && Main.tileSolid[Main.tile[tileX, tileY].type] &&
|
||||||
!args.Player.Group.HasPermission(Permissions.ignorekilltiledetection))
|
!args.Player.Group.HasPermission(Permissions.ignorekilltiledetection))
|
||||||
{
|
{
|
||||||
args.Player.TileKillThreshold++;
|
args.Player.TileKillThreshold++;
|
||||||
|
|
|
||||||
|
|
@ -1368,11 +1368,11 @@ namespace TShockAPI
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckTilePermission( TSPlayer player, int tileX, int tileY, byte tileType, byte actionType )
|
public static bool CheckTilePermission( TSPlayer player, int tileX, int tileY, byte tileType, GetDataHandlers.EditAction actionType )
|
||||||
{
|
{
|
||||||
if (!player.Group.HasPermission(Permissions.canbuild))
|
if (!player.Group.HasPermission(Permissions.canbuild))
|
||||||
{
|
{
|
||||||
if (TShock.Config.AllowIce && actionType != 1)
|
if (TShock.Config.AllowIce && actionType != GetDataHandlers.EditAction.PlaceTile)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (Point p in player.IceTiles)
|
foreach (Point p in player.IceTiles)
|
||||||
|
|
@ -1392,7 +1392,7 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TShock.Config.AllowIce && actionType == 1 && tileType == 127)
|
if (TShock.Config.AllowIce && actionType == GetDataHandlers.EditAction.PlaceTile && tileType == 127)
|
||||||
{
|
{
|
||||||
player.IceTiles.Add(new Point(tileX, tileY));
|
player.IceTiles.Add(new Point(tileX, tileY));
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1423,12 +1423,12 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (!player.Group.HasPermission(Permissions.editspawn))
|
if (!player.Group.HasPermission(Permissions.editspawn))
|
||||||
{
|
{
|
||||||
if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000){
|
if (((DateTime.Now.Ticks/TimeSpan.TicksPerMillisecond) - player.WPm) > 2000)
|
||||||
player.SendMessage("The world is protected from changes.", Color.Red);
|
{
|
||||||
player.WPm=DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
|
player.SendMessage("The world is protected from changes.", Color.Red);
|
||||||
|
player.WPm = DateTime.Now.Ticks/TimeSpan.TicksPerMillisecond;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Config.SpawnProtection)
|
if (Config.SpawnProtection)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue