Skip to content

Commit

Permalink
Nebuli support
Browse files Browse the repository at this point in the history
  • Loading branch information
NotIntense committed Sep 5, 2023
1 parent d85168f commit 29cbac5
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 45 deletions.
50 changes: 50 additions & 0 deletions RainbowTags - Nebuli/Commands/ToggleRTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using CommandSystem;
using Nebuli.API.Features.Player;
using RemoteAdmin;

namespace RainbowTags.Commands;

[CommandHandler(typeof(ClientCommandHandler))]
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class ToggleRTag : ICommand
{
public string Command { get; } = "togglerainbowtag";
public string[] Aliases { get; } = { "trt" };
public string Description { get; } = "Toggles your rainbow tag on or off";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (sender is PlayerCommandSender playerCommandSender)
{
NebuliPlayer player = NebuliPlayer.Get(playerCommandSender);
if (player == null)
{
response = "You must be in-game to use this command!";
return false;
}

if (!MainClass.Instance.Config.RanksWithRTags.Contains(player.GroupName))
{
response = "You must be a member of a rank with a rainbow tag to use this command!";
return false;
}

if (player.GameObject.TryGetComponent(out TagController rainbowTag))
{
player.RemoveComponent(rainbowTag);
MainClass.PlayersWithoutRTags.Add(player);
response = "Your rainbow tag has been disabled!";
return true;
}

player.GameObject.AddComponent<TagController>();
MainClass.PlayersWithoutRTags.Remove(player);
response = "Your rainbow tag has been enabled!";
return true;
}

response = "You must be in-game to use this command!";
return false;
}
}
31 changes: 31 additions & 0 deletions RainbowTags - Nebuli/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Nebuli.API.Interfaces;
using System.Collections.Generic;
using System.ComponentModel;

namespace RainbowTags;

public class Config : IConfiguration
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;

[Description("Tags Configuration")]
public float ColorInterval { get; set; } = 0.5f;
public List<string> RanksWithRTags { get; set; } = new()
{
"owner",
"moderator",
"admin"
};
public string[] Sequences { get; set; } = new[]
{
"red",
"orange",
"yellow",
"green",
"blue_green",
"magenta",
"silver",
"crimson"
};
}
22 changes: 22 additions & 0 deletions RainbowTags - Nebuli/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Nebuli.API.Features.Player;
using UnityEngine;
using Object = UnityEngine.Object;

namespace RainbowTags;

public static class Extensions
{
public static void RemoveComponent(this NebuliPlayer player, Component component)
{
var componentInstance = player.GameObject.GetComponent(component.GetType());
if (componentInstance != null)
Object.Destroy(componentInstance);
}

public static void RemoveComponent<T>(this NebuliPlayer player) where T : Component
{
var component = player.GameObject.GetComponent<T>();
if (component != null)
Object.Destroy(component);
}
}
75 changes: 75 additions & 0 deletions RainbowTags - Nebuli/MainClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using InventorySystem.Items.Usables;
using Nebuli.API.Features;
using Nebuli.API.Features.Player;
using Nebuli.Events.EventArguments.Player;
using Nebuli.Events.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using Object = UnityEngine.Object;

namespace RainbowTags;

public class MainClass : Plugin<Config>
{
public static MainClass Instance { get; set; }
public override string Creator => "NotIntense : (Ported From Build & xNexus-ACS)";
public override string Name => "RainbowTags";
public override Version Version { get; } = new(1, 0, 2);
public override Version NebuliVersion { get; } = new(0, 0, 0);

public static List<NebuliPlayer> PlayersWithoutRTags { get; } = new();

public override void OnEnabled()
{
Instance = this;
PlayerHandlers.UserChangingUserGroup += OnChangingGroup;
base.OnEnabled();
}

public override void OnDisabled()
{
PlayerHandlers.UserChangingUserGroup -= OnChangingGroup;
base.OnDisabled();
Instance = null;
}

private bool TryGetColors(string rank, out string[] availableColors)
{
availableColors = Config.Sequences;
return !string.IsNullOrEmpty(rank) && Config.RanksWithRTags.Contains(rank);
}
private bool EqualsTo(UserGroup thisGroup, UserGroup otherGroup)
{
return thisGroup.BadgeColor == otherGroup.BadgeColor && thisGroup.BadgeText == otherGroup.BadgeText &&
thisGroup.Permissions == otherGroup.Permissions && thisGroup.Cover == otherGroup.Cover &&
thisGroup.HiddenByDefault == otherGroup.HiddenByDefault && thisGroup.Shared == otherGroup.Shared &&
thisGroup.KickPower == otherGroup.KickPower &&
thisGroup.RequiredKickPower == otherGroup.RequiredKickPower;
}
private string GetGroupKey(UserGroup group)
{
if (group == null)
return string.Empty;

return ServerStatic.PermissionsHandler._groups.FirstOrDefault(g => EqualsTo(g.Value, group)).Key ??
string.Empty;
}
private void OnChangingGroup(PlayerChangingUserGroupEvent ev)
{
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.Group != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.Group), out var colors))
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
if (TryGetColors(GetGroupKey(ev.Group), out colors))
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
}
35 changes: 35 additions & 0 deletions RainbowTags - Nebuli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RainbowTags")]
[assembly: AssemblyDescription("RainbowTags Plugin for EXILED")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RainbowTags")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("638EE7D1-ED8F-4565-8C08-14165D93E041")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
87 changes: 87 additions & 0 deletions RainbowTags - Nebuli/RainbowTags - Nebuli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0374FCB4-D3D8-4169-B79B-9933A65F8A1F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RainbowTags</RootNamespace>
<AssemblyName>RainbowTags</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>10</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-Publicized, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-Publicized.dll</HintPath>
</Reference>
<Reference Include="CommandSystem.Core, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\CommandSystem.Core.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Mirror.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>B:\SteamLibrary\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\ToggleRTag.cs" />
<Compile Include="Config.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="MainClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TagController.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nebuli">
<Version>1.2.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
80 changes: 80 additions & 0 deletions RainbowTags - Nebuli/TagController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using MEC;
using Nebuli.API.Features.Player;
using UnityEngine;

namespace RainbowTags;

public class TagController : MonoBehaviour
{
private NebuliPlayer _player;
private int _position;
private float _interval;
private int _intervalInFrames;
private string[] _colors;
private CoroutineHandle _coroutineHandle;

public string[] Colors
{
get => _colors ?? Array.Empty<string>();
set
{
_colors = value ?? Array.Empty<string>();
_position = 0;
}
}
public float Interval
{
get => _interval;
set
{
_interval = value;
_intervalInFrames = Mathf.CeilToInt(value) * 50;
}
}
private void Awake()
{
_player = NebuliPlayer.Get(gameObject);
}
private void Start()
{
_coroutineHandle = Timing.RunCoroutine(UpdateColor().CancelWith(_player.GameObject));
}
private void OnDestroy()
{
Timing.KillCoroutines(_coroutineHandle);
}
private string RollNext()
{
var num = _position + 1;
_position = num;

if (num >= _colors.Length)
_position = 0;

if (_colors.Length == 0)
return string.Empty;

return _colors[_position];
}
private IEnumerator<float> UpdateColor()
{
for (; ; )
{
int num;
for (var z = 0; z < _intervalInFrames; z = num + 1)
{
yield return 0f;
num = z;
}
var text = RollNext();
if (string.IsNullOrEmpty(text))
{
break;
}
_player.RankColor = text;
}
Destroy(this);
}
}
Loading

0 comments on commit 29cbac5

Please sign in to comment.