-
Notifications
You must be signed in to change notification settings - Fork 0
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
Setpopa
authored and
Setpopa
committed
Aug 13, 2023
1 parent
41df087
commit d9d3100
Showing
12 changed files
with
406 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,17 @@ | ||
using OpenMod.API.Commands; | ||
using OpenMod.API.Ioc; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewCommandMerger.API | ||
{ | ||
[Service] | ||
public interface ICommandSourceController | ||
{ | ||
Task<IReadOnlyCollection<ICommandRegistration>> GetCommandsAsync(); | ||
|
||
Task AddCommandAsync(ICommandRegistration registration); | ||
|
||
Task InvalidateAsync(); | ||
} | ||
} |
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,40 @@ | ||
using Cysharp.Threading.Tasks; | ||
using OpenMod.Unturned.Commands; | ||
using OpenMod.Unturned.Users; | ||
using System; | ||
using Rocket.Core; | ||
using NewCommandMerger.RegistrationComponents; | ||
using OpenMod.API.Commands; | ||
using OpenMod.Core.Helpers; | ||
using Rocket.Unturned.Player; | ||
|
||
namespace NewCommandMerger.Commands | ||
{ | ||
internal class CommandMerged : UnturnedCommand | ||
{ | ||
private readonly ICommandExecutor m_commandExecutor; | ||
private readonly CommandMergedData _commandMergedData; | ||
public CommandMerged(CommandMergedData commandMergedData, ICommandExecutor commandExecutor, IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
_commandMergedData = commandMergedData; | ||
m_commandExecutor = commandExecutor; | ||
} | ||
|
||
protected override async UniTask OnExecuteAsync() | ||
{ | ||
var user = (UnturnedUser)Context.Actor; | ||
|
||
await UniTask.SwitchToMainThread(); | ||
|
||
foreach (string rmCommand in _commandMergedData.RocketModCommands) | ||
{ | ||
R.Commands.Execute(UnturnedPlayer.FromPlayer(user.Player.Player), rmCommand); | ||
} | ||
foreach (string omCommand in _commandMergedData.OpenModCommands) | ||
{ | ||
await m_commandExecutor.ExecuteAsync(Context.Actor, ArgumentsParser.ParseArguments(omCommand), ""); | ||
} | ||
|
||
} | ||
} | ||
} |
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 @@ | ||
| ||
namespace NewCommandMerger.Config | ||
{ | ||
public class CommandMergerConfig | ||
{ | ||
public string CommandName { get; set; } | ||
public string[] RocketModCommands { get; set; } | ||
public string[] OpenModCommands { get; set; } | ||
|
||
public CommandMergerConfig() | ||
{ | ||
CommandName = ""; | ||
RocketModCommands = new string[0]; | ||
OpenModCommands = new string[0]; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
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,59 @@ | ||
using System; | ||
using OpenMod.Unturned.Plugins; | ||
using Cysharp.Threading.Tasks; | ||
using NewCommandMerger.API; | ||
using NewCommandMerger.Config; | ||
using NewCommandMerger.RegistrationComponents; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Configuration; | ||
using OpenMod.API.Plugins; | ||
using YamlDotNet.Core.Tokens; | ||
|
||
[assembly: PluginMetadata("NewCommandMerger", | ||
DisplayName = "NewCommandMerger", | ||
Author = "Huge thanks to SilK I used most of his code", | ||
Website = "")] | ||
namespace NewCommandMerger | ||
{ | ||
public class NewCommandMerger : OpenModUnturnedPlugin | ||
{ | ||
private readonly IConfiguration m_configuration; | ||
private readonly ICommandSourceController m_commandSourceController; | ||
private readonly ILogger<NewCommandMerger> m_Logger; | ||
|
||
|
||
public NewCommandMerger(ICommandSourceController commandSourceController,IConfiguration configuration, ILogger<NewCommandMerger> logger, IServiceProvider serviceProvider) : base(serviceProvider) | ||
{ | ||
m_configuration = configuration; | ||
m_commandSourceController = commandSourceController; | ||
m_Logger = logger; | ||
} | ||
|
||
protected override async UniTask OnLoadAsync() | ||
{ | ||
var commands = m_configuration.GetSection("commands").Get<CommandMergerConfig[]?>(); | ||
|
||
if (commands != null) | ||
{ | ||
m_Logger.LogInformation("Config loaded!"); | ||
foreach (var config in commands) | ||
{ | ||
m_Logger.LogInformation($"Registrating command {config.CommandName}! With {config.RocketModCommands.Length} RocketMod commands. And {config.OpenModCommands.Length} Openmod commands!"); | ||
await m_commandSourceController.AddCommandAsync(new CommandMergedRegistration(this, config)); | ||
} | ||
|
||
await m_commandSourceController.InvalidateAsync(); | ||
} | ||
else | ||
{ | ||
m_Logger.LogWarning("Empty config or something went wrong."); | ||
} | ||
|
||
} | ||
|
||
protected override UniTask OnUnloadAsync() | ||
{ | ||
return UniTask.CompletedTask; | ||
} | ||
} | ||
} |
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,63 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>NewCommandMerger</PackageId> | ||
<PackageDescription>Merge Rocked Mods and OpenMods commands to one.</PackageDescription> | ||
<PackageAuthor>Setpopa</PackageAuthor> | ||
<TargetFramework>net461</TargetFramework> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageTags>openmod openmod-plugin unturned</PackageTags> | ||
<RootNamespace>NewCommandMerger</RootNamespace> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<GenerateNugetPackage>true</GenerateNugetPackage> | ||
<Product>NewCommandMerger</Product> | ||
<Nullable>enable</Nullable> | ||
<WarningsAsErrors>nullable</WarningsAsErrors> | ||
<NoWarn>$(NoWarn);NU1701;NU1702;CS0436</NoWarn> | ||
<Version>1.0.0</Version> | ||
<InformationalVersion>1.0.0</InformationalVersion> | ||
<PackageVersion>1.0.0</PackageVersion> | ||
<LangVersion>9.0</LangVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OpenMod.Unturned" Version="3.5.0+7527c861" /> | ||
<PackageReference Include="Legacy2CPSWorkaround" Version="1.0.0"> | ||
<PrivateAssets>All</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="1.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="config.yaml" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Rocket.API"> | ||
<HintPath>..\..\..\Desktop\CommandScheduler\Libraries\Rocket.API.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rocket.Core"> | ||
<HintPath>..\..\..\Desktop\CommandScheduler\Libraries\Rocket.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Rocket.Unturned"> | ||
<HintPath>..\..\..\Desktop\CommandScheduler\Libraries\Rocket.Unturned.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
<Target Name="ChangeAliasesOfNugetRefs" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences"> | ||
<ItemGroup> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.6.33829.357 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewCommandMerger", "NewCommandMerger.csproj", "{664C7E84-55D3-4962-A2A5-2491CCB614B7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{664C7E84-55D3-4962-A2A5-2491CCB614B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{664C7E84-55D3-4962-A2A5-2491CCB614B7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{664C7E84-55D3-4962-A2A5-2491CCB614B7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{664C7E84-55D3-4962-A2A5-2491CCB614B7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C08EC4C0-C750-4698-B879-D916130E3E21} | ||
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,17 @@ | ||
| ||
using UnityEngine.Android; | ||
|
||
namespace NewCommandMerger.RegistrationComponents | ||
{ | ||
internal class CommandMergedData | ||
{ | ||
public string[] RocketModCommands { get; set; } | ||
|
||
public string[] OpenModCommands { get; set; } | ||
public CommandMergedData() { | ||
|
||
RocketModCommands = new string[] {}; | ||
OpenModCommands = new string[] { }; | ||
} | ||
} | ||
} |
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 @@ | ||
using OpenMod.API; | ||
using OpenMod.API.Commands; | ||
using OpenMod.API.Permissions; | ||
using OpenMod.API.Prioritization; | ||
using OpenMod.Core.Ioc; | ||
using OpenMod.Unturned.Users; | ||
using System; | ||
using System.Collections.Generic; | ||
using NewCommandMerger.Config; | ||
using NewCommandMerger.Commands; | ||
|
||
namespace NewCommandMerger.RegistrationComponents | ||
{ | ||
internal class CommandMergedRegistration : ICommandRegistration | ||
{ | ||
private readonly CommandMergedData _commandMergedData; | ||
|
||
public CommandMergedRegistration(IOpenModComponent component, CommandMergerConfig config) | ||
{ | ||
Component = component; | ||
|
||
Id = $"{component.OpenModComponentId}.{config.CommandName}"; | ||
Name = config.CommandName; | ||
Description = ""; | ||
Priority = Priority.High; | ||
|
||
_commandMergedData = new CommandMergedData | ||
{ | ||
RocketModCommands = config.RocketModCommands, | ||
OpenModCommands = config.OpenModCommands | ||
}; | ||
|
||
IsEnabled = true; | ||
|
||
Description = null; | ||
Aliases = null; | ||
PermissionRegistrations = null; | ||
Syntax = null; | ||
ParentId = null; | ||
} | ||
|
||
public IOpenModComponent Component { get; } | ||
|
||
public string Id { get; } | ||
|
||
public string Name { get; } | ||
|
||
public IReadOnlyCollection<string>? Aliases { get; } | ||
|
||
public IReadOnlyCollection<IPermissionRegistration>? PermissionRegistrations { get; } | ||
|
||
public string? Description { get; } | ||
|
||
public string? Syntax { get; } | ||
|
||
public Priority Priority { get; } | ||
|
||
public string? ParentId { get; } | ||
|
||
public bool IsEnabled { get; } | ||
|
||
public ICommand Instantiate(IServiceProvider serviceProvider) | ||
{ | ||
return ActivatorUtilitiesEx.CreateInstance<CommandMerged>(Component.LifetimeScope, _commandMergedData); | ||
} | ||
|
||
public bool SupportsActor(ICommandActor actor) | ||
{ | ||
return actor is UnturnedUser; | ||
} | ||
} | ||
} |
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 OpenMod.API.Commands; | ||
using System.Collections.Generic; | ||
using NewCommandMerger.API; | ||
using System.Threading.Tasks; | ||
|
||
namespace NewCommandMerger.RegistrationComponents | ||
{ | ||
internal class CommandMergedSource : ICommandSource | ||
{ | ||
private readonly ICommandSourceController _commandSourceController; | ||
public CommandMergedSource(ICommandSourceController commandSourceController) | ||
{ | ||
_commandSourceController = commandSourceController; | ||
} | ||
public Task<IReadOnlyCollection<ICommandRegistration>> GetCommandsAsync() | ||
{ | ||
return _commandSourceController.GetCommandsAsync(); | ||
} | ||
} | ||
} |
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,42 @@ | ||
using OpenMod.API.Commands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NewCommandMerger.API; | ||
using OpenMod.API.Prioritization; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OpenMod.API.Ioc; | ||
|
||
namespace NewCommandMerger.RegistrationComponents | ||
{ | ||
[ServiceImplementation(Lifetime = ServiceLifetime.Singleton, Priority = Priority.Lowest)] | ||
internal class CommandSourceController : ICommandSourceController | ||
{ | ||
private readonly Lazy<ICommandStore> _commandStore; | ||
private readonly List<ICommandRegistration> _registrations; | ||
|
||
public CommandSourceController(Lazy<ICommandStore> commandStore) | ||
{ | ||
_commandStore = commandStore; | ||
|
||
_registrations = new List<ICommandRegistration>(); | ||
} | ||
|
||
public Task AddCommandAsync(ICommandRegistration registration) | ||
{ | ||
_registrations.Add(registration); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<IReadOnlyCollection<ICommandRegistration>> GetCommandsAsync() | ||
{ | ||
return Task.FromResult((IReadOnlyCollection<ICommandRegistration>)_registrations); | ||
} | ||
|
||
public Task InvalidateAsync() | ||
{ | ||
return _commandStore.Value.InvalidateAsync(); | ||
} | ||
} | ||
} |
Oops, something went wrong.