From c11b9447357b7bf6dd94af8342528895f79e6ff2 Mon Sep 17 00:00:00 2001 From: Zidonuke Date: Tue, 27 Dec 2011 13:26:37 -0500 Subject: [PATCH] Invisibility Potions are now item banable. New noclip detection, has ignore permission. --- TShockAPI/ConfigFile.cs | 3 ++ TShockAPI/GetDataHandlers.cs | 53 +++++++++++++++++++++++++++++++++--- TShockAPI/Permissions.cs | 3 ++ TShockAPI/TShock.cs | 3 +- 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 98b9bd21..9dc5fd6d 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -195,6 +195,9 @@ namespace TShockAPI [Description("Require all players to register or login before being allowed to play.")] public bool RequireLogin = false; + + [Description("Disables Invisibility potions from being used in PvP (Note, they can use them on the client, but the effect isn't sent to the rest of the server)")] + public bool DisableInvisPvP = false; public static ConfigFile Read(string path) { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 7ddba6a0..53672d73 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -90,6 +90,7 @@ namespace TShockAPI {PacketTypes.NpcStrike, HandleNpcStrike}, {PacketTypes.NpcSpecial, HandleSpecial}, {PacketTypes.PlayerAnimation, HandlePlayerAnimation}, + {PacketTypes.PlayerBuff, HandlePlayerBuffUpdate} }; } @@ -624,6 +625,22 @@ namespace TShockAPI args.Player.Spawn(); return true; } + + if(!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) && TShock.CheckPlayerCollision((int)(pos.X / 16f), (int)(pos.Y / 16f))) + { + int lastTileX = (int)(args.Player.LastNetPosition.X / 16f); + int lastTileY = (int)(args.Player.LastNetPosition.Y / 16f); + if(args.Player.Teleport(lastTileX, lastTileY)) + { + args.Player.SendMessage("You got stuck in a solid object, Sent to last good position."); + } + else + { + args.Player.SendMessage("You got stuck in a solid object, Sent to spawn point."); + args.Player.Spawn(); + } + return true; + } } args.Player.LastNetPosition = pos; @@ -1063,7 +1080,7 @@ namespace TShockAPI args.Player.SendData(PacketTypes.PlayerBuff, "", id); return true; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 64)) + if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50)) { args.Player.SendData(PacketTypes.PlayerBuff, "", id); return true; @@ -1097,7 +1114,7 @@ namespace TShockAPI return false; } - if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f), 64)) + if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); return true; @@ -1163,7 +1180,7 @@ namespace TShockAPI return true; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 128)) + if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 100)) { args.Player.SendData(PacketTypes.PlayerHp, "", id); args.Player.SendData(PacketTypes.PlayerUpdate, "", id); @@ -1209,7 +1226,7 @@ namespace TShockAPI return true; } - if (TShock.Config.RangeChecks && ((Math.Abs(args.Player.TileX - (Main.npc[id].position.X / 16f)) > 128) || (Math.Abs(args.Player.TileY - (Main.npc[id].position.Y / 16f)) > 128))) + if (TShock.Config.RangeChecks && TShock.CheckRangePermission(args.Player, (int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 100)) { args.Player.SendData(PacketTypes.NpcUpdate, "", id); return true; @@ -1255,5 +1272,33 @@ namespace TShockAPI return false; } + + private static bool HandlePlayerBuffUpdate(GetDataHandlerArgs args) + { + var id = args.Data.ReadInt8(); + for (int i = 0; i < 10; i++) + { + var buff = args.Data.ReadInt8(); + + if (buff == 10) + { + if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned("Invisibility Potion")) + buff = 0; + else if (TShock.Config.DisableInvisPvP && args.TPlayer.hostile) + buff = 0; + } + + args.TPlayer.buffType[i] = buff; + if (args.TPlayer.buffType[i] > 0) + { + args.TPlayer.buffTime[i] = 60; + } + else + { + args.TPlayer.buffTime[i] = 0; + } + } + return true; + } } } diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index e4d72245..84891947 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -38,6 +38,9 @@ namespace TShockAPI [Description("Prevents you from being reverted by place tile abuse detection")] public static readonly string ignoreplacetiledetection; + [Description("Prevents you from being reverted by no clip detection")] + public static readonly string ignorenoclipdetection; + [Description("Specific log messages are sent to users with this permission")] public static readonly string logs; diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 7489e028..c8fb5613 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -755,8 +755,7 @@ namespace TShockAPI if (Config.RememberLeavePos) { var pos = RememberedPos.GetLeavePos(player.Name, player.IP); - player.Teleport((int)pos.X, (int)pos.Y); - player.SendTileSquare((int)pos.X, (int)pos.Y); + player.Teleport((int) pos.X, (int) pos.Y); } e.Handled = true; }