Skip to content

Commit

Permalink
Auto Close Door added you can configure it in "config.json", as defau…
Browse files Browse the repository at this point in the history
…lt is 5 seconds.

And fixed the libraries issue with dotnet-desktop.yml.
  • Loading branch information
TH3AL3X committed Apr 6, 2024
1 parent 5898cad commit 27bba68
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
mkdir ./publish/uEssentials
mkdir ./publish/uEssentials/Libraries
mv ./publish/uEssentials.dll ./publish/uEssentials/uEssentials.dll
mv ./Libraries/netstandard.dll ./publish/uEssentials/Libraries/netstandard.dll
mv ./Libraries/* ./publish/uEssentials/Libraries/
- name: Git Semantic Version
Expand Down
14 changes: 13 additions & 1 deletion src/Configuration/EssConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class EssConfig : JsonConfig {
public bool Allow_Structures_Buildings;
public bool Allow_Barricades_Buildings;


public bool EnablePollRunningMessage;
public int PollRunningMessageCooldown;
public int ServerFrameRate;
Expand All @@ -61,6 +60,7 @@ public class EssConfig : JsonConfig {
public ushort ItemSpawnLimit;
public int AmmoCommandSpawnLimit;

public AutoCloseDoor CloseDoor;
public AntiSpamSettings AntiSpam;
public HomeCommandSettings Home;
public WarpCommandSettings Warp;
Expand Down Expand Up @@ -102,6 +102,11 @@ public override void LoadDefaults() {
Allow_Structures_Buildings = true;
Allow_Barricades_Buildings = true;

CloseDoor = new AutoCloseDoor
{
Enabled = false,
Seconds = 5
};

AutoAnnouncer = new AutoAnnouncer();
AutoAnnouncer.LoadDefaults();
Expand Down Expand Up @@ -249,6 +254,13 @@ public struct AntiSpamSettings {
public int Interval;
}

public struct AutoCloseDoor
{
public bool Enabled;
public int Seconds;
}


public struct HomeCommandSettings {
public int TeleportDelay;
public bool CancelTeleportWhenMove;
Expand Down
72 changes: 28 additions & 44 deletions src/Core/EssCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,27 @@
using Steamworks;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using UnityEngine;
using System.Globalization;
using HarmonyLib;
using Essentials.Api.Command.Source;
using Essentials.Components.Player;

using System.Collections;
using Rocket.API;
using System.Reflection;
namespace Essentials.Core {

public sealed class EssCore : RocketPlugin {

internal const string ROCKET_VERSION = "4.X.X.X";
internal const string UNTURNED_VERSION = "3.X.X.X";

#if DEV
// Dev build version -- patched in compile-time (see uEssentials.csproj)
// This needs to be different every time because
// of Assembly loading -- I (leonardosnt) use a custom version of Rocket for
// development that allows to reload plugins without restaring the server.
internal const string PLUGIN_VERSION = "999.0.0.0";
#else
// Deprecated
internal const string PLUGIN_VERSION = "Release";
#endif
public static Assembly rocketModAssembly = typeof(RocketPlugin).Assembly;

#if E
ERIMENTAL
internal const string BUILD_INFO = " experimental (commit: COMMIT_HASH)";
#elif DEV
internal const string BUILD_INFO = " (development)";
#else
internal const string BUILD_INFO = "";
#endif
internal static string ROCKET_VERSION = rocketModAssembly.GetName().Version.ToString();
internal static string UNTURNED_VERSION = "4.X.X.X";

// Will remove this and add automatization
[Obsolete]
internal static string PLUGIN_VERSION = Application.version;

internal static EssCore Instance;

Expand All @@ -97,7 +82,6 @@ public sealed class EssCore : RocketPlugin {
internal ICommandManager CommandManager { get; set; }
internal IEventManager EventManager { get; set; }
internal HookManager HookManager { get; set; }

internal CommandOptions CommandOptions { get; set; }
internal TextCommands TextCommands { get; set; }
internal EssConfig Config { get; set; }
Expand Down Expand Up @@ -141,7 +125,6 @@ protected override void Load()

_consoleTraceListener = new EssentialsConsoleTraceListener();

// Agrega el EssentialsConsoleTraceListener al Trace
Trace.Listeners.Add(_consoleTraceListener);

Provider.onServerDisconnected += PlayerDisconnectCallback;
Expand All @@ -150,7 +133,7 @@ protected override void Load()
Logger.LogInfo("Enabling uEssentials...");

new [] {
"Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO,
"Plugin version: ~white~" + PLUGIN_VERSION,

Check warning on line 136 in src/Core/EssCore.cs

View workflow job for this annotation

GitHub Actions / build

'EssCore.PLUGIN_VERSION' is obsolete
"Recommended Rocket/OpenMod version: ~white~" + ROCKET_VERSION,
"Recommended Unturned version: ~white~" + UNTURNED_VERSION,
"Author: ~white~Terror",
Expand Down Expand Up @@ -195,6 +178,7 @@ protected override void Load()
CommandWindow.onCommandWindowInputted += ReloadCallback;
BarricadeManager.onDeployBarricadeRequested += onBarricadeDeploy;
StructureManager.onDeployStructureRequested += onStructureDeploy;
InteractableDoor.OnDoorChanged_Global += OnDoorChanged;

EventManager.RegisterAll(GetType().Assembly);

Expand All @@ -217,11 +201,6 @@ protected override void Load()
// register commands.
Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands");

#if EXPERIMENTAL
Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, IT CAN BE BUGGY.");
#endif

// Delete useless files generated by Rocket
Task.Create()
.Id("Delete Xml Files")
Expand Down Expand Up @@ -260,15 +239,6 @@ protected override void Load()
messages.ForEach(m => Logger.LogError(m));
}
}

#if !DEV
// Analytics.SendEvent($"ServerInit");
#endif

#if DEV
Console.Title = "Unturned Server";
#else
#endif
}

protected override void Unload() {
Expand All @@ -285,6 +255,7 @@ protected override void Unload() {

BarricadeManager.onDeployBarricadeRequested -= onBarricadeDeploy;
StructureManager.onDeployStructureRequested -= onStructureDeploy;
InteractableDoor.OnDoorChanged_Global -= OnDoorChanged;

var executingAssembly = GetType().Assembly;

Expand All @@ -298,19 +269,32 @@ protected override void Unload() {

TaskExecutor.Stop();


Trace.Listeners.Remove(_consoleTraceListener);

// Restore overridden commands
var rocketCommands = GetRocketCommands();
if (rocketCommands != null) {
rocketCommands.AddRange(_overriddenCommands);
_overriddenCommands.Clear();
}
}
}

private Harmony HarmonyInstance;

private void OnDoorChanged(InteractableDoor door)
{
if (door.isOpen && UEssentials.Config.CloseDoor.Enabled)
{
StartCoroutine(AutoCloseDoor(door));
}
}

private IEnumerator AutoCloseDoor(InteractableDoor door)
{
yield return new WaitForSeconds(UEssentials.Config.CloseDoor.Seconds);
BarricadeManager.ServerSetDoorOpen(door, false);
}

private void onStructureDeploy(Structure structure, ItemStructureAsset asset, ref Vector3 point, ref float angle_x, ref float angle_y, ref float angle_z, ref ulong owner, ref ulong group, ref bool shouldAllow)
{
if (!UEssentials.Config.Allow_Structures_Buildings)
Expand Down

0 comments on commit 27bba68

Please sign in to comment.