Files
src
pom.xml
README.md
Code
9 549
src/main/java/com/badumoh4ik/jumpboost/JumpBoostPlugin.java
package com.badumoh4ik.jumpboost;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* Entry point for the JumpBoost plugin.
*/
public final class JumpBoostPlugin extends JavaPlugin {
private final ConcurrentHashMap<UUID, Long> lastJumpTimes = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, Boolean> originalAllowFlight = new ConcurrentHashMap<>();
private JumpBoostSettings settings;
@Override
public void onEnable() {
saveDefaultConfig();
settings = new JumpBoostSettings(this);
settings.reload();
getServer().getPluginManager().registerEvents(new JumpBoostListener(this), this);
JumpBoostCommand command = new JumpBoostCommand(this);
if (getCommand("jumpboost") != null) {
getCommand("jumpboost").setExecutor(command);
getCommand("jumpboost").setTabCompleter(command);
}
syncFlightAccess();
}
@Override
public void onDisable() {
for (Player player : Bukkit.getOnlinePlayers()) {
restoreFlightAccess(player);
}
lastJumpTimes.clear();
}
/**
* Reloads the configuration and immediately applies the enabled state to online players.
*/
public void reloadPluginConfig() {
reloadConfig();
settings.reload();
syncFlightAccess();
}
public JumpBoostSettings settings() {
return settings;
}
public void prepareFlightAccess(Player player) {
if (!settings.isMechanicActive()) {
return;
}
originalAllowFlight.putIfAbsent(player.getUniqueId(), player.getAllowFlight());
player.setAllowFlight(true);
}
public void restoreFlightAccess(Player player) {
Boolean previousValue = originalAllowFlight.remove(player.getUniqueId());
if (previousValue != null) {
player.setAllowFlight(previousValue);
}
lastJumpTimes.remove(player.getUniqueId());
}
/**
* Records a jump if the player's cooldown has elapsed.
*
* @return true when the jump may be performed
*/
public boolean tryUseCooldown(UUID playerId, double cooldownSeconds) {
if (cooldownSeconds <= 0.0) {
return true;
}
long now = System.nanoTime();
long cooldownNanos = (long) (cooldownSeconds * 1_000_000_000L);
Long previousJump = lastJumpTimes.get(playerId);
if (previousJump != null && now - previousJump < cooldownNanos) {
return false;
}
lastJumpTimes.put(playerId, now);
return true;
}
private void syncFlightAccess() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (settings.isMechanicActive()) {
prepareFlightAccess(player);
} else {
restoreFlightAccess(player);
}
}
}
}