//jakies metodki public class HouseManager { private final Map houses = new HashMap<>(); private Schematic houseSchematic; private HouseFactory factory; public void loadSchematic(File file) { try { this.houseSchematic = ClipboardFormat.SCHEMATIC.load(file); } catch (IOException ignored) {} } public void loadHouses(Database database) { CompletableFuture.runAsync(() -> { try (final Connection connection = database.getConnection(); final PreparedStatement select = connection .prepareStatement("SELECT * from `housing_homes`")) { this.factory = HouseFactory.from(connection); final ResultSet resultSet = select.executeQuery(); while (resultSet.next()) { final String houseName = resultSet.getString("house_name"); final String ownerName = resultSet.getString("owner_name"); final UUID ownerUUID = UUIDUtil.getUUIDFromBytes(resultSet.getBytes("owner_uuid")); final Location locationStart = LocationUtil .fromString(resultSet.getString("location_start")); final Location locatioNEnd = LocationUtil .fromString(resultSet.getString("location_end")); final House house = new House(ownerUUID, houseName, ownerName, locationStart, locatioNEnd); this.houses.put(ownerUUID, house); } } catch (SQLException ignored) { } }); } public House doNewHouse(HousingUser user) { return this.houses.putIfAbsent(user.getUniqueId(), new House( user.getUniqueId(), user.getName(), //user name user.getName(), //house name new Location(SettingsConfig.worldHousesName(), this.factory.nextX, SettingsConfig.WORLD$HOUSES_WORLD_Y, this.factory.nextZ), new Location(SettingsConfig.worldHousesName(), this.factory.nextX=this.factory.nextX+40, SettingsConfig.WORLD$HOUSES_WORLD_Y+30, this.factory.nextZ=this.factory.nextZ+40) )); @EventHandler public void onJoin(PlayerJoinEvent event) { final Player player = event.getPlayer(); final HousingUser user = this.userManager.getOrCreateUser(player); new MessageSender(MessagesConfig.JOIN_MESSAGE).sendTo(player); this.sidebarManager.loadFor(user); this.houseManager.getHouse(player.getUniqueId()).ifPresentOrElse((house) -> { player.teleport(house.getCuboid().getCenter()); }, () -> { final House house = this.houseManager.doNewHouse(user); player.teleport(house.getCuboid().getCenter()); }); static class HouseFactory { double nextX, nextZ; HouseFactory(double x, double z) { this.nextX = x; this.nextZ = z; } static HouseFactory from(Connection connection) throws SQLException { final PreparedStatement selectFactory = connection .prepareStatement("SELECT * from `housing_houseFactory`"); final ResultSet resultSetFactory = selectFactory.executeQuery(); if (resultSetFactory.next()) { return new HouseFactory( resultSetFactory.getDouble("nextX"), resultSetFactory.getDouble("nextZ") ); } return new HouseFactory(0.0D, 0.0D); } }