ketchu13

7dtd-server-fixes - ListPrefabs Console Command

Sep 27th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.16 KB | None | 0 0
  1. //7 Days To Die - List prefabs files in /Data/Prefabs folder.
  2. //@Author: Alloc => 7dtd-server-fixes => https://7dtd.illy.bz/browser/binary-improvements/7dtd-server-fixes
  3. //@Author: ketchu13 => Unban console command => [email protected]
  4. using System;
  5. using System.IO;
  6.  
  7.  
  8. namespace AllocsFixes.CustomCommands
  9. {
  10.     public class ListPrefabs: ConsoleCommand
  11.     {
  12.         private readonly string prefabsPath = UnityEngine.Application.dataPath + "/../Data/Prefabs";
  13.         //private readonly string prefabsXMLpath = UnityEngine.Application.dataPath + "/../Data/Worlds/Random Gen/PrefabsKFP.xml";
  14.         //private readonly World world = CommonMappingFunctions.GetGameManager().World;
  15.  
  16.         public ListPrefabs(ConsoleSdtd cons) : base(cons)
  17.         {
  18.         }
  19.  
  20.         public override string Description ()
  21.         {
  22.             return "List all prefab files in /Data/Prefabs folder.";
  23.         }
  24.  
  25.         public override string[] Names ()
  26.         {
  27.             return new string[] { "lisprefabs", "lpf" };
  28.         }
  29.  
  30.         public override void Run (string[] _params)
  31.         {
  32.             try {
  33.                 if (_params.Length != 1 || _params [0].Length == 0) {
  34.                     m_Console.SendResult ("Usage: listprefabs <searchString>");
  35.                     m_Console.SendResult ("    or listprefabs All");
  36.                     return;
  37.                 }
  38.                
  39.                 string[] prefabsList = Directory.GetFiles(prefabsPath, "*.tts");
  40.                 int num = 0;
  41.                
  42.  
  43.                 if (_params[0].Equals("All")) {
  44.                     m_Console.SendResult("***Liste de tous les prefabs***");
  45.                     foreach (string s in prefabsList) {
  46.                         m_Console.SendResult (num + "   " + Path.GetFileNameWithoutExtension(s));
  47.                         num++;
  48.                     }
  49.                     m_Console.SendResult ("Listed " + num + "prefabs.");
  50.                 }else {
  51.                     m_Console.SendResult("***Liste des prefabs contenant " + _params [0] + "***");
  52.                     foreach (string s in prefabsList) {
  53.                         string fileName = Path.GetFileNameWithoutExtension(s);
  54.                         if (fileName.ToLower ().Contains (_params [0].ToLower ())) {
  55.                             m_Console.SendResult (num + "   " +  fileName);
  56.                             num++;
  57.                         }
  58.                     }
  59.                     m_Console.SendResult ("Listed " + num + " matching prefabs.");
  60.                 }
  61.             }
  62.             catch (Exception ex) {
  63.                 Log.Out("ListPrefab error: " + ex.Message);
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment