Skip to content

Commit

Permalink
Fix colors sometimes being wrong in TNT wars
Browse files Browse the repository at this point in the history
Could be wrong when TNT wars map is set to spawn map, player's colour is changed through /rank or /color, settings are saved in GUI, etc
  • Loading branch information
UnknownShadow200 committed Jun 6, 2020
1 parent d7313bf commit bc91204
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 9 additions & 1 deletion MCGalaxy/Games/TntWars/TWGame.Plugin.cs
Expand Up @@ -41,6 +41,7 @@ public sealed partial class TWGame : RoundsGame {
OnSentMapEvent.Register(HandleSentMap, Priority.High);
OnJoinedLevelEvent.Register(HandleJoinedLevel, Priority.High);
OnTabListEntryAddedEvent.Register(HandleTabListEntryAdded, Priority.High);
OnSettingColorEvent.Register(HandleSettingColor, Priority.High);

base.HookEventHandlers();
}
Expand All @@ -51,6 +52,7 @@ public sealed partial class TWGame : RoundsGame {
OnSentMapEvent.Unregister(HandleSentMap);
OnJoinedLevelEvent.Unregister(HandleJoinedLevel);
OnTabListEntryAddedEvent.Unregister(HandleTabListEntryAdded);
OnSettingColorEvent.Unregister(HandleSettingColor);

base.UnhookEventHandlers();
}
Expand Down Expand Up @@ -101,7 +103,13 @@ public sealed partial class TWGame : RoundsGame {
tabGroup = "&7Spectators";
}
}


void HandleSettingColor(Player p, ref string color) {
if (p.level != Map) return;
TWTeam team = TeamOf(p);
if (team != null) color = team.Color;
}

void HandleSentMap(Player p, Level prevLevel, Level level) {
if (level != Map) return;
MessageMapInfo(p);
Expand Down
7 changes: 2 additions & 5 deletions MCGalaxy/Games/TntWars/TWGame.cs
Expand Up @@ -48,7 +48,6 @@ internal sealed class TWData {
public float ScoreMultiplier = 1f;
public int LastKillStreakAnnounced;
public Player HarmedBy; // For Assists
public string OrigCol;

public void Reset(TWDifficulty diff) {
bool easyish = diff == TWDifficulty.Easy || diff == TWDifficulty.Normal;
Expand Down Expand Up @@ -94,8 +93,6 @@ sealed class TWTeam {
data = new TWData();

// TODO: Is this even thread-safe
data.OrigCol = p.color;

p.Extras[twExtrasKey] = data;
return data;
}
Expand Down Expand Up @@ -181,7 +178,7 @@ sealed class TWTeam {
// TODO: p.Socket.Disconnected check should be elsewhere
if (data == null || p.Socket.Disconnected) return;

p.color = data.OrigCol;
p.UpdateColor(PlayerInfo.DefaultColor(p));
p.SetPrefix();
TabList.Update(p, true);
}
Expand All @@ -190,7 +187,7 @@ sealed class TWTeam {
team.Members.Add(p);
Map.Message(p.ColoredName + " %Sjoined the " + team.ColoredName + " %Steam");

p.color = team.Color;
p.UpdateColor(team.Color);
p.SetPrefix();

p.Message("You are now on the " + team.ColoredName + " team!");
Expand Down

0 comments on commit bc91204

Please sign in to comment.