Fix /fly not respecting -fly zone motds

This commit is contained in:
UnknownShadow200 2018-12-24 23:24:25 +11:00
parent 0bdfd347ac
commit 0265c9b910
6 changed files with 37 additions and 25 deletions

View File

@ -19,6 +19,7 @@ using System;
using MCGalaxy.Commands.Building;
using MCGalaxy.Commands.CPE;
using MCGalaxy.Commands.World;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
@ -144,7 +145,7 @@ namespace MCGalaxy.Commands.Moderation {
void OnChangedZone(Zone zone) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.ZoneIn == zone) pl.OnChangedZone();
if (pl.ZoneIn == zone) OnChangedZoneEvent.Call(pl);
}
}

View File

@ -37,9 +37,10 @@ namespace MCGalaxy.Core {
OnChatEvent.Register(ChatHandler.HandleOnChat, Priority.Critical);
OnPlayerStartConnectingEvent.Register(ConnectingHandler.HandleConnecting, Priority.Critical);
OnSentMapEvent.Register(MiscHandlers.HandleOnMapSent, Priority.Critical);
OnSentMapEvent.Register(MiscHandlers.HandleSentMap, Priority.Critical);
OnPlayerMoveEvent.Register(MiscHandlers.HandlePlayerMove, Priority.Critical);
OnPlayerClickEvent.Register(MiscHandlers.HandlePlayerClick, Priority.Critical);
OnChangedZoneEvent.Register(MiscHandlers.HandleChangedZone, Priority.Critical);
OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction, Priority.Critical);
OnModActionEvent.Register(ModActionHandler.HandleModAction, Priority.Critical);
@ -53,9 +54,10 @@ namespace MCGalaxy.Core {
OnChatEvent.Unregister(ChatHandler.HandleOnChat);
OnPlayerStartConnectingEvent.Unregister(ConnectingHandler.HandleConnecting);
OnSentMapEvent.Unregister(MiscHandlers.HandleOnMapSent);
OnSentMapEvent.Unregister(MiscHandlers.HandleSentMap);
OnPlayerMoveEvent.Unregister(MiscHandlers.HandlePlayerMove);
OnPlayerClickEvent.Unregister(MiscHandlers.HandlePlayerClick);
OnChangedZoneEvent.Unregister(MiscHandlers.HandleChangedZone);
OnEcoTransactionEvent.Unregister(EcoHandlers.HandleEcoTransaction);
OnModActionEvent.Unregister(ModActionHandler.HandleModAction);

View File

@ -40,20 +40,15 @@ namespace MCGalaxy.Core {
p.cancelmove = true;
}
internal static void HandleOnMapSent(Player p, Level prevLevel, Level level) {
internal static void HandleSentMap(Player p, Level prevLevel, Level level) {
p.AFKCooldown = DateTime.UtcNow.AddSeconds(2);
p.prevMsg = "";
p.showMBs = false;
p.showPortals = false;
p.SetModel(p.Model, level); // in case had been using a level-only custom block for their model
if (p.isFlying && !Hacks.CanUseFly(p, level)) {
p.Message("You cannot use %T/Fly %Son this map.");
p.isFlying = false;
}
p.ZoneIn = null;
p.OnChangedZone(); // TODO: CurrentEnv here??
OnChangedZoneEvent.Call(p);
p.SendCurrentTextures();
p.SendCurrentBlockPermissions();
@ -71,11 +66,20 @@ namespace MCGalaxy.Core {
p.Message("BlockDB is disabled here, %Wyou will not be able to /undo or /redo");
}
}
internal static void HandleChangedZone(Player p) {
if (p.Supports(CpeExt.InstantMOTD)) p.SendMapMotd();
p.SendCurrentEnv();
if (p.isFlying && !Hacks.CanUseFly(p, p.level)) {
p.Message("You cannot use %T/Fly %Son this map.");
p.isFlying = false;
}
}
internal static void HandlePlayerClick(Player p, MouseButton button, MouseAction action, ushort yaw, ushort pitch,
byte entity, ushort x, ushort y, ushort z, TargetBlockFace face) {
if (action != MouseAction.Pressed) return;
if (action != MouseAction.Pressed) return;
if (entity != Entities.SelfID && ClickOnBot(p, entity)) return;
if (p.level.Config.Deletable || !p.level.IsValidPos(x, y, z)) return;

View File

@ -210,7 +210,7 @@ namespace MCGalaxy.Events.PlayerEvents {
}
public delegate void OnSendingMotd(Player p, ref string motd);
/// <summary> Called when MOTD is being send to the user. </summary>
/// <summary> Called when MOTD is being sent to a player. </summary>
public sealed class OnSendingMotdEvent : IEvent<OnSendingMotd> {
public static void Call(Player p, ref string motd) {
@ -221,12 +221,10 @@ namespace MCGalaxy.Events.PlayerEvents {
catch (Exception ex) { LogHandlerException(ex, items[i]); }
}
}
}
}
public delegate void OnPlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning);
/// <summary> Called when a player is being initially spawned in a map,
/// or is respawning (e.g. died from a killer block). </summary>
/// <summary> Called when a player is initially spawning in a map, or is respawning (e.g. killed by deadly lava). </summary>
public sealed class OnPlayerSpawningEvent : IEvent<OnPlayerSpawning> {
public static void Call(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) {
@ -241,4 +239,15 @@ namespace MCGalaxy.Events.PlayerEvents {
}
}
}
public delegate void OnChangedZone(Player p);
/// <summary> Called when player has moved into a different zone. </summary>
/// <remarks> The 'zone' the player moves into may be null. </remarks>
public sealed class OnChangedZoneEvent : IEvent<OnChangedZone> {
public static void Call(Player p) {
if (handlers.Count == 0) return;
CallCommon(pl => pl(p));
}
}
}

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MCGalaxy.Config;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Maths;
using MCGalaxy.Network;
@ -141,7 +142,7 @@ namespace MCGalaxy {
foreach (Player pl in players) {
if (pl.ZoneIn != this) continue;
pl.ZoneIn = null;
pl.OnChangedZone();
OnChangedZoneEvent.Call(pl);
}
}

View File

@ -356,17 +356,12 @@ namespace MCGalaxy {
if (!zones[i].Contains(P.X, P.Y, P.Z)) continue;
ZoneIn = zones[i];
OnChangedZone();
OnChangedZoneEvent.Call(this);
return;
}
ZoneIn = null;
if (zone != null) OnChangedZone();
}
public void OnChangedZone() {
if (Supports(CpeExt.InstantMOTD)) SendMapMotd();
SendCurrentEnv();
if (zone != null) OnChangedZoneEvent.Call(this);
}
int CurrentEnvProp(EnvProp i, Zone zone) {