Permalink
Browse files

Regions function as intended and the same as when it was in the core.

  • Loading branch information...
1 parent 4eba470 commit 3d9e946c0eb6656e73445080cc0c4b63b5d4256c Zack Piispanen committed May 31, 2012
Showing with 75 additions and 19 deletions.
  1. +20 −13 Commands.cs
  2. BIN DLLS/TShockAPI.dll
  3. +15 −0 RegionManager.cs
  4. +40 −6 Regions.cs
  5. BIN Regions.suo
View
@@ -9,6 +9,13 @@ namespace Regions
{
internal class Commands
{
+ private RegionManager Regions;
+
+ public Commands( RegionManager r )
+ {
+ Regions = r;
+ }
+
public void Region(CommandArgs args)
{
string cmd = "help";
@@ -54,7 +61,7 @@ public void Region(CommandArgs args)
var width = Math.Abs(args.Player.TempPoints[0].X - args.Player.TempPoints[1].X);
var height = Math.Abs(args.Player.TempPoints[0].Y - args.Player.TempPoints[1].Y);
- if (TShock.Regions.AddRegion(x, y, width, height, regionName, args.Player.UserAccountName,
+ if (Regions.AddRegion(x, y, width, height, regionName, args.Player.UserAccountName,
Main.worldID.ToString()))
{
args.Player.TempPoints[0] = Point.Zero;
@@ -82,14 +89,14 @@ public void Region(CommandArgs args)
string regionName = args.Parameters[1];
if (args.Parameters[2].ToLower() == "true")
{
- if (TShock.Regions.SetRegionState(regionName, true))
+ if (Regions.SetRegionState(regionName, true))
args.Player.SendSuccessMessage("Protected region " + regionName);
else
args.Player.SendErrorMessage("Could not find specified region");
}
else if (args.Parameters[2].ToLower() == "false")
{
- if (TShock.Regions.SetRegionState(regionName, false))
+ if (Regions.SetRegionState(regionName, false))
args.Player.SendSuccessMessage("Unprotected region " + regionName);
else
args.Player.SendErrorMessage("Could not find specified region");
@@ -106,7 +113,7 @@ public void Region(CommandArgs args)
if (args.Parameters.Count > 1)
{
string regionName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
- if (TShock.Regions.DeleteRegion(regionName))
+ if (Regions.DeleteRegion(regionName))
args.Player.SendSuccessMessage("Deleted region " + regionName);
else
args.Player.SendErrorMessage("Could not find specified region");
@@ -143,7 +150,7 @@ public void Region(CommandArgs args)
}
if (TShock.Users.GetUserByName(playerName) != null)
{
- if (TShock.Regions.AddNewUser(regionName, playerName))
+ if (Regions.AddNewUser(regionName, playerName))
{
args.Player.SendSuccessMessage("Added user " + playerName + " to " + regionName);
}
@@ -178,7 +185,7 @@ public void Region(CommandArgs args)
}
if (TShock.Users.GetUserByName(playerName) != null)
{
- if (TShock.Regions.RemoveUser(regionName, playerName))
+ if (Regions.RemoveUser(regionName, playerName))
{
args.Player.SendSuccessMessage("Removed user " + playerName + " from " + regionName);
}
@@ -213,7 +220,7 @@ public void Region(CommandArgs args)
}
if (TShock.Groups.GroupExists(group))
{
- if (TShock.Regions.AllowGroup(regionName, group))
+ if (Regions.AllowGroup(regionName, group))
{
args.Player.SendSuccessMessage("Added group " + group + " to " + regionName);
}
@@ -248,7 +255,7 @@ public void Region(CommandArgs args)
}
if (TShock.Groups.GroupExists(group))
{
- if (TShock.Regions.RemoveGroup(regionName, group))
+ if (Regions.RemoveGroup(regionName, group))
{
args.Player.SendSuccessMessage("Removed group " + group + " from " + regionName);
}
@@ -283,7 +290,7 @@ public void Region(CommandArgs args)
page--; //Substract 1 as pages are parsed starting at 1 and not 0
}
- var regions = TShock.Regions.ListAllRegions(Main.worldID.ToString());
+ var regions = Regions.ListAllRegions(Main.worldID.ToString());
// Are there even any regions to display?
if (regions.Count == 0)
@@ -329,7 +336,7 @@ public void Region(CommandArgs args)
if (args.Parameters.Count > 1)
{
string regionName = String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1));
- TShockAPI.DB.Region r = TShock.Regions.GetRegionByName(regionName);
+ Region r = Regions.GetRegionByName(regionName);
if (r == null)
{
@@ -360,7 +367,7 @@ public void Region(CommandArgs args)
int z = 0;
if (int.TryParse(args.Parameters[2], out z))
{
- if (TShock.Regions.SetZ(regionName, z))
+ if (Regions.SetZ(regionName, z))
args.Player.SendInfoMessage("Region's z is now " + z);
else
args.Player.SendErrorMessage("Could not find specified region");
@@ -412,10 +419,10 @@ public void Region(CommandArgs args)
}
int addAmount;
int.TryParse(args.Parameters[3], out addAmount);
- if (TShock.Regions.resizeRegion(args.Parameters[1], addAmount, direction))
+ if (Regions.resizeRegion(args.Parameters[1], addAmount, direction))
{
args.Player.SendSuccessMessage("Region Resized Successfully!");
- TShock.Regions.ReloadAllRegions();
+ Regions.ReloadAllRegions();
}
else
{
View
Binary file not shown.
View
@@ -285,6 +285,21 @@ public List<string> InAreaRegionName(int x, int y)
return regions;
}
+ public List<Region> InAreaRegion(int x, int y)
+ {
+ List<Region> regions = new List<Region>() { };
+ foreach (Region region in Regions)
+ {
+ if (x >= region.Area.Left && x <= region.Area.Right &&
+ y >= region.Area.Top && y <= region.Area.Bottom &&
+ region.DisableBuild)
+ {
+ regions.Add(region);
+ }
+ }
+ return regions;
+ }
+
public static List<string> ListIDs(string MergedIDs)
{
return MergedIDs.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).ToList();
View
@@ -8,18 +8,15 @@
namespace Regions
{
+ [APIVersion( 1, 12 )]
internal class Regions : TerrariaPlugin
{
private RegionManager RegionManager;
private IDbConnection DB;
-
- public delegate void InitializedD();
- public static event InitializedD Initialized;
private Commands comms;
public Regions( Main game) : base( game )
{
- comms = new Commands();
}
public override string Author
@@ -46,15 +43,52 @@ public override void Initialize()
{
DB = TShock.DB;
RegionManager = new RegionManager(DB);
-
+ comms = new Commands( RegionManager );
Hooks.GameHooks.PostInitialize += OnPostInit;
+ GetDataHandlers.TileEdit += OnTileEdit;
TShockAPI.Commands.ChatCommands.Add(new Command("manageregion", comms.Region, "region"));
}
private void OnPostInit()
{
RegionManager.ReloadAllRegions();
- Initialized();
+ }
+
+ private void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
+ {
+ if (args.Player.AwaitingName)
+ {
+ var protectedregions = RegionManager.InAreaRegionName(args.X, args.Y);
+ if (protectedregions.Count == 0)
+ {
+ args.Player.SendMessage("Region is not protected", Color.Yellow);
+ }
+ else
+ {
+ string regionlist = string.Join(",", protectedregions.ToArray());
+ args.Player.SendMessage("Region Name(s): " + regionlist, Color.Yellow);
+ }
+ args.Player.SendTileSquare(args.X, args.Y);
+ args.Player.AwaitingName = false;
+ args.Handled = true;
+ }
+
+ if (args.Handled)
+ {
+ return;
+ }
+
+ Region region = RegionManager.GetTopRegion(RegionManager.InAreaRegion(args.X, args.Y));
+ if (!RegionManager.CanBuild(args.X, args.Y, args.Player))
+ {
+ if (((DateTime.Now.Ticks/TimeSpan.TicksPerMillisecond) - args.Player.RPm) > 2000)
+ {
+ args.Player.SendMessage("Region protected from changes.", Color.Red);
+ args.Player.RPm = DateTime.Now.Ticks/TimeSpan.TicksPerMillisecond;
+ }
+ args.Player.SendTileSquare(args.X, args.Y);
+ args.Handled = true;
+ }
}
protected override void Dispose(bool disposing)
View
Binary file not shown.

0 comments on commit 3d9e946

Please sign in to comment.