private void createCoupon(final CommandSender sender, String[] args) { String[] stripped = Arrays.copyOfRange(args, 1, args.length); final Coupon coupon; try { coupon = CouponUtil.parseArguments(stripped); } catch (Exception e) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("coupon_creation_arg_parse_failure", e.getMessage())); return; } plugin.getPlatform().executeAsync(new Runnable() { @Override public void run() { try { plugin.getApiClient().createCoupon(coupon); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_creation_success", coupon.getCode())); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("generic_api_operation_error")); } } }); }
private void createCoupon(final CommandSender sender, String[] args) { String[] stripped = Arrays.copyOfRange(args, 1, args.length); final Coupon coupon; try { coupon = CouponUtil.parseArguments(stripped); } catch (Exception e) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("coupon_creation_arg_parse_failure", e.getMessage())); return; } plugin.getPlatform().executeAsync(new Runnable() { @Override public void run() { try { plugin.getApiClient().createCoupon(coupon); sender.sendMessage(TextFormat.GREEN + plugin.getI18n().get("coupon_creation_success", coupon.getCode())); } catch (ApiException | IOException e) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("generic_api_operation_error")); } } }); }
private void createCoupon(final CommandSender sender, String[] args) { String[] stripped = Arrays.copyOfRange(args, 1, args.length); final Coupon coupon; try { coupon = CouponUtil.parseArguments(stripped); } catch (Exception e) { sender.sendMessage(e.getMessage()); sender.sendMessage(ChatColor.RED + plugin.getI18n().get("coupon_creation_arg_parse_failure", e.getMessage())); return; } plugin.getPlatform().executeAsync(new Runnable() { @Override public void run() { try { plugin.getApiClient().createCoupon(coupon); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_creation_success", coupon.getCode())); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); } } }); }
public CommandResult createCoupon(CommandSource source, CommandContext ctx) throws CommandException { Collection<String> argsList = ctx.getAll("args"); String[] argsArray = argsList.toArray(new String[argsList.size()]); final Coupon coupon; try { coupon = CouponUtil.parseArguments(argsArray); } catch (Exception e) { source.sendMessage(Text.builder(plugin.getI18n().get("coupon_creation_arg_parse_failure", e.getMessage())) .color(TextColors.RED) .build()); return CommandResult.empty(); } plugin.getPlatform().executeAsync(new Runnable() { @Override public void run() { try { plugin.getApiClient().createCoupon(coupon); source.sendMessage(Text.builder(plugin.getI18n().get("coupon_creation_success", coupon.getCode())) .color(TextColors.GREEN) .build()); } catch (ApiException | IOException e) { source.sendMessage(Text.builder(plugin.getI18n().get("generic_api_operation_error")) .color(TextColors.RED) .build()); } } }); return CommandResult.empty(); }