C#:
using System;
using System.Collections.Generic;
using Oxide.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins {
[Info("WipeBlockMovement", "King.", "1.0.0")]
class WipeBlockMovement : RustPlugin {
[PluginReference]
Plugin ImageLibrary = null;
private string Layer = "WipeBlockMovement_UI";
private Dictionary<BasePlayer, Vector3> _playerPosition = new Dictionary<BasePlayer, Vector3>();
#region Configuration
private PluginConfig config;
protected override void LoadDefaultConfig() {
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig() {
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version) UpdateConfigValues();
Config.WriteObject(config, true);
}
private void UpdateConfigValues() {
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < new VersionNumber(1, 0, 0)) {
PrintWarning("Config update detected! Updating config values...");
PrintWarning("Config update completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig() {
Config.WriteObject(config);
}
private class PluginConfig {
[JsonProperty("Настройки плагина")]
public Settings _Settings;
[JsonProperty("Версия конфигурации")]
public VersionNumber PluginVersion = new VersionNumber();
public static PluginConfig DefaultConfig() {
return new PluginConfig() {
_Settings = new Settings() {
BlockCommand = new List<string>() {
"kit", "menu", "store"
}
,
}
, PluginVersion = new VersionNumber(),
}
;
}
}
public class Settings {
[JsonProperty("Черный список команд какие запрещены в блоке-движении")]
public List<string> BlockCommand;
}
private int Time = 300;
#endregion
#region [Time]
static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
static double CurrentTime() => DateTime.UtcNow.Subtract(epoch).TotalSeconds;
private double IsBlocked() {
var lefTime = SaveRestore.SaveCreatedTime.ToUniversalTime().Subtract(epoch).TotalSeconds + Time - CurrentTime();
return lefTime > 0 ? lefTime : 0;
}
private double BlockMovementTime() => (SaveRestore.SaveCreatedTime.ToUniversalTime().Subtract(epoch).TotalSeconds + Time) - CurrentTime();
private string GetFormatTime(TimeSpan timespan) => string.Format(timespan.TotalHours >= 1 ? "{2:00}:{0:00}:{1:00}" : "{0:00}:{1:00}", timespan.Minutes, timespan.Seconds, System.Math.Floor(timespan.TotalHours));
#endregion
#region [Oxide]
private void OnServerInitialized() {
Puts($"{IsBlocked()}");
if (IsBlocked() == 0) {
PrintWarning("Уже прошло время блокировки движения, Пока!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
if(!ImageLibrary) {
PrintWarning("ImageLibrary не установлен!");
Interface.Oxide.UnloadPlugin(Name);
return;
}
ImageLibrary?.Call("AddImage", "https://i.imgur.com/qRQCdmV.png", "WipeBlockMovementImage");
ServerMgr.Instance.InvokeRepeating(CheckBlockMovement, 0f, 0.5f);
}
private void Unload() {
ServerMgr.Instance.CancelInvoke(CheckBlockMovement);
foreach (var player in BasePlayer.activePlayerList) CuiHelper.DestroyUi(player, Layer);
}
#endregion
#region [Rust]
private object OnPlayerCommand(BasePlayer player, string command, string[] args) {
if (player == null) return null;
if (config._Settings.BlockCommand.Contains(command.ToLower())) {
player.ChatMessage("Вы не можете использовать эту команду во время блока движения!");
return false;
}
return null;
}
#endregion
#region [Functional]
private void CheckBlockMovement() {
if (IsBlocked() == 0) {
ServerMgr.Instance.CancelInvoke(CheckBlockMovement);
Server.Broadcast("Блок движения окончен!");
Interface.Oxide.UnloadPlugin(Name);
}
else {
foreach (var player in BasePlayer.activePlayerList) {
if (!_playerPosition.ContainsKey(player)) _playerPosition.Add(player, player.transform.position);
BlockMovementUI(player);
player.MovePosition(_playerPosition[player]);
}
}
}
#endregion
#region [UI]
private void BlockMovementUI(BasePlayer player) {
var container = new CuiElementContainer();
container.Add(new CuiElement {
Name = Layer, Parent = $"Hud", Components = {
new CuiRawImageComponent {
Png = (string)ImageLibrary?.Call("GetImage", "WipeBlockMovementImage"), Color = "1 1 1 0.8"
}
, new CuiRectTransformComponent {
AnchorMin="0.5 0.5", AnchorMax="0.5 0.5", OffsetMin="-199 100", OffsetMax="180 260"
}
}
}
);
container.Add(new CuiElement {
Parent = Layer, Components = {
new CuiTextComponent {
Text = $"Запрещен блок движения перед вайпом\n\n{GetFormatTime(TimeSpan.FromSeconds(BlockMovementTime()))}", Color = "1 1 1 1", FontSize = 20, Font = "robotocondensed-bold.ttf", Align = TextAnchor.MiddleCenter
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1"
}
,
}
}
);
CuiHelper.DestroyUi(player, Layer);
CuiHelper.AddUi(player, container);
}
#endregion
}
}