private void loadFromDatabase() { final ResultSet result = this.connection.getSQL().getResult("SELECT * FROM `cp_bans`;", false, true); try { while (result != null && result.next()) { final CraftoPlayer player = CraftoPlayer.getPlayer(result.getInt("player_id")); final CraftoPlayer bannedBy = CraftoPlayer.getPlayer(result.getInt("banned_by")); if (player != null && bannedBy != null) { final BanRecord record = new BanRecord( player, bannedBy, result.getString("reason"), result.getTimestamp("created_at"), result.getLong("duration")); this.map.put(record.getPlayer().getUniqueId(), record); } } } catch (final SQLException e) { int id = -1; try { id = result.getInt("id"); } catch (final Exception ignoreMe) { } CraftoMessenger.exception( "BanModule/BanDatabase.java/createTable()", "SQL Exception at BanRecord: " + id, e); } }
@Command("kit") @Aliases({"kits"}) public boolean onCommand(final CommandSender cs, final String command, final String[] args) { if (command.equalsIgnoreCase("kit")) { if (cs instanceof Player) { if (args.length > 0 && args.length < 2) { if (this.module.containsKit(args[0].toLowerCase())) { final Kit kit = this.module.getKit(args[0].toLowerCase()); if (kit.isEnabled()) { final Player p = (Player) cs; final CraftoPlayer cp = CraftoPlayer.getPlayer(p); if (cs.hasPermission(kit.getPermission())) { final Timestamp updated_at = (Timestamp) CraftoDatabase.getValue( "SELECT `updated_at` FROM `cp_kits` WHERE `player` = " + cp.getId(), "updated_at", true); if (updated_at != null) { try { final long lastTimeUse = updated_at.getTime(); if (kit.isOnetimeuse()) { CraftoMessenger.sendFailed(cs, "KIT_ALREADY_USED"); return true; } else { if (lastTimeUse + kit.getInterval() > System.currentTimeMillis()) { CraftoMessenger.sendFailed(cs, "KIT_NOT_YET"); CraftoMessenger.sendMessage( cs, "§7Verwendung in: " + (((lastTimeUse + kit.getInterval()) - System.currentTimeMillis()) / 1000 + " Sekunden.")); return true; } } } catch (final Exception e) { CraftoMessenger.exception( "KitCommands/onCommand()", "Failed to lookup last time use", e); } } for (final ItemStack item : kit.getItems()) { p.getInventory().addItem(item); } this.module .getPlugin() .getScheduler() .registerQuery( "" + "INSERT INTO `cp_kits` (`player`, `kit`, `updated_at`, `count`) " + "VALUES (" + cp.getId() + ", '" + kit.getName() + "', '" + new Timestamp(System.currentTimeMillis()) + "', 1) " + "ON DUPLICATE KEY UPDATE `updated_at`='" + new Timestamp(System.currentTimeMillis()) + "', `count`=count+1;"); } else { CraftoMessenger.sendFailed(cs, "KIT_NO_ACCESS"); } } else { CraftoMessenger.sendFailed(cs, "KIT_DOESNT_EXIST"); } } else { CraftoMessenger.sendFailed(cs, "KIT_DOESNT_EXIST"); } } else if (cs.hasPermission("craftoplugin.kits.admin")) { if (args[0].equalsIgnoreCase("create")) { final String kit = args[1].toLowerCase(); if (!this.module.getPlugin().getConfig().contains("kits." + kit)) { final Player p = (Player) cs; Boolean oneTimeUse = true; Long interval = 1000L; if (args.length == 3) { // kit create name true try { oneTimeUse = Boolean.parseBoolean(args[3]); } catch (final Exception e) { } } else if (args.length == 4) { // kit name create // true 1000 try { oneTimeUse = Boolean.parseBoolean(args[3]); } catch (final Exception e) { } try { interval = Long.parseLong(args[4]); } catch (final Exception e) { } } final FileConfiguration cfg = this.module.getPlugin().getConfig(); cfg.createSection("kits." + kit); cfg.set("kits." + kit + ".onetimeuse", oneTimeUse.toString()); cfg.set("kits." + kit + ".interval", interval.toString()); final List<String> enabledKits = cfg.getStringList("kits.enabled"); enabledKits.add(kit); cfg.set("kits.enabled", enabledKits); final List<ItemStack> items = new ArrayList<ItemStack>(); for (final ItemStack item : p.getInventory().getContents()) { if (item != null && !item.getType().equals(Material.AIR)) { items.add(item); } } cfg.set("kits." + kit + ".items", items); this.module.getPlugin().saveConfig(); CraftoMessenger.sendSuccess(cs, "KIT_CREATED_SUCCESS"); } else { CraftoMessenger.sendFailed(cs, "KIT_ALREADY_EXISTS"); } } else if (args[0].equalsIgnoreCase("reload")) { this.module.reload(); CraftoMessenger.sendSuccess(cs, "KITS_RELOADED"); } else { CraftoMessenger.sendFailed(cs, "INVALID_COMMAND"); } } else { CraftoMessenger.sendFailed(cs, "NO_GIVEN_KIT"); } } } else if (command.equalsIgnoreCase("kits")) { String text = "Verfügbare Kits: "; for (final Entry<String, Kit> entry : this.module.getKits()) { if (cs.hasPermission(entry.getValue().getPermission())) { text += entry.getKey() + ", "; } } CraftoMessenger.sendMessage(cs, text.substring(0, text.length() - 2)); } return true; }