better features!
This commit is contained in:
@@ -12,6 +12,7 @@ import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.block.Action
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.inventory.ItemFlag
|
||||
import org.bukkit.inventory.ItemStack
|
||||
@@ -20,11 +21,13 @@ import org.bukkit.plugin.java.JavaPlugin
|
||||
import org.bukkit.potion.PotionEffect
|
||||
import org.bukkit.potion.PotionEffectType
|
||||
import java.util.UUID
|
||||
import java.util.HashMap
|
||||
|
||||
class Leaper : JavaPlugin(), Listener {
|
||||
private val LEAPER_KEY = "leaper_item"
|
||||
private lateinit var leaperKey: NamespacedKey
|
||||
private val cooldowns = HashMap<UUID, Long>()
|
||||
private val fallProtection = HashMap<UUID, Long>()
|
||||
|
||||
// Configurable settings
|
||||
private var cooldownTime = 5 * 1000 // Default: 5 seconds in milliseconds
|
||||
@@ -37,6 +40,8 @@ class Leaper : JavaPlugin(), Listener {
|
||||
private var soundEffect = Sound.ENTITY_RABBIT_JUMP // Default: rabbit jump sound
|
||||
private var soundVolume = 1.0f // Default: 100% volume
|
||||
private var soundPitch = 1.0f // Default: normal pitch
|
||||
private var fallDamageProtectionTime = 5 * 1000 // Default: 5 seconds fall protection
|
||||
private var fallDamageReduction = 1.0 // Default: 100% reduction (0.0 to 1.0)
|
||||
|
||||
override fun onEnable() {
|
||||
// Save default config if it doesn't exist
|
||||
@@ -71,6 +76,12 @@ class Leaper : JavaPlugin(), Listener {
|
||||
jumpBoostDuration = config.getInt("settings.jump-boost-duration", 20)
|
||||
jumpBoostAmplifier = config.getInt("settings.jump-boost-amplifier", 1)
|
||||
|
||||
// Load fall damage settings
|
||||
fallDamageProtectionTime = config.getInt("settings.fall-protection-duration", 5) * 1000
|
||||
fallDamageReduction = config.getDouble("settings.fall-damage-reduction", 1.0)
|
||||
if (fallDamageReduction < 0.0) fallDamageReduction = 0.0
|
||||
if (fallDamageReduction > 1.0) fallDamageReduction = 1.0
|
||||
|
||||
// Load particle settings
|
||||
val particleTypeName = config.getString("effects.particle-type", "CLOUD")
|
||||
try {
|
||||
@@ -133,12 +144,21 @@ class Leaper : JavaPlugin(), Listener {
|
||||
val meta = leaper.itemMeta
|
||||
|
||||
meta?.setDisplayName("${ChatColor.AQUA}${ChatColor.BOLD}The Leaper")
|
||||
meta?.lore = listOf(
|
||||
"${ChatColor.GRAY}A magical foot that grants you the ability to leap!",
|
||||
"${ChatColor.YELLOW}Right-click to jump forward",
|
||||
|
||||
val loreList = mutableListOf(
|
||||
"${ChatColor.GRAY}Simon Brunauer's Fetter Haxen",
|
||||
"${ChatColor.YELLOW}Rechts Klick um zu Leapen",
|
||||
"${ChatColor.RED}Cooldown: ${cooldownTime / 1000} seconds"
|
||||
)
|
||||
|
||||
// Add fall protection info if enabled
|
||||
if (fallDamageProtectionTime > 0 && fallDamageReduction > 0) {
|
||||
val reductionPercent = (fallDamageReduction * 100).toInt()
|
||||
loreList.add("${ChatColor.GREEN}Reduces fall damage by $reductionPercent% for ${fallDamageProtectionTime / 1000} seconds after leap")
|
||||
}
|
||||
|
||||
meta?.lore = loreList
|
||||
|
||||
// Add item flags to hide enchantments/attributes
|
||||
meta?.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS)
|
||||
|
||||
@@ -179,6 +199,62 @@ class Leaper : JavaPlugin(), Listener {
|
||||
|
||||
// Set cooldown
|
||||
cooldowns[playerUUID] = currentTime
|
||||
|
||||
// Set fall protection
|
||||
if (fallDamageProtectionTime > 0 && fallDamageReduction > 0) {
|
||||
fallProtection[playerUUID] = currentTime
|
||||
|
||||
// Visual indicator for fall protection
|
||||
player.world.spawnParticle(
|
||||
Particle.BUBBLE_POP,
|
||||
player.location,
|
||||
15,
|
||||
0.5, 0.2, 0.5,
|
||||
0.05
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onEntityDamage(event: EntityDamageEvent) {
|
||||
// Check if it's a player taking fall damage
|
||||
if (event.entity !is Player || event.cause != EntityDamageEvent.DamageCause.FALL) {
|
||||
return
|
||||
}
|
||||
|
||||
val player = event.entity as Player
|
||||
val playerUUID = player.uniqueId
|
||||
val currentTime = System.currentTimeMillis()
|
||||
|
||||
// Check if player has fall protection
|
||||
if (fallProtection.containsKey(playerUUID)) {
|
||||
val protectionTime = currentTime - fallProtection[playerUUID]!!
|
||||
|
||||
if (protectionTime < fallDamageProtectionTime) {
|
||||
// Calculate reduced damage
|
||||
val originalDamage = event.damage
|
||||
val reducedDamage = originalDamage * (1.0 - fallDamageReduction)
|
||||
|
||||
// Apply the reduced damage
|
||||
if (reducedDamage <= 0) {
|
||||
event.isCancelled = true
|
||||
|
||||
// Visual effect for damage negation
|
||||
player.world.spawnParticle(
|
||||
Particle.CLOUD,
|
||||
player.location,
|
||||
10,
|
||||
0.3, 0.1, 0.3,
|
||||
0.05
|
||||
)
|
||||
|
||||
// Play a soft landing sound
|
||||
player.world.playSound(player.location, Sound.BLOCK_WOOL_FALL, 0.5f, 1.2f)
|
||||
} else {
|
||||
event.damage = reducedDamage
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,16 @@ settings:
|
||||
# Amplifier for jump boost effect (0 = level 1, 1 = level 2, etc.)
|
||||
jump-boost-amplifier: 1
|
||||
|
||||
# Fall damage protection settings
|
||||
# Duration in seconds (0 to disable)
|
||||
fall-protection-duration: 5
|
||||
|
||||
# Fall damage reduction (0.0 to 1.0)
|
||||
# 1.0 = 100% reduction (no fall damage)
|
||||
# 0.5 = 50% reduction
|
||||
# 0.0 = no reduction
|
||||
fall-damage-reduction: 1.0
|
||||
|
||||
# Visual and sound effects
|
||||
effects:
|
||||
# Particle effect type
|
||||
|
||||
@@ -3,15 +3,24 @@ version: 1.0-SNAPSHOT
|
||||
main: org.leaper.leaper.Leaper
|
||||
api-version: 1.21
|
||||
description: A plugin that adds a special leaping item
|
||||
author: YourName
|
||||
author: rattatwinko
|
||||
|
||||
commands:
|
||||
getleaper:
|
||||
description: Get the Leaper item
|
||||
usage: /getleaper
|
||||
permission: leaper.get
|
||||
permission-message: You don't have permission to use this command.
|
||||
reloadleaper:
|
||||
description: Reload the Leaper plugin configuration
|
||||
usage: /reloadleaper
|
||||
permission: leaper.admin
|
||||
permission-message: You don't have permission to use this command.
|
||||
|
||||
permissions:
|
||||
leaper.get:
|
||||
description: Allows players to get the Leaper item
|
||||
default: true
|
||||
default: true
|
||||
leaper.admin:
|
||||
description: Allows administrators to reload the plugin configuration
|
||||
default: op
|
||||
Reference in New Issue
Block a user