mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-03 02:21:53 -04:00
Add OnGettingCanSee event too
This commit is contained in:
parent
3be4601ee5
commit
3e8764d141
@ -57,7 +57,7 @@ namespace MCGalaxy {
|
|||||||
Rot = rot;
|
Rot = rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Whether this player can see the given entity as an entity in the map. </summary>
|
/// <summary> Whether this player can see the given entity as an entity in the level. </summary>
|
||||||
public abstract bool CanSeeEntity(Entity other);
|
public abstract bool CanSeeEntity(Entity other);
|
||||||
public abstract byte EntityID { get; }
|
public abstract byte EntityID { get; }
|
||||||
/// <summary> The level this entity is currently on. </summary>
|
/// <summary> The level this entity is currently on. </summary>
|
||||||
|
@ -97,7 +97,7 @@ namespace MCGalaxy.Events.EntityEvents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnGettingCanSeeEntity(Player p, ref bool canSee, Entity target);
|
public delegate void OnGettingCanSeeEntity(Player p, ref bool canSee, Entity target);
|
||||||
/// <summary> Called when code is checking if this player can see the given entity. </summary>
|
/// <summary> Called when checking if this player can see the given entity as an entity in the level. </summary>
|
||||||
/// <remarks> e.g. You can use this event to make a player invisible during a game. </remarks>
|
/// <remarks> e.g. You can use this event to make a player invisible during a game. </remarks>
|
||||||
public sealed class OnGettingCanSeeEntityEvent : IEvent<OnGettingCanSeeEntity> {
|
public sealed class OnGettingCanSeeEntityEvent : IEvent<OnGettingCanSeeEntity> {
|
||||||
|
|
||||||
|
@ -297,4 +297,18 @@ namespace MCGalaxy.Events.PlayerEvents {
|
|||||||
CallCommon(pl => pl(p));
|
CallCommon(pl => pl(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public delegate void OnGettingCanSee(Player p, LevelPermission plRank, ref bool canSee, Player target);
|
||||||
|
/// <summary> Called when code is checking if this player can see the given player. </summary>
|
||||||
|
public sealed class OnGettingCanSeeEvent : IEvent<OnGettingCanSee> {
|
||||||
|
|
||||||
|
public static void Call(Player p, LevelPermission plRank, ref bool canSee, Player target) {
|
||||||
|
IEvent<OnGettingCanSee>[] items = handlers.Items;
|
||||||
|
// Can't use CallCommon because we need to pass arguments by ref
|
||||||
|
for (int i = 0; i < items.Length; i++) {
|
||||||
|
try { items[i].method(p, plRank, ref canSee, target); }
|
||||||
|
catch (Exception ex) { LogHandlerException(ex, items[i]); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,15 +76,18 @@ namespace MCGalaxy {
|
|||||||
public bool CanSee(Player target) { return CanSee(target, Rank); }
|
public bool CanSee(Player target) { return CanSee(target, Rank); }
|
||||||
/// <summary> Whether this player can see the given player, as if they were the given rank. </summary>
|
/// <summary> Whether this player can see the given player, as if they were the given rank. </summary>
|
||||||
public bool CanSee(Player target, LevelPermission plRank) {
|
public bool CanSee(Player target, LevelPermission plRank) {
|
||||||
return target == this || target == null || !target.hidden || plRank >= target.hideRank;
|
if (target == this || target == null) return true;
|
||||||
|
|
||||||
|
bool canSee = !target.hidden || plRank >= target.hideRank;
|
||||||
|
OnGettingCanSeeEvent.Call(this, plRank, ref canSee, target);
|
||||||
|
return canSee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanSeeEntity(Entity other) {
|
public override bool CanSeeEntity(Entity target) {
|
||||||
Player target = other as Player;
|
if (target == this) return true; // always see self
|
||||||
if (other == this) return true; // always see self
|
|
||||||
|
|
||||||
bool canSee = CanSee(target, Rank);
|
bool canSee = CanSee(target as Player, Rank);
|
||||||
OnGettingCanSeeEntityEvent.Call(this, ref canSee, other);
|
OnGettingCanSeeEntityEvent.Call(this, ref canSee, target);
|
||||||
return canSee;
|
return canSee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ namespace MCGalaxy {
|
|||||||
/// <summary> Message to display once plugin is loaded. </summary>
|
/// <summary> Message to display once plugin is loaded. </summary>
|
||||||
public virtual string welcome { get { return ""; } }
|
public virtual string welcome { get { return ""; } }
|
||||||
/// <summary> The creator/author of this plugin. (Your name) </summary>
|
/// <summary> The creator/author of this plugin. (Your name) </summary>
|
||||||
public abstract string creator { get; }
|
public virtual string creator { get { return ""; } }
|
||||||
/// <summary> Whether or not to auto load this plugin on server startup. </summary>
|
/// <summary> Whether or not to auto load this plugin on server startup. </summary>
|
||||||
public virtual bool LoadAtStartup { get { return true; } }
|
public virtual bool LoadAtStartup { get { return true; } }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user