public async void OnOtherMessage(IServerConsole console, ServerMessage message) { string deathMessage = MatchesDeathMessage(message.Text); if (deathMessage == null) { return; } console.SendCommand("save-all", false, false); await Task.Delay(3000); string player = message.Text.Split(' ')[0].Trim(); if (!File.Exists(Path.Combine(console.Server.WorkingDirectory, "usercache.json"))) { return; } var items = JsonConvert.DeserializeObject <UserCacheItem[]>(File.ReadAllText(Path.Combine(console.Server.WorkingDirectory, "usercache.json"))); string uuid = null; foreach (UserCacheItem item in items) { if (item.Name == player) { uuid = item.UUID; } } if (uuid == null) { return; } bool worldPropertyExists = console.Server.TryGetProperty("level-name", out string world); if (!worldPropertyExists) { return; } string playerData = Path.Combine(console.Server.WorkingDirectory, world, $"playerdata/{uuid}.dat"); if (!File.Exists(playerData)) { return; } var data = new NbtFile(playerData).RootTag.Get <NbtList>("Pos"); console.SendCommand(CommandHelper.Tellraw("@a", new MinecraftTextComponent($"[Death Location] {player} died at approximately ({string.Join(", ", data.Select(x => (int)x.DoubleValue))})", MinecraftColor.light_purple)), true, false); }
protected override void OnStart(string[] args) { logging.WriteEntry("Service start"); serverActivator = new RemoteServerActivator(); string currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); ServerConsoleSettings serverConsoleSettings = new ServerConsoleSettings(ConfigurationManager.AppSettings); string assemblyDirectory = Path.Combine(currentDirectory, serverConsoleSettings.ServerAssembliesFolder); string filePath = Path.Combine(assemblyDirectory, serverConsoleSettings.RemoteServerActivatorAssembly); ObjectHandle objectHandle = null; try { objectHandle = Activator.CreateInstanceFrom(filePath, serverConsoleSettings.ActivatorName, true, BindingFlags.Instance | BindingFlags.Public, null, null, null, null, AppDomain.CurrentDomain.Evidence); } catch (Exception ex) { logging.WriteEntry(ex, "eCustomSyncSvc.OnStart(string[] args)"); throw ex.InnerException; } try { serverActivator = (IServerConsole)objectHandle.Unwrap(); //GlobalUsage.RemoteServerActivator = serverActivator; } catch (Exception e) { logging.WriteEntry(e, "eCustomSyncSvc.OnStart(string[] args)"); } try { serverActivator.Start(args); } catch (Exception exception) { logging.WriteEntry(exception, "eCustomSyncSvc c-tor"); } logging.WriteEntry("Starting the timer listener!"); timer.Start(); logging.WriteEntry("Starting Deletion Service!"); deletionService.Open(); logging.WriteEntry("All Services Started successfully!"); }
/// <summary> /// Called when the server exits /// </summary> /// <param name="console">The server GUI - provides access to the underlying server process</param> public void OnExit(IServerConsole console) { foreach (IPlugin plugin in Enabled) { try { plugin.OnExit(console); } catch (Exception ex) { console.DisplayLine($"Error in method OnExit for plugin {plugin.Name}: {ex}", red); } } }
/// <summary> /// Called when a player disconnects from the server /// </summary> /// <param name="console">The server GUI - provides access to the underlying server process</param> /// <param name="message">The disconnection message</param> public void OnPlayerDisconnect(IServerConsole console, ServerConnectionMessage message) { foreach (IPlugin plugin in Enabled) { try { plugin.OnPlayerDisconnect(console, message); } catch (Exception ex) { console.DisplayLine($"Error in method OnPlayerDisconnect for plugin {plugin.Name}: {ex}", red); } } }
private async void PostWebhookMessage(DiscordWebhookMessage message, IServerConsole console) { if (config.WebhookUrl == null) { return; } try { await client.PostAsync(config.WebhookUrl, new StringContent(message.ToString(), Encoding.UTF8, "application/json")); } catch (Exception ex) { console.DisplayLine($"[Discord Webhook] Error sending webhook message: {ex}", Color.Red); } }
public void OnPlayerConnect(IServerConsole console, ServerConnectionMessage message) { var recentChat = new List <string>(); foreach (var m in chatMessages) { if (m.Timestamp > DateTime.Now - TimeSpan.FromMinutes(30)) { recentChat.Add($"{m.Timestamp:[HH:mm:ss]} {m}"); } } if (recentChat.Count > 0) { console.SendCommand( CommandHelper.Tellraw( message.Username, new MinecraftTextComponent { Text = $"Welcome {message.Username}! Here are some recent chat messages:", Color = MinecraftColor.gold } ), displayInConsole: false, addToHistory: false ); foreach (string s in recentChat) { console.SendCommand( CommandHelper.Tellraw( message.Username, new MinecraftTextComponent { Text = s, Color = MinecraftColor.gold } ), displayInConsole: false, addToHistory: false ); } } chatMessages.AddLast(message); }
/// <summary> /// Attaches a Monitor to the Server /// </summary> /// <param name="monitor">Monitor</param> public void AttachMonitor(ServerMonitor monitor) { this.DetachMonitor(); //Set up logger this._activeLogger = new MonitorLogger(monitor, this._logFormat); this._server.AddLogger(this._activeLogger); //Set up console this._activeConsole = new MonitorConsole(monitor); if (this._server.Console is MulticastConsole) { ((MulticastConsole)this._server.Console).AddConsole(this._activeConsole); } else { IServerConsole current = this._server.Console; IServerConsole multicast = new MulticastConsole(new IServerConsole[] { current, this._activeConsole }); this._server.Console = multicast; } }
public void OnPlayerDisconnect(IServerConsole console, ServerConnectionMessage message) { chatMessages.AddLast(message); }
public void OnOtherMessage(IServerConsole console, ServerMessage message) { }
public void OnSuccessMessage(IServerConsole console, ServerSuccessMessage message) { }
public void OnErrorMessage(IServerConsole console, ServerErrorMessage message) { }
public void OnChatMessage(IServerConsole console, ServerChatMessage message) { chatMessages.AddLast(message); }
public void OnExit(IServerConsole console) { }
public void OnPlayerDisconnect(IServerConsole console, ServerConnectionMessage message) { PostWebhookMessage(DiscordWebhookMessage.FromServerMessage(message), console); }
public void OnChatMessage(IServerConsole console, ServerChatMessage message) { }
public void OnExit(IServerConsole console) { PostWebhookMessage(new DiscordWebhookMessage("Server is now offline"), console); }
public void OnPlayerDisconnect(IServerConsole console, ServerConnectionMessage message) { }
public void OnExit(IServerConsole console) { chatMessages.Clear(); }
public void OnStart(IServerConsole console) { }