From 0a9d750d3e3a4a12c237bd42a10ef3e2b7580dac Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 26 Aug 2023 10:37:21 -0500 Subject: [PATCH] clean: wardrobe javadocs and Lombok --- .../api/events/PlayerWardrobeEnterEvent.java | 11 +--- .../hmccosmetics/config/Wardrobe.java | 56 +++++++++---------- .../hmccosmetics/config/WardrobeLocation.java | 35 ++++++------ 3 files changed, 46 insertions(+), 56 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/events/PlayerWardrobeEnterEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/events/PlayerWardrobeEnterEvent.java index 16e9a25f..d349d8f6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/events/PlayerWardrobeEnterEvent.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/events/PlayerWardrobeEnterEvent.java @@ -2,6 +2,8 @@ package com.hibiscusmc.hmccosmetics.api.events; import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import lombok.Getter; +import lombok.Setter; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -12,6 +14,7 @@ import org.jetbrains.annotations.NotNull; public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; + @Getter @Setter private Wardrobe wardrobe; public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) { @@ -48,12 +51,4 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can public static HandlerList getHandlerList() { return handlers; } - - public void setWardrobe(Wardrobe wardrobe) { - this.wardrobe = wardrobe; - } - - public Wardrobe getWardrobe() { - return wardrobe; - } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java index 8bbe1d84..52a54c69 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java @@ -1,56 +1,52 @@ package com.hibiscusmc.hmccosmetics.config; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; public class Wardrobe { - private String id; + @Getter + private final String id; + @Getter @Setter private int distance = WardrobeSettings.getDisplayRadius(); + @Getter @Setter private String permission; + @Getter @Setter private WardrobeLocation location; - public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance) { + /** + * This creates a Wardrobe object with all the information that a user will need when entering. + * @param id The id of the wardrobe + * @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work + * @param permission The permission required to enter the wardrobe, if null, no permission is required + * @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance + */ + public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) { this.id = id; this.location = location; if (permission != null) this.permission = permission; if (distance != -1) this.distance = distance; } - public String getId() { - return id; - } - - public WardrobeLocation getLocation() { - return location; - } - - public void setDistance(int distance) { - this.distance = distance; - } - - public void setPermission(String permission) { - this.permission = permission; - } - + /** + * This checks if the wardrobe has a permission. If it's null, no permission is required and will return false. If it's not null, it will return true. + * @return if the wardrobe has a permission + */ public boolean hasPermission() { return permission != null; } - public int getDistance() { - return distance; - } - public String getPermission() { - return permission; - } - - public void setLocation(WardrobeLocation location) { - this.location = location; - } - - public boolean canEnter(CosmeticUser user) { + /** + * Calculates if a player can enter a wardrobe. Will return true if the player can enter, else false. + * @param user The user that is trying to enter the wardrobe + * @return if the player can enter the wardrobe + */ + public boolean canEnter(@NotNull CosmeticUser user) { Location wardrobeLocation = location.getNpcLocation(); Location location = user.getEntity().getLocation(); if (wardrobeLocation == null) return false; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java index f540ee07..4cb937c7 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/WardrobeLocation.java @@ -1,37 +1,36 @@ package com.hibiscusmc.hmccosmetics.config; +import lombok.Getter; import lombok.Setter; import org.bukkit.Location; +import org.jetbrains.annotations.Nullable; public class WardrobeLocation { - @Setter + @Getter @Setter private Location npcLocation; - @Setter + @Getter @Setter private Location viewerLocation; - @Setter + @Getter @Setter private Location leaveLocation; - public WardrobeLocation(Location npcLocation, Location viewerLocation, Location leaveLocation) { + /** + * This creates a WardrobeLocation object with the 3 locations that are required for a wardrobe to work + * @param npcLocation The location of the NPC + * @param viewerLocation The location of the viewer + * @param leaveLocation The location that the player will be teleported to when they leave the wardrobe if return-last-location in the config is false + */ + public WardrobeLocation(@Nullable Location npcLocation, @Nullable Location viewerLocation, @Nullable Location leaveLocation) { this.npcLocation = npcLocation; this.viewerLocation = viewerLocation; this.leaveLocation = leaveLocation; } - public Location getNpcLocation() { - return npcLocation.clone(); - } - - public Location getViewerLocation() { - return viewerLocation.clone(); - } - - public Location getLeaveLocation() { - return leaveLocation.clone(); - } - + /** + * Checks if any of the locations are null + * @return true if all locations are not null, else false + */ public boolean hasAllLocations() { - if (npcLocation == null || viewerLocation == null || leaveLocation == null) return false; - return true; + return npcLocation != null && viewerLocation != null && leaveLocation != null; } }