Skip to content

Commit f701f5a

Browse files
Merge pull request #28 from Test-Account666/4.1.0
4.0.0 -> 4.1.0
2 parents 5039a3a + 48933f6 commit f701f5a

File tree

198 files changed

+2694
-4086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+2694
-4086
lines changed

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
<groupId>me.testaccount666</groupId>
88
<artifactId>ServerSystem</artifactId>
9-
<version>4.0.0</version>
9+
<version>4.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>ServerSystem</name>
1313

1414
<properties>
1515
<java.version>21</java.version>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
1618
<kotlin.version>2.3.20-Beta1</kotlin.version>
1719
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1820
<cleanVersion>${project.version}</cleanVersion>

src/main/kotlin/me/testaccount666/migration/LegacyDataMigrator.kt

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import me.testaccount666.serversystem.ServerSystem.Companion.instance
44
import me.testaccount666.serversystem.ServerSystem.Companion.log
55
import me.testaccount666.serversystem.commands.executables.kit.manager.Kit
66
import me.testaccount666.serversystem.commands.executables.kit.manager.KitManager
7-
import me.testaccount666.serversystem.commands.executables.warp.manager.Warp
8-
import me.testaccount666.serversystem.commands.executables.warp.manager.WarpManager
7+
import me.testaccount666.serversystem.commands.executables.waypoints.warp.manager.Warp
8+
import me.testaccount666.serversystem.commands.executables.waypoints.warp.manager.WarpManager
99
import me.testaccount666.serversystem.moderation.AbstractModeration
1010
import me.testaccount666.serversystem.moderation.BanModeration
1111
import me.testaccount666.serversystem.moderation.MuteModeration
@@ -27,24 +27,23 @@ import java.sql.DriverManager
2727
import java.sql.ResultSet
2828
import java.sql.SQLException
2929
import java.util.*
30-
import java.util.function.Consumer
3130
import java.util.logging.Level
3231

