public HubLevel(SkyCoreAPI plugin, string gameId, string levelPath, GameLevelInfo gameLevelInfo, bool modifiable = false) : base(plugin, "hub", gameId, levelPath, gameLevelInfo, modifiable) { AddPendingTask(() => { PlayerLocation portalInfoLocation = new PlayerLocation(256.5, 79.5, 276.5); const string hologramContent = " §d§lSkytonia§r §f§lNetwork§r" + "\n" + " §7Enter the portal and§r" + "\n" + "§7enjoy your adventure!§r" + "\n" + " §ewww.skytonia.com§r"; new Hologram(hologramContent, this, portalInfoLocation).SpawnEntity(); RunnableTask.RunTaskLater(() => { try { PlayerNPC.SpawnAllHubNPCs(this); //SpawnHubMaps(); } catch (Exception e) { BugSnagUtil.ReportBug(e, this); } }, 250); }); }
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(); }
// public void OnEnable(PluginContext context) { context.PluginManager.LoadCommands(new SkyCommands(this)); //Initialize Generic Commands context.PluginManager.LoadCommands(Permissions); //Initialize Permission Commands context.PluginManager.LoadCommands(new GameCommands()); //Initialize GameController Commands (/gameedit) context.PluginManager.LoadCommands(new Whitelist()); //Initialize Whitelist Commands (/whitelist) //Register listeners context.Server.PlayerFactory.PlayerCreated += (sender, args) => { _shouldSchedule = false; //Avoid scheduling pending tasks once a player has joined MiNET.Player player = args.Player; player.PlayerLeave += OnPlayerLeave; if (_pendingTasks.Count > 0) { foreach (PendingTask pendingTask in _pendingTasks) { RunnableTask.RunTaskLater(() => { try { pendingTask.Invoke(); } catch (Exception e) { BugSnagUtil.ReportBug(e, new AnonMetadatable((metadata) => { metadata.AddToTab("PendingTask", "Target", pendingTask.Target); metadata.AddToTab("PendingTask", "Method", pendingTask.Method); })); } }, 5000); } _pendingTasks.Clear(); } }; //Trigger any post-launch tasks that cannot be run during startup foreach (GameController coreGameController in GameModes.Values) { coreGameController.PostLaunchTask(); } //Start RestartHandler for Automatic Reboots RestartHandler.Start(); SkyUtil.log("Initialized!"); }
public override void InitializePlayer() { if (_hasJoined) { return; } try { if (CertificateData.ExtraData.Xuid == null) { Disconnect("§cAn §2§lXBOX§r §caccount required to login to §dSkytonia §eNetwork"); return; } if (Whitelist.IsEnabled() && !Whitelist.OnWhitelist(Username)) { Disconnect(Whitelist.GetWhitelistMessage()); return; } StatisticsCore.AddPlayer(CertificateData.ExtraData.Xuid, Username); //Sync retrieve any active punishments PlayerPunishments playerPunishments = PunishCore.GetPunishmentsFor(CertificateData.ExtraData.Xuid); Punishment activePunishment = playerPunishments.GetActive(PunishmentType.Ban); if (activePunishment != null) { Disconnect("§cYou are currently banned from the §dSkytonia §eNetwork\n" + $"§c({PunishmentMessages.GetNeatExpiryForPunishment(activePunishment)})\n" + $"§cReason: {activePunishment.PunishReason}"); return; } BarHandler = new BarHandler(this); SetPlayerGroup(PlayerGroup.Player); _hasJoined = true; RunnableTask.RunTask(() => { new DatabaseAction().Query( "SELECT `group_name` FROM player_groups WHERE `player_xuid`=@id", (command) => { command.Parameters.AddWithValue("@id", CertificateData.ExtraData.Xuid); }, (reader) => { PlayerGroup.ValueOf(reader.GetString(0), out var playerGroup); if (playerGroup == null) { //Simply set, then update perms in the post-delegate playerGroup = PlayerGroup.Player; } PlayerGroup = playerGroup; }, new Action(delegate { //Update permission levels SetPlayerGroup(PlayerGroup); _isRankLoaded = true; //SkyUtil.log($"Initialized as {PlayerGroup.GroupName}({CommandPermission})"); SetGameMode(GameMode.Adventure); if (SkyCoreApi.GameType.Equals("hub") && PlayerGroup.IsAtLeast(PlayerGroup.Mvp)) { SetAllowFly(true); } foreach (Action action in _postLoginActions) { action.Invoke(); } _postLoginActions.Clear(); if (Username.Equals("OhBlihv") || Username.Equals("Erazeo")) { if (PlayerGroup != PlayerGroup.Admin) { SetPlayerGroup(PlayerGroup.Admin); //SkyUtil.log($"Overriding {Username}'s group to Admin"); } } RunnableTask.RunTaskLater(() => { SendTitle("§f", TitleType.Clear); SendTitle("§f", TitleType.AnimationTimes, 6, 6, 20 * 10); SendTitle("§f", TitleType.ActionBar, 6, 6, 20 * 10); SendTitle("§f", TitleType.Title, 6, 6, 20 * 10); SendTitle("§f", TitleType.SubTitle, 6, 6, 20 * 10); }, 500); //Traditional Loading IsSpawned = true; //Should already be in a 'GameLevel'. //Check and force-spawn them in if they're missing. if (Level is GameLevel level && !level.PlayerTeamDict.ContainsKey(Username)) { level.AddPlayer(this); } GameInfo targetedGame = ExternalGameHandler.GetGameForIncomingPlayer(Username); if (targetedGame != null && (!(Level is GameLevel) || !((GameLevel)Level).GameId.Equals(targetedGame.GameId))) { SkyCoreApi.GameModes[SkyCoreApi.GameType].InstantQueuePlayer(this, targetedGame); } //Search this players pending groups new DatabaseAction().Query( "SELECT `group_name` FROM player_pending_groups WHERE `player_name`=@name", (command) => { command.Parameters.AddWithValue("@name", Username); }, (reader) => { PlayerGroup.ValueOf(reader.GetString(0), out var playerGroup); if (playerGroup == null) { return; } SetPlayerGroup(playerGroup); new DatabaseAction().Execute( "DELETE FROM player_pending_groups WHERE `player_name`=@name", (command) => { command.Parameters.AddWithValue("@name", Username); }, null); 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", CertificateData.ExtraData.Xuid); command.Parameters.AddWithValue("@group", PlayerGroup.GroupName); }, null ); }, null); }) ); }); //Initialize once we've loaded the group etc. base.InitializePlayer(); }
public override void InitializePlayer(GameLevel gameLevel, SkyPlayer player) { if (!player.Effects.ContainsKey(EffectType.NightVision)) { NightVision nightVision = new NightVision { Duration = int.MaxValue, Level = 0, Particles = false }; player.SetEffect(nightVision); } if (!(player.Inventory.Slots[4] is ItemNavigationCompass)) { player.Inventory.SetInventorySlot(4, new ItemNavigationCompass()); //Wait until the compass has appeared to change held slots RunnableTask.RunTaskLater(() => { player.Inventory.SetHeldItemSlot(4); }, 500); } /*try * { * ISet<long> mapIds = MapUtil.GetLevelMapIds(gameLevel); * if (mapIds == null) * { * SkyUtil.log( * $"Attempted to respawn missing maps for {player.Username}, but no maps were registered for {gameLevel.GameId}"); * } * else * { * RunnableTask.RunTaskLater(() => * { * //Murder one as example * Block block = gameLevel.GetBlock(new BlockCoordinates(260, 77, 270)); * * var message = McpeUpdateBlock.CreateObject(); * message.blockId = block.Id; * message.coordinates = block.Coordinates; * message.blockMetaAndPriority = (byte)(0xb << 4 | (block.Metadata & 0xf)); * player.SendPackage(message); * * /*MapUtil.SpawnMapImage(@"C:\Users\Administrator\Desktop\dl\map-images\comingsoonmapimage.png", 1, 1, this, * new BlockCoordinates(249, 77, 268), MapUtil.MapDirection.West); * MapUtil.SpawnMapImage(@"C:\Users\Administrator\Desktop\dl\map-images\buildbattlemapimage.png", 1, 1, this, * new BlockCoordinates(252, 77, 270), MapUtil.MapDirection.West); * MapUtil.SpawnMapImage(@"C:\Users\Administrator\Desktop\dl\map-images\murdermapimage.png", 1, 1, this, * new BlockCoordinates(260, 77, 270), MapUtil.MapDirection.West); * MapUtil.SpawnMapImage(@"C:\Users\Administrator\Desktop\dl\map-images\comingsoonmapimage.png", 1, 1, this, * new BlockCoordinates(263, 77, 268), MapUtil.MapDirection.West);#1# * * /*foreach (long mapEntityId in mapIds) * { * if (gameLevel.GetEntity(mapEntityId) is MapEntity mapEntity) * { * player.SendPackage(((MapImageProvider)mapEntity.ImageProvider).Batch); * } * }#1# * }, 1000); * } * } * catch (Exception e) * { * Console.WriteLine(e); * }*/ }
//New GameLevel Method public void AddPlayer(SkyPlayer player) { if (player.Level != this && player.Level is GameLevel level) { level.RemovePlayer(player, true); //Clear from old world } //Remove a player from _incomingPlayers only if it's non-empty. //Avoid claiming a lock for a useless check if (_incomingPlayers.Count > 0) { lock (_incomingPlayers) { if (_incomingPlayers.ContainsKey(player.Username)) { _incomingPlayers.Remove(player.Username); } } } GameTeam defaultTeam = GetDefaultTeam(); SetPlayerTeam(player, defaultTeam); //SkyUtil.log($"Added {player.Username} to team {defaultTeam.DisplayName} in game {GameId}"); /*if (player.Level != this) * { * //Only show the level transition screen to players changing games on this instance * //player.SpawnLevel(this, GameLevelInfo.LobbyLocation, !_incomingPlayers.ContainsKey(player.Username)); * player.SpawnLevel(this, GameLevelInfo.LobbyLocation, false); //Remove loading screen to prevent 'building terrain' issue * } * else //Still teleport the player to the spawn location * { * player.Teleport(GameLevelInfo.LobbyLocation); * }*/ //Fix for maps on first join to an instance player.SpawnLevel(this, GameLevelInfo.LobbyLocation, false); //Remove loading screen to prevent 'building terrain' issue try { CurrentState.InitializePlayer(this, player); } catch (Exception e) { BugSnagUtil.ReportBug(e, this, CurrentState, player); } //Update Time McpeSetTime message = McpeSetTime.CreateObject(); message.time = GameLevelInfo.WorldTime; player.SendPackage(message); // //Pending Tasks //Attempts to execute tasks like spawning NPCs in once a single player has loaded the world if (_shouldSchedule) { _shouldSchedule = false; if (_pendingTasks.Count > 0) { foreach (SkyCoreAPI.PendingTask pendingTask in _pendingTasks) { RunnableTask.RunTaskLater(() => { try { pendingTask.Invoke(); } catch (Exception e) { BugSnagUtil.ReportBug(e, new AnonMetadatable((metadata) => { metadata.AddToTab("PendingTask", "Target", pendingTask.Target); metadata.AddToTab("PendingTask", "Method", pendingTask.Method); })); } }, 250); //Small delay for the level to initialize } _pendingTasks.Clear(); } } }
public static void SpawnHubNPC(GameLevel level, string npcName, PlayerLocation spawnLocation, string command) { NPCSpawnTask spawnTask = (gameLevel) => { try { if (String.IsNullOrEmpty(npcName)) { Console.WriteLine("§c§l(!) §r§cInvalid NPC text. /hologram <text>"); return; } npcName = npcName.Replace("_", " ").Replace("&", "§"); if (npcName.Equals("\"\"")) { npcName = ""; } string gameName = command; onInteract action = null; if (!String.IsNullOrEmpty(command)) { if (command.StartsWith("GID:")) { gameName = command.Split(':')[1]; switch (gameName) { case "murder": case "build-battle": { action = player => { //Freeze the players movement player.Freeze(true); RunnableTask.RunTaskLater(() => ExternalGameHandler.AddPlayer(player, gameName), 200); }; break; } } } } if (gameName.Equals(command)) { SkyUtil.log($"Unknown game command '{command}'"); return; } //Ensure this NPC can be seen PlayerNPC npc; /*if (action != null) * { * npc = new PlayerNPC("§a(Punch to play)", gameLevel, spawnLocation, action, gameName) { Scale = 1.5 }; * } * else * { * npc = new PlayerNPC("§e(Coming Soon)", gameLevel, spawnLocation, null, gameName) { Scale = 1.5 }; * }*/ npc = new PlayerNPC("", gameLevel, spawnLocation, action, gameName) { Scale = 1.5 }; SkyCoreAPI.Instance.AddPendingTask(() => { npc.KnownPosition = spawnLocation; //npc.Width = 0D; //npc.Height = 1.0D; npc.SpawnEntity(); }); { PlayerLocation playerCountLocation = (PlayerLocation)spawnLocation.Clone(); //Spawn a hologram with player counts PlayerCountHologram hologram = new PlayerCountHologram(npcName, gameLevel, playerCountLocation, gameName); SkyCoreAPI.Instance.AddPendingTask(() => hologram.SpawnEntity()); } { PlayerLocation gameNameLocation = (PlayerLocation)spawnLocation.Clone(); gameNameLocation.Y += 3.1f; Hologram gameNameHologram = new Hologram(npcName, gameLevel, gameNameLocation); SkyCoreAPI.Instance.AddPendingTask(() => gameNameHologram.SpawnEntity()); } Console.WriteLine($"§e§l(!) §r§eSpawned NPC with text '{npcName}§r'"); } catch (Exception e) { Console.WriteLine(e); } }; if (String.IsNullOrWhiteSpace(command)) { SkyUtil.log("Found null command as key. Using npc game name instead."); command = npcName; } GameNPCs.Add(command, spawnTask); if (level != null) { spawnTask.Invoke(level); } }
public override void EnterState(GameLevel gameLevel) { base.EnterState(gameLevel); gameLevel.DoForAllPlayers(player => { player.Inventory.Clear(); }); SkyPlayer winningPlayer = null; List <KeyValuePair <SkyPlayer, int> > topPlayers = null; if (_voteTally != null) { topPlayers = new List <KeyValuePair <SkyPlayer, int> >(); foreach (SkyPlayer player in _voteTally.Keys) { topPlayers.Add(new KeyValuePair <SkyPlayer, int>(player, _voteTally[player])); } topPlayers.Sort((x, y) => 0 - x.Value.CompareTo(y.Value)); int i = 0; foreach (KeyValuePair <SkyPlayer, int> topPlayer in topPlayers) { if (++i > 1) //Top 1 Player for now { break; } //If the player has left, skip them. if (!gameLevel.PlayerTeamDict.ContainsKey(topPlayer.Key.Username)) { i = 0; } else { winningPlayer = topPlayer.Key; } } } string winningPlayerName = winningPlayer == null ? "Unknown..." : winningPlayer.Username; List <PlayerLocation> podiumLocations; if (winningPlayer == null) { BuildBattleTeam podiumCentre; if (topPlayers == null || topPlayers.Count == 0) { //Pick a random team podiumCentre = ((BuildBattleLevel)gameLevel).BuildTeams[0]; } else { //Pick a random player podiumCentre = (BuildBattleTeam)topPlayers[0].Key.GameTeam; } podiumLocations = ((BuildBattleLevel)gameLevel).GetVoteLocations(podiumCentre); } else { podiumLocations = ((BuildBattleLevel)gameLevel).GetVoteLocations((BuildBattleTeam)winningPlayer.GameTeam); } int j = 0; gameLevel.DoForAllPlayers(player => { player.SetAllowFly(true); player.IsFlying = true; player.SendAdventureSettings(); player.Inventory.Clear(); TitleUtil.SendCenteredSubtitle(player, $"§a§lWinning Builder\n§7{winningPlayerName}"); if (player == winningPlayer) { PlayerLocation teleportLocation = (PlayerLocation)((BuildBattleTeam)player.GameTeam).SpawnLocation.Clone(); teleportLocation.Y += 10; player.Teleport(teleportLocation); } else { player.Teleport(podiumLocations[j]); j++; } }); RunnableTask.RunTaskLater(() => { gameLevel.UpdateGameState(GetNextGameState(gameLevel)); }, 5000); }
public override bool DoInteractAtEntity(GameLevel gameLevel, int interactId, SkyPlayer player, SkyPlayer target) { MurderLevel murderLevel = (MurderLevel)gameLevel; Item itemInHand = player.Inventory.GetItemInHand(); if (player == murderLevel.Murderer && itemInHand is ItemMurderKnife && target != null) { KillPlayer((MurderLevel)gameLevel, target); player.Inventory.SetInventorySlot(0, new ItemMurderKnife()); //Update Knife } //Left click only (Right click charges up) else if (interactId != 2 && itemInHand is ItemInnocentGun && PlayerAmmoCounts[player.Username] > 0) { if (player.Experience > 0.05f) { return(true); } var arrow = new GunProjectile(player, gameLevel) { Damage = 0, KnownPosition = (PlayerLocation)player.KnownPosition.Clone() }; arrow.KnownPosition.Y += 1.62f; arrow.Velocity = arrow.KnownPosition.GetHeadDirection() * (2 * 2.0f * 1.5f); arrow.KnownPosition.Yaw = (float)arrow.Velocity.GetYaw(); arrow.KnownPosition.Pitch = (float)arrow.Velocity.GetPitch(); arrow.BroadcastMovement = true; arrow.DespawnOnImpact = true; arrow.SpawnEntity(); int currentAmmo = --PlayerAmmoCounts[player.Username]; if (currentAmmo <= 0) { player.Inventory.SetInventorySlot(0, new ItemAir()); //Remove Gun } else { //Ensure the gun is updated to a 'ItemInnocentGun' rather than an ItemBow RunnableTask.RunTaskLater(() => player.Inventory.SetInventorySlot(0, new ItemInnocentGun()), 50); } const float levelOneFullBarXp = 6.65f; player.Experience = 0; player.AddExperience(levelOneFullBarXp); player.Inventory.SetInventorySlot(9, new ItemAir()); const int updateTicks = 60; const int timerMillis = 50; RunnableTask.RunTaskTimer(() => { player.AddExperience(-(levelOneFullBarXp / updateTicks)); if (currentAmmo > 0 && player.Experience <= 0.1) { player.Inventory.SetInventorySlot(9, new ItemArrow()); } }, timerMillis, updateTicks + 2); } return(true); }