@EventHandler public void onPlayerJoin(final PlayerJoinEvent event) { if (event.getPlayer().hasPermission("buycraft.admin") && !upToDate) { plugin.getPlatform().executeAsyncLater(new Runnable() { @Override public void run() { event.getPlayer().sendMessage(ChatColor.YELLOW + plugin.getI18n().get("update_available", lastKnownVersion.getVersion())); } }, 3, TimeUnit.SECONDS); } } }
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()); } } }); }
private void deleteCoupon(final CommandSender sender, String[] args) { if (args.length != 2) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("no_coupon_specified")); return; } final String code = args[1]; plugin.getPlatform().executeAsync(new Runnable() { @Override public void run() { try { plugin.getApiClient().deleteCoupon(code); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("coupon_deleted")); } catch (ApiException | IOException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); return; } } }); }
@Override public void run() { ReportBuilder builder = ReportBuilder.builder() .client(plugin.getHttpClient()) .configuration(plugin.getConfiguration()) .platform(plugin.getPlatform()) .duePlayerFetcher(plugin.getDuePlayerFetcher()) .ip(Bukkit.getIp()) .port(Bukkit.getPort()) .listingUpdateTask(plugin.getListingUpdateTask()) .serverOnlineMode(Bukkit.getOnlineMode()) .build(); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); String filename = "report-" + f.format(new Date()) + ".txt"; Path p = plugin.getDataFolder().toPath().resolve(filename); String generated = builder.generate(); try (BufferedWriter w = Files.newBufferedWriter(p, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW)) { w.write(generated); sender.sendMessage(ChatColor.YELLOW + plugin.getI18n().get("report_saved", p.toAbsolutePath().toString())); } catch (IOException e) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("report_cant_save")); plugin.getLogger().info(generated); } } });