Skip to content
This repository was archived by the owner on Jan 16, 2020. It is now read-only.

Commit da1a880

Browse files
committed
Update examples
1 parent 1c975d6 commit da1a880

11 files changed

Lines changed: 56 additions & 207 deletions

File tree

Rocket.Core/Logging/BaseLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class BaseLogger : ILogger
2222
typeof(LoggingExtensions),
2323
typeof(StdConsoleUserManager),
2424
typeof(UserExtensions),
25-
typeof(PlayerExtensions),
25+
typeof(EntityExtensions),
2626
};
2727

2828
private static readonly ICollection<MethodBase> ignoredLoggingMethods = new HashSet<MethodBase>

Rocket.Core/Player/PlayerExtensions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Rocket.API.Entities;
34
using Rocket.API.Permissions;
45
using Rocket.API.Player;
56
using Rocket.API.User;
67
using Rocket.Core.Extensions;
78

89
namespace Rocket.Core.Player
910
{
10-
public static class PlayerExtensions
11+
public static class EntityExtensions
1112
{
1213
public static Task<bool> KickAsync(this IPlayer player, IUser kickedBy = null, string reason = null)
1314
{
@@ -56,5 +57,11 @@ public static IUser GetUser(this IPlayer player)
5657
{
5758
return player.GetPrivateProperty<IUser>("User");
5859
}
60+
61+
62+
public static IEntity GetEntity(this IPlayer player)
63+
{
64+
return player.GetPrivateProperty<IEntity>("Entity");
65+
}
5966
}
6067
}

Rocket.Core/User/UserExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Collections.Generic;
55
using System.Threading.Tasks;
66
using Rocket.API.Permissions;
7+
using Rocket.API.Player;
8+
using Rocket.Core.Extensions;
79

810
namespace Rocket.Core.User
911
{
@@ -102,5 +104,10 @@ public static async Task<PermissionResult> CheckHasAllPermissionsAsync(this IUse
102104
var permissionProvider = user.Container.Resolve<IPermissionProvider>();
103105
return await permissionProvider.CheckHasAllPermissionsAsync(user, permissions);
104106
}
107+
108+
public static IPlayer GetPlayer(this IUser user)
109+
{
110+
return user.GetPrivateProperty<IPlayer>("Player");
111+
}
105112
}
106113
}
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
using Rocket.API.Commands;
1+
using System.Threading.Tasks;
2+
using Rocket.API.Commands;
23
using Rocket.API.Entities;
34
using Rocket.API.I18N;
45
using Rocket.API.Player;
56
using Rocket.API.User;
67
using Rocket.Core.Commands;
8+
using Rocket.Core.Player;
79
using Rocket.Core.User;
810

