-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
acedc8c
commit 3640bf3
Showing
2 changed files
with
77 additions
and
81 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
70 changes: 33 additions & 37 deletions
70
src/main/java/net/simplyvanilla/simplyheightlimit/SimplyHeightLimit.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 |
---|---|---|
@@ -1,61 +1,57 @@ | ||
package net.simplyvanilla.simplyheightlimit; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.logging.Level; | ||
|
||
public final class SimplyHeightLimit extends JavaPlugin { | ||
|
||
private FileConfiguration config; | ||
private FileConfiguration config; | ||
|
||
@Override | ||
public void onEnable() { | ||
@Override | ||
public void onEnable() { | ||
|
||
initConfig(); | ||
initLimiter(); | ||
} | ||
initConfig(); | ||
initLimiter(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
// Plugin shutdown logic | ||
} | ||
@Override | ||
public void onDisable() { | ||
// Plugin shutdown logic | ||
} | ||
|
||
private void initLimiter() { | ||
HeightLimiter limiter; | ||
private void initLimiter() { | ||
HeightLimiter limiter; | ||
|
||
int maxHeight = config.getInt("limit"); | ||
double damage = config.getDouble("damage"); | ||
double intervalSeconds = config.getDouble("interval"); | ||
int maxHeight = config.getInt("limit"); | ||
double damage = config.getDouble("damage"); | ||
double intervalSeconds = config.getDouble("interval"); | ||
|
||
int intervalTicks = (int) (20.0 * intervalSeconds); // Converting seconds to ticks | ||
int intervalTicks = (int) (20.0 * intervalSeconds); // Converting seconds to ticks | ||
|
||
limiter = new HeightLimiter(maxHeight, intervalTicks, damage, this); | ||
limiter.startAsyncChecking(); | ||
} | ||
limiter = new HeightLimiter(maxHeight, intervalTicks, damage, this); | ||
limiter.startAsyncChecking(); | ||
} | ||
|
||
private void initConfig() { | ||
this.config = loadConfig(); | ||
} | ||
private void initConfig() { | ||
this.config = loadConfig(); | ||
} | ||
|
||
private FileConfiguration loadConfig() { | ||
File dataFolder = getDataFolder(); | ||
private FileConfiguration loadConfig() { | ||
File dataFolder = getDataFolder(); | ||
|
||
if (!dataFolder.exists()) { | ||
dataFolder.mkdirs(); | ||
} | ||
if (!dataFolder.exists()) { | ||
dataFolder.mkdirs(); | ||
} | ||
|
||
File configFile = new File(dataFolder, "config.yml"); | ||
File configFile = new File(dataFolder, "config.yml"); | ||
|
||
if (!configFile.exists()) { | ||
this.saveResource("config.yml", false); | ||
} | ||
if (!configFile.exists()) { | ||
this.saveResource("config.yml", false); | ||
} | ||
|
||
return YamlConfiguration.loadConfiguration(configFile); | ||
} | ||
return YamlConfiguration.loadConfiguration(configFile); | ||
} | ||
} |