Remove crappy spaces in this file.
This commit is contained in:
parent
1c7fe908b6
commit
1421c23df7
1 changed files with 99 additions and 99 deletions
|
|
@ -39,22 +39,22 @@ namespace TShockAPI.DB
|
||||||
database = db;
|
database = db;
|
||||||
var table = new SqlTable("Regions",
|
var table = new SqlTable("Regions",
|
||||||
new SqlColumn("Id", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
|
new SqlColumn("Id", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
|
||||||
new SqlColumn("X1", MySqlDbType.Int32),
|
new SqlColumn("X1", MySqlDbType.Int32),
|
||||||
new SqlColumn("Y1", MySqlDbType.Int32),
|
new SqlColumn("Y1", MySqlDbType.Int32),
|
||||||
new SqlColumn("width", MySqlDbType.Int32),
|
new SqlColumn("width", MySqlDbType.Int32),
|
||||||
new SqlColumn("height", MySqlDbType.Int32),
|
new SqlColumn("height", MySqlDbType.Int32),
|
||||||
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Unique = true},
|
new SqlColumn("RegionName", MySqlDbType.VarChar, 50) {Unique = true},
|
||||||
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
|
new SqlColumn("WorldID", MySqlDbType.Text) {Unique = true},
|
||||||
new SqlColumn("UserIds", MySqlDbType.Text),
|
new SqlColumn("UserIds", MySqlDbType.Text),
|
||||||
new SqlColumn("Protected", MySqlDbType.Int32),
|
new SqlColumn("Protected", MySqlDbType.Int32),
|
||||||
new SqlColumn("Groups", MySqlDbType.Text),
|
new SqlColumn("Groups", MySqlDbType.Text),
|
||||||
new SqlColumn("Owner", MySqlDbType.VarChar, 50),
|
new SqlColumn("Owner", MySqlDbType.VarChar, 50),
|
||||||
new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" }
|
new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" }
|
||||||
);
|
);
|
||||||
var creator = new SqlTableCreator(db,
|
var creator = new SqlTableCreator(db,
|
||||||
db.GetSqlType() == SqlType.Sqlite
|
db.GetSqlType() == SqlType.Sqlite
|
||||||
? (IQueryBuilder) new SqliteQueryCreator()
|
? (IQueryBuilder) new SqliteQueryCreator()
|
||||||
: new MysqlQueryCreator());
|
: new MysqlQueryCreator());
|
||||||
creator.EnsureExists(table);
|
creator.EnsureExists(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ namespace TShockAPI.DB
|
||||||
string name = reader.Get<string>("RegionName");
|
string name = reader.Get<string>("RegionName");
|
||||||
string owner = reader.Get<string>("Owner");
|
string owner = reader.Get<string>("Owner");
|
||||||
string groups = reader.Get<string>("Groups");
|
string groups = reader.Get<string>("Groups");
|
||||||
int z = reader.Get<int>("Z");
|
int z = reader.Get<int>("Z");
|
||||||
|
|
||||||
string[] splitids = mergedids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
string[] splitids = mergedids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ namespace TShockAPI.DB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
database.Query("UPDATE Regions SET Protected=@0 WHERE RegionName=@1 AND WorldID=@2", state ? 1 : 0, name,
|
database.Query("UPDATE Regions SET Protected=@0 WHERE RegionName=@1 AND WorldID=@2", state ? 1 : 0, name,
|
||||||
Main.worldID.ToString());
|
Main.worldID.ToString());
|
||||||
var region = GetRegionByName(name);
|
var region = GetRegionByName(name);
|
||||||
if (region != null)
|
if (region != null)
|
||||||
region.DisableBuild = state;
|
region.DisableBuild = state;
|
||||||
|
|
@ -193,26 +193,26 @@ namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Region top = null;
|
Region top = null;
|
||||||
|
|
||||||
foreach (Region region in Regions.ToList())
|
foreach (Region region in Regions.ToList())
|
||||||
{
|
{
|
||||||
if (region.InArea(x, y))
|
if (region.InArea(x, y))
|
||||||
{
|
{
|
||||||
if (top == null || region.Z > top.Z)
|
if (top == null || region.Z > top.Z)
|
||||||
top = region;
|
top = region;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return top == null || top.HasPermissionToBuildInRegion(ply);
|
return top == null || top.HasPermissionToBuildInRegion(ply);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InArea(int x, int y)
|
public bool InArea(int x, int y)
|
||||||
{
|
{
|
||||||
foreach (Region region in Regions.ToList())
|
foreach (Region region in Regions.ToList())
|
||||||
{
|
{
|
||||||
if (x >= region.Area.Left && x <= region.Area.Right &&
|
if (x >= region.Area.Left && x <= region.Area.Right &&
|
||||||
y >= region.Area.Top && y <= region.Area.Bottom &&
|
y >= region.Area.Top && y <= region.Area.Bottom &&
|
||||||
region.DisableBuild)
|
region.DisableBuild)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -220,35 +220,35 @@ namespace TShockAPI.DB
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> InAreaRegionName(int x, int y)
|
public List<string> InAreaRegionName(int x, int y)
|
||||||
{
|
{
|
||||||
List<string> regions = new List<string>() { };
|
List<string> regions = new List<string>() { };
|
||||||
foreach (Region region in Regions.ToList())
|
foreach (Region region in Regions.ToList())
|
||||||
{
|
{
|
||||||
if (x >= region.Area.Left && x <= region.Area.Right &&
|
if (x >= region.Area.Left && x <= region.Area.Right &&
|
||||||
y >= region.Area.Top && y <= region.Area.Bottom &&
|
y >= region.Area.Top && y <= region.Area.Bottom &&
|
||||||
region.DisableBuild)
|
region.DisableBuild)
|
||||||
{
|
{
|
||||||
regions.Add(region.Name);
|
regions.Add(region.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Region> InAreaRegion(int x, int y)
|
public List<Region> InAreaRegion(int x, int y)
|
||||||
{
|
{
|
||||||
List<Region> regions = new List<Region>() { };
|
List<Region> regions = new List<Region>() { };
|
||||||
foreach (Region region in Regions.ToList())
|
foreach (Region region in Regions.ToList())
|
||||||
{
|
{
|
||||||
if (x >= region.Area.Left && x <= region.Area.Right &&
|
if (x >= region.Area.Left && x <= region.Area.Right &&
|
||||||
y >= region.Area.Top && y <= region.Area.Bottom &&
|
y >= region.Area.Top && y <= region.Area.Bottom &&
|
||||||
region.DisableBuild)
|
region.DisableBuild)
|
||||||
{
|
{
|
||||||
regions.Add(region);
|
regions.Add(region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return regions;
|
return regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> ListIDs(string MergedIDs)
|
public static List<string> ListIDs(string MergedIDs)
|
||||||
{
|
{
|
||||||
|
|
@ -269,7 +269,7 @@ namespace TShockAPI.DB
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = database.QueryReader("SELECT X1, Y1, height, width FROM Regions WHERE RegionName=@0 AND WorldID=@1",
|
using (var reader = database.QueryReader("SELECT X1, Y1, height, width FROM Regions WHERE RegionName=@0 AND WorldID=@1",
|
||||||
regionName, Main.worldID.ToString()))
|
regionName, Main.worldID.ToString()))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
{
|
{
|
||||||
|
|
@ -321,7 +321,7 @@ namespace TShockAPI.DB
|
||||||
r.RemoveID(TShock.Users.GetUserID(userName));
|
r.RemoveID(TShock.Users.GetUserID(userName));
|
||||||
string ids = string.Join(",", r.AllowedIDs);
|
string ids = string.Join(",", r.AllowedIDs);
|
||||||
int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", ids,
|
int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", ids,
|
||||||
regionName, Main.worldID.ToString());
|
regionName, Main.worldID.ToString());
|
||||||
if (q > 0)
|
if (q > 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -335,7 +335,7 @@ namespace TShockAPI.DB
|
||||||
string mergedIDs = string.Empty;
|
string mergedIDs = string.Empty;
|
||||||
using (
|
using (
|
||||||
var reader = database.QueryReader("SELECT UserIds FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName,
|
var reader = database.QueryReader("SELECT UserIds FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName,
|
||||||
Main.worldID.ToString()))
|
Main.worldID.ToString()))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
mergedIDs = reader.Get<string>("UserIds");
|
mergedIDs = reader.Get<string>("UserIds");
|
||||||
|
|
@ -353,7 +353,7 @@ namespace TShockAPI.DB
|
||||||
mergedIDs = string.Concat(mergedIDs, ",", userIdToAdd);
|
mergedIDs = string.Concat(mergedIDs, ",", userIdToAdd);
|
||||||
|
|
||||||
int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", mergedIDs,
|
int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", mergedIDs,
|
||||||
regionName, Main.worldID.ToString());
|
regionName, Main.worldID.ToString());
|
||||||
foreach (var r in Regions)
|
foreach (var r in Regions)
|
||||||
{
|
{
|
||||||
if (r.Name == regionName && r.WorldID == Main.worldID.ToString())
|
if (r.Name == regionName && r.WorldID == Main.worldID.ToString())
|
||||||
|
|
@ -430,7 +430,7 @@ namespace TShockAPI.DB
|
||||||
{
|
{
|
||||||
region.Owner = newOwner;
|
region.Owner = newOwner;
|
||||||
int q = database.Query("UPDATE Regions SET Owner=@0 WHERE RegionName=@1 AND WorldID=@2", newOwner,
|
int q = database.Query("UPDATE Regions SET Owner=@0 WHERE RegionName=@1 AND WorldID=@2", newOwner,
|
||||||
regionName, Main.worldID.ToString());
|
regionName, Main.worldID.ToString());
|
||||||
if (q > 0)
|
if (q > 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -442,7 +442,7 @@ namespace TShockAPI.DB
|
||||||
string mergedGroups = "";
|
string mergedGroups = "";
|
||||||
using (
|
using (
|
||||||
var reader = database.QueryReader("SELECT Groups FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName,
|
var reader = database.QueryReader("SELECT Groups FROM Regions WHERE RegionName=@0 AND WorldID=@1", regionName,
|
||||||
Main.worldID.ToString()))
|
Main.worldID.ToString()))
|
||||||
{
|
{
|
||||||
if (reader.Read())
|
if (reader.Read())
|
||||||
mergedGroups = reader.Get<string>("Groups");
|
mergedGroups = reader.Get<string>("Groups");
|
||||||
|
|
@ -458,7 +458,7 @@ namespace TShockAPI.DB
|
||||||
mergedGroups += groupName;
|
mergedGroups += groupName;
|
||||||
|
|
||||||
int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", mergedGroups,
|
int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", mergedGroups,
|
||||||
regionName, Main.worldID.ToString());
|
regionName, Main.worldID.ToString());
|
||||||
|
|
||||||
Region r = GetRegionByName(regionName);
|
Region r = GetRegionByName(regionName);
|
||||||
if (r != null)
|
if (r != null)
|
||||||
|
|
@ -481,47 +481,47 @@ namespace TShockAPI.DB
|
||||||
r.RemoveGroup(group);
|
r.RemoveGroup(group);
|
||||||
string groups = string.Join(",", r.AllowedGroups);
|
string groups = string.Join(",", r.AllowedGroups);
|
||||||
int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groups,
|
int q = database.Query("UPDATE Regions SET Groups=@0 WHERE RegionName=@1 AND WorldID=@2", groups,
|
||||||
regionName, Main.worldID.ToString());
|
regionName, Main.worldID.ToString());
|
||||||
if (q > 0)
|
if (q > 0)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region GetTopRegion( List<Region> regions )
|
public Region GetTopRegion( List<Region> regions )
|
||||||
{
|
{
|
||||||
Region ret = null;
|
Region ret = null;
|
||||||
foreach( Region r in regions)
|
foreach( Region r in regions)
|
||||||
{
|
{
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
ret = r;
|
ret = r;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (r.Z > ret.Z)
|
if (r.Z > ret.Z)
|
||||||
ret = r;
|
ret = r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetZ( string name, int z )
|
public bool SetZ( string name, int z )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
database.Query("UPDATE Regions SET Z=@0 WHERE RegionName=@1 AND WorldID=@2", z, name,
|
database.Query("UPDATE Regions SET Z=@0 WHERE RegionName=@1 AND WorldID=@2", z, name,
|
||||||
Main.worldID.ToString());
|
Main.worldID.ToString());
|
||||||
|
|
||||||
var region = GetRegionByName(name);
|
var region = GetRegionByName(name);
|
||||||
if (region != null)
|
if (region != null)
|
||||||
region.Z = z;
|
region.Z = z;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex.ToString());
|
Log.Error(ex.ToString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Region
|
public class Region
|
||||||
|
|
@ -533,7 +533,7 @@ namespace TShockAPI.DB
|
||||||
public string WorldID { get; set; }
|
public string WorldID { get; set; }
|
||||||
public List<int> AllowedIDs { get; set; }
|
public List<int> AllowedIDs { get; set; }
|
||||||
public List<string> AllowedGroups { get; set; }
|
public List<string> AllowedGroups { get; set; }
|
||||||
public int Z { get; set; }
|
public int Z { get; set; }
|
||||||
|
|
||||||
public Region(Rectangle region, string name, string owner, bool disablebuild, string RegionWorldIDz, int z)
|
public Region(Rectangle region, string name, string owner, bool disablebuild, string RegionWorldIDz, int z)
|
||||||
: this()
|
: this()
|
||||||
|
|
@ -543,7 +543,7 @@ namespace TShockAPI.DB
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
DisableBuild = disablebuild;
|
DisableBuild = disablebuild;
|
||||||
WorldID = RegionWorldIDz;
|
WorldID = RegionWorldIDz;
|
||||||
Z = z;
|
Z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region()
|
public Region()
|
||||||
|
|
@ -554,7 +554,7 @@ namespace TShockAPI.DB
|
||||||
WorldID = string.Empty;
|
WorldID = string.Empty;
|
||||||
AllowedIDs = new List<int>();
|
AllowedIDs = new List<int>();
|
||||||
AllowedGroups = new List<string>();
|
AllowedGroups = new List<string>();
|
||||||
Z = 0;
|
Z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InArea(Rectangle point)
|
public bool InArea(Rectangle point)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue