diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index e8d03e730..a39f7e2d7 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -185,7 +185,7 @@ namespace MCGalaxy { if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue; pl.Send(def.MakeDefinePacket(pl)); - if (pl.HasCpeExt(CpeExt.BlockPermissions)) + if (pl.Supports(CpeExt.BlockPermissions)) pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete)); } Save(global, level); @@ -220,7 +220,7 @@ namespace MCGalaxy { if (!global && pl.level != level) continue; if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue; - if (!pl.HasCpeExt(CpeExt.InventoryOrder)) continue; + if (!pl.Supports(CpeExt.InventoryOrder)) continue; pl.Send(Packet.SetInventoryOrder(raw, order)); } } @@ -282,9 +282,9 @@ namespace MCGalaxy { } public byte[] MakeDefinePacket(Player pl) { - if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) { + if (pl.Supports(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) { return Packet.DefineBlockExt(this, true, pl.hasCP437); - } else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && Shape != 0) { + } else if (pl.Supports(CpeExt.BlockDefinitionsExt) && Shape != 0) { return Packet.DefineBlockExt(this, false, pl.hasCP437); } else { return Packet.DefineBlock(this, pl.hasCP437); diff --git a/MCGalaxy/Blocks/BlockPerms.cs b/MCGalaxy/Blocks/BlockPerms.cs index 561717230..260fb6b8f 100644 --- a/MCGalaxy/Blocks/BlockPerms.cs +++ b/MCGalaxy/Blocks/BlockPerms.cs @@ -69,7 +69,7 @@ namespace MCGalaxy.Blocks { public static void ResendBlockPermissions(byte block) { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (!pl.HasCpeExt(CpeExt.BlockPermissions)) continue; + if (!pl.Supports(CpeExt.BlockPermissions)) continue; int count = pl.hasCustomBlocks ? Block.CpeCount : Block.OriginalCount; if (block < count) { diff --git a/MCGalaxy/Chat/Colors.cs b/MCGalaxy/Chat/Colors.cs index e0665dfa7..a4a8fb6fb 100644 --- a/MCGalaxy/Chat/Colors.cs +++ b/MCGalaxy/Chat/Colors.cs @@ -92,7 +92,7 @@ namespace MCGalaxy { List[col.Code] = col; Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { - if (!p.HasCpeExt(CpeExt.TextColors)) continue; + if (!p.Supports(CpeExt.TextColors)) continue; p.Send(Packet.SetTextColor(col)); } SaveList(); diff --git a/MCGalaxy/Commands/CPE/CmdReachDistance.cs b/MCGalaxy/Commands/CPE/CmdReachDistance.cs index b1622b9c3..83263ad44 100644 --- a/MCGalaxy/Commands/CPE/CmdReachDistance.cs +++ b/MCGalaxy/Commands/CPE/CmdReachDistance.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.CPE { if (packedDist > short.MaxValue) { Player.Message(p, "\"{0}\", is too long a reach distance. Max is 1023 blocks.", message); - } else if (!p.HasCpeExt(CpeExt.ClickDistance)) { + } else if (!p.Supports(CpeExt.ClickDistance)) { Player.Message(p, "Your client doesn't support changing your reach distance."); } else { p.Send(Packet.ClickDistance((short)packedDist)); diff --git a/MCGalaxy/CorePlugin/ConnectHandler.cs b/MCGalaxy/CorePlugin/ConnectHandler.cs index 1b35b8803..f785ddf27 100644 --- a/MCGalaxy/CorePlugin/ConnectHandler.cs +++ b/MCGalaxy/CorePlugin/ConnectHandler.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Core { if (!short.TryParse(reach, out reachDist)) return; p.ReachDistance = reachDist / 32f; - if (p.HasCpeExt(CpeExt.ClickDistance)) + if (p.Supports(CpeExt.ClickDistance)) p.Send(Packet.ClickDistance(reachDist)); } diff --git a/MCGalaxy/CorePlugin/MiscHandlers.cs b/MCGalaxy/CorePlugin/MiscHandlers.cs index 711b3abb2..6d4a9a299 100644 --- a/MCGalaxy/CorePlugin/MiscHandlers.cs +++ b/MCGalaxy/CorePlugin/MiscHandlers.cs @@ -50,9 +50,9 @@ namespace MCGalaxy.Core { p.isFlying = false; } - if (p.HasCpeExt(CpeExt.EnvWeatherType)) + if (p.Supports(CpeExt.EnvWeatherType)) p.Send(Packet.EnvWeatherType((byte)level.Config.Weather)); - if (p.HasCpeExt(CpeExt.EnvColors)) + if (p.Supports(CpeExt.EnvColors)) p.SendCurrentEnvColors(); p.SendCurrentMapAppearance(); p.SendCurrentBlockPermissions(); diff --git a/MCGalaxy/Entity/Entities.cs b/MCGalaxy/Entity/Entities.cs index c51012f0e..fbd70e6d8 100644 --- a/MCGalaxy/Entity/Entities.cs +++ b/MCGalaxy/Entity/Entities.cs @@ -139,8 +139,11 @@ namespace MCGalaxy { if (id == Entities.SelfID) pos.Y -= 22; name = Colors.Cleanup(name, dst.hasTextColors); - if (dst.hasExtList) { + if (dst.Supports(CpeExt.ExtPlayerList, 2)) { dst.Send(Packet.ExtAddEntity2(id, skin, name, pos, rot, dst.hasCP437, dst.hasExtPositions)); + } else if (dst.hasExtList) { + dst.Send(Packet.ExtAddEntity(id, skin, name, dst.hasCP437)); + dst.Send(Packet.Teleport(id, pos, rot, dst.hasExtPositions)); } else { dst.Send(Packet.AddEntity(id, name, pos, rot, dst.hasCP437, dst.hasExtPositions)); } @@ -149,7 +152,7 @@ namespace MCGalaxy { dst.Send(Packet.ChangeModel(id, model, dst.hasCP437)); } - if (dst.HasCpeExt(CpeExt.EntityProperty)) { + if (dst.Supports(CpeExt.EntityProperty)) { dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX))); dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ))); } @@ -186,7 +189,7 @@ namespace MCGalaxy { entity.ModelBB = AABB.ModelAABB(model, lvl); foreach (Player pl in players) { - if (pl.level != lvl || !pl.HasCpeExt(CpeExt.ChangeModel)) continue; + if (pl.level != lvl || !pl.Supports(CpeExt.ChangeModel)) continue; if (!pl.CanSeeEntity(entity)) continue; byte id = (pl == entity) ? Entities.SelfID : entity.EntityID; @@ -217,7 +220,7 @@ namespace MCGalaxy { if (prop == EntityProp.RotY) entity.SetYawPitch(rot.RotY, rot.HeadX); foreach (Player pl in players) { - if (pl.level != lvl || !pl.HasCpeExt(CpeExt.EntityProperty)) continue; + if (pl.level != lvl || !pl.Supports(CpeExt.EntityProperty)) continue; if (!pl.CanSeeEntity(entity)) continue; byte id = (pl == entity) ? Entities.SelfID : entity.EntityID; diff --git a/MCGalaxy/Games/LevelPicker.cs b/MCGalaxy/Games/LevelPicker.cs index 18e98f200..9f399f3e4 100644 --- a/MCGalaxy/Games/LevelPicker.cs +++ b/MCGalaxy/Games/LevelPicker.cs @@ -99,14 +99,14 @@ namespace MCGalaxy.Games { // Show message for non-CPE clients Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (pl.level != game.Map || pl.HasCpeExt(CpeExt.MessageTypes)) continue; + if (pl.level != game.Map || pl.Supports(CpeExt.MessageTypes)) continue; pl.SendMessage("You have 20 seconds to vote for the next map"); } for (int i = 0; i < 20; i++) { players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (pl.level != game.Map || !pl.HasCpeExt(CpeExt.MessageTypes)) continue; + if (pl.level != game.Map || !pl.Supports(CpeExt.MessageTypes)) continue; pl.SendCpeMessage(CpeMessageType.BottomRight1, "&e" + (20 - i) + "s %Sleft to vote"); } Thread.Sleep(1000); @@ -150,7 +150,7 @@ namespace MCGalaxy.Games { const string line1 = "&eLevel vote - type &a1&e, &b2&e or &c3"; string line2 = "&a" + Candidate1 + "&e, &b" + Candidate2 + "&e, &c" + Candidate3; - if (p.HasCpeExt(CpeExt.MessageTypes)) { + if (p.Supports(CpeExt.MessageTypes)) { p.SendCpeMessage(CpeMessageType.BottomRight3, line1); p.SendCpeMessage(CpeMessageType.BottomRight2, line2); } else { diff --git a/MCGalaxy/Games/ZombieSurvival/ZSPlugin.cs b/MCGalaxy/Games/ZombieSurvival/ZSPlugin.cs index e585f7020..bd7cf5c87 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZSPlugin.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZSPlugin.cs @@ -114,14 +114,14 @@ namespace MCGalaxy.Games.ZS { Command.all.FindByName("Spawn").Use(p, ""); p.Game.Referee = false; - if (p.HasCpeExt(CpeExt.HackControl)) + if (p.Supports(CpeExt.HackControl)) p.Send(Hacks.MakeHackControl(p)); } else { HandlePlayerDisconnect(p, null); Entities.GlobalDespawn(p, false, true); p.Game.Referee = true; - if (p.HasCpeExt(CpeExt.HackControl)) + if (p.Supports(CpeExt.HackControl)) p.Send(Packet.HackControl(true, true, true, true, true, -1)); } diff --git a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs index 23627b5c6..929326bc9 100644 --- a/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/MCGalaxy/Games/ZombieSurvival/ZombieGame.Core.cs @@ -234,7 +234,7 @@ namespace MCGalaxy.Games { Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (p.level != Map) continue; - CpeMessageType type = announce && p.HasCpeExt(CpeExt.MessageTypes) + CpeMessageType type = announce && p.Supports(CpeExt.MessageTypes) ? CpeMessageType.Announcement : CpeMessageType.Normal; p.Send(Packet.Message(message, type, p.hasCP437)); @@ -258,7 +258,7 @@ namespace MCGalaxy.Games { p.Game.InvisibilityTime = left; string msg = "&bInvisibility for &a" + left; - if (p.HasCpeExt(CpeExt.MessageTypes)) { + if (p.Supports(CpeExt.MessageTypes)) { p.SendCpeMessage(CpeMessageType.BottomRight2, msg); } else { Player.Message(p, msg); diff --git a/MCGalaxy/Levels/LevelEnv.cs b/MCGalaxy/Levels/LevelEnv.cs index d7c4eb0db..ffa5b614f 100644 --- a/MCGalaxy/Levels/LevelEnv.cs +++ b/MCGalaxy/Levels/LevelEnv.cs @@ -46,7 +46,7 @@ namespace MCGalaxy { lvl.Config.Weather = weather; Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (pl.level == lvl && pl.HasCpeExt(CpeExt.EnvWeatherType)) + if (pl.level == lvl && pl.Supports(CpeExt.EnvWeatherType)) pl.Send(Packet.EnvWeatherType(weather)); } } @@ -166,7 +166,7 @@ namespace MCGalaxy { foreach (Player pl in players) { if (pl.level != lvl) continue; - if (pl.HasCpeExt(CpeExt.EnvMapAspect)) { + if (pl.Supports(CpeExt.EnvMapAspect)) { pl.Send(Packet.EnvMapProperty(prop, value)); } else { pl.SendCurrentMapAppearance(); @@ -177,7 +177,7 @@ namespace MCGalaxy { internal static void UpdateEnvColor(Player p, byte type, string hex) { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (pl.level != p.level || !pl.HasCpeExt(CpeExt.EnvColors)) continue; + if (pl.level != p.level || !pl.Supports(CpeExt.EnvColors)) continue; pl.SendEnvColor(type, hex); } } diff --git a/MCGalaxy/Network/Player.Networking.cs b/MCGalaxy/Network/Player.Networking.cs index 50aaa6a8e..3ab151d88 100644 --- a/MCGalaxy/Network/Player.Networking.cs +++ b/MCGalaxy/Network/Player.Networking.cs @@ -128,7 +128,7 @@ namespace MCGalaxy { retryTag: try { foreach (string raw in LineWrapper.Wordwrap(message)) { string line = raw; - if (!HasCpeExt(CpeExt.EmoteFix) && LineEndsInEmote(line)) + if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line)) line += '\''; Send(Packet.Message(line, (CpeMessageType)id, hasCP437)); @@ -150,7 +150,7 @@ namespace MCGalaxy { } public void SendCpeMessage(CpeMessageType type, string message, bool colorParse = true) { - if (type != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) { + if (type != CpeMessageType.Normal && !Supports(CpeExt.MessageTypes)) { if (type == CpeMessageType.Announcement) type = CpeMessageType.Normal; else return; } @@ -166,7 +166,7 @@ namespace MCGalaxy { OnSendingMotdEvent.Call(this, packet); Send(packet); - if (!HasCpeExt(CpeExt.HackControl)) return; + if (!Supports(CpeExt.HackControl)) return; Send(Hacks.MakeHackControl(this)); if (Game.Referee) Send(Packet.HackControl(true, true, true, true, true, -1)); @@ -200,7 +200,7 @@ namespace MCGalaxy { } BlockDefinition.SendLevelCustomBlocks(this); - if (HasCpeExt(CpeExt.InventoryOrder)) { + if (Supports(CpeExt.InventoryOrder)) { BlockDefinition.SendLevelInventoryOrder(this); } } diff --git a/MCGalaxy/Player/Player.CPE.cs b/MCGalaxy/Player/Player.CPE.cs index fa8a798c4..04d856080 100644 --- a/MCGalaxy/Player/Player.CPE.cs +++ b/MCGalaxy/Player/Player.CPE.cs @@ -92,7 +92,7 @@ namespace MCGalaxy { } /// Returns whether this player's client supports the given CPE extension. - public bool HasCpeExt(string extName, int version = 1) { + public bool Supports(string extName, int version = 1) { if (!hasCpe) return false; ExtEntry ext = FindExtension(extName); return ext != null && ext.ClientExtVersion == version; @@ -104,7 +104,7 @@ namespace MCGalaxy { if (!hasBlockDefs) side = level.RawFallback(side); if (!hasBlockDefs) edge = level.RawFallback(edge); - if (HasCpeExt(CpeExt.EnvMapAspect)) { + if (Supports(CpeExt.EnvMapAspect)) { string url = GetTextureUrl(); // reset all other textures back to client default. if (url != lastUrl) Send(Packet.EnvMapUrl("", hasCP437)); @@ -121,7 +121,7 @@ namespace MCGalaxy { Send(Packet.EnvMapProperty(EnvProp.CloudsSpeed, level.Config.CloudsSpeed)); Send(Packet.EnvMapProperty(EnvProp.WeatherSpeed, level.Config.WeatherSpeed)); Send(Packet.EnvMapProperty(EnvProp.ExpFog, level.Config.ExpFog ? 1 : 0)); - } else if (HasCpeExt(CpeExt.EnvMapAppearance, 2)) { + } else if (Supports(CpeExt.EnvMapAppearance, 2)) { string url = GetTextureUrl(); // reset all other textures back to client default. if (url != lastUrl) { @@ -131,7 +131,7 @@ namespace MCGalaxy { Send(Packet.MapAppearanceV2(url, side, edge, level.Config.EdgeLevel, level.Config.CloudsHeight, level.Config.MaxFogDistance, hasCP437)); lastUrl = url; - } else if (HasCpeExt(CpeExt.EnvMapAppearance)) { + } else if (Supports(CpeExt.EnvMapAppearance)) { string url = level.Config.Terrain.Length == 0 ? ServerConfig.DefaultTerrain : level.Config.Terrain; Send(Packet.MapAppearance(url, side, edge, level.Config.EdgeLevel, hasCP437)); } @@ -166,7 +166,7 @@ namespace MCGalaxy { } public void SendCurrentBlockPermissions() { - if (!HasCpeExt(CpeExt.BlockPermissions)) return; + if (!Supports(CpeExt.BlockPermissions)) return; // Write the block permissions as one bulk TCP packet int count = NumBlockPermissions(); diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 393008eac..03d0c043b 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -303,7 +303,7 @@ namespace MCGalaxy { void HandleMovement(byte[] buffer, int offset) { if (!loggedIn || trainGrab || following.Length > 0) { CheckBlocks(Pos); return; } - if (HasCpeExt(CpeExt.HeldBlock)) { + if (Supports(CpeExt.HeldBlock)) { RawHeldBlock = ExtBlock.FromRaw(buffer[offset + 1]); } @@ -490,7 +490,7 @@ namespace MCGalaxy { return true; } - if (HasCpeExt(CpeExt.LongerMessages) && continued != 0) { + if (Supports(CpeExt.LongerMessages) && continued != 0) { partialMessage += text; if (text.Length < NetUtils.StringSize) partialMessage += " "; return true;