-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alex2276564
committed
Oct 11, 2024
1 parent
6607223
commit e399dc8
Showing
5 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
package uz.alex2276564.leverlock; | ||
|
||
import lombok.Getter; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import uz.alex2276564.leverlock.commands.ReloadCommand; | ||
import uz.alex2276564.leverlock.listeners.PlayerLeverClickListener; | ||
import uz.alex2276564.leverlock.utils.ConfigManager; | ||
|
||
public final class LeverLock extends JavaPlugin { | ||
private PlayerLeverClickListener leverClickListener; | ||
@Getter | ||
private static LeverLock instance; | ||
|
||
@Override | ||
public void onEnable() { | ||
saveDefaultConfig(); | ||
leverClickListener = new PlayerLeverClickListener(this); | ||
getServer().getPluginManager().registerEvents(leverClickListener, this); | ||
getCommand("leverlockreload").setExecutor(new ReloadCommand(this)); | ||
instance = this; | ||
registerListeners(); | ||
registerCommands(); | ||
loadUtils(); | ||
} | ||
|
||
public void reloadListenerConfig() { | ||
leverClickListener.reloadConfig(); | ||
private void registerListeners() { | ||
getServer().getPluginManager().registerEvents(new PlayerLeverClickListener(this), this); | ||
} | ||
|
||
private void registerCommands() { | ||
getCommand("leverlockreload").setExecutor(new ReloadCommand()); | ||
} | ||
|
||
private void loadUtils() { | ||
ConfigManager.reload(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/uz/alex2276564/leverlock/utils/ConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uz.alex2276564.leverlock.utils; | ||
|
||
import lombok.Getter; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.plugin.Plugin; | ||
import uz.alex2276564.leverlock.LeverLock; | ||
|
||
import java.time.Duration; | ||
|
||
public class ConfigManager { | ||
private static FileConfiguration config; | ||
@Getter | ||
private static Duration cooldownDuration; | ||
@Getter | ||
private static long cleanupInterval; | ||
@Getter | ||
private static String cooldownMessage; | ||
|
||
public static void reload() { | ||
Plugin plugin = LeverLock.getInstance(); | ||
|
||
plugin.saveDefaultConfig(); | ||
plugin.reloadConfig(); | ||
config = plugin.getConfig(); | ||
loadConfig(); | ||
} | ||
|
||
public static void loadConfig() { | ||
cooldownDuration = Duration.ofSeconds(config.getLong("cooldown.duration", 1)); | ||
cleanupInterval = config.getLong("cleanup.interval", 300) * 20; // convert to ticks | ||
cooldownMessage = config.getString("message.cooldown", "§cYou are interacting with the lever too quickly!"); | ||
} | ||
|
||
private ConfigManager() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
} |