Skip to content

Commit

Permalink
- Finished javadocs, annotations and null checkers in scheduler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakan Kargın committed Mar 18, 2022
1 parent 6eaf166 commit cf5d11c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
65 changes: 60 additions & 5 deletions api/src/main/java/com/hakan/core/scheduler/HScheduler.java
Original file line number Diff line number Diff line change
@@ -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<BukkitRunnable> taskConsumer) {
/**
* Starts to scheduler.
*
* @param taskConsumer Callback.
* @return This class.
*/
@Nonnull
public synchronized HScheduler run(@Nonnull Consumer<BukkitRunnable> taskConsumer) {
Validate.notNull(taskConsumer, "task consumer cannot be null!");

BukkitRunnable bukkitRunnable = new BukkitRunnable() {
@Override
public void run() {
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/java/com/hakan/core/ui/inventory/HInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ public final <T extends HInventory> 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() {
Expand Down Expand Up @@ -254,7 +254,7 @@ public final <T extends HInventory> 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
*/
Expand Down

0 comments on commit cf5d11c

Please sign in to comment.