org.spongepowered.api.command.source.ConsoleSource Java Examples

The following examples show how to use org.spongepowered.api.command.source.ConsoleSource. 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: CommandSentListener.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Listener
public void onCommandSent(SendCommandEvent event, @Root CommandSource src)
{
	if (src instanceof Player && Utils.isPlayerCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (src instanceof ConsoleSource && Utils.isConsoleCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (src instanceof CommandBlockSource && Utils.isCommandBlockCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
	else if (Utils.isOtherCommandLoggingEnabled())
	{
		EssentialCmds.getEssentialCmds().getLogger().info("[" + src.getName() + "]" + " executed command " + event.getCommand() + " " + event.getArguments());
	}
}
 
Example #2
Source File: UCChannel.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Send a message from a channel as console.
 *
 * @param sender  {@code ConsoleSource} - Console sender.
 * @param message {@code Text} - Message to send.
 * @param direct  {@code boolean} - Send message direct to players on channel.
 */
public void sendMessage(ConsoleSource sender, Text message, boolean direct) {
    if (direct) {
        for (Player p : Sponge.getServer().getOnlinePlayers()) {
            UCChannel chp = UChat.get().getPlayerChannel(p);
            if (UChat.get().getPerms().channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))) {
                UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message");
                p.sendMessage(message);
            }
        }
        sender.sendMessage(message);
    } else {
        UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire MessageChannelEvent");
        UCMessages.sendFancyMessage(new String[0], message, this, sender, null);
    }
}
 
Example #3
Source File: UCCommands.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
private void sendPreTell(CommandSource sender, CommandSource receiver, Text msg) {
    CommandSource src = sender;
    if (sender instanceof ConsoleSource) {
        src = receiver;
    }

    UChat.get().getLogger().timings(UCLogger.timingType.START, "UCListener#sendPreTell()|Fire AsyncPlayerChatEvent");

    MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(
            UChat.get().getVHelper().getCause(src),
            src.getMessageChannel(),
            Optional.of(src.getMessageChannel()),
            new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ")
                    .onShiftClick(TextActions.insertText(src.getName()))
                    .onClick(TextActions.suggestCommand("/msg " + src.getName()))
                    .build(), msg),
            msg,
            false);
    Sponge.getEventManager().post(event);
}
 
Example #4
Source File: WorldsBase.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		player.getWorld().getProperties().setSpawnPosition(player.getLocation().getBlockPosition());
		src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "World spawn set."));
	}
	else if (src instanceof ConsoleSource || src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /world setspawn!"));
	}

	return CommandResult.success();
}
 
Example #5
Source File: TPADenyExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Player sender = null;

		PendingInvitation cancel = null;

		for (PendingInvitation invitation : EssentialCmds.pendingInvites)
		{
			if (invitation.recipient == player)
			{
				sender = invitation.sender;
				cancel = invitation;
				break;
			}
		}

		if (cancel != null && sender != null)
		{
			sender.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Your TPA Request was Denied by " + player.getName() + "!"));
			EssentialCmds.pendingInvites.remove(cancel);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, "TPA Request Denied."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Pending TPA request not found!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!"));
	}
	return CommandResult.success();
}
 
Example #6
Source File: LangManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void sendCommandHelp(CommandSource sender, String cmd, boolean usage) {
    if (sender instanceof ConsoleSource) {
        CommandHandlers.HandleHelpPage(sender, 1);
        return;
    }
    if (usage) sendMessage(sender, "correct.usage");
    sender.sendMessage(RedProtect.get().getUtil().toText(get("cmdmanager.help." + cmd).replace("{cmd}", getCmd(cmd)).replace("{alias}", getCmdAlias(cmd))));
}
 
Example #7
Source File: SocialSpyExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (EssentialCmds.socialSpies.contains(player.getUniqueId()))
		{
			EssentialCmds.socialSpies.remove(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.RED, "Toggled social spy off!"));
		}
		else
		{
			EssentialCmds.socialSpies.add(player.getUniqueId());
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "Toggled social spy on!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /socialspy!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /socialspy!"));
	}
}
 
Example #8
Source File: MailReadExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	int number = ctx.<Integer> getOne("mail no").get();
	if (src instanceof Player)
	{
		Player player = (Player) src;
		List<Mail> mail = Utils.getMail(player);

		if (mail.isEmpty())
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have no new mail!"));
			return;
		}

		try
		{
			Mail m = mail.get(number);
			Utils.removeMail(m);
			player.sendMessage(Text.of(TextColors.GOLD, "[Mail]: Message from ", TextColors.WHITE, m.getSenderName() + ": ", TextColors.GRAY, m.getMessage()));
		}
		catch (Exception e)
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "That mail does not exist!"));
		}

	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /readmail!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /readmail!"));
	}
}
 
Example #9
Source File: HealExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<Player> p = ctx.<Player> getOne("player");

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.hasPermission("essentialcmds.heal.others") && p.isPresent())
		{
			Player recipient = p.get();
			recipient.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
			recipient.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've been healed by " + player.getName()));
			src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've healed " + recipient.getName()));
		}
		else if (p.isPresent())
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to heal other players!"));
		}
		else
		{
			player.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
			src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "You've been healed."));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /heal!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /heal!"));
	}

	return CommandResult.success();
}
 
Example #10
Source File: MoreExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			ItemStack stack = player.getItemInHand(HandTypes.MAIN_HAND).get();
			stack.setQuantity(64);
			player.setItemInHand(HandTypes.MAIN_HAND, stack);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Stacked the item in your hand!"));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You're not holding anything to stack!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /more!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /more!"));
	}
	return CommandResult.success();
}
 
Example #11
Source File: TPAHereExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Player recipient = ctx.<Player> getOne("player").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		if (recipient == player)
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport to yourself!"));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Requested for " + recipient.getName() + " to be teleported to you"));
			game.getEventManager().post(new TPAHereEvent(player, recipient));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpahere!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpahere!"));
	}
}
 
Example #12
Source File: RespondExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Optional<Message> om = EssentialCmds.recentlyMessaged.stream().filter(m -> m.getRecipient().getUniqueId().toString().equals(player.getUniqueId().toString())).findFirst();
		if (!om.isPresent())
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No recent messages found!"));
			return;
		}

		ctx.putArg("recipient", om.get().getSender());

		// Logic is the same as in the MessageExecutor now, so hand off to that.
		super.executeAsync(src, ctx);
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /r!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /r!"));
	}
}
 
Example #13
Source File: TPAExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Player recipient = ctx.<Player> getOne("player").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		
		if (recipient == player)
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport to yourself!"));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Requested to be teleported to " + recipient.getName() + "."));
			game.getEventManager().post(new TPAEvent(player, recipient));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpa!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpa!"));
	}
}
 
Example #14
Source File: TPHereExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player recipient = ctx.<Player> getOne("player").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		if (recipient == player)
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport to yourself!"));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, recipient.getName() + " has been teleported to your location!"));
			recipient.sendMessage(Text.of(TextColors.GREEN, player.getName(), TextColors.WHITE, " has teleported you to their location!"));
			recipient.setLocation(player.getLocation());
		}

	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tphere!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tphere!"));
	}
	
	return CommandResult.success();
}
 
Example #15
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 #16
Source File: SpongeCommandSender.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public boolean isConsole() {
    return handle instanceof ConsoleSource;
}
 
Example #17
Source File: UCPerms7.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
public boolean hasPerm(CommandSource p, String perm) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat." + perm) || p.hasPermission("uchat.admin");
}
 
Example #18
Source File: UCPerms7.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isAdmin(CommandSource p) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat.admin");
}
 
Example #19
Source File: PowertoolExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Optional<String> optionalCommand = ctx.<String> getOne("command");
		Player player = (Player) src;

		// TODO: Allow players not holding an item to remove their powertool
		if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			if (optionalCommand.isPresent())
			{
				String command = optionalCommand.get();

				// If there is a powertool for the player, remove it.
				EssentialCmds.powertools.stream()
					.filter(p -> p.getPlayer().equals(player) && p.getItemID().equals(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName()))
					.findFirst().ifPresent(x -> EssentialCmds.powertools.remove(x));
				Powertool powertool = new Powertool(player, player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName(), command);
				EssentialCmds.powertools.add(powertool);

				player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Successfully bound command ", TextColors.BLUE, command, TextColors.YELLOW, " to ", TextColors.RED, player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName(), TextColors.YELLOW, "!"));
			}
			else
			{
				Optional<Powertool> powertoolToRemove = EssentialCmds.powertools.stream()
					.filter(p -> p.getPlayer().equals(player) && p.getItemID().equals(player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getName()))
					.findFirst();

				if (powertoolToRemove.isPresent())
				{
					EssentialCmds.powertools.remove(powertoolToRemove.get());
					player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Removed command from this powertool!"));
				}
				else
				{
					player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "There is no command assigned to this!"));
				}
			}
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be holding something to use /powertool!"));
		}

	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /powertool!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /powertool!"));
	}
	return CommandResult.success();
}
 
Example #20
Source File: UCPerms8.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
public boolean hasPerm(CommandSource p, String perm) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat." + perm) || p.hasPermission("uchat.admin");
}
 
Example #21
Source File: UCPerms8.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isAdmin(CommandSource p) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat.admin");
}
 
Example #22
Source File: UCPerms56.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
public boolean hasPerm(CommandSource p, String perm) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat." + perm) || p.hasPermission("uchat.admin");
}
 
Example #23
Source File: UCPerms56.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isAdmin(CommandSource p) {
    return (p instanceof ConsoleSource) || p.hasPermission("uchat.admin");
}
 
Example #24
Source File: RTPExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	int tryTimes = 10;

	if (src instanceof Player)
	{
		Player player = (Player) src;
		//Why 3999? why hard code it?
		Optional<Location<World>> optionalLocation = randomLocation(player, 3999);
		if (optionalLocation.isPresent())
		{
			//Why check danger? shouldn't safe teleport have already checked this?
			if (isDangerous(optionalLocation))
			{
				//restrict the number of times we check, as every time we do this we are loading chunks...
				for(int i = 0; i < tryTimes; i++)
				{
					//Why 10000? are we supposed to be "less fussy" or something?
					// we only checked a width of 9 by default with safe teleport
					optionalLocation = randomLocation(player, 10000);
					//repeated isDanger check, when we have already checked it in safeTeleport
					if (optionalLocation.isPresent() && !isDangerous(optionalLocation))
					{
						teleportPlayer(player, optionalLocation);
						return CommandResult.success();
					}
				}
				player.sendMessage(Text.of(TextColors.DARK_RED, "A safe random location was not found, please try again"));
				return CommandResult.empty();
			} else {
				teleportPlayer(player, optionalLocation);
				return CommandResult.success();
			}
		}
		else
		{
			for(int i = 0; i < tryTimes; i++)
			{
				optionalLocation = randomLocation(player, 10000);
				//swapping to isWet? but the danger check is already done in safe teleport
				if (optionalLocation.isPresent() && !isWet(optionalLocation))
				{
					teleportPlayer(player, optionalLocation);
					return CommandResult.success();
				}
			}
			player.sendMessage(Text.of(TextColors.DARK_RED, "A safe random location was not found, please try again"));
			return CommandResult.empty();
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /rtp!"));
		return CommandResult.empty();
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /rtp!"));
		return CommandResult.empty();
	}

	return CommandResult.success();
}
 
Example #25
Source File: TPAAcceptExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Player sender = null;
		boolean tpaHere = false;
		PendingInvitation foundInvitation = null;

		for (PendingInvitation invitation : EssentialCmds.pendingInvites)
		{
			if (!invitation.isTPAHere && invitation.recipient == player)
			{
				sender = invitation.sender;
				foundInvitation = invitation;
				break;
			}
			else if (invitation.isTPAHere && invitation.recipient == player)
			{
				tpaHere = true;
				sender = invitation.sender;
				foundInvitation = invitation;
				break;
			}
		}

		if (sender != null && !tpaHere)
		{
			game.getEventManager().post(new TPAAcceptEvent(player, sender));
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, "TPA Request Accepted."));
		}
		else if (sender != null)
		{
			game.getEventManager().post(new TPAHereAcceptEvent(player, sender));
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, "TPA Here Request Accepted."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Pending TPA request not found!"));
		}

		if (foundInvitation != null)
			EssentialCmds.pendingInvites.remove(foundInvitation);
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpaccept!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpaccept!"));
	}
	return CommandResult.success();
}
 
Example #26
Source File: UCCommands.java    From UltimateChat with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
    return Sponge.getServer().getOnlinePlayers().stream().filter(
            play -> args.hasNext() && (src instanceof ConsoleSource || (src instanceof Player && ((Player) src).canSee(play))) && play.getName().toUpperCase().startsWith(args.getAll().get(args.getAll().size() - 1).toUpperCase()))
            .map(Player::getName).collect(Collectors.toList());
}
 
Example #27
Source File: ListWarpExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Set<Object> warps = Utils.getWarps();

		if (warps.size() == 0)
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!"));
			return;
		}

		if (warps.size() > 0)
		{
			PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
			List<Text> warpText = Lists.newArrayList();

			for (Object name : warps)
			{
				if (player.hasPermission("essentialcmds.warp.use." + String.valueOf(name)))
				{
					Text item = Text.builder(String.valueOf(name))
						.onClick(TextActions.runCommand("/warp " + String.valueOf(name)))
						.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Warp to ", TextColors.GOLD, String.valueOf(name))))
						.color(TextColors.DARK_AQUA)
						.style(TextStyles.UNDERLINE)
						.build();

					warpText.add(item);
				}
			}

			PaginationList.Builder paginationBuilder = paginationService.builder().contents(warpText).title(Text.of(TextColors.GREEN, "Showing Warps")).padding(Text.of("-"));
			paginationBuilder.sendTo(src);
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!"));
	}
}
 
Example #28
Source File: VirtualChestActions.java    From VirtualChest with GNU Lesser General Public License v3.0 4 votes vote down vote up
private CompletableFuture<CommandResult> processConsole(CommandResult parent, String command,
                                                        ClassToInstanceMap<Context> contextMap)
{
    ConsoleSource source = Sponge.getServer().getConsole();
    return CompletableFuture.completedFuture(Sponge.getCommandManager().process(source, command));
}
 
Example #29
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityConstruct(ConstructEntityEvent.Pre event, @Root Object source) {
    lastConstructEntityTick = Sponge.getServer().getRunningTimeTicks();
    if (true || source instanceof ConsoleSource || !GDFlags.ENTITY_SPAWN) {
        return;
    }

    final World world = event.getTransform().getExtent();
    final String entityTypeId = event.getTargetType().getId();
    if (entityTypeId.equals(EntityTypes.EXPERIENCE_ORB.getId())) {
        return;
    }

    final Location<World> location = event.getTransform().getLocation();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_SPAWN.getName(), source, world.getProperties())) {
        return;
    }
    if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_CHUNK_SPAWN.getName(), source, world.getProperties())) {
        return;
    }

    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ENTITY_SPAWN.getName(), entityTypeId, world.getProperties())) {
        return;
    }

    GDTimings.ENTITY_SPAWN_PRE_EVENT.startTimingIfSync();
    final User user = CauseContextHelper.getEventUser(event);
    final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location);
    if (targetClaim.isUserTrusted(user, TrustTypes.BUILDER)) {
        GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
        return;
    }

    Flag flag = Flags.ENTITY_SPAWN;
    if (event.getTargetType() == EntityTypes.ITEM) {
        if (user == null) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }
        if (!GDFlags.ITEM_SPAWN) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }
        if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_SPAWN.getName(), entityTypeId, world.getProperties())) {
            GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
            return;
        }

        flag = Flags.ITEM_SPAWN;
        if (source instanceof BlockSnapshot) {
            final BlockSnapshot block = (BlockSnapshot) source;
            final Location<World> blockLocation = block.getLocation().orElse(null);
            if (blockLocation != null) {
                if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_BREAK.getName(), block, world.getProperties())) {
                    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                    return;
                }
                final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_BREAK, source, block, user, true);
                if (result != Tristate.UNDEFINED) {
                    if (result == Tristate.TRUE) {
                        // Check if item drop is allowed
                        if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, flag, source, entityTypeId, user, true) == Tristate.FALSE) {
                            event.setCancelled(true);
                        }
                        GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                        return;
                    }
                    event.setCancelled(true);
                    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
                    return;
                }
            }
        }
    }
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, flag, source, entityTypeId, user, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }
    GDTimings.ENTITY_SPAWN_PRE_EVENT.stopTimingIfSync();
}
 
Example #30
Source File: UCChannel.java    From UltimateChat with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Send a message from a channel as console.<p>
 * <i>Use {@code sendMessage(ConsoleSource, message, direct)} as replecement for this method</i>
 *
 * @param sender  {@code ConsoleSource} - Console sender.
 * @param message {@code Text} - message to send.
 */
@Deprecated
public void sendMessage(ConsoleSource sender, String message) {
    sendMessage(sender, Text.of(message), UChat.get().getConfig().root().api.format_console_messages);
}