• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

Administrator's Toolkit VS plugin


Commit MetaInfo

Revision8ba00983036921e9c1b2e200b15862006546750a (tree)
Zeit2020-09-14 05:08:34
Autormelchior <melchior@user...>
Commitermelchior

Log Message

W.I.P. Untested sp fix

Ändern Zusammenfassung

Diff

--- a/AdminToolkit/Commands/VariableSpawnpoints.cs
+++ b/AdminToolkit/Commands/VariableSpawnpoints.cs
@@ -16,7 +16,7 @@ using ProtoBuf;
1616 namespace AdminToolkit
1717 {
1818 [ProtoContract]
19- public struct Spawnpoint
19+ internal struct Spawnpoint
2020 {
2121 [ProtoMember(1)]
2222 public PlayerSpawnPos Location;
@@ -49,52 +49,23 @@ 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);
56- ServerAPI.Event.PlayerCreate += NewPlayerCreation;
56+ ServerAPI.Event.PlayerJoin += PlayerJoins;
5757 ServerAPI.Event.PlayerDeath += PlayerDied;
5858 ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistSpawnpoints);
5959 }
6060
61- private void ReloadSpawnpoints( )
62- {
63- var spawnsBytes = ServerAPI.WorldManager.SaveGame.GetData(_spawnsDataKey);
64-
65- if (spawnsBytes != null) {
66- this.Spawnpoints = SerializerUtil.Deserialize<List<Spawnpoint>>(spawnsBytes);
67- Logger.Notification("Loaded Variable-Spawns # ({0})", Spawnpoints.Count);
68- }
69- else {
70- this.Spawnpoints = new List<Spawnpoint>( );
71-
72- var emptySpawnsList = SerializerUtil.Serialize(this.Spawnpoints);
73-
74- ServerAPI.WorldManager.SaveGame.StoreData(_spawnsDataKey, emptySpawnsList);
75-
76- Logger.Notification("Created (empty) Spawnpoints Data");
77- }
78-
79-
80- }
81-
82- private void PersistSpawnpoints( )
83- {
84- if (this.Spawnpoints != null && this.Spawnpoints.Count > 0) {
85- var spawnDatas = SerializerUtil.Serialize(this.Spawnpoints);
86- ServerAPI.WorldManager.SaveGame.StoreData(_spawnsDataKey, spawnDatas);
87- Logger.Notification("Persisted Spawnpoints Data");
88- }
8961
90- }
9162
9263 private void HandleCommand(IServerPlayer player, int groupId, CmdArgs args)
9364 {
9465 string name;
9566 Vec3i position;
96-
97-
67+
68+ bool console = player is ServerConsolePlayer;
9869
9970 if (args.Length >= 1) {
10071 string cmd = args.PopWord(string.Empty).ToLowerInvariant();
@@ -103,19 +74,26 @@ namespace AdminToolkit
10374 case "add":
10475 name = args.PopWord("?");
10576
106- if (String.Equals(args.PeekWord(), "here", StringComparison.OrdinalIgnoreCase)) {
77+ if (console == false && String.Equals(args.PeekWord( ), "here", StringComparison.OrdinalIgnoreCase)) {
10778 position = player.Entity.Pos.XYZInt;
10879 }
109- position = args.PopVec3i(player.Entity.Pos.XYZInt);
80+ else {
81+ var pos = args.PopVec3i(ServerAPI.World.DefaultSpawnPosition.AsBlockPos.ToVec3i( ));
82+ position = RelativeToAbsolute(pos);
83+ }
84+
11085 if (AddSpawnpoint(name, position)) {
111- player.SendMessage(groupId, "Added Spawnpoint", EnumChatType.CommandSuccess);
86+ player.SendMessage(groupId, "Added Spawnpoint.", EnumChatType.CommandSuccess);
87+ }
88+ else {
89+ player.SendMessage(groupId, "Can't add Spawnpoint!", EnumChatType.CommandError);
11290 }
11391 break;
11492
11593 case "remove":
11694 name = args.PopWord( );
11795 if (RemoveSpawnpoint(name)) {
118- player.SendMessage(groupId, "Removed Spawnpoint", EnumChatType.CommandSuccess);
96+ player.SendMessage(groupId, $"Removed Spawnpoint '{name}'", EnumChatType.CommandSuccess);
11997 }
12098 break;
12199
@@ -131,6 +109,16 @@ namespace AdminToolkit
131109 Toggle(false);
132110 break;
133111
112+ case "reset":
113+ if (console) {
114+ name = args.PopWord("?");
115+ #if DEBUG
116+ ResetPlayer(name);
117+ player.SendMessage(groupId, $"Reset Playerdata for '{name}'", EnumChatType.CommandSuccess);
118+ #endif
119+ }
120+ break;
121+
134122 default:
135123 player.SendMessage(groupId, "Unrecognised command ", EnumChatType.CommandError);
136124 break;
@@ -161,7 +149,7 @@ namespace AdminToolkit
161149 return true;
162150 }
163151 else {
164- Logger.VerboseDebug($"Apparently spawnpoint Unsafe! @ {position}");
152+ Logger.VerboseDebug($"Apparently '{name}' spawnpoint is Unsafe! @ABS:{position}");
165153 }
166154
167155 return false;
@@ -182,7 +170,7 @@ namespace AdminToolkit
182170 {
183171 if (this.Spawnpoints.Count > 0) {
184172 foreach (var sp in this.Spawnpoints) {
185- player.SendMessage(chatGroupId, $"Spawn: '{sp.Name}' @({sp.Location})", EnumChatType.CommandSuccess);
173+ player.SendMessage(chatGroupId, $"Spawn: '{sp.Name}' ({PrettyFormat(sp.Location)}) ABS:({sp.Location})", EnumChatType.CommandSuccess);
186174 }
187175 }
188176 }
@@ -192,18 +180,62 @@ namespace AdminToolkit
192180 this.CachedConfiguration.VariableSpawnpoints = state;
193181 }
194182
195- private void NewPlayerCreation( IServerPlayer byPlayer)
183+ private void ResetPlayer(string name)
184+ {
185+ var byPlayer = ServerAPI.Server.Players.SingleOrDefault(plr => plr.PlayerName == name);
186+ if (byPlayer != null && this.Spawnpoints != null && this.Spawnpoints.Count > 0)
187+ {
188+ byPlayer.ClearSpawnPosition( );
189+ //var datas = ServerAPI.PlayerData.GetPlayerDataByUid(byPlayer.PlayerUID);
190+ //datas.
191+ //ServerAPI.Server.Players.Remove(byPlayer); //List is a array copy
192+ var servPlayer = byPlayer as ServerPlayer;
193+
194+ }
195+ }
196+
197+ #region Events
198+
199+ private void ReloadSpawnpoints( )
200+ {
201+ var spawnsBytes = ServerAPI.WorldManager.SaveGame.GetData(_spawnsDataKey);
202+
203+ if (spawnsBytes != null) {
204+ this.Spawnpoints = SerializerUtil.Deserialize<List<Spawnpoint>>(spawnsBytes);
205+ Logger.Notification("Loaded Variable-Spawns # ({0}) STATE: {1}", Spawnpoints.Count, (this.CachedConfiguration.VariableSpawnpoints ? "Enabled" : "Disabled"));
206+ }
207+ else {
208+ this.Spawnpoints = new List<Spawnpoint>( );
209+
210+ var emptySpawnsList = SerializerUtil.Serialize(this.Spawnpoints);
211+
212+ ServerAPI.WorldManager.SaveGame.StoreData(_spawnsDataKey, emptySpawnsList);
213+
214+ Logger.Notification("Created (empty) Spawnpoints Data");
215+ }
216+
217+
218+ }
219+
220+ private void PersistSpawnpoints( )
221+ {
222+ if (this.Spawnpoints != null && this.Spawnpoints.Count > 0) {
223+ var spawnDatas = SerializerUtil.Serialize(this.Spawnpoints);
224+ ServerAPI.WorldManager.SaveGame.StoreData(_spawnsDataKey, spawnDatas);
225+ Logger.Notification("Persisted Spawnpoints Data");
226+ }
227+
228+ }
229+
230+ private void PlayerJoins( IServerPlayer byPlayer)
196231 {
197232 if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
198233
199234 var swpd = byPlayer.WorldData as ServerWorldPlayerData;
200- if (swpd.SpawnPosition == null) {
201- var newSP = RandomSpawnpoint( );
202- byPlayer.SetSpawnPosition(newSP.Location);
203- #if DEBUG
204- Logger.VerboseDebug($"New spawn Pos: '{newSP.Name}' @ {newSP.Location} ");
205- #endif
206- }
235+ if (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition))
236+ {
237+ RandomizeSpawnpoint(byPlayer);
238+ }
207239 }
208240 }
209241
@@ -212,19 +244,23 @@ namespace AdminToolkit
212244 if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
213245
214246 var swpd = byPlayer.WorldData as ServerWorldPlayerData;
215- if (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition)) {
216- var newSP = RandomSpawnpoint( );
217- byPlayer.SetSpawnPosition(newSP.Location);
218- #if DEBUG
219- Logger.VerboseDebug( $"Changed spawn Pos: '{newSP.Name}' @ {newSP.Location} ");
220- #endif
221- }
247+ if (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition))
248+ {
249+ RandomizeSpawnpoint(byPlayer);
250+ }
222251 }
223252 }
224253
225- private Spawnpoint RandomSpawnpoint( )
254+ #endregion
255+
256+
257+ private void RandomizeSpawnpoint(IServerPlayer byPlayer)
226258 {
227- return this.Spawnpoints[random.Next(0, Spawnpoints.Count - 1)];
259+ var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count - 1)];
260+ byPlayer.SetSpawnPosition(randSp.Location);
261+ #if DEBUG
262+ Logger.VerboseDebug($"Changed spawn Pos: '{randSp.Name}' @ {randSp.Location} for {byPlayer.PlayerName}");
263+ #endif
228264 }
229265
230266 private bool KnownSpawn(PlayerSpawnPos aSpawn)
@@ -237,6 +273,32 @@ namespace AdminToolkit
237273
238274 return false;
239275 }
276+
277+ private Vec3i RelativeToAbsolute(Vec3i location)
278+ {
279+ var start = ServerAPI.World.DefaultSpawnPosition.AsBlockPos;
280+ return new Vec3i( location.X + start.X, location.Y, location.Z + start.Z);
281+ }
282+
283+ private Vec3i AbsoluteToRelative(Vec3i location)
284+ {
285+ var start = ServerAPI.World.DefaultSpawnPosition.AsBlockPos;
286+ return new Vec3i(start.X - location.X, location.Y, start.Z - location.Z);
287+ }
288+
289+ private string PrettyFormat(PlayerSpawnPos spawnPos)
290+ {
291+ var start = ServerAPI.World.DefaultSpawnPosition.AsBlockPos;
292+
293+ return String.Format
294+ (
295+ @"{0:D}, {1:D}, {2:D}",
296+ spawnPos.x - start.X,
297+ spawnPos.y - start.Y,
298+ spawnPos.z - start.Z
299+ );
300+
301+ }
240302 }
241303 }
242304
--- a/AdminToolkit/readme.md
+++ b/AdminToolkit/readme.md
@@ -1,5 +1,5 @@
11 
2-Instructions for using the Administrator's Toolkit (V0.3.3);
2+Instructions for using the Administrator's Toolkit (V0.3.6);
33 ============================================================
44
55 It provides the (server side only) commands:
@@ -7,6 +7,12 @@ It provides the (server side only) commands:
77 * /rules
88 * /admins
99 * /backups
10+* /pings
11+* /spawnpoints
12+
13+The configuration file: 'admintoolkit.json' ( %home%/.config/VintagestoryData/ModConfig );
14+Note: by default most features are _DISABLED_ .
15+
1016
1117 RULES
1218 -----
@@ -97,3 +103,30 @@ A special feature for admins; their text messages get underlined.
97103 edit file ('/ModConfig/admintoolkit.json' ) :
98104
99105 > "BoomingVoice": true
106+
107+
108+
109+VAIRABLE SPAWNS
110+---------------
111+
112+Lets admins define and have players spawn from a list of pre-defined coordinates.
113+(chosen at random)
114+
115+Config file setting: "VariableSpawnpoints" : set value to 'true' or 'false' (no quotes)
116+
117+Use command:
118+/spawnpoints
119+
120+/spawnpoints add {name} {5123 100 3992} | here
121+
122+(either 'here' where admin is standing OR manually entered RELATIVE (to-spawn) coordinates)
123+
124+/spawnpoints remove {name}
125+
126+(by name of spawnpoint)
127+
128+/spawnpoints list
129+
130+/spawnpoints enable
131+
132+/spawnpoints disable