Administrator's Toolkit VS plugin
Revision | 90c4dfcea834bf8ea90aa29a11ef8a07771210b6 (tree) |
---|---|
Time | 2021-01-12 11:36:10 |
Author | melchior <melchior@user...> |
Commiter | melchior |
Bugfix for V.S.P. & invalid RoleCode
@@ -49,13 +49,13 @@ namespace AdminToolkit | ||
49 | 49 | this.Command = "spawnpoints"; |
50 | 50 | this.Description = "Control add / remove / adjust List of approved player spawn points"; |
51 | 51 | this.RequiredPrivilege = Privilege.setspawn; |
52 | - this.Syntax = @"Add {name} {123 456 -678}|here / Remove {name} / List / Enable / Disable"; | |
52 | + this.Syntax = @"add {name} {123 456 -678}|here / remove {name} / list / enable / disable"; | |
53 | 53 | this.handler += HandleCommand; |
54 | 54 | |
55 | 55 | ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.RunGame, ReloadSpawnpoints); |
56 | 56 | |
57 | 57 | ServerAPI.Event.PlayerDeath += PlayerDied; |
58 | - ServerAPI.Event.PlayerCreate += (byPlayer) => ChangeDefaultRoleSpawnPoint(); | |
58 | + ServerAPI.Event.PlayerCreate += PlayerCreated; | |
59 | 59 | |
60 | 60 | |
61 | 61 | ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistSpawnpoints); |
@@ -79,7 +79,12 @@ namespace AdminToolkit | ||
79 | 79 | position = player.Entity.Pos.XYZInt; |
80 | 80 | } |
81 | 81 | else { |
82 | - var pos = args.PopVec3i(ServerAPI.World.DefaultSpawnPosition.AsBlockPos.ToVec3i( )); | |
82 | + var pos = args.PopVec3i(null); | |
83 | + if (pos == null) { | |
84 | + player.SendMessage(groupId, $"Can't add Spawnpoint '{name}' - Co-Ordinates Invalid!", EnumChatType.CommandError); | |
85 | + return; | |
86 | + } | |
87 | + | |
83 | 88 | position = RelativeToAbsolute(pos); |
84 | 89 | } |
85 | 90 |
@@ -103,10 +108,12 @@ namespace AdminToolkit | ||
103 | 108 | break; |
104 | 109 | |
105 | 110 | case "enable": |
111 | + player.SendMessage(groupId, "OK.", EnumChatType.CommandSuccess); | |
106 | 112 | Toggle(true); |
107 | 113 | break; |
108 | 114 | |
109 | 115 | case "disable": |
116 | + player.SendMessage(groupId, "OK.", EnumChatType.CommandSuccess); | |
110 | 117 | Toggle(false); |
111 | 118 | break; |
112 | 119 |
@@ -139,14 +146,14 @@ namespace AdminToolkit | ||
139 | 146 | { |
140 | 147 | if (IsItSafe(position.AsBlockPos)) { |
141 | 148 | //Appears OK... |
142 | - Logger.VerboseDebug($"Adding variable spawnpoint '{name}' @ {position}"); | |
149 | + Logger.Event($"Adding variable spawnpoint '{name}' @ {position}"); | |
143 | 150 | var newSpawnpoint = new Spawnpoint(name, position); |
144 | 151 | |
145 | 152 | this.Spawnpoints.Add(newSpawnpoint); |
146 | 153 | return true; |
147 | 154 | } |
148 | 155 | else { |
149 | - Logger.VerboseDebug($"Apparently '{name}' spawnpoint is Unsafe! @ABS:{position}"); | |
156 | + Logger.Notification($"Apparently '{name}' spawnpoint is Unsafe! @ABS:{position}"); | |
150 | 157 | } |
151 | 158 | |
152 | 159 | return false; |
@@ -186,6 +193,7 @@ namespace AdminToolkit | ||
186 | 193 | |
187 | 194 | private void ListSpawnpoints( int chatGroupId, IServerPlayer player ) |
188 | 195 | { |
196 | + player.SendMessage(chatGroupId, $"V.S.P are {(this.CachedConfiguration.VariableSpawnpoints? "ENABLED":"DISABLED")}, with {this.Spawnpoints.Count} points.\n", EnumChatType.CommandSuccess); | |
189 | 197 | if (this.Spawnpoints.Count > 0) { |
190 | 198 | foreach (var sp in this.Spawnpoints) { |
191 | 199 | player.SendMessage(chatGroupId, $"Spawn: '{sp.Name}' ({PrettyFormat(sp.Location)}) ABS:({sp.Location})", EnumChatType.CommandSuccess); |
@@ -195,7 +203,18 @@ namespace AdminToolkit | ||
195 | 203 | |
196 | 204 | private void Toggle(bool state) |
197 | 205 | { |
198 | - this.CachedConfiguration.VariableSpawnpoints = state; | |
206 | + if (state == false && this.CachedConfiguration.VariableSpawnpoints ) { | |
207 | + ServerAPI.Event.PlayerDeath -= PlayerDied; | |
208 | + ServerAPI.Event.PlayerCreate -= PlayerCreated; | |
209 | + Logger.Notification("Variable Spawnpoints: DISABLED, events disconnected."); | |
210 | + this.CachedConfiguration.VariableSpawnpoints = false; | |
211 | + } | |
212 | + else if (state && this.CachedConfiguration.VariableSpawnpoints == false) { | |
213 | + ServerAPI.Event.PlayerDeath += PlayerDied; | |
214 | + ServerAPI.Event.PlayerCreate += PlayerCreated; | |
215 | + Logger.Notification("Variable Spawnpoints: RE-ENABLED, events attached."); | |
216 | + this.CachedConfiguration.VariableSpawnpoints = true; | |
217 | + } | |
199 | 218 | } |
200 | 219 | |
201 | 220 | private void ResetPlayer(string name) |
@@ -273,6 +292,13 @@ namespace AdminToolkit | ||
273 | 292 | } |
274 | 293 | } |
275 | 294 | |
295 | + private void PlayerCreated(IServerPlayer byPlayer) | |
296 | + { | |
297 | + ChangeDefaultRoleSpawnPoint( ); | |
298 | + } | |
299 | + | |
300 | + | |
301 | + | |
276 | 302 | private void ChangeDefaultRoleSpawnPoint( ) |
277 | 303 | { |
278 | 304 | if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) { |
@@ -280,7 +306,13 @@ namespace AdminToolkit | ||
280 | 306 | var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count)]; |
281 | 307 | |
282 | 308 | string roleCode = CachedConfiguration.PlayerRoleNormal; //ServerAPI.Server.Config.DefaultRoleCode; |
283 | - var serverPlayerRole = ServerAPI.Server.Config.Roles.Single(pr => pr.Code == roleCode) as PlayerRole; | |
309 | + var serverPlayerRole = ServerAPI.Server.Config.Roles.SingleOrDefault(pr => pr.Code == roleCode) as PlayerRole; | |
310 | + if (serverPlayerRole == null) { | |
311 | + Logger.Error("Missing RoleCode: {0} - Cannot use VSP! ", roleCode); | |
312 | + Toggle(false); | |
313 | + return; | |
314 | + } | |
315 | + | |
284 | 316 | |
285 | 317 | #if DEBUG |
286 | 318 | Logger.VerboseDebug($"Changing ({serverPlayerRole.Name}) to spawn '{randSp.Name}' @ {randSp.Location}"); |
@@ -333,7 +365,7 @@ namespace AdminToolkit | ||
333 | 365 | ( |
334 | 366 | @"{0:D}, {1:D}, {2:D}", |
335 | 367 | spawnPos.x - start.X, |
336 | - spawnPos.y - start.Y, | |
368 | + spawnPos.y, | |
337 | 369 | spawnPos.z - start.Z |
338 | 370 | ); |
339 | 371 |