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.Building;
using MCGalaxy.Commands.CPE; using MCGalaxy.Commands.CPE;
using MCGalaxy.Commands.World; using MCGalaxy.Commands.World;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Maths; using MCGalaxy.Maths;
using BlockID = System.UInt16; using BlockID = System.UInt16;
@ -144,7 +145,7 @@ namespace MCGalaxy.Commands.Moderation {
void OnChangedZone(Zone zone) { void OnChangedZone(Zone zone) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { 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); OnChatEvent.Register(ChatHandler.HandleOnChat, Priority.Critical);
OnPlayerStartConnectingEvent.Register(ConnectingHandler.HandleConnecting, 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); OnPlayerMoveEvent.Register(MiscHandlers.HandlePlayerMove, Priority.Critical);
OnPlayerClickEvent.Register(MiscHandlers.HandlePlayerClick, Priority.Critical); OnPlayerClickEvent.Register(MiscHandlers.HandlePlayerClick, Priority.Critical);
OnChangedZoneEvent.Register(MiscHandlers.HandleChangedZone, Priority.Critical);
OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction, Priority.Critical); OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction, Priority.Critical);
OnModActionEvent.Register(ModActionHandler.HandleModAction, Priority.Critical); OnModActionEvent.Register(ModActionHandler.HandleModAction, Priority.Critical);
@ -53,9 +54,10 @@ namespace MCGalaxy.Core {
OnChatEvent.Unregister(ChatHandler.HandleOnChat); OnChatEvent.Unregister(ChatHandler.HandleOnChat);
OnPlayerStartConnectingEvent.Unregister(ConnectingHandler.HandleConnecting); OnPlayerStartConnectingEvent.Unregister(ConnectingHandler.HandleConnecting);
OnSentMapEvent.Unregister(MiscHandlers.HandleOnMapSent); OnSentMapEvent.Unregister(MiscHandlers.HandleSentMap);
OnPlayerMoveEvent.Unregister(MiscHandlers.HandlePlayerMove); OnPlayerMoveEvent.Unregister(MiscHandlers.HandlePlayerMove);
OnPlayerClickEvent.Unregister(MiscHandlers.HandlePlayerClick); OnPlayerClickEvent.Unregister(MiscHandlers.HandlePlayerClick);
OnChangedZoneEvent.Unregister(MiscHandlers.HandleChangedZone);
OnEcoTransactionEvent.Unregister(EcoHandlers.HandleEcoTransaction); OnEcoTransactionEvent.Unregister(EcoHandlers.HandleEcoTransaction);
OnModActionEvent.Unregister(ModActionHandler.HandleModAction); OnModActionEvent.Unregister(ModActionHandler.HandleModAction);

View File

@ -40,20 +40,15 @@ namespace MCGalaxy.Core {
p.cancelmove = true; 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.AFKCooldown = DateTime.UtcNow.AddSeconds(2);
p.prevMsg = ""; p.prevMsg = "";
p.showMBs = false; p.showMBs = false;
p.showPortals = false; p.showPortals = false;
p.SetModel(p.Model, level); // in case had been using a level-only custom block for their model 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.ZoneIn = null;
p.OnChangedZone(); // TODO: CurrentEnv here?? OnChangedZoneEvent.Call(p);
p.SendCurrentTextures(); p.SendCurrentTextures();
p.SendCurrentBlockPermissions(); p.SendCurrentBlockPermissions();
@ -71,11 +66,20 @@ namespace MCGalaxy.Core {
p.Message("BlockDB is disabled here, %Wyou will not be able to /undo or /redo"); 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, internal static void HandlePlayerClick(Player p, MouseButton button, MouseAction action, ushort yaw, ushort pitch,
byte entity, ushort x, ushort y, ushort z, TargetBlockFace face) { 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 (entity != Entities.SelfID && ClickOnBot(p, entity)) return;
if (p.level.Config.Deletable || !p.level.IsValidPos(x, y, z)) 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); 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 sealed class OnSendingMotdEvent : IEvent<OnSendingMotd> {
public static void Call(Player p, ref string motd) { public static void Call(Player p, ref string motd) {
@ -221,12 +221,10 @@ namespace MCGalaxy.Events.PlayerEvents {
catch (Exception ex) { LogHandlerException(ex, items[i]); } catch (Exception ex) { LogHandlerException(ex, items[i]); }
} }
} }
} }
public delegate void OnPlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning); 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, /// <summary> Called when a player is initially spawning in a map, or is respawning (e.g. killed by deadly lava). </summary>
/// or is respawning (e.g. died from a killer block). </summary>
public sealed class OnPlayerSpawningEvent : IEvent<OnPlayerSpawning> { public sealed class OnPlayerSpawningEvent : IEvent<OnPlayerSpawning> {
public static void Call(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) { 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;
using System.Collections.Generic; using System.Collections.Generic;
using MCGalaxy.Config; using MCGalaxy.Config;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Maths; using MCGalaxy.Maths;
using MCGalaxy.Network; using MCGalaxy.Network;
@ -141,7 +142,7 @@ namespace MCGalaxy {
foreach (Player pl in players) { foreach (Player pl in players) {
if (pl.ZoneIn != this) continue; if (pl.ZoneIn != this) continue;
pl.ZoneIn = null; 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; if (!zones[i].Contains(P.X, P.Y, P.Z)) continue;
ZoneIn = zones[i]; ZoneIn = zones[i];
OnChangedZone(); OnChangedZoneEvent.Call(this);
return; return;
} }
ZoneIn = null; ZoneIn = null;
if (zone != null) OnChangedZone(); if (zone != null) OnChangedZoneEvent.Call(this);
}
public void OnChangedZone() {
if (Supports(CpeExt.InstantMOTD)) SendMapMotd();
SendCurrentEnv();
} }
int CurrentEnvProp(EnvProp i, Zone zone) { int CurrentEnvProp(EnvProp i, Zone zone) {