mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Move motd event into GetMotd
This allows plugins to change MOTD for /fly,/ascend etc checks
This commit is contained in:
parent
05a3de6fbe
commit
0efe8e9d4b
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
if (p.Game.Referee) {
|
||||
p.Send(Packet.HackControl(true, true, true, true, true, -1));
|
||||
} else {
|
||||
p.Send(Hacks.MakeHackControl(p, p.level.GetMotd(p)));
|
||||
p.Send(Hacks.MakeHackControl(p, p.GetMotd()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.World {
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (!Hacks.CanUseRespawn(p, p.level)) {
|
||||
if (!Hacks.CanUseRespawn(p)) {
|
||||
p.Message("You cannot use %T/Spawn %Son this map.");
|
||||
p.isFlying = false; return;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (!Hacks.CanUseHacks(p, p.level)) {
|
||||
if (!Hacks.CanUseHacks(p)) {
|
||||
p.Message("You cannot use %T/Ascend %Son this map."); return;
|
||||
}
|
||||
int x = p.Pos.BlockX, y = p.Pos.BlockY, z = p.Pos.BlockZ;
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (!Hacks.CanUseHacks(p, p.level)) {
|
||||
if (!Hacks.CanUseHacks(p)) {
|
||||
p.Message("You cannot use %T/Descend %Son this map."); return;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
||||
public override bool SuperUseable { get { return false; } }
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (!Hacks.CanUseFly(p, p.level)) {
|
||||
if (!Hacks.CanUseFly(p)) {
|
||||
p.Message("You cannot use %T/Fly %Son this map.");
|
||||
p.isFlying = false; return;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ namespace MCGalaxy.Core {
|
||||
if (p.Supports(CpeExt.InstantMOTD)) p.SendMapMotd();
|
||||
p.SendCurrentEnv();
|
||||
|
||||
if (p.isFlying && !Hacks.CanUseFly(p, p.level)) {
|
||||
if (p.isFlying && !Hacks.CanUseFly(p)) {
|
||||
p.Message("You cannot use %T/Fly %Son this map.");
|
||||
p.isFlying = false;
|
||||
}
|
||||
|
@ -209,12 +209,13 @@ namespace MCGalaxy.Events.PlayerEvents {
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void OnSendingMotd(Player p, ref string motd);
|
||||
/// <summary> Called when MOTD is being sent to a player. </summary>
|
||||
public sealed class OnSendingMotdEvent : IEvent<OnSendingMotd> {
|
||||
public delegate void OnGettingMotd(Player p, ref string motd);
|
||||
/// <summary> Called when MOTD is being retrieved for a player. </summary>
|
||||
/// <remarks> e.g. You can use this event to make one player always have +hax motd. </remarks>
|
||||
public sealed class OnGettingMotdEvent : IEvent<OnGettingMotd> {
|
||||
|
||||
public static void Call(Player p, ref string motd) {
|
||||
IEvent<OnSendingMotd>[] items = handlers.Items;
|
||||
IEvent<OnGettingMotd>[] 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, ref motd); }
|
||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Games {
|
||||
static TimeSpan interval = TimeSpan.FromSeconds(5);
|
||||
|
||||
public static bool DetectNoclip(Player p, Position newPos) {
|
||||
if (p.Game.Referee || Hacks.CanUseNoclip(p, p.level)) return false;
|
||||
if (p.Game.Referee || Hacks.CanUseNoclip(p)) return false;
|
||||
if (!p.IsLikelyInsideBlock() || p.Game.NoclipLog.AddSpamEntry(5, interval)) return false;
|
||||
|
||||
Warn(ref p.Game.LastNoclipWarn, p, "noclip");
|
||||
@ -37,7 +37,7 @@ namespace MCGalaxy.Games {
|
||||
}
|
||||
|
||||
public static bool DetectSpeedhack(Player p, Position newPos, float moveDist) {
|
||||
if (p.Game.Referee || Hacks.CanUseSpeed(p, p.level)) return false;
|
||||
if (p.Game.Referee || Hacks.CanUseSpeed(p)) return false;
|
||||
int dx = Math.Abs(p.Pos.X - newPos.X), dz = Math.Abs(p.Pos.Z - newPos.Z);
|
||||
|
||||
int maxMove = (int)(moveDist * 32);
|
||||
|
@ -24,29 +24,29 @@ namespace MCGalaxy {
|
||||
public static class Hacks {
|
||||
|
||||
/// <summary> Returns whether the player is currently able to use any hacks at all. </summary>
|
||||
public static bool CanUseHacks(Player p, Level lvl) {
|
||||
byte[] packet = MakeHackControl(p, lvl.GetMotd(p));
|
||||
public static bool CanUseHacks(Player p) {
|
||||
byte[] packet = MakeHackControl(p, p.GetMotd());
|
||||
return packet[1] != 0 && packet[2] != 0 && packet[3] != 0 && packet[4] != 0 && packet[5] != 0;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the player is currently able to fly. </summary>
|
||||
public static bool CanUseFly(Player p, Level lvl) {
|
||||
return MakeHackControl(p, lvl.GetMotd(p))[1] != 0;
|
||||
public static bool CanUseFly(Player p) {
|
||||
return MakeHackControl(p, p.GetMotd())[1] != 0;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the player is currently able to use noclip. </summary>
|
||||
public static bool CanUseNoclip(Player p, Level lvl) {
|
||||
return MakeHackControl(p, lvl.GetMotd(p))[2] != 0;
|
||||
public static bool CanUseNoclip(Player p) {
|
||||
return MakeHackControl(p, p.GetMotd())[2] != 0;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the player is currently able to move at faster speeds. </summary>
|
||||
public static bool CanUseSpeed(Player p, Level lvl) {
|
||||
return MakeHackControl(p, lvl.GetMotd(p))[3] != 0;
|
||||
public static bool CanUseSpeed(Player p) {
|
||||
return MakeHackControl(p, p.GetMotd())[3] != 0;
|
||||
}
|
||||
|
||||
/// <summary> Returns whether the player is currently able to respawn. </summary>
|
||||
public static bool CanUseRespawn(Player p, Level lvl) {
|
||||
return MakeHackControl(p, lvl.GetMotd(p))[4] != 0;
|
||||
public static bool CanUseRespawn(Player p) {
|
||||
return MakeHackControl(p, p.GetMotd())[4] != 0;
|
||||
}
|
||||
|
||||
/// <summary> Parses the MOTD flags and returns resulting HackControl packet. </summary>
|
||||
|
@ -24,6 +24,7 @@ using MCGalaxy.Bots;
|
||||
using MCGalaxy.Commands;
|
||||
using MCGalaxy.DB;
|
||||
using MCGalaxy.Events.LevelEvents;
|
||||
using MCGalaxy.Events.PlayerEvents;
|
||||
using MCGalaxy.Games;
|
||||
using MCGalaxy.Generator;
|
||||
using MCGalaxy.Levels.IO;
|
||||
@ -96,15 +97,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
public string GetMotd(Player p) {
|
||||
Zone zone = p.ZoneIn;
|
||||
string zoneMOTD = zone == null ? null : zone.Config.MOTD;
|
||||
if (zoneMOTD != null && zoneMOTD != "ignore") return zoneMOTD;
|
||||
|
||||
if (Config.MOTD != "ignore") return Config.MOTD;
|
||||
return String.IsNullOrEmpty(p.group.MOTD) ? Server.Config.MOTD : p.group.MOTD;
|
||||
}
|
||||
|
||||
public Zone FindZoneExact(string name) {
|
||||
Zone[] zones = Zones.Items;
|
||||
foreach (Zone zone in zones) {
|
||||
|
@ -150,10 +150,9 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public void SendMapMotd() {
|
||||
string motd = level.GetMotd(this);
|
||||
string motd = GetMotd();
|
||||
motd = Chat.Format(motd, this);
|
||||
|
||||
OnSendingMotdEvent.Call(this, ref motd);
|
||||
byte[] packet = Packet.Motd(this, motd);
|
||||
Send(packet);
|
||||
|
||||
|
@ -106,6 +106,18 @@ namespace MCGalaxy {
|
||||
return BlockBindings[RawHeldBlock];
|
||||
}
|
||||
|
||||
public string GetMotd() {
|
||||
Zone zone = ZoneIn;
|
||||
string motd = zone == null ? "ignore" : zone.Config.MOTD;
|
||||
|
||||
// fallback to level MOTD, then rank MOTD, then server MOTD
|
||||
if (motd == "ignore") motd = level.Config.MOTD;
|
||||
if (motd == "ignore") motd = String.IsNullOrEmpty(group.MOTD) ? Server.Config.MOTD : group.MOTD;
|
||||
|
||||
OnGettingMotdEvent.Call(this, ref motd);
|
||||
return motd;
|
||||
}
|
||||
|
||||
public void SetPrefix() {
|
||||
prefix = Game.Referee ? "&2[Ref] " : "";
|
||||
if (GroupPrefix.Length > 0) { prefix += GroupPrefix + color; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user