9-
namespace Rocket.Examples.CommandsPlugin
11+
namespace Rocket.Examples.CommandsExample
1012
{
1113
public class CommandsCollection
1214
{
@@ -20,20 +22,20 @@ public CommandsCollection(IUserManager userManager, ITranslationCollection trans
2022
}
2123

2224
[Command(Summary = "Kills a player.")] //By default, name is the same as the method name, and it will support all command callers
23-
public void KillPlayer(IUser sender, IPlayer target)
25+
public async Task KillPlayer(IUser sender, IPlayer target)
2426
{
25-
if (target.IsOnline && target.Entity is ILivingEntity entity)
26-
entity.Kill(sender);
27+
if (target.IsOnline && target.GetEntity() is ILivingEntity entity)
28+
await entity.KillAsync(sender);
2729
else // the game likely does not support killing players (e.g. Eco)
28-
sender.SendMessage("Target could not be killed :(");
30+
await sender.SendMessageAsync("Target could not be killed :(");
2931
}
3032

3133
[Command(Name = "Broadcast", Summary = "Broadcasts a message.")]
3234
[CommandAlias("bc")]
3335
[CommandUser(typeof(IConsole))] // only console can call it
3436
public void Broadcast(IUser sender, string[] args)
3537
{
36-
userManager.Broadcast(sender, translations.Get("broadcast", sender, string.Join(" ", args)));
38+
userManager.BroadcastAsync(sender, translations.GetAsync("broadcast", sender, string.Join(" ", args)).Result);
3739
}
3840
}
3941
}
Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
42
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{AF4E374A-89FB-4364-8BB6-E5E1A3A10EC7}</ProjectGuid>
3+
<TargetFrameworks>net461</TargetFrameworks>
4+
<AssemblyName>Rocket.Examples.CommandsExample</AssemblyName>
5+
<Description>Example project for Rocket commands</Description>
6+
<RootNamespace>Rocket.Examples.CommandsExample</RootNamespace>
87
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>Rocket.Examples.CommandsPlugin</RootNamespace>
11-
<AssemblyName>CommandsExample</AssemblyName>
12-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
149
</PropertyGroup>
15-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16-
<DebugSymbols>true</DebugSymbols>
17-
<DebugType>full</DebugType>
18-
<Optimize>false</Optimize>
19-
<OutputPath>bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21-
<ErrorReport>prompt</ErrorReport>
22-
<WarningLevel>4</WarningLevel>
23-
</PropertyGroup>
24-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<DebugType>pdbonly</DebugType>
26-
<Optimize>true</Optimize>
27-
<OutputPath>bin\Release\</OutputPath>
28-
<DefineConstants>TRACE</DefineConstants>
29-
<ErrorReport>prompt</ErrorReport>
30-
<WarningLevel>4</WarningLevel>
31-
</PropertyGroup>
32-
<ItemGroup>
33-
<Reference Include="System" />
34-
<Reference Include="System.Core" />
35-
<Reference Include="System.Xml.Linq" />
36-
<Reference Include="System.Data.DataSetExtensions" />
37-
<Reference Include="System.Data" />
38-
<Reference Include="System.Xml" />
39-
</ItemGroup>
40-
<ItemGroup>
41-
<Compile Include="CommandsPlugin.cs" />
42-
<Compile Include="CommandsCollection.cs" />
43-
<Compile Include="Properties\AssemblyInfo.cs" />
44-
<Compile Include="SetHealthCommand.cs" />
45-
</ItemGroup>
4610
<ItemGroup>
47-
<ProjectReference Include="..\..\Rocket.API\Rocket.API.csproj">
48-
<Project>{da356abb-aa77-4b22-9ab1-34a30cf4048a}</Project>
49-
<Name>Rocket.API</Name>
50-
</ProjectReference>
51-
<ProjectReference Include="..\..\Rocket.Compatibility\Rocket.Compatibility.csproj">
52-
<Project>{01263b0d-9ce3-4d5a-afcb-165592ef24b5}</Project>
53-
<Name>Rocket.Compatibility</Name>
54-
</ProjectReference>
55-
<ProjectReference Include="..\..\Rocket.Core\Rocket.Core.csproj">
56-
<Project>{a7056ab1-c5f5-493b-8e47-dc42de69961d}</Project>
57-
<Name>Rocket.Core</Name>
58-
</ProjectReference>
59-
</ItemGroup>
60-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
11+
<ProjectReference Include="..\..\Rocket.API\Rocket.API.csproj" />
12+
<ProjectReference Include="..\..\Rocket.Compatibility\Rocket.Compatibility.csproj" />
13+
<ProjectReference Include="..\..\Rocket.Core\Rocket.Core.csproj" />
14+
</ItemGroup>
6115
</Project>

examples/commands/CommandsPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Rocket.API.User;
44
using Rocket.Core.Plugins;
55

