Skip to content

Commit 569bd41

Browse files
committed
Added PlaceholderAPI support, code cleanup
- Configuration -> Config - Added MissingConfigValueException
1 parent ed71cbc commit 569bd41

62 files changed

Lines changed: 760 additions & 323 deletions

File tree

Some content is hidden

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

doublejump-api/src/main/java/com/github/imdmk/doublejump/DoubleJumpApi.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.imdmk.doublejump;
22

3-
import com.github.imdmk.doublejump.configuration.ConfigurationManager;
3+
import com.github.imdmk.doublejump.config.ConfigManager;
44
import com.github.imdmk.doublejump.jump.cache.JumpPlayerCache;
55
import com.github.imdmk.doublejump.jump.feature.restriction.RestrictionChecker;
66
import com.github.imdmk.doublejump.jump.feature.visual.repository.JumpVisualCache;
@@ -23,17 +23,17 @@
2323
public interface DoubleJumpApi {
2424

2525
/**
26-
* Retrieves the {@link ConfigurationManager} responsible for loading,
26+
* Retrieves the {@link ConfigManager} responsible for loading,
2727
* parsing, and providing access to all plugin configuration files.
2828
* <p>
2929
* This manager provides methods to obtain current configuration values
3030
* and supports dynamic reloads if implemented.
3131
* </p>
3232
*
33-
* @return a non-null instance of {@link ConfigurationManager} used by the plugin.
33+
* @return a non-null instance of {@link ConfigManager} used by the plugin.
3434
*/
3535
@NotNull
36-
ConfigurationManager getConfigurationManager();
36+
ConfigManager getConfigurationManager();
3737

3838
/**
3939
* Returns the {@link JumpPlayerCache} containing runtime data for all active players
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.imdmk.doublejump.config;
2+
3+
public final class ConfigLoadException extends RuntimeException {
4+
public ConfigLoadException(Throwable cause) {
5+
super("Failed to load configuration", cause);
6+
}
7+
8+
public ConfigLoadException(String message) {
9+
super(message);
10+
}
11+
12+
public ConfigLoadException(String message, Throwable cause) {
13+
super(message, cause);
14+
}
15+
}

doublejump-api/src/main/java/com/github/imdmk/doublejump/configuration/ConfigurationManager.java renamed to doublejump-api/src/main/java/com/github/imdmk/doublejump/config/ConfigManager.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.github.imdmk.doublejump.configuration;
1+
package com.github.imdmk.doublejump.config;
22

3-
import eu.okaeri.configs.ConfigManager;
43
import eu.okaeri.configs.OkaeriConfig;
54
import eu.okaeri.configs.exception.OkaeriException;
65
import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer;
@@ -29,15 +28,15 @@
2928
* Supports asynchronous reload of all configs and tracks created config instances.
3029
* </p>
3130
*/
32-
public final class ConfigurationManager {
31+
public final class ConfigManager {
3332

3433
private final Set<ConfigSection> configs = ConcurrentHashMap.newKeySet();
3534

3635
private final Logger logger;
3736
private final File dataFolder;
3837
private final ExecutorService executor;
3938

40-
public ConfigurationManager(@NotNull Logger logger, @NotNull File dataFolder) {
39+
public ConfigManager(@NotNull Logger logger, @NotNull File dataFolder) {
4140
this.logger = Objects.requireNonNull(logger, "logger cannot be null");
4241
this.dataFolder = Objects.requireNonNull(dataFolder, "dataFolder cannot be null");
4342
this.executor = Executors.newSingleThreadExecutor();
@@ -54,7 +53,7 @@ public ConfigurationManager(@NotNull Logger logger, @NotNull File dataFolder) {
5453
* @return the created and loaded configuration instance
5554
*/
5655
public <T extends ConfigSection> T create(@NotNull Class<T> config) {
57-
T configFile = ConfigManager.create(config);
56+
T configFile = eu.okaeri.configs.ConfigManager.create(config);
5857
String fileName = configFile.getFileName();
5958

6059
if (fileName.isEmpty()) {
@@ -121,15 +120,15 @@ private void loadAll() {
121120
* If loading fails, logs the error and throws a runtime exception.
122121
*
123122
* @param config the configuration instance to load, must not be null
124-
* @throws ConfigurationLoadException if an error occurs during loading
123+
* @throws ConfigLoadException if an error occurs during loading
125124
*/
126125
public void load(@NotNull OkaeriConfig config) {
127126
try {
128127
config.load(true);
129128
}
130129
catch (OkaeriException exception) {
131130
this.logger.log(Level.SEVERE, "Failed to load config: " + config.getClass().getSimpleName(), exception);
132-
throw new ConfigurationLoadException(exception);
131+
throw new ConfigLoadException(exception);
133132
}
134133
}
135134

doublejump-api/src/main/java/com/github/imdmk/doublejump/configuration/ConfigSection.java renamed to doublejump-api/src/main/java/com/github/imdmk/doublejump/config/ConfigSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.imdmk.doublejump.configuration;
1+
package com.github.imdmk.doublejump.config;
22

33
import eu.okaeri.configs.OkaeriConfig;
44
import eu.okaeri.configs.exception.OkaeriException;

doublejump-api/src/main/java/com/github/imdmk/doublejump/configuration/CustomRepresenter.java renamed to doublejump-api/src/main/java/com/github/imdmk/doublejump/config/CustomRepresenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.imdmk.doublejump.configuration;
1+
package com.github.imdmk.doublejump.config;
22

33
import org.yaml.snakeyaml.DumperOptions;
44
import org.yaml.snakeyaml.nodes.Node;

doublejump-api/src/main/java/com/github/imdmk/doublejump/configuration/ConfigurationLoadException.java

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.imdmk.doublejump.event;
2+
3+
import org.bukkit.event.Event;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
/**
7+
* Interface representing a caller that can trigger Bukkit events.
8+
*/
9+
public interface EventCaller {
10+
11+
/**
12+
* Calls (fires) the given Bukkit event.
13+
*
14+
* @param event the event to be called; must not be null
15+
*/
16+
void callEvent(@NotNull Event event);
17+
}

doublejump-api/src/main/java/com/github/imdmk/doublejump/jump/JumpPlayer.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class JumpPlayer {
4040
private boolean jumpAllowed = true;
4141

4242
/**
43-
* Timestamp of the player's last performed jump.
43+
* Timestamp of the player's performed jump delay.
4444
* Used for applying cooldowns and delay-based restrictions.
4545
*/
46-
private Instant lastJump;
46+
private Instant nextAllowedJump;
4747

4848
/**
4949
* The last restriction reason that was notified to the player.
@@ -154,21 +154,23 @@ public void setJumpAllowed(boolean jumpAllowed) {
154154
}
155155

156156
/**
157-
* Gets the timestamp of the player's last jump, if present.
157+
* Gets the timestamp indicating when the player is next allowed to perform a jump.
158+
* This value is used to enforce cooldowns between jumps.
158159
*
159-
* @return an optional containing the last jump time, or empty if not set
160+
* @return an optional containing the next allowed jump time, or empty if not set
160161
*/
161-
public Optional<Instant> getLastJump() {
162-
return Optional.ofNullable(this.lastJump);
162+
public Optional<Instant> getNextAllowedJump() {
163+
return Optional.ofNullable(this.nextAllowedJump);
163164
}
164165

165166
/**
166-
* Sets the timestamp of the player's last jump.
167+
* Sets the timestamp after which the player is allowed to perform the next jump.
168+
* This is typically used to apply a cooldown delay.
167169
*
168-
* @param lastJump the time the last jump occurred
170+
* @param nextAllowedJump the time after which jumping is allowed again; may be null to clear
169171
*/
170-
public void setLastJump(@Nullable Instant lastJump) {
171-
this.lastJump = lastJump;
172+
public void setNextAllowedJump(@Nullable Instant nextAllowedJump) {
173+
this.nextAllowedJump = nextAllowedJump;
172174
}
173175

174176
/**
@@ -255,7 +257,7 @@ public String toString() {
255257
", activationType=" + this.activationType +
256258
", active=" + this.active +
257259
", jumpAllowed=" + this.jumpAllowed +
258-
", lastJump=" + this.lastJump +
260+
", nextAllowedJump=" + this.nextAllowedJump +
259261
", lastNotifiedReason=" + this.lastNotifiedReason +
260262
", jumpProperties=" + this.jumpVelocity +
261263
'}';

doublejump-api/src/main/java/com/github/imdmk/doublejump/jump/event/DoubleJumpEvent.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,24 @@ public final class DoubleJumpEvent extends Event implements Cancellable {
2929
* @param jumpPlayer The JumpPlayer data associated with the player.
3030
* @param jumpVelocity The jump properties (boosts) applied during this double jump.
3131
*/
32-
public DoubleJumpEvent(
33-
final @NotNull Player player,
34-
final @NotNull JumpPlayer jumpPlayer,
35-
final @NotNull JumpVelocity jumpVelocity) {
32+
public DoubleJumpEvent(final @NotNull Player player, final @NotNull JumpPlayer jumpPlayer, final @NotNull JumpVelocity jumpVelocity) {
3633
this.player = player;
3734
this.jumpPlayer = jumpPlayer;
3835
this.jumpVelocity = jumpVelocity;
3936
}
4037

38+
/**
39+
* Constructs a new DoubleJumpEvent.
40+
*
41+
* @param player The player who performed the double jump.
42+
* @param jumpPlayer The JumpPlayer data associated with the player.
43+
*/
44+
public DoubleJumpEvent(final @NotNull Player player, final @NotNull JumpPlayer jumpPlayer) {
45+
this.player = player;
46+
this.jumpPlayer = jumpPlayer;
47+
this.jumpVelocity = jumpPlayer.getJumpVelocity();
48+
}
49+
4150
@Override
4251
public @NotNull HandlerList getHandlers() {
4352
return HANDLERS;
@@ -75,7 +84,7 @@ public DoubleJumpEvent(
7584
*
7685
* @return The DoubleJumpProperties instance.
7786
*/
78-
public @NotNull JumpVelocity getJumpProperties() {
87+
public @NotNull JumpVelocity getJumpVelocity() {
7988
return this.jumpVelocity;
8089
}
8190

@@ -84,7 +93,7 @@ public DoubleJumpEvent(
8493
*
8594
* @param jumpVelocity The new jump properties.
8695
*/
87-
public void setJumpProperties(final @NotNull JumpVelocity jumpVelocity) {
96+
public void setJumpVelocity(@NotNull JumpVelocity jumpVelocity) {
8897
this.jumpVelocity = jumpVelocity;
8998
}
9099

@@ -94,7 +103,7 @@ public boolean isCancelled() {
94103
}
95104

96105
@Override
97-
public void setCancelled(final boolean cancel) {
106+
public void setCancelled(boolean cancel) {
98107
this.cancelled = cancel;
99108
}
100109
}

doublejump-plugin/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ version = "1.0.0"
1010
repositories {
1111
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") // SpigotMC
1212
maven("https://repo.eternalcode.pl/releases") // EternalCode
13-
maven("https://maven.enginehub.org/repo/") //World Guard API
13+
maven("https://maven.enginehub.org/repo/") // World Guard API
14+
maven("https://repo.extendedclip.com/releases/") // Placeholder API
1415
}
1516

1617
dependencies {
1718
implementation(project(":doublejump-api"))
1819

1920
compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")
2021
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.9")
22+
compileOnly("me.clip:placeholderapi:2.11.6")
2123

2224
implementation("com.zaxxer:HikariCP:6.2.1")
2325
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
@@ -46,7 +48,7 @@ bukkit {
4648
author = "imDMK"
4749
description = "Game-changing double jump mechanics. Feels native. Lag-free performance."
4850
website = "https://github.com/imDMK/DoubleJump"
49-
softDepend = listOf("WorldGuard")
51+
softDepend = listOf("WorldGuard", "PlaceholderAPI")
5052
}
5153

5254
tasks.withType<ShadowJar> {

0 commit comments

Comments
 (0)