forked from Olink/AutoTeamPlus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoTeamPlus.cs
117 lines (102 loc) · 3.24 KB
/
AutoTeamPlus.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
110
111
112
113
114
115
116
117
using System;
using TerrariaApi.Server;
using Terraria;
using TShockAPI;
using TShockAPI.Hooks;
namespace AutoTeamPlus
{
[ApiVersion(1, 23)]
public class AutoTeamPlus : TerrariaPlugin
{
public override string Author
{
get { return "Jewsus"; }
}
public override string Description
{
get { return "Force teams based on user permissions"; }
}
public override string Name
{
get { return "AutoTeamPlus"; }
}
public override Version Version
{
get { return new Version(1, 0); }
}
public AutoTeamPlus(Main game) : base(game)
{
}
public override void Initialize()
{
ServerApi.Hooks.NetGreetPlayer.Register(this, OnJoin);
GetDataHandlers.PlayerTeam += OnTeamChange;
PlayerHooks.PlayerPostLogin += OnLogin;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Hooks.NetGreetPlayer.Deregister(this, OnJoin);
GetDataHandlers.PlayerTeam -= OnTeamChange;
PlayerHooks.PlayerPostLogin -= OnLogin;
}
base.Dispose(disposing);
}
private void OnJoin(GreetPlayerEventArgs args)
{
var ply = TShock.Players[args.Who];
SetTeam(ply);
}
private void OnTeamChange(object sender, GetDataHandlers.PlayerTeamEventArgs args)
{
var ply = TShock.Players[args.PlayerId];
args.Handled = SetTeam(ply);
}
private void OnLogin(PlayerPostLoginEventArgs args)
{
SetTeam(args.Player);
}
private bool SetTeam(TSPlayer ply)
{
if (ply.Group.Name == "superadmin" || ply.Group.HasPermission("*"))
{
return false;
}
var ret = false;
if (ply.Group.HasPermission("autoteam.none"))
{
ply.SetTeam(0);
ret = true;
}
if (ply.Group.HasPermission("autoteam.red"))
{
ply.SetTeam(1);
ret = true;
}
if (ply.Group.HasPermission("autoteam.green"))
{
ply.SetTeam(2);
ret = true;
}
if (ply.Group.HasPermission("autoteam.blue"))
{
ply.SetTeam(3);
ret = true;
}
if (ply.Group.HasPermission("autoteam.yellow"))
{
ply.SetTeam(4);
ret = true;
}
if (ply.Group.HasPermission("autoteam.pink"))
{
ply.SetTeam(5);
ret = true;
}
if (ret)
ply.SendInfoMessage("Your team has been changed to {0}.", ply.Team == 0 ? "none" : ply.Team == 1 ? "the red team" : ply.Team == 2 ? "the green team" : ply.Team == 3 ? "the blue team" : ply.Team == 4 ? "the yellow team" : "the pink team");
return ret;
}
}
}