Skip to content

Commit

Permalink
fix indent (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Netherwhal authored Jun 22, 2023
1 parent acedc8c commit 3640bf3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,51 @@

public class HeightLimiter {

private final int maxHeight;
private final JavaPlugin plugin;
private final int period;
private final double damage;

public HeightLimiter(int maxHeight, int period, double damage, JavaPlugin plugin) {
this.maxHeight = maxHeight;
this.plugin = plugin;
this.period = period;
this.damage = damage;
}

public void checkHeightOnAll() {
var players = Bukkit.getOnlinePlayers();

for (Player p : players) {
checkAndAdjustPlayer(p);
private final int maxHeight;
private final JavaPlugin plugin;
private final int period;
private final double damage;

public HeightLimiter(int maxHeight, int period, double damage, JavaPlugin plugin) {
this.maxHeight = maxHeight;
this.plugin = plugin;
this.period = period;
this.damage = damage;
}
}

private void checkAndAdjustPlayer(Player p) {
var loc = p.getLocation();
int height = loc.getBlockY();

if (height > maxHeight) {
var newLoc = new Location(loc.getWorld(), loc.getBlockX(), maxHeight, loc.getBlockZ());
newLoc.setYaw(loc.getYaw());
newLoc.setPitch(loc.getPitch());

// Going back to sync to access bukkit APIs
Bukkit.getScheduler()
.runTask(
this.plugin,
() -> {
p.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are too high!"));
p.teleport(newLoc);
p.setFlying(false);
p.damage(this.damage);
p.setGliding(false);
});

public void checkHeightOnAll() {
var players = Bukkit.getOnlinePlayers();

for (Player p : players) {
checkAndAdjustPlayer(p);
}
}
}

public void startAsyncChecking() {
Bukkit.getScheduler()
.runTaskTimerAsynchronously(this.plugin, this::checkHeightOnAll, 0, this.period);
}
private void checkAndAdjustPlayer(Player p) {
var loc = p.getLocation();
int height = loc.getBlockY();

if (height > maxHeight) {
var newLoc = new Location(loc.getWorld(), loc.getBlockX(), maxHeight, loc.getBlockZ());
newLoc.setYaw(loc.getYaw());
newLoc.setPitch(loc.getPitch());

// Going back to sync to access bukkit APIs
Bukkit.getScheduler()
.runTask(
this.plugin,
() -> {
p.sendMessage(MiniMessage.miniMessage().deserialize("<red>You are too high!"));
p.teleport(newLoc);
p.setFlying(false);
p.damage(this.damage);
p.setGliding(false);
});
}
}

public void startAsyncChecking() {
Bukkit.getScheduler()
.runTaskTimerAsynchronously(this.plugin, this::checkHeightOnAll, 0, this.period);
}
}
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);
}
}

0 comments on commit 3640bf3

Please sign in to comment.