Add hooks for Region creation/deletion. Add hooks for Region Enter/Leave. Add member to TSPlayer displaying current region. Set private setters in AccountHooks.
This commit is contained in:
parent
803aa643c2
commit
406abce30c
6 changed files with 156 additions and 4 deletions
|
|
@ -115,6 +115,18 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a region to the database.
|
||||
/// </summary>
|
||||
/// <param name="tx">TileX of the top left corner.</param>
|
||||
/// <param name="ty">TileY of the top left corner.</param>
|
||||
/// <param name="width">Width of the region in tiles.</param>
|
||||
/// <param name="height">Height of the region in tiles.</param>
|
||||
/// <param name="regionname">The name of the region.</param>
|
||||
/// <param name="owner">The User Account Name of the person who created this region.</param>
|
||||
/// <param name="worldid">The world id that this region is in.</param>
|
||||
/// <param name="z">The Z index of the region.</param>
|
||||
/// <returns>Whether the region was created and added successfully.</returns>
|
||||
public bool AddRegion(int tx, int ty, int width, int height, string regionname, string owner, string worldid, int z = 0)
|
||||
{
|
||||
if (GetRegionByName(regionname) != null)
|
||||
|
|
@ -126,7 +138,9 @@ namespace TShockAPI.DB
|
|||
database.Query(
|
||||
"INSERT INTO Regions (X1, Y1, width, height, RegionName, WorldID, UserIds, Protected, Groups, Owner, Z) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);",
|
||||
tx, ty, width, height, regionname, worldid, "", 1, "", owner, z);
|
||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z));
|
||||
var region = new Region(new Rectangle(tx, ty, width, height), regionname, owner, true, worldid, z);
|
||||
Regions.Add(region);
|
||||
Hooks.RegionHooks.OnRegionCreated(region);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -136,13 +150,20 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the region from this world with a given name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the region to delete.</param>
|
||||
/// <returns>Whether the region was successfully deleted.</returns>
|
||||
public bool DeleteRegion(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
database.Query("DELETE FROM Regions WHERE RegionName=@0 AND WorldID=@1", name, Main.worldID.ToString());
|
||||
var worldid = Main.worldID.ToString();
|
||||
var region = Regions.FirstOrDefault(r => r.Name == name && r.WorldID == worldid);
|
||||
Regions.RemoveAll(r => r.Name == name && r.WorldID == worldid);
|
||||
Hooks.RegionHooks.OnRegionDeleted(region);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue