This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
forked from J-Wass/LegendCraft
/
WorldCommands.cs
5458 lines (4932 loc) · 229 KB
/
WorldCommands.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2009-2012 Matvei Stefarov <me@matvei.org>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using fCraft.MapConversion;
using JetBrains.Annotations;
using fCraft.Drawing;
using fCraft.Portals;
using ServiceStack.Text;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.Media;
using fCraft.Events;
namespace fCraft
{
/// <summary> Contains commands related to world management. </summary>
static class WorldCommands
{
const int WorldNamesPerPage = 30;
internal static void Init()
{
CommandManager.RegisterCommand(CdBlockDB);
CommandManager.RegisterCommand(CdBlockInfo);
CommandManager.RegisterCommand(CdEnv);
CdGenerate.Help = "Generates a new map. If no dimensions are given, uses current world's dimensions. " +
"If no filename is given, loads generated world into current world.\n" +
"Available themes: Grass, " + Enum.GetNames(typeof(MapGenTheme)).JoinToString() + '\n' +
"Available terrain types: Empty, Ocean, " + Enum.GetNames(typeof(MapGenTemplate)).JoinToString() + '\n' +
"Note: You do not need to specify a theme with \"Empty\" and \"Ocean\" templates.";
CommandManager.RegisterCommand(CdGenerate);
CommandManager.RegisterCommand(CdJoin);
CommandManager.RegisterCommand(CdWorldLock);
CommandManager.RegisterCommand(CdWorldUnlock);
CommandManager.RegisterCommand(CdSpawn);
CommandManager.RegisterCommand(CdWorlds);
CommandManager.RegisterCommand(CdWorldAccess);
CommandManager.RegisterCommand(CdWorldBuild);
CommandManager.RegisterCommand(CdWorldFlush);
CommandManager.RegisterCommand(CdWorldHide);
CommandManager.RegisterCommand(CdWorldUnhide);
CommandManager.RegisterCommand(CdWorldInfo);
CommandManager.RegisterCommand(CdWorldLoad);
CommandManager.RegisterCommand(CdWorldMain);
CommandManager.RegisterCommand(CdWorldRename);
CommandManager.RegisterCommand(CdWorldSave);
CommandManager.RegisterCommand(CdWorldUnload);
CommandManager.RegisterCommand(CdRealm);
CommandManager.RegisterCommand(CdGuestwipe);
CommandManager.RegisterCommand(CdRankHide);
CommandManager.RegisterCommand(CdPortal);
CommandManager.RegisterCommand(CdWorldSearch);
//SchedulerTask TimeCheckR = Scheduler.NewTask(TimeCheck).RunForever(TimeSpan.FromSeconds(120));
CommandManager.RegisterCommand(CdPhysics);
CommandManager.RegisterCommand(CdRejoin);
//CommandManager.RegisterCommand(CdWorldChat);
CommandManager.RegisterCommand(CdBack);
CommandManager.RegisterCommand(CdJump);
CommandManager.RegisterCommand(CdMapEdit);
CommandManager.RegisterCommand(CdHax);
CommandManager.RegisterCommand(CdMessageBlock);
}
#region LegendCraft
/* Copyright (c) <2012-2014> <LeChosenOne, DingusBungus>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
static readonly CommandDescriptor CdMessageBlock = new CommandDescriptor
{
Name = "MessageBlock",
Aliases = new[] { "messageblocks", "mb" },
Category = CommandCategory.World,
IsConsoleSafe = false,
Permissions = new[] { Permission.ManageWorlds },
Usage = "/MessageBlock [List / Remove (name) / Create (name) (message) / Edit (name) (message)]",
Help = "Manages the MessageBlocks on the current world.",
Handler = MessageBlockH
};
private static void MessageBlockH(Player player, Command cmd)
{
string option = cmd.Next();
if (String.IsNullOrEmpty(option))
{
CdMessageBlock.PrintUsage(player);
return;
}
switch (option.ToLower())
{
case "list":
player.Message("__MessageBlocks on {0}__", player.World.Name);
foreach (KeyValuePair<string, Tuple<Vector3I, string>> messageBlock in player.World.MessageBlocks)
{
//block name and location
player.Message(messageBlock.Key + " " + messageBlock.Value.Item1.ToString());
}
break;
case "remove":
string removeTarget = cmd.Next();
if (String.IsNullOrEmpty(removeTarget))
{
player.Message("&ePlease identify which MessageBlock you want to remove.");
return;
}
if (!player.World.MessageBlocks.Keys.Contains(removeTarget))
{
player.Message("&c'{0}' was not found! Use '/MessageBlock List' to view all MessageBlocks on your world.", removeTarget);
return;
}
player.Message("&a{0} was removed from {1}.", removeTarget, player.World.Name);
player.World.MessageBlocks.Remove(removeTarget);
break;
case "create":
string addTarget = cmd.Next();
if (String.IsNullOrEmpty(addTarget))
{
player.Message("&ePlease identify the name of the MessageBlock you want to create.");
return;
}
if (player.World.MessageBlocks.Keys.Contains(addTarget))
{
player.Message("&c{0} is already the name of a current MessageBlock on this world! Use '/MessageBlock List' to view all MessageBlocks on your world.", addTarget);
return;
}
string message = cmd.NextAll();
if (String.IsNullOrEmpty(message))
{
player.Message("&ePlease choose the message for your MessageBlock!");
return;
}
Vector3I pos = new Vector3I(player.Position.ToBlockCoords().X, player.Position.ToBlockCoords().Y, player.Position.ToBlockCoords().Z);
//tell the user that the message block is created on the block they are standing on, but the message block is actually on their head
player.Message("&a{0} was added.", addTarget);
player.World.MessageBlocks.Add(addTarget, new Tuple<Vector3I, string>(pos, message));
break;
case "edit":
string editTarget = cmd.Next();
if (String.IsNullOrEmpty(editTarget))
{
player.Message("&ePlease identify which MessageBlock you want to edit.");
return;
}
if (!player.World.MessageBlocks.Keys.Contains(editTarget))
{
player.Message("&c'{0}' was not found! Use '/MessageBlock List' to view all MessageBlocks on your world.", editTarget);
return;
}
string editMessage = cmd.NextAll();
if (String.IsNullOrEmpty(editMessage))
{
player.Message("&ePlease choose the message for your MessageBlock!");
return;
}
//get the block coord of the message block being edited by finding the tuple of the key
Tuple<Vector3I, string> tuple;
player.World.MessageBlocks.TryGetValue(editMessage, out tuple);
//player.Message("&aMessageBlock was successfully edited.");
player.World.MessageBlocks.Remove(editTarget);
player.World.MessageBlocks.Add(editTarget, new Tuple<Vector3I, string>(tuple.Item1, editMessage));
break;
default:
break;
}
}
static readonly CommandDescriptor CdHax = new CommandDescriptor
{
Name = "Hax",
Aliases = new[] { "htoggle", "haxtoggle", "hacks", "hackstoggle" },
Category = CommandCategory.World,
IsConsoleSafe = false,
Permissions = new[] { Permission.ManageWorlds },
Usage = "/Hax (World) (On/Off)",
Help = "Sets if you want to enable or disable hax on a specific world.",
Handler = HaxHandler
};
private static void HaxHandler(Player player, Command cmd)
{
string worldName = cmd.Next();
if (string.IsNullOrEmpty(worldName) || worldName.Length < 1)
{
CdHax.PrintUsage(player);
return;
}
World world = WorldManager.FindWorldOrPrintMatches(player, worldName);
if (world == null)
{
player.MessageNoWorld(worldName);
return;
}
string hax = cmd.Next();
if (string.IsNullOrEmpty(hax) || hax.Length < 1)
{
CdHax.PrintUsage(player);
return;
}
if (hax.ToLower() == "on" || hax.ToLower() == "true")
{
if (world.Hax == true)
{
player.Message("&sHax are already enabled on {0}", world.ClassyName);
return;
}
world.Hax = true;
Server.Message("&sHax have been enabled on {0}", world.ClassyName);
foreach (Player p in world.Players)
{
p.JoinWorld(player.World, WorldChangeReason.Rejoin);
}
return;
}
if (hax.ToLower() == "off" || hax.ToLower() == "false")
{
if (world.Hax == false)
{
player.Message("&sHax are already disabled on {0}", world.ClassyName);
return;
}
world.Hax = false;
Server.Message("&sHax have been disabled on {0}", world.ClassyName);
foreach (Player p in world.Players) //make all players rejoin to force changes
{
p.JoinWorld(player.World, WorldChangeReason.Rejoin);
}
return;
}
}
static readonly CommandDescriptor CdMapEdit = new CommandDescriptor
{
Name = "MapEdit",
Aliases = new[] { "WorldEdit", "MEdit", "WEdit", "MapSet" },
Category = CommandCategory.World,
Permissions = new[] { Permission.ManageWorlds },
Help = "&SPrints or changes the environmental variables for a given world. " +
"Variables are: clouds, fog, sky, and weather. " +//add level, edge, side, and texture once supported
"See &H/Help MapEdit <Variable>&S for details about each variable. " +
"Type &H/MapEdit <WorldName> normal&S to reset everything for a world. " +
"All Color formats should be in hexcode. \n Ex: #ffffff",
HelpSections = new Dictionary<string, string>{
{ "normal", "&H/MapEdit <WorldName> normal\n&S" +
"Resets all environment settings to their defaults for the given world." },
{ "clouds", "&H/MapEdit <WorldName> clouds <Color>\n&S" +
"Sets color of the clouds. Use \"normal\" instead of color to reset." },
{ "fog", "&H/MapEdit <WorldName> fog <Color>\n&S" +
"Sets color of the fog. Sky color blends with fog color in the distance. " +
"Use \"normal\" instead of color to reset." },
{ "sky", "&H/MapEdit <WorldName> sky <Color>\n&S" +
"Sets color of the sky. Sky color blends with fog color in the distance. " +
"Use \"normal\" instead of color to reset." },
/*{ "level", "&H/MapEdit <WorldName> level <#>\n&S" +
"Sets height of the map edges/water level, in terms of blocks from the bottom of the map. " +
"Use \"normal\" instead of a number to reset to default (middle of the map)." },
{ "edge", "&H/MapEdit <WorldName> edge <BlockType>\n&S" +
"Changes the type of block that's visible beyond the map boundaries. "+
"Use \"normal\" instead of a number to reset to default (water)." },
{ "side", "&H/MapEdit <WorldName> side <BlockType>\n&S" +
"Changes the type of block that is visible on the boundary of the map. "+
"Use \"normal\" instead of a number to reset to default (admincrete)." },
{ "texture", "&H/MapEdit <WorldName> texture url\n&S" +
"Retextures the blocks of the map to a specific texture pack. "+
"Use \"normal\" instead of a url to reset to default." },*/
{ "weather", "&H/MapEdit <WorldName> weather <Normal/Rain/Snow>\n&S" +
"Sets the default weather of the map. " +
"Use \"normal\" instead of a number to reset to default (Clear)" },
},
Usage = "/MapEdit <WorldName> <Variable> <Setting>",
IsConsoleSafe = true,
Handler = MEditHandler
};
static void MEditHandler(Player player, Command cmd)
{
if (!Heartbeat.ClassiCube())
{
player.Message("/MapEdit only works for ClassiCube, not MineCraft! If you are playing on Minecraft.net, please use /Env.");
return;
}
if (!ConfigKey.WoMEnableEnvExtensions.Enabled())
{
player.Message("This command has been disabled for the server!");
return;
}
string worldName = cmd.Next();
World world;
if (string.IsNullOrEmpty(worldName))
{
player.Message("Please specify a world.");
return;
}
try
{
world = WorldManager.FindWorldExact(worldName);
}
catch
{
player.Message("Cannot find world {0}. Please make sure to type in the exact world name.", worldName);
return;
}
string option = cmd.Next();
if (string.IsNullOrEmpty(option))
{
player.Message("Please specify an option for mapedit. To reset the mapedit settings for this world, type /mapedit [world] normal.");
return;
}
string setting = cmd.Next();
switch (option)
{
case "normal":
//reset all defaults
world.sideBlock = 7;
world.edgeBlock = 8;
world.WeatherCC = 0;
world.sideLevel = (short)(world.Map.Height / 2);
world.SkyColorCC = "#99ccff";
world.CloudColorCC = "#ffffff";
world.FogColorCC = "#ffffff";
Packet fog = PacketWriter.MakeEnvSetColor((byte)2, (world.FogColorCC));
Packet cloud = PacketWriter.MakeEnvSetColor((byte)1, (world.CloudColorCC));
Packet sky = PacketWriter.MakeEnvSetColor((byte)0, (world.SkyColorCC));
//Packet appearence = PacketWriter.MakeEnvSetMapAppearance("", world.sideBlock, world.edgeBlock, world.sideLevel); update once supported
Packet weather = PacketWriter.MakeEnvWeatherAppearance((byte)world.WeatherCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(sky);
p.Send(cloud);
p.Send(fog);
//p.Send(appearence);
p.Send(weather);
}
break;
/*case "texture":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify the url of the texture pack.");
break;
}
if (setting == "normal")
{
player.Message("Reset texture pack to default minecraft.");
world.textureURL = "";
Packet textNormal = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(textNormal);
}
player.Message("Map settings have been updated.");
return;
}
try
{
world.textureURL = setting;
Packet texture = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(texture);
}
player.Message("Map settings have been updated.");
}
catch
{
player.Message("Please use a valid HTTP URL! Make sure the url starts with 'http' and ends in a '.png'.");
}
break;
case "edge":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for your variable.");
break;
}
if (setting == "normal")
{
player.Message("Reset edge block to water.");
world.edgeBlock = 8;
Packet edgeNormal = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(edgeNormal);
}
player.Message("Map settings have been updated.");
return;
}
//if the setting param is actually a block
try
{
Block eBlock = (Block)Enum.Parse(typeof(Block), setting.Substring(0, 1).ToUpper() + setting.Substring(1));//modifies the input to be "Stone" and not stone, STONE, etc
world.edgeBlock = (byte)eBlock;
Packet edge = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(edge);
}
player.Message("Map settings have been updated.");
}
catch
{
player.Message("Please choose a valid block for the edge!");
}
break;
case "side":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}", option);
break;
}
if (setting == "normal")
{
player.Message("Reset side block to admincrete.");
world.sideBlock = 7;
Packet sideNormal = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(sideNormal);
}
player.Message("Map settings have been updated.");
return;
}
//if the setting param is actually a block
try
{
Block sBlock = (Block)Enum.Parse(typeof(Block), setting.Substring(0, 1).ToUpper() + setting.Substring(1));
world.sideBlock = (byte)sBlock;
Packet side = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(side);
}
player.Message("Map settings have been updated.");
}
catch
{
player.Message("Please choose a valid block for the side of the map!");
}
break;
case "level":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}", option);
break;
}
if (setting == "normal")
{
player.Message("Reset map level to half of the map's height.");
world.sideLevel = (short)(world.Map.Height / 2);
Packet levelNormal = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(levelNormal);
}
player.Message("Map settings have been updated.");
return;
}
int level;
if (!int.TryParse(setting, out level))
{
player.Message("Please choose a number between 0 and {0}.", world.Map.Height.ToString());
break;
}
if (level < world.Map.Height && level > 0)
{
world.sideLevel = (short)level;
Packet levelP = PacketWriter.MakeEnvSetMapAppearance(world.textureURL, world.sideBlock, world.edgeBlock, world.sideLevel);
foreach (Player p in world.Players.Where(p => p.ClassiCube))
{
p.Send(levelP);
}
player.Message("Map settings have been updated.");
break;
}
else
{
player.Message("Please choose a number between 0 and {0}.", world.Map.Height.ToString());
}
break;*/
case "clouds":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}", option);
break;
}
if (setting == "normal")
{
player.Message("Reset cloud color.");
world.CloudColorCC = "#ffffff";
Packet cloudPacketNormal = PacketWriter.MakeEnvSetColor((byte)1, (world.CloudColorCC));
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(cloudPacketNormal);
}
return;
}
try //roughly created try parse, lol
{
System.Drawing.Color cloudColor = (System.Drawing.Color)System.Drawing.ColorTranslator.FromHtml(setting);
}
catch
{
player.Message("Please use a valid hexcode color. Example: #ffffff for white.");
return;
}
world.CloudColorCC = setting;
player.Message("The map texture has been edited.");
Packet cloudPacket = PacketWriter.MakeEnvSetColor((byte)1, world.CloudColorCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(cloudPacket);
}
break;
case "fog":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}", option);
break;
}
if (setting == "normal")
{
player.Message("Reset fog color.");
world.FogColorCC = "#ffffff";
Packet fogPacketNormal = PacketWriter.MakeEnvSetColor((byte)2, world.FogColorCC.Replace("#", ""));
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(fogPacketNormal);
}
return;
}
try //try parse again
{
System.Drawing.Color fogColor = (System.Drawing.Color)System.Drawing.ColorTranslator.FromHtml(setting);
}
catch
{
player.Message("Please use a valid hexcode color. Example: #ffffff for white.");
return;
}
world.FogColorCC = setting;
player.Message("The map texture has been edited.");
Packet fogPacket = PacketWriter.MakeEnvSetColor((byte)2, world.FogColorCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(fogPacket);
}
break;
case "sky":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}", option);
break;
}
if (setting == "normal")
{
player.Message("Reset sky color.");
world.SkyColorCC = "#99CCFF";
Packet skyPacketNormal = PacketWriter.MakeEnvSetColor((byte)0, world.SkyColorCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(skyPacketNormal);
}
return;
}
try //last time, tryparse thingy
{
System.Drawing.Color skyColor = (System.Drawing.Color)System.Drawing.ColorTranslator.FromHtml(setting);
}
catch
{
player.Message("Please use a valid hexcode color. Example: #ffffff for white.");
return;
}
world.SkyColorCC = setting;
player.Message("The map texture has been edited.");
Packet skyPacket = PacketWriter.MakeEnvSetColor((byte)0, world.SkyColorCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(skyPacket);
}
break;
case "weather":
if (string.IsNullOrEmpty(setting))
{
player.Message("Please specify a setting for {0}. Choose either normal, rain or snow.", option);
break;
}
switch (setting.ToLower())
{
case "normal":
case "clear":
case "sunny":
case "0":
player.Message("Weather set to {0}", setting);
world.WeatherCC = 0;
Packet weatherPacketNormal = PacketWriter.MakeEnvWeatherAppearance((byte)world.WeatherCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(weatherPacketNormal);
}
break;
case "rain":
case "rainy":
case "1":
player.Message("Weather set to {0}", setting);
world.WeatherCC = 1;
Packet weatherPacketRain = PacketWriter.MakeEnvWeatherAppearance((byte)world.WeatherCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(weatherPacketRain);
}
break;
case "snow":
case "snowy":
case "snowing":
case "2":
player.Message("Weather set to {0}", setting);
world.WeatherCC = 2;
Packet weatherPacketSnow = PacketWriter.MakeEnvWeatherAppearance((byte)world.WeatherCC);
foreach (Player p in world.Players.Where(p => p.CPE))
{
p.Send(weatherPacketSnow);
}
break;
default:
player.Message("Please specify a setting for {0}. Choose either normal, rain or snow.", option);
break;
}
break;
default:
CdMapEdit.PrintUsage(player);
break;
}
}
static readonly CommandDescriptor CdJump = new CommandDescriptor
{
Name = "Jump",
Category = CommandCategory.World,
Permissions = new Permission[] { Permission.Teleport },
IsConsoleSafe = false,
Usage = "/Jump [blocks]",
Help = "Moves the player up a certain amount of blocks.",
Handler = JumpHandler,
};
static void JumpHandler(Player player, Command cmd)
{
String blocks = cmd.Next();
short count = 0;
if (String.IsNullOrWhiteSpace(blocks))
{
CdJump.PrintUsage(player);
return;
}
if (blocks.Contains("-"))
{
player.Message("Jumping a negative distance is really hard!");
return;
}
if (short.TryParse(blocks, out count))
{
Position target = new Position(player.Position.X, player.Position.Y, player.Position.Z + (count * 32));
player.TeleportTo(target);
player.Message("You have jumped {0} blocks.", count.ToString());
return;
}
player.Message("Please use a whole number.");
return;
}
static readonly CommandDescriptor CdBack = new CommandDescriptor
{
Name = "Back",
Category = CommandCategory.World,
Permissions = new Permission[] { Permission.Teleport },
IsConsoleSafe = false,
Usage = "/back",
Help = "Sends you back to your last location after a teleport.",
Handler = BackHandler,
};
static void BackHandler(Player player, Command cmd)
{
if (player.previousLocation == null)
{
player.Message("&cYou haven't been teleported somewhere yet!");
return;
}
else
{
player.Message("&aTeleporting you back to your previous location...");
if (player.previousWorld == null)
{
player.TeleportTo(player.previousLocation);
}
else
{
player.JoinWorld(player.previousWorld, WorldChangeReason.ManualJoin);
player.TeleportTo(player.previousLocation);
}
return;
}
}
static readonly CommandDescriptor CdWorldChat = new CommandDescriptor
{
Name = "WorldChat",
Category = CommandCategory.World | CommandCategory.Chat,
Permissions = new Permission[] { Permission.ManageWorldChat },
IsConsoleSafe = false,
Usage = "/WorldChat [toggle:check]",
Help = "Toggles World Chat.",
Handler = WorldChat,
};
static void WorldChat(Player player, Command cmd)
{
string option = cmd.Next();
if (option == "toggle")
{
if (player.World.WorldOnlyChat == false)
{
Server.Message("{0}&c has activated world chat on {1}", player.ClassyName, player.World);
player.World.WorldOnlyChat = true;
}
else
{
Server.Message("{0}&c has deactivated world chat on {1}", player.ClassyName, player.World);
player.World.WorldOnlyChat = false;
}
}
else if (option == "check")
{
if (player.World.WorldOnlyChat == true)
{
player.Message("World Chat is enabled on {0}", player.World);
return;
}
else
{
player.Message("World Chat is disabled on {0}", player.World);
return;
}
}
else
{
player.Message("Valid options are toggle and check.");
return;
}
}
static readonly CommandDescriptor CdRejoin = new CommandDescriptor
{
Name = "Rejoin",
Category = CommandCategory.World,
IsConsoleSafe = false,
Permissions = new[] { Permission.Chat },
Usage = "/rejoin",
Help = "Rejoins the current world you are in.",
Handler = RejoinHandler
};
static void RejoinHandler(Player player, Command cmd)
{
player.JoinWorld(player.World, WorldChangeReason.Rejoin);
}
#endregion
#region 800Craft
//Copyright (C) <2012> <Jon Baker, Glenn Mariën and Lao Tszy>
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program. If not, see <http://www.gnu.org/licenses/>.
#region Physics
static readonly CommandDescriptor CdPhysics = new CommandDescriptor
{
Name = "Physics",
Category = CommandCategory.World,
Permissions = new Permission[] { Permission.Physics },
IsConsoleSafe = false,
Usage = "/Physics <TNT | Fireworks | Water | Plant | Sand | Gun | All> <On / Off>",
Help = "Enables / disables a type of Physics for the current world. Physics may use more server resources.",
HelpSections = new Dictionary<string, string>() {
{ "tnt", "&H/Physics tnt on/off \n&S" +
"Turns TNT exploding physics on / off in the current world"},
{ "fireworks", "&H/Physics fireworks on/off \n&S" +
"Turns firework physics on / off in the current world"},
{ "water", "&H/Physics water on/off \n&S" +
"Turns water physics on / off in the current world"},
{ "plant", "&H/Physics plant on/off \n&S" +
"Turns plant physics on / off in the current world"},
{ "sand", "&H/Physics sand on/off \n&S" +
"Turns sand and gravel physics on / off in the current world"},
{ "gun", "&H/Physics gun on/off \n&S" +
"Turns gun physics on / off in the current world"},
{ "all", "&H/Physics all on/off \n&S" +
"Turns all physics on / off in the current world"},
},
Handler = PhysicsHandler
};
private static void PhysicsHandler(Player player, Command cmd)
{
string option = cmd.Next();
World world = player.World;
if (option == null)
{
CdPhysics.PrintUsage(player);
return;
}
string NextOp = cmd.Next();
if (NextOp == null)
{
CdPhysics.PrintUsage(player);
return;
}
switch (option.ToLower())
{
case "tnt":
if (NextOp.ToLower() == "on")
{
world.EnableTNTPhysics(player, true);
return;
}
if (NextOp.ToLower() == "off")
{
world.DisableTNTPhysics(player, true);
return;
}
break;
case "gun":
if (NextOp.ToLower() == "on")
{
world.EnableGunPhysics(player, true);
return;
}
if (NextOp.ToLower() == "off")
{
world.DisableGunPhysics(player, true);
return;
}
break;
case "plant":
if (NextOp.ToLower() == "off")
{
world.DisablePlantPhysics(player, true);
return;
}
if (NextOp.ToLower() == "on")
{
world.EnablePlantPhysics(player, true);
return;
}
break;
case "fireworks":
case "firework":
if (NextOp.ToLower() == "on")
{
world.EnableFireworkPhysics(player, true);
return;
}
if (NextOp.ToLower() == "off")
{
world.DisableFireworkPhysics(player, true);
return;
}
break;
case "sand":
if (NextOp.ToLower() == "on")
{
world.EnableSandPhysics(player, true);
return;
}
if (NextOp.ToLower() == "off")
{
world.DisableSandPhysics(player, true);
return;
}
break;
case "water":
if (NextOp.ToLower() == "on")
{
world.EnableWaterPhysics(player, true);
return;
}
if (NextOp.ToLower() == "off")
{
world.DisableWaterPhysics(player, true);
return;
}
break;
case "all":
if (NextOp.ToLower() == "on")
{
if (!world.tntPhysics)
{
world.EnableTNTPhysics(player, false);
} if (!world.sandPhysics)
{
world.EnableSandPhysics(player, false);
} if (!world.fireworkPhysics)
{
world.EnableFireworkPhysics(player, false);
} if (!world.waterPhysics)