org.spongepowered.api.command.CommandManager Java Examples

The following examples show how to use org.spongepowered.api.command.CommandManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeSkinSponge.java    From ChangeSkin with MIT License 6 votes vote down vote up
@Listener
public void onInit(GameInitializationEvent initEvent) {
    if (!initialized)
        return;

    CommandManager cmdManager = Sponge.getCommandManager();

    //command and event register
    cmdManager.register(this, injector.getInstance(SelectCommand.class).buildSpec(), "skin-select", "skinselect");
    cmdManager.register(this, injector.getInstance(InfoCommand.class).buildSpec(), "skin-info");
    cmdManager.register(this, injector.getInstance(UploadCommand.class).buildSpec(), "skin-upload");
    cmdManager.register(this, injector.getInstance(SetCommand.class).buildSpec(), "changeskin", "setskin", "skin");
    cmdManager.register(this, injector.getInstance(InvalidateCommand.class)
            .buildSpec(), "skininvalidate", "skin-invalidate");

    Sponge.getEventManager().registerListeners(this, injector.getInstance(LoginListener.class));

    //incoming channel
    ChannelRegistrar channelReg = Sponge.getChannelRegistrar();
    String updateChannelName = new NamespaceKey(ARTIFACT_ID, UPDATE_SKIN_CHANNEL).getCombinedName();
    String permissionChannelName = new NamespaceKey(ARTIFACT_ID, CHECK_PERM_CHANNEL).getCombinedName();
    RawDataChannel updateChannel = channelReg.getOrCreateRaw(this, updateChannelName);
    RawDataChannel permChannel = channelReg.getOrCreateRaw(this, permissionChannelName);
    updateChannel.addListener(Type.SERVER, injector.getInstance(UpdateSkinListener.class));
    permChannel.addListener(Type.SERVER, injector.getInstance(CheckPermissionListener.class));
}
 
Example #2
Source File: SudoExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player p = ctx.<Player> getOne("player").get();
	String command = ctx.<String> getOne("command").get();
	if (src instanceof Player)
	{
		Player player = (Player) src;
		CommandManager cmdService = game.getCommandManager();
		if (!(p.hasPermission("sudo.exempt")))
		{
			cmdService.process(p, command);
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "Forcing " + p.getName() + " to run /" + command));
			p.sendMessage(Text.of(TextColors.GOLD, "[Sudo]: ", TextColors.WHITE, player.getName() + " has forced you to run /" + command));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "This player is exempt from sudo!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /sudo!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /sudo!"));
	}
	return CommandResult.success();
}
 
Example #3
Source File: FlexibleLogin.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Inject
FlexibleLogin(Logger logger, Injector injector, Settings settings, CommandManager commandManager) {
    this.logger = logger;
    this.config = settings;

    this.injector = injector;
    this.commandManager = commandManager;
}
 
Example #4
Source File: UnknowncommandListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onCommand(SendCommandEvent event) {
    CommandSource p = event.getCause().first(CommandSource.class).orElse(null);
    if (p == null) return;
    CommandManager cm = Sponge.getCommandManager();
    if (cm.get(event.getCommand()).isPresent()) return;

    //Send message
    event.setCancelled(true);
    Messages.send(p, "unknowncommand.message");
}
 
Example #5
Source File: UCCommandService.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void registerLateCommands() {
    CommandManager cm = Sponge.getCommandManager();
    getUnregisteredCommands().forEach((cmd, run) -> {
        for (String alias : cmd.getAliases()) {
            cm.get(alias).ifPresent(cm::removeMapping);
        }
        register(cmd);
        run.run();
    });
    this.commandsLater.clear();
}
 
Example #6
Source File: WebAPI.java    From Web-API with MIT License 4 votes vote down vote up
public static CommandResult executeCommand(String command, CommandSource source) {
    CommandManager cmdManager = Sponge.getGame().getCommandManager();
    return cmdManager.process(source, command);
}
 
Example #7
Source File: PlayerInteractListener.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Listener
public void onPlayerInteractBlock(InteractBlockEvent event, @Root Player player)
{
	if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while frozen."));
		event.setCancelled(true);
		return;
	}

	if (EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while jailed."));
		event.setCancelled(true);
		return;
	}

	Optional<Location<World>> optLocation = event.getTargetBlock().getLocation();

	if (optLocation.isPresent() && optLocation.get().getTileEntity().isPresent())
	{
		Location<World> location = optLocation.get();
		TileEntity clickedEntity = location.getTileEntity().get();

		if (event.getTargetBlock().getState().getType().equals(BlockTypes.STANDING_SIGN) || event.getTargetBlock().getState().getType().equals(BlockTypes.WALL_SIGN))
		{
			Optional<SignData> signData = clickedEntity.getOrCreate(SignData.class);

			if (signData.isPresent())
			{
				SignData data = signData.get();
				CommandManager cmdService = Sponge.getGame().getCommandManager();
				String line0 = data.getValue(Keys.SIGN_LINES).get().get(0).toPlain();
				String line1 = data.getValue(Keys.SIGN_LINES).get().get(1).toPlain();
				String command = "warp " + line1;

				if (line0.equals("[Warp]"))
				{
					if (player.hasPermission("essentialcmds.warps.use.sign"))
					{
						cmdService.process(player, command);
					}
					else
					{
						player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to use Warp Signs!"));
					}
				}
			}
		}
	}
}
 
Example #8
Source File: PreventListener.java    From FlexibleLogin with MIT License 4 votes vote down vote up
@Inject PreventListener(FlexibleLogin plugin, Settings settings, CommandManager commandManager) {
    super(plugin, settings);

    this.commandManager = commandManager;
}