Merge pull request #1223 from mistzzt/protect-gem-lock
Add protection for gem locks in region
This commit is contained in:
commit
eced9ec392
2 changed files with 84 additions and 1 deletions
|
|
@ -319,6 +319,10 @@ namespace TShockAPI
|
||||||
[Description("Protect chests with region and build permissions.")]
|
[Description("Protect chests with region and build permissions.")]
|
||||||
public bool RegionProtectChests;
|
public bool RegionProtectChests;
|
||||||
|
|
||||||
|
/// <summary>RegionProtectGemLocks - Whether or not region protection should apply to gem locks.</summary>
|
||||||
|
[Description("Protect gem locks with region and build permissions.")]
|
||||||
|
public bool RegionProtectGemLocks = true;
|
||||||
|
|
||||||
/// <summary>DisableLoginBeforeJoin - This will prevent users from being able to login before connecting.</summary>
|
/// <summary>DisableLoginBeforeJoin - This will prevent users from being able to login before connecting.</summary>
|
||||||
[Description("Disable users from being able to login with account password when joining.")]
|
[Description("Disable users from being able to login with account password when joining.")]
|
||||||
public bool DisableLoginBeforeJoin;
|
public bool DisableLoginBeforeJoin;
|
||||||
|
|
|
||||||
|
|
@ -1249,7 +1249,8 @@ namespace TShockAPI
|
||||||
{ PacketTypes.DoorUse, HandleDoorUse },
|
{ PacketTypes.DoorUse, HandleDoorUse },
|
||||||
{ PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest },
|
{ PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest },
|
||||||
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
|
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
|
||||||
{ PacketTypes.MassWireOperation, HandleMassWireOperation }
|
{ PacketTypes.MassWireOperation, HandleMassWireOperation },
|
||||||
|
{ PacketTypes.GemLockToggle, HandleGemLockToggle }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3899,5 +3900,83 @@ namespace TShockAPI
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// For use with a ToggleGemLock event
|
||||||
|
/// </summary>
|
||||||
|
public class GemLockToggleEventArgs : HandledEventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// X Location
|
||||||
|
/// </summary>
|
||||||
|
public Int32 X { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Y Location
|
||||||
|
/// </summary>
|
||||||
|
public Int32 Y { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// On status
|
||||||
|
/// </summary>
|
||||||
|
public bool On { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// GemLockToggle - Called when a gem lock is switched
|
||||||
|
/// </summary>
|
||||||
|
public static HandlerList<GemLockToggleEventArgs> GemLockToggle;
|
||||||
|
|
||||||
|
private static bool OnGemLockToggle(Int32 x, Int32 y, bool on)
|
||||||
|
{
|
||||||
|
if (GemLockToggle == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var args = new GemLockToggleEventArgs
|
||||||
|
{
|
||||||
|
X = x,
|
||||||
|
Y = y,
|
||||||
|
On = on
|
||||||
|
};
|
||||||
|
GemLockToggle.Invoke(null, args);
|
||||||
|
return args.Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HandleGemLockToggle(GetDataHandlerArgs args)
|
||||||
|
{
|
||||||
|
var x = (int)args.Data.ReadInt16();
|
||||||
|
var y = (int)args.Data.ReadInt16();
|
||||||
|
var on = args.Data.ReadBoolean();
|
||||||
|
|
||||||
|
if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OnGemLockToggle(x, y, on))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TShock.Config.RegionProtectGemLocks)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TShock.Utils.TilePlacementValid(x, y) || (args.Player.Dead && TShock.Config.PreventDeadModification))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.CheckIgnores(args.Player))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TShock.CheckTilePermission(args.Player, x, y))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue