-
Notifications
You must be signed in to change notification settings - Fork 3
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
7e8db49
commit 8d01aac
Showing
8 changed files
with
402 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31005.135 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedCosmetics", "AdvancedCosmetics\AdvancedCosmetics.csproj", "{8BFDD083-265C-451F-B378-86664E84334A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8BFDD083-265C-451F-B378-86664E84334A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8BFDD083-265C-451F-B378-86664E84334A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8BFDD083-265C-451F-B378-86664E84334A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8BFDD083-265C-451F-B378-86664E84334A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9EEEB2D1-1123-45F5-B1DC-33F55283B62F} | ||
EndGlobalSection | ||
EndGlobal |
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,75 @@ | ||
using AdvancedCosmetics.Models; | ||
using Rocket.API.Collections; | ||
using Rocket.Core.Logging; | ||
using Rocket.Core.Plugins; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Permissions; | ||
using SDG.Provider; | ||
using SDG.Unturned; | ||
using Steamworks; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
using Logger = Rocket.Core.Logging.Logger; | ||
|
||
namespace AdvancedCosmetics | ||
{ | ||
public class AdvancedCosmetics : RocketPlugin<Configuration> | ||
{ | ||
public static AdvancedCosmetics Instance { get; private set; } | ||
public Color MessageColor { get; private set; } | ||
public List<UnturnedEconInfo> EconInfos { get; private set;} | ||
public Dictionary<CSteamID, Cosmetic> Cosmetics { get; set; } | ||
protected override void Load() | ||
{ | ||
Instance = this; | ||
MessageColor = UnturnedChat.GetColorFromName(Configuration.Instance.MessageColor, Color.green); | ||
Cosmetics = new Dictionary<CSteamID, Cosmetic>(); | ||
var dir = System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).FullName).FullName).FullName + @"\EconInfo.json"; | ||
EconInfos = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UnturnedEconInfo>>(File.ReadAllText(dir)); | ||
UnturnedPermissions.OnJoinRequested += UnturnedPermissions_OnJoinRequested; | ||
Logger.Log($"{Name} {Assembly.GetName().Version} has been loaded"); | ||
} | ||
|
||
protected override void Unload() | ||
{ | ||
UnturnedPermissions.OnJoinRequested -= UnturnedPermissions_OnJoinRequested; | ||
Logger.Log($"{Name} {Assembly.GetName().Version} has been unloaded"); | ||
} | ||
|
||
public override TranslationList DefaultTranslations => new TranslationList | ||
{ | ||
{ "NotSetUp", "You didnt setup any custom cosmetic yet !" }, | ||
{ "RemovedCos", "Sucssesfully removed your custom cosmetics !"}, | ||
{ "AddCos", "Sucssesfully added a {0} to your cosmetics !"}, | ||
{ "NotFound", "Cosmetic with the id or name {0} not found !"} | ||
}; | ||
|
||
private void UnturnedPermissions_OnJoinRequested(Steamworks.CSteamID player, ref SDG.Unturned.ESteamRejection? rejectionReason) | ||
{ | ||
var pending = Provider.pending.FirstOrDefault(x => x.playerID.steamID == player); | ||
if (pending != null && Cosmetics.ContainsKey(player)) | ||
{ | ||
var cosmetics = Cosmetics[player]; | ||
if(cosmetics != null) | ||
{ | ||
pending.backpackItem = cosmetics.Backpack; | ||
pending.glassesItem = cosmetics.Glass; | ||
pending.hatItem = cosmetics.Hat; | ||
pending.maskItem = cosmetics.Mask; | ||
pending.pantsItem = cosmetics.Pants; | ||
pending.shirtItem = cosmetics.Shirt; | ||
pending.vestItem = cosmetics.Vest; | ||
if(cosmetics.Skins != null) | ||
{ | ||
pending.skinItems = cosmetics.Skins.ToArray(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,78 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{8BFDD083-265C-451F-B378-86664E84334A}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AdvancedCosmetics</RootNamespace> | ||
<AssemblyName>AdvancedCosmetics</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Assembly-CSharp"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp-firstpass"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Assembly-CSharp-firstpass.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rocket.API"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Rocket.API.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rocket.Core"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Rocket.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rocket.Unturned"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\Rocket.Unturned.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>..\..\VirtualGarage\bin\Debug\UnityEngine.CoreModule.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AdvancedCosmetics.cs" /> | ||
<Compile Include="Commands\CustomCosmeticCommand.cs" /> | ||
<Compile Include="Commands\RemoveCustomCosmeticsCommand.cs" /> | ||
<Compile Include="Configuration.cs" /> | ||
<Compile Include="Models\Cosmetic.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
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,107 @@ | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using SDG.Provider; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdvancedCosmetics.Commands | ||
{ | ||
public class CustomCosmeticCommand : IRocketCommand | ||
{ | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "customcosmetic"; | ||
|
||
public string Help => "A command to get a custom cosmetic"; | ||
|
||
public string Syntax => "/customcosmetic <cosmeticId> | /customcosmetic <cosmeticName>"; | ||
|
||
public List<string> Aliases => new List<string>(); | ||
|
||
public List<string> Permissions => new List<string>(); | ||
|
||
public void Execute(IRocketPlayer caller, string[] command) | ||
{ | ||
var player = (UnturnedPlayer)caller; | ||
if(command.Length < 1) | ||
{ | ||
UnturnedChat.Say(player, "Correct Usage: " + Syntax, AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
else if(int.TryParse(command[0], out int SkinId)) | ||
{ | ||
if(AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.itemdefid == SkinId) != null) | ||
{ | ||
AddCosmetic(player, AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.itemdefid == SkinId)); | ||
} | ||
else | ||
{ | ||
UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotFound", SkinId), AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
} | ||
else | ||
{ | ||
var skin = command[0]; | ||
if(AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.name.Contains(skin)) != null) | ||
{ | ||
AddCosmetic(player, AdvancedCosmetics.Instance.EconInfos.FirstOrDefault(x => x.name.Contains(skin))); | ||
} | ||
else | ||
{ | ||
UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotFound", command[0]), AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
} | ||
} | ||
|
||
public void AddCosmetic(UnturnedPlayer player, UnturnedEconInfo info) | ||
{ | ||
if (!AdvancedCosmetics.Instance.Cosmetics.ContainsKey(player.CSteamID)) | ||
{ | ||
AdvancedCosmetics.Instance.Cosmetics.Add(player.CSteamID, new Models.Cosmetic()); | ||
} | ||
|
||
var cosmetics = AdvancedCosmetics.Instance.Cosmetics[player.CSteamID]; | ||
var tipo = info.type.ToLower(); | ||
if (tipo.Contains("backpack")) | ||
{ | ||
cosmetics.Backpack = info.itemdefid; | ||
} | ||
else if (tipo.Contains("glasses")) | ||
{ | ||
cosmetics.Glass = info.itemdefid; | ||
} | ||
else if (tipo.Contains("hat")) | ||
{ | ||
cosmetics.Hat = info.itemdefid; | ||
} | ||
else if (tipo.Contains("mask")) | ||
{ | ||
cosmetics.Mask = info.itemdefid; | ||
} | ||
else if (tipo.Contains("pants")) | ||
{ | ||
cosmetics.Pants = info.itemdefid; | ||
} | ||
else if (tipo.Contains("shirt")) | ||
{ | ||
cosmetics.Shirt = info.itemdefid; | ||
} | ||
else if (tipo.Contains("vest")) | ||
{ | ||
cosmetics.Vest = info.itemdefid; | ||
} | ||
else if(tipo.Contains("skin")) | ||
{ | ||
if(cosmetics.Skins == null) | ||
{ | ||
cosmetics.Skins = new List<int>(); | ||
} | ||
cosmetics.Skins.Add(info.itemdefid); | ||
} | ||
UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("AddCos", info.name), AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
AdvancedCosmetics/Commands/RemoveCustomCosmeticsCommand.cs
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,43 @@ | ||
using Rocket.API; | ||
using Rocket.Unturned.Chat; | ||
using Rocket.Unturned.Player; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdvancedCosmetics.Commands | ||
{ | ||
public class RemoveCustomCosmeticsCommand : IRocketCommand | ||
{ | ||
public AllowedCaller AllowedCaller => AllowedCaller.Player; | ||
|
||
public string Name => "removecustomcosmetics"; | ||
|
||
public string Help => "A command to remove the custom cosmetics"; | ||
|
||
public string Syntax => "/removecustomcosmetics"; | ||
|
||
public List<string> Aliases => new List<string> | ||
{ | ||
"removecosmetics", | ||
}; | ||
|
||
public List<string> Permissions => new List<string>(); | ||
|
||
public void Execute(IRocketPlayer caller, string[] command) | ||
{ | ||
var player = (UnturnedPlayer)caller; | ||
if (AdvancedCosmetics.Instance.Cosmetics.ContainsKey(player.CSteamID)) | ||
{ | ||
AdvancedCosmetics.Instance.Cosmetics.Remove(player.CSteamID); | ||
UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("RemovedCos"), AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
else | ||
{ | ||
UnturnedChat.Say(player, AdvancedCosmetics.Instance.Translate("NotSetUp"), AdvancedCosmetics.Instance.MessageColor); | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
using Rocket.API; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdvancedCosmetics | ||
{ | ||
public class Configuration : IRocketPluginConfiguration | ||
{ | ||
public string MessageColor; | ||
public void LoadDefaults() | ||
{ | ||
MessageColor = "magenta"; | ||
} | ||
} | ||
} |
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,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdvancedCosmetics.Models | ||
{ | ||
public class Cosmetic | ||
{ | ||
public int Backpack { get; set; } | ||
public int Glass { get; set; } | ||
public int Hat { get; set; } | ||
public int Mask { get; set; } | ||
public int Pants { get; set; } | ||
public int Shirt { get; set; } | ||
public int Vest { get; set; } | ||
public List<int> Skins { get; set; } | ||
} | ||
} |
Oops, something went wrong.