diff --git a/src/main/java/minevalley/core/api/ChatMenu.java b/src/main/java/minevalley/core/api/ChatMenu.java index 8e9a4fc7..b3d5518c 100644 --- a/src/main/java/minevalley/core/api/ChatMenu.java +++ b/src/main/java/minevalley/core/api/ChatMenu.java @@ -2,6 +2,7 @@ import minevalley.core.api.utils.ClickableMessage; +@Deprecated(forRemoval = true) public interface ChatMenu { /** diff --git a/src/main/java/minevalley/core/api/Core.java b/src/main/java/minevalley/core/api/Core.java index ed03a062..1032ac67 100644 --- a/src/main/java/minevalley/core/api/Core.java +++ b/src/main/java/minevalley/core/api/Core.java @@ -10,7 +10,7 @@ import minevalley.core.api.economy.BankAccount; import minevalley.core.api.enums.DebugType; import minevalley.core.api.enums.InterfaceItem; -import minevalley.core.api.enums.Server; +import minevalley.core.api.enums.ServerType; import minevalley.core.api.gui.GuiBuilder; import minevalley.core.api.gui.GuiItem; import minevalley.core.api.gui.MultiPageGui; @@ -27,6 +27,7 @@ import minevalley.core.api.regions.utils.Area; import minevalley.core.api.regions.utils.Boundary; import minevalley.core.api.regions.utils.FakeBlock; +import minevalley.core.api.team.Team; import minevalley.core.api.timing.Reminder; import minevalley.core.api.timing.RepeatingTimer; import minevalley.core.api.timing.Timer; @@ -331,11 +332,17 @@ public static UUID getUniqueId(@Nullable String name) { return server.getUniqueId(name); } + public static Team team() { + return server.team(); + } + /** * Sends a message to all online team-members * * @param message message as string */ + @Deprecated(forRemoval = true) + @SuppressWarnings("removal") public static void sendTeamChatMessage(@Nonnull String message) { server.sendTeamChatMessage(message); } @@ -345,7 +352,8 @@ public static void sendTeamChatMessage(@Nonnull String message) { * * @param message message as base-component (useful for clickable messages) */ - @Deprecated + @Deprecated(forRemoval = true) + @SuppressWarnings("removal") public static void sendTeamChatMessage(@Nonnull BaseComponent[] message) { server.sendTeamChatMessage(message); } @@ -867,6 +875,8 @@ public static HoverEvent createHoverText(@Nonnull String text) { * @return new chat menu */ @Contract("_ -> new") + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) public static ChatMenu createChatMenu(ChatMenu.Option... options) { return server.createChatMenu(options); } @@ -876,6 +886,8 @@ public static ChatMenu createChatMenu(ChatMenu.Option... options) { * * @return new chat menu */ + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) public static ChatMenu createChatMenu() { return server.createChatMenu(); } @@ -1787,7 +1799,18 @@ public static FakeArmorStand getFakeArmorStand(int id) { * @return server type */ @Nonnull - public static Server getServer() { + @Deprecated(forRemoval = true) + public static ServerType getServer() { + return server.getServerType(); + } + + /** + * Gets the server type. + * + * @return server type + */ + @Nonnull + public static ServerType getServerType() { return server.getServerType(); } diff --git a/src/main/java/minevalley/core/api/CoreServer.java b/src/main/java/minevalley/core/api/CoreServer.java index 03635a04..7681f777 100644 --- a/src/main/java/minevalley/core/api/CoreServer.java +++ b/src/main/java/minevalley/core/api/CoreServer.java @@ -9,7 +9,7 @@ import minevalley.core.api.discord.Webhook; import minevalley.core.api.economy.BankAccount; import minevalley.core.api.enums.DebugType; -import minevalley.core.api.enums.Server; +import minevalley.core.api.enums.ServerType; import minevalley.core.api.gui.GuiBuilder; import minevalley.core.api.gui.GuiItem; import minevalley.core.api.gui.MultiPageGui; @@ -26,6 +26,7 @@ import minevalley.core.api.regions.utils.Area; import minevalley.core.api.regions.utils.Boundary; import minevalley.core.api.regions.utils.FakeBlock; +import minevalley.core.api.team.Team; import minevalley.core.api.timing.Reminder; import minevalley.core.api.timing.RepeatingTimer; import minevalley.core.api.timing.Timer; @@ -54,6 +55,7 @@ import org.bukkit.util.Vector; import org.intellij.lang.annotations.Language; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; @@ -109,9 +111,12 @@ public interface CoreServer { @Nullable UUID getUniqueId(@Nullable String name); + Team team(); + + @Deprecated(forRemoval = true) void sendTeamChatMessage(@Nonnull String message); - @Deprecated + @Deprecated(forRemoval = true) void sendTeamChatMessage(@Nonnull BaseComponent[] message); void sendDebug(@Nonnull DebugType type, @Nonnull String message); @@ -124,12 +129,13 @@ public interface CoreServer { double getStatistic(@Nonnull String key) throws IllegalArgumentException; - @Nullable + @Contract("null -> null") String removeColorCodes(@Nullable String text); - @Nullable + @Contract("null -> null") String convertColorCodes(@Nullable String text); + @Contract("null -> false") boolean containsForForbiddenWords(@Nullable String string); @Nonnull @@ -137,8 +143,10 @@ public interface CoreServer { int getRandomInteger(int chars) throws IllegalArgumentException; + @Contract("null -> false") boolean isInteger(@Nullable String string); + @Contract("null -> false") boolean isDouble(@Nullable String string); @Nonnull @@ -148,10 +156,10 @@ public interface CoreServer { String formatRelativeTimestamp(long time); @Nonnull - GuiBuilder createGui(int size) throws IllegalArgumentException; + GuiBuilder createGui(@Nonnegative int size) throws IllegalArgumentException; @Nonnull - MultiPageGui createMultiPageGui(int size) throws IllegalArgumentException; + MultiPageGui createMultiPageGui(@Nonnegative int size) throws IllegalArgumentException; GuiItem createGuiItem(@Nonnull ItemStack itemStack, @Nullable Consumer consumer); @@ -174,28 +182,39 @@ public interface CoreServer { FakeBlock createFakeBlock(@Nonnull Block block, @Nonnull Material material, int data) throws IllegalArgumentException; @Nonnull + @Contract("_ -> new") ItemBuilder createItem(@Nonnull ItemStack itemStack) throws IllegalArgumentException; @Nonnull + @Contract("_ -> new") ItemBuilder createItem(@Nonnull Material material) throws IllegalArgumentException; @Nonnull + @Contract("_, _ -> new") ItemBuilder createItem(@Nonnull Material material, int data) throws IllegalArgumentException; @Nonnull + @Contract("_ -> new") ItemBuilder createItem(@Nonnull Player player) throws IllegalArgumentException; @Nonnull + @Contract("_ -> new") ItemBuilder createItem(@Nonnull UUID uniqueId) throws IllegalArgumentException; @Nonnull + @Contract("_, _ -> new") ItemBuilder createItem(@Nonnull String value, @Nonnull String signature) throws IllegalArgumentException; @Nonnull + @Contract("_ -> new") ItemBuilder createItem(String url) throws IllegalArgumentException; + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) ChatMenu createChatMenu(ChatMenu.Option... options); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) ChatMenu createChatMenu(); @Nonnull @@ -370,7 +389,7 @@ Apartment createApartment(@Nonnull Region region, @Nonnull Registrant landlord, FakeArmorStand getFakeArmorStand(int id); @Nonnull - Server getServerType(); + ServerType getServerType(); @Nullable String convertToTransparent(@Nullable String text) throws IllegalArgumentException; diff --git a/src/main/java/minevalley/core/api/Module.java b/src/main/java/minevalley/core/api/Module.java index ebb32d84..5d6f733a 100644 --- a/src/main/java/minevalley/core/api/Module.java +++ b/src/main/java/minevalley/core/api/Module.java @@ -1,6 +1,6 @@ package minevalley.core.api; -import minevalley.core.api.enums.Server; +import minevalley.core.api.enums.ServerType; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -15,5 +15,5 @@ String[] authors(); - Server[] servers() default {}; + ServerType[] servers() default {}; } diff --git a/src/main/java/minevalley/core/api/chat/MessageReceiver.java b/src/main/java/minevalley/core/api/chat/MessageReceiver.java new file mode 100644 index 00000000..ec8ead7a --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/MessageReceiver.java @@ -0,0 +1,226 @@ +package minevalley.core.api.chat; + +import lombok.NonNull; +import minevalley.core.api.chat.clickable.ChatMenu; +import minevalley.core.api.chat.clickable.ClickableOption; +import minevalley.core.api.chat.instruction.Instruction; +import minevalley.core.api.chat.types.ActionBarType; +import minevalley.core.api.chat.types.MessageType; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.TextComponent; +import org.jetbrains.annotations.Contract; + +import javax.annotation.Nonnull; +import java.util.function.Consumer; + +/** + * This interface is meant to simplify and standardize the way messages are sent to players. + * It's extended by other interfaces representing one or a group of users. This way a lot of boilerplate code (e.g. for-loops, streams and if-clauses) is omitted. + *

+ * Using the {@link ComponentLike} object enables a lot of features given by the Adventure API as used in Paper. + * While having a lot of features, most of the messages (that were formally sent as {@link String} objects) can be sent as a {@link TextComponent} via: + *

+ *     {@code
+ *     receiver.sendMessage(Component.text("Hello World!"));
+ *     }
+ * 
+ * There is a great documentation covering everything you need to know about {@link Component}, {@link TextComponent} and {@link ComponentLike} in the Adventure API documentation. + *

+ * The {@link Instruction} object is used to send instructions to the user. It can be sent in two ways: + *

+ * In both cases the user is able to hide the instruction by clicking a button that is added automatically. + * Doing so, the instruction will not show up in any circumstance (neither as question mark nor as a message in the chat). + *

+ * Note: The instruction id has to be unique (consider adding the feature- oder module name as a prefix to the id to prevent duplicates) and should not be changed afterward. + *

+ * Another addition to chat messages are {@link ClickableOption} objects. They are used to create menus that can be displayed to the user. + * Those are displayed underneath the message and can be used to trigger actions. They are displayed as buttons and can be used to trigger actions. + *

+ * Always give the user a clear description of what the buttons do. The user should be able to understand what happens when clicking a button without having to click it first. A useful hover text can enhance the user experience. + *

+ * Note: The {@link ClickableOption} allows to enable single use. This means that the user can only use the button once. + * This does not only mean that the user can only use the button once, but also that if the button was clicked once, all buttons of that message (including the clicked one) are disabled. + *

+ * All methods accepting {@link ClickableOption} objects return a {@link ChatMenu} object that can be used to disable the menu manually. + * + * @see Instruction + * @see ClickableOption + * @see Component + * @see TextComponent + * @see ComponentLike + */ +@SuppressWarnings("unused") +public interface MessageReceiver { + + /** + * Displays the given message in the receivers action bar. + * + * @param message the message to send + * @throws IllegalArgumentException if the message is null + */ + void sendActionBar(@Nonnull ComponentLike message) throws IllegalArgumentException; + + /** + * Displays the given message in the receivers action bar. + * + * @param type the type of message (defines the prefix) + * @param message the message to send + * @throws IllegalArgumentException if the type or message is null + */ + void sendActionBar(@Nonnull ActionBarType type, @Nonnull ComponentLike message) throws IllegalArgumentException; + + /** + * Sends an instruction to the receiver. + * + * @param instruction the instruction to send + * @throws IllegalArgumentException if the instruction is null + */ + void sendInstruction(@Nonnull Instruction instruction) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @throws IllegalArgumentException if the message is null + */ + void sendMessage(@Nonnull ComponentLike message) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @param instruction the instruction to send + * @throws IllegalArgumentException if the message or instruction is null + */ + void sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instruction) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the message or menu is null + */ + @Nonnull + @Contract("_, _ -> new") + ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param message the message to send + * @param instruction the instruction to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the message, instruction or menu is null + */ + @Nonnull + @Contract("_, _, _ -> new") + ChatMenu sendMessage(@Nonnull ComponentLike message, @Nonnull Instruction instruction, @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @throws IllegalArgumentException if the type or message is null + */ + void sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @param instruction the instruction to send + * @throws IllegalArgumentException if the type, message or instruction is null + */ + void sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull Instruction instruction) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the type, message or menu is null + */ + @Nonnull + @Contract("_, _, _ -> new") + ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to the receiver. + * + * @param type the type of message + * @param message the message to send + * @param instruction the instruction to send + * @param menu the menu to send + * @return the menu that was sent + * @throws IllegalArgumentException if the type, message, instruction or menu is null + */ + @Nonnull + @Contract("_, _, _, _ -> new") + ChatMenu sendMessage(@Nonnull MessageType type, @Nonnull ComponentLike message, @Nonnull Instruction instruction, @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Shows a title to the receiver. + * + * @param title the title to show + * @param subtitle the subtitle to show + * @throws IllegalArgumentException if the title or subtitle is null + */ + void showTitle(@Nonnull ComponentLike title, @Nonnull ComponentLike subtitle) throws IllegalArgumentException; + + /** + * Shows a title to the receiver. + * + * @param title the title to show + * @param subtitle the subtitle to show + * @param fadeIn the time in ticks for the title to fade in + * @param stay the time in ticks for the title to stay + * @param fadeOut the time in ticks for the title to fade out + * @throws IllegalArgumentException if the title or subtitle is null + */ + void showTitle(@Nonnull ComponentLike title, @Nonnull ComponentLike subtitle, int fadeIn, int stay, int fadeOut) throws IllegalArgumentException; + + /** + * Sends a message to the receiver and waits for an input. + * + * @param text the text to send + * @param callback the callback to call when the user inputs something + * @throws IllegalArgumentException if the text or callback is null + */ + void input(@NonNull String text, @NonNull Consumer callback) throws IllegalArgumentException; + + /** + * Sends a message to the receiver and waits for an input. + * + * @param text the text to send + * @param instruction the instruction to send + * @param callback the callback to call when the user inputs something + * @throws IllegalArgumentException if the text, instruction or callback is null + */ + void input(@NonNull String text, @Nonnull Instruction instruction, @NonNull Consumer callback) throws IllegalArgumentException; + + /** + * Checks if the receiver is currently in a chat input. + * + * @return true if the receiver is in a chat input, false otherwise + */ + @Contract(pure = true) + boolean isInChatInput(); + + /** + * Leaves the current chat input. + *

+ * If the receiver is not in a chat input, this method does nothing. + */ + void leaveChatInput(); +} diff --git a/src/main/java/minevalley/core/api/chat/MessageSender.java b/src/main/java/minevalley/core/api/chat/MessageSender.java new file mode 100644 index 00000000..0a63fd06 --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/MessageSender.java @@ -0,0 +1,60 @@ +package minevalley.core.api.chat; + +import minevalley.core.api.chat.clickable.ChatMenu; +import minevalley.core.api.chat.clickable.ClickableOption; +import minevalley.core.api.chat.instruction.Instruction; +import minevalley.core.api.utils.ClickableMessage; +import net.kyori.adventure.text.ComponentLike; +import org.jetbrains.annotations.Contract; + +import javax.annotation.Nonnull; + +@SuppressWarnings("unused") +public interface MessageSender { + + /** + * Sends a message to a receiver. + * + * @param receiver receiver to send the message to + * @param message message to send + * @throws IllegalArgumentException if the receiver or message is null + */ + void send(@Nonnull MessageReceiver receiver, @Nonnull ComponentLike message) throws IllegalArgumentException; + + /** + * Sends a message to a receiver with an instruction. + * + * @param receiver receiver to send the message to + * @param message message to send + * @param instruction instruction to send + * @throws IllegalArgumentException if the receiver, message or instruction is null + */ + void send(@Nonnull MessageReceiver receiver, @Nonnull ComponentLike message, @Nonnull Instruction instruction) throws IllegalArgumentException; + + /** + * Sends a message to a receiver with a menu. + * + * @param receiver receiver to send the message to + * @param message message to send + * @param menu menu to send + * @return the chat menu + * @throws IllegalArgumentException if the receiver, message or menu is null + */ + @Nonnull + @Contract("_, _, _ -> new") + ChatMenu send(@Nonnull MessageReceiver receiver, @Nonnull ComponentLike message, @Nonnull ClickableOption... menu) throws IllegalArgumentException; + + /** + * Sends a message to a receiver with an instruction and a menu. + * + * @param receiver receiver to send the message to + * @param message message to send + * @param instruction instruction to send + * @param menu menu to send + * @return the chat menu + * @throws IllegalArgumentException if the receiver, message, instruction or menu is null + */ + @Nonnull + @Contract("_, _, _, _ -> new") + ChatMenu send(@Nonnull MessageReceiver receiver, @Nonnull ComponentLike message, @Nonnull Instruction instruction, @Nonnull ClickableMessage... menu) throws IllegalArgumentException; +} diff --git a/src/main/java/minevalley/core/api/chat/clickable/ChatMenu.java b/src/main/java/minevalley/core/api/chat/clickable/ChatMenu.java new file mode 100644 index 00000000..95a35fab --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/clickable/ChatMenu.java @@ -0,0 +1,30 @@ +package minevalley.core.api.chat.clickable; + +import minevalley.core.api.chat.MessageReceiver; + +/** + * The {@code ChatMenu} is an interface that represents a chat menu that was sent to a {@link MessageReceiver}. + * It is used to determine if the menu is still enabled or not and to disable it manually. Doing so prevents unwanted inputs and is therefor recommended when the menu is no longer needed. + */ +@SuppressWarnings("unused") +public interface ChatMenu { + + /** + * Checks if the menu is still enabled. + *

+ * Note: ChatMenus will only be disabled if a {@link ClickableOption} was clicked that is marked as single-use or {@link #disable()} is called on this menu. + * + * @return true if the menu is still enabled, false otherwise + * @see #disable() + */ + boolean isEnabled(); + + /** + * Disables the menu. This prevents any further input from the user. + *

+ * Note: After disabling the menu, it is not possible to re-enable it. If menu is disabled, this method will do nothing. + * + * @see #isEnabled() + */ + void disable(); +} diff --git a/src/main/java/minevalley/core/api/chat/clickable/ClickableOption.java b/src/main/java/minevalley/core/api/chat/clickable/ClickableOption.java new file mode 100644 index 00000000..be750468 --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/clickable/ClickableOption.java @@ -0,0 +1,36 @@ +package minevalley.core.api.chat.clickable; + +import minevalley.core.api.chat.MessageReceiver; +import minevalley.core.api.users.OnlineUser; +import net.kyori.adventure.text.ComponentLike; + +import javax.annotation.Nonnull; +import java.util.function.Consumer; + +/** + * The {@code ClickableOption} is a record that represents a clickable option in a chat menu. + * It contains the text to be displayed, the hover text, a flag indicating if it is a single-use option, and a callback function that is executed when the option is clicked. + * If the option is single-use, not only the option itself is disabled, but also the entire {@link ChatMenu} is. + * + * @param text text that is displayed in the chat menu and can be clicked (use color to make it distinguish it from normal text) + * @param hoverText text that is displayed when the mouse hovers over the option + * @param singleUse if true, the option can only be used once (and the entire {@link ChatMenu} is disabled when this specific option is clicked) + * @param callback function that is executed when the option is clicked + * @see MessageReceiver + * @see ChatMenu + */ +public record ClickableOption(@Nonnull ComponentLike text, @Nonnull String hoverText, boolean singleUse, + @Nonnull Consumer callback) { + + public ClickableOption { + if (text == null) { + throw new IllegalArgumentException("text must not be null"); + } + if (hoverText == null) { + throw new IllegalArgumentException("hoverText must not be null"); + } + if (callback == null) { + throw new IllegalArgumentException("callback must not be null"); + } + } +} \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/chat/instruction/Instruction.java b/src/main/java/minevalley/core/api/chat/instruction/Instruction.java new file mode 100644 index 00000000..a1fff9cd --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/instruction/Instruction.java @@ -0,0 +1,30 @@ +package minevalley.core.api.chat.instruction; + +import minevalley.core.api.chat.MessageReceiver; + +import javax.annotation.Nonnull; + +/** + * The {@code Instruction} is a record that represents an instruction that can be sent to a {@link MessageReceiver}. + * It is used to provide additional information about any action this instruction is associated with. + * + * @param id the id of the instruction (is used to identify the instruction and should therefor be unique for each instruction but should be consistently used for the same instruction) + * @param text the text of the instruction + */ +public record Instruction(@Nonnull String id, @Nonnull String text) { + + public Instruction { + if (id == null) { + throw new IllegalArgumentException("id must not be null"); + } + if (text == null) { + throw new IllegalArgumentException("text must not be null"); + } + if (id.isBlank()) { + throw new IllegalArgumentException("id must not be blank"); + } + if (text.isBlank()) { + throw new IllegalArgumentException("text must not be blank"); + } + } +} \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/chat/types/ActionBarType.java b/src/main/java/minevalley/core/api/chat/types/ActionBarType.java new file mode 100644 index 00000000..fda30e0c --- /dev/null +++ b/src/main/java/minevalley/core/api/chat/types/ActionBarType.java @@ -0,0 +1,22 @@ +package minevalley.core.api.chat.types; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum ActionBarType { + + /** + * Used to signal the success of a process or action, by using the action-bar. + */ + SUCCESS("§a✔§8 ━ §7"), + + /** + * Used to signal the failure of a process or action, by using the action-bar. + */ + ERROR("§c✘§8 ━ §7"); + + private final String prefix; +} \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/enums/MessageType.java b/src/main/java/minevalley/core/api/chat/types/MessageType.java similarity index 75% rename from src/main/java/minevalley/core/api/enums/MessageType.java rename to src/main/java/minevalley/core/api/chat/types/MessageType.java index 63a8346d..691f8fa2 100644 --- a/src/main/java/minevalley/core/api/enums/MessageType.java +++ b/src/main/java/minevalley/core/api/chat/types/MessageType.java @@ -1,8 +1,9 @@ -package minevalley.core.api.enums; +package minevalley.core.api.chat.types; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import minevalley.core.api.enums.CustomCharacter; @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -21,7 +22,8 @@ public enum MessageType { /** * Used to signal a misspelled command. */ - SYNTAX_ERROR(ERROR.getValue() + "Korrekte Verwendung: §e/"), + @Deprecated(forRemoval = true) + SYNTAX_ERROR(ERROR.getPrefix() + "Korrekte Verwendung: §e/"), INFO(" §f" + CustomCharacter.MV + " §8━ §7"), @@ -32,12 +34,14 @@ public enum MessageType { /** * Used to signal the success of a process or action, by using the action-bar. */ + @Deprecated(forRemoval = true) ACTION_BAR_SUCCESS("§a✔§8 ━ §7"), /** * Used to signal the failure of a process or action, by using the action-bar. */ + @Deprecated(forRemoval = true) ACTION_BAR_ERROR("§c✘§8 ━ §7"); - private final String value; + private final String prefix; } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/enums/Server.java b/src/main/java/minevalley/core/api/enums/ServerType.java similarity index 75% rename from src/main/java/minevalley/core/api/enums/Server.java rename to src/main/java/minevalley/core/api/enums/ServerType.java index a4eaba33..53e21639 100644 --- a/src/main/java/minevalley/core/api/enums/Server.java +++ b/src/main/java/minevalley/core/api/enums/ServerType.java @@ -1,6 +1,6 @@ package minevalley.core.api.enums; -public enum Server { +public enum ServerType { MAIN, HUB, diff --git a/src/main/java/minevalley/core/api/npc/NPC.java b/src/main/java/minevalley/core/api/npc/NPC.java index 5d67e234..6575f96a 100644 --- a/src/main/java/minevalley/core/api/npc/NPC.java +++ b/src/main/java/minevalley/core/api/npc/NPC.java @@ -3,8 +3,8 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; -import minevalley.core.api.ChatMenu; import minevalley.core.api.armorstand.FakeArmorStand; +import minevalley.core.api.chat.MessageSender; import minevalley.core.api.modifiers.EquipmentModifier; import minevalley.core.api.modifiers.InteractionModifier; import minevalley.core.api.modifiers.LocationModifier; @@ -17,11 +17,10 @@ import org.bukkit.util.Vector; import java.util.List; -import java.util.function.BiConsumer; import java.util.function.Consumer; @SuppressWarnings("unused") -public interface NPC extends EquipmentModifier, InteractionModifier, LocationModifier, VisibilityModifier { +public interface NPC extends MessageSender, EquipmentModifier, InteractionModifier, LocationModifier, VisibilityModifier { String getName(); @@ -77,29 +76,47 @@ default void zoomIn(OnlineUser user) { NPC setChatPrefix(String prefix); + @Deprecated(forRemoval = true) void say(OnlineUser user, String text); + @Deprecated(forRemoval = true) void say(OnlineUser user, BaseComponent[] baseComponent); - void say(OnlineUser user, String text, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, String text, minevalley.core.api.ChatMenu chatMenu); - void say(OnlineUser user, BaseComponent[] baseComponent, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu); + @Deprecated(forRemoval = true) void say(OnlineUser user, String text, OnlineUser.Notice notice); + @Deprecated(forRemoval = true) void say(OnlineUser user, BaseComponent[] baseComponent, OnlineUser.Notice notice); - void say(OnlineUser user, String text, ChatMenu chatMenu, OnlineUser.Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, String text, minevalley.core.api.ChatMenu chatMenu, OnlineUser.Notice notice); - void say(OnlineUser user, BaseComponent[] baseComponent, ChatMenu chatMenu, OnlineUser.Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu, OnlineUser.Notice notice); + @Deprecated(forRemoval = true) void say(OnlineUser user, RandomText... text); - void say(OnlineUser user, ChatMenu chatMenu, RandomText... text); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, minevalley.core.api.ChatMenu chatMenu, RandomText... text); + @Deprecated(forRemoval = true) void say(OnlineUser user, OnlineUser.Notice notice, RandomText... text); - void say(OnlineUser user, ChatMenu chatMenu, OnlineUser.Notice notice, RandomText... text); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void say(OnlineUser user, minevalley.core.api.ChatMenu chatMenu, OnlineUser.Notice notice, RandomText... text); OnlineUser.Notice getTalkWithMeNotice(); diff --git a/src/main/java/minevalley/core/api/team/Team.java b/src/main/java/minevalley/core/api/team/Team.java new file mode 100644 index 00000000..87c84b61 --- /dev/null +++ b/src/main/java/minevalley/core/api/team/Team.java @@ -0,0 +1,27 @@ +package minevalley.core.api.team; + +import minevalley.core.api.chat.MessageReceiver; +import minevalley.core.api.chat.instruction.Instruction; + +import javax.annotation.Nonnull; + +@SuppressWarnings("unused") +public interface Team extends MessageReceiver { + + /** + * Send a message to the team chat. + * + * @param message The message to send. + * @throws IllegalArgumentException If the message is null. + */ + void sendTeamChatMessage(@Nonnull String message) throws IllegalArgumentException; + + /** + * Send a message to the team chat. + * + * @param message The message to send. + * @param instruction The instruction to send. + * @throws IllegalArgumentException If the message or instruction is null. + */ + void sendTeamChatMessage(@Nonnull String message, @Nonnull Instruction instruction) throws IllegalArgumentException; +} diff --git a/src/main/java/minevalley/core/api/users/OnlineUser.java b/src/main/java/minevalley/core/api/users/OnlineUser.java index 13112707..14815d73 100644 --- a/src/main/java/minevalley/core/api/users/OnlineUser.java +++ b/src/main/java/minevalley/core/api/users/OnlineUser.java @@ -1,13 +1,10 @@ package minevalley.core.api.users; -import lombok.AllArgsConstructor; -import lombok.Getter; import lombok.NonNull; -import lombok.Setter; -import minevalley.core.api.ChatMenu; +import minevalley.core.api.chat.MessageReceiver; +import minevalley.core.api.chat.types.MessageType; import minevalley.core.api.economy.AccountUser; import minevalley.core.api.economy.BankAccount; -import minevalley.core.api.enums.MessageType; import minevalley.core.api.enums.sounds.AmbientSound; import minevalley.core.api.enums.sounds.Sound; import minevalley.core.api.regions.utils.PlayerLocation; @@ -27,21 +24,29 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.function.Consumer; -public interface OnlineUser extends User { +@SuppressWarnings("unused") +public interface OnlineUser extends User, MessageReceiver { /** - * Gets the player-object of this user. + * Gets the player object of this user. * - * @return player-object of this user + * @return player object */ + @Nonnull Player getPlayer(); - User getUser(); - - void closeInventory(); + /** + * Closes the inventory of this user. + */ + default void closeInventory() { + getPlayer().closeInventory(); + } /** * Gets whether this user is currently logged in via labymod. @@ -50,30 +55,35 @@ public interface OnlineUser extends User { * * @return true, if this user is using labymod */ + @Contract(pure = true) boolean isUsingLabyMod(); /** - * Gets the version this user is currently playing with. + * Gets the version of the client this user is using. * - * @return current version + * @return client version */ + @Nonnull + @Contract(pure = true) McVersion getVersion(); - // Messages + // Sounds /** * Plays a specific sound. * * @param sound sound to be played + * @throws IllegalArgumentException if sound is null or an empty string */ - void playSound(Sound sound); + void playSound(@Nonnull String sound) throws IllegalArgumentException; /** * Plays a specific sound. * * @param sound sound to be played + * @throws IllegalArgumentException if sound is null */ - void playSound(String sound); + void playSound(@Nonnull Sound sound) throws IllegalArgumentException; /** * Plays a specific sound. @@ -81,9 +91,9 @@ public interface OnlineUser extends User { * @param sound sound to be played * @param location location where the sound will be played * @param spatial defines whether the sound should be spatial + * @throws IllegalArgumentException if sound or location is null, or the location is not in the same world as the user */ - void playSound(Sound sound, Location location, boolean spatial); - + void playSound(@Nonnull Sound sound, @Nonnull Location location, boolean spatial) throws IllegalArgumentException; /** * Plays a specific sound. @@ -91,42 +101,58 @@ public interface OnlineUser extends User { * @param sound sound to be played * @param location location where the sound will be played * @param spatial defines whether the sound should be spatial + * @throws IllegalArgumentException if sound or location is null, or the location is not in the same world as the user */ - void playSound(String sound, Location location, boolean spatial); + void playSound(@Nonnull String sound, @Nonnull Location location, boolean spatial) throws IllegalArgumentException; /** * Gets the ambient this user is currently hearing * * @return ambient this user is hearing */ + @Nonnull + @Contract(pure = true) AmbientSound getAmbient(); /** - * Sets the current ambient, the user will hear + * Sets the ambient this user is hearing * - * @param ambient ambient for the user to hear + * @param ambient ambient to be set + * @throws IllegalArgumentException if ambient is null */ - void setAmbient(AmbientSound ambient); + void setAmbient(@Nonnull AmbientSound ambient) throws IllegalArgumentException; /** * Starts the credits sequence. */ void sendCredits(); - void sendActionBar(@NonNull String message); + // Messages + + /** + * Sends a message to the user that is displayed in the action bar. + * + * @param message message to be sent + * @throws IllegalArgumentException if message is null or an empty string + */ + @Deprecated(forRemoval = true) + void sendActionBar(@Nonnull String message) throws IllegalArgumentException; /** - * Sends a tab-list view to this user. + * Sets the tab-list view of this user. * - * @param view view to be sent + * @param view tab-list view to be set + * @throws IllegalArgumentException if view is null */ - void sendTabListView(@NonNull TabListView view); + void setTabListView(@Nonnull TabListView view) throws IllegalArgumentException; /** * Gets the current tab-list view of this user. * * @return current tab-list view */ + @Nonnull + @Contract(pure = true) TabListView getTabListView(); /** @@ -134,6 +160,7 @@ public interface OnlineUser extends User { * * @param message message to be sent as string */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull String message); /** @@ -143,6 +170,7 @@ public interface OnlineUser extends User { * @param message message to be sent as string * @param notice notice that is sent to the user */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull String message, @NonNull Notice notice); /** @@ -151,6 +179,7 @@ public interface OnlineUser extends User { * @param messageType type of prefix to be displayed in front of the message * @param message message to be sent as string */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull MessageType messageType, @NonNull String message); /** @@ -161,6 +190,7 @@ public interface OnlineUser extends User { * @param message message to be sent as string * @param notice notice that is sent to the user */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull MessageType messageType, @NonNull String message, @NonNull Notice notice); /** @@ -169,6 +199,7 @@ public interface OnlineUser extends User { * @param messageType type of prefix to be displayed in front of the message * @param baseComponent message to be sent as string */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent); /** @@ -179,6 +210,7 @@ public interface OnlineUser extends User { * @param baseComponent message to be sent as string * @param notice notice that is sent to the user */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent, @NonNull Notice notice); /** @@ -186,6 +218,7 @@ public interface OnlineUser extends User { * * @param baseComponent base-component which can be created by "new ComponentBuilder().create()" */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull BaseComponent[] baseComponent); /** @@ -195,6 +228,7 @@ public interface OnlineUser extends User { * @param baseComponent base-component which can be created by "new ComponentBuilder().create()" * @param notice notice that is sent to the user */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull BaseComponent[] baseComponent, @NonNull Notice notice); @@ -204,8 +238,9 @@ public interface OnlineUser extends User { * @param message message to be sent as string * @param chatMenu menu to attach underneath the message */ - - void sendMessage(@NonNull String message, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull String message, minevalley.core.api.ChatMenu chatMenu); /** * Sends a message to this user like the default player.sendMessage()-method. Without any prefix or color. @@ -215,7 +250,9 @@ public interface OnlineUser extends User { * @param chatMenu menu to attach underneath the message * @param notice notice that is sent to the user */ - void sendMessage(@NonNull String message, ChatMenu chatMenu, @NonNull Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull String message, minevalley.core.api.ChatMenu chatMenu, @NonNull Notice notice); /** * Sends a message to this user with a specific prefix. @@ -224,7 +261,9 @@ public interface OnlineUser extends User { * @param message message to be sent as string * @param chatMenu menu to attach underneath the message */ - void sendMessage(@NonNull MessageType messageType, @NonNull String message, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull MessageType messageType, @NonNull String message, minevalley.core.api.ChatMenu chatMenu); /** * Sends a message to this user with a specific prefix. @@ -235,7 +274,9 @@ public interface OnlineUser extends User { * @param chatMenu menu to attach underneath the message * @param notice notice that is sent to the user */ - void sendMessage(@NonNull MessageType messageType, @NonNull String message, ChatMenu chatMenu, @NonNull Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull MessageType messageType, @NonNull String message, minevalley.core.api.ChatMenu chatMenu, @NonNull Notice notice); /** * Sends a message to this user with a specific prefix, using ComponentBuilders. @@ -244,7 +285,9 @@ public interface OnlineUser extends User { * @param baseComponent message to be sent as string * @param chatMenu menu to attach underneath the message */ - void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu); /** * Sends a message to this user with a specific prefix, using ComponentBuilders. @@ -255,7 +298,9 @@ public interface OnlineUser extends User { * @param chatMenu menu to attach underneath the message * @param notice notice that is sent to the user */ - void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent, ChatMenu chatMenu, @NonNull Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull MessageType messageType, @NonNull BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu, @NonNull Notice notice); /** * Sends a message to this user, with using ComponentBuilders. This way you can use hover and click-events and can take advantage of the clickable messages. @@ -263,7 +308,9 @@ public interface OnlineUser extends User { * @param baseComponent base-component which can be created by "new ComponentBuilder().create()" * @param chatMenu menu to attach underneath the message */ - void sendMessage(@NonNull BaseComponent[] baseComponent, ChatMenu chatMenu); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu); /** * Sends a message to this user, with using ComponentBuilders. This way you can use hover and click-events and can take advantage of the clickable messages. @@ -273,18 +320,22 @@ public interface OnlineUser extends User { * @param chatMenu menu to attach underneath the message * @param notice notice that is sent to the user */ - void sendMessage(@NonNull BaseComponent[] baseComponent, ChatMenu chatMenu, @NonNull Notice notice); + @SuppressWarnings("removal") + @Deprecated(forRemoval = true) + void sendMessage(@NonNull BaseComponent[] baseComponent, minevalley.core.api.ChatMenu chatMenu, @NonNull Notice notice); /** * Sends a message to the user providing useful side information. The user can click a button so that the message will not be sent the next time. * * @param notice notice that is sent to the user */ + @Deprecated(forRemoval = true) void sendMessage(@NonNull Notice notice); /** * Sends the usual "Unbekannter Befehl!"-error to the user. Mostly used when a player is trying to execute a command that they are not allowed to do. */ + @Deprecated(forRemoval = true) void sendError(); // ChatInput @@ -295,6 +346,7 @@ public interface OnlineUser extends User { * @param message the message to be sent to the player. Normally containing a question or a request to put in any data * @param callback the callback that is called when the player makes an entry in the chat-interface. The consumer contains a string of the message. */ + @Deprecated(forRemoval = true) void input(@NonNull String message, @NonNull Consumer callback); /** @@ -302,11 +354,14 @@ public interface OnlineUser extends User { * * @return true, if the user is in a chat input */ + @Deprecated(forRemoval = true) + @Contract(pure = true) boolean isInChatInput(); /** * Lets the user leave his current chat input */ + @Deprecated(forRemoval = true) void leaveChatInput(); /** @@ -318,7 +373,7 @@ public interface OnlineUser extends User { * @param callback callback with the chosen bank account * @param requiredPermissions permissions that need to be granted to this user to let him choose the specific bank account */ - void askForBankAccount(Consumer callback, AccountUser.BankAccountUserPermission... requiredPermissions); + void askForBankAccount(@Nonnull Consumer callback, @Nonnull AccountUser.BankAccountUserPermission... requiredPermissions) throws IllegalArgumentException; // FractionService @@ -328,9 +383,10 @@ public interface OnlineUser extends User { * * @return users fraction */ + @Contract(pure = true) Fraction getFractionService(); - void enterFractionService(Fraction service); + void enterFractionService(@Nonnull Fraction service) throws IllegalArgumentException; void leaveFractionService(); @@ -341,6 +397,7 @@ public interface OnlineUser extends User { * * @return true, if the user is part of the server-team (and in team-service) */ + @Contract(pure = true) boolean isTeamler(); /** @@ -348,6 +405,7 @@ public interface OnlineUser extends User { * * @return true, if the user is team-plus-member */ + @Contract(pure = true) boolean isTeamPlus(); /** @@ -355,6 +413,8 @@ public interface OnlineUser extends User { * * @return users team-rank */ + @Nullable + @Contract(pure = true) TeamRank getTeamRank(); /** @@ -363,6 +423,8 @@ public interface OnlineUser extends User { * * @return [custom] team rank name */ + @Nullable + @Contract(pure = true) String getCustomTeamRankName(); /** @@ -373,6 +435,7 @@ public interface OnlineUser extends User { * * @return true, if this user is displayed as team member in chat, tab list, etc. */ + @Contract(pure = true) boolean isDisplayedAsTeamler(); /** @@ -381,13 +444,15 @@ public interface OnlineUser extends User { * @param ranks list of team-ranks to be checked for * @return true, if the user has one of the ranks */ - boolean hasTeamRank(@NonNull TeamRank... ranks); + @Contract(pure = true) + boolean hasTeamRank(@Nonnull TeamRank... ranks); /** * Gets whether the user is allowed to use a general-key * * @return true, if the player is allowed to use a general-key */ + @Contract(pure = true) boolean isAllowedToUseGeneralKey(); /** @@ -395,40 +460,43 @@ public interface OnlineUser extends User { * * @return true, if the player is using a general-key */ + @Contract(pure = true) boolean isUsingGeneralKey(); /** * Lets the user enter the team-service. If the user isn't teamler, nothing happens. */ - void joinTeamService(); + void joinTeamService() throws UnsupportedOperationException, IllegalStateException; /** * Lets the user leave the team-service. */ - void leaveTeamService(); + void leaveTeamService() throws IllegalStateException; /** * Gets whether the user is allowed to enter the support-service. * * @return true, if the user is allowed to enter the support-service */ + @Contract(pure = true) boolean canEnterSupportService(); /** * Lets the user enter the support-service. If the user isn't allowed to, nothing happens. */ - void joinSupportService(); + void joinSupportService() throws UnsupportedOperationException, IllegalStateException; /** * Lets the user leave the support-service. */ - void leaveSupportService(); + void leaveSupportService() throws IllegalStateException; /** * Gets whether the user is marked as server-operator (!= OP-permission) * * @return true, if the user is marked as server-operator */ + @Contract(pure = true) boolean isOperator(); /** @@ -436,17 +504,19 @@ public interface OnlineUser extends User { * * @return true, if the user is in support-service */ + @Contract(pure = true) boolean isInSupportService(); void heal(); - void revive(); + void revive() throws IllegalStateException; /** * Gets whether the user has reached the maximum idle time and is marked as afk. * * @return true, if the user reached the maximum idle time */ + @Contract(pure = true) boolean isIdle(); /** @@ -454,6 +524,7 @@ public interface OnlineUser extends User { * * @return true, if this user is vanished */ + @Contract(pure = true) boolean isVanish(); /** @@ -462,25 +533,26 @@ public interface OnlineUser extends User { * * @param vanish vanish state */ - void setVanish(boolean vanish); + void setVanish(boolean vanish) throws UnsupportedOperationException; /** * Imprisons this user. * * @param duration duration in minutes */ - void imprison(int duration); + void imprison(int duration) throws UnsupportedOperationException, IllegalStateException; /** * Releases this user from prison (im imprisoned). */ - void releaseFromPrison(); + void releaseFromPrison() throws IllegalStateException; /** * Gets whether the user has completed registration on our network. * * @return true, if the user is registered */ + @Contract(pure = true) boolean isRegistered(); /** @@ -489,18 +561,20 @@ public interface OnlineUser extends User { * @param block block to check * @return true, if this user is allowed to break/place/use a block here */ + @Contract(pure = true) boolean isAllowedToUse(Block block); - void changeSign(Block block, final String line1, final String line2, final String line3, final String line4); + void changeSign(@Nonnull Block block, @Nonnull String line1, @Nonnull String line2, @Nonnull String line3, @Nonnull String line4) throws IllegalArgumentException; - void resetSign(Block block); + void resetSign(@Nonnull Block block) throws IllegalArgumentException; - void setNavigationTarget(Location location); + void setNavigationTarget(@Nonnull Location location) throws IllegalArgumentException; void resetNavigationTarget(); void updateLatestJoin(); + @Contract(pure = true) default LoadedVehicle getVehicle() { final Entity vehicle = getPlayer().getVehicle(); if (vehicle == null) return null; @@ -510,24 +584,28 @@ default LoadedVehicle getVehicle() { void checkRegistration(); - default void chat(ChatType type, String message) { + default void chat(@Nonnull ChatType type, @Nonnull String message) throws IllegalArgumentException { ChatHandler.chat(this, type, message); } - default void chat(String message) { - chat(ChatType.NORMAL, message); + default void chat(@Nonnull String message) throws IllegalArgumentException { + ChatHandler.chat(this, ChatType.NORMAL, message); } - void performCommand(String command); + void performCommand(@Nonnull String command) throws IllegalArgumentException; - boolean addItem(ItemStack item); + boolean addItem(@Nonnull ItemStack item) throws IllegalArgumentException; + @Contract(pure = true) int getAmountOfFreeInventorySlots(); + @Contract(pure = true) default boolean hasFreeInventorySlot() { return getAmountOfFreeInventorySlots() != 0; } + @Contract(pure = true) + @Nonnull PlayerLocation getLocation(); /** @@ -554,6 +632,7 @@ default boolean hasFreeInventorySlot() { */ ClickableMessage createClickableMessage(boolean selfCancelling, Runnable callback); + @Deprecated(forRemoval = true) ClickEvent createClickEvent(boolean selfCancelling, Runnable callback); /** @@ -565,7 +644,7 @@ default boolean hasFreeInventorySlot() { * @param range maximum range for the result to be true * @return true, if user is in range */ - boolean isInCubicRange(Location location, int range); + boolean isInCubicRange(@Nonnull Location location, int range) throws IllegalArgumentException; /** * Checks whether the user is in a virtual sphere whose radius is the square root of specified range. @@ -577,7 +656,7 @@ default boolean hasFreeInventorySlot() { * @param rangeSquared maximum range for the result to be true * @return true, if user is in range */ - boolean isInSquaredRange(Location location, int rangeSquared); + boolean isInSquaredRange(@Nonnull Location location, int rangeSquared) throws IllegalArgumentException; /** * Checks whether the user is in a virtual sphere whose radius is the specified range. @@ -586,15 +665,11 @@ default boolean hasFreeInventorySlot() { * @param range maximum range for the result to be true * @return true, if user is in range */ - default boolean isInRange(Location location, int range) { + default boolean isInRange(@Nonnull Location location, int range) throws IllegalArgumentException { return isInSquaredRange(location, range * range); } - @Getter - @Setter - @AllArgsConstructor - class Notice { - String id, message; + record Notice(@Nonnull String id, @Nonnull String message) { } enum ChatType { diff --git a/src/main/java/minevalley/core/api/users/enums/McVersion.java b/src/main/java/minevalley/core/api/users/enums/McVersion.java index b6985ae1..14ef3a2f 100644 --- a/src/main/java/minevalley/core/api/users/enums/McVersion.java +++ b/src/main/java/minevalley/core/api/users/enums/McVersion.java @@ -7,16 +7,29 @@ @Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public enum McVersion { + + @Deprecated(forRemoval = true) V1_12(335), + @Deprecated(forRemoval = true) V1_14(477), + @Deprecated(forRemoval = true) V1_16(735), - V1_18(757); + @Deprecated(forRemoval = true) + V1_18(757), /** - * Note: The client's protocol version may differ from those specified here. - * There are many sub-versions like 1.12.1 and 1.12.2. To get the currently used version, - * check if the client's protocol number is between two of those specified here. - * If the client is use a version lower than 1.12, it will not be able to join the server. + * 1.20.0 and 1.20.1 share the same protocol version and are therefore indistinguishable for the server. */ + V1_20_1(763), + + V1_20_2(764), + + /** + * 1.20.3 and 1.20.4 share the same protocol version and are therefore indistinguishable for the server. + */ + V1_20_4(765), + + V1_20_5(766); + private final int protocolVersion; } \ No newline at end of file diff --git a/src/main/java/minevalley/core/api/utils/ChatHandler.java b/src/main/java/minevalley/core/api/utils/ChatHandler.java index 9d9c3ee8..ab39cb46 100644 --- a/src/main/java/minevalley/core/api/utils/ChatHandler.java +++ b/src/main/java/minevalley/core/api/utils/ChatHandler.java @@ -3,16 +3,18 @@ import lombok.Setter; import minevalley.core.api.users.OnlineUser; +import javax.annotation.Nonnull; + public final class ChatHandler { @Setter private static Manager manager; - public static void chat(OnlineUser user, OnlineUser.ChatType chatType, String text) { + public static void chat(@Nonnull OnlineUser user, @Nonnull OnlineUser.ChatType chatType, @Nonnull String text) throws IllegalArgumentException { manager.chat(user, chatType, text); } public interface Manager { - void chat(OnlineUser user, OnlineUser.ChatType chatType, String text); + void chat(@Nonnull OnlineUser user, @Nonnull OnlineUser.ChatType chatType, @Nonnull String text) throws IllegalArgumentException; } } \ No newline at end of file