• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Administrator's Toolkit VS plugin


Commit MetaInfo

Revisionc98f626ee6c0ff75fa6262c2e4f9de5ac299e5a1 (tree)
Time2020-11-05 07:23:22
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Attempt to change spawn points for First time joins

Change Summary

Incremental Difference

--- a/AdminToolkit/Commands/VariableSpawnpoints.cs
+++ b/AdminToolkit/Commands/VariableSpawnpoints.cs
@@ -47,19 +47,20 @@ namespace AdminToolkit
4747 public VariableSpawnpoints(ICoreServerAPI _serverAPI) : base(_serverAPI)
4848 {
4949 this.Command = "spawnpoints";
50- this.Description = "Control add/remove/adjust List of approved player spawn points";
50+ this.Description = "Control add / remove / adjust List of approved player spawn points";
5151 this.RequiredPrivilege = Privilege.setspawn;
5252 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.PlayerJoin += PlayerJoins;
56+
5757 ServerAPI.Event.PlayerDeath += PlayerDied;
58+ ServerAPI.Event.PlayerCreate += (byPlayer) => ChangeDefaultRoleSpawnPoint();
59+
60+
5861 ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistSpawnpoints);
5962 }
6063
61-
62-
6364 private void HandleCommand(IServerPlayer player, int groupId, CmdArgs args)
6465 {
6566 string name;
@@ -114,9 +115,12 @@ namespace AdminToolkit
114115 name = args.PopWord("?");
115116 #if DEBUG
116117 ResetPlayer(name);
117- player.SendMessage(groupId, $"Reset Playerdata for '{name}'", EnumChatType.CommandSuccess);
118+ player.SendMessage(groupId, $"Reset State / Playerdata for '{name}'", EnumChatType.CommandSuccess);
118119 #endif
119120 }
121+ else {
122+ player.SendMessage(groupId, "Only CONSOLE may use command!", EnumChatType.CommandError);
123+ }
120124 break;
121125
122126 default:
@@ -186,11 +190,16 @@ namespace AdminToolkit
186190 if (byPlayer != null && this.Spawnpoints != null && this.Spawnpoints.Count > 0)
187191 {
188192 byPlayer.ClearSpawnPosition( );
189- //var datas = ServerAPI.PlayerData.GetPlayerDataByUid(byPlayer.PlayerUID);
190- //datas.
191- //ServerAPI.Server.Players.Remove(byPlayer); //List is a array copy
193+
194+ var serverMain = ServerAPI.World as ServerMain;
192195 var servPlayer = byPlayer as ServerPlayer;
196+ var pdm = ServerAPI.PlayerData as PlayerDataManager;
197+ var swpd = servPlayer.WorldData as ServerWorldPlayerData;
198+ //swpd.Init(serverMain);
199+ pdm.PlayerDataByUid.Remove(byPlayer.PlayerUID);
200+ pdm.WorldDataByUID.Remove(byPlayer.PlayerUID);
193201
202+ //pdm.GetOrCreateServerPlayerData(byPlayer.PlayerUID);
194203 }
195204 }
196205
@@ -214,7 +223,7 @@ namespace AdminToolkit
214223 Logger.Notification("Created (empty) Spawnpoints Data");
215224 }
216225
217-
226+ ChangeDefaultRoleSpawnPoint( );
218227 }
219228
220229 private void PersistSpawnpoints( )
@@ -227,12 +236,12 @@ namespace AdminToolkit
227236
228237 }
229238
230- private void PlayerJoins( IServerPlayer byPlayer)
239+ private void RotateSpawnPoint( IServerPlayer byPlayer)
231240 {
232241 if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
233242
234- var swpd = byPlayer.WorldData as ServerWorldPlayerData;
235- if (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition))
243+ var swpd = byPlayer.WorldData as ServerWorldPlayerData;
244+ if (swpd != null && (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition)))
236245 {
237246 RandomizeSpawnpoint(byPlayer);
238247 }
@@ -243,27 +252,43 @@ namespace AdminToolkit
243252 {
244253 if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
245254
246- var swpd = byPlayer.WorldData as ServerWorldPlayerData;
247- if (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition))
248- {
255+ var swpd = byPlayer.WorldData as ServerWorldPlayerData;
256+ if (swpd != null && (swpd.SpawnPosition == null || KnownSpawn(swpd.SpawnPosition))) {
249257 RandomizeSpawnpoint(byPlayer);
250258 }
251259 }
252260 }
253261
262+ private void ChangeDefaultRoleSpawnPoint( )
263+ {
264+ if (this.CachedConfiguration.VariableSpawnpoints && this.Spawnpoints.Count > 0) {
265+
266+ var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count)];
267+
268+ string roleCode = ServerAPI.Server.Config.DefaultRoleCode;
269+ var serverPlayerRole = ServerAPI.Server.Config.Roles.Single(pr => pr.Code == roleCode) as PlayerRole;
270+
271+ #if DEBUG
272+ Logger.VerboseDebug($"Changing ({serverPlayerRole.Name}) to spawn '{randSp.Name}' @ {randSp.Location}");
273+ #endif
274+ serverPlayerRole.DefaultSpawn = randSp.Location;
275+ }
276+
277+ }
278+
254279 #endregion
255280
256281
257- private void RandomizeSpawnpoint(IServerPlayer byPlayer)
282+ internal void RandomizeSpawnpoint(IServerPlayer byPlayer)
258283 {
259- var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count - 1)];
284+ var randSp = this.Spawnpoints[random.Next(0, Spawnpoints.Count)];
260285 byPlayer.SetSpawnPosition(randSp.Location);
261286 #if DEBUG
262287 Logger.VerboseDebug($"Changed spawn Pos: '{randSp.Name}' @ {randSp.Location} for {byPlayer.PlayerName}");
263288 #endif
264289 }
265290
266- private bool KnownSpawn(PlayerSpawnPos aSpawn)
291+ internal bool KnownSpawn(PlayerSpawnPos aSpawn)
267292 {
268293 if (this.Spawnpoints.Count > 0) {
269294 return this.Spawnpoints.Any(vsps => vsps.Location.x == aSpawn.x
@@ -274,7 +299,7 @@ namespace AdminToolkit
274299 return false;
275300 }
276301
277- private Vec3i RelativeToAbsolute(Vec3i location)
302+ internal Vec3i RelativeToAbsolute(Vec3i location)
278303 {
279304 var start = ServerAPI.World.DefaultSpawnPosition.AsBlockPos;
280305 return new Vec3i( location.X + start.X, location.Y, location.Z + start.Z);
@@ -286,7 +311,7 @@ namespace AdminToolkit
286311 return new Vec3i(start.X - location.X, location.Y, start.Z - location.Z);
287312 }
288313
289- private string PrettyFormat(PlayerSpawnPos spawnPos)
314+ internal string PrettyFormat(PlayerSpawnPos spawnPos)
290315 {
291316 var start = ServerAPI.World.DefaultSpawnPosition.AsBlockPos;
292317
--- a/AdminToolkit/readme.md
+++ b/AdminToolkit/readme.md
@@ -106,7 +106,7 @@ edit file ('/ModConfig/admintoolkit.json' ) :
106106
107107
108108
109-VAIRABLE SPAWNS
109+VARIABLE SPAWNS
110110 ---------------
111111
112112 Lets admins define and have players spawn from a list of pre-defined coordinates.