Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gamemode command #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.slampvp.factory.command.generic;

import com.slampvp.factory.command.Command;
import com.slampvp.factory.command.FactoryCommand;
import com.slampvp.factory.player.Rank;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;

@Command(description = "Change the gamemode of a player.",
usage = "/gamemode <gamemode> [player]",
minimumRank = Rank.DEFAULT,
playerOnly = false)
public class GamemodeCommand extends FactoryCommand {
public GamemodeCommand() {
super("gamemode", "gm");
}

@Override
public void init() {
var gamemodeArgument = ArgumentType.Word("gamemode").from("creative", "survival", "adventure", "spectator");
var playerArgument = ArgumentType.Entity("player").onlyPlayers(true);
Comment on lines +21 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No var 🙏🏿


addSyntax((sender, context) -> {
Player player = (Player) sender;
player.sendMessage("§7[§bFT§7] §8» §7Gamemode changed to §b" + context.get(gamemodeArgument));
player.setGameMode(GameMode.valueOf(context.get(gamemodeArgument).toUpperCase()));
}, gamemodeArgument);

addSyntax((sender, context) -> {
Player player = (Player) sender;
Player target = context.get(playerArgument).findFirstPlayer(sender);
assert target != null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No assert 🙏🏿


player.sendMessage("§7[§bFT§7] §8» §7Gamemode of §b" + target.getUsername() + "§7 changed to §b" + context.get(gamemodeArgument));
target.sendMessage("§7[§bFT§7] §8» §7Gamemode changed to §b" + context.get(gamemodeArgument));
target.setGameMode(GameMode.valueOf(context.get(gamemodeArgument).toUpperCase()));
}, gamemodeArgument, playerArgument);
}
}
Loading