From 68a15308f94f7c01196eb3defc13559138f1f307 Mon Sep 17 00:00:00 2001 From: poyraz Date: Sun, 25 Aug 2024 01:45:16 +0300 Subject: [PATCH] updated typo + code cleanup + added comment to methods and classes + fixed random uuid issue + added @Weesli to plugin.yml authors --- pom.xml | 9 +++-- .../farmer/integrations/rclaim/RClaim.java | 24 ++++++++----- .../integrations/rclaim/RClaimListener.java | 36 +++++++++++++++---- src/main/resources/plugin.yml | 2 +- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 4dcace47..7d650639 100644 --- a/pom.xml +++ b/pom.xml @@ -128,16 +128,19 @@ - net.weesli - weesli-rclaim + com.github.Weesli + RClaim 1.2.0 - provided + + github + https://maven.pkg.github.com/Weesli/RClaim + craftaro-minecraft-plugins diff --git a/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaim.java b/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaim.java index 133e38c9..fd78776d 100644 --- a/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaim.java +++ b/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaim.java @@ -3,13 +3,19 @@ import net.weesli.rClaim.api.RClaimAPI; import net.weesli.rClaim.utils.Claim; import org.bukkit.Location; -import org.bukkit.event.Listener; import xyz.geik.farmer.integrations.Integrations; import java.util.Optional; import java.util.UUID; +/** + * Main RClaim integration class that extends Integration + * + * @author Weesli + * @since 25.08.2024 + */ public class RClaim extends Integrations { + /** * Constructor register event of super class * @@ -17,9 +23,10 @@ public class RClaim extends Integrations { public RClaim() {super(new RClaimListener());} /** + * Gets UUID of owner from RClaimAPI by regionId * * @param regionID id of region - * @return + * @return UUID of region owner */ @Override public UUID getOwnerUUID(String regionID) { @@ -27,9 +34,10 @@ public UUID getOwnerUUID(String regionID) { } /** + * Gets UUID of owner from RClaimAPI by location * * @param location location of region - * @return + * @return UUID of region owner */ @Override public UUID getOwnerUUID(Location location) { @@ -37,21 +45,19 @@ public UUID getOwnerUUID(Location location) { if (claim != null){ return claim.getOwner(); } - return UUID.randomUUID(); + return null; } /** + * Gets getRegionID of location * * @param location location of region - * @return + * @return id of region */ @Override public String getRegionID(Location location) { Claim claim = RClaimAPI.getInstance().getClaim(location.getChunk()); Optional center_claim = RClaimAPI.getInstance().getClaims().stream().filter(c -> c.isOwner(claim.getOwner())).filter(Claim::isCenter).findFirst(); - if (center_claim.isPresent()){ - return center_claim.get().getID(); - } - return ""; + return center_claim.map(Claim::getID).orElse(null); } } diff --git a/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaimListener.java b/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaimListener.java index ac55cd98..71173c99 100644 --- a/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaimListener.java +++ b/src/main/java/xyz/geik/farmer/integrations/rclaim/RClaimListener.java @@ -21,10 +21,19 @@ import java.util.Optional; import java.util.UUID; +/** + * RClaim Integration Listener class + * + * @author Weesli + * @since 25.08.2024 + */ public class RClaimListener implements Listener { - - // When a player creates a claim, if the automatic farmer is on, a farmer is added to the claim point. + /** + * When a player creates a claim, if the automatic farmer is on, a farmer is added to the claim point. + * + * @param e Event of ClaimCrateEvent + */ @EventHandler public void createClaim(ClaimCreateEvent e){ String claimId = e.getClaim().getID(); @@ -33,8 +42,11 @@ public void createClaim(ClaimCreateEvent e){ ChatUtils.sendMessage(e.getSender(), Main.getLangFile().getMessages().getBoughtFarmer()); } } - // After a claimant adds a player to their territory, the added player is granted farmer access + /** + * After a claimant adds a player to their territory, the added player is granted farmer access + * @param e Event of TrustedPlayerEvent + */ @EventHandler public void trustPlayer(TrustedPlayerEvent e){ Claim claim = RClaimAPI.getInstance().getClaims().stream().filter(c -> c.isOwner(e.getTruster().getUniqueId())).toList().get(0); @@ -44,16 +56,23 @@ public void trustPlayer(TrustedPlayerEvent e){ farmer.addUser(target,Bukkit.getOfflinePlayer(target).getName(), FarmerPerm.COOP); } - // If the requester removes a trusted player from the demand zone, farmer access is terminated + /** + * If the requester removes a trusted player from the demand zone, farmer access is terminated + * @param e Event of UnTrustedPlayerEvent + */ @EventHandler - public void untrustPlayer(UnTrustedPlayerEvent e){ + public void unTrustPlayer(UnTrustedPlayerEvent e){ Claim claim = RClaimAPI.getInstance().getClaims().stream().filter(c -> c.isOwner(e.getTruster().getUniqueId())).toList().get(0); if (!FarmerManager.getFarmers().containsKey(claim.getID())) return; Farmer farmer = FarmerManager.getFarmers().get(claim.getID()); Optional user = farmer.getUsersWithoutOwner().stream().filter(u -> u.getUuid().equals(e.getTrusted().getUniqueId())).findFirst(); user.ifPresent(farmer::removeUser); } - // When a claim is deleted, the farmer is removed as well + + /** + * When a claim is deleted, the farmer is removed as well + * @param e Event of UnTrustedPlayerEvent + */ @EventHandler public void deleteClaim(ClaimDeleteEvent e){ if (FarmerManager.farmers.containsKey(e.getClaim().getID())){ @@ -61,7 +80,10 @@ public void deleteClaim(ClaimDeleteEvent e){ } } - // When the farmer is subsequently purchased, access is granted to all members in the Region. + /** + * When the farmer is subsequently purchased, access is granted to all members in the Region. + * @param e Event of buyFarmer + */ @EventHandler public void buyFarmer(FarmerBoughtEvent e) { String claimId = e.getFarmer().getRegionID(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ce5d97f4..7f2d5fdb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: Farmer -author: Geik, Amowny, WaterArchery, hyperion, rudde, mehmet-27, Khontrom +author: Geik, Amowny, WaterArchery, hyperion, rudde, mehmet-27, Khontrom, weesli main: xyz.geik.farmer.Main version: v6-b107 api-version: 1.13