mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Add some events for tab list entries. (WIP broken)
This commit is contained in:
parent
9c66b78ff3
commit
34d0f62f07
@ -17,6 +17,7 @@
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Games;
|
||||
using MCGalaxy.Events.EntityEvents;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
namespace MCGalaxy {
|
||||
@ -37,13 +38,11 @@ namespace MCGalaxy {
|
||||
dst.Send(Packet.ExtAddPlayerName(id, p.truename, name, group, grpPerm, dst.hasCP437));
|
||||
}
|
||||
|
||||
/// <summary> Gets the name and the group name for the given player. </summary>
|
||||
public static void GetEntry(Player p, Player dst, out string name, out string group) {
|
||||
static void GetEntry(Player p, Player dst, out string name, out string group) {
|
||||
string col = Entities.GetSupportedCol(dst, p.color);
|
||||
group = ServerConfig.TablistGlobal ? "On " + p.level.name : "&fPlayers";
|
||||
name = col + p.truename;
|
||||
IGame game = p.level.CurrentGame();
|
||||
if (game != null) game.GetTabName(p, dst, ref name, ref group);
|
||||
OnTabListEntryAddedEvent.Call(p, ref name, ref group, dst);
|
||||
|
||||
if (p.hidden && p.IsAfk) { name += " &f(Hid, &7AFK)"; return; }
|
||||
if (p.hidden) name += " &f(Hid)";
|
||||
@ -53,7 +52,10 @@ namespace MCGalaxy {
|
||||
/// <summary> Adds the given bot to that player's tab list (if their client support it). </summary>
|
||||
public static void Add(Player dst, PlayerBot b) {
|
||||
if (!dst.hasExtList) return;
|
||||
dst.Send(Packet.ExtAddPlayerName(b.id, b.SkinName, b.color + b.name, "Bots", 0, dst.hasCP437));
|
||||
|
||||
string name = b.color + b.name, group = "Bots";
|
||||
OnTabListEntryAddedEvent.Call(b, ref name, ref group, dst);
|
||||
dst.Send(Packet.ExtAddPlayerName(b.id, b.SkinName, name, group, 0, dst.hasCP437));
|
||||
}
|
||||
|
||||
/// <summary> Removes the given player from player's tab list (if their client supports it). </summary>
|
||||
@ -62,6 +64,7 @@ namespace MCGalaxy {
|
||||
dst.Send(Packet.ExtRemovePlayerName(id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Updates the tab list entry for this player to all other players
|
||||
/// (whose clients support it) who can see the player in the tab list. </summary>
|
||||
internal static void Update(Player p, bool self) {
|
51
MCGalaxy/Events/EntityEvents.cs
Normal file
51
MCGalaxy/Events/EntityEvents.cs
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MCGalaxy.Events.EntityEvents {
|
||||
|
||||
public delegate void OnTabListEntryAdded(Entity entity, ref string tabName, ref string tabGroup, Player dst);
|
||||
/// <summary> Called when a tab list entry is being sent to a user. </summary>
|
||||
public sealed class OnTabListEntryAddedEvent : IEvent<OnTabListEntryAdded> {
|
||||
|
||||
public static void Call(Entity entity, ref string tabName, ref string tabGroup, Player dst) {
|
||||
IEvent<OnTabListEntryAdded>[] items = handlers.Items;
|
||||
// Can't use CallCommon because we need to pass arguments by ref
|
||||
for (int i = 0; i < items.Length; i++) {
|
||||
IEvent<OnTabListEntryAdded> handler = items[i];
|
||||
|
||||
try {
|
||||
handler.method(entity, ref tabName, ref tabGroup, dst);
|
||||
} catch (Exception ex) {
|
||||
LogHandlerException(ex, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void OnTabListEntryRemoved(Entity entity, Player dst);
|
||||
/// <summary> Called when a tab list entry is being removed from a user. </summary>
|
||||
public sealed class OnTabListEntryRemovedEvent : IEvent<OnTabListEntryRemoved> {
|
||||
|
||||
public static void Call(Entity entity, Player dst) {
|
||||
if (handlers.Count == 0) return;
|
||||
CallCommon(pl => pl(entity, dst));
|
||||
}
|
||||
}
|
||||
}
|
@ -479,7 +479,9 @@
|
||||
<Compile Include="Entity\Entities.cs" />
|
||||
<Compile Include="Entity\Entity.cs" />
|
||||
<Compile Include="Entity\Structs.cs" />
|
||||
<Compile Include="Entity\TabList.cs" />
|
||||
<Compile Include="Events\EconomyEvents.cs" />
|
||||
<Compile Include="Events\EntityEvents.cs" />
|
||||
<Compile Include="Events\GroupEvents.cs" />
|
||||
<Compile Include="Events\IPluginEvent.cs" />
|
||||
<Compile Include="Events\LevelEvents.cs" />
|
||||
@ -597,7 +599,6 @@
|
||||
<Compile Include="Player\PlayerInfo.cs" />
|
||||
<Compile Include="Player\PlayerPhysics.cs" />
|
||||
<Compile Include="Player\SpamChecker.cs" />
|
||||
<Compile Include="Player\TabList.cs" />
|
||||
<Compile Include="Database\Undo\UndoFormatCBin.cs" />
|
||||
<Compile Include="Player\Warp.cs" />
|
||||
<Compile Include="Database\Undo\UndoFormat.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user