Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aed14ba
commit 1446a39
Showing
6 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* This file is part of uEssentials project. | ||
* https://uessentials.github.io/ | ||
* | ||
* Copyright (C) 2015-2016 Leonardosc | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
using Essentials.Common; | ||
using Essentials.Common.Reflect; | ||
using Rocket.Core; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Essentials.Compatibility.Hooks | ||
{ | ||
public class UconomyHook : Hook | ||
{ | ||
private MethodAccessor<decimal> _getBalanceMethod; | ||
private MethodAccessor<decimal> _increaseBalanceMethod; | ||
|
||
public UconomyHook() : base("economy") {} | ||
|
||
public override void OnLoad() | ||
{ | ||
var uconomyPlugin = R.Plugins.GetPlugins().FirstOrDefault( c => c.Name.EqualsIgnoreCase( "uconomy" ) ); | ||
var uconomyType = uconomyPlugin.GetType().Assembly.GetType( "fr34kyn01535.Uconomy.Uconomy" ); | ||
var uconomyInstance = uconomyType.GetField( "Instance", BindingFlags.Static | BindingFlags.Public ).GetValue( uconomyPlugin ); | ||
|
||
var databaseInstance = uconomyInstance.GetType().GetField( "Database" ).GetValue( uconomyInstance ); | ||
_getBalanceMethod = AccessorFactory.AccessMethod<decimal>( databaseInstance, "GetBalance" ); | ||
_increaseBalanceMethod = AccessorFactory.AccessMethod<decimal>( databaseInstance, "IncreaseBalance" ); | ||
} | ||
|
||
public override void OnUnload() | ||
{ | ||
} | ||
|
||
public override bool CanBeLoaded() | ||
{ | ||
return R.Plugins.GetPlugins().Any( c => c.Name.EqualsIgnoreCase( "uconomy" ) ); | ||
} | ||
|
||
public decimal Withdraw( ulong playerId, decimal amount ) | ||
{ | ||
return _increaseBalanceMethod.Invoke( playerId.ToString(), -amount ); | ||
} | ||
|
||
public decimal Deposit( ulong playerId, decimal amount ) | ||
{ | ||
return _increaseBalanceMethod.Invoke( playerId.ToString(), amount ); | ||
} | ||
|
||
public decimal GetBalance( ulong playerId ) | ||
{ | ||
return _getBalanceMethod.Invoke( playerId.ToString() ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* This file is part of uEssentials project. | ||
* https://uessentials.github.io/ | ||
* | ||
* Copyright (C) 2015-2016 Leonardosc | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
using Essentials.Api.Unturned; | ||
using Essentials.Compatibility.Hooks; | ||
using Essentials.Core; | ||
using Newtonsoft.Json; | ||
|
||
namespace Essentials.InternalModules.Kit.Item | ||
{ | ||
public class KitItemMoney : AbstractKitItem | ||
{ | ||
[JsonProperty( "Money" )] | ||
public decimal Amount { get; set; } | ||
|
||
public KitItemMoney( decimal amount ) | ||
{ | ||
Amount = amount; | ||
} | ||
|
||
public override bool GiveTo( UPlayer player, bool dropIfInventoryFull = true ) | ||
{ | ||
EssCore.Instance.HookManager.GetByType<UconomyHook>().IfPresent( h => { | ||
h.Deposit( player.CSteamId.m_SteamID, Amount ); | ||
} ); | ||
return true; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"Money: {Amount}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters