@Override public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception { if (service == null) { service = Sponge.getServiceManager().provideUnchecked(NucleusWarpService.class); } PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class); // Get the warp list. Set<String> ws = service.getWarpNames(); if (ws.isEmpty()) { src.sendMessage(Util.getTextMessageWithFormat("command.warps.list.nowarps")); return CommandResult.empty(); } List<Text> lt = ws.stream() .filter(s -> canView(src, s.toLowerCase())) .map( s -> { if (service.getWarp(s).isPresent()) { return Text.builder(s) .color(TextColors.GREEN) .style(TextStyles.UNDERLINE) .onClick(TextActions.runCommand("/warp " + s)) .onHover( TextActions.showText( Util.getTextMessageWithFormat("command.warps.warpprompt", s))) .build(); } else { return Text.builder(s) .color(TextColors.RED) .onHover( TextActions.showText( Util.getTextMessageWithFormat("command.warps.unavailable"))) .build(); } }) .collect(Collectors.toList()); PaginationList.Builder pb = ps.builder() .title(Util.getTextMessageWithFormat("command.warps.list.header")) .padding(Text.of(TextColors.GREEN, "-")) .contents(lt); if (!(src instanceof Player)) { pb.linesPerPage(-1); } pb.sendTo(src); return CommandResult.success(); }
public void init() { SqlService sql = Sponge.getServiceManager() .provide(SqlService.class) .orElseThrow(() -> new IllegalStateException("NoSQL?")); String jdbcUrl = Planetesimals.getInstance().getJDBCUrl(); String[] dbParts = jdbcUrl.split(":"); if (dbParts.length < 2 || !dbParts[1].equals("h2")) { throw new IllegalStateException("Not H2. Dunno what to do."); } try { this.data = sql.getDataSource(jdbcUrl); } catch (SQLException e) { throw new IllegalStateException("Couldn't load DB", e); } this.db = using(this.data, SQLDialect.H2); if (getDB() .meta() .getTables() .stream() .noneMatch(t -> t.getName().equalsIgnoreCase(PLANETS_TABLE.getName()))) { getDB() .createTable(PLANETS_TABLE) .column(CHUNK_X_FIELD, getDataType(Integer.class)) .column(CHUNK_Y_FIELD, getDataType(Integer.class)) .column(CHUNK_Z_FIELD, getDataType(Integer.class)) .column(PLANET_X_FIELD, getDataType(Integer.class)) .column(PLANET_Y_FIELD, getDataType(Integer.class)) .column(PLANET_Z_FIELD, getDataType(Integer.class)) .column(PLANET_RADIUS_FIELD, getDataType(Integer.class)) .execute(); } }
@Override public Optional<Text> getValue(@Nullable Object player) { if (player == null) return Optional.empty(); if (player instanceof Player) { Player p = (Player) player; if (Sponge.getServiceManager().provide(EconomyService.class).isPresent()) { EconomyService es = Sponge.getServiceManager().provide(EconomyService.class).get(); if (es.getOrCreateAccount(p.getUniqueId()).isPresent()) { BigDecimal balance = es.getOrCreateAccount(p.getUniqueId()).get().getBalance(es.getDefaultCurrency()); return Optional.of(Text.of(balance.toString())); } } return Optional.empty(); } return Optional.empty(); }
@Override public Optional<Text> getBanReason(GameProfile profile) { checkNotNull(profile, "Game profile cannot be null!"); BanService service = Sponge.getServiceManager().provide(BanService.class).get(); Optional<Ban.Profile> optionalBan = service.getBanFor(profile); if (optionalBan.isPresent()) { return optionalBan.get().getReason(); } return Optional.empty(); }
@Listener(order = Order.PRE) public void onDestructEntityEventDeathPlayer( DestructEntityEvent.Death event, @First EntityDamageSource damageSrc) { if (!(event.getTargetEntity() instanceof Player)) { return; } Player player = (Player) event.getTargetEntity(); WorldSettings settings = WorldSettings.get(player.getWorld()); DeathReason reason = DeathReason.GENERIC; Entity src = damageSrc.getSource(); if (src instanceof Player) { reason = DeathReason.PLAYER; } else if (src instanceof Projectile) { Projectile projectile = (Projectile) src; Optional<UUID> optionalUUID = projectile.getCreator(); if (!optionalUUID.isPresent()) { return; } Optional<Player> optionalPlayer = Sponge.getServer().getPlayer(optionalUUID.get()); if (optionalPlayer.isPresent()) { reason = DeathReason.PLAYER; } else { reason = DeathReason.PROJECTILE; } } else { DamageType cause = damageSrc.getType(); reason = DeathReason.valueOf(cause.getName().toUpperCase()); } Optional<EconomyService> optionalEconomy = Sponge.getServiceManager().provide(EconomyService.class); if (!optionalEconomy.isPresent()) { Main.instance().getLog().error("Economy plugin not found"); return; } EconomyService economy = optionalEconomy.get(); BigDecimal balance = economy .getOrCreateAccount(player.getUniqueId()) .get() .getBalance(WorldSettings.get(player.getWorld()).getCurrency()); PlayerWallet wallet = settings.getPlayerWallet(); BigDecimal amount = wallet.getAmount(reason, balance); WalletDropEvent walletDropEvent = new WalletDropEvent(amount, player); if (walletDropEvent.getAmount().compareTo(BigDecimal.ZERO) != 0 && (!Sponge.getEventManager().post(walletDropEvent))) { WalletDrop.depositOrWithdraw( player, walletDropEvent.getAmount().multiply(BigDecimal.valueOf(-1))); if (settings.isDropsEnabled()) { for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) { moneyStack.drop(walletDropEvent.getLocation()); } } WalletDrop.sendDeathMessage( WorldSettings.get(player.getWorld()), player, walletDropEvent.getAmount()); } }