本文整理汇总了C#中MinecraftServer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# MinecraftServer.Start方法的具体用法?C# MinecraftServer.Start怎么用?C# MinecraftServer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MinecraftServer
的用法示例。
在下文中一共展示了MinecraftServer.Start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSoundEffects
public void TestSoundEffects()
{
var server = new MinecraftServer(new IPEndPoint(IPAddress.Loopback, 25565));
server.AddLevel(new Level());
server.Settings.MotD = "Sound effect test";
server.Settings.OnlineMode = false;
server.Start();
bool success = true;
string failedSound = "n/a";
DateTime inconclusiveTime = DateTime.Now.AddSeconds(100);
Queue<string> effects = new Queue<string>();
Thread test = null;
foreach (var effect in typeof(SoundEffect).GetFields().Where(f => f.FieldType == typeof(string) && f.IsLiteral))
{
effects.Enqueue(effect.GetValue(new SoundEffect()) as string);
}
server.PlayerLoggedIn += (s ,e) =>
{
e.Client.SendChat("Beginning sound effect test in 5 seconds. Type \"fail\" into chat to indicate failure.");
inconclusiveTime = DateTime.MaxValue;
test = new Thread(new ThreadStart(() =>
{
Thread.Sleep(5000);
while (effects.Any())
{
e.Client.SendChat("Playing sound: " + effects.Peek());
e.Client.SendPacket(new NamedSoundEffectPacket(effects.Peek(), e.Client.Entity.Position));
Thread.Sleep(5000);
effects.Dequeue();
}
}));
test.Start();
e.Handled = true;
};
server.PlayerLoggedOut += (s, e) =>
{
test.Abort();
server.Stop();
success = false;
failedSound = "Player left before test completion.";
effects = new Queue<string>();
e.Handled = true;
Assert.Fail("Player left before test completion.");
};
server.ChatMessage += (s, e) =>
{
if (e.RawMessage == "fail")
{
test.Abort();
server.Stop();
failedSound = effects.Peek();
effects = new Queue<string>();
success = false;
Assert.Fail("Sound effect: " + effects.Peek());
}
};
while (effects.Count != 0 && DateTime.Now < inconclusiveTime) { Thread.Sleep(100); }
if (DateTime.Now >= inconclusiveTime)
Assert.Inconclusive("No player joined within 10 second time limit.");
else
{
if (success)
Assert.Pass();
else
Assert.Fail("Failed sound effect: " + failedSound);
}
}