public Punishment GetActive(PunishmentType punishmentType) { if (Punishments.ContainsKey(punishmentType)) { SortedSet <Punishment> punishments = Punishments[punishmentType]; //SkyUtil.log($"Punishments (in order):\n -{string.Join("\n -", (from o in punishments select o.ToString()).ToArray())}"); if (punishments.Count == 0) { return(null); } //Dodgy way to get 1st entry Punishment punishment = punishments.Min; if (punishment != null && punishment.IsActive()) { return(punishment); } /*if (punishment != null) * { * SkyUtil.log("Ban Found, not active? " + punishment); * }*/ } //SkyUtil.log("Nothing found. Keys: " + Punishments.Keys.ToArray()); return(null); }
private static void RunPunishmentCommand(MiNET.Player player, PunishmentType punishmentType, String playerName, string[] args) { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } args = ParseExpiryTime(player, args, out DurationUnit durationUnit, out int durationAmount); if (args == null) { return; //Message printed to player } string punishReason = GetReasonFromArgs(args); DateTime expiry = UpdateExpiryTime(durationUnit, durationAmount); Punishment punishment = new Punishment(punishReason, player.CertificateData.ExtraData.Xuid, true, durationAmount, durationUnit, expiry); PunishCore.AddPunishment(targetXuid, punishmentType, punishment); if (punishmentType == PunishmentType.Ban) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned permanently for: \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } } else if (punishmentType == PunishmentType.Mute) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted permanently for: \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } } }
public static void AddPunishment(string xuid, PunishmentType punishmentType, Punishment punishment) { PlayerPunishments playerPunishments = GetPunishmentsFor(xuid); playerPunishments.AddPunishment(punishmentType, punishment); punishment.Dirty = true; //Flag for db saving //Ban/Mute have durations, must be held active if (punishmentType != PunishmentType.Kick) { punishment.Active = true; //Set active by default } }
public static string GetNeatExpiryForPunishment(Punishment punishment) { string expiryString = ""; if (punishment.DurationUnit != DurationUnit.Permanent) { TimeSpan expiryTime = punishment.Expiry.Subtract(DateTime.Now); if (expiryTime.Days > 0) { expiryString += expiryTime.Days + " Days"; } if (expiryTime.Hours > 0) { if (expiryString.Length > 0) { expiryString += " "; } expiryString += expiryTime.Hours + " Hours"; } if (expiryTime.Minutes > 0) { if (expiryString.Length > 0) { expiryString += " "; } expiryString += expiryTime.Minutes + " Minutes"; } if (expiryTime.Seconds > 0) { if (expiryString.Length > 0) { expiryString += " "; } expiryString += expiryTime.Seconds + " Seconds"; } expiryString += $" Remaining"; } else { expiryString = "Permanent"; } return(expiryString); }
public bool RemoveActive(PunishmentType punishmentType) { Punishment activePunishment = GetActive(punishmentType); if (activePunishment != null) { if (activePunishment.Active) { activePunishment.Active = false; activePunishment.Dirty = true; } return(true); } return(false); }
public void AddPunishment(PunishmentType punishmentType, Punishment punishment) { //Deactivate existing punishment if exists RemoveActive(punishmentType); SortedSet <Punishment> punishments; if (Punishments.ContainsKey(punishmentType)) { punishments = Punishments[punishmentType]; } else { punishments = new SortedSet <Punishment>(); Punishments.Add(punishmentType, punishments); } punishments.Add(punishment); }
public static string GetPunishmentMessage(SkyPlayer player, PunishmentType punishmentType, Punishment punishment) { switch (punishmentType) { case PunishmentType.Kick: { return (TextUtils.CenterLine("§d§lSkytonia §f§lNetwork") + "\n" + "\n" + TextUtils.CenterLine("§r§cYou have been kicked from Skytonia!") + "\n" + TextUtils.CenterLine($"§r§7Reason: §f{punishment.PunishReason}") + "\n" + "\n" + TextUtils.CenterLine("§r§7Read our rules at: §e§nwww.skytonia.com/rules")); } case PunishmentType.Ban: { return (TextUtils.CenterLine("§d§lSkytonia §f§lNetwork") + "\n" + "\n" + TextUtils.CenterLine("§r§cYou have been banned from entering Skytonia!") + "\n" + "\n" + (punishment.DurationUnit == DurationUnit.Permanent ? TextUtils.CenterLine($"§r§7Time: §fPermanent") + "\n" : TextUtils.CenterLine($"§r§7Time: §f{GetNeatExpiryForPunishment(punishment)}") + "\n") + TextUtils.CenterLine($"§r§7Reason: §f{punishment.PunishReason}") + "\n" + TextUtils.CenterLine($"§r§7Date: §f{punishment.GetIssueDate()}") + "\n" + "\n" + TextUtils.CenterLine("§r§7Appeal at: §e§nwww.skytonia.com/appeal")); } case PunishmentType.Mute: { return ("§f[PUNISH] §cYou are currently muted from talking in chat.\n" + "§7Read our rules at: §e§nwww.skytonia.com/rules"); } } return(null); }
public PendingUpdatePunishment(string playerXuid, PunishmentType punishmentType, Punishment punishment) { PlayerXuid = playerXuid; PunishmentType = punishmentType; Punishment = punishment; }