Skip to content

Commit

Permalink
updated typo
Browse files Browse the repository at this point in the history
+ code cleanup
+ added comment to methods and classes
+ fixed random uuid issue
+ added @Weesli to plugin.yml authors
  • Loading branch information
poyrazinan committed Aug 24, 2024
1 parent d47b9ca commit 68a1530
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
9 changes: 6 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,19 @@
</dependency>
<!-- RClaim -->
<dependency>
<groupId>net.weesli</groupId>
<artifactId>weesli-rclaim</artifactId>
<groupId>com.github.Weesli</groupId>
<artifactId>RClaim</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

<!-- Repos -->
<repositories>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/Weesli/RClaim</url>
</repository>
<!-- FabledSkyblock -->
<repository>
<id>craftaro-minecraft-plugins</id>
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/xyz/geik/farmer/integrations/rclaim/RClaim.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,61 @@
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
*
*/
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) {
return RClaimAPI.getInstance().getClaim(regionID).getOwner();
}

/**
* 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) {
Claim claim = RClaimAPI.getInstance().getClaim(location.getChunk());
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<Claim> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -44,24 +56,34 @@ 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> 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())){
FarmerAPI.getFarmerManager().removeFarmer(e.getClaim().getID());
}
}

// 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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 68a1530

Please sign in to comment.