public void CommandUnban(MiNET.Player player, string playerName) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Mod)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } if (PunishCore.GetPunishmentsFor(targetXuid).RemoveActive(PunishmentType.Ban)) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been unbanned."); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not currently banned."); } }); }
public void CommandKick(MiNET.Player player, string playerName, string[] reason) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Helper)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } string punishReason = GetReasonFromArgs(reason); PunishCore.AddKick(targetXuid, punishReason, player.CertificateData.ExtraData.Xuid); SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); target?.Disconnect($"§cYou have been kicked from the server.\n" + $"§6Reason: {punishReason}"); player.SendMessage($"§f[PUNISH] §7{playerName} §chas been kicked for: §f\"{punishReason}\""); }); }
static PunishCore() { SkyCoreAPI.Instance.Server.PluginManager.LoadCommands(new PunishmentCommands()); //Initialize Punishment Commands RunnableTask.RunTask(() => { //TODO: Remove /*new DatabaseAction().Query( * "DROP TABLE `punishments`;", * null, null, null);*/ //TODO: Un-delay once db is finalized RunnableTask.RunTaskLater(() => { new DatabaseAction().Query( "CREATE TABLE IF NOT EXISTS `punishments` (\n" + "`player_xuid` varchar(50) NOT NULL,\n" + "`punish_type` ENUM\n" + " ('Ban', 'Kick', 'Mute') DEFAULT 'Ban' NOT NULL,\n"+ "`issuer` varchar(50) NOT NULL,\n"+ //Issuer XUID "`reason` varchar(128),\n"+ "`active` BOOLEAN,\n"+ "`duration_amount` TINYINT(1) UNSIGNED DEFAULT 0,\n"+ //0-255 possible units "`duration_unit` ENUM\n"+ " ('minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years', 'Permanent') DEFAULT 'Permanent' NOT NULL,\n"+ "`issue_time` DATETIME(1) NOT NULL,\n" + " PRIMARY KEY(`player_xuid`, `punish_type`, `issue_time`)\n" + ");", null, null, null); }, 1000); }); /* * Loops through all players and ensures active punishments * are actually active. * * (Active is a boolean, separate from the Expiry DateTime) */ PunishmentUpdateThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; while (!SkyCoreAPI.IsDisabled) { Thread.Sleep(60000); //60 Second Delay RunUpdateTask(); } }); PunishmentUpdateThread.Start(); }
// static PlayerGroup() { RunnableTask.RunTask(() => { new DatabaseAction().Query( "CREATE TABLE IF NOT EXISTS `player_groups` (\n" + "`player_xuid` varchar(50),\n" + "`group_name` varchar(50),\n" + " PRIMARY KEY(`player_xuid`)\n" + ");", null, null, null); }); }
public void CommandMute(MiNET.Player player, string playerName, params string[] args) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Helper)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { RunPunishmentCommand(player, PunishmentType.Mute, playerName, args); }); }
public static void Start() { if (Timer != null) { throw new Exception("RestartHandler already running!"); } RunnableTask.RunTask(() => { var autoEvent = new AutoResetEvent(false); Timer = new Timer(RestartTask.RestartTick, autoEvent, 1000, 1000); autoEvent.WaitOne(); TriggerReboot(); }); }
public void InitializeNewGame() { RunnableTask.RunTask(() => { lock (GameLevels) { if (GameLevels.Count >= MaxGames) { return; //Cannot create any more games. } GameLevel gameLevel = _initializeNewGame(); if (gameLevel != null) { GameLevels.TryAdd(gameLevel.GameId, gameLevel); } } }); }
static StatisticsCore() { RunnableTask.RunTask(() => { new DatabaseAction().Query( "CREATE TABLE IF NOT EXISTS `player_info` (\n" + "`player_xuid` varchar(32),\n" + "`current_name` varchar(16),\n" + "PRIMARY KEY(`player_xuid`)\n" + ");", null, null, null); new DatabaseAction().Query( "CREATE TABLE IF NOT EXISTS `player_global_stats` (\n" + "`player_xuid` varchar(32),\n" + "`first_join` DATETIME(1) NOT NULL,\n" + "`experience` INT(4) DEFAULT 0,\n" + "`coins` INT(4) DEFAULT 0,\n" + "PRIMARY KEY(`player_xuid`)\n" + ");", null, null, null); }); StatisticUpdateThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; while (!SkyCoreAPI.IsDisabled) { Thread.Sleep(15000); //15 Second Delay RunUpdateTask(); } }); StatisticUpdateThread.Start(); }
public void CommandPermSet(MiNET.Player player, string targetName, string targetGroupName) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Admin)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } if (String.IsNullOrEmpty(targetName)) { player.SendMessage($"{ChatColors.Red}Enter a valid player name."); return; } SkyPlayer target = _skyCoreApi.GetPlayer(targetName); if (target == null || !target.IsConnected) { player.SendMessage($"{ChatColors.Red}Target player is not online."); return; } //Format as our Enums targetGroupName = targetGroupName.ToLower(); targetGroupName = Char.ToUpper(targetGroupName.ToCharArray()[0]) + targetGroupName.Substring(1); if (!PlayerGroup.ValueOf(targetGroupName, out var targetGroup)) { player.SendMessage($"{ChatColors.Red}Unrecognized group name '{targetGroupName}'."); string possibleGroups = ""; foreach (PlayerGroup groupLoop in PlayerGroup.Values) { possibleGroups += groupLoop.GroupName + ","; } player.SendMessage($"Possible Groups: {possibleGroups}"); return; } target.SetPlayerGroup(targetGroup); RunnableTask.RunTask(() => { new DatabaseAction().Execute( "INSERT INTO `player_groups`\n" + " (`player_xuid`, `group_name`)\n" + "VALUES\n" + " (@xuid, @group)\n" + "ON DUPLICATE KEY UPDATE\n" + " `player_xuid` = VALUES(`player_xuid`),\n" + " `group_name` = VALUES(`group_name`);", (command) => { command.Parameters.AddWithValue("@xuid", target.CertificateData.ExtraData.Xuid); command.Parameters.AddWithValue("@group", targetGroup.GroupName); }, new Action(delegate { player.SendMessage($"{ChatColors.Yellow}Updated {target.Username}'s group to {targetGroup.GroupName}"); }) ); }); }
public override void EnterState(GameLevel gameLevel) { base.EnterState(gameLevel); GunPartLocations.Clear(); PlayerSpawnLocations.Clear(); GunPartLocations.AddRange(((MurderLevelInfo)((MurderLevel)gameLevel).GameLevelInfo).GunPartLocations); PlayerSpawnLocations.AddRange(((MurderLevelInfo)((MurderLevel)gameLevel).GameLevelInfo).PlayerSpawnLocations); while (PlayerSpawnLocations.Count < gameLevel.GetMaxPlayers()) { PlayerSpawnLocations.Add(((MurderLevelInfo)((MurderLevel)gameLevel).GameLevelInfo).PlayerSpawnLocations[0]); } EndTick = gameLevel.Tick + MaxGameTime + PreStartTime; try { RunnableTask.RunTask(() => { //Create new collection due to iterating over a live list ICollection <SkyPlayer> players = gameLevel.GetAllPlayers(); foreach (SkyPlayer player in players) { player.SetEffect(new Blindness { Duration = 80, Particles = false }); //Should be 3 seconds? player.SetHideNameTag(true); player.IsAlwaysShowName = false; player.SetNameTagVisibility(false); } List <PlayerLocation> usedSpawnLocations = new List <PlayerLocation>(); gameLevel.DoForAllPlayers(player => { //Pre-add all players to the map to avoid any unnecessary contains if (PlayerAmmoCounts.ContainsKey(player.Username)) { PlayerAmmoCounts[player.Username] = 0; } else { PlayerAmmoCounts.Add(player.Username, 0); } if (PlayerGunPartCounts.ContainsKey(player.Username)) { PlayerGunPartCounts[player.Username] = 0; } else { PlayerGunPartCounts.Add(player.Username, 0); } player.SetGameMode(GameMode.Adventure); //Avoid spawning two players in the same location PlayerLocation spawnLocation; while (usedSpawnLocations.Contains((spawnLocation = PlayerSpawnLocations[Random.Next(PlayerSpawnLocations.Count)]))) { // } usedSpawnLocations.Add(spawnLocation); //Mark spawn position for AFK Check player.SpawnPosition = spawnLocation; player.Teleport(spawnLocation); player.SetHideNameTag(true); player.IsAlwaysShowName = false; player.SetNameTagVisibility(false); player.Freeze(true); player.HungerManager.Hunger = 6; //Set food to 'unable to run' level. player.SendUpdateAttributes(); //TODO: Not required? Or is this required for Hunger }); List <MurderTeam> teamRotation = new List <MurderTeam> { MurderTeam.Murderer, MurderTeam.Detective, MurderTeam.Innocent }; int offset = Random.Next(teamRotation.Count); for (int i = 0; i < 12; i++) { MurderTeam team = teamRotation[(offset + i) % 3]; foreach (SkyPlayer player in players) { TitleUtil.SendCenteredSubtitle(player, team.TeamPrefix + "§l" + team.TeamName); //Poorly enforce speed if (i == 0 || i == 11) { player.Freeze(true); player.SetHideNameTag(true); player.IsAlwaysShowName = false; player.SetNameTagVisibility(false); } } //SkyUtil.log($"Printed scroll {i}/12, with {team.TeamPrefix + "§l" + team.TeamName}"); Thread.Sleep(250); } int murdererIdx = Random.Next(players.Count), detectiveIdx = 0; int idx = 0; while (++idx < 50 && (detectiveIdx = Random.Next(players.Count)) == murdererIdx) { // } //Console.WriteLine($"Rolled Murderer as {murdererIdx} Detective as {detectiveIdx} with 0-{players.Count - 1} possible indexes"); idx = 0; foreach (SkyPlayer player in players) { if (idx == murdererIdx) { gameLevel.SetPlayerTeam(player, MurderTeam.Murderer); } else if (idx == detectiveIdx) { gameLevel.SetPlayerTeam(player, MurderTeam.Detective); } else { gameLevel.SetPlayerTeam(player, MurderTeam.Innocent); } idx++; } //Workaround for one player (single murderer) if (((MurderLevel)gameLevel).Detective == null) { ((MurderLevel)gameLevel).Detective = ((MurderLevel)gameLevel).Murderer; } gameLevel.DoForPlayersIn(player => { TitleUtil.SendCenteredSubtitle(player, "§a§lInnocent §r\n§7Track down the murderer!"); }, MurderTeam.Innocent); gameLevel.DoForPlayersIn(player => { TitleUtil.SendCenteredSubtitle(player, "§9§lDetective §r\n§7Track down the murderer!"); player.Inventory.SetInventorySlot(0, new ItemInnocentGun()); //SkyUtil.log($"In Slot 0 = {player.Inventory.GetSlots()[0].GetType().FullName}"); player.Inventory.SetInventorySlot(9, new ItemArrow()); PlayerAmmoCounts[player.Username] = int.MaxValue; }, MurderTeam.Detective); gameLevel.DoForPlayersIn(InitializeMurderer, MurderTeam.Murderer); gameLevel.DoForAllPlayers(player => { player.SendAdventureSettings(); player.Freeze(false); //Ensure this player is at the correct spawn location if (gameLevel.GetBlock(player.KnownPosition).Id != 0) { PlayerLocation newLocation = (PlayerLocation)player.KnownPosition.Clone(); newLocation.Y++; player.Teleport(newLocation); } }); }); } catch (Exception e) { BugSnagUtil.ReportBug(e, this, gameLevel); } }
public override void EnterState(GameLevel gameLevel) { EndTick = gameLevel.Tick + MaxGameTime + PreStartTime; RunnableTask.RunTask(() => { ICollection <MiNET.Player> players = new List <MiNET.Player>(gameLevel.Players.Values); foreach (BuildBattleTeam gameTeam in ((BuildBattleLevel)gameLevel).BuildTeams) { foreach (SkyPlayer player in gameLevel.GetPlayersInTeam(gameTeam)) { player.IsWorldImmutable = true; //Prevent Breaking //player.IsWorldBuilder = false; player.Teleport(gameTeam.SpawnLocation); player.SetAllowFly(true); player.IsFlying = true; player.SendAdventureSettings(); player.UseCreativeInventory = true; player.UpdateGameMode(GameMode.Creative, false); player.SetNameTagVisibility(false); } } List <BuildBattleTheme> categoryRotation = ((BuildBattleLevel)gameLevel).ThemeList; { int initialTheme = Random.Next(categoryRotation.Count); for (int i = initialTheme; i < (initialTheme + 12); i++) { BuildBattleTheme category = categoryRotation[i % categoryRotation.Count]; foreach (MiNET.Player player in players) { TitleUtil.SendCenteredSubtitle(player, category.ThemeName); } Thread.Sleep(250); } } SelectedCategory = categoryRotation[Random.Next(categoryRotation.Count)]; gameLevel.DoForAllPlayers(player => { player.IsWorldImmutable = true; //Allow breaking //player.IsWorldBuilder = false; player.SendAdventureSettings(); player.UpdateGameMode(GameMode.Creative, true); string secondLine = "§fYou have §75 minutes§f, let's go!"; TitleUtil.SendCenteredSubtitle(player, $"{SelectedCategory.ThemeName}\n{secondLine}"); player.Inventory.Clear(); for (int i = 0; i < SelectedCategory.TemplateItems.Count; i++) { player.Inventory.SetInventorySlot(i, SelectedCategory.TemplateItems[i].GetItem()); } //Ensure this player is at the correct spawn location if (gameLevel.GetBlock(player.KnownPosition).Id != 0) { PlayerLocation newLocation = (PlayerLocation)player.KnownPosition.Clone(); newLocation.Y++; player.Teleport(newLocation); } }); gameLevel.AllowBreak = true; gameLevel.AllowBuild = true; }); }