Ejemplo n.º 1
0
            public void deliver()
            {
                StringBuilder sb1 = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();

                foreach (ulong id in Conversation.Participants)
                {
                    Profile    profile = ProfileData.getProfile(id);
                    BasePlayer player  = profile.Player;
                    if (player == Sender)
                    {
                        continue;
                    }
                    player.ChatMessage(string.Format(PluginInstance.lang.GetMessage(msg.message.ToString(), PluginInstance), SenderName, Content));
                    profile.lastConversation = Conversation.ID;
                    sb1.Append($" {player.displayName}[{player.userID}]");
                    sb2.Append($"\n{player.displayName}({profile.Status})");
                }
                string logEntry = $"{DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")} {SenderName}[{SenderID}] -> [{sb1.ToString().Trim()}]: \"{Content}\"";

                PluginInstance.Puts(logEntry);
                PluginInstance.LogToFile("Messages", logEntry, PluginInstance);
                PluginInstance.PrintToChat(Sender, PluginInstance.lang.GetMessage(msg.messageSent.ToString(), PluginInstance, Sender.UserIDString), Content, sb2);
                //Sender.ChatMessage($"Message: {Content} \ndelivered to {sb2}");
            }
Ejemplo n.º 2
0
            public void display(BasePlayer player)
            {
                if (this.Count == 0)
                {
                    return;
                }

                foreach (CuiElement element in this)
                {
                    if (!string.IsNullOrEmpty(element.Name))
                    {
                        element.Name = PluginInstance.prependContainerName(this, element.Name);
                    }
                    if (!string.IsNullOrEmpty(element.Parent) && !layers.Contains(element.Parent))
                    {
                        element.Parent = PluginInstance.prependContainerName(this, element.Parent);
                    }
                }

                GuiTracker.getGuiTracker(player).addGuiToTracker(plugin, this);

#if DEBUG
                PluginInstance.Puts(JsonConvert.SerializeObject(this));
                player.ConsoleMessage(JsonConvert.SerializeObject(this));
#endif

                CuiHelper.AddUi(player, CuiContainer);
            }
Ejemplo n.º 3
0
 private void purgeDuplicates(string name)
 {
     foreach (GuiElement element in this)
     {
         if (element.Name == name)
         {
             PluginInstance.Puts($"Duplicate element: {element.Name} in container: {this.name}");
             this.Remove(element);
             return;
         }
     }
 }
Ejemplo n.º 4
0
 public static void load()
 {
     try
     {
         instance = CooldownDataFile.ReadObject <CooldownData>();
     }
     catch (Exception E)
     {
         StringBuilder sb = new StringBuilder($"loading {typeof(CooldownData).Name} failed. Make sure that all classes you're saving have a default constructor!\n");
         sb.Append(E.Message);
         PluginInstance.Puts(sb.ToString());
     }
 }
Ejemplo n.º 5
0
                public void ProcessDownload(Action finishCallback)
                {
                    var il = new GameObject("WebObject").AddComponent <ImageLoader>();

                    il.StartCoroutine(il.DownloadImage(Url, (b) =>
                    {
                        PluginInstance.ImageLibrary.Call("AddImageData", SafeName, b, (ulong)0, Callback);
                        finishCallback();
#if CoroutineDEBUG
                        PluginInstance.Puts($"completed processing image download: {SafeName}");
#endif
                    }, ImgSizeX, ImgSizeY, finishCallback));
                }
Ejemplo n.º 6
0
 public static void save()
 {
     if (!initialized)
     {
         init();
     }
     try
     {
         bountyDataFile.WriteObject(instance);
     }
     catch (Exception E)
     {
         StringBuilder sb = new StringBuilder($"saving {typeof(BountyData).Name} failed. Are you trying to save complex classes like BasePlayer or Item? that won't work!\n");
         sb.Append(E.Message);
         PluginInstance.Puts(sb.ToString());
     }
 }
