From cdcea25e1cb236c86089471699eadd6c9022d0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20Karg=C4=B1n?= Date: Fri, 18 Mar 2022 17:28:17 +0300 Subject: [PATCH] - Finished javadocs, annotations and null checkers in sign system. --- api/src/main/java/com/hakan/core/HCore.java | 2 +- .../java/com/hakan/core/ui/sign/HSign.java | 79 +++++++++++++--- .../com/hakan/core/ui/sign/HSignHandler.java | 93 +++++++++++++++++-- .../core/ui/sign/listeners/HSignListener.java | 17 +++- .../core/ui/sign/wrapper/HSign_v1_10_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_11_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_12_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_13_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_13_R2.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_14_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_15_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_16_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_16_R2.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_16_R3.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_17_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_18_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_18_R2.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_8_R3.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_9_R1.java | 12 ++- .../core/ui/sign/wrapper/HSign_v1_9_R2.java | 12 ++- 20 files changed, 311 insertions(+), 72 deletions(-) diff --git a/api/src/main/java/com/hakan/core/HCore.java b/api/src/main/java/com/hakan/core/HCore.java index 87cc4481..d1396339 100644 --- a/api/src/main/java/com/hakan/core/HCore.java +++ b/api/src/main/java/com/hakan/core/HCore.java @@ -172,7 +172,7 @@ public static HSign getSignByUID(UUID uid) { return HSignHandler.getByUID(uid); } - public static HSign createSign(Material type, String... lines) { + public static HSign createSign(@Nonnull Material type, @Nonnull String... lines) { return HSignHandler.create(type, lines); } diff --git a/api/src/main/java/com/hakan/core/ui/sign/HSign.java b/api/src/main/java/com/hakan/core/ui/sign/HSign.java index 5c04aa1b..452677b4 100644 --- a/api/src/main/java/com/hakan/core/ui/sign/HSign.java +++ b/api/src/main/java/com/hakan/core/ui/sign/HSign.java @@ -3,43 +3,100 @@ import org.bukkit.Material; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; +import java.util.Objects; import java.util.function.Consumer; +/** + * HSign class to manage + * and show sign to player. + */ public abstract class HSign { protected Material type; protected String[] lines; protected Consumer consumer; - public HSign(Material type, String... lines) { - this.type = type; - this.lines = lines; + /** + * Creates new instance of this class. + * + * @param type Type of sign. + * @param lines Lines of sign. + */ + public HSign(@Nonnull Material type, @Nonnull String... lines) { + this.type = Objects.requireNonNull(type, "type cannot be null!"); + this.lines = Objects.requireNonNull(lines, "lines cannot be null!"); } + /** + * Gets type of sign. + * + * @return Type of sign. + */ + @Nonnull public final Material getType() { return this.type; } - public final HSign setType(Material type) { - this.type = type; + /** + * Sets type of sign. + * + * @param type Type of sign. + * @return This class. + */ + @Nonnull + public final HSign setType(@Nonnull Material type) { + this.type = Objects.requireNonNull(type, "type cannot be null!"); return this; } + /** + * Gets line of sign. + * + * @return Lines of sign. + */ + @Nonnull public final String[] getLines() { return this.lines; } - public final HSign setLines(String[] lines) { - this.lines = lines; + /** + * Sets lines of sign. + * + * @param lines Lines of sign. + * @return This class. + */ + @Nonnull + public final HSign setLines(@Nonnull String[] lines) { + this.lines = Objects.requireNonNull(lines, "lines cannot be null!"); return this; } - public final HSign onComplete(Consumer consumer) { - this.consumer = consumer; + /** + * Runs when sign close. + * + * @param consumer Callback. + * @return This class. + */ + @Nonnull + public final HSign onComplete(@Nonnull Consumer consumer) { + this.consumer = Objects.requireNonNull(consumer, "complete consumer cannot be null!"); return this; } - public abstract void open(Player player); + /** + * Opens the sign to player. + * + * @param player Player. + */ + public abstract void open(@Nonnull Player player); - public abstract void listen(Player player, T packet); + /** + * Listens player packet if + * packet is a sign packet. + * + * @param player Player. + * @param packet Packet. + */ + public abstract void listen(@Nonnull Player player, @Nonnull T packet); } \ No newline at end of file diff --git a/api/src/main/java/com/hakan/core/ui/sign/HSignHandler.java b/api/src/main/java/com/hakan/core/ui/sign/HSignHandler.java index 82262e42..6dba2ff5 100644 --- a/api/src/main/java/com/hakan/core/ui/sign/HSignHandler.java +++ b/api/src/main/java/com/hakan/core/ui/sign/HSignHandler.java @@ -3,59 +3,132 @@ import com.hakan.core.HCore; import com.hakan.core.listener.HListenerAdapter; import com.hakan.core.ui.sign.listeners.HSignListener; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import javax.annotation.Nonnull; import java.util.*; -public class HSignHandler { +/** + * HSignHandler class to find + * and create the signs. + */ +public final class HSignHandler { private static final Map signMap = new HashMap<>(); - public static void initialize(JavaPlugin plugin) { + /** + * Initializes sign system. + * + * @param plugin Main class of plugin. + */ + public static void initialize(@Nonnull JavaPlugin plugin) { HListenerAdapter.register(new HSignListener(plugin)); } - + /** + * Gets content as safe. + * + * @return Content. + */ + @Nonnull public static Map getContentSafe() { return new HashMap<>(HSignHandler.signMap); } + /** + * Gets content. + * + * @return Content + */ + @Nonnull public static Map getContent() { return HSignHandler.signMap; } + /** + * Gets values as safe. + * + * @return Values. + */ + @Nonnull public static Collection getValuesSafe() { return new ArrayList<>(HSignHandler.signMap.values()); } + /** + * Gets values. + * + * @return Values. + */ + @Nonnull public static Collection getValues() { return HSignHandler.signMap.values(); } - public static Optional findByPlayer(Player player) { + /** + * Finds HSign by player. + * + * @param player Player. + * @return HSign as optional. + */ + @Nonnull + public static Optional findByPlayer(@Nonnull Player player) { return HSignHandler.findByUID(player.getUniqueId()); } - public static HSign getByPlayer(Player player) { + /** + * Gets HSign by player. + * + * @param player Player. + * @return HSign. + */ + @Nonnull + public static HSign getByPlayer(@Nonnull Player player) { return HSignHandler.findByPlayer(player).orElseThrow(() -> new NullPointerException("this player doesn't have a inventory!")); } - public static Optional findByUID(UUID uid) { - return Optional.ofNullable(HSignHandler.signMap.get(uid)); + /** + * Finds HSign by player UID. + * + * @param uid Player UID. + * @return HSign as optional. + */ + @Nonnull + public static Optional findByUID(@Nonnull UUID uid) { + return Optional.ofNullable(HSignHandler.signMap.get(Objects.requireNonNull(uid, "UID cannot be null!"))); } - public static HSign getByUID(UUID uid) { + /** + * Gets HSign by player UID. + * + * @param uid Player UID. + * @return HSign. + */ + @Nonnull + public static HSign getByUID(@Nonnull UUID uid) { return HSignHandler.findByUID(uid).orElseThrow(() -> new NullPointerException("this player doesn't have a inventory!")); } - public static HSign create(Material type, String... lines) { + /** + * Creates HSign. + * + * @param type Sign type as Material. + * @param lines Lines of sign. + * @return Created HSign. + */ + @Nonnull + public static HSign create(@Nonnull Material type, @Nonnull String... lines) { + Validate.notNull(type, "type cannot be null!"); + Validate.notNull(lines, "lines cannot be null!"); + try { return (HSign) Class.forName("com.hakan.core.ui.sign.wrapper.HSign_" + HCore.getVersionString()) .getConstructor(Material.class, String[].class).newInstance(type, lines); } catch (Exception e) { - return null; + throw new NullPointerException(e.getMessage()); } } } \ No newline at end of file diff --git a/api/src/main/java/com/hakan/core/ui/sign/listeners/HSignListener.java b/api/src/main/java/com/hakan/core/ui/sign/listeners/HSignListener.java index d539bd86..f63041fa 100644 --- a/api/src/main/java/com/hakan/core/ui/sign/listeners/HSignListener.java +++ b/api/src/main/java/com/hakan/core/ui/sign/listeners/HSignListener.java @@ -8,14 +8,27 @@ import javax.annotation.Nonnull; -public class HSignListener extends HListenerAdapter { +/** + * HSignListener class. + */ +public final class HSignListener extends HListenerAdapter { + /** + * Creates new instance of this class. + * + * @param plugin Main class of plugin. + */ public HSignListener(@Nonnull JavaPlugin plugin) { super(plugin); } + /** + * Packet event. + * + * @param event Event. + */ @EventHandler - public void onPacketEvent(PacketEvent event) { + public void onPacketEvent(@Nonnull PacketEvent event) { if (event.getPacket().toString().contains("PacketPlayInUpdateSign")) { HSignHandler.findByPlayer(event.getPlayer()) .ifPresent(hSign -> hSign.listen(event.getPlayer(), event.getPacket())); diff --git a/nms/1_10_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_10_R1.java b/nms/1_10_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_10_R1.java index 7364b530..92c3e95e 100644 --- a/nms/1_10_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_10_R1.java +++ b/nms/1_10_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_10_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_10_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_10_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_10_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_10_R1(Material type, String... lines) { + public HSign_v1_10_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_10_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a(); diff --git a/nms/1_11_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_11_R1.java b/nms/1_11_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_11_R1.java index 6e4d03c1..f9f0d42f 100644 --- a/nms/1_11_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_11_R1.java +++ b/nms/1_11_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_11_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_11_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_11_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_11_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_11_R1(Material type, String... lines) { + public HSign_v1_11_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_11_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a(); diff --git a/nms/1_12_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_12_R1.java b/nms/1_12_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_12_R1.java index c7302c35..6c2011b2 100644 --- a/nms/1_12_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_12_R1.java +++ b/nms/1_12_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_12_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_12_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_12_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_12_R1(Material type, String... lines) { + public HSign_v1_12_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_12_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a(); diff --git a/nms/1_13_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R1.java b/nms/1_13_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R1.java index 5bb68b7d..831882ab 100644 --- a/nms/1_13_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R1.java +++ b/nms/1_13_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_13_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_13_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_13_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_13_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_13_R1(Material type, String... lines) { + public HSign_v1_13_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_13_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_13_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R2.java b/nms/1_13_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R2.java index 96b8f0a3..f45567df 100644 --- a/nms/1_13_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R2.java +++ b/nms/1_13_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_13_R2.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_13_R2.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_13_R2.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_13_R2 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_13_R2(Material type, String... lines) { + public HSign_v1_13_R2(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_13_R2(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_14_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_14_R1.java b/nms/1_14_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_14_R1.java index b62a61f6..5c4365be 100644 --- a/nms/1_14_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_14_R1.java +++ b/nms/1_14_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_14_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_14_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_14_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_14_R1(Material type, String... lines) { + public HSign_v1_14_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_14_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_15_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_15_R1.java b/nms/1_15_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_15_R1.java index d93e3d60..e7ec2ea8 100644 --- a/nms/1_15_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_15_R1.java +++ b/nms/1_15_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_15_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_15_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_15_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_15_R1(Material type, String... lines) { + public HSign_v1_15_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_15_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_16_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R1.java b/nms/1_16_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R1.java index aa1fe880..d865245b 100644 --- a/nms/1_16_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R1.java +++ b/nms/1_16_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_16_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_16_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_16_R1(Material type, String... lines) { + public HSign_v1_16_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_16_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_16_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R2.java b/nms/1_16_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R2.java index d3272b0c..1e7c4bb1 100644 --- a/nms/1_16_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R2.java +++ b/nms/1_16_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R2.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_16_R2.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_16_R2.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_16_R2 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_16_R2(Material type, String... lines) { + public HSign_v1_16_R2(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_16_R2(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_16_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R3.java b/nms/1_16_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R3.java index 803ac525..8241386a 100644 --- a/nms/1_16_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R3.java +++ b/nms/1_16_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_16_R3.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_16_R3.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_16_R3 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_16_R3(Material type, String... lines) { + public HSign_v1_16_R3(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_16_R3(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_17_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_17_R1.java b/nms/1_17_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_17_R1.java index 558ad6fd..c5062c9f 100644 --- a/nms/1_17_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_17_R1.java +++ b/nms/1_17_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_17_R1.java @@ -10,11 +10,14 @@ import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntitySign; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_17_R1.block.CraftSign; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -23,7 +26,7 @@ public final class HSign_v1_17_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_17_R1(Material type, String... lines) { + public HSign_v1_17_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -31,7 +34,8 @@ public HSign_v1_17_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); HCore.sendPacket(player, new PacketPlayOutBlockChange(blockPosition, Blocks.cg.getBlockData())); @@ -49,7 +53,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_18_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R1.java b/nms/1_18_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R1.java index b9f4e003..d3b0465e 100644 --- a/nms/1_18_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R1.java +++ b/nms/1_18_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R1.java @@ -10,11 +10,14 @@ import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntitySign; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_18_R1.block.CraftSign; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -23,7 +26,7 @@ public final class HSign_v1_18_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_18_R1(Material type, String... lines) { + public HSign_v1_18_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -31,7 +34,8 @@ public HSign_v1_18_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); HCore.sendPacket(player, new PacketPlayOutBlockChange(blockPosition, Blocks.cg.n())); @@ -49,7 +53,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_18_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R2.java b/nms/1_18_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R2.java index f2217fac..dadaeacb 100644 --- a/nms/1_18_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R2.java +++ b/nms/1_18_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_18_R2.java @@ -10,11 +10,14 @@ import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntitySign; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_18_R2.block.CraftSign; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -23,7 +26,7 @@ public final class HSign_v1_18_R2 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_18_R2(Material type, String... lines) { + public HSign_v1_18_R2(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -31,7 +34,8 @@ public HSign_v1_18_R2(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); HCore.sendPacket(player, new PacketPlayOutBlockChange(blockPosition, Blocks.cg.n())); @@ -49,7 +53,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.b(); diff --git a/nms/1_8_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_8_R3.java b/nms/1_8_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_8_R3.java index 87cac058..1a2be073 100644 --- a/nms/1_8_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_8_R3.java +++ b/nms/1_8_R3/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_8_R3.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_8_R3.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_8_R3.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_8_R3 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_8_R3(Material type, String... lines) { + public HSign_v1_8_R3(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_8_R3(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a(); diff --git a/nms/1_9_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R1.java b/nms/1_9_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R1.java index 68918d70..8e95a093 100644 --- a/nms/1_9_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R1.java +++ b/nms/1_9_R1/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R1.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_9_R1.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_9_R1.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_9_R1 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_9_R1(Material type, String... lines) { + public HSign_v1_9_R1(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_9_R1(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a(); diff --git a/nms/1_9_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R2.java b/nms/1_9_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R2.java index 83e5cb52..f9a36cca 100644 --- a/nms/1_9_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R2.java +++ b/nms/1_9_R2/src/main/java/com/hakan/core/ui/sign/wrapper/HSign_v1_9_R2.java @@ -4,6 +4,7 @@ import com.hakan.core.ui.sign.HSign; import com.hakan.core.ui.sign.HSignHandler; import net.minecraft.server.v1_9_R2.*; +import org.apache.commons.lang.Validate; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; @@ -11,6 +12,8 @@ import org.bukkit.craftbukkit.v1_9_R2.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import javax.annotation.Nonnull; + /** * {@inheritDoc} */ @@ -19,7 +22,7 @@ public final class HSign_v1_9_R2 extends HSign { /** * {@inheritDoc} */ - public HSign_v1_9_R2(Material type, String... lines) { + public HSign_v1_9_R2(@Nonnull Material type, @Nonnull String... lines) { super(type, lines); } @@ -27,7 +30,8 @@ public HSign_v1_9_R2(Material type, String... lines) { * {@inheritDoc} */ @Override - public void open(Player player) { + public void open(@Nonnull Player player) { + Validate.notNull(player, "player cannot be null!"); BlockPosition blockPosition = new BlockPosition(player.getLocation().getBlockX(), 1, player.getLocation().getBlockZ()); PacketPlayOutBlockChange packet = new PacketPlayOutBlockChange(((CraftWorld) player.getWorld()).getHandle(), blockPosition); @@ -48,7 +52,9 @@ public void open(Player player) { * {@inheritDoc} */ @Override - public void listen(Player player, T packet) { + public void listen(@Nonnull Player player, @Nonnull T packet) { + Validate.notNull(player, "player cannot be null!"); + Validate.notNull(packet, "packet cannot be null!"); PacketPlayInUpdateSign packetPlayInUpdateSign = (PacketPlayInUpdateSign) packet; BlockPosition position = packetPlayInUpdateSign.a();