32+
//TODO: Remove this class
33+
@Deprecated("This class is deprecated and will be removed in v4.4.0!")
3334
class LegacyDataMigrator {
3435
private lateinit var _legacyDataDirectory: File
3536
private var _foundLegacyData = false
3637

3738
/**
3839
* Retrieves an offline user by UUID.
39-
*
40+
*
4041
* @param uuid The UUID of the user to retrieve
4142
* @return Optional containing the offline user if found, empty otherwise
4243
*/
4344
private fun getOfflineUser(uuid: UUID): OfflineUser? {
4445
val userManager = instance.registry.getService<UserManager>()
45-
val user = userManager.getUserOrNull(uuid)
46-
47-
if (user == null) {
46+
val user = userManager.getUserOrNull(uuid) ?: run {
4847
log.warning("Could not find user with UUID: ${uuid}")
4948
return null
5049
}
@@ -54,15 +53,15 @@ class LegacyDataMigrator {
5453

5554
/**
5655
* Logs a message with the specified level.
57-
*
56+
*
5857
* @param level The log level
5958
* @param message The message to log
6059
*/
6160
private fun log(level: Level, message: String) = log.log(level, message)
6261

6362
/**
6463
* Logs a message with the specified level and exception.
65-
*
64+
*
6665
* @param level The log level
6766
* @param message The message to log
6867
* @param exception The exception to log
@@ -71,7 +70,7 @@ class LegacyDataMigrator {
7170

7271
/**
7372
* Processes database records using a generic approach.
74-
*
73+
*
7574
* @param connection The database connection
7675
* @param query The SQL query to execute
7776
* @param recordType The type of records being processed (for logging)
@@ -98,35 +97,38 @@ class LegacyDataMigrator {
9897

9998
/**
10099
* Opens a database connection with the given URL.
101-
*
100+
*
102101
* @param url The JDBC URL
103102
* @param processor The function to process the connection
104103
*/
105-
private fun withConnection(url: String, processor: Consumer<Connection>) {
104+
private fun withConnection(url: String, processor: (Connection) -> Unit) {
106105
try {
107-
DriverManager.getConnection(url).use { processor.accept(it) }
106+
DriverManager.getConnection(url).use { processor(it) }
108107
} catch (exception: SQLException) {
109108
log(Level.SEVERE, "Error connecting to database: ${exception.message}", exception)
110109
}
111110
}
112111

113112
/**
114113
* Applies moderation to a user.
115-
*
114+
*
116115
* @param targetUuid The UUID of the target user
117116
* @param moderation The moderation to apply
118117
*/
119118
private fun applyModeration(targetUuid: UUID, moderation: AbstractModeration) {
120119
val user = getOfflineUser(targetUuid) ?: return
121120

122-
if (moderation is BanModeration) user.banManager.addModeration(moderation)
123-
if (moderation is MuteModeration) user.muteManager.addModeration(moderation)
121+
when (moderation) {
122+
is BanModeration -> user.banManager.addModeration(moderation)
123+
is MuteModeration -> user.muteManager.addModeration(moderation)
124+
}
124125
}
125126

127+
@Deprecated("This method is deprecated and will be removed in v4.4.0!")
126128
val isLegacyDataPresent: Boolean
127129
/**
128130
* Checks if legacy data is present that needs to be migrated.
129-
*
131+
*
130132
* @return true if legacy data is present, false otherwise
131133
*/
132134
get() {
@@ -143,10 +145,10 @@ class LegacyDataMigrator {
143145
if (verInt < 300) return true
144146

145147
val split = previousVersion.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
146-
previousVersion = split.joinToString { "." }.trim { it <= ' ' }
148+
previousVersion = split.joinToString { "." }.trim()
147149

148150
if (previousVersion.startsWith(".")) previousVersion = previousVersion.drop(1)
149-
if (previousVersion.endsWith(".")) previousVersion = previousVersion.substring(0, previousVersion.length - 1)
151+
if (previousVersion.endsWith(".")) previousVersion = previousVersion.dropLast(1)
150152
if (previousVersion.isEmpty()) return true
151153
} catch (_: NumberFormatException) {
152154
return true
@@ -158,6 +160,7 @@ class LegacyDataMigrator {
158160
/**
159161
* Prepares for migration by renaming the current data directory to a backup directory.
160162
*/
163+
@Deprecated("This method is deprecated and will be removed in v4.4.0!")
161164
fun prepareMigration() {
162165
val directory = instance.dataFolder
163166
if (!directory.exists()) return
@@ -170,6 +173,7 @@ class LegacyDataMigrator {
170173
/**
171174
* Migrates all legacy data.
172175
*/
176+
@Deprecated("This method is deprecated and will be removed in v4.4.0!")
173177
fun migrateLegacyData() {
174178
if (!_foundLegacyData) return
175179
migrateModerationAndEconomy()
@@ -187,8 +191,7 @@ class LegacyDataMigrator {
187191
val legacyKitsConfig = YamlConfiguration.loadConfiguration(legacyKitsFile)
188192
log(Level.INFO, "Legacy Kits Data detected. Migrating...")
189193

190-
val kitsSection = legacyKitsConfig.getConfigurationSection("Kits")
191-
if (kitsSection == null) {
194+
val kitsSection = legacyKitsConfig.getConfigurationSection("Kits") ?: run {
192195
log(Level.WARNING, "No kits found in legacy kits file")
193196
return
194197
}
@@ -264,21 +267,18 @@ class LegacyDataMigrator {
264267
val pitch = legacyWarpsConfig.getDouble("${prefix}.Pitch").toFloat()
265268
val worldName = legacyWarpsConfig.getString("${prefix}.World") ?: ""
266269

267-
val world = Bukkit.getWorld(worldName)
268-
if (world == null) {
270+
val world = Bukkit.getWorld(worldName) ?: run {
269271
log(Level.WARNING, "World '${worldName}' not found for warp '${warpName}', skipping")
270272
continue
271273
}
272274

273275
val location = Location(world, x, y, z, yaw, pitch)
274-
val warp = Warp.of(warpName, location)
275-
276-
if (warp == null) {
276+
val warp = Warp.of(warpName, location) ?: run {
277277
log(Level.WARNING, "Warp name '${warpName}' contains invalid characters, skipping")
278278
continue
279279
}
280280

281-
warpManager.addWarp(warp)
281+
warpManager.addPoint(warp)
282282
migratedCount++
283283
} catch (exception: Exception) {
284284
log(Level.WARNING, "Failed to migrate warp '${warpName}'", exception)
@@ -316,7 +316,7 @@ class LegacyDataMigrator {
316316

317317
/**
318318
* Migrates homes for a specific user.
319-
*
319+
*
320320
* @param uuid The UUID of the user
321321
* @param legacyHomesConfig The legacy homes configuration
322322
* @return The number of homes migrated
@@ -331,13 +331,12 @@ class LegacyDataMigrator {
331331

332332
for (homeName in homeNames) try {
333333
val location = legacyHomesConfig.getLocation("Homes.${homeName}") ?: continue
334-
val home = Home.of(homeName, location)
335-
if (home == null) {
334+
val home = Home.of(homeName, location) ?: run {
336335
log(Level.WARNING, "Home name '${homeName}' (${uuid}) contains invalid characters, skipping")
337336
continue
338337
}
339338

340-
user.homeManager.addHome(home)
339+
user.homeManager.addPoint(home)
341340
migratedCount++
342341
} catch (exception: Exception) {
343342
log(Level.WARNING, "Failed to migrate home '${homeName}' for ${uuid}: ${exception.message}", exception)
@@ -380,18 +379,18 @@ class LegacyDataMigrator {
380379

381380
/**
382381
* Migrates ban data from a SQLite file.
383-
*
382+
*
384383
* @param bansFile The SQLite file containing ban data
385384
*/
386385
private fun migrateBansFile(bansFile: File) {
387386
log(Level.INFO, "Migrating bans from legacy database: ${bansFile.absolutePath}")
388387
val url = "jdbc:sqlite:${bansFile.absolutePath}"
389-
withConnection(url) { connection -> processBanRecords(connection, "Sqlite Ban") }
388+
withConnection(url) { processBanRecords(it, "Sqlite Ban") }
390389
}
391390

392391
/**
393392
* Processes ban records from a database.
394-
*
393+
*
395394
* @param connection The database connection
396395
* @param recordType The type of records being processed (for logging)
397396
*/
@@ -417,7 +416,7 @@ class LegacyDataMigrator {
417416

418417
/**
419418
* Parses a sender UUID string, falling back to the console UUID if invalid.
420-
*
419+
*
421420
* @param senderUuidStr The sender UUID string to parse
422421
* @return The parsed UUID, or the console UUID if the input is invalid
423422
*/
@@ -432,7 +431,7 @@ class LegacyDataMigrator {
432431

433432
/**
434433
* Migrates mute data from a SQLite file.
435-
*
434+
*
436435
* @param mutesFile The SQLite file containing mute data
437436
*/
438437
private fun migrateMutesFile(mutesFile: File) {
@@ -443,7 +442,7 @@ class LegacyDataMigrator {
443442

444443
/**
445444
* Processes mute records from a database.
446-
*
445+
*
447446
* @param connection The database connection
448447
* @param recordType The type of records being processed (for logging)
449448
*/
@@ -470,7 +469,7 @@ class LegacyDataMigrator {
470469

471470
/**
472471
* Migrates economy data from a SQLite file.
473-
*
472+
*
474473
* @param economyFile The SQLite file containing economy data
475474
*/
476475
private fun migrateEconomyFile(economyFile: File) {
@@ -481,7 +480,7 @@ class LegacyDataMigrator {
481480

482481
/**
483482
* Processes economy records from a database.
484-
*
483+
*
485484
* @param connection The database connection
486485
* @param query The SQL query to execute
487486
* @param recordType The type of records being processed (for logging)
@@ -499,7 +498,7 @@ class LegacyDataMigrator {
499498

500499
/**
501500
* Migrates data from MySQL configuration.
502-
*
501+
*
503502
* @param legacyConfig The legacy configuration
504503
*/
505504
private fun migrateMySqlConfig(legacyConfig: FileConfiguration) {
@@ -527,7 +526,7 @@ class LegacyDataMigrator {
527526

528527
/**
529528
* Migrates data from H2 configuration.
530-
*
529+
*
531530
* @param legacyConfig The legacy configuration
532531
*/
533532
private fun migrateH2Config(legacyConfig: FileConfiguration) {
@@ -556,7 +555,7 @@ class LegacyDataMigrator {
556555

557556
/**
558557
* Migrates economy data from MySQL.
559-
*
558+
*
560559
* @param connection The database connection
561560
* @param serverName The server name to filter by
562561
*/
@@ -566,22 +565,22 @@ class LegacyDataMigrator {
566565

567566
/**
568567
* Migrates ban data from MySQL.
569-
*
568+
*
570569
* @param connection The database connection
571570
*/
572571
private fun migrateBansFromMySql(connection: Connection) = processBanRecords(connection, "MySQL ban")
573572

574573
/**
575574
* Migrates data from an H2 database file.
576-
*
575+
*
577576
* @param h2File The H2 database file
578577
* @param type The type of data to migrate
579578
*/
580579
private fun migrateH2(h2File: File, type: String) {
581580
log(Level.INFO, "Migrating ${type} from H2 database: ${h2File.absolutePath}")
582581

583582
var h2Path = h2File.absolutePath
584-
if (h2Path.endsWith(".h2.db")) h2Path = h2Path.substring(0, h2Path.length - 6) // Remove .h2.db extension
583+
if (h2Path.endsWith(".h2.db", true)) h2Path = h2Path.dropLast(6) // Remove .h2.db extension
585584

586585
val url = "jdbc:h2:file:${h2Path}"
587586

@@ -592,9 +591,9 @@ class LegacyDataMigrator {
592591
withConnection(url) { connection ->
593592
log(Level.INFO, "Successfully connected to H2 database.")
594593
when {
595-
type.equals("economy", ignoreCase = true) -> processEconomyRecords(connection, "SELECT * FROM Economy", "H2 economy")
596-
type.equals("bans", ignoreCase = true) -> processBanRecords(connection, "H2 ban")
597-
type.equals("mutes", ignoreCase = true) -> processMuteRecords(connection, "H2 mute")
594+
type.equals("economy", true) -> processEconomyRecords(connection, "SELECT * FROM Economy", "H2 economy")
595+
type.equals("bans", true) -> processBanRecords(connection, "H2 ban")
596+
type.equals("mutes", true) -> processMuteRecords(connection, "H2 mute")
598597
}
599598
}
600599
} catch (exception: ClassNotFoundException) {

src/main/kotlin/me/testaccount666/migration/plugins/MigratorRegistry.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package me.testaccount666.migration.plugins
22

33
import io.github.classgraph.ClassGraph
44
import me.testaccount666.serversystem.ServerSystem.Companion.log
5-
import java.util.Locale.getDefault
65
import java.util.logging.Level
76

87
class MigratorRegistry {
9-
private val _migrators: MutableMap<String, PluginMigrator> = HashMap()
8+
private val _migrators = HashMap<String, PluginMigrator>()
109

1110
fun registerMigrators() {
1211
ClassGraph()
@@ -18,14 +17,14 @@ class MigratorRegistry {
1817
val migrator = migratorClass.getConstructor().newInstance() as PluginMigrator
1918
val plugin = migrator.plugin ?: continue
2019

21-
_migrators[plugin.name.lowercase(getDefault())] = migrator
20+
_migrators[plugin.name.lowercase()] = migrator
2221
} catch (exception: Exception) {
2322
log.log(Level.WARNING, "Failed to register migrator '${migratorClass.name}'", exception)
2423
}
2524
}
2625
}
2726

28-
fun getMigrator(pluginName: String) = _migrators[pluginName.lowercase(getDefault())]
27+
fun getMigrator(pluginName: String) = _migrators[pluginName.lowercase()]
2928

3029
val migrators
3130
get() = _migrators.keys.toSet()

0 commit comments

Comments
 (0)