Beispiel #1
0
        void OnPlayerPermission(PlayerPermissionEventArgs e)
        {
            // If the player isn't logged it, he's certainly not a contributor
            if (e.Player == null || !e.Player.IsLoggedIn || !e.Player.ContainsData(Contributor.DataKey))
            {
                return;
            }

            Contributor con = e.Player.GetData <Contributor>(Contributor.DataKey);

            #region DEBUG
#if DEBUG
            //TShock.Log.ConsoleInfo("[" + e.Player.Index + "] Checking permission for: " + e.Permission);
#endif
            #endregion

            Tier tier = Tiers.Get(con.Tier);
            e.Handled = tier.Permissions.HasPermission(e.Permission);
            #region DEBUG
#if DEBUG
            if (e.Handled)
            {
                TShock.Log.ConsoleInfo("OnPlayerPermission: Contributor had the permission");
            }
#endif
            #endregion
        }
Beispiel #2
0
        void MultiplyExp(object sender, PendingTransactionEventArgs e)
        {
            // Should only work with system accounts as this will also make the sender pay more currency
            if (SEconomyPlugin.Instance != null &&
                e.ToAccount != null &&
                e.FromAccount != null &&
                e.FromAccount.IsSystemAccount &&
                (!e.Options.HasFlag(BankAccountTransferOptions.SuppressDefaultAnnounceMessages)))
            {
                // Find the player (note: could be troublesome if multiple login is enabled)
                var player = (from p in TShock.Players
                              where p.IsLoggedIn && p.User.Name == e.ToAccount.UserAccountName &&
                              p.ContainsData(Contributor.DataKey)
                              select p).FirstOrDefault();

                if (player == null)
                {
                    return;
                }

                Contributor con = player.GetData <Contributor>(Contributor.DataKey);

                // Get the tier, find the experience multiplier
                Tier tier = Tiers.Get(con.Tier);
                if (tier == null)
                {
                    TShock.Log.ConsoleError($"CTRS: contributor {con.Accounts[0]} has an invalid tier ID! ({con.Tier})");
                    return;
                }

                if (tier.ExperienceMultiplier != 1f)
                {
                    // Multiply the amount of currency gained by the experience multiplier
                    e.Amount = new Money(Convert.ToInt64(e.Amount.Value * tier.ExperienceMultiplier));
                }
            }
        }
Beispiel #3
0
        void OnChat(ServerChatEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            // A quick check to reduce DB work when this feature isn't in use
            if (String.IsNullOrWhiteSpace(Config.ContributorChatFormat))
            {
                return;
            }

            var player = TShock.Players[e.Who];

            if (player == null || !player.Active || !player.IsLoggedIn || !player.ContainsData(Contributor.DataKey))
            {
                return;
            }

            if (e.Text.Length > 500)
            {
                return;
            }

            // If true, the message is a command, so we skip it
            if ((e.Text.StartsWith(TShockAPI.Commands.Specifier) || e.Text.StartsWith(TShockAPI.Commands.SilentSpecifier)) &&
                !String.IsNullOrWhiteSpace(e.Text.Substring(1)))
            {
                return;
            }

            // Player needs to be able to talk, not be muted, and must be logged in
            if (!player.HasPermission(TShockAPI.Permissions.canchat) || player.mute || !player.IsLoggedIn)
            {
                return;
            }

            // At this point, ChatAboveHeads is not supported, but it could be a thing in the future
            if (!TShock.Config.EnableChatAboveHeads)
            {
                Contributor con  = player.GetData <Contributor>(Contributor.DataKey);
                Tier        tier = Tiers.Get(con.Tier);

                /* Contributor chat format:
                 *      {0} - group name
                 *      {1} - group prefix
                 *      {2} - player name
                 *      {3} - group suffix
                 *      {4} - message text
                 *      {5} - tier shortname
                 *      {6} - tier name
                 *      {7} - webID
                 */
                var text = String.Format(Config.ContributorChatFormat, player.Group.Name, player.Group.Prefix, player.Name,
                                         player.Group.Suffix, e.Text, tier.ShortName ?? "", tier.Name ?? "", con.XenforoId ?? -1);
                PlayerHooks.OnPlayerChat(player, e.Text, ref text);
                Color?color = con.ChatColor;
                if (!color.HasValue)
                {
                    #region DEBUG
#if DEBUG
                    TShock.Log.ConsoleInfo("OnChat: Contributor color was null");
#endif
                    #endregion
                    // If the contributor doesn't have a custom chat color, check their tier
                    color = tier.ChatColor;
                    if (!color.HasValue)
                    {
                        // As neither the tier nor the contributor have a custom chat color, use the group's default
                        color = new Color(player.Group.R, player.Group.G, player.Group.B);
                    }
                }
                TShock.Utils.Broadcast(text, color.Value.R, color.Value.G, color.Value.B);
                #region
#if DEBUG
                TShock.Log.ConsoleInfo("OnChat: Contributor was handled by CTRS");
#endif
                #endregion
                e.Handled = true;
            }
        }