本文整理汇总了C#中fCraft.CommandReader.Rewind方法的典型用法代码示例。如果您正苦于以下问题:C# CommandReader.Rewind方法的具体用法?C# CommandReader.Rewind怎么用?C# CommandReader.Rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fCraft.CommandReader
的用法示例。
在下文中一共展示了CommandReader.Rewind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TeleportHandler
static void TeleportHandler( Player player, CommandReader cmd ) {
string name = cmd.Next();
if( name == null ) {
CdTeleport.PrintUsage( player );
return;
}
if( cmd.Next() != null ) {
cmd.Rewind();
int x, y, z;
if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) {
if( x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024 ) {
player.Message( "Coordinates are outside the valid range!" );
} else {
player.TeleportTo( new Position {
X = (short)(x * 32 + 16),
Y = (short)(y * 32 + 16),
Z = (short)(z * 32 + 16),
R = player.Position.R,
L = player.Position.L
} );
}
} else {
CdTeleport.PrintUsage( player );
}
} else {
if( name == "-" ) {
if( player.LastUsedPlayerName != null ) {
name = player.LastUsedPlayerName;
} else {
player.Message( "Cannot repeat player name: you haven't used any names yet." );
return;
}
}
Player[] matches = Server.FindPlayers( player, name, false, true, true );
if( matches.Length == 1 ) {
Player target = matches[0];
World targetWorld = target.World;
if( targetWorld == null ) PlayerOpException.ThrowNoWorld( target );
if( targetWorld == player.World ) {
player.TeleportTo( target.Position );
} else {
switch( targetWorld.AccessSecurity.CheckDetailed( player.Info ) ) {
case SecurityCheckResult.Allowed:
case SecurityCheckResult.WhiteListed:
if( targetWorld.IsFull ) {
player.Message( "Cannot teleport to {0}&S because world {1}&S is full.",
target.ClassyName,
targetWorld.ClassyName );
return;
}
player.StopSpectating();
player.JoinWorld( targetWorld, WorldChangeReason.Tp, target.Position );
break;
case SecurityCheckResult.BlackListed:
player.Message( "Cannot teleport to {0}&S because you are blacklisted on world {1}",
target.ClassyName,
targetWorld.ClassyName );
break;
case SecurityCheckResult.RankTooLow:
player.Message( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
target.ClassyName,
targetWorld.ClassyName,
targetWorld.AccessSecurity.MinRank.ClassyName );
break;
}
}
} else if( matches.Length > 1 ) {
player.MessageManyMatches( "player", matches );
} else {
player.MessageNoPlayer( name );
}
}
}
示例2: LeBotHandler
private static void LeBotHandler(Player player, CommandReader cmd) {
string cmdchat = cmd.Next();
string option = cmd.Next();
string helper = cmd.Next();
if (cmdchat == null) {
player.Message(CdBot.Help);
return;
}
if (option != null)
option = option.ToLower();
if (cmdchat != "<CalledFromChat>") {
cmd.Rewind();
option = cmd.Next().ToLower();
helper = cmd.Next();
player.ParseMessage(string.Format("Bot {0} {1}", option ?? "", helper ?? ""), (player == Player.Console));
return;
}
if (player.Info.TimeSinceLastServerMessage.TotalSeconds < 5) {
player.Info.getLeftOverTime(5, cmd);
return;
}
if (option == null) {
player.Message(CdBot.Help);
return;
}
if (player.Info.TimesUsedBot == 0) {
player.Message(
"&6Bot&f: This is your first time using &6Bot&s, I suggest you use \"/Help Bot\" to further understand how I work.");
}
bool sentMessage = true;
switch (option) {
case "go":
Scheduler.NewTask(t => Server.BotMessage("5")).RunManual(TimeSpan.FromSeconds(0));
Scheduler.NewTask(t => Server.BotMessage("4")).RunManual(TimeSpan.FromSeconds(1));
Scheduler.NewTask(t => Server.BotMessage("3")).RunManual(TimeSpan.FromSeconds(2));
Scheduler.NewTask(t => Server.BotMessage("2")).RunManual(TimeSpan.FromSeconds(3));
Scheduler.NewTask(t => Server.BotMessage("1")).RunManual(TimeSpan.FromSeconds(4));
Scheduler.NewTask(t => Server.BotMessage("Go!")).RunManual(TimeSpan.FromSeconds(5));
break;
case "server":
Server.BotMessage("The name of this server is " + ConfigKey.ServerName.GetString() + ".");
break;
case "joke":
FileInfo jokeList = new FileInfo("./Bot/Jokes.txt");
string[] jokeStrings;
if (jokeList.Exists) {
jokeStrings = File.ReadAllLines("./Bot/Jokes.txt");
} else {
Server.BotMessage("I cannot tell a joke at this time!");
return;
}
Random RandjokeString = new Random();
string joker = jokeStrings[RandjokeString.Next(0, jokeStrings.Length)];
Server.BotMessage(joker);
break;
case "idea":
FileInfo adjectiveList = new FileInfo("./Bot/Adjectives.txt");
FileInfo nounList = new FileInfo("./Bot/Nouns.txt");
string[] adjectiveStrings;
string[] nounStrings;
if (adjectiveList.Exists && nounList.Exists) {
adjectiveStrings = File.ReadAllLines("./Bot/Adjectives.txt");
nounStrings = File.ReadAllLines("./Bot/Nouns.txt");
} else {
Server.BotMessage("I cannot tell you a build idea at this time!");
return;
}
Random randAdjectiveString = new Random();
Random randNounString = new Random();
string adjective = adjectiveStrings[randAdjectiveString.Next(0, adjectiveStrings.Length)];
string noun = nounStrings[randNounString.Next(0, nounStrings.Length)];
string ana = "a";
if (adjective.StartsWith("a") || adjective.StartsWith("e") || adjective.StartsWith("i") ||
adjective.StartsWith("o") || adjective.StartsWith("u")) {
ana = "an";
} else if (noun.EndsWith("s")) {
ana = "some";
}
Server.BotMessage("Build " + ana + " " + adjective + " " + noun);
break;
case "protip":
FileInfo tipList = new FileInfo("./Bot/Protips.txt");
string[] tipStrings;
if (tipList.Exists) {
tipStrings = File.ReadAllLines("./Bot/Protips.txt");
} else {
Server.BotMessage("I cannot tell a protip at this time!");
return;
}
Random RandtipString = new Random();
string tipper = tipStrings[RandtipString.Next(0, tipStrings.Length)];
Server.BotMessage(tipper);
break;
case "time":
TimeSpan time = player.Info.TotalTime;
TimeSpan timenow = player.Info.TimeSinceLastLogin;
if (helper == "total") {
Server.BotMessage(player.ClassyName + "&f has spent a total of {0:F2} hours on this server.", time.TotalHours);
} else {
Server.BotMessage(player.ClassyName + "&f has played a total of {0:F2} minutes this session.", timenow.TotalMinutes);
//.........这里部分代码省略.........
示例3: PlaceHandler
private static void PlaceHandler(Player player, CommandReader cmd) {
bool isConsole = (player == Player.Console);
if (isConsole && cmd.Count < 6) {
player.Message("When used by console /Place requires a world name.");
player.Message("/Place [x] [y] [z] [block] [world]");
return;
}
Block block = Block.Stone;
if (!isConsole && player.LastUsedBlockType != Block.None)
block = player.LastUsedBlockType;
Vector3I coords;
int x, y, z;
if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
if (cmd.HasNext) {
string last = cmd.Next();
if (!Map.GetBlockByName(last, false, out block)) {
player.Message("\"{0}\" is not a valid block type", last);
return;
}
}
coords = new Vector3I(x, y, z);
} else if (isConsole) {
player.Message("Invalid coordinates!");
return;
} else {
cmd.Rewind();
if (cmd.HasNext) {
string last = cmd.Next();
if (!Map.GetBlockByName(last, false, out block)) {
player.Message("\"{0}\" is not a valid block type", last);
return;
}
}
coords = new Vector3I(player.Position.X / 32, player.Position.Y / 32, (player.Position.Z - 64) / 32);
}
World world;
if (player == Player.Console) {
string worldName = cmd.Next();
if (string.IsNullOrEmpty(worldName)) {
player.Message("Console must specify a world!");
}
world = WorldManager.FindWorldOrPrintMatches(player, worldName);
if (world == null)
return;
} else {
world = player.World;
}
bool unLoad = false;
if (!world.IsLoaded) {
world.LoadMap();
unLoad = true;
}
coords.X = Math.Min(world.map.Width - 1, Math.Max(0, coords.X));
coords.Y = Math.Min(world.map.Length - 1, Math.Max(0, coords.Y));
coords.Z = Math.Min(world.map.Height - 1, Math.Max(0, coords.Z));
if (player == Player.Console) {
BlockUpdate blockUpdate = new BlockUpdate(player, coords, block);
player.Info.ProcessBlockPlaced((byte)block);
world.map.QueueUpdate(blockUpdate);
player.RaisePlayerPlacedBlockEvent(player, world.map, coords, block, world.map.GetBlock(coords), BlockChangeContext.Manual, true);
} else {
player.SendNow(Packet.MakeSetBlock(coords, block, player));
player.PlaceBlockWithEvents(coords, ClickAction.Build, block);
}
if (!isConsole)
player.Message("{0} placed at {1}", block.ToString(), coords.ToString());
if (unLoad) {
world.UnloadMap(true);
}
}
示例4: TeleportHandler
private static void TeleportHandler(Player player, CommandReader cmd) {
string name = cmd.Next();
if (name == null) {
CdTeleport.PrintUsage(player);
return;
}
if (player.World.Name.ToLower() == "maze") {
player.Message("Hey no cheating!");
return;
}
if (name == "zone") {
string zoneName = cmd.Next();
if (zoneName == null) {
player.Message("No zone name specified. See &H/Help tpzone");
return;
} else {
Zone zone = player.World.Map.Zones.Find(zoneName);
if (zone == null) {
player.MessageNoZone(zoneName);
return;
}
int zoneX = (zone.Bounds.XMin + zone.Bounds.XMax)/2;
int zoneY = (zone.Bounds.YMin + zone.Bounds.YMax)/2;
int zoneZ = (zone.Bounds.ZMin + zone.Bounds.ZMax)/2;
retry2:
if (player.World.map.GetBlock(zoneX, zoneY, zoneZ - 1) == Block.Air) {
zoneZ = zoneZ - 1;
goto retry2;
}
retry:
if (player.World.map.GetBlock(zoneX, zoneY, zoneZ) != Block.Air ||
player.World.map.GetBlock(zoneX, zoneY, zoneZ + 1) != Block.Air) {
zoneZ = zoneZ + 1;
goto retry;
}
Position zPos = new Position((zoneX) * 32 + 16, (zoneY) * 32 + 16, (zoneZ) * 32 + 64);
if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
}
player.TeleportTo((zPos));
player.Message("&sTeleporting you to zone " + zone.ClassyName);
return;
}
}
if (name == "random" || name == "rand") {
Random rand = new Random();
int x = rand.Next(0, player.WorldMap.Width);
int y = rand.Next(0, player.WorldMap.Length);
int z = player.Position.Z/32 + 1;
retry2:
if (player.World.map.GetBlock(x, y, z - 3) == Block.Air) {
z = z - 1;
goto retry2;
}
retry:
if (player.World.map.GetBlock(x, y, z - 2) != Block.Air ||
player.World.map.GetBlock(x, y, z - 1) != Block.Air) {
z = z + 1;
goto retry;
}
if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
}
player.TeleportTo(new Position {
X = (short) (x*32 + 16),
Y = (short) (y*32 + 16),
Z = (short) (z*32 + 16),
R = player.Position.R,
L = player.Position.L
});
player.Message("Teleported to: ({0}, {1}, {2})", x, y, z);
return;
}
if (cmd.Next() != null) {
cmd.Rewind();
int x, y, z, rot, lot;
rot = player.Position.R;
lot = player.Position.L;
if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
if (cmd.HasNext) {
if (cmd.HasNext) {
if (cmd.NextInt(out rot) && cmd.NextInt(out lot)) {
if (rot > 255 || rot < 0) {
player.Message("R must be inbetween 0 and 255. Set to player R");
}
if (lot > 255 || lot < 0) {
player.Message("L must be inbetween 0 and 255. Set to player L");
}
}
}
}
if (x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024) {
player.Message("Coordinates are outside the valid range!");
} else {
if (player.World != null) {
//.........这里部分代码省略.........
示例5: GlobalBlockHandler
static void GlobalBlockHandler(Player player, CommandReader cmd) {
string opt = cmd.Next();
if (opt != null)
opt = opt.ToLower();
switch (opt) {
case "create":
case "add":
if (player.currentGB != null)
GlobalBlockDefineHandler(player, cmd.NextAll());
else
GlobalBlockAddHandler(player, cmd);
break;
case "nvm":
case "abort":
if (player.currentGB == null) {
player.Message("You do not have a global custom block definition currently being created.");
} else {
player.currentGB = null;
player.currentGBStep = -1;
player.Message("Discarded the global custom block definition that was being created.");
}
break;
case "edit":
case "change":
GlobalBlockEditHandler(player, cmd);
break;
case "copy":
case "duplicate":
GlobalBlockDuplicateHandler(player, cmd);
break;
case "i":
case "info":
string input = cmd.Next() ?? "n/a";
Block def;
if (!Map.GetBlockByName(input, false, out def) || def < Map.MaxCustomBlockType) {
player.Message("No blocks by that name or id!");
return;
}
BlockDefinition block = BlockDefinition.GlobalDefinitions[(byte)def];
if (block == null) {
player.Message("No custom block by the Name/ID");
player.Message("Use \"&h/gb list\" &sto see a list of global custom blocks.");
return;
}
Block fallback;
Map.GetBlockByName(block.FallBack.ToString(), false, out fallback);
player.Message("&3---Name&3:&a{0} &3ID:&a{1}&3---", block.Name, block.BlockID);
player.Message(" &3FallBack: &a{0}&3, Solidity: &a{2}&3, Speed: &a{1}",
fallback.ToString(), block.Speed, block.CollideType);
player.Message(" &3Top ID: &a{0}&3, Side ID: &a{1}&3, Bottom ID: &a{2}",
block.TopTex, block.SideTex, block.BottomTex);
player.Message(" &3Block Light: &a{0}&3, Sound: &a{1}&3, FullBright: &a{2}",
block.BlocksLight.ToString(), block.WalkSound, block.FullBright.ToString());
player.Message(" &3Shape: &a{0}&3, Draw: &a{1}&3, Fog Density: &a{2}",
block.Shape, block.BlockDraw, block.FogDensity);
player.Message(" &3Fog Red: &a{0}&3, Fog Green: &a{1}&3, Fog Blue: &a{2}",
block.FogR, block.FogG, block.FogB);
player.Message(" &3Min X: &a{0}&3, Max X: &a{1}&3, Min Y: &a{2}&3, Max Y: &a{3}",
block.MinX, block.MaxX, block.MinY, block.MaxY);
break;
case "list":
GlobalBlockListHandler(player, cmd);
break;
case "remove":
case "delete":
GlobalBlockRemoveHandler(player, cmd);
break;
case "tex":
case "texture":
case "terrain":
player.Message("Terrain IDs: &9http://123dmwm.tk/ID-Overlay.png");
player.Message("Current world terrain: &9{0}", player.World.Texture == "Default" ? Server.DefaultTerrain : player.World.Texture);
break;
default:
if (player.currentGB != null) {
cmd.Rewind();
GlobalBlockDefineHandler(player, cmd.NextAll());
} else {
CdGlobalBlock.PrintUsage(player);
}
break;
}
}