From f52d9903d50931995f9aa2827bad1194d26a8529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Karg=C4=B1n?= Date: Fri, 18 Mar 2022 23:05:17 +0300 Subject: [PATCH] - Finished javadocs, annotations and null checkers in project. - Optimized imports. --- api/src/main/java/com/hakan/core/HCore.java | 463 ++++++++++++++++-- .../hakan/core/hologram/HHologramHandler.java | 2 + .../hakan/core/ui/inventory/HInventory.java | 88 +++- .../core/ui/inventory/HInventoryHandler.java | 81 ++- .../inventory/builder/HInventoryBuilder.java | 89 +++- .../core/ui/inventory/item/ClickableItem.java | 21 + .../listeners/bukkit/PlayerQuitListener.java | 17 +- .../bukkit/PluginDisableListener.java | 17 +- .../inventory/InventoryClickListener.java | 16 +- .../inventory/InventoryCloseListener.java | 18 +- .../core/ui/inventory/pagination/Page.java | 22 +- .../ui/inventory/pagination/Pagination.java | 138 +++++- .../message/bossbar/HBossBar_v1_8_R3.java | 1 - 13 files changed, 867 insertions(+), 106 deletions(-) diff --git a/api/src/main/java/com/hakan/core/HCore.java b/api/src/main/java/com/hakan/core/HCore.java index d1396339..19d6b6b8 100644 --- a/api/src/main/java/com/hakan/core/HCore.java +++ b/api/src/main/java/com/hakan/core/HCore.java @@ -1,7 +1,7 @@ package com.hakan.core; -import com.hakan.core.command.functional.HCommand; import com.hakan.core.command.HCommandExecutor; +import com.hakan.core.command.functional.HCommand; import com.hakan.core.hologram.HHologram; import com.hakan.core.hologram.HHologramHandler; import com.hakan.core.hooks.Metrics; @@ -23,7 +23,6 @@ import com.hakan.core.worldborder.HWorldBorderHandler; import com.hakan.core.worldborder.border.HBorderColor; import com.hakan.core.worldborder.border.HWorldBorder; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -45,6 +44,7 @@ public class HCore { private static JavaPlugin instance; + @Nonnull public static JavaPlugin getInstance() { return HCore.instance; } @@ -72,6 +72,13 @@ public static void initialize(@Nonnull JavaPlugin plugin) { /* OTHERS */ + + /** + * Gets version string (example: v1_8_R3) + * + * @return Version string + */ + @Nonnull public static String getVersionString() { return Bukkit.getServer().getClass().getName().split("\\.")[3]; } @@ -80,14 +87,34 @@ public static String getVersionString() { /* SCHEDULER */ + + /** + * Creates scheduler. + * + * @param async Async status. + * @return HScheduler. + */ + @Nonnull public static HScheduler scheduler(boolean async) { return new HScheduler(HCore.instance, async); } + /** + * Creates async scheduler. + * + * @return HScheduler. + */ + @Nonnull public static HScheduler asyncScheduler() { return new HScheduler(HCore.instance, true); } + /** + * Creates sync scheduler. + * + * @return HScheduler. + */ + @Nonnull public static HScheduler syncScheduler() { return new HScheduler(HCore.instance, false); } @@ -96,82 +123,210 @@ public static HScheduler syncScheduler() { /* INVENTORY API */ + + /** + * Gets content as safe. + * + * @return Content. + */ + @Nonnull public static Map getInventoryContentSafe() { return HInventoryHandler.getContentSafe(); } + /** + * Gets content. + * + * @return Content. + */ + @Nonnull public static Map getInventoryContent() { return HInventoryHandler.getContent(); } + /** + * Gets values as safe. + * + * @return Values. + */ + @Nonnull public static Collection getInventoryValuesSafe() { return HInventoryHandler.getValuesSafe(); } + /** + * Gets values. + * + * @return Values. + */ + @Nonnull public static Collection getInventoryValues() { return HInventoryHandler.getValues(); } - public static Optional findInventoryByPlayer(Player player) { + /** + * Finds HInventory by player. + * + * @param player Player. + * @return HInventory as optional. + */ + @Nonnull + public static Optional findInventoryByPlayer(@Nonnull Player player) { return HInventoryHandler.findByPlayer(player); } - public static HInventory getInventoryByPlayer(Player player) { + /** + * Gets HInventory by player. + * + * @param player Player. + * @return HInventory. + */ + @Nonnull + public static HInventory getInventoryByPlayer(@Nonnull Player player) { return HInventoryHandler.getByPlayer(player); } - public static Optional findInventoryByUID(UUID uid) { + /** + * Finds HInventory by UID. + * + * @param uid Player UID. + * @return HInventory as optional. + */ + @Nonnull + public static Optional findInventoryByUID(@Nonnull UUID uid) { return HInventoryHandler.findByUID(uid); } - public static HInventory getInventoryByUID(UUID uid) { + /** + * Gets HInventory by UID. + * + * @param uid Player UId. + * @return HInventory. + */ + @Nonnull + public static HInventory getInventoryByUID(@Nonnull UUID uid) { return HInventoryHandler.getByUID(uid); } - public static HInventoryBuilder buildInventory(String id) { - return new HInventoryBuilder(id); + /** + * Creates builder with ID. + * + * @param id ID. + * @return HInventoryBuilder. + */ + @Nonnull + public static HInventoryBuilder buildInventory(@Nonnull String id) { + return HInventoryHandler.builder(id); } - public static HInventory createInventory(String id, String title, InventoryType type, int size) { - return new HInventoryBuilder(id).title(title).type(type).size(size).build(); + /** + * Creates HInventory with ID. + * + * @param id ID. + * @return HInventory. + */ + @Nonnull + public static HInventory createInventory(@Nonnull String id, @Nonnull String title, @Nonnull InventoryType type, int size) { + return HInventoryHandler.builder(id).title(title).type(type).size(size).build(); } /* SIGN */ + + /** + * Gets content as safe. + * + * @return Content. + */ + @Nonnull public static Map getSignContentSafe() { return HSignHandler.getContentSafe(); } + /** + * Gets content. + * + * @return Content + */ + @Nonnull public static Map getSignContent() { return HSignHandler.getContent(); } + /** + * Gets values as safe. + * + * @return Values. + */ + @Nonnull public static Collection getSignValuesSafe() { return HSignHandler.getValuesSafe(); } + /** + * Gets values. + * + * @return Values. + */ + @Nonnull public static Collection getSignValues() { return HSignHandler.getValues(); } - public static Optional findSignByPlayer(Player player) { + /** + * Finds HSign by player. + * + * @param player Player. + * @return HSign as optional. + */ + @Nonnull + public static Optional findSignByPlayer(@Nonnull Player player) { return HSignHandler.findByPlayer(player); } - public static HSign getSignByPlayer(Player player) { + /** + * Gets HSign by player. + * + * @param player Player. + * @return HSign. + */ + @Nonnull + public static HSign getSignByPlayer(@Nonnull Player player) { return HSignHandler.getByPlayer(player); } - public static Optional findSignByUID(UUID uid) { + /** + * Finds HSign by player UID. + * + * @param uid Player UID. + * @return HSign as optional. + */ + @Nonnull + public static Optional findSignByUID(@Nonnull UUID uid) { return HSignHandler.findByUID(uid); } - public static HSign getSignByUID(UUID uid) { + /** + * Gets HSign by player UID. + * + * @param uid Player UID. + * @return HSign. + */ + @Nonnull + public static HSign getSignByUID(@Nonnull UUID uid) { return HSignHandler.getByUID(uid); } + /** + * Creates HSign. + * + * @param type Sign type as Material. + * @param lines Lines of sign. + * @return Created HSign. + */ + @Nonnull public static HSign createSign(@Nonnull Material type, @Nonnull String... lines) { return HSignHandler.create(type, lines); } @@ -180,87 +335,217 @@ public static HSign createSign(@Nonnull Material type, @Nonnull String... lines) /* COMMAND */ - public static HCommand registerCommand(String command, String... aliases) { + + /** + * Registers a new command with aliases. + * + * @param command Command name. + * @param aliases Aliases. + * @return HCommand. + */ + @Nonnull + public static HCommand registerCommand(@Nonnull String command, @Nonnull String... aliases) { return new HCommand(command, aliases).register(); } - public static void registerCommand(HCommandExecutor... executors) { - Arrays.asList(executors).forEach(HCommandExecutor::register); + /** + * Registers command executors. + * + * @param executors Command executors. + */ + public static void registerCommands(@Nonnull HCommandExecutor... executors) { + Arrays.asList(Objects.requireNonNull(executors, "executors cannot be null!")).forEach(HCommandExecutor::register); } /* PACKET */ - public static void sendPacket(Player player, Object packet) { - HPacketHandler.getContent().get(player).send(packet); + + /** + * Sends packet to players + * + * @param player Player. + * @param packet Packet. + */ + public static void sendPacket(@Nonnull Player player, @Nonnull Object packet) { + HCore.sendPacket(player, new Object[]{packet}); } - public static void sendPacket(Player player, Object... packets) { - HPacketHandler.getContent().get(player).send(packets); + /** + * Sends packets to player. + * + * @param player Player. + * @param packets Packets. + */ + public static void sendPacket(@Nonnull Player player, @Nonnull Object... packets) { + HPacketHandler.getContent().get(Objects.requireNonNull(player, "player cannot be null!")).send(packets); } - public static void sendPacket(Collection players, Object packet) { - players.forEach(player -> HCore.sendPacket(player, packet)); + /** + * Sends packet to player list. + * + * @param players Player list. + * @param packet Packet. + */ + public static void sendPacket(@Nonnull Collection players, @Nonnull Object packet) { + HCore.sendPacket(players, new Object[]{packet}); } - public static void sendPacket(Collection players, Object... packets) { - players.forEach(player -> HCore.sendPacket(player, packets)); + /** + * Sends packets to player list. + * + * @param players Player list. + * @param packets Packets. + */ + public static void sendPacket(@Nonnull Collection players, @Nonnull Object... packets) { + Objects.requireNonNull(players, "players cannot be null!").forEach(player -> HCore.sendPacket(player, packets)); } /* PARTICLE */ - public static void playParticle(Player player, Location location, HParticle hParticle) { - HParticleAPI.play(player, location, hParticle); + + /** + * Plays particle for player. + * + * @param player Player. + * @param location Location. + * @param particle HParticle class. + */ + public static void playParticle(@Nonnull Player player, @Nonnull Location location, @Nonnull HParticle particle) { + HParticleAPI.play(player, location, particle); } - public static void playParticle(Collection players, Location location, HParticle hParticle) { - HParticleAPI.play(players, location, hParticle); + /** + * Plays particle for players. + * + * @param players Players. + * @param location Location. + * @param particle HParticle class. + */ + public static void playParticle(@Nonnull Collection players, @Nonnull Location location, @Nonnull HParticle particle) { + HParticleAPI.play(players, location, particle); } /* MESSAGE */ - public static void sendTitle(Player player, HTitle hTitle) { + + /** + * Sends title to player. + * + * @param player Player. + * @param hTitle HTitle class. + */ + public static void sendTitle(@Nonnull Player player, @Nonnull HTitle hTitle) { HMessageAPI.sendTitle(player, hTitle); } - public static void sendTitle(Player player, String title, String subTitle) { + /** + * Sends title to player. + * + * @param player Player. + * @param title Title. + * @param subTitle Subtitle. + */ + public static void sendTitle(@Nonnull Player player, @Nonnull String title, @Nonnull String subTitle) { HMessageAPI.sendTitle(player, title, subTitle); } - public static void sendTitle(Player player, String title, String subTitle, int stay, int fadein, int fadeout) { + /** + * Sends title to player. + * + * @param player Player. + * @param title Title. + * @param subTitle Subtitle. + * @param stay Stay time. + * @param fadein Fade in time. + * @param fadeout Fade out time. + */ + public static void sendTitle(@Nonnull Player player, @Nonnull String title, @Nonnull String subTitle, int stay, int fadein, int fadeout) { HMessageAPI.sendTitle(player, title, subTitle, stay, fadein, fadeout); } - public static void sendTitle(Collection players, HTitle hTitle) { + /** + * Sends title to players. + * + * @param players Players. + * @param hTitle HTitle class. + */ + public static void sendTitle(@Nonnull Collection players, @Nonnull HTitle hTitle) { HMessageAPI.sendTitle(players, hTitle); } - public static void sendTitle(Collection players, String title, String subTitle) { + /** + * Sends title to players. + * + * @param players Players. + * @param title Title. + * @param subTitle Subtitle. + */ + public static void sendTitle(@Nonnull Collection players, @Nonnull String title, @Nonnull String subTitle) { HMessageAPI.sendTitle(players, title, subTitle); } - public static void sendTitle(Collection players, String title, String subTitle, int stay, int fadein, int fadeout) { + /** + * Sends title to players. + * + * @param players Players. + * @param title Title. + * @param subTitle Subtitle. + * @param stay Stay time. + * @param fadein Fade in time. + * @param fadeout Fade out time. + */ + public static void sendTitle(@Nonnull Collection players, @Nonnull String title, @Nonnull String subTitle, int stay, int fadein, int fadeout) { HMessageAPI.sendTitle(players, title, subTitle, stay, fadein, fadeout); } - public static void sendActionBar(Player player, String text) { + /** + * Sends action bar to player. + * + * @param player Player. + * @param text Text. + */ + public static void sendActionBar(@Nonnull Player player, @Nonnull String text) { HMessageAPI.sendActionBar(player, text); } - public static void sendActionBar(Collection players, String text) { + /** + * Sends action bar to players. + * + * @param players Players. + * @param text Text. + */ + public static void sendActionBar(@Nonnull Collection players, @Nonnull String text) { HMessageAPI.sendActionBar(players, text); } + /** + * Creates bossbar. + * + * @param title Title. + * @param color Color. + * @param style Style. + * @param flags Flags. + * @return New instance of HBossBar. + */ public static HBossBar createBossBar(@Nonnull String title, @Nonnull HBarColor color, @Nonnull HBarStyle style, @Nonnull HBarFlag... flags) { return HMessageAPI.createBossBar(title, color, style, flags); } - public static HBossBar createBossBar(String title, HBarColor color, HBarStyle style) { + /** + * Creates bossbar. + * + * @param title Title. + * @param color Color. + * @param style Style. + * @return New instance of HBossBar. + */ + public static HBossBar createBossBar(@Nonnull String title, @Nonnull HBarColor color, @Nonnull HBarStyle style) { return HMessageAPI.createBossBar(title, color, style); } @@ -268,22 +553,62 @@ public static HBossBar createBossBar(String title, HBarColor color, HBarStyle st /* WORLD BORDER */ + + /** + * Gets values as safe. + * + * @return Values. + */ + @Nonnull public static Collection getBorderValuesSafe() { return HWorldBorderHandler.getValuesSafe(); } + /** + * Gets values. + * + * @return Values. + */ + @Nonnull public static Collection getBorderValues() { return HWorldBorderHandler.getValues(); } - public static Optional findBorderByPlayer(Player player) { + /** + * Finds world border from player. + * + * @param player Player. + * @return HWorldBorder from player as optional. + */ + @Nonnull + public static Optional findBorderByPlayer(@Nonnull Player player) { return HWorldBorderHandler.findByPlayer(player); } - public static HWorldBorder getBorderByPlayer(Player player) { + /** + * Gets world border from player. + * + * @param player Player. + * @return HWorldBorder from player. + */ + @Nonnull + public static HWorldBorder getBorderByPlayer(@Nonnull Player player) { return HWorldBorderHandler.getByPlayer(player); } + /** + * Creates world border. + * + * @param location Center location. + * @param size Size of world border. + * @param damageAmount Damage amount. + * @param damageBuffer Damage buffer. + * @param warningDistance Warning distance. + * @param warningTime Warning time. + * @param color Color of border. + * @return Created world border. + */ + @Nonnull public static HWorldBorder createBorder(@Nonnull Location location, double size, double damageAmount, double damageBuffer, int warningDistance, int warningTime, @Nonnull HBorderColor color) { return HWorldBorderHandler.create(location, size, damageAmount, damageBuffer, warningDistance, warningTime, color); } @@ -292,44 +617,100 @@ public static HWorldBorder createBorder(@Nonnull Location location, double size, /* HOLOGRAM */ + + /** + * Gets content as safe. + * + * @return holograms map. + */ @Nonnull public static Map getHologramContentSafe() { return HHologramHandler.getContentSafe(); } + /** + * Gets content. + * + * @return holograms map. + */ @Nonnull public static Map getHologramContent() { return HHologramHandler.getContent(); } + /** + * Gets holograms as safe. + * + * @return holograms. + */ + @Nonnull public static Collection getHologramValuesSafe() { return HHologramHandler.getValuesSafe(); } + /** + * Gets holograms. + * + * @return holograms. + */ + @Nonnull public static Collection getHologramValues() { return HHologramHandler.getValues(); } + /** + * Finds a created hologram + * + * @param id hologram id that you want + * @return hologram from id + */ @Nonnull public static Optional findHologramByID(@Nonnull String id) { return HHologramHandler.findByID(id); } + /** + * Gets a created hologram + * + * @param id hologram id that you want + * @return hologram from id + */ @Nonnull public static HHologram getHologramByID(@Nonnull String id) { return HHologramHandler.getByID(id); } + /** + * Creates a new hologram + * + * @param id hologram id + * @param location location + * @param players player list + * @return new hologram + */ @Nonnull - public static HHologram createHologram(@Nonnull String id, @Nonnull Location location, @Nonnull Set players) { + public static HHologram createHologram(@Nonnull String id, @Nonnull Location location, @Nullable Set players) { return HHologramHandler.create(id, location, players); } + /** + * Creates a new hologram + * + * @param id hologram id + * @param location location + * @return new hologram + */ @Nonnull public static HHologram createHologram(@Nonnull String id, @Nonnull Location location) { return HHologramHandler.create(id, location); } + /** + * Deletes hologram by id + * + * @param id id of hologram + * @return hologram to be deleted + */ @Nullable public static HHologram deleteHologram(@Nonnull String id) { return HHologramHandler.delete(id); diff --git a/api/src/main/java/com/hakan/core/hologram/HHologramHandler.java b/api/src/main/java/com/hakan/core/hologram/HHologramHandler.java index 9d8d3cc4..fc591225 100644 --- a/api/src/main/java/com/hakan/core/hologram/HHologramHandler.java +++ b/api/src/main/java/com/hakan/core/hologram/HHologramHandler.java @@ -45,6 +45,7 @@ public static Map getContent() { * * @return holograms. */ + @Nonnull public static Collection getValuesSafe() { return new ArrayList<>(HHologramHandler.holograms.values()); } @@ -54,6 +55,7 @@ public static Collection getValuesSafe() { * * @return holograms. */ + @Nonnull public static Collection getValues() { return HHologramHandler.holograms.values(); } 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 46d5f94d..39494d15 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 @@ -3,7 +3,6 @@ import com.hakan.core.ui.inventory.item.ClickableItem; import com.hakan.core.ui.inventory.pagination.Page; import com.hakan.core.ui.inventory.pagination.Pagination; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -29,7 +28,16 @@ public class HInventory { private final Set