From 3640bf379f32c4401c70cd792e50504ecb56db59 Mon Sep 17 00:00:00 2001 From: Netherwhal Date: Thu, 22 Jun 2023 14:51:54 +0200 Subject: [PATCH] fix indent (#14) --- .../simplyheightlimit/HeightLimiter.java | 88 +++++++++---------- .../simplyheightlimit/SimplyHeightLimit.java | 70 +++++++-------- 2 files changed, 77 insertions(+), 81 deletions(-) diff --git a/src/main/java/net/simplyvanilla/simplyheightlimit/HeightLimiter.java b/src/main/java/net/simplyvanilla/simplyheightlimit/HeightLimiter.java index ffd8146..d518046 100644 --- a/src/main/java/net/simplyvanilla/simplyheightlimit/HeightLimiter.java +++ b/src/main/java/net/simplyvanilla/simplyheightlimit/HeightLimiter.java @@ -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("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("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); + } } diff --git a/src/main/java/net/simplyvanilla/simplyheightlimit/SimplyHeightLimit.java b/src/main/java/net/simplyvanilla/simplyheightlimit/SimplyHeightLimit.java index f0441ed..f978355 100644 --- a/src/main/java/net/simplyvanilla/simplyheightlimit/SimplyHeightLimit.java +++ b/src/main/java/net/simplyvanilla/simplyheightlimit/SimplyHeightLimit.java @@ -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); + } }