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

Core Systems Refactor #377

Merged
merged 83 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ebe3d76
Remove "Services"
Tides Jun 7, 2023
5be58dd
Add logging to service collection
Tides Jun 7, 2023
4f3a2cc
Refactor plugin related classes to use DI
Tides Jun 7, 2023
1fc8d4c
Some code cleanup
Tides Jun 7, 2023
4ea9b10
Inject service provider to Server.cs
Tides Jun 7, 2023
318915c
Update sample plugin
Tides Jun 7, 2023
59ced23
Merge branch 'master' into plugin-manager-cleanup
Tides Jun 7, 2023
e609782
Merge branch 'master' into plugin-manager-cleanup
Tides Jun 9, 2023
e555e8f
Merge branch 'master' into plugin-manager-cleanup
Tides Jun 10, 2023
cf0e79c
A little refactor
Tides Jun 11, 2023
e002e79
Initial impl using Microsofts DI
Tides Jun 11, 2023
4b25396
Merge branch 'master' into plugin-manager-cleanup
Tides Jun 11, 2023
b06a428
Some cleanup
Tides Jun 16, 2023
4b5b8b7
Merge branch 'master' into plugin-manager-cleanup
Tides Dec 11, 2023
1abfd35
Fix logging stuff :)))
Tides Dec 11, 2023
d350298
Fix error
Tides Dec 11, 2023
b3c26fb
Little refactors
Tides Dec 11, 2023
eee6612
Update dependencies
Tides Dec 11, 2023
4380f81
Make PluginBase inherit IAsync/Disposable
Tides Dec 13, 2023
6a671a7
Refactors
Tides Dec 13, 2023
fd841a5
Start reworking plugin manager
Tides Dec 13, 2023
011088d
Remove plugin wrapper and anything to do with reflection
Tides Dec 13, 2023
831149b
Fix errors
Tides Dec 13, 2023
de2668d
More refactors
Tides Dec 13, 2023
de1a7f7
IPluginConfigurationManager -> IPluginRegistry
Tides Dec 14, 2023
85d18fe
More plugin registry cleanup
Tides Dec 15, 2023
b6b11bb
Start organizing/fixing all things to do with commands
Tides Dec 15, 2023
58575a1
PluginContainer now manages service injection
Tides Dec 16, 2023
1504a2f
Update SamplePlugin.csproj
Tides Dec 16, 2023
489cefb
Fix up commands
Tides Dec 18, 2023
1bb5279
Merge branch 'master' into plugin-manager-cleanup
Tides Dec 22, 2023
44657d9
ObjectMethodExecutor
Tides Dec 22, 2023
812424d
Cleanup
Tides Dec 22, 2023
77ac3f0
New event system pt. 1
Tides Dec 22, 2023
e229aa6
Fix build error :sob:
Tides Dec 22, 2023
05c4df7
Some organization
Tides Dec 26, 2023
107c766
Event stuff
Tides Dec 31, 2023
d9d7e52
Code cleanup
Tides Dec 31, 2023
29257ed
More cleanup
Tides Dec 31, 2023
3d3ab93
More cleanup
Tides Dec 31, 2023
21ae3f3
Update PluginBase.cs
Tides Dec 31, 2023
a78ad7f
Command refactor start
Tides Jan 18, 2024
bcad8a5
Re-do command execution
Tides Jan 18, 2024
d46fa12
Refactor
Tides Jan 18, 2024
c18f78b
PluginContainer can be null
Tides Jan 19, 2024
d7c187c
Fix plugins not registering data properly
Tides Jan 19, 2024
3d928b7
Commands now use ObjectMethodExecutor
Tides Jan 19, 2024
bd90f7d
Fix tests
Tides Jan 19, 2024
9fd8809
SamplePlugin cleanup
Tides Jan 19, 2024
43b0b3e
Command framework refactor completed
Tides Jan 19, 2024
f5050a0
Fix arguments not parsing correctly
Tides Jan 19, 2024
5a1a5c5
Update SamplePlugin.cs
Tides Jan 19, 2024
fad759c
Code cleanup
Tides Jan 19, 2024
3690000
Update SamplePlugin.cs
Tides Jan 19, 2024
c8c6685
Cleanup events (they work now)
Tides Jan 20, 2024
f155f6a
Move chat message event stuff
Tides Jan 20, 2024
03fbe4e
Use EventDispatcher for all events
Tides Jan 20, 2024
5261ef0
Some more cleanup
Tides Jan 20, 2024
872cc78
Remove overridable name property
Tides Jan 20, 2024
d0fb738
Update EventDispatcher.cs
Tides Jan 20, 2024
48f5e66
Fix errors
Tides Jan 20, 2024
34b4833
Update EventDispatcher.cs
Tides Jan 20, 2024
342a981
Try catch around HostedServices
Tides Jan 20, 2024
c05fb21
Code cleanup
Tides Jan 20, 2024
ca91b91
Merge branch 'master' into plugin-manager-cleanup
Tides Jan 24, 2024
b353202
Create IExecutor.cs
Tides Jan 24, 2024
f761e26
Use IExecutor for commands
Tides Jan 24, 2024
b265481
Use IExecutor for events
Tides Jan 24, 2024
c01ded3
Fix commands
Tides Jan 24, 2024
f6bd096
Whoopsie
Tides Jan 24, 2024
cd879a6
Fix delegate commands not reading params properly
Tides Jan 24, 2024
c5f2e48
Fix event dispatcher :sweat_smile:
Tides Jan 24, 2024
371ac05
Cleanup argument parsers
Tides Jan 25, 2024
2012274
Code cleanup
Tides Jan 25, 2024
be861e8
Only return when fetching relative pos
Tides Jan 25, 2024
73491ea
Assign player if valid guid
Tides Jan 25, 2024
bea06d5
Update Client.cs
Tides Jan 25, 2024
fbb742d
Code cleanup
Tides Jan 25, 2024
619eff1
Fix commands and commands tests
Tides Jan 26, 2024
b4efc52
Use DI
Tides Jan 26, 2024
5b91613
throw if we didn't find a valid executor
Tides Jan 26, 2024
f3f3a1a
Some more cleanup
Tides Jan 27, 2024
fa393cc
Merge branch 'master' into plugin-manager-cleanup
Tides Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Obsidian.Entities;
namespace Obsidian.API.Commands.ArgumentParsers;

namespace Obsidian.Commands.Parsers;

public class LocationTypeParser : BaseArgumentParser<VectorF>
public sealed class LocationArgumentParser : BaseArgumentParser<VectorF>
{
public LocationTypeParser() : base(10, "minecraft:vec3")
public LocationArgumentParser() : base(10, "minecraft:vec3")
{
}

public override bool TryParseArgument(string input, CommandContext context, out VectorF result)
{
var splitted = input.Split(' ');
var location = new VectorF();
var player = context.Player;

for (int i = 0; i < splitted.Length; i++)
for (var i = 0; i < splitted.Length; i++)
{
var text = splitted[i];
if (float.TryParse(text, out var floatResult))
Expand All @@ -31,25 +30,24 @@ public override bool TryParseArgument(string input, CommandContext context, out
default:
throw new IndexOutOfRangeException("Count went out of range");
}
else if (text.StartsWith("~"))
else if (text.StartsWith('~'))
{
if (context.Player is not Player player)
if (player is null)
{
result = default;
return false;
}

float.TryParse(text.Replace("~", ""), out float relative);
switch (i)
{
case 0:
location.X = player.Position.X + relative;
location.X = player.Position.X;
break;
case 1:
location.Y = player.Position.Y + relative;
location.Y = player.Position.Y;
break;
case 2:
location.Z = player.Position.Z + relative;
location.Z = player.Position.Z;
break;
default:
throw new IndexOutOfRangeException("Count went out of range");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
namespace Obsidian.API;
namespace Obsidian.API.Commands.ArgumentParsers;

public class SignedIntArgumentParser : BaseArgumentParser<int>
public sealed class SignedIntArgumentParser : BaseArgumentParser<int>
{
public SignedIntArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out int result)
=> int.TryParse(input, out result);
}

public class BoolArgumentParser : BaseArgumentParser<bool>
public sealed class BoolArgumentParser : BaseArgumentParser<bool>
{
public BoolArgumentParser() : base(0, "brigadier:bool") { }
public override bool TryParseArgument(string input, CommandContext ctx, out bool result)
=> bool.TryParse(input, out result);
}

public class UnsignedByteArgumentParser : BaseArgumentParser<byte>
public sealed class UnsignedByteArgumentParser : BaseArgumentParser<byte>
{
public UnsignedByteArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out byte result)
=> byte.TryParse(input, out result);
}

public class SignedByteArgumentParser : BaseArgumentParser<sbyte>
public sealed class SignedByteArgumentParser : BaseArgumentParser<sbyte>
{
public SignedByteArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out sbyte result)
=> sbyte.TryParse(input, out result);
}

public class SignedShortArgumentParser : BaseArgumentParser<short>
public sealed class SignedShortArgumentParser : BaseArgumentParser<short>
{
public SignedShortArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out short result)
=> short.TryParse(input, out result);
}

public class UnsignedShortArgumentParser : BaseArgumentParser<ushort>
public sealed class UnsignedShortArgumentParser : BaseArgumentParser<ushort>
{
public UnsignedShortArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out ushort result)
=> ushort.TryParse(input, out result);
}

public class UnsignedIntArgumentParser : BaseArgumentParser<uint>
public sealed class UnsignedIntArgumentParser : BaseArgumentParser<uint>
{
public UnsignedIntArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out uint result)
=> uint.TryParse(input, out result);
}

public class SignedLongArgumentParser : BaseArgumentParser<long>
public sealed class SignedLongArgumentParser : BaseArgumentParser<long>
{
public SignedLongArgumentParser() : base(3, "brigadier:long") { }
public override bool TryParseArgument(string input, CommandContext ctx, out long result)
=> long.TryParse(input, out result);
}

public class UnsignedLongArgumentParser : BaseArgumentParser<ulong>
public sealed class UnsignedLongArgumentParser : BaseArgumentParser<ulong>
{
public UnsignedLongArgumentParser() : base(4, "brigadier:long") { }
public override bool TryParseArgument(string input, CommandContext ctx, out ulong result)
=> ulong.TryParse(input, out result);
}

public class FloatArgumentParser : BaseArgumentParser<float>
public sealed class FloatArgumentParser : BaseArgumentParser<float>
{
public FloatArgumentParser() : base(1, "brigadier:float") { }
public override bool TryParseArgument(string input, CommandContext ctx, out float result)
=> float.TryParse(input, out result);
}
public class DoubleArgumentParser : BaseArgumentParser<double>
public sealed class DoubleArgumentParser : BaseArgumentParser<double>
{
public DoubleArgumentParser() : base(2, "brigadier:double") { }
public override bool TryParseArgument(string input, CommandContext ctx, out double result)
=> double.TryParse(input, out result);
}
public class DecimalArgumentParser : BaseArgumentParser<decimal>
public sealed class DecimalArgumentParser : BaseArgumentParser<decimal>
{
public DecimalArgumentParser() : base(3, "brigadier:integer") { }
public override bool TryParseArgument(string input, CommandContext ctx, out decimal result)
Expand Down
25 changes: 25 additions & 0 deletions Obsidian.API/Commands/ArgumentParsers/PlayerArgumentParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Obsidian.API.Commands.ArgumentParsers;

public class PlayerArgumentParser : BaseArgumentParser<IPlayer>
{
public PlayerArgumentParser() : base(7, "minecraft:game_profile")
{
}

//TODO support selectors
public override bool TryParseArgument(string input, CommandContext context, out IPlayer result)
{
var server = context.Server;
IPlayer? player = null;

if (Guid.TryParse(input, out var guid))
// is valid GUID, try find with guid
player = server.GetPlayer(guid);
else
// is not valid GUID, try find with name
player = server.GetPlayer(input);

result = player;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Obsidian.API;
namespace Obsidian.API.Commands.ArgumentParsers;

public class StringArgumentParser : BaseArgumentParser<string>
public sealed class StringArgumentParser : BaseArgumentParser<string>
{
public StringArgumentParser() : base(5, "brigadier:string") { }
public override bool TryParseArgument(string input, CommandContext ctx, out string result)
Expand All @@ -10,9 +10,9 @@ public override bool TryParseArgument(string input, CommandContext ctx, out stri
}
}

public class GuidArgumentParser : BaseArgumentParser<Guid>
public sealed class GuidArgumentParser : BaseArgumentParser<Guid>
{
public GuidArgumentParser() : base(47, "minecraft:uuid") { }
public GuidArgumentParser() : base(49, "minecraft:uuid") { }
public override bool TryParseArgument(string input, CommandContext ctx, out Guid result)
{
return Guid.TryParse(input, out result);
Expand Down
34 changes: 34 additions & 0 deletions Obsidian.API/Commands/CommandModuleBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Obsidian.API.Plugins;
using System.Diagnostics;

namespace Obsidian.API.Commands;
public abstract class CommandModuleBase
{
private CommandContext? commandContext;

[CommandContext]
public CommandContext CommandContext
{
get
{
if (commandContext == null)
throw new UnreachableException();//TODO empty command context maybe??
Naamloos marked this conversation as resolved.
Show resolved Hide resolved

return this.commandContext;
}
set
{
ArgumentNullException.ThrowIfNull(value);

this.commandContext = value;
}
}

public IPlayer? Player => this.CommandContext.Player;
public IServer Server => this.CommandContext.Server;
public ICommandSender Sender => this.CommandContext.Sender;

public bool IsPlayer => this.CommandContext.IsPlayer;

public PluginBase? Plugin => this.CommandContext.Plugin;
}
2 changes: 1 addition & 1 deletion Obsidian.API/Events/BaseMinecraftEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represents the base class for classes that contain minecraft event data.
/// </summary>
public class BaseMinecraftEventArgs : AsyncEventArgs
public abstract class BaseMinecraftEventArgs : AsyncEventArgs
{
/// <summary>
/// Server this event took place in.
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal Logger(string prefix, LogLevel minLevel = LogLevel.Debug)
Prefix = prefix;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
if (!IsEnabled(logLevel))
return;
Expand Down Expand Up @@ -64,7 +64,7 @@ void PrintLinePrefix()
var lines = message.Split('\n');

if (message.IsNullOrEmpty())
{
{
this.LogTrace($"Empty log message sent. Dumping stacktrace:\n{new StackTrace().ToString().Replace("\n", " ")}");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Obsidian.API/Obsidian.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="SharpNoise" Version="0.12.1.1" />
</ItemGroup>

Expand Down
34 changes: 0 additions & 34 deletions Obsidian.API/Plugins/DependencyAttribute.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Obsidian.API/Plugins/IPluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public interface IPluginInfo
public string Name { get; }
public Version Version { get; }
public string Description { get; }
public string Authors { get; }
public string[] Authors { get; }
public Uri ProjectUrl { get; }
}
19 changes: 19 additions & 0 deletions Obsidian.API/Plugins/IPluginRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Obsidian.API.Events;

namespace Obsidian.API.Plugins;
public interface IPluginRegistry
{
public IPluginRegistry RegisterCommandArgumentHandler<T>(T parser) where T : BaseArgumentParser;

public IPluginRegistry MapCommands();
public IPluginRegistry MapCommand(string name, Delegate contextDelegate);
public IPluginRegistry MapCommand(string name, ValueTaskContextDelegate<CommandContext> contextDelegate);

public IPluginRegistry MapEvent<TEventArgs>(ValueTaskContextDelegate<TEventArgs> contextDelegate, Priority priority = Priority.Low) where TEventArgs : BaseMinecraftEventArgs;
public IPluginRegistry MapEvent(Delegate contextDelegate, Priority priority = Priority.Low);
public IPluginRegistry MapEvents();
}


//TODO better name maybe??
public delegate ValueTask ValueTaskContextDelegate<TContext>(TContext context);
42 changes: 0 additions & 42 deletions Obsidian.API/Plugins/PluginAttribute.cs

This file was deleted.

Loading
Loading