Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
- removed waste
- code cleaned
- better practices implemented
- /dm alias now works
- /dm reload, help & clear added
- better error handling
  • Loading branch information
RenderBr committed Jun 9, 2023
1 parent 0f1355c commit 7863f78
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 3,127 deletions.
41 changes: 17 additions & 24 deletions Api/DiemobApi.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
using Auxiliary;
using Auxiliary.Configuration;
using MongoDB.Driver;
using System.Collections.Generic;
using System.Threading.Tasks;
using TShockAPI;

namespace DieMob.Api
{
public class DiemobApi
{
public class DiemobApi
{

public void DeleteDiemob(string regionName)
{
StorageProvider.GetMongoCollection<DieMobRegion>("DieMobRegions").FindOneAndDeleteAsync(x => x.Region == regionName);
}
public void DeleteDiemob(string regionName) => StorageProvider.GetMongoCollection<DieMobRegion>("DieMobRegions").FindOneAndDeleteAsync(x => x.Region == regionName);

public List<DieMobRegion> RetrieveAllRegions()
{
return StorageProvider.GetMongoCollection<DieMobRegion>("DieMobRegions").Find(x => true).ToList();
public List<DieMobRegion> RetrieveAllRegions() => StorageProvider.GetMongoCollection<DieMobRegion>("DieMobRegions").Find(x => true).ToList();

}
public async Task<DieMobRegion> RetrieveRegion(string regionName) => await IModel.GetAsync(GetRequest.Bson<DieMobRegion>(x => x.Region == regionName));

public async Task<DieMobRegion> RetrieveRegion(string regionName)
{
return await IModel.GetAsync(GetRequest.Bson<DieMobRegion>(x => x.Region == regionName));
}

public async Task<DieMobRegion> CreateDieMobRegion(string regionName)
=> await IModel.GetAsync(GetRequest.Bson<DieMobRegion>(x => x.Region == regionName), x =>
{
x.Region = TShock.Regions.GetRegionByName(regionName).Name;
x.AffectFriendlyNPCs = false;
x.AffectStatueSpawns = true;
x.ReplaceMobs = new();
x.Type = RegionType.Kill;
});

public async Task<DieMobRegion> CreateDieMobRegion(string regionName)
=> await IModel.GetAsync(GetRequest.Bson<DieMobRegion>(x => x.Region == regionName), x =>
{
x.Region = TShock.Regions.GetRegionByName(regionName).Name;
x.AffectFriendlyNPCs = false;
x.AffectStatueSpawns = true;
x.ReplaceMobs = new();
x.Type = RegionType.Kill;
});
public void ReloadDieMob() => Configuration<DiemobSettings>.Load(nameof(DieMob));


}
}
}
18 changes: 9 additions & 9 deletions DiemobSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace DieMob
{
public class DiemobSettings : ISettings
{
[JsonPropertyName("UpdateInterval")]
public int UpdateInterval { get; set; }
public class DiemobSettings : ISettings
{
[JsonPropertyName("UpdateInterval")]
public int UpdateInterval { get; set; }

[JsonPropertyName("RepelPowerModifier")]
public float RepelPowerModifier { get; set; }
[JsonPropertyName("RepelPowerModifier")]
public float RepelPowerModifier { get; set; }

[JsonPropertyName("RegionStretch")]
public int RegionStretch { get; set; }
}
[JsonPropertyName("RegionStretch")]
public int RegionStretch { get; set; }
}
}
134 changes: 67 additions & 67 deletions Models/DieMobRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,77 @@

namespace DieMob
{
public class DieMobRegion : BsonModel
{
private string _region;
public string Region
{
get
=> _region;
set
{
_ = this.SaveAsync(x => x.Region, value);
_region = value;
}
}
public class DieMobRegion : BsonModel
{
private string _region;
public string Region
{
get
=> _region;
set
{
_ = this.SaveAsync(x => x.Region, value);
_region = value;
}
}

private RegionType _type;
public RegionType Type
{
get
=> _type;
set
{
_ = this.SaveAsync(x => x.Type, value);
_type = value;
}
}
private RegionType _type;
public RegionType Type
{
get
=> _type;
set
{
_ = this.SaveAsync(x => x.Type, value);
_type = value;
}
}

private Dictionary<int, int> _replaceMobs;
public Dictionary<int, int> ReplaceMobs
{
get
=> _replaceMobs;
set
{
_ = this.SaveAsync(x => x.ReplaceMobs, value);
_replaceMobs = value;
}
}
private Dictionary<int, int> _replaceMobs;
public Dictionary<int, int> ReplaceMobs
{
get
=> _replaceMobs;
set
{
_ = this.SaveAsync(x => x.ReplaceMobs, value);
_replaceMobs = value;
}
}

private bool _affectFriendlyNPCS;
public bool AffectFriendlyNPCs
{
get
=> _affectFriendlyNPCS;
set
{
_ = this.SaveAsync(x => x.AffectFriendlyNPCs, value);
_affectFriendlyNPCS = value;
}
}
private bool _affectFriendlyNPCS;
public bool AffectFriendlyNPCs
{
get
=> _affectFriendlyNPCS;
set
{
_ = this.SaveAsync(x => x.AffectFriendlyNPCs, value);
_affectFriendlyNPCS = value;
}
}

private bool _affectStatueSpawns;
public bool AffectStatueSpawns
{
get
=> _affectStatueSpawns;
set
{
_ = this.SaveAsync(x => x.AffectStatueSpawns, value);
_affectStatueSpawns = value;
}
}
private bool _affectStatueSpawns;
public bool AffectStatueSpawns
{
get
=> _affectStatueSpawns;
set
{
_ = this.SaveAsync(x => x.AffectStatueSpawns, value);
_affectStatueSpawns = value;
}
}

public DieMobRegion() { }
public DieMobRegion() { }

public DieMobRegion(Region _reg)
{
Region = _reg.Name;
Type = RegionType.Kill;
ReplaceMobs = new Dictionary<int, int>();
AffectFriendlyNPCs = false;
AffectStatueSpawns = false;
}
}
public DieMobRegion(Region _reg)
{
Region = _reg.Name;
Type = RegionType.Kill;
ReplaceMobs = new Dictionary<int, int>();
AffectFriendlyNPCs = false;
AffectStatueSpawns = false;
}
}
}
12 changes: 6 additions & 6 deletions Models/RegionType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace DieMob
{
public enum RegionType
{
Kill = 0,
Repel = 1,
Passive = 2
}
public enum RegionType
{
Kill = 0,
Repel = 1,
Passive = 2
}
}
11 changes: 5 additions & 6 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Reflection;
using Terraria;
using Terraria.Localization;
using TerrariaApi.Server;
Expand All @@ -14,8 +15,6 @@

namespace DieMob
{


[ApiVersion(2, 1)]
public class Plugin : TerrariaPlugin
{
Expand All @@ -30,12 +29,12 @@ public override string Description
=> "Removes any entities that decide to enter a region";

public override Version Version
=> new(1, 0);
=> new Version(1, 1);

#endregion
#endregion

#region Plugin Initialization
public Plugin(Main game)
#region Plugin Initialization
public Plugin(Main game)
: base(game)
{
Order = 1;
Expand Down
Loading

0 comments on commit 7863f78

Please sign in to comment.