diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java b/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java index 677ebce..9e975c3 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java @@ -34,26 +34,19 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class BukkitPlugin extends JavaPlugin { - private static BukkitPlugin instance; - - @Override - public void onLoad() { - instance = this; - } - - protected void makeConfig() { - saveDefaultConfig(); - getConfig().options().copyDefaults(true); - saveConfig(); - } @Override public void onEnable() { - makeConfig(); + // Make the config file + saveDefaultConfig(); + getConfig().options().copyDefaults(true); + saveConfig(); + // Load VR LS final FileConfiguration config = getConfig(); new BukkitRunnable() { + @Override public void run() { int serverProtocol = Via.getAPI().getServerVersion().lowestSupportedVersion(); @@ -67,15 +60,15 @@ public class BukkitPlugin extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new BounceListener(), BukkitPlugin.this); } if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("sound-fix")) { - Bukkit.getPluginManager().registerEvents(new SoundListener(), BukkitPlugin.this); + Bukkit.getPluginManager().registerEvents(new SoundListener(BukkitPlugin.this), BukkitPlugin.this); } // Added in 15w31a (1.9) if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("ladder-fix")) { - BoundingBoxFixer.fixLadder(serverProtocol); + BoundingBoxFixer.fixLadder(getLogger(), serverProtocol); } // Added in 15w32c (1.9) if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("area-effect-cloud-particles")) { - Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(), BukkitPlugin.this); + Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(BukkitPlugin.this), BukkitPlugin.this); } // Added in 15w40b (1.9) if (serverProtocol > ProtocolVersion.v1_9.getVersion() && config.getBoolean("elytra-fix")) { @@ -87,20 +80,16 @@ public class BukkitPlugin extends JavaPlugin { } // Added in 15w44b (1.9) if (serverProtocol >= ProtocolVersion.v1_9.getVersion() && config.getBoolean("lily-pad-fix")) { - BoundingBoxFixer.fixLilyPad(); + BoundingBoxFixer.fixLilyPad(getLogger()); } if (serverProtocol >= ProtocolVersion.v1_14_4.getVersion() && config.getBoolean("carpet-fix")) { - BoundingBoxFixer.fixCarpet(serverProtocol); + BoundingBoxFixer.fixCarpet(getLogger(), serverProtocol); } if (config.getBoolean("versioninfo.active")) { - new VersionInformer(); + new VersionInformer(BukkitPlugin.this, config); } } }.runTaskTimer(this, 1L, 1L); } - - public static BukkitPlugin getInstance() { - return instance; - } } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java b/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java index 59c10be..8606d9e 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java @@ -27,31 +27,32 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.logging.Level; +import java.util.logging.Logger; public class BoundingBoxFixer { - public static void fixLilyPad() { + public static void fixLilyPad(final Logger logger) { try { final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), "a"); setBoundingBox(boundingBoxField.get(null), 0.0625, 0.0, 0.0625, 0.9375, 0.015625, 0.9375); } catch (Exception ex) { - BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix lily pad bounding box.", ex); + logger.log(Level.SEVERE, "Could not fix lily pad bounding box.", ex); } } - public static void fixCarpet(final int serverVersion) { + public static void fixCarpet(final Logger logger, final int serverVersion) { try { final Class blockCarpetClass = serverVersion <= ProtocolVersion.v1_16_4.getVersion() ? NMSReflection.getNMSBlock("BlockCarpet") : NMSReflection.getNMSBlock("CarpetBlock"); final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, "a"); setBoundingBox(boundingBoxField.get(0), 0.0D, -0.0000001D, 0.0D, 1.0D, 0.0000001D, 1.0D); } catch (Exception ex) { - BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix carpet bounding box.", ex); + logger.log(Level.SEVERE, "Could not fix carpet bounding box.", ex); } } - public static void fixLadder(final int serverVersion) { + public static void fixLadder(final Logger logger, final int serverVersion) { try { final boolean pre1_12_2 = serverVersion <= ProtocolVersion.v1_12_2.getVersion(); final boolean pre1_13_2 = serverVersion <= ProtocolVersion.v1_13_2.getVersion(); @@ -69,7 +70,7 @@ public class BoundingBoxFixer { setBoundingBox(boundingBoxSouthField.get(null), 0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D); setBoundingBox(boundingBoxNorthField.get(null), 0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D); } catch (Exception ex) { - BukkitPlugin.getInstance().getLogger().log(Level.SEVERE, "Could not fix ladder bounding box.", ex); + logger.log(Level.SEVERE, "Could not fix ladder bounding box.", ex); } } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java index c8cc01b..7863738 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java @@ -39,8 +39,8 @@ import java.util.stream.Collectors; public class AreaEffectCloudListener implements Listener { private final ArrayList effectClouds = new ArrayList<>(); - public AreaEffectCloudListener() { - Bukkit.getScheduler().runTaskTimer(BukkitPlugin.getInstance(), () -> { + public AreaEffectCloudListener(final BukkitPlugin plugin) { + Bukkit.getScheduler().runTaskTimer(plugin, () -> { final Set affectedPlayers = Bukkit.getOnlinePlayers().stream().filter(p -> Via.getAPI().getPlayerVersion(p) <= ProtocolVersion.v1_8.getVersion()).collect(Collectors.toSet()); effectClouds.removeIf(e -> !e.isValid()); effectClouds.forEach(cloud -> { diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java index 39db6ae..2632557 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java @@ -36,7 +36,7 @@ public class BrewingListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent e) { if (!e.hasBlock() || e.getClickedBlock().getType() != Material.BREWING_STAND) return; - Player player = (Player) e.getPlayer(); + Player player = e.getPlayer(); int version = Via.getAPI().getPlayerVersion(player); if (version > 79) return; ItemStack blazePowder = new ItemStack(Material.BLAZE_POWDER); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java index 0009d22..3fd5572 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java @@ -19,7 +19,7 @@ package com.viaversion.viarewind.legacysupport.listener; import com.viaversion.viaversion.api.Via; -import org.bukkit.Location; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -27,50 +27,58 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; +@SuppressWarnings("unchecked") public class ElytraListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e) { - Player p = e.getPlayer(); - if (!p.isGliding()) return; - if (Via.getAPI().getPlayerVersion(p) > 76) return; + final Player player = e.getPlayer(); + + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_9.getVersion()) return; // Only apply for 1.8 and below players + if (!player.isGliding()) return; // Only apply if the player is gliding + + final Vector direction = player.getLocation().getDirection(); + final Vector velocity = player.getVelocity(); - Location loc = p.getLocation(); - Vector velocity = p.getVelocity(); - Vector direction = loc.getDirection(); double motionX = velocity.getX(); double motionY = velocity.getY(); double motionZ = velocity.getZ(); - float pitch = loc.getPitch() * 0.017453292F; + float pitch = player.getLocation().getPitch() * 0.017453292F; double directionH = Math.sqrt(direction.getX() * direction.getX() + direction.getZ() * direction.getZ()); double speedH = Math.sqrt(motionX * motionX + motionZ * motionZ); float speedV = (float) Math.cos(pitch); + speedV = (float) (speedV * speedV * Math.min(1.0D, direction.length() / 0.4D)); motionY += -0.08D + speedV * 0.06D; + if ((motionY < 0.0D) && (directionH > 0.0D)) { double d2 = motionY * -0.1D * speedV; motionY += d2; motionX += direction.getX() * d2 / directionH; motionZ += direction.getZ() * d2 / directionH; } + if (pitch < 0.0F) { double speed = speedH * -Math.sin(pitch) * 0.04D; motionY += speed * 3.2D; motionX -= direction.getX() * speed / directionH; motionZ -= direction.getZ() * speed / directionH; } + if (directionH > 0.0D) { motionX += (direction.getX() / directionH * speedH - motionX) * 0.1D; motionZ += (direction.getZ() / directionH * speedH - motionZ) * 0.1D; } + motionX *= 0.9900000095367432D; motionY *= 0.9800000190734863D; motionZ *= 0.9900000095367432D; + velocity.setX(motionX); velocity.setY(motionY); velocity.setZ(motionZ); - p.setVelocity(velocity); + player.setVelocity(velocity); } } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java index 6c70781..5802333 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java @@ -19,6 +19,7 @@ package com.viaversion.viarewind.legacysupport.listener; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -32,22 +33,38 @@ import org.bukkit.inventory.PlayerInventory; import java.util.Map; +@SuppressWarnings("unchecked") public class EnchantingListener implements Listener { - private final boolean newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null; - private final Material lapisMaterial = newMaterialNames ? Material.LAPIS_LAZULI : Material.getMaterial("INK_SACK"); + private final boolean newMaterialNames; + private final Material lapisMaterial; + + public EnchantingListener() { + newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null; + + if (newMaterialNames) { + lapisMaterial = Material.LAPIS_LAZULI; + } else { + lapisMaterial = Material.getMaterial("INK_SACK"); + } + } @EventHandler public void onInventoryOpen(InventoryOpenEvent e) { if (!(e.getInventory() instanceof EnchantingInventory)) return; - Player player = (Player) e.getPlayer(); - if (Via.getAPI().getPlayerVersion(player) > 5) return; - PlayerInventory playerInventory = player.getInventory(); - ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4); + + final Player player = (Player) e.getPlayer(); + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return; + + final PlayerInventory inv = player.getInventory(); + final ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4); + int amount = 0; - for (int i = 0; i < playerInventory.getSize(); i++) { - ItemStack item = playerInventory.getItem(i); + for (int i = 0; i < inv.getSize(); i++) { + ItemStack item = inv.getItem(i); + if (item == null || !item.isSimilar(lapis)) continue; + if (amount + item.getAmount() > 64) { item.setAmount(amount + item.getAmount() - 64); amount = 64; @@ -55,29 +72,37 @@ public class EnchantingListener implements Listener { amount += item.getAmount(); item = new ItemStack(Material.AIR); } - playerInventory.setItem(i, item); + + inv.setItem(i, item); if (amount == 64) break; } + if (amount == 0) return; - EnchantingInventory inventory = (EnchantingInventory) e.getInventory(); + + final EnchantingInventory replacement = (EnchantingInventory) e.getInventory(); lapis.setAmount(amount); - inventory.setSecondary(lapis); + replacement.setSecondary(lapis); } @EventHandler public void onInventoryClose(InventoryCloseEvent e) { if (!(e.getInventory() instanceof EnchantingInventory)) return; - Player player = (Player) e.getPlayer(); - int version = Via.getAPI().getPlayerVersion(player); - if (version > 5) return; - PlayerInventory playerInventory = player.getInventory(); - EnchantingInventory inventory = (EnchantingInventory) e.getInventory(); - ItemStack item = inventory.getSecondary(); + + final Player player = (Player) e.getPlayer(); + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return; + + final PlayerInventory inv = player.getInventory(); + final EnchantingInventory replacement = (EnchantingInventory) e.getInventory(); + + final ItemStack item = replacement.getSecondary(); if (item == null || item.getType() == Material.AIR) return; - inventory.setSecondary(new ItemStack(Material.AIR)); - Map remaining = playerInventory.addItem(item); + + replacement.setSecondary(new ItemStack(Material.AIR)); + + Map remaining = inv.addItem(item); if (!remaining.isEmpty()) { - Location location = player.getLocation(); + final Location location = player.getLocation(); + for (ItemStack value : remaining.values()) { player.getWorld().dropItem(location, value); } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java index e03933a..6480a84 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java @@ -23,6 +23,7 @@ import com.viaversion.viarewind.legacysupport.reflection.ReflectionAPI; import com.viaversion.viaversion.api.Via; import com.viaversion.viarewind.legacysupport.BukkitPlugin; import com.viaversion.viarewind.legacysupport.injector.NMSReflection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; @@ -40,6 +41,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import java.lang.reflect.Method; +@SuppressWarnings("unchecked") public class SoundListener implements Listener { private static boolean isSoundCategory = false; @@ -52,7 +54,7 @@ public class SoundListener implements Listener { } } - public SoundListener() { + public SoundListener(final BukkitPlugin plugin) { try { Class.forName("org.bukkit.event.entity.EntityPickupItemEvent"); @@ -60,12 +62,12 @@ public class SoundListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onItemPickUp(EntityPickupItemEvent e) { - if (!(e.getEntity() instanceof Player)) - return; + if (!(e.getEntity() instanceof Player)) return; + SoundListener.this.onItemPickUp((Player) e.getEntity()); } - }, BukkitPlugin.getInstance()); + }, plugin); } catch (Exception ex) { Bukkit.getPluginManager().registerEvents(new Listener() { @@ -74,18 +76,16 @@ public class SoundListener implements Listener { SoundListener.this.onItemPickUp(e.getPlayer()); } - }, BukkitPlugin.getInstance()); + }, plugin); } } @EventHandler public void onBlockPlace(BlockPlaceEvent e) { - Player player = e.getPlayer(); + final Player player = e.getPlayer(); + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_9.getVersion()) return; - if (Via.getAPI().getPlayerVersion(player) > 47) - return; - - if (Via.getAPI().getServerVersion().lowestSupportedVersion() >= 755) { + if (Via.getAPI().getServerVersion().lowestSupportedVersion() >= ProtocolVersion.v1_17.getVersion()) { player.playSound(e.getBlockPlaced().getLocation(), e.getBlock().getBlockData().getSoundGroup().getPlaceSound(), 1.0f, 0.8f); } else { playBlockPlaceSoundNMS(player, e.getBlock()); @@ -93,27 +93,28 @@ public class SoundListener implements Listener { } private void onItemPickUp(Player player) { - float volume = 0.2f; - float pitch = (float) ((Math.random() - Math.random()) * 0.7f + 1.0f) * 2.0f; - Location loc = player.getLocation(); - playSound(loc, Sound.ENTITY_ITEM_PICKUP, "PLAYERS", volume, pitch, 16, 47); + final float volume = 0.2f; + final float pitch = (float) ((Math.random() - Math.random()) * 0.7f + 1.0f) * 2.0f; + + playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, volume, pitch); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void onExperienceOrbPickup(PlayerExpChangeEvent e) { - float volume = 0.1f; - float pitch = (float) (0.5f * ((Math.random() - Math.random()) * 0.7f + 1.8f)); - playSound(e.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, "PLAYERS", volume, pitch, 16, 47); + final float volume = 0.1f; + final float pitch = (float) (0.5f * ((Math.random() - Math.random()) * 0.7f + 1.8f)); + + playSound(e.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, volume, pitch); } - private static void playSound(Location loc, Sound sound, String category, float volume, float pitch, double dist, int version) { + private static void playSound(final Location loc, final Sound sound, final float volume, final float pitch) { Bukkit.getOnlinePlayers().stream() .filter(p -> p.getWorld() == loc.getWorld()) - .filter(p -> p.getLocation().distanceSquared(loc) < dist * dist) - .filter(p -> Via.getAPI().getPlayerVersion(p) <= version) + .filter(p -> p.getLocation().distanceSquared(loc) < (double) 16 * (double) 16) + .filter(p -> Via.getAPI().getPlayerVersion(p) <= 47) .forEach(p -> { if (isSoundCategory) { - p.playSound(loc, sound, SoundCategory.valueOf(category), volume, pitch); + p.playSound(loc, sound, SoundCategory.valueOf("PLAYERS"), volume, pitch); } else { p.playSound(loc, sound, volume, pitch); } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/reflection/MethodSignature.java b/src/main/java/com/viaversion/viarewind/legacysupport/reflection/MethodSignature.java index 5d3444c..acb1681 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/reflection/MethodSignature.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/reflection/MethodSignature.java @@ -23,7 +23,6 @@ import java.util.Objects; import java.util.StringJoiner; public class MethodSignature { - private final String name; private final Class[] parameterTypes; diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/reflection/ReflectionAPI.java b/src/main/java/com/viaversion/viarewind/legacysupport/reflection/ReflectionAPI.java index a8faa72..96a8d21 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/reflection/ReflectionAPI.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/reflection/ReflectionAPI.java @@ -18,11 +18,7 @@ package com.viaversion.viarewind.legacysupport.reflection; -import sun.reflect.ReflectionFactory; - -import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/versioninfo/VersionInformer.java b/src/main/java/com/viaversion/viarewind/legacysupport/versioninfo/VersionInformer.java index b92ee10..2ade3be 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/versioninfo/VersionInformer.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/versioninfo/VersionInformer.java @@ -22,40 +22,49 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viarewind.legacysupport.BukkitPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; +@SuppressWarnings({"DataFlowIssue", "unchecked"}) public class VersionInformer implements Listener { private final String[] versionMessage; private final int maxVersion; - public VersionInformer() { - String message = BukkitPlugin.getInstance().getConfig().getString("versioninfo.message"); - message = ChatColor.translateAlternateColorCodes('&', message); - message = message.replace("%version%", Bukkit.getVersion().split(" ")[2].replace(")", "")); - this.versionMessage = message.split(System.lineSeparator()); + public VersionInformer(final BukkitPlugin plugin, final FileConfiguration config) { + final String message = ChatColor.translateAlternateColorCodes('&', config.getString("versioninfo.message")). + replace("%version%", Bukkit.getVersion().split(" ")[2].replace(")", "")); - maxVersion = BukkitPlugin.getInstance().getConfig().getInt("versioninfo.max-version"); - String interval = BukkitPlugin.getInstance().getConfig().getString("versioninfo.interval"); + this.versionMessage = message.split(System.lineSeparator()); + maxVersion = config.getInt("versioninfo.max-version"); + + String interval = config.getString("versioninfo.interval"); if (interval.equalsIgnoreCase("JOIN")) { - Bukkit.getPluginManager().registerEvents(this, BukkitPlugin.getInstance()); + Bukkit.getPluginManager().registerEvents(this, plugin); } else { - long ticks = Long.parseLong(interval); - Bukkit.getScheduler().runTaskTimer(BukkitPlugin.getInstance(), () -> { - Bukkit.getOnlinePlayers().forEach(player -> { - int version = Via.getAPI().getPlayerVersion(player); - if (version > maxVersion) return; - player.sendMessage(this.versionMessage); - }); - }, ticks, ticks); + long ticks; + try { + ticks = Long.parseLong(interval); + } catch (NumberFormatException e) { + Bukkit.getLogger().warning("Invalid interval for versioninfo.interval, defaulting to 6000"); + ticks = 6000; + } + + Bukkit.getScheduler().runTaskTimer(plugin, () -> Bukkit.getOnlinePlayers().forEach(this::inform), ticks, ticks); } } + protected void inform(final Player player) { + int version = Via.getAPI().getPlayerVersion(player); + if (version > maxVersion) return; + + player.sendMessage(this.versionMessage); + } + @EventHandler public void onJoin(PlayerJoinEvent e) { - int version = Via.getAPI().getPlayerVersion(e.getPlayer()); - if (version > maxVersion) return; - e.getPlayer().sendMessage(this.versionMessage); + inform(e.getPlayer()); } }