add luckperms plugin
This commit is contained in:
12
LuckPerms.Torch/Extensions/CommandExtensions.cs
Normal file
12
LuckPerms.Torch/Extensions/CommandExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Linq;
|
||||
using Torch.Commands;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class CommandExtensions
|
||||
{
|
||||
public static string GetPermissionString(this Command command)
|
||||
{
|
||||
return $"minecraft.command.{string.Join(".", command.Path.Select(b => b.ToLowerInvariant()))}";
|
||||
}
|
||||
}
|
19
LuckPerms.Torch/Extensions/DelegateExtensions.cs
Normal file
19
LuckPerms.Torch/Extensions/DelegateExtensions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using java.lang;
|
||||
using java.util.concurrent;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class DelegateExtensions
|
||||
{
|
||||
public static Runnable ToRunnable(this Action action) => new DelegateRunnable(action);
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// lets make it an overload for convenience
|
||||
public static void execute(this Executor executor, Action action) => executor.execute(action.ToRunnable());
|
||||
|
||||
private sealed class DelegateRunnable(Action action) : Runnable
|
||||
{
|
||||
public void run() => action();
|
||||
}
|
||||
}
|
20
LuckPerms.Torch/Extensions/EnumerableExtensions.cs
Normal file
20
LuckPerms.Torch/Extensions/EnumerableExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static Collection ToCollection<T>(this IEnumerable<T> enumerable)
|
||||
{
|
||||
var collection = enumerable is IReadOnlyCollection<T> readOnlyCollection ? new ArrayList(readOnlyCollection.Count) : new ArrayList(((IReadOnlyCollection<T>)(enumerable = enumerable.ToArray())).Count);
|
||||
|
||||
foreach (var t in enumerable)
|
||||
{
|
||||
collection.add(t);
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
53
LuckPerms.Torch/Extensions/IteratorExtensions.cs
Normal file
53
LuckPerms.Torch/Extensions/IteratorExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class IteratorExtensions
|
||||
{
|
||||
public static IteratorEnumerator<object> GetEnumerator(this Iterator iterator) => new(iterator);
|
||||
|
||||
public static IteratorEnumerable<T> AsEnumerable<T>(this Iterator iterator) => new(iterator);
|
||||
|
||||
public struct IteratorEnumerator<T>(Iterator iterator) : IEnumerator<T>
|
||||
{
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
Current = iterator.next() is T ? (T)iterator.next() : default;
|
||||
return true;
|
||||
}
|
||||
|
||||
Current = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
object? IEnumerator.Current => Current;
|
||||
|
||||
public T? Current { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public struct IteratorEnumerable<T>(Iterator iterator) : IEnumerable<T>
|
||||
{
|
||||
public IteratorEnumerator<T> GetEnumerator() => new(iterator);
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => null!;
|
||||
}
|
||||
}
|
20
LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs
Normal file
20
LuckPerms.Torch/Extensions/KeyedConfigurationExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using java.lang;
|
||||
using me.lucko.luckperms.common.config.generic;
|
||||
using me.lucko.luckperms.common.config.generic.key;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class KeyedConfigurationExtensions
|
||||
{
|
||||
public static bool GetBoolean(this KeyedConfiguration config, ConfigKey key, bool defaultValue = default)
|
||||
{
|
||||
var value = config.get(key);
|
||||
|
||||
return value switch
|
||||
{
|
||||
bool boolValue => boolValue,
|
||||
Boolean booleanValue => booleanValue.booleanValue(),
|
||||
_ => defaultValue
|
||||
};
|
||||
}
|
||||
}
|
19
LuckPerms.Torch/Extensions/StreamExtensions.cs
Normal file
19
LuckPerms.Torch/Extensions/StreamExtensions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using java.io;
|
||||
using Torch.Utils;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class StreamExtensions
|
||||
{
|
||||
public static InputStream GetInputStream(this Stream stream)
|
||||
{
|
||||
if (!stream.CanRead)
|
||||
throw new ArgumentException("Stream should be readable", nameof(stream));
|
||||
|
||||
var array = stream.ReadToEnd(); // TODO make it not allocate array for an entire stream content
|
||||
|
||||
return new ByteArrayInputStream(array);
|
||||
}
|
||||
}
|
10
LuckPerms.Torch/Extensions/UUIDExtensions.cs
Normal file
10
LuckPerms.Torch/Extensions/UUIDExtensions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using java.util;
|
||||
|
||||
namespace LuckPerms.Torch.Extensions;
|
||||
|
||||
public static class UuidExtensions
|
||||
{
|
||||
public static ulong GetSteamId(this UUID uuid) => (ulong)uuid.getLeastSignificantBits();
|
||||
|
||||
public static UUID GetUuid(this ulong steamId) => new(0, (long)steamId);
|
||||
}
|
Reference in New Issue
Block a user