Skip to content

Commit e27d833

Browse files
authored
Merge pull request #57 from UncomplicatedCustomServer/dev-main
Version v6.0.0 - Candidate I
2 parents 590ac28 + 24b6fdb commit e27d833

46 files changed

Lines changed: 806 additions & 618 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Localization/README-DE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Du kannst die <ins>Rolle</ins>, die <ins>HP</ins>, die <ins>Rolle nach dem Escap
3232
- Spielinterne Befehle zur Handhabung des Plugins und der Rollen
3333

3434
## Einrichtung
35-
Lade die `UncomplicatedCustomRoles.dll` aus der [neuesten Version] (https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/releases/latest) herunter und lege die .dll in den Ordner `EXILED/Plugins`.
35+
Lade die `UncomplicatedCustomRoles.dll` aus der [neuesten Version](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/releases/latest) herunter und lege die .dll in den Ordner `EXILED/Plugins`.
3636

3737
## Entwickler
3838
UncomplicatedCustomRoles hat ein einfaches und schnelles API-System für Entwickler, um unser Plugin zu verwenden.

Localization/README-PL.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<div align="center">
2+
<a href="https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/releases/latest">
3+
<img src="https://img.shields.io/github/v/release/UncomplicatedCustomServer/UncomplicatedCustomRoles">
4+
</a>
5+
<a href="https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/releases/latest">
6+
<img src="https://img.shields.io/github/downloads/UncomplicatedCustomServer/UncomplicatedCustomRoles/total">
7+
</a>
8+
<a href="https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/pulls">
9+
<img src="https://img.shields.io/github/issues-pr/UncomplicatedCustomServer/UncomplicatedCustomRoles">
10+
</a>
11+
<a href="https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/pulls">
12+
<img src="https://img.shields.io/github/issues-pr-closed/UncomplicatedCustomServer/UncomplicatedCustomRoles">
13+
</a>
14+
<a href="https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/commits/main/">
15+
<img src="https://badgen.net/github/commits/UncomplicatedCustomServer/UncomplicatedCustomRoles/main">
16+
</a>
17+
<img src="https://img.shields.io/badge/Verified_Exiled_Plugin-ss">
18+
19+
<img src="https://raw.githubusercontent.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/refs/heads/resources/ucr_promo_banner.png">
20+
<i>Prosty, w pełni konfigurowalny system customowych ról dla Twojego serwera SCP:SL!</i>
21+
22+
<br><br>
23+
<br><br>
24+
<a href='https://discord.gg/5StRGu8EJV'>
25+
<img src='https://www.allkpop.com/upload/2021/01/content/262046/1611711962-discord-button.png' height="100">
26+
</a>
27+
<br><br>
28+
</div>
29+
30+
**EXILED** >= `v9.x`
31+
<br><br>
32+
33+
## Zlokalizowane README
34+
- [&#127467;&#127479; Francuski](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-FR.md)
35+
- [&#x1F1EE;&#x1F1F9; Włoski](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-IT.md)
36+
- [&#127479;&#127482; Rosyjski](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-RU.md)
37+
- [&#127465;&#127466; Niemiecki](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-DE.md)
38+
- [&#127477;&#127473; Polski](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-PL.md)
39+
40+
## Czym jest UncomplicatedCustomRoles?
41+
**UncomplicatedCustomRoles** (UCR) to plugin dla [EXILED](https://github.com/ExMod-Team/EXILED), który pozwala na tworzenie w pełni konfigurowalnych ról z użyciem YAML.\
42+
Możesz ustawić <ins>rolę</ins>, <ins>ilość HP</ins>, <ins>co się stanie po ucieczce</ins> i wiele więcej!
43+
44+
## Funkcje
45+
**UCR** oferuje mnóstwo możliwości, m.in.:
46+
- Nieograniczona liczba custom ról
47+
- Konfiguracja w osobnym pliku, a nie w domyślnym pliku EXILED
48+
- Szczegółowa [wiki](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/wiki)
49+
- Aktywna społeczność na **Discordzie**
50+
- __Specjalne przywileje i dostęp do wersji testowych__ dla właścicieli zweryfikowanych serwerów
51+
- Komendy w grze do zarządzania customowymi rolami i pluginem
52+
53+
## Instalacja
54+
Pobierz `UncomplicatedCustomRoles.dll` z [najnowszego wydania](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/releases/latest) i wrzuć go do folderu `EXILED/Plugins`.
55+
56+
## Dla deweloperów
57+
UncomplicatedCustomRoles ma prosty i szybki system API, który pozwala na łatwe rozszerzanie funkcjonalności pluginu.\
58+
W [wiki dla deweloperów](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/wiki/Developers-World) znajdziesz przykłady użycia.
59+
60+
## Masz skill issue?
61+
Przeczytaj [WIKI](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/wiki), a jeśli dalej nie możesz rozwiązać problemu, zapytaj społeczność na naszym [Discordzie](https://discord.gg/5StRGu8EJV)!
62+
63+
## Wesprzyj UncomplicatedCustomServer Collective
64+
Wszystkie nasze pluginy są **darmowe** i **open-source**.\
65+
Jeśli chcesz wesprzeć naszą pracę, możesz przekazać dotację przez **OpenCollective**:
66+
<a href="https://opencollective.com/ucs">
67+
<img height="15" src="https://raw.githubusercontent.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/refs/heads/resources/oc_icon.png">&nbsp;&nbsp;Wesprzyj nas!
68+
</a>
69+
70+
## Kontakt
71+
### UncomplicatedCustomRoles
72+
**Discord:** [https://discord.gg/5StRGu8EJV](https://discord.gg/5StRGu8EJV)
73+
74+
### FoxWorn3365
75+
**Discord:** `@foxworn`\
76+
**Email:** `foxworn3365@gmail.com`
77+
78+
### Dr.Agenda
79+
**Discord:** `dr.agenda`
80+
81+
## Podziękowania za tłumaczenia
82+
**Francuski:** `@robocnop`\
83+
**Włoski:** `@foxworn`\
84+
**Rosyjski:** `@naxefir`\
85+
**Niemiecki:** `@seekedstroy`\
86+
**Polski:** `@.piwnica2137`

Localization/README-RU.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<br><br>
1515
</div>
1616

17-
**EXILED** >= `v8.12`
17+
**EXILED** >= `v9.x`
1818
<br><br>
1919

2020
## Локализованные README

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [&#x1F1EE;&#x1F1F9; Italiano](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-IT.md)
1818
- [&#127479;&#127482; Russian](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-RU.md)
1919
- [&#127465;&#127466; German](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-DE.md)
20+
- [&#127477;&#127473; Polski](https://github.com/UncomplicatedCustomServer/UncomplicatedCustomRoles/blob/main/Localization/README-PL.md)
2021

2122
## What's UncomplicatedCustomRoles
2223
**UncomplicatedCustomRoles** or **UCR** is a plugin for [EXILED](https://github.com/ExMod-Team/EXILED) that allow you to create fully configurable and customizable custom role with YAML.\
@@ -59,4 +60,6 @@ Please consider donating something to support our work through **OpenCollective*
5960
## Translation Credits
6061
**French:** `@robocnop`\
6162
**Italian:** `@foxworn`\
62-
**Russian:** `@naxefir`
63+
**Russian:** `@naxefir`\
64+
**Deutsch:** `@seekedstroy`\
65+
**Polish:** `@.piwnica2137`

UncomplicatedCustomRoles/API/Features/CustomModules/CoroutineModule.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 99 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,147 @@
1-
using HarmonyLib;
1+
using Exiled.Events.EventArgs.Interfaces;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Reflection;
6-
using UncomplicatedCustomRoles.API.Enums;
7-
using UncomplicatedCustomRoles.API.Interfaces;
85
using UncomplicatedCustomRoles.Manager;
96

107
namespace UncomplicatedCustomRoles.API.Features.CustomModules
118
{
12-
#pragma warning disable IDE1006
13-
14-
public abstract class CustomModule : ICustomModule
9+
public abstract class CustomModule
1510
{
1611
/// <summary>
17-
/// Gets the <see cref="CustomFlags"/> that represent this module
12+
/// Gets the display name of the given <see cref="CustomModule"/>
1813
/// </summary>
19-
public static CustomFlags Flag => CustomFlags.NotExecutable;
14+
/// <value>Default one is the class' name</value>
15+
public virtual string Name
16+
{
17+
get
18+
{
19+
return GetType().Name;
20+
}
21+
}
2022

2123
/// <summary>
22-
/// Gets the <see cref="SummonedCustomRole"/> instance that refers to this specific Module.<br></br>
23-
/// This can be null if the module does not implement anything related to it!
24+
/// Gets the list of events that this <see cref="CustomModule"/> will listen for.
2425
/// </summary>
25-
public SummonedCustomRole Instance { get; } = null;
26+
/// <remarks>The <see cref="OnEvent(string, IPlayerEvent)"/> will be invoked only for the given events!</remarks>
27+
public virtual List<string> TriggerOnEvents { get; } = new();
2628

27-
public string Name { get; } = string.Empty;
29+
/// <summary>
30+
/// Gets the list of required argument names for the current <see cref="CustomModule"/>
31+
/// </summary>
32+
public virtual List<string> RequiredArgs { get; } = new();
2833

2934
/// <summary>
30-
/// Gets whether the given <see cref="CustomModule"/> has it's <see cref="Instance"/> or not
35+
/// Gets the args of the current <see cref="CustomModule"/>
3136
/// </summary>
32-
public bool HasInstance => Instance is not null;
37+
/// <remarks>Every value is a <see cref="string"/></remarks>
38+
internal Dictionary<string, string> Args { get; private set; }
3339

34-
private static IEnumerable<Type> _loadedCache { get; set; } = null;
40+
/// <summary>
41+
/// Gets the instance of the <see cref="SummonedCustomRole"/> in which the current <see cref="CustomModule"/> is embedded
42+
/// </summary>
43+
internal SummonedCustomRole CustomRole { get; private set; }
3544

36-
private static IEnumerable<Type> _loaded { get
37-
{
38-
_loadedCache ??= LoadAll();
39-
return _loadedCache;
40-
}
45+
internal void Initialize(SummonedCustomRole summonedCustomRole, Dictionary<string, string> args)
46+
{
47+
CustomRole = summonedCustomRole;
48+
Args = args;
4149
}
4250

4351
/// <summary>
44-
/// Create a new instance of <see cref="CustomModule"/> without a <see cref="SummonedCustomRole"/>
52+
/// The added event function
4553
/// </summary>
46-
public CustomModule() => Name = GetType().Name;
54+
/// <remarks>Invoked when the <see cref="CustomModule"/> has been added to the <see cref="SummonedCustomRole"/></remarks>
55+
public virtual void OnAdded()
56+
{ }
4757

4858
/// <summary>
49-
/// Create a new instance of <see cref="CustomModule"/>
59+
/// The removed event function
5060
/// </summary>
51-
/// <param name="instance"></param>
52-
public CustomModule(SummonedCustomRole instance)
53-
{
54-
Instance = instance;
55-
Name = GetType().Name;
56-
}
61+
/// <remarks>Invoked when the <see cref="CustomModule"/> has been removed from the <see cref="SummonedCustomRole"/></remarks>
62+
public virtual void OnRemoved()
63+
{ }
5764

5865
/// <summary>
59-
/// Executen the Custom Module action
66+
/// The generic event function
6067
/// </summary>
68+
/// <param name="name"></param>
69+
/// <param name="ev"></param>
70+
/// <returns>Invoked only for the events listed in <see cref="TriggerOnEvents"/></returns>
71+
public virtual bool OnEvent(string name, IPlayerEvent ev) => true;
72+
73+
/// <summary>
74+
/// A generic function
75+
/// </summary>
76+
/// <remark>This won't be invoked by UCR</remark>
6177
public virtual void Execute()
6278
{ }
6379

64-
private static IEnumerable<Type> LoadAll()
80+
#nullable enable
81+
internal static List<CustomModule> Load(List<object> modules, SummonedCustomRole summonedCustomRole)
6582
{
66-
return Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(CustomModule)) && !t.IsAbstract);
83+
LogManager.Silent($"[CM Loader] Initialize loading for {summonedCustomRole}\nPreloaded {YamlFlagsHandler.Modules.Length} modules...");
84+
85+
Dictionary<string, Dictionary<string, string>?> data = YamlFlagsHandler.Decode(modules) ?? new();
86+
87+
List<CustomModule> mods = new();
88+
89+
foreach (KeyValuePair<string, Dictionary<string, string>?> module in data)
90+
if (InitializeCustomModule(module.Key, module.Value, YamlFlagsHandler.Modules, summonedCustomRole) is CustomModule mod)
91+
mods.Add(mod);
92+
93+
LogManager.Debug($"Successfully loaded {mods.Count} CustomModules for player {summonedCustomRole.Player.Nickname}!");
94+
95+
return mods;
6796
}
6897

69-
/// <summary>
70-
/// Load a <see cref="List{T}"/> of <see cref="ICustomModule"/> from the given <see cref="CustomFlags"/>
71-
/// </summary>
72-
/// <param name="flags"></param>
73-
/// <param name="instance"></param>
74-
/// <returns></returns>
75-
public static List<ICustomModule> Load(CustomFlags flags, SummonedCustomRole instance)
98+
internal static CustomModule? FastAdd(Type type, SummonedCustomRole role, Dictionary<string, string>? args = null)
7699
{
77-
LogManager.Debug($"Loading custom modules for {instance.Player} - {instance.Role.Id} -- {flags} -- {_loaded.Count()}");
78-
List<ICustomModule> result = new();
100+
if (Activator.CreateInstance(type) is not CustomModule module)
101+
{
102+
LogManager.Error($"Failed to enable CustomModule '{type?.Name}'!\nError: ERR_CUSTOM_MODULE_NULLREFERENCE_OR_NOTMODULE", "CM0003");
103+
return null;
104+
}
105+
106+
module.Initialize(role, args ?? new());
107+
module.OnAdded(); // Invoke added event
79108

109+
return module;
110+
}
111+
112+
private static CustomModule? InitializeCustomModule(string name, Dictionary<string, string>? args, Type[] types, SummonedCustomRole summonedCustomRole)
113+
{
80114
try
81115
{
82-
foreach (Type type in _loaded)
116+
LogManager.Silent($"[CM Loader] Initialize loading module '{name}' for {summonedCustomRole}");
117+
118+
Type type = types.FirstOrDefault(t => t.Name == name);
119+
120+
if (type is null)
83121
{
84-
PropertyInfo property = type.GetProperty("Flag", BindingFlags.Public | BindingFlags.Static);
85-
if (property is not null)
86-
{
87-
CustomFlags flag = (CustomFlags)property.GetValue(null, null);
88-
if ((flags & flag) == flag)
89-
if (type.GetConstructors()[0].GetParameters().Length > 0 && type.GetConstructors()[0].GetParameters()[0].ParameterType == typeof(SummonedCustomRole))
90-
result.Add((CustomModule)Activator.CreateInstance(type, new object[] { instance }));
91-
else
92-
result.Add((CustomModule)Activator.CreateInstance(type));
93-
94-
}
122+
LogManager.Error($"[CM Loader] Failed to enable CustomModule '{name}'!\nError: ERR_CUSTOM_MODULE_NOT_FOUND", "CM0001");
123+
return null;
95124
}
125+
126+
if (Activator.CreateInstance(type) is not CustomModule module)
127+
{
128+
LogManager.Error($"[CM Loader] Failed to enable CustomModule '{name}'!\nError: ERR_CUSTOM_MODULE_NULLREFERENCE_OR_NOTMODULE", "CM0002");
129+
return null;
130+
}
131+
132+
module.Initialize(summonedCustomRole, args ?? new());
133+
module.OnAdded(); // Invoke added event
134+
135+
LogManager.Silent($"[CM Loader] CustomModule '{name}' successfully enabled for {summonedCustomRole}!");
136+
137+
return module;
96138
}
97139
catch (Exception e)
98140
{
99-
LogManager.Error($"Failed to act CustomModule::Load(CustomFlags, SummonedCustomRole) - {e.GetType().FullName}: {e.Message}\n{e.StackTrace}");
100-
}
101-
102-
LogManager.Silent($"rff for {flags}: {result.Count}");
103-
return result;
104-
}
141+
LogManager.Error(e.ToString());
105142

106-
public static ICustomModule Load(Type type, SummonedCustomRole instance)
107-
{
108-
if (type.GetConstructors()[0].GetParameters().Length > 0 && type.GetConstructors()[0].GetParameters()[0].ParameterType == typeof(SummonedCustomRole))
109-
return (CustomModule)Activator.CreateInstance(type, new object[] { instance });
110-
return (CustomModule)Activator.CreateInstance(type);
143+
return null;
144+
}
111145
}
112146
}
113147
}

0 commit comments

Comments
 (0)