From e9d504afd4ab66d6cd3e914418cda6dc9804ddfd Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Tue, 2 Aug 2016 18:41:28 +0200 Subject: [PATCH 1/3] Add ItemForceIntoChest hook. Fixes #1250 --- TShockAPI/TShock.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index e90576f5..275ad29f 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -317,6 +317,7 @@ namespace TShockAPI ServerApi.Hooks.WorldChristmasCheck.Register(this, OnXmasCheck); ServerApi.Hooks.WorldHalloweenCheck.Register(this, OnHalloweenCheck); ServerApi.Hooks.NetNameCollision.Register(this, NetHooks_NameCollision); + ServerApi.Hooks.ItemForceIntoChest.Register(this, OnItemForceIntoChest); Hooks.PlayerHooks.PlayerPreLogin += OnPlayerPreLogin; Hooks.PlayerHooks.PlayerPostLogin += OnPlayerLogin; Hooks.AccountHooks.AccountDelete += OnAccountDelete; @@ -384,6 +385,7 @@ namespace TShockAPI ServerApi.Hooks.WorldChristmasCheck.Deregister(this, OnXmasCheck); ServerApi.Hooks.WorldHalloweenCheck.Deregister(this, OnHalloweenCheck); ServerApi.Hooks.NetNameCollision.Deregister(this, NetHooks_NameCollision); + ServerApi.Hooks.ItemForceIntoChest.Deregister(this, OnItemForceIntoChest); TShockAPI.Hooks.PlayerHooks.PlayerPostLogin -= OnPlayerLogin; if (File.Exists(Path.Combine(SavePath, "tshock.pid"))) @@ -471,6 +473,45 @@ namespace TShockAPI } } + /// OnItemForceIntoChest - Internal hook fired when a player quick stacks items into a chest. + /// The object. + private void OnItemForceIntoChest(ForceItemIntoChestEventArgs args) + { + if (args.Handled) + { + return; + } + + if (args.Player == null) + { + args.Handled = true; + return; + } + + TSPlayer tsplr = Players[args.Player.whoAmI]; + if (tsplr == null) + { + args.Handled = true; + return; + } + + if (args.Chest != null) + { + if (Config.RegionProtectChests && !tsplr.HasPermission(Permissions.editregion) + && !Regions.CanBuild((int)args.Position.X, (int)args.Position.Y, tsplr) && Regions.InArea((int)args.Position.X, (int)args.Position.Y)) + { + args.Handled = true; + return; + } + + if (CheckRangePermission(tsplr, (int)args.Position.X, (int)args.Position.Y)) + { + args.Handled = true; + return; + } + } + } + /// OnXmasCheck - Internal hook fired when the XMasCheck happens. /// args - The ChristmasCheckEventArgs object. private void OnXmasCheck(ChristmasCheckEventArgs args) From 0919641b7f639cbee8be317fefc63ef6c519466b Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Tue, 2 Aug 2016 18:44:19 +0200 Subject: [PATCH 2/3] Update ApiVersion --- CHANGELOG.md | 2 ++ TShockAPI/TShock.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92a4b919..80318d35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming Changes * API: Fixed chat line breaks when using chat tags and long strings of text (@ProfessorXZ) +* API: Added ItemForceIntoChest hook (@WhiteXZ) * The setdungeon command correctly uses tshock.world.setdungeon as its permission (@OnsenManju) * Fixed clients being able to "Catch" and remove NPCs (@ProfessorXZ) * Fixed clients being able to remove other players' portals (@ProfessorXZ) @@ -14,6 +15,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed a bug involving Item Frames which allowed players to duplicate items (@ProfessorXZ) * Fixed an issue allowing clients to teleport NPCs to arbitrary locations (@ProfessorXZ) * Fixed a bug where players would get teleported to their previous location after dismounting the Unicorn Mount (@ProfessorXZ) +* Players can no longer quick stack items into region protected chests (@ProfessorXZ) ## TShock 4.3.17 diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 275ad29f..82192c32 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -45,7 +45,7 @@ namespace TShockAPI /// This is the TShock main class. TShock is a plugin on the TerrariaServerAPI, so it extends the base TerrariaPlugin. /// TShock also complies with the API versioning system, and defines its required API version here. /// - [ApiVersion(1, 23)] + [ApiVersion(1, 24)] public class TShock : TerrariaPlugin { /// VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info. From 37d9e93e6c5323f6b3195ef9632ab7c338dbaa91 Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Tue, 2 Aug 2016 19:22:47 +0200 Subject: [PATCH 3/3] Remove redundant region checks --- TShockAPI/DB/RegionManager.cs | 2 +- TShockAPI/TShock.cs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index 894f4a27..48e17c39 100755 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -759,7 +759,7 @@ namespace TShockAPI.DB return false; } - return AllowedIDs.Contains(ply.User.ID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.User.Name; + return ply.HasPermission(Permissions.editregion) || AllowedIDs.Contains(ply.User.ID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.User.Name; } /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 82192c32..8f48506c 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -497,8 +497,7 @@ namespace TShockAPI if (args.Chest != null) { - if (Config.RegionProtectChests && !tsplr.HasPermission(Permissions.editregion) - && !Regions.CanBuild((int)args.Position.X, (int)args.Position.Y, tsplr) && Regions.InArea((int)args.Position.X, (int)args.Position.Y)) + if (Config.RegionProtectChests && !Regions.CanBuild((int)args.Position.X, (int)args.Position.Y, tsplr)) { args.Handled = true; return; @@ -1741,8 +1740,7 @@ namespace TShockAPI return true; } - if (!player.HasPermission(Permissions.editregion) && !Regions.CanBuild(tileX, tileY, player) && - Regions.InArea(tileX, tileY)) + if (!Regions.CanBuild(tileX, tileY, player)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000) { @@ -1809,8 +1807,7 @@ namespace TShockAPI return true; } - if (!player.HasPermission(Permissions.editregion) && !Regions.CanBuild(tileX, tileY, player) && - Regions.InArea(tileX, tileY)) + if (!Regions.CanBuild(tileX, tileY, player)) { if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000) {