Skip to content
This repository has been archived by the owner on Feb 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17 from Renerte/develop
Browse files Browse the repository at this point in the history
Release 1.1.0.0
  • Loading branch information
Renerte authored Jun 4, 2020
2 parents fc36250 + 8da37a9 commit 2321e6a
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 66 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install NuGet
run: wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- name: Restore packages
run: mono nuget.exe restore CitieZ.sln
- name: Build CitieZ
run: msbuild CitieZ.sln /p:Configuration=Release
- uses: actions/upload-artifact@master
with:
name: CitieZ
path: CitieZ/bin/Release/CitieZ.dll
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install NuGet
run: wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- name: Restore packages
run: mono nuget.exe restore KitZ.sln
- name: Build CitieZ
run: msbuild CitieZ.sln /p:Configuration=Release
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./CitieZ/bin/Release/CitieZ.dll
asset_name: CitieZ.dll
asset_content_type: application/vnd.microsoft.portable-executable
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

CitieZ.sln.DotSettings.user
.idea/

# User-specific files
*.suo
*.user
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml

This file was deleted.

15 changes: 7 additions & 8 deletions CitieZ/CitieZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CitieZ
{
[ApiVersion(2, 0)]
[ApiVersion(2, 1)]
public class CitieZ : TerrariaPlugin
{
public CitieZ(Main game) : base(game)
Expand All @@ -39,6 +39,7 @@ protected override void Dispose(bool disposing)
ServerApi.Hooks.GameInitialize.Deregister(this, OnGameInitialize);
ServerApi.Hooks.GamePostInitialize.Deregister(this, OnGamePostInitialize);
}

base.Dispose(disposing);
}

Expand All @@ -64,17 +65,18 @@ private async void OnRegionEntered(RegionHooks.RegionEnteredEventArgs e)
if (city != null)
{
var first = city.Discovered.Count == 0;
if (!e.Player.HasPermission("citiez.all") && !city.Discovered.Contains(e.Player.User.ID) &&
if (!e.Player.HasPermission("citiez.all") && !city.Discovered.Contains(e.Player.Account.ID) &&
await Cities.DiscoverAsync(city.Name, e.Player))
{
if (first && await Cities.AddDiscoveryAsync(city.Name, e.Player))
e.Player.SendInfoMessage(string.Format(Config.FirstDiscoveredCity, city.Name));
e.Player.SendInfoMessage(string.Format(Config.DiscoveredCity, city.Name));
}

var discovery = await Cities.GetDiscoveryAsync(city.Name);
if (discovery == null)
return;
e.Player.SendInfoMessage(string.Format(Config.WelcomeMessage, city.Name, discovery.PlayerName));
e.Player.SendInfoMessage(string.Format(Config.WelcomeMessage, city.Name, discovery.User.Name));
}
}

Expand Down Expand Up @@ -140,14 +142,11 @@ private void OnGameInitialize(EventArgs e)

#region Commands

//Allows overriding of already created commands.
Action<Command> Add = c =>
void Add(Command c)
{
//Finds any commands with names and aliases that match the new command and removes them.
TShockAPI.Commands.ChatCommands.RemoveAll(c2 => c2.Names.Exists(s2 => c.Names.Contains(s2)));
//Then adds the new command.
TShockAPI.Commands.ChatCommands.Add(c);
};
}

Add(new Command("citiez.tp", Commands.City, "city")
{
Expand Down
21 changes: 6 additions & 15 deletions CitieZ/CitieZ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Data.Sqlite">
<HintPath>..\References\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="OTAPI">
<HintPath>..\References\OTAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -74,7 +60,12 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mono.Data.Sqlite" Version="1.0.61" />
<PackageReference Include="MySql.Data" Version="6.9.12" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="OTAPI" Version="2.0.0.36" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
9 changes: 7 additions & 2 deletions CitieZ/Commands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using CitieZ.Util;
using TShockAPI;

Expand All @@ -13,8 +13,9 @@ public static async void City(CommandArgs e)
e.Player.SendErrorMessage("Use: /city name");
return;
}

var city = await CitieZ.Cities.GetAsync(e.Parameters[0]);
if (city != null && (city.Discovered.Contains(e.Player.User.ID) || e.Player.HasPermission("citiez.all")))
if (city != null && (city.Discovered.Contains(e.Player.Account.ID) || e.Player.HasPermission("citiez.all")))
{
e.Player.SendInfoMessage(string.Format(CitieZ.Config.TeleportingToCity, city.Name));
e.Player.Teleport(city.Warp.X * 16, city.Warp.Y * 16);
Expand All @@ -33,6 +34,7 @@ public static async void Manage(CommandArgs e)
$"CitieZ v{Assembly.GetExecutingAssembly().GetName().Version} by Renerte - the best city system for TShock!");
return;
}

switch (e.Parameters[0])
{
case "add":
Expand All @@ -41,6 +43,7 @@ public static async void Manage(CommandArgs e)
e.Player.SendErrorMessage("Use: /citiez add name region");
break;
}

if (
await
CitieZ.Cities.AddAsync(e.Parameters[1], e.Parameters[2],
Expand All @@ -53,6 +56,7 @@ public static async void Manage(CommandArgs e)
e.Player.SendErrorMessage("Use: /citiez setwarp name");
break;
}

if (await CitieZ.Cities.SetWarpAsync(e.Parameters[1], new Position(e.Player.TileX, e.Player.TileY)))
e.Player.SendInfoMessage($"Successfully set warp for city {e.Parameters[1]}");
break;
Expand All @@ -62,6 +66,7 @@ public static async void Manage(CommandArgs e)
e.Player.SendErrorMessage("Use: /citiez setregion name region");
break;
}

if (await CitieZ.Cities.SetRegionAsync(e.Parameters[1], e.Parameters[2]))
e.Player.SendInfoMessage($"Successfully set region {e.Parameters[2]} to city {e.Parameters[1]}");
else
Expand Down
4 changes: 2 additions & 2 deletions CitieZ/Db/City.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public City(string name, string regionName, Position warp, List<int> discovered)
Discovered = discovered;
}

public string Name { get; private set; }
public List<int> Discovered { get; private set; }
public string Name { get; }
public List<int> Discovered { get; }
}
}
12 changes: 7 additions & 5 deletions CitieZ/Db/CityDiscovery.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
namespace CitieZ.Db
using TShockAPI.DB;

namespace CitieZ.Db
{
public class CityDiscovery
{
public CityDiscovery(string cityName, string playerName)
public CityDiscovery(string cityName, UserAccount user)
{
CityName = cityName;
PlayerName = playerName;
User = user;
}

public string CityName { get; private set; }
public string PlayerName { get; private set; }
public string CityName { get; }
public UserAccount User { get; }
}
}
31 changes: 17 additions & 14 deletions CitieZ/Db/CityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CityManager(IDbConnection db)
sqlCreator.EnsureTableStructure(new SqlTable("CityDiscoveries",
new SqlColumn("ID", MySqlDbType.Int32) {AutoIncrement = true, Primary = true},
new SqlColumn("City", MySqlDbType.VarChar, 32) {Unique = true, Length = 32},
new SqlColumn("Player", MySqlDbType.VarChar, 32) {Length = 32},
new SqlColumn("UserID", MySqlDbType.Int32, 32) {Length = 32},
new SqlColumn("WorldID", MySqlDbType.Int32)));

using (
Expand All @@ -58,7 +58,7 @@ public CityManager(IDbConnection db)
while (result.Read())
discoveries.Add(new CityDiscovery(
result.Get<string>("City"),
TShock.Users.GetUserByName(result.Get<string>("Player")).Name));
TShock.UserAccounts.GetUserAccountByID(result.Get<int>("UserID"))));
}

TShock.Log.ConsoleInfo($"[CitieZ] {discoveries.Count} cities have been discovered!");
Expand Down Expand Up @@ -87,14 +87,16 @@ public async Task<bool> ReloadAsync()

discoveries.Clear();
using (
var result = db.QueryReader("SELECT * FROM CityDiscoveries WHERE WorldID = @0", Main.worldID)
var result = db.QueryReader("SELECT * FROM CityDiscoveries WHERE WorldID = @0",
Main.worldID)
)
{
while (result.Read())
discoveries.Add(new CityDiscovery(
result.Get<string>("City"),
TShock.Users.GetUserByName(result.Get<string>("Player")).Name));
TShock.UserAccounts.GetUserAccountByID(result.Get<int>("UserID"))));
}

return true;
}
}
Expand Down Expand Up @@ -161,8 +163,8 @@ public async Task<bool> SetWarpAsync(string name, Position warpPosition)
{
city.Warp = warpPosition;
return db.Query(query,
warpPosition,
name) > 0;
warpPosition,
name) > 0;
}
}
catch (Exception ex)
Expand All @@ -188,8 +190,8 @@ public async Task<bool> SetRegionAsync(string name, string regionName)
{
city.RegionName = regionName;
return db.Query(query,
regionName,
name) > 0;
regionName,
name) > 0;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -230,7 +232,8 @@ public async Task<City> FindByRegionAsync(string regionName)
{
lock (syncLock)
{
return cities.Find(c => c.RegionName.Equals(regionName, StringComparison.InvariantCultureIgnoreCase));
return cities.Find(
c => c.RegionName.Equals(regionName, StringComparison.InvariantCultureIgnoreCase));
}
});
}
Expand All @@ -248,10 +251,10 @@ public async Task<bool> DiscoverAsync(string name, TSPlayer player)
lock (syncLock)
{
var city = cities.Find(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
city.Discovered.Add(player.User.ID);
city.Discovered.Add(player.Account.ID);
return db.Query(query,
string.Join(",", city.Discovered),
name) > 0;
string.Join(",", city.Discovered),
name) > 0;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -281,11 +284,11 @@ public async Task<bool> AddDiscoveryAsync(string name, TSPlayer player)
{
lock (syncLock)
{
discoveries.Add(new CityDiscovery(name, player.User.Name));
discoveries.Add(new CityDiscovery(name, player.Account));
return
db.Query("INSERT INTO CityDiscoveries (City, Player, WorldID) VALUES (@0, @1, @2)",
name,
player.Name,
player.Account.ID,
Main.worldID) > 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions CitieZ/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
9 changes: 1 addition & 8 deletions CitieZ/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

</configuration>
6 changes: 0 additions & 6 deletions CitieZ/packages.config

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

|Branch|Status|
|------|------|
|master|[![Build Status](https://travis-ci.com/Renerte/CitieZ.svg?token=LoXu7euXY6qjUVn9K8KV&branch=master)](https://travis-ci.com/Renerte/CitieZ)|
|develop|[![Build Status](https://travis-ci.com/Renerte/CitieZ.svg?token=LoXu7euXY6qjUVn9K8KV&branch=develop)](https://travis-ci.com/Renerte/CitieZ)|
|Stable|![Build](https://github.com/Renerte/CitieZ/workflows/Build/badge.svg?branch=master)|
|Edge|![Build](https://github.com/Renerte/CitieZ/workflows/Build/badge.svg?branch=develop)|

Configurable cities system for your TShock server!
Binary file removed References/Mono.Data.Sqlite.dll
Binary file not shown.
Binary file removed References/OTAPI.dll
Binary file not shown.
Binary file modified References/TShockAPI.dll
Binary file not shown.
Binary file modified References/TerrariaServer.exe
Binary file not shown.

0 comments on commit 2321e6a

Please sign in to comment.