diff --git a/README.md b/README.md
index 012c59d..4e86922 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
-# FastMinecarts Plugin
+# SuperExpress Plugin
[](https://github.com/0x002500/superExpress/actions/workflows/maven.yml)

-Simple plugin for Minecraft [Paper](https://papermc.io) servers that changes the speed of minecarts depending on the block beneath the rails.
+Simple plugin for Minecraft [Folia](https://papermc.io/software/folia) servers that changes the speed of minecarts depending on the block beneath the rails.
## Features
- Configure which blocks affect speed.
@@ -10,7 +10,7 @@ Simple plugin for Minecraft [Paper](https://papermc.io) servers that changes the
- Slow minecarts back to vanilla speed when player disembarks.
## Installation
To install FastMinecarts, follow these steps:
-1. Download the plugin JAR file from [Modrinth](https://modrinth.com/plugin/#####) or the [Releases](https://github.com/certainly1182/FastMinecarts/releases) page.
+1. Download the plugin JAR file from [Modrinth](https://modrinth.com/plugin/superexpress) or the [Releases](https://github.com/0x002500/superExpress/releases) page.
2. Place the JAR file in the plugins folder of your Paper (or Paper fork) server.
3. Start the server and verify that the plugin loaded successfully.
## Configuration
diff --git a/pom.xml b/pom.xml
index e403810..ce64c0d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
top.godbranch
superExpress
- 1.0-SNAPSHOT
+ 1.0
jar
SuperExpress
diff --git a/src/main/java/top/godbranch/superExpress/FastMinecarts.kt b/src/main/java/top/godbranch/superExpress/FastMinecarts.kt
index 3e2c409..d14f327 100644
--- a/src/main/java/top/godbranch/superExpress/FastMinecarts.kt
+++ b/src/main/java/top/godbranch/superExpress/FastMinecarts.kt
@@ -1,7 +1,5 @@
package top.godbranch.superExpress
-import net.kyori.adventure.text.Component
-import net.kyori.adventure.text.format.NamedTextColor
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.entity.Minecart
@@ -11,23 +9,29 @@ import org.bukkit.event.Listener
import org.bukkit.event.vehicle.VehicleExitEvent
import org.bukkit.event.vehicle.VehicleMoveEvent
import org.bukkit.plugin.java.JavaPlugin
-import org.bukkit.scheduler.BukkitRunnable
class FastMinecarts : JavaPlugin(), Listener {
+ // Define the default maximum speed for minecarts
private val vanillaMaxSpeed = 0.4
+ // Store the maximum speeds for different block types
private var _blockMaxSpeeds = mutableMapOf()
+ // Define the types of rail blocks
private val railTypes = listOf(
Material.RAIL, Material.POWERED_RAIL,
Material.DETECTOR_RAIL, Material.ACTIVATOR_RAIL
)
- private val playerActionBarTasks = mutableMapOf()
+ // Called when the plugin is enabled
override fun onEnable() {
+ // Save the default configuration file
saveDefaultConfig()
+ // Load the data from the configuration file
loadConfig()
+ // Register the event listener
Bukkit.getPluginManager().registerEvents(this, this)
}
+ // Load data from the configuration file
private fun loadConfig() {
val blockConfig = config.getConfigurationSection("blocks") ?: return
_blockMaxSpeeds.clear()
@@ -39,6 +43,7 @@ class FastMinecarts : JavaPlugin(), Listener {
}
}
+ // Handle minecart movement events
@EventHandler(ignoreCancelled = true)
fun onVehicleMove(event: VehicleMoveEvent) {
if (event.vehicle !is Minecart) return
@@ -53,37 +58,13 @@ class FastMinecarts : JavaPlugin(), Listener {
val blockBelow = railBlock.getRelative(0, -1, 0)
val blockMultiplier = _blockMaxSpeeds[blockBelow.type] ?: vanillaMaxSpeed
- // Update minecart speed on the main thread
+ // Use Folia's scheduler to update the minecart speed on the main thread
FoliaScheduler.callSyncMethod(this) {
minecart.maxSpeed = blockMultiplier
}
- val velocity = minecart.velocity
- // Send long-term action bar message
- displayMinecartsSpeed(minecart.passengers.first() as Player, "Speed: ${velocity.length()}", 100) // Display for 5 seconds
- }
-
- private fun displayMinecartsSpeed(player: Player, message: String, durationTicks: Long) {
- playerActionBarTasks[player]?.cancel()
-
- val runnable = object : BukkitRunnable() {
- var ticksLeft = durationTicks
-
- override fun run() {
- if (ticksLeft <= 0) {
- cancel()
- playerActionBarTasks.remove(player)
- return
- }
-
- player.sendActionBar(Component.text(message, NamedTextColor.YELLOW))
- ticksLeft -= 20
- }
- }
-
- runnable.runTaskTimer(this, 0, 20)
- playerActionBarTasks[player] = runnable
}
+ // Handle player exiting the minecart events
@EventHandler(ignoreCancelled = true)
fun onVehicleExit(event: VehicleExitEvent) {
if (event.vehicle !is Minecart) return
@@ -91,15 +72,15 @@ class FastMinecarts : JavaPlugin(), Listener {
val minecart = event.vehicle as Minecart
if (minecart.maxSpeed > vanillaMaxSpeed) {
- // Reset minecart speed on the main thread
+ // Use Folia's scheduler to reset the minecart speed on the main thread
FoliaScheduler.callSyncMethod(this) {
minecart.maxSpeed = vanillaMaxSpeed
}
}
}
+ // Folia scheduler object for executing tasks on the main thread
object FoliaScheduler {
- // Ensure tasks are executed on the main thread
fun callSyncMethod(plugin: JavaPlugin, task: () -> Unit) {
if (Bukkit.isPrimaryThread()) {
task()
@@ -109,4 +90,3 @@ class FastMinecarts : JavaPlugin(), Listener {
}
}
}
-