Skip to content
This repository was archived by the owner on Nov 26, 2019. It is now read-only.

Commit e04e455

Browse files
committed
Fix style and activate DLL injection connecting again
1 parent 5c110b4 commit e04e455

File tree

14 files changed

+65
-95
lines changed

14 files changed

+65
-95
lines changed

src/main/kotlin/com/msc/serverbrowser/data/FavouritesController.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import java.nio.charset.StandardCharsets
1515
import java.nio.file.Files
1616
import java.nio.file.Paths
1717
import java.sql.SQLException
18-
import java.util.ArrayList
18+
import java.util.*
1919

2020
/**
2121
* Contains static methods for setting and retrieving favourite servers
@@ -68,18 +68,18 @@ object FavouritesController {
6868
val server = SampServer(address, port)
6969
try {
7070
SampQuery(address, port).use { query ->
71-
query.basicServerInfo.ifPresent({ serverInfo ->
71+
query.basicServerInfo.ifPresent { serverInfo ->
7272
server.players = Integer.parseInt(serverInfo[1])
7373
server.maxPlayers = Integer.parseInt(serverInfo[2])
7474
server.hostname = serverInfo[3]!!
7575
server.mode = serverInfo[4]!!
7676
server.language = serverInfo[5]!!
77-
})
77+
}
7878

79-
query.serversRules.ifPresent({ rules ->
79+
query.serversRules.ifPresent { rules ->
8080
server.website = rules["weburl"]!!
8181
server.version = rules["version"]!!
82-
})
82+
}
8383
}
8484
} catch (exception: SocketException) {
8585
warn("Error updating server information.", exception)

src/main/kotlin/com/msc/serverbrowser/data/ServerConfig.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package com.msc.serverbrowser.data
33
import com.msc.serverbrowser.data.entites.SampServer
44
import com.msc.serverbrowser.severe
55
import java.sql.SQLException
6-
import java.util.ArrayList
7-
import java.util.Optional
6+
import java.util.*
87

98
/**
109
* Allows controller over server specific settings. TODO(MSC) I could still improve the setter
@@ -102,7 +101,7 @@ object ServerConfig {
102101
* @return An [Optional] containing the to be used username or empty
103102
*/
104103
private fun getLastJoinForServer(ip: String, port: Int): Optional<Long> {
105-
return getStringOfField(ip, port, "lastJoin").map({ it.toLong() })
104+
return getStringOfField(ip, port, "lastJoin").map { it.toLong() }
106105
}
107106

108107
/**
@@ -141,7 +140,7 @@ object ServerConfig {
141140
* @param servers servers to inject their last join date into
142141
*/
143142
fun initLastJoinData(servers: Collection<SampServer>) {
144-
servers.forEach { server -> getLastJoinForServer(server.address, server.port).ifPresent({ server.lastJoin = it }) }
143+
servers.forEach { server -> getLastJoinForServer(server.address, server.port).ifPresent { server.lastJoin = it } }
145144
}
146145

147146
private fun getStringOfField(ip: String, port: Int, field: String): Optional<String> {
@@ -157,11 +156,11 @@ object ServerConfig {
157156

158157
if (resultSet != null) {
159158
try {
160-
resultSet.use({
159+
resultSet.use {
161160
if (it.next()) {
162161
return Optional.of(it.getString(field))
163162
}
164-
})
163+
}
165164
} catch (exception: SQLException) {
166165
severe("Error while retrieving field: '$field of server: $ip:$port", exception)
167166
}

src/main/kotlin/com/msc/serverbrowser/gui/UncaughtExceptionHandlerController.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import java.net.URISyntaxException
1414
*/
1515
class UncaughtExceptionHandlerController {
1616

17+
companion object {
18+
private const val LINE_SEPARATOR = "\n"
19+
}
20+
1721
/**
1822
* Opens the webbrowser with the new issue Github-page and an already given issue title and
1923
* issue body, which already contains information about the exception, th os and the jvm.
@@ -72,10 +76,5 @@ class UncaughtExceptionHandlerController {
7276
} catch (exception: URISyntaxException) {
7377
severe("Error reporting severe", exception)
7478
}
75-
76-
}
77-
78-
companion object {
79-
private const val LINE_SEPARATOR = "\n"
8079
}
8180
}

src/main/kotlin/com/msc/serverbrowser/gui/components/SampServerTable.kt

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,16 @@ import javafx.collections.FXCollections
1313
import javafx.collections.ObservableList
1414
import javafx.collections.transformation.FilteredList
1515
import javafx.collections.transformation.SortedList
16-
import javafx.scene.control.Alert
16+
import javafx.scene.control.*
1717
import javafx.scene.control.Alert.AlertType
18-
import javafx.scene.control.ButtonType
19-
import javafx.scene.control.ContextMenu
20-
import javafx.scene.control.MenuItem
21-
import javafx.scene.control.SelectionMode
22-
import javafx.scene.control.SeparatorMenuItem
23-
import javafx.scene.control.TableRow
24-
import javafx.scene.control.TableView
25-
import javafx.scene.input.Clipboard
26-
import javafx.scene.input.ClipboardContent
27-
import javafx.scene.input.DataFormat
28-
import javafx.scene.input.DragEvent
29-
import javafx.scene.input.KeyCode
30-
import javafx.scene.input.MouseButton
31-
import javafx.scene.input.MouseEvent
32-
import javafx.scene.input.TransferMode
18+
import javafx.scene.input.*
3319
import javafx.scene.text.Text
34-
import java.util.Collections
3520
import java.util.Optional
3621
import java.util.StringJoiner
3722
import java.util.function.Predicate
3823
import java.util.stream.Collectors
24+
import kotlin.collections.ArrayList
25+
import kotlin.collections.set
3926

4027
/**
4128
* [TableView] that was made for the ServerList View, contains a special TableRowFactory and
@@ -216,7 +203,7 @@ class SampServerTable(val client: Client) : TableView<SampServer>() {
216203
val clipboardContent = ClipboardContent()
217204

218205
val selectedServerIndices = selectionModel.selectedItems.stream()
219-
.map<Int>({ servers.indexOf(it) })
206+
.map<Int> { servers.indexOf(it) }
220207
.collect(Collectors.toList())
221208
clipboardContent[OLD_INDEXES_LIST_DATA_FORMAT] = selectedServerIndices
222209

src/main/kotlin/com/msc/serverbrowser/gui/controllers/implementations/ServerListController.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import javafx.scene.text.TextAlignment
3535
import javafx.util.Pair
3636
import java.io.IOException
3737
import java.text.MessageFormat
38-
import java.util.Objects
39-
import java.util.Optional
38+
import java.util.*
4039
import java.util.function.Predicate
4140
import java.util.regex.PatternSyntaxException
4241

@@ -74,7 +73,7 @@ class ServerListController(private val client: Client, private val mainControlle
7473
val address = view.addressTextField.text
7574

7675
if (Objects.nonNull(address) && !address.isEmpty()) {
77-
val ipAndPort = view.addressTextField.text.split("[:]".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()
76+
val ipAndPort = view.addressTextField.text.split("[:]".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
7877
if (ipAndPort.size == 1) {
7978
return Optional.of(Pair(ipAndPort[0], ServerUtility.DEFAULT_SAMP_PORT.toString()))
8079
} else if (ipAndPort.size == 2) {
@@ -173,7 +172,7 @@ class ServerListController(private val client: Client, private val mainControlle
173172
view.serverTable.placeholder = Label(Client.getString("noServerHistory"))
174173
view.lastJoinTableColumn.isVisible = true
175174
val servers = ServerConfig.lastJoinedServers
176-
servers.forEach({ server -> updateServerInfo(server, false) })
175+
servers.forEach { server -> updateServerInfo(server, false) }
177176
view.serverTable.addAll(servers)
178177
}
179178
}

src/main/kotlin/com/msc/serverbrowser/gui/views/ServerView.kt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,9 @@ import com.msc.serverbrowser.data.entites.SampServer
66
import com.msc.serverbrowser.gui.components.SampServerTable
77
import javafx.collections.FXCollections
88
import javafx.geometry.Orientation
9-
import javafx.scene.control.Button
10-
import javafx.scene.control.CheckBox
11-
import javafx.scene.control.ComboBox
12-
import javafx.scene.control.Hyperlink
13-
import javafx.scene.control.Label
14-
import javafx.scene.control.RadioButton
15-
import javafx.scene.control.Separator
16-
import javafx.scene.control.TableCell
17-
import javafx.scene.control.TableColumn
18-
import javafx.scene.control.TableView
19-
import javafx.scene.control.TextField
20-
import javafx.scene.control.TitledPane
21-
import javafx.scene.control.ToggleGroup
22-
import javafx.scene.control.cell.CheckBoxTableCell
9+
import javafx.scene.control.*
2310
import javafx.scene.control.cell.PropertyValueFactory
24-
import javafx.scene.layout.ColumnConstraints
25-
import javafx.scene.layout.GridPane
26-
import javafx.scene.layout.HBox
27-
import javafx.scene.layout.Priority
28-
import javafx.scene.layout.Region
29-
import javafx.scene.layout.RowConstraints
30-
import javafx.scene.layout.VBox
11+
import javafx.scene.layout.*
3112
import java.time.Instant
3213
import java.time.LocalDateTime
3314
import java.time.ZoneId

src/main/kotlin/com/msc/serverbrowser/util/ServerUtility.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object ServerUtility {
3939
openConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
4040
BufferedReader(InputStreamReader(openConnection.getInputStream())).use { `in` ->
4141
`in`.lines().forEach { inputLine ->
42-
val data = inputLine.split(":".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()
42+
val data = inputLine.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
4343
val server = SampServer(data[0], Integer.parseInt(data[1]))
4444
if (!servers.contains(server)) {
4545
servers.add(server)
@@ -93,7 +93,7 @@ object ServerUtility {
9393

9494
jsonArray.forEach { `object` ->
9595
val jsonServerData = `object`.asObject()
96-
val addressData = jsonServerData.getString("ip", UNKNOWN).split(":".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()
96+
val addressData = jsonServerData.getString("ip", UNKNOWN).split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
9797
val port = if (addressData.size == 2) Integer.parseInt(addressData[1]) else ServerUtility.DEFAULT_SAMP_PORT
9898
val server = SampServer(addressData[0], port)
9999

src/main/kotlin/com/msc/serverbrowser/util/UpdateUtility.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import com.msc.serverbrowser.util.basic.ArrayUtility
66
import org.kohsuke.github.GHRelease
77
import org.kohsuke.github.GitHubBuilder
88
import org.kohsuke.github.RateLimitHandler
9-
import java.io.FileInputStream
109
import java.io.IOException
11-
import java.net.URL
12-
import java.nio.file.Files
1310
import java.util.*
1411
import java.util.stream.IntStream
1512

@@ -35,7 +32,7 @@ object UpdateUtility {
3532
/** Username/Repository on GitHub. */
3633
private const val TARGET_REPOSITORY_FOR_UPDATES = "Bios-Marcel/ServerBrowser"
3734

38-
fun readVersionNumber(): String {
35+
private fun readVersionNumber(): String {
3936
val versionFile = UpdateUtility::class.java.getResourceAsStream("/com/msc/serverbrowser/version.properties")
4037
val properties = Properties()
4138
versionFile.use {

src/main/kotlin/com/msc/serverbrowser/util/basic/FileUtility.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object FileUtility {
5454
*/
5555
@Throws(IOException::class)
5656
fun copyOverwrite(source: String, target: String) {
57-
Files.newInputStream(Paths.get(source)).use { fileInputStream -> Channels.newChannel(fileInputStream).use({ readableByteChannel -> FileOutputStream(target).use { fileOutputStream -> fileOutputStream.channel.transferFrom(readableByteChannel, 0, java.lang.Long.MAX_VALUE) } }) }
57+
Files.newInputStream(Paths.get(source)).use { fileInputStream -> Channels.newChannel(fileInputStream).use { readableByteChannel -> FileOutputStream(target).use { fileOutputStream -> fileOutputStream.channel.transferFrom(readableByteChannel, 0, java.lang.Long.MAX_VALUE) } } }
5858
}
5959

6060
/**
@@ -116,9 +116,7 @@ object FileUtility {
116116
connection.inputStream
117117
return connection.contentLength
118118
} finally {
119-
if (connection != null) {
120-
connection.disconnect()
121-
}
119+
connection?.disconnect()
122120
}
123121
}
124122

@@ -150,20 +148,20 @@ object FileUtility {
150148
parent?.mkdirs()
151149

152150
// Extract the file
153-
zipFile.getInputStream(zipEntry).use({ inputStream ->
151+
zipFile.getInputStream(zipEntry).use { inputStream ->
154152
Files.newOutputStream(Paths.get(outputFile.toURI())).use { outputStream ->
155153
/*
156-
* The buffer is the max amount of bytes kept in RAM during any given time while
157-
* unzipping. Since most windows disks are aligned to 4096 or 8192, we use a
158-
* multiple of those values for best performance.
159-
*/
154+
* The buffer is the max amount of bytes kept in RAM during any given time while
155+
* unzipping. Since most windows disks are aligned to 4096 or 8192, we use a
156+
* multiple of those values for best performance.
157+
*/
160158
val bytes = ByteArray(8192)
161159
while (inputStream.available() > 0) {
162160
val length = inputStream.read(bytes)
163161
outputStream.write(bytes, 0, length)
164162
}
165163
}
166-
})
164+
}
167165
}
168166
}
169167
}
@@ -220,7 +218,7 @@ object FileUtility {
220218
*/
221219
@Throws(IOException::class)
222220
fun readAllLinesTryEncodings(path: Path, vararg charsets: Charset): List<String> {
223-
if(!Files.exists(path)) {
221+
if (!Files.exists(path)) {
224222
throw FileNotFoundException("The file at $path doesn't exist.")
225223
}
226224

src/main/kotlin/com/msc/serverbrowser/util/basic/HashingUtility.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import java.nio.file.Files
66
import java.nio.file.Paths
77
import java.security.MessageDigest
88
import java.security.NoSuchAlgorithmException
9-
import kotlin.experimental.and
109

1110
/**
1211
* Contains a single method, that is used to take the SHA-256 of a file.

0 commit comments

Comments
 (0)