From cf5d11c921399792f560faf5205ef39b75d57e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Karg=C4=B1n?= Date: Fri, 18 Mar 2022 16:59:38 +0300 Subject: [PATCH] - Finished javadocs, annotations and null checkers in scheduler. --- .../core/hologram/util/HHologramUtils.java | 6 +- .../com/hakan/core/scheduler/HScheduler.java | 65 +++++++++++++++++-- .../hakan/core/ui/inventory/HInventory.java | 8 +-- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/api/src/main/java/com/hakan/core/hologram/util/HHologramUtils.java b/api/src/main/java/com/hakan/core/hologram/util/HHologramUtils.java index b7054647..c57e4d56 100644 --- a/api/src/main/java/com/hakan/core/hologram/util/HHologramUtils.java +++ b/api/src/main/java/com/hakan/core/hologram/util/HHologramUtils.java @@ -23,14 +23,14 @@ public final class HHologramUtils { @Nonnull public static HHologramArmorStand createHologramArmorStand(@Nonnull HHologram hHologram) { try { - Validate.notNull(hHologram, "vezorHologram cannot be null"); + Validate.notNull(hHologram, "hHologram cannot be null"); Constructor constructor = Class.forName("com.hakan.core.line.entity.HHologramArmorStand_" + HCore.getVersionString()).getDeclaredConstructor(HHologram.class, Location.class); constructor.setAccessible(true); - HHologramArmorStand vezorHologramArmorStand = (HHologramArmorStand) constructor.newInstance(hHologram, hHologram.getLocation()); + HHologramArmorStand armorStand = (HHologramArmorStand) constructor.newInstance(hHologram, hHologram.getLocation()); constructor.setAccessible(false); - return vezorHologramArmorStand; + return armorStand; } catch (Exception e) { throw new NullPointerException(e.getMessage()); } diff --git a/api/src/main/java/com/hakan/core/scheduler/HScheduler.java b/api/src/main/java/com/hakan/core/scheduler/HScheduler.java index 503d8353..a7861499 100644 --- a/api/src/main/java/com/hakan/core/scheduler/HScheduler.java +++ b/api/src/main/java/com/hakan/core/scheduler/HScheduler.java @@ -1,46 +1,101 @@ package com.hakan.core.scheduler; +import org.apache.commons.lang.Validate; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; +import javax.annotation.Nonnull; +import java.util.Objects; import java.util.function.Consumer; -public class HScheduler { +/** + * HScheduler class. + */ +public final class HScheduler { private final JavaPlugin plugin; private boolean async; private long after; private Long every; - public HScheduler(JavaPlugin plugin, boolean async) { - this.plugin = plugin; + /** + * Creates new instance of this class. + * + * @param plugin Plugin. + * @param async Async. + */ + public HScheduler(@Nonnull JavaPlugin plugin, boolean async) { + this.plugin = Objects.requireNonNull(plugin, "plugin cannot be null!"); this.async = async; } + /** + * Checks will scheduler run as async? + * + * @return If scheduler run as async, returns true. + */ public boolean isAsync() { return this.async; } + /** + * Sets async mode of scheduler. + * + * @param async Async mode. + * @return This class. + */ + @Nonnull public HScheduler async(boolean async) { this.async = async; return this; } + /** + * Runs how money ticks later. + * + * @param after Ticks. + * @return This class. + */ + @Nonnull public HScheduler after(long after) { this.after = after; return this; } + /** + * Runs every how many ticks. + * + * @param every Ticks. + * @return This class. + */ + @Nonnull public HScheduler every(long every) { this.every = every; return this; } - public synchronized HScheduler run(Runnable runnable) { + /** + * Starts to scheduler. + * + * @param runnable Callback. + * @return This class. + */ + @Nonnull + public synchronized HScheduler run(@Nonnull Runnable runnable) { + Validate.notNull(runnable, "runnable cannot be null!"); return this.run(consumer -> runnable.run()); } - public synchronized HScheduler run(Consumer taskConsumer) { + /** + * Starts to scheduler. + * + * @param taskConsumer Callback. + * @return This class. + */ + @Nonnull + public synchronized HScheduler run(@Nonnull Consumer taskConsumer) { + Validate.notNull(taskConsumer, "task consumer cannot be null!"); + BukkitRunnable bukkitRunnable = new BukkitRunnable() { @Override public void run() { diff --git a/api/src/main/java/com/hakan/core/ui/inventory/HInventory.java b/api/src/main/java/com/hakan/core/ui/inventory/HInventory.java index 3cab1899..46d5f94d 100644 --- a/api/src/main/java/com/hakan/core/ui/inventory/HInventory.java +++ b/api/src/main/java/com/hakan/core/ui/inventory/HInventory.java @@ -132,10 +132,10 @@ public final T removeOption(@Nonnull Option option) { } /** - * If you want to use pagination, you need - * VezorPagination instance + * If you want to use pagination, you + * need pagination instance. * - * @return VezorPagination instance + * @return Pagination instance */ @Nonnull public final Pagination getPagination() { @@ -254,7 +254,7 @@ public final T removeItem(int slot) { /** * Sets the slots with clickable item * - * @param clickableItem VezorClickableItem object + * @param clickableItem ClickableItem object * @param replaceWithItems If this param is true, it replaces all items with clickable item * @return instance of this class */