From 5cf3ecc008c11e951d96f626541c7961637effaa Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 1 Sep 2016 18:48:11 +0200 Subject: [PATCH] Probably fixed a rename bug --- src/buttondevteam/bucket/core/TBMCPlayer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/buttondevteam/bucket/core/TBMCPlayer.java b/src/buttondevteam/bucket/core/TBMCPlayer.java index 972ba0f..4ee3001 100644 --- a/src/buttondevteam/bucket/core/TBMCPlayer.java +++ b/src/buttondevteam/bucket/core/TBMCPlayer.java @@ -11,6 +11,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.TownyUniverse; /** @@ -94,7 +95,14 @@ public class TBMCPlayer { if (!p.getName().equals(player.PlayerName)) { System.out.println("Renaming " + player.PlayerName + " to " + p.getName()); TownyUniverse tu = Towny.getPlugin(Towny.class).getTownyUniverse(); - tu.getResidentMap().get(player.PlayerName).setName(p.getName()); + Resident resident = tu.getResidentMap().get(player.PlayerName); + if (resident == null) + System.out.println("Resident not found - couldn't rename in Towny."); + else if (tu.getResidentMap().contains(p.getName())) + System.out.println("Target resident name is already in use."); // TODO: Handle + else + resident.setName(p.getName()); + player.PlayerName = p.getName(); System.out.println("Renaming done."); }