6-
namespace Rocket.Examples.CommandsPlugin
6+
namespace Rocket.Examples.CommandsExample
77
{
88
public class CommandsPlugin : Plugin
99
{

examples/commands/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
1+
using System.Threading.Tasks;
22
using Rocket.API.Commands;
33
using Rocket.API.Entities;
44
using Rocket.API.Player;
55
using Rocket.API.User;
6+
using Rocket.Core.Player;
67
using Rocket.Core.User;
78

8-
namespace Rocket.Examples.CommandsPlugin
9+
namespace Rocket.Examples.CommandsExample
910
{
1011
public class SetHealthCommand : ICommand
1112
{
@@ -17,17 +18,17 @@ public class SetHealthCommand : ICommand
1718
public IChildCommand[] ChildCommands => null;
1819
public string[] Aliases => new[] {"sh"};
1920

20-
public bool SupportsUser(Type user) => true;
21+
public bool SupportsUser(IUser user) => true;
2122

22-
public void Execute(ICommandContext context)
23+
public async Task ExecuteAsync(ICommandContext context)
2324
{
24-
IPlayer target = context.Parameters.Get<IPlayer>(0); // target player is first parameter
25-
double health = context.Parameters.Get<double>(1); // health is second parameter
25+
IPlayer target = await context.Parameters.GetAsync<IPlayer>(0); // target player is first parameter
26+
double health = await context.Parameters.GetAsync<double>(1); // health is second parameter
2627

27-
if (target.IsOnline && target.Entity is ILivingEntity entity)
28+
if (target.IsOnline && target.GetEntity() is ILivingEntity entity)
2829
entity.Health = health;
2930
else // the game likely does not support killing players (e.g. Eco)
30-
context.User.SendMessage("Target could not be killed :(");
31+
await context.User.SendMessageAsync("Target could not be killed :(");
3132
}
3233
}
3334
}

examples/hello_world/HelloWorldPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Rocket.Core.Logging;
44
using Rocket.Core.Plugins;
55

6-
namespace Rocket.Examples.HelloWorldPlugin
6+
namespace Rocket.Examples.HelloWorld
77
{
88
public class HelloWorldPlugin : Plugin
99
{
Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,15 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{31BA2AC3-EF06-430F-8008-61D16FD567B5}</ProjectGuid>
3+
<TargetFrameworks>net461</TargetFrameworks>
4+
<AssemblyName>Rocket.Examples.HelloWorld</AssemblyName>
5+
<Description>Example "Hello world" project for RocketMod</Description>
6+
<RootNamespace>Rocket.Examples.HelloWorld</RootNamespace>
97
<OutputType>Library</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>Rocket.Examples.HelloWorldPlugin</RootNamespace>
12-
<AssemblyName>HelloWorldPlugin</AssemblyName>
13-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14-
<FileAlignment>512</FileAlignment>
8+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
159
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<DebugSymbols>true</DebugSymbols>
18-
<DebugType>full</DebugType>
19-
<Optimize>false</Optimize>
20-
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
22-
<ErrorReport>prompt</ErrorReport>
23-
<WarningLevel>4</WarningLevel>
24-
</PropertyGroup>
25-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26-
<DebugType>pdbonly</DebugType>
27-
<Optimize>true</Optimize>
28-
<OutputPath>bin\Release\</OutputPath>
29-
<DefineConstants>TRACE</DefineConstants>
30-
<ErrorReport>prompt</ErrorReport>
31-
<WarningLevel>4</WarningLevel>
32-
</PropertyGroup>
33-
<ItemGroup>
34-
<Reference Include="System" />
35-
<Reference Include="System.Core" />
36-
<Reference Include="System.Xml.Linq" />
37-
<Reference Include="System.Data.DataSetExtensions" />
38-
<Reference Include="System.Data" />
39-
<Reference Include="System.Xml" />
40-
</ItemGroup>
41-
<ItemGroup>
42-
<Compile Include="HelloWorldPlugin.cs" />
43-
<Compile Include="Properties\AssemblyInfo.cs" />
44-
</ItemGroup>
4510
<ItemGroup>
46-
<ProjectReference Include="..\..\Rocket.API\Rocket.API.csproj">
47-
<Project>{da356abb-aa77-4b22-9ab1-34a30cf4048a}</Project>
48-
<Name>Rocket.API</Name>
49-
</ProjectReference>
50-
<ProjectReference Include="..\..\Rocket.Compatibility\Rocket.Compatibility.csproj">
51-
<Project>{01263b0d-9ce3-4d5a-afcb-165592ef24b5}</Project>
52-
<Name>Rocket.Compatibility</Name>
53-
</ProjectReference>
54-
<ProjectReference Include="..\..\Rocket.Core\Rocket.Core.csproj">
55-
<Project>{a7056ab1-c5f5-493b-8e47-dc42de69961d}</Project>
56-
<Name>Rocket.Core</Name>
57-
</ProjectReference>
58-
</ItemGroup>
59-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
60-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
61-
Other similar extension points exist, see Microsoft.Common.targets.
62-
<Target Name="BeforeBuild">
63-
</Target>
64-
<Target Name="AfterBuild">
65-
</Target>
66-
-->
11+
<ProjectReference Include="..\..\Rocket.API\Rocket.API.csproj" />
12+
<ProjectReference Include="..\..\Rocket.Compatibility\Rocket.Compatibility.csproj" />
13+
<ProjectReference Include="..\..\Rocket.Core\Rocket.Core.csproj" />
14+
</ItemGroup>
6715
</Project>

0 commit comments

Comments
 (0)