Skip to content

Instantly share code, notes, and snippets.

View NiclasOlofsson's full-sized avatar

Niclas Olofsson NiclasOlofsson

View GitHub Profile
[Plugin]
public class StartupPlugin : Plugin, IStartup
{
private static readonly ILog Log = LogManager.GetLogger(typeof (StartupPlugin));
/// <summary>
/// Startup class for MiNET. Example sets the user and role managers and stores
/// for the application.
/// </summary>
/// <param name="server"></param>
@NiclasOlofsson
NiclasOlofsson / gist:f07edb6df8de8ebc3a90
Created March 9, 2015 18:21
MiNET login command in plugin.
[Plugin("CoreCommands", "The core commands for MiNET", "1.0", "MiNET Team")]
public class CoreCommands : Plugin
{
[Command]
public void Login(Player player, string password)
{
UserManager<User> userManager = player.Server.UserManager;
if (userManager != null)
{
if (player.Username == null) return;
@NiclasOlofsson
NiclasOlofsson / Plugin.cs
Last active December 26, 2015 19:08
MiNET configuration using JSON
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Xml.Serialization;
using log4net;
using MiNET.Plugins;
[Plugin]
public class PlayerLoginPlugin
{
private static readonly ILog Log = LogManager.GetLogger(typeof (PlayerLoginPlugin));
[PacketHandler]
public Package OnLogin(McpeLogin packet, Player newPlayer)
{
Log.InfoFormat("Player {0} connected from {1}", newPlayer.Username, newPlayer.EndPoint.Address);
using System.Collections.Generic;
using System.Threading.Tasks;
using MiNET;
using MiNET.BlockEntities;
using MiNET.Blocks;
using MiNET.Utils;
using MiNET.Worlds;
namespace TestPlugin.MobHunt
{
@NiclasOlofsson
NiclasOlofsson / server.conf
Created June 16, 2015 14:20
Example server.conf
#DO NOT REMOVE THIS LINE - MiNET Config
#WorldProvider=anvil
WorldProvider=flat
ViewDistance=250
#PCWorldFolder=D:\Downloads\KingsLanding1\KingsLanding1
#PCWaterOffset=30
#PCWorldFolder=D:\Development\Worlds\MiniGames\Capture the flag
#PCWorldFolder=D:\Development\Worlds\MiniGames\Castle Wars
#PCWorldFolder=D:\Development\Worlds\MiniGames\King of the hill
public class TextEntity : Entity
{
public TextEntity(Level level, string text, Vector3 pos) : base(64, level)
{
NameTag = text;
KnownPosition = new PlayerLocation(pos);
HealthManager = new NoDamageHealthManager(this);
}
public override void OnTick()
@NiclasOlofsson
NiclasOlofsson / ecdh.cs
Last active April 20, 2016 15:37
ECDH key import
var clientKey = CreateEcDiffieHellmanPublicKey("MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEDEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyodFH+wO0dEr4GM1WoaWog8xsYQ6mQJAC0eVpBM96spUB1eMN56+BwlJ4H3Qx4TAvAs");
private ECDiffieHellmanPublicKey CreateEcDiffieHellmanPublicKey(string clientPubKeyString)
{
byte[] clientPublicKeyBlob = Base64Url.Decode(clientPubKeyString);
clientPublicKeyBlob = FixPublicKey(clientPublicKeyBlob.Skip(23).ToArray());
ECDiffieHellmanPublicKey clientKey = ECDiffieHellmanCngPublicKey.FromByteArray(clientPublicKeyBlob, CngKeyBlobFormat.EccPublicBlob);
return clientKey;
}
public class CountDownTimer
{
private Stopwatch _startTimer;
private TimeSpan _delay;
private long _currentTick;
private readonly int _skipTicks;
private readonly Action<TimeSpan> _tickAction;
private readonly Action _endAction;
@NiclasOlofsson
NiclasOlofsson / Hologram.cs
Last active July 2, 2016 16:26
Hologram class based on invisible players.
public class Hologram : Mob
{
public UUID Uuid { get; private set; }
public string Name { get; private set; }
public bool Silent { get; set; }
public bool HideNameTag { get; set; }
public bool NoAi { get; set; }
public Hologram(Level level) : base(63, level)
{