Ejemplo n.º 7
0
            public IEnumerator DownloadImage(string url, Action <byte[]> callback, int?sizeX = null, int?sizeY = null, Action ErrorCallback = null)
            {
                UnityWebRequest www = UnityWebRequest.Get(url);

                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    PluginInstance.Puts(string.Format("Image failed to download! Error: {0}, Image URL: {1}", www.error, url));
                    www.Dispose();
                    ErrorCallback?.Invoke();
                    yield break;
                }

                Texture2D texture = new Texture2D(2, 2);

                texture.LoadImage(www.downloadHandler.data);

                byte[] originalBytes = null;
                byte[] resizedBytes  = null;

                if (texture != null)
                {
                    originalBytes = texture.EncodeToPNG();
                }
                else
                {
                    ErrorCallback?.Invoke();
                }

                if (sizeX != null && sizeY != null)
                {
                    resizedBytes = Resize(originalBytes, sizeX.Value, sizeY.Value, sizeX.Value, sizeY.Value, true);
                }

                if (originalBytes.Length <= resizedBytes.Length)
                {
                    callback(originalBytes);
                }
                else
                {
                    callback(resizedBytes);
                }

                www.Dispose();
            }
Ejemplo n.º 8
0
 public bool runCallback(string name, BasePlayer player, string[] input)
 {
     if (!callbacks.ContainsKey(name))
     {
         return(false);
     }
     try
     {
         callbacks[name](player, input);
         return(true);
     }
     catch (Exception E)
     {
         PluginInstance.Puts($"Failed to run callback: {name}, {E.Message}");
         return(false);
     }
 }
Ejemplo n.º 9
0
 public void tick()
 {
     try
     {
         PluginInstance.sendHunterIndicator(hunter, this);
     }
     catch (Exception e)
     {
         PluginInstance.Puts(e.Message);
     }
     try
     {
         PluginInstance.sendTargetIndicator(target, this);
     }
     catch (Exception e)
     {
         PluginInstance.Puts(e.Message);
     }
 }
Ejemplo n.º 10
0
 public Hunt(Bounty bounty, BasePlayer hunter)
 {
     if (bounty.hunt != null)
     {
         PluginInstance.Puts($"Hunt Constructor: Bounty {bounty.placerName} -> {bounty.targetName} already has an ongoing hunt!");
     }
     timestamp   = DateTime.Now;
     this.bounty = bounty;
     hunterID    = hunter.userID;
     hunterName  = hunter.displayName;
     initTicker();
     PluginInstance.sendHunterIndicator(hunter, this);
     PluginInstance.sendTargetIndicator(target, this);
     HuntData.addHunt(this);
     if (PluginInstance.hasPermission(hunter, permissions.mask))
     {
         hunter.ChatMessage("<color=#00ff33>Hunt started!</color> Remember that you can use /mask and /unmask to randomize your name for some extra stealth!");
     }
     PluginInstance.LogToFile(huntLogFileName, $"{DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")} Hunt started: {hunter.displayName}[{hunter.UserIDString}] hunting {target.displayName}[{target.UserIDString}], placed by {bounty.placerName}[{bounty.placerID}]", PluginInstance);
 }
Ejemplo n.º 11
0
            private void destroyGuiContainer(Plugin plugin, GuiContainer container, List <GuiContainer> garbage)
            {
#if DEBUG
                player.ChatMessage($"destroyGuiContainer: start {plugin.Name} {container.name}");
#endif
                if (activeGuiContainers.Contains(container))
                {
                    foreach (GuiContainer cont in activeGuiContainers)
                    {
                        if (cont.plugin != container.plugin)
                        {
                            continue;
                        }
                        if (cont.parent == container.name)
                        {
                            destroyGuiContainer(cont.plugin, cont, garbage);
                        }
                    }
                    container.closeCallback?.Invoke(player);
                    List <GuiElement> eGarbage = new List <GuiElement>();
                    foreach (GuiElement element in container)
                    {
                        destroyGuiElement(plugin, container, element.Name, eGarbage);
                    }
                    foreach (GuiElement element in eGarbage)
                    {
                        container.Remove(element);
                    }
                    foreach (Timer timer in container.timers)
                    {
                        timer.Destroy();
                    }
                    garbage.Add(container);
                }
                else
                {
                    PluginInstance.Puts($"destroyGui(container.name: {container.name}): no GUI containers found");
                }
            }