regions should work, and load from db at start.
regions also have remove syntax, /region remove user region which removes them from the list, if they exist.
This commit is contained in:
parent
e0d509982f
commit
ec63e61e1f
2 changed files with 66 additions and 2 deletions
|
|
@ -154,7 +154,7 @@ namespace TShockAPI
|
|||
ChatCommands.Add(new Command("pvpfun", Slap, "slap"));
|
||||
ChatCommands.Add(new Command("editspawn", ToggleAntiBuild, "antibuild"));
|
||||
ChatCommands.Add(new Command("editspawn", ProtectSpawn, "protectspawn"));
|
||||
ChatCommands.Add(new Command("editspawn", Region, "region"));
|
||||
ChatCommands.Add(new Command("manageregion", Region, "region"));
|
||||
ChatCommands.Add(new Command("editspawn", DebugRegions, "debugreg"));
|
||||
ChatCommands.Add(new Command(Help, "help"));
|
||||
ChatCommands.Add(new Command(Playing, "playing", "online", "who"));
|
||||
|
|
@ -1837,6 +1837,41 @@ namespace TShockAPI
|
|||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region allow [name] [region]", Color.Red);
|
||||
break;
|
||||
}
|
||||
case "remove":
|
||||
if (args.Parameters.Count > 2)
|
||||
{
|
||||
string playerName = args.Parameters[1];
|
||||
string regionName = "";
|
||||
User playerID;
|
||||
|
||||
for (int i = 2; i < args.Parameters.Count; i++)
|
||||
{
|
||||
if (regionName == "")
|
||||
{
|
||||
regionName = args.Parameters[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
regionName = regionName + " " + args.Parameters[i];
|
||||
}
|
||||
}
|
||||
if ((playerID = TShock.Users.GetUserByName(playerName)) != null)
|
||||
{
|
||||
if (TShock.Regions.RemoveUser(regionName, playerName))
|
||||
{
|
||||
args.Player.SendMessage("Removed user " + playerName + " from " + regionName, Color.Yellow);
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Region " + regionName + " not found", Color.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Player.SendMessage("Player " + playerName + " not found", Color.Red);
|
||||
}
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region allow [name] [region]", Color.Red);
|
||||
break;
|
||||
case "list":
|
||||
{
|
||||
//How many regions per page
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ namespace TShockAPI.DB
|
|||
creator.EnsureExists(table);
|
||||
|
||||
ImportOld();
|
||||
ReloadAllRegions();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -361,6 +362,20 @@ namespace TShockAPI.DB
|
|||
return MergedIDs.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
public bool RemoveUser(string regionName, string userName )
|
||||
{
|
||||
Region r = getRegion(regionName);
|
||||
if( r != null )
|
||||
{
|
||||
r.RemoveID(TShock.Users.GetUserID(userName));
|
||||
string ids = string.Join(",", r.AllowedIDs);
|
||||
int q = database.Query("UPDATE Regions SET UserIds=@0 WHERE RegionName=@1 AND WorldID=@2", ids,
|
||||
regionName, Main.worldID.ToString());
|
||||
if (q > 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool AddNewUser(string regionName, String userName)
|
||||
{
|
||||
try
|
||||
|
|
@ -420,7 +435,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
foreach (Region r in Regions)
|
||||
{
|
||||
if (r.Name.Equals(name))
|
||||
if (r.Name.Equals(name) && r.WorldID == Main.worldID.ToString())
|
||||
return r;
|
||||
}
|
||||
return new Region();
|
||||
|
|
@ -501,5 +516,19 @@ namespace TShockAPI.DB
|
|||
}
|
||||
AllowedIDs = id_list;
|
||||
}
|
||||
|
||||
public void RemoveID(int id)
|
||||
{
|
||||
var index = -1;
|
||||
for (int i = 0; i < AllowedIDs.Count; i++ )
|
||||
{
|
||||
if (AllowedIDs[i] == id)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
AllowedIDs.RemoveAt( index );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue