org.bukkit.command.BlockCommandSender Java Examples

The following examples show how to use org.bukkit.command.BlockCommandSender. 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: CustomCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
private int executeNormalExecutor(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	if(sender instanceof Player && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PLAYER)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PLAYER).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof Entity && ex.stream().anyMatch(o -> o.getType() == ExecutorType.ENTITY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.ENTITY).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ConsoleCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.CONSOLE)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.CONSOLE).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof BlockCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.BLOCK)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.BLOCK).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ProxiedCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PROXY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PROXY).findFirst().get().executeWith(sender, args);
	} else if(ex.stream().anyMatch(o -> o.getType() == ExecutorType.ALL)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.ALL).findFirst().get().executeWith(sender, args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("This command has no implementations for " + sender.getClass().getSimpleName().toLowerCase())
			).create()
		); 
	}
}
 
Example #2
Source File: CustomCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
private int executeResultingExecutor(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	if(sender instanceof Player && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.PLAYER)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.PLAYER).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof Entity && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ENTITY)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ENTITY).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ConsoleCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.CONSOLE)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.CONSOLE).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof BlockCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.BLOCK)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.BLOCK).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ProxiedCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PROXY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PROXY).findFirst().get().executeWith(sender, args);
	} else if(rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ALL)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ALL).findFirst().get().executeWith(sender, args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("This command has no implementations for " + sender.getClass().getSimpleName().toLowerCase())
			).create()
		); 
	}
}
 
Example #3
Source File: VanillaCommandWrapper.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
private net.minecraft.command.ICommandSender getListener(CommandSender sender) {
    if (sender instanceof Player) {
        return ((CraftPlayer) sender).getHandle();
    }
    if (sender instanceof BlockCommandSender) {
        return ((CraftBlockCommandSender) sender).getTileEntity();
    }
    if (sender instanceof CommandMinecart) {
        return ((net.minecraft.entity.EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).func_145822_e();
    }
    if (sender instanceof RemoteConsoleCommandSender) {
        return net.minecraft.network.rcon.RConConsoleSource.instance;
    }
    if (sender instanceof ConsoleCommandSender) {
        return ((CraftServer) sender.getServer()).getServer();
    }
    return null;
}
 
Example #4
Source File: AddEmailCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldRejectNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verifyNoInteractions(management);
}
 
Example #5
Source File: ChannelMemberBukkit.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * CommandSenderから、ChannelMemberを作成して返す
 * @param sender
 * @return ChannelMember
 */
public static ChannelMemberBukkit getChannelMemberBukkit(Object sender) {
    if ( sender == null || !(sender instanceof CommandSender) ) return null;
    if ( sender instanceof BlockCommandSender ) {
        return new ChannelMemberBlock((BlockCommandSender)sender);
    } else if ( sender instanceof ConsoleCommandSender ) {
        return new ChannelMemberBukkitConsole((ConsoleCommandSender)sender);
    } else {
        return ChannelMemberPlayer.getChannelPlayer((CommandSender)sender);
    }
}
 
Example #6
Source File: ChannelPlayer.java    From LunaChat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * CommandSenderから、ChannelPlayerを作成して返す
 * @param sender
 * @return ChannelPlayer
 */
public static ChannelPlayer getChannelPlayer(CommandSender sender) {
    if ( sender == null ) {
        return null;
    } else if ( sender instanceof BlockCommandSender ) {
        return new ChannelPlayerBlock((BlockCommandSender)sender);
    } else if ( sender instanceof ConsoleCommandSender ) {
        return new ChannelPlayerConsole((ConsoleCommandSender)sender);
    }
    return ChannelPlayerUUID.getChannelPlayer(sender);
}
 
Example #7
Source File: PlayerCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldRejectNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);
    PlayerCommandImpl command = new PlayerCommandImpl();

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verify(sender).sendMessage(argThat(containsString("only for players")));
}
 
Example #8
Source File: ChangePasswordCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldRejectNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verify(sender).sendMessage(argThat(containsString("use /authme password <playername> <password> instead")));
}
 
Example #9
Source File: RegisterCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldNotRunForNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verify(sender).sendMessage(argThat(containsString("Player only!")));
    verifyNoInteractions(management, emailService);
}
 
Example #10
Source File: LoginCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldStopIfSenderIsNotAPlayer() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verifyNoInteractions(management);
    verify(sender).sendMessage(argThat(containsString("/authme forcelogin <player>")));
}
 
Example #11
Source File: LogoutCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldStopIfSenderIsNotAPlayer() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, new ArrayList<String>());

    // then
    verifyNoInteractions(management);
    verify(sender).sendMessage(argThat(containsString("only for players")));
}
 
Example #12
Source File: ChangeEmailCommandTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldRejectNonPlayerSender() {
    // given
    CommandSender sender = mock(BlockCommandSender.class);

    // when
    command.executeCommand(sender, Collections.emptyList());

    // then
    verifyNoInteractions(management);
}
 
Example #13
Source File: BukkitCommandSource.java    From BlueMap with MIT License 5 votes vote down vote up
private Location getLocation() {
	Location location = null;
	if (delegate instanceof Entity) {
		location = ((Entity) delegate).getLocation();
	}
	if (delegate instanceof BlockCommandSender) {
		location = ((BlockCommandSender) delegate).getBlock().getLocation();
	}
	
	return location;
}
 
Example #14
Source File: MyCommand.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
public boolean isValidSender(CommandSender sender) {
	switch (this) {
	case PLAYER_ONLY:
		return (sender instanceof Player);
	case NO_PLAYER:
		return (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender || sender instanceof BlockCommandSender);
	case CONSOLE_ONLY:
		return (sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender);
	case BLOCK_ONLY:
		return (sender instanceof BlockCommandSender);
	case DEFAULT:
		return true;
	}
	return false;
}
 
Example #15
Source File: RandomTeleportCommand.java    From RandomTeleport with GNU General Public License v3.0 5 votes vote down vote up
private static Location getLocation(CommandSender sender) {
    if (sender instanceof Entity) {
        return ((Entity) sender).getLocation();
    } else if (sender instanceof BlockCommandSender) {
        return ((BlockCommandSender) sender).getBlock().getLocation();
    }
    return new Location(Bukkit.getWorlds().get(0), 0, 0, 0);
}
 
Example #16
Source File: WorldBorderCommand.java    From UHC with MIT License 5 votes vote down vote up
protected Optional<World> getWorld(CommandSender sender) {
    if (sender instanceof Entity) {
        return Optional.of(((Entity) sender).getWorld());
    }

    if (sender instanceof BlockCommandSender) {
        return Optional.of(((BlockCommandSender) sender).getBlock().getWorld());
    }

    return Optional.absent();
}
 
Example #17
Source File: NMS.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
default World getCommandSenderWorld(CommandSender sender) {
	if(sender instanceof BlockCommandSender) {
		return ((BlockCommandSender) sender).getBlock().getWorld();
	} else if(sender instanceof ProxiedCommandSender) {
		return getCommandSenderWorld(((ProxiedCommandSender) sender).getCallee());
	} else if(sender instanceof Entity) {
		return ((Entity) sender).getWorld();
	} else {
		return null;
	}
}
 
Example #18
Source File: CommandEvent.java    From Lukkit with MIT License 4 votes vote down vote up
public CommandEvent(CommandSender sender, String command, String... args) {


        this.set("isPlayerSender", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return sender instanceof Player ? TRUE : FALSE;
            }
        });

        this.set("isConsoleSender", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return sender instanceof ConsoleCommandSender ? TRUE : FALSE;
            }
        });

        this.set("isBlockSender", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return sender instanceof BlockCommandSender ? TRUE : FALSE;
            }
        });

        this.set("isEntitySender", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return sender instanceof Entity ? TRUE : FALSE;
            }
        });

        this.set("getSender", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return CoerceJavaToLua.coerce(sender);
            }
        });

        this.set("getArgs", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                LuaTable tbl = new LuaTable();
                for (int i = 0; i < args.length; i++)
                    tbl.set(i + 1, args[i]);
                return tbl;
            }
        });

        this.set("getCommand", new ZeroArgFunction() {
            @Override
            public LuaValue call() {
                return CoerceJavaToLua.coerce(command);
            }
        });

    }
 
Example #19
Source File: CommandParticle.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
	Location location = null;
	boolean color = false;
	if (sender instanceof Player) {
		if (!sender.isOp()) {
			return false;
		}
		location = ((Player) sender).getLocation();
		color = true;
	} else if (sender instanceof BlockCommandSender) {
		location = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5D, 0.5D, 0.5D);
	} else {
		sender.sendMessage("This command needs to be sent by an ingame command executor.");
		return true;
	}
	if (args.length >= 8) {
		String name = args[0];
		String x = args[1];
		String y = args[2];
		String z = args[3];
		Location finalLocation = getLocation(sender, color, location, x, y, z);
		String xd = args[4];
		String yd = args[5];
		String zd = args[6];
		String speed = args[7];
		String amount = args.length > 8 ? args[8] : "1";
		float fXd = parseFloat(sender, color, xd);
		float fYd = parseFloat(sender, color, yd);
		float fZd = parseFloat(sender, color, zd);
		float fSpeed = parseFloat(sender, color, speed);
		int iAmount = parseInt(sender, color, amount);
		if (fXd != -1.0F && fYd != -1.0F && fZd != -1.0F && iAmount != -1) {
			try {
				ParticleEffect.fromName(name).display(fXd, fYd, fZd, fSpeed, iAmount, finalLocation, 32.0D);
				return true;
			} catch (Exception ex) {
				if (color) {
					sender.sendMessage("" + ChatColor.RED + "An internal error occurred while attempting to perform this command");
				} else {
					sender.sendMessage("An internal error occurred while attempting to perform this command");
				}
			}
		}
	}
	return false;
}
 
Example #20
Source File: ChannelPlayerBlock.java    From LunaChat with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BlockCommandSender getBlockCommandSender() {
    return sender;
}
 
Example #21
Source File: ChannelMemberBlock.java    From LunaChat with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BlockCommandSender getBlockCommandSender() {
    return sender;
}
 
Example #22
Source File: CommandManager.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s,
						 @NotNull String[] args) {
	if (!(sender.hasPermission("minetinker.commands.main"))) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.NoPermission"));
		return true;
	}

	if (args.length <= 0) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.InvalidArguments"));
		sendHelp(sender, null);
		return true;
	}

	if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
		sendHelp(sender, args.length >= 2 ? map.get(args[1].toLowerCase()) : null);
		return true;
	}

	SubCommand sub = map.get(args[0].toLowerCase());
	if (sub == null) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.UnknownCommand"));
		sendHelp(sender, null);
		return true;
	}

	parseArguments(sender, sub, args);

	//@all / @allworld
	{
		int index = -1;
		boolean worldOnly = false;
		for (int i = 0; i < args.length; i++) {
			List<ArgumentType> types = sub.getArgumentsToParse().get(i);
			if (types != null && types.contains(ArgumentType.PLAYER)) {
				if (args[i].startsWith("@aw")) {
					index = i;
					worldOnly = true;
					break;
				} else if (args[i].startsWith("@a")) {
					index = i;
					break;
				}
			}
		}
		if (index != -1) {
			Collection<? extends Player> players;
			if (worldOnly) {
				World world = null;
				if (sender instanceof BlockCommandSender) {
					world = ((BlockCommandSender) sender).getBlock().getWorld();
				} else if (sender instanceof Entity) {
					world = ((Entity) sender).getWorld();
				}

				if (world == null) return true;
				players = world.getPlayers();
			} else {
				players = Bukkit.getOnlinePlayers();
			}

			boolean ret = true;
			for (Player player : players) {
				String[] arg = args.clone();
				arg[index] = player.getName();
				ret = ret && onCommand(sender, command, s, arg);
			}
		}
	}

	if (!sender.hasPermission(sub.getPermission())) {
		sendError(sender, LanguageManager.getString("Commands.Failure.Cause.NoPermission"));
		return true;
	}

	return sub.onCommand(sender, args);
}
 
Example #23
Source File: CommandBlockCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 2 votes vote down vote up
/**
 * The code to run when this command is performed
 * 
 * @param sender
 *            The sender of this command (a player, the console etc.)
 * @param args
 *            The arguments given to this command. The objects are
 *            determined by the hashmap of arguments IN THE ORDER of
 *            insertion into the hashmap
 */
void run(BlockCommandSender sender, Object[] args) throws WrapperCommandSyntaxException;
 
Example #24
Source File: ChannelPlayerBlock.java    From LunaChat with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * コンストラクタ
 * @param sender コマンドブロック
 */
public ChannelPlayerBlock(BlockCommandSender sender) {
    this.sender = sender;
}
 
Example #25
Source File: ChannelMemberBlock.java    From LunaChat with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * コンストラクタ
 * @param sender コマンドブロック
 */
public ChannelMemberBlock(BlockCommandSender sender) {
    this.sender = sender;
}