fmpp initial
+ Fmpp.kt
+ FMPPCommand.kt
+ plugin.yml
+ pom.xml
This commit is contained in:
113
.gitignore
vendored
Normal file
113
.gitignore
vendored
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
87
pom.xml
Normal file
87
pom.xml
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.fmpp</groupId>
|
||||||
|
<artifactId>fmpp</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>fmpp</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>21</java.version>
|
||||||
|
<kotlin.version>2.2.0-Beta2</kotlin.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>${java.version}</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.5.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc-repo</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.21.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
80
src/main/kotlin/org/fmpp/fmpp/FMPPCommand.kt
Normal file
80
src/main/kotlin/org/fmpp/fmpp/FMPPCommand.kt
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package org.fmpp.fmpp
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor
|
||||||
|
import org.bukkit.command.Command
|
||||||
|
import org.bukkit.command.CommandExecutor
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.entity.minecart.PoweredMinecart
|
||||||
|
|
||||||
|
class FMPPCommand(private val plugin: Fmpp) : CommandExecutor {
|
||||||
|
|
||||||
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||||
|
if (sender !is Player) {
|
||||||
|
sender.sendMessage("${ChatColor.RED}This command can only be used by players.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
showHelp(sender)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
when (args[0].lowercase()) {
|
||||||
|
"boost" -> boostMinecart(sender)
|
||||||
|
"fuel" -> refuelMinecart(sender)
|
||||||
|
"stop" -> stopMinecart(sender)
|
||||||
|
"help" -> showHelp(sender)
|
||||||
|
else -> {
|
||||||
|
sender.sendMessage("${ChatColor.RED}Unknown command. Use /fmpp help for a list of commands.")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun boostMinecart(player: Player) {
|
||||||
|
val vehicle = player.vehicle
|
||||||
|
|
||||||
|
if (vehicle is PoweredMinecart) {
|
||||||
|
// Boost the minecart in the direction it's facing
|
||||||
|
val direction = vehicle.location.direction.setY(0).normalize()
|
||||||
|
vehicle.velocity = vehicle.velocity.add(direction.multiply(0.5))
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Minecart boosted!")
|
||||||
|
} else {
|
||||||
|
player.sendMessage("${ChatColor.RED}You must be in a furnace minecart to use this command.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun refuelMinecart(player: Player) {
|
||||||
|
val vehicle = player.vehicle
|
||||||
|
|
||||||
|
if (vehicle is PoweredMinecart) {
|
||||||
|
vehicle.fuel = 3600 // Set to max fuel
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Minecart refueled!")
|
||||||
|
} else {
|
||||||
|
player.sendMessage("${ChatColor.RED}You must be in a furnace minecart to use this command.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopMinecart(player: Player) {
|
||||||
|
val vehicle = player.vehicle
|
||||||
|
|
||||||
|
if (vehicle is PoweredMinecart) {
|
||||||
|
vehicle.velocity = vehicle.velocity.multiply(0.1)
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}Minecart slowed down!")
|
||||||
|
} else {
|
||||||
|
player.sendMessage("${ChatColor.RED}You must be in a furnace minecart to use this command.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showHelp(player: Player) {
|
||||||
|
player.sendMessage("${ChatColor.GOLD}===== FurnaceMinecart++ Commands =====")
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}/fmpp boost ${ChatColor.WHITE}- Gives your minecart a speed boost")
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}/fmpp fuel ${ChatColor.WHITE}- Refills your minecart's fuel")
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}/fmpp stop ${ChatColor.WHITE}- Slows down your minecart")
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}/fmpp help ${ChatColor.WHITE}- Shows this help message")
|
||||||
|
player.sendMessage("${ChatColor.GOLD}==================================")
|
||||||
|
}
|
||||||
|
}
|
||||||
169
src/main/kotlin/org/fmpp/fmpp/Fmpp.kt
Normal file
169
src/main/kotlin/org/fmpp/fmpp/Fmpp.kt
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
package org.fmpp.fmpp
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor
|
||||||
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.entity.EntityType
|
||||||
|
import org.bukkit.entity.Minecart
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.entity.minecart.PoweredMinecart
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.vehicle.VehicleCreateEvent
|
||||||
|
import org.bukkit.event.vehicle.VehicleEnterEvent
|
||||||
|
import org.bukkit.event.vehicle.VehicleMoveEvent
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
import org.bukkit.util.Vector
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
class Fmpp : JavaPlugin() {
|
||||||
|
|
||||||
|
override fun onEnable() {
|
||||||
|
logger.info("${ChatColor.GREEN}FurnaceMinecart++ is now enabled!")
|
||||||
|
server.pluginManager.registerEvents(FMPPListener(this), this)
|
||||||
|
|
||||||
|
// Register command for controlling furnace minecarts
|
||||||
|
getCommand("fmpp")?.setExecutor(FMPPCommand(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDisable() {
|
||||||
|
logger.info("${ChatColor.RED}FurnaceMinecart++ is now disabled!")
|
||||||
|
}
|
||||||
|
|
||||||
|
class FMPPListener(private val plugin: Fmpp) : Listener {
|
||||||
|
|
||||||
|
// Track enhanced minecarts
|
||||||
|
private val enhancedMinecarts = mutableSetOf<PoweredMinecart>()
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onVehicleCreate(event: VehicleCreateEvent) {
|
||||||
|
val vehicle = event.vehicle
|
||||||
|
if (vehicle is PoweredMinecart) {
|
||||||
|
enhanceMinecart(vehicle)
|
||||||
|
plugin.logger.info("Enhanced a new furnace minecart!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onVehicleEnter(event: VehicleEnterEvent) {
|
||||||
|
val vehicle = event.vehicle
|
||||||
|
val entity = event.entered
|
||||||
|
|
||||||
|
if (vehicle is PoweredMinecart && entity is Player) {
|
||||||
|
entity.sendMessage("${ChatColor.GOLD}This is an enhanced FurnaceMinecart++!")
|
||||||
|
entity.sendMessage("${ChatColor.YELLOW}Use WASD to control direction and speed.")
|
||||||
|
|
||||||
|
if (!enhancedMinecarts.contains(vehicle)) {
|
||||||
|
enhanceMinecart(vehicle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
fun onVehicleMove(event: VehicleMoveEvent) {
|
||||||
|
val vehicle = event.vehicle
|
||||||
|
|
||||||
|
if (vehicle is PoweredMinecart && enhancedMinecarts.contains(vehicle)) {
|
||||||
|
val passenger = vehicle.passengers.firstOrNull()
|
||||||
|
|
||||||
|
if (passenger is Player) {
|
||||||
|
handlePlayerControl(vehicle, passenger)
|
||||||
|
} else {
|
||||||
|
// Maintain momentum for empty carts
|
||||||
|
if (vehicle.velocity.lengthSquared() > 0.01) {
|
||||||
|
// Reduce slowdown factor
|
||||||
|
val currentVelocity = vehicle.velocity
|
||||||
|
if (currentVelocity.lengthSquared() > 0.01) {
|
||||||
|
vehicle.velocity = currentVelocity.multiply(0.99)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handlePlayerControl(minecart: PoweredMinecart, player: Player) {
|
||||||
|
// Get player's looking direction as a reference
|
||||||
|
val direction = player.location.direction.setY(0).normalize()
|
||||||
|
val rightVector = Vector(-direction.z, 0.0, direction.x).normalize()
|
||||||
|
|
||||||
|
// Calculate desired velocity based on player's input
|
||||||
|
var velocity = Vector(0, 0, 0)
|
||||||
|
|
||||||
|
// Forward/backward
|
||||||
|
if (player.isSneaking) {
|
||||||
|
// Brake
|
||||||
|
minecart.velocity = minecart.velocity.multiply(0.9)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
// Check if player is pressing movement keys
|
||||||
|
val moveForward = when {
|
||||||
|
isMovingForward(player) -> 0.1
|
||||||
|
isMovingBackward(player) -> -0.05
|
||||||
|
else -> 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply forward/backward momentum
|
||||||
|
if (moveForward != 0.0) {
|
||||||
|
velocity = velocity.add(direction.multiply(moveForward))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left/right steering
|
||||||
|
val moveStrafing = when {
|
||||||
|
isMovingLeft(player) -> -0.02
|
||||||
|
isMovingRight(player) -> 0.02
|
||||||
|
else -> 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply left/right steering
|
||||||
|
if (moveStrafing != 0.0) {
|
||||||
|
velocity = velocity.add(rightVector.multiply(moveStrafing))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only change velocity if we have input
|
||||||
|
if (velocity.lengthSquared() > 0.001) {
|
||||||
|
// Set new velocity, preserving some of the existing momentum
|
||||||
|
val currentVel = minecart.velocity
|
||||||
|
minecart.velocity = currentVel.multiply(0.8).add(velocity)
|
||||||
|
|
||||||
|
// Set fuel level to ensure minecart stays active
|
||||||
|
minecart.fuel = 3600 // Max fuel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun enhanceMinecart(minecart: PoweredMinecart) {
|
||||||
|
// Increase base speed
|
||||||
|
minecart.maxSpeed = 0.6 // Default is 0.4
|
||||||
|
|
||||||
|
// Add to tracked minecarts
|
||||||
|
enhancedMinecarts.add(minecart)
|
||||||
|
|
||||||
|
// Set initial fuel
|
||||||
|
minecart.fuel = 3600
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods to detect player movement
|
||||||
|
private fun isMovingForward(player: Player): Boolean {
|
||||||
|
return player.velocity.length() > 0.01 &&
|
||||||
|
abs(player.location.direction.dot(player.velocity.clone().setY(0).normalize())) > 0.7
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isMovingBackward(player: Player): Boolean {
|
||||||
|
return player.velocity.length() > 0.01 &&
|
||||||
|
player.location.direction.dot(player.velocity.clone().setY(0).normalize()) < -0.7
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isMovingLeft(player: Player): Boolean {
|
||||||
|
val direction = player.location.direction.setY(0).normalize()
|
||||||
|
val rightVector = Vector(-direction.z, 0.0, direction.x).normalize()
|
||||||
|
return player.velocity.length() > 0.01 &&
|
||||||
|
rightVector.dot(player.velocity.clone().setY(0).normalize()) < -0.7
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isMovingRight(player: Player): Boolean {
|
||||||
|
val direction = player.location.direction.setY(0).normalize()
|
||||||
|
val rightVector = Vector(-direction.z, 0.0, direction.x).normalize()
|
||||||
|
return player.velocity.length() > 0.01 &&
|
||||||
|
rightVector.dot(player.velocity.clone().setY(0).normalize()) > 0.7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/main/resources/plugin.yml
Normal file
18
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
name: FurnaceMinecartPP
|
||||||
|
version: 1.0-SNAPSHOT
|
||||||
|
main: org.fmpp.fmpp.Fmpp
|
||||||
|
api-version: 1.21
|
||||||
|
description: Enhances Furnace Minecart functionality with better control and performance
|
||||||
|
author: YourName
|
||||||
|
website: https://example.com
|
||||||
|
|
||||||
|
commands:
|
||||||
|
fmpp:
|
||||||
|
description: Control your enhanced Furnace Minecart
|
||||||
|
usage: /fmpp [boost|fuel|stop|help]
|
||||||
|
permission: fmpp.use
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
fmpp.use:
|
||||||
|
description: Allows players to use FurnaceMinecart++ commands
|
||||||
|
default: true
|
||||||
Reference in New Issue
Block a user