Skip to content

Commit

Permalink
Merge pull request #110 from adabugra/fix/towny-npe-nosuchelement
Browse files Browse the repository at this point in the history
Fix NPE and NoSuchElementException in Towny integration
  • Loading branch information
poyrazinan authored Nov 25, 2024
2 parents 2a9729d + e47e88a commit bf514d5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<version>0.100.3.0</version>
<version>0.100.4.0</version>
<scope>provided</scope>
</dependency>
<!-- LandsAPI -->
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.palmergames.bukkit.towny.event.NewTownEvent;
import com.palmergames.bukkit.towny.event.TownAddResidentEvent;
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
import com.palmergames.bukkit.towny.event.player.PlayerEntersIntoTownBorderEvent;
import com.palmergames.bukkit.towny.event.town.TownKickEvent;
import com.palmergames.bukkit.towny.event.town.TownLeaveEvent;
import com.palmergames.bukkit.towny.event.town.TownMayorChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -77,7 +74,7 @@ public void townResidentAddEvent(@NotNull TownAddResidentEvent e) {
String townID = e.getTown().getUUID().toString();
if (!FarmerManager.getFarmers().containsKey(townID))
return;
UUID member = e.getResident().getPlayer().getUniqueId();
UUID member = e.getResident().getUUID();
Farmer farmer = FarmerManager.getFarmers().get(townID);
if (farmer.getUsers().stream().noneMatch(user -> user.getUuid().equals(member)))
farmer.addUser(member, Bukkit.getOfflinePlayer(member).getName(), FarmerPerm.COOP);
Expand Down

0 comments on commit bf514d5

Please sign in to comment.