Skip to content

Commit

Permalink
Fix NoSuchElementException that occurs when attempting to modify role…
Browse files Browse the repository at this point in the history
…s for users not in the cache
  • Loading branch information
adabugra committed Nov 25, 2024
1 parent c15b73f commit e47e88a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/xyz/geik/farmer/api/managers/FarmerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void changeOwner(UUID oldOwner, UUID newOwner, String regionId) {
// Replaces old owner role to coop on db
Main.getInstance().getSql().updateRole(oldOwner, 1, newFarmer.getId());
// Replace old owner role to coop on cache
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(oldOwner)).findFirst().get().setPerm(FarmerPerm.MEMBER);
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(oldOwner)).findFirst().ifPresent(user -> user.setPerm(FarmerPerm.MEMBER));
// Adds player if not exists on farmer users
if (newFarmer.getUsers().stream().noneMatch(user -> user.getUuid().equals(newOwner)))
/*
Expand All @@ -87,7 +87,7 @@ public void changeOwner(UUID oldOwner, UUID newOwner, String regionId) {
// Replaces new owner role to owner on db
Main.getInstance().getSql().updateRole(newOwner, 2, newFarmer.getId());
// Replaces new owner role to owner on cache
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(newOwner)).findFirst().get().setPerm(FarmerPerm.OWNER);
newFarmer.getUsers().stream().filter(user -> user.getUuid().equals(newOwner)).findFirst().ifPresent(user -> user.setPerm(FarmerPerm.OWNER));
}
// Update farmer regionId if same as ownerid
if (regionId.equals(oldOwner.toString()))
Expand Down

0 comments on commit e47e88a

Please sign in to comment.