Skip to content

Commit

Permalink
Apply style settings to project
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepGoMeh committed Dec 27, 2023
1 parent f6f6e66 commit 3b24206
Show file tree
Hide file tree
Showing 17 changed files with 1,716 additions and 1,734 deletions.
107 changes: 53 additions & 54 deletions Visibility/Api/IVisibilityApi.cs
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
using System.Collections.Generic;

namespace Visibility.Api
namespace Visibility.Api;

public interface IVisibilityApi
{
public interface IVisibilityApi
{
public int ApiVersion { get; }

/// <summary>
/// Fetch all entries from VoidList
/// </summary>
/// <returns>A collection of strings in the form of (name worldId reason)</returns>
public IEnumerable<string> GetVoidListEntries();

/// <summary>
/// Adds entry to VoidList
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
/// <param name="reason">Reason for adding</param>
public void AddToVoidList(string name, uint worldId, string reason);

/// <summary>
/// Removes entry from VoidList
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
public void RemoveFromVoidList(string name, uint worldId);

/// <summary>
/// Fetch all entries from Whitelist
/// </summary>
/// <returns>A collection of strings in the form of (name worldId reason)</returns>
public IEnumerable<string> GetWhitelistEntries();

/// <summary>
/// Adds entry to Whitelist
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
/// <param name="reason">Reason for adding</param>
public void AddToWhitelist(string name, uint worldId, string reason);

/// <summary>
/// Removes entry from Whitelist
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
public void RemoveFromWhitelist(string name, uint worldId);

/// <summary>
/// Enables or disables Visibility
/// </summary>
/// <param name="state">Enabled = true</param>
public void Enable(bool state);
}
}
public int ApiVersion { get; }

/// <summary>
/// Fetch all entries from VoidList
/// </summary>
/// <returns>A collection of strings in the form of (name worldId reason)</returns>
public IEnumerable<string> GetVoidListEntries();

/// <summary>
/// Adds entry to VoidList
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
/// <param name="reason">Reason for adding</param>
public void AddToVoidList(string name, uint worldId, string reason);

/// <summary>
/// Removes entry from VoidList
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
public void RemoveFromVoidList(string name, uint worldId);

/// <summary>
/// Fetch all entries from Whitelist
/// </summary>
/// <returns>A collection of strings in the form of (name worldId reason)</returns>
public IEnumerable<string> GetWhitelistEntries();

/// <summary>
/// Adds entry to Whitelist
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
/// <param name="reason">Reason for adding</param>
public void AddToWhitelist(string name, uint worldId, string reason);

/// <summary>
/// Removes entry from Whitelist
/// </summary>
/// <param name="name">Full player name</param>
/// <param name="worldId">World ID</param>
public void RemoveFromWhitelist(string name, uint worldId);

/// <summary>
/// Enables or disables Visibility
/// </summary>
/// <param name="state">Enabled = true</param>
public void Enable(bool state);
}
184 changes: 89 additions & 95 deletions Visibility/Api/VisibilityApi.cs
Original file line number Diff line number Diff line change
@@ -1,132 +1,126 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Lumina.Excel.GeneratedSheets;

namespace Visibility.Api
using Visibility.Void;

namespace Visibility.Api;

