-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a38b896
commit e2d5d1b
Showing
10 changed files
with
173 additions
and
15 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/MineCase.Server.Commands/MineCase.Server.Commands.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MineCase.Server.Grains\MineCase.Server.Grains.csproj" /> | ||
<ProjectReference Include="..\MineCase.Server.Interfaces\MineCase.Server.Interfaces.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
105 changes: 105 additions & 0 deletions
105
src/MineCase.Server.Commands/Vanilla/GameModeCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MineCase.Server.Game; | ||
using MineCase.Server.Game.Entities; | ||
using MineCase.Server.Game.Commands; | ||
|
||
namespace MineCase.Server.Commands.Vanilla | ||
{ | ||
public class GameModeCommand | ||
: SimpleCommand | ||
{ | ||
public GameModeCommand() | ||
: base("gamemode", "Changes the player to a specific game mode") | ||
{ | ||
} | ||
|
||
public override async Task<bool> Execute(ICommandSender commandSender, IReadOnlyList<ICommandArgument> args) | ||
{ | ||
var player = (IPlayer)commandSender; | ||
|
||
if (args.Count < 1) | ||
{ | ||
throw new CommandWrongUsageException(this, "Invalid arguments"); | ||
} | ||
|
||
GameMode.Class gameModeClass; | ||
|
||
switch (((UnresolvedArgument)args[0]).RawContent) | ||
{ | ||
case "survival": | ||
case "s": | ||
case "0": | ||
gameModeClass = GameMode.Class.Survival; | ||
break; | ||
case "creative": | ||
case "c": | ||
case "1": | ||
gameModeClass = GameMode.Class.Creative; | ||
break; | ||
case "adventure": | ||
case "ad": | ||
case "2": | ||
gameModeClass = GameMode.Class.Adventure; | ||
break; | ||
case "spectator": | ||
case "sp": | ||
case "3": | ||
gameModeClass = GameMode.Class.Spectator; | ||
break; | ||
default: | ||
throw new CommandWrongUsageException(this); | ||
} | ||
|
||
var target = player; | ||
|
||
if (args.Count == 2) | ||
{ | ||
var rawArg = (UnresolvedArgument)args[1]; | ||
|
||
if (rawArg is TargetSelectorArgument targetSelector) | ||
{ | ||
switch (targetSelector.Type) | ||
{ | ||
case TargetSelectorType.NearestPlayer: | ||
break; | ||
case TargetSelectorType.RandomPlayer: | ||
break; | ||
case TargetSelectorType.AllPlayers: | ||
break; | ||
case TargetSelectorType.AllEntites: | ||
break; | ||
case TargetSelectorType.Executor: | ||
break; | ||
default: | ||
throw new CommandException(this); | ||
} | ||
|
||
throw new CommandException(this, "Sorry, this feature has not been implemented."); | ||
} | ||
else | ||
{ | ||
var user = await player.GetUser(); | ||
var session = await user.GetGameSession(); | ||
|
||
target = await (await session.FindUserByName(rawArg.RawContent)).GetPlayer(); | ||
|
||
if (target == null) | ||
{ | ||
throw new CommandException(this, $"Player \"{rawArg.RawContent}\" not found, may be offline or not existing."); | ||
} | ||
} | ||
} | ||
|
||
var targetDesc = await target.GetDescription(); | ||
var mode = targetDesc.GameMode; | ||
mode.ModeClass = gameModeClass; | ||
targetDesc.GameMode = mode; | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters