-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regions.cs
109 lines (95 loc) · 3.11 KB
/
Regions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using TShockAPI;
using Terraria;
namespace Regions
{
[APIVersion( 1, 12 )]
internal class Regions : TerrariaPlugin
{
private RegionManager RegionManager;
private IDbConnection DB;
private Commands comms;
public Regions( Main game) : base( game )
{
}
public override string Author
{
get { return "Team Nyx"; }
}
public override string Description
{
get { return "Region Control"; }
}
public override string Name
{
get { return "Regions"; }
}
public override Version Version
{
get { return TShock.VersionNum; }
}
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();
}
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)
{
if( disposing )
{
Hooks.GameHooks.PostInitialize -= OnPostInit;
}
base.Dispose(disposing);
}
public RegionManager GetRegionManager()
{
return RegionManager;
}
}
}