public class VisibilityApi: IDisposable, IVisibilityApi
{
public class VisibilityApi : IDisposable, IVisibilityApi
{
public int ApiVersion => 1;
public int ApiVersion => 1;

private bool initialised;
private bool initialised;

public VisibilityApi()
{
this.initialised = true;
}
public VisibilityApi() => this.initialised = true;

private void CheckInitialised()
private void CheckInitialised()
{
if (!this.initialised)
{
if (!this.initialised)
{
throw new Exception("PluginShare is not initialised.");
}
throw new Exception("PluginShare is not initialised.");
}
}

public IEnumerable<string> GetVoidListEntries()
{
this.CheckInitialised();

return VisibilityPlugin
.Instance
.Configuration
.VoidList
.Select(x => $"{x.Name} {x.HomeworldId} {x.Reason}")
.ToList();
}

public void AddToVoidList(string name, uint worldId, string reason)
{
this.CheckInitialised();

World? world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);

public IEnumerable<string> GetVoidListEntries()
if (world == null)
{
this.CheckInitialised();

return VisibilityPlugin
.Instance
.Configuration
.VoidList
.Select(x => $"{x.Name} {x.HomeworldId} {x.Reason}")
.ToList();
throw new Exception($"Invalid worldId ({worldId}).");
}

public void AddToVoidList(string name, uint worldId, string reason)
{
this.CheckInitialised();
VisibilityPlugin.Instance.VoidPlayer("", $"{name} {world.Name} {reason}");
}

var world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);
public void RemoveFromVoidList(string name, uint worldId)
{
this.CheckInitialised();

if (world == null)
{
throw new Exception($"Invalid worldId ({worldId}).");
}
VoidItem? item = VisibilityPlugin.Instance.Configuration.VoidList.SingleOrDefault(
x => x.Name == name && x.HomeworldId == worldId);

VisibilityPlugin.Instance.VoidPlayer("", $"{name} {world.Name} {reason}");
}

public void RemoveFromVoidList(string name, uint worldId)
if (item == null)
{
this.CheckInitialised();

var item = VisibilityPlugin.Instance.Configuration.VoidList.SingleOrDefault(
x => x.Name == name && x.HomeworldId == worldId);

if (item == null)
{
return;
}

VisibilityPlugin.Instance.Configuration.VoidList.Remove(item);
VisibilityPlugin.Instance.Configuration.Save();

if (item.ObjectId > 0)
{
VisibilityPlugin.Instance.RemoveChecked(item.ObjectId);
VisibilityPlugin.Instance.ShowPlayer(item.ObjectId);
}
else
{
VisibilityPlugin.Instance.RemoveChecked(item.Name);
}
return;
}

public IEnumerable<string> GetWhitelistEntries()
VisibilityPlugin.Instance.Configuration.VoidList.Remove(item);
VisibilityPlugin.Instance.Configuration.Save();

if (item.ObjectId > 0)
{
this.CheckInitialised();

return VisibilityPlugin
.Instance
.Configuration
.Whitelist
.Select(x => $"{x.Name} {x.HomeworldId} {x.Reason}")
.ToList();
VisibilityPlugin.Instance.RemoveChecked(item.ObjectId);
VisibilityPlugin.Instance.ShowPlayer(item.ObjectId);
}

public void AddToWhitelist(string name, uint worldId, string reason)
else
{
this.CheckInitialised();
VisibilityPlugin.Instance.RemoveChecked(item.Name);
}
}

var world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);
public IEnumerable<string> GetWhitelistEntries()
{
this.CheckInitialised();

return VisibilityPlugin
.Instance
.Configuration
.Whitelist
.Select(x => $"{x.Name} {x.HomeworldId} {x.Reason}")
.ToList();
}

if (world == null)
{
throw new Exception($"Invalid worldId ({worldId}).");
}
public void AddToWhitelist(string name, uint worldId, string reason)
{
this.CheckInitialised();

VisibilityPlugin.Instance.WhitelistPlayer("", $"{name} {world.Name} {reason}");
}
World? world = Service.DataManager.GetExcelSheet<World>()?.SingleOrDefault(x => x.RowId == worldId);

public void RemoveFromWhitelist(string name, uint worldId)
if (world == null)
{
this.CheckInitialised();
throw new Exception($"Invalid worldId ({worldId}).");
}

var item = VisibilityPlugin.Instance.Configuration.Whitelist.SingleOrDefault(
x => x.Name == name && x.HomeworldId == worldId);
VisibilityPlugin.Instance.WhitelistPlayer("", $"{name} {world.Name} {reason}");
}

if (item == null)
{
return;
}
public void RemoveFromWhitelist(string name, uint worldId)
{
this.CheckInitialised();

VisibilityPlugin.Instance.Configuration.Whitelist.Remove(item);
VisibilityPlugin.Instance.Configuration.Save();
}
VoidItem? item = VisibilityPlugin.Instance.Configuration.Whitelist.SingleOrDefault(
x => x.Name == name && x.HomeworldId == worldId);

public void Enable(bool state)
if (item == null)
{
VisibilityPlugin.Instance.Configuration
.SettingDictionary[nameof(VisibilityPlugin.Instance.Configuration.Enabled)].Invoke(state, false, false);
return;
}

public void Dispose()
{
this.initialised = false;
}
VisibilityPlugin.Instance.Configuration.Whitelist.Remove(item);
VisibilityPlugin.Instance.Configuration.Save();
}
}

public void Enable(bool state) =>
VisibilityPlugin.Instance.Configuration
.SettingDictionary[nameof(VisibilityPlugin.Instance.Configuration.Enabled)].Invoke(state, false, false);

public void Dispose() => this.initialised = false;
}
7 changes: 2 additions & 5 deletions Visibility/Configuration/TerritoryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ public class TerritoryConfig
public bool ShowFriendChocobo;
public bool ShowDeadPlayer;

public TerritoryConfig Clone()
{
return (TerritoryConfig)this.MemberwiseClone();
}
}
public TerritoryConfig Clone() => (TerritoryConfig)this.MemberwiseClone();
}
Loading

0 comments on commit 3b24206

Please sign in to comment.