53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Terraria.ID;
|
|
using Terraria.Localization;
|
|
using Terraria.ModLoader;
|
|
using Terraria;
|
|
using Microsoft.Xna.Framework;
|
|
using Newtonsoft.Json;
|
|
using System.Data;
|
|
using System.IO;
|
|
using Terraria.Map;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace tTP.Common.Systems
|
|
{
|
|
internal class ModPlayerOnEnterWorld
|
|
{
|
|
public class ModPlayerOnEnterWorldPlayer : ModPlayer
|
|
{
|
|
public override void OnEnterWorld()
|
|
{
|
|
if (!Directory.Exists("tTP")) { Directory.CreateDirectory("tTP"); }
|
|
tTP.worldName = Main.worldName;
|
|
|
|
if (!File.Exists($"tTP/{tTP.worldName}.json"))
|
|
{
|
|
string prepjson = @"{ ""tp"": " + '[' + ']' + " }";
|
|
File.WriteAllText($"tTP/{tTP.worldName}.json", prepjson);
|
|
}
|
|
|
|
string json = File.ReadAllText($"tTP/{tTP.worldName}.json");
|
|
dynamic jo = JsonConvert.DeserializeObject(json);
|
|
JArray jar = jo["tp"];
|
|
if (jar.Count == 0)
|
|
{
|
|
tTP.table.Columns.Add("name", typeof(String));
|
|
tTP.table.Columns.Add("x", typeof(Int64));
|
|
tTP.table.Columns.Add("y", typeof(Int64));
|
|
} else
|
|
{
|
|
int tpc = jar.Count;
|
|
Main.NewText($"[tTP] You have {tpc} Personal Teleporter in this world.", Color.Aqua);
|
|
DataSet ds = JsonConvert.DeserializeObject<DataSet>(File.ReadAllText($"tTP/{tTP.worldName}.json"));
|
|
tTP.table = ds.Tables["tp"];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|