Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions APITest/APITest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<ItemGroup>
<Compile Include="APITestConfig.cs" />
<Compile Include="APITestMain.cs" />
<Compile Include="Commands\PlaceholderTest.cs" />
<Compile Include="Commands\AddUI.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\Elements\ProfilePictureElement.cs" />
Expand Down
48 changes: 48 additions & 0 deletions APITest/Commands/PlaceholderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using APITest.UI;
using APITest.UI.Elements;
using CommandSystem;
using Exiled.API.Features;
using MEC;
using NorthwoodLib.Pools;
using NotAnAPI.API.Commands;
using NotAnAPI.Features.PAPI.API;
using NotAnAPI.Features.UI;
using NotAnAPI.Features.UI.API.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace APITest.Commands
{

[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class PlaceholderTest : NotCommands
{
public override string[] GetAliases() => [];

public override string GetCommandName() => "placeholder";

public override string GetDescription() => "Test placeholder.";

public override string[] GetPerms() => null;

public override bool GetRequirePlayer() => true;

public override string[] GetUsage() => ["string"];

public override bool PlayerBasedFunction(Player player, string[] args, out string result)
{
if (!TryGetArgument(args, 1, out string arg1))
{
result = "No Args!";
return true;
}

result = $"{PlaceholderAPI.SetPlaceholders(player, $"Hello %player_{arg1}%")}";
return false;
}

}
}
61 changes: 61 additions & 0 deletions APITest/Commands/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using APITest.UI;
using APITest.UI.Elements;
using CommandSystem;
using Exiled.API.Features;
using Exiled.API.Interfaces;
using Hints;
using InventorySystem.Items.Firearms;
using MEC;
using Mirror;
using NorthwoodLib.Pools;
using NotAnAPI.API.Commands;
using NotAnAPI.Features.UI;
using NotAnAPI.Features.UI.API.Abstract;
using RelativePositioning;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using YamlDotNet.Core.Tokens;
using static EncryptedChannelManager;
using static Unity.IO.LowLevel.Unsafe.AsyncReadManagerMetrics;

namespace APITest.Commands
{

[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class Test : NotCommands
{
public override string[] GetAliases() => [];

public override string GetCommandName() => "test";

public override string GetDescription() => "test.";

public override string[] GetPerms() => null;

public override bool GetRequirePlayer() => true;

public override string[] GetUsage() => ["string"];

public override bool PlayerBasedFunction(Player player, string[] args, out string result)
{


SceneMessage message = new()
{
sceneName = "Facility",
};

player.Connection.Send(message);

player.SendConsoleMessage("Hello World", "red");

result = $"PersonalElement Enabled";
return false;
}

}
}
24 changes: 24 additions & 0 deletions NotAnAPI/API/Extensions/HashsetExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NotAnAPI.API.Extensions
{
public static class HashsetExtension
{

public static bool TryGetValue<T>(this HashSet<T> set, T equalValue, out T actualValue)
{
if (set.Contains(equalValue))
{
actualValue = equalValue;
return true;
}
actualValue = default;
return false;
}

}
}
28 changes: 28 additions & 0 deletions NotAnAPI/Features/PAPI/API/Abstract/PlaceholderExpansion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Exiled.API.Features;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NotAnAPI.Features.PAPI.API.Abstract
{
public abstract class PlaceholderExpansion
{

public abstract string Author { get; set; }
public abstract string Identifier { get; set; }

public abstract string onRequest(Player player, string param);

public void Register()
{
PAPIFeature.Instance.Placeholders.Add(Identifier, this);
}

public void Unregister()
{
PAPIFeature.Instance.Placeholders.Remove(Identifier);
}
}
}
43 changes: 43 additions & 0 deletions NotAnAPI/Features/PAPI/API/PlaceholderAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Discord;
using Exiled.API.Features;
using NotAnAPI.API.Extensions;
using NotAnAPI.Features.PAPI.API.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine.Windows;

namespace NotAnAPI.Features.PAPI.API
{
public static class PlaceholderAPI
{

private const string pattern = @"%(?<identifier>[a-zA-Z0-9]+)_(?<params>[^%]+)%";

private static readonly Regex regex = new Regex(pattern);

public static string SetPlaceholders(Player player, string text)
{
return regex.Replace(text, match =>
{
string identifier = match.Groups["identifier"].Value;
string parameters = match.Groups["params"].Value;

if (PAPIFeature.Instance.Placeholders.TryGetValue(identifier, out PlaceholderExpansion replacement))
{
string final = replacement.onRequest(player, parameters);

return final == null ? "NaN" : final;
}
else
{
return match.Value;
}
});
}

}
}
44 changes: 44 additions & 0 deletions NotAnAPI/Features/PAPI/PAPIFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NotAnAPI.Features.Base;
using NotAnAPI.Features.Logger;
using NotAnAPI.Features.PAPI.API.Abstract;
using NotAnAPI.Features.PAPI.impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NotAnAPI.Features.PAPI
{
public class PAPIFeature : APIFeatures
{

public static PAPIFeature Instance { get; set; }

public static string Name { get; set; } = "UI";
public override bool IsEnabled { get; set; } = true;

public Dictionary<string, PlaceholderExpansion> Placeholders = new();

public override void OnEnable()
{
NotALogger.Info("PAPI Loaded");
Instance = this;

new PlayerPlaceholder().Register();

base.OnEnable();
}

public override void OnDisable()
{
NotALogger.Info("PAPI Unloaded");

new PlayerPlaceholder().Unregister();

Instance = null;
IsEnabled = false;
base.OnDisable();
}
}
}
44 changes: 44 additions & 0 deletions NotAnAPI/Features/PAPI/impl/PlayerPlaceholder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Exiled.API.Features;
using NotAnAPI.Features.PAPI.API.Abstract;

namespace NotAnAPI.Features.PAPI.impl
{
public class PlayerPlaceholder : PlaceholderExpansion
{
public override string Author { get; set; } = "NotZer0Two";
public override string Identifier { get; set; } = "player";

public override string onRequest(Player player, string param)
{
switch(param.ToLower())
{
case "name":
return player.Nickname;
case "displayname":
return player.DisplayNickname;
case "ip":
return player.IPAddress;
case "dnt":
return player.DoNotTrack ? "Enabled" : "Disabled";
case "health":
return player.Health.ToString();
case "maxhealth":
return player.MaxHealth.ToString();
case "ping":
return player.Ping.ToString();
case "id":
return player.RawUserId;
case "fullid":
return player.UserId;
case "x":
return player.Position.x.ToString();
case "y":
return player.Position.y.ToString();
case "z":
return player.Position.z.ToString();
}

return null;
}
}
}
5 changes: 5 additions & 0 deletions NotAnAPI/NotAnAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="API\Commands\NotCommands.cs" />
<Compile Include="API\Extensions\HashsetExtension.cs" />
<Compile Include="API\Extensions\HintHelper.cs" />
<Compile Include="API\Extensions\PlayerExtensions.cs" />
<Compile Include="API\Translator\GoogleTranslator.cs" />
<Compile Include="API\Translator\Languages.cs" />
<Compile Include="API\Translator\TranslationResponse.cs" />
<Compile Include="Features\Base\APIFeaturesManager.cs" />
<Compile Include="Features\PAPI\API\Abstract\PlaceholderExpansion.cs" />
<Compile Include="Features\PAPI\API\PlaceholderAPI.cs" />
<Compile Include="Features\PAPI\impl\PlayerPlaceholder.cs" />
<Compile Include="Features\PAPI\PAPIFeature.cs" />
<Compile Include="Features\UI\API\Abstract\GameElementDisplay.cs" />
<Compile Include="Features\UI\API\Abstract\GameDisplayBuilder.cs" />
<Compile Include="Features\UI\API\Elements\Element.cs" />
Expand Down