• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Administrator's Toolkit VS plugin


Commit MetaInfo

Revision90c4dfcea834bf8ea90aa29a11ef8a07771210b6 (tree)
Time2021-01-12 11:36:10
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Bugfix for V.S.P. & invalid RoleCode

Change Summary

Incremental Difference

--- a/AdminToolkit/Commands/VariableSpawnpoints.cs
+++ b/AdminToolkit/Commands/VariableSpawnpoints.cs
@@ -49,13 +49,13 @@ namespace AdminToolkit
4949 this.Command = "spawnpoints";
5050 this.Description = "Control add / remove / adjust List of approved player spawn points";
5151 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";
5353 this.handler += HandleCommand;
5454
5555 ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.RunGame, ReloadSpawnpoints);
5656
5757 ServerAPI.Event.PlayerDeath += PlayerDied;
58- ServerAPI.Event.PlayerCreate += (byPlayer) => ChangeDefaultRoleSpawnPoint();
58+ ServerAPI.Event.PlayerCreate += PlayerCreated;
5959
6060
6161 ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistSpawnpoints);
@@ -79,7 +79,12 @@ namespace AdminToolkit
7979 position = player.Entity.Pos.XYZInt;
8080 }
8181 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+
8388 position = RelativeToAbsolute(pos);
8489 }
8590
@@ -103,10 +108,12 @@ namespace AdminToolkit
103108 break;
104109
105110 case "enable":
111+ player.SendMessage(groupId, "OK.", EnumChatType.CommandSuccess);
106112 Toggle(true);
107113 break;
108114
109115 case "disable":
116+ player.SendMessage(groupId, "OK.", EnumChatType.CommandSuccess);
110117 Toggle(false);
111118 break;
112119
@@ -139,14 +146,14 @@ namespace AdminToolkit
139146 {
140147 if (IsItSafe(position.AsBlockPos)) {
141148 //Appears OK...
142- Logger.VerboseDebug($"Adding variable spawnpoint '{name}' @ {position}");
149+ Logger.Event($"Adding variable spawnpoint '{name}' @ {position}");
143150 var newSpawnpoint = new Spawnpoint(name, position);
144151
145152 this.Spawnpoints.Add(newSpawnpoint);
146153 return true;
147154 }
148155 else {
149- Logger.VerboseDebug($"Apparently '{name}' spawnpoint is Unsafe! @ABS:{position}");
156+ Logger.Notification($"Apparently '{name}' spawnpoint is Unsafe! @ABS:{position}");
150157 }
151158
152159 return false;
@@ -186,6 +193,7 @@ namespace AdminToolkit
186193
187194 private void ListSpawnpoints( int chatGroupId, IServerPlayer player )
188195 {
196+ player.SendMessage(chatGroupId, $"V.S.P are {(this.CachedConfiguration.VariableSpawnpoints? "ENABLED":"DISABLED")}, with {this.Spawnpoints.Count} points.\n", EnumChatType.CommandSuccess);
189197 if (this.Spawnpoints.Count > 0) {
190198 foreach (var sp in this.Spawnpoints) {
191199 player.SendMessage(chatGroupId, $"Spawn: '{sp.Name}' ({PrettyFormat(sp.Location)}) ABS:({sp.Location})", EnumChatType.CommandSuccess);
@@ -195,7 +203,18 @@ namespace AdminToolkit
195203
196204 private void Toggle(bool state)
197205 {
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+ }
199218 }
200219
201220 private void ResetPlayer(string name)
@@ -273,6 +292,13 @@ namespace AdminToolkit
273292 }
274293 }
275294
295+ private void PlayerCreated(IServerPlayer byPlayer)
296+ {
297+ ChangeDefaultRoleSpawnPoint( );
298+ }
299+
300+
301+
276302 private void ChangeDefaultRoleSpawnPoint( )
277303 {
278304 if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
@@ -280,7 +306,13 @@ namespace AdminToolkit
280306 var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count)];
281307
282308 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+
284316
285317 #if DEBUG
286318 Logger.VerboseDebug($"Changing ({serverPlayerRole.Name}) to spawn '{randSp.Name}' @ {randSp.Location}");
@@ -333,7 +365,7 @@ namespace AdminToolkit
333365 (
334366 @"{0:D}, {1:D}, {2:D}",
335367 spawnPos.x - start.X,
336- spawnPos.y - start.Y,
368+ spawnPos.y,
337369 spawnPos.z - start.Z
338370 );
339371