Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2] Make properties async #76

Merged
merged 12 commits into from
Mar 9, 2019
Merged
Prev Previous commit
Next Next commit
Fix async errors in example resource and commands
markatk committed Mar 9, 2019
commit e263c37ad02acbb10279abfaa7c3678ba6111122
4 changes: 2 additions & 2 deletions src/AlternateLife.RageMP.Net.Example/Server/CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public class CommandHandler : ICommandHandler
[Command("vehicle")]
public async Task Vehicle(IPlayer player, VehicleHash vehicleName)
{
var vehicle = await MP.Vehicles.NewAsync(vehicleName, player.Position);
var vehicle = await MP.Vehicles.NewAsync(vehicleName, await player.GetPositionAsync());

await player.PutIntoVehicleAsync(vehicle, -1);

@@ -48,7 +48,7 @@ public async Task PrintArguments(IPlayer player, string[] arguments)
return;
}

player.Model = result;
await player.SetModelAsync(result);

await player.OutputChatBoxAsync($"Skin changed to \"{result}\"!");
}
18 changes: 7 additions & 11 deletions src/AlternateLife.RageMP.Net.Example/Server/ExampleResource.cs
Original file line number Diff line number Diff line change
@@ -33,25 +33,21 @@ public Task OnStopAsync()
return Task.CompletedTask;
}

private Task OnPlayerJoin(IPlayer player)
private async Task OnPlayerJoin(IPlayer player)
{
MP.Logger.Info($"Player {player.SocialClubName} ({player.Ip}) joined!");

return Task.CompletedTask;
MP.Logger.Info($"Player {await player.GetSocialClubNameAsync()} ({await player.GetIpAsync()}) joined!");
}

private Task OnPlayerReady(IPlayer player)
private async Task OnPlayerReady(IPlayer player)
{
player.Dimension = MP.GlobalDimension;
await player.SetDimensionAsync(MP.GlobalDimension);

MP.Logger.Info($"Player {player.SocialClubName} ({player.Ip}) is ready now.");

return Task.CompletedTask;
MP.Logger.Info($"Player {await player.GetSocialClubNameAsync()} ({await player.GetIpAsync()}) is ready now.");
}

private Task OnPlayerDeath(IPlayer player, uint reason, IPlayer killerplayer)
private async Task OnPlayerDeath(IPlayer player, uint reason, IPlayer killerplayer)
{
return player.SpawnAsync(player.Position, player.Heading);
await player.SpawnAsync(await player.GetPositionAsync(), await player.GetHeadingAsync());
}
}
}
2 changes: 1 addition & 1 deletion src/AlternateLife.RageMP.Net/Elements/Entities/Blip.cs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ public async Task<float> GetDrawDistanceAsync()
return await _plugin.Schedule(() => Rage.Blip.Blip_GetDrawDistance(NativePointer)).ConfigureAwait(false);
}

public new async Task SetRotationAsync(int value)
public async Task SetRotationAsync(int value)
{
CheckExistence();

Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ namespace AlternateLife.RageMP.Net.Elements.Entities
{
internal partial class Player
{
public new async Task SetModelAsync(PedHash value)
public async Task SetModelAsync(PedHash value)
{
CheckExistence();

2 changes: 1 addition & 1 deletion src/AlternateLife.RageMP.Net/Interfaces/IBlip.cs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public interface IBlip : IEntity
/// </summary>
/// <param name="rotation">New rotation of the blip</param>
/// <exception cref="EntityDeletedException">This entity was deleted before</exception>
new Task SetRotationAsync(int rotation);
Task SetRotationAsync(int rotation);

/// <summary>
/// Get the rotation of the blip.
2 changes: 1 addition & 1 deletion src/AlternateLife.RageMP.Net/Interfaces/IPlayer.cs
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ public interface IPlayer : IEntity
/// </summary>
/// <param name="model">New model of the player</param>
/// <exception cref="EntityDeletedException">This entity was deleted before</exception>
new Task SetModelAsync(PedHash model);
Task SetModelAsync(PedHash model);

/// <summary>
/// Get the model of the player.
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ private async Task ExecuteReflectionCommand(IPlayer player, ReflectionCommand re
}
catch (Exception e)
{
_logger.Error($"An error occured when player {player.Name} executed command: {reflectionCommand.Name}: ", e);
_logger.Error($"An error occured when player {await player.GetNameAsync()} executed command: {reflectionCommand.Name}: ", e);
}
}

@@ -242,7 +242,7 @@ private async Task ExecuteDelegateCommand(IPlayer player, DelegateCommand delega
}
catch (Exception e)
{
_logger.Error($"An error occured when player {player.Name} executed command: {delegateCommand.Name}: ", e);
_logger.Error($"An error occured when player {await player.GetNameAsync()} executed command: {delegateCommand.Name}: ", e);
}
}