Fix resident rename

Even more than last time
This commit is contained in:
Norbi Peti 2020-03-21 19:19:57 +01:00
parent 6b68bdab0f
commit 7b505bb8e9
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -4,7 +4,6 @@ import buttondevteam.core.ComponentManager;
import buttondevteam.core.MainPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
@ -34,18 +33,19 @@ public class TownyComponent extends Component<MainPlugin> {
if (!ComponentManager.isEnabled(TownyComponent.class))
return;
Bukkit.getLogger().info("Renaming" + oldName + " in Towny to " + newName);
TownyUniverse tu = Towny.getPlugin(Towny.class).getTownyUniverse();
Resident resident = tu.getResidentMap().get(oldName.toLowerCase()); //The map keys are lowercase
TownyUniverse tu = TownyUniverse.getInstance();
try {
Resident resident = tu.getDataSource().getResident(oldName);
if (resident == null) {
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
} else if (tu.getDataSource().hasResident(newName)) {
Bukkit.getLogger().warning("Target resident name is already in use.");
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
} else
try {
} else {
tu.getDataSource().renamePlayer(resident, newName); //Fixed in Towny 0.91.1.2
Bukkit.getLogger().info("Renaming done.");
}
} catch (AlreadyRegisteredException e) {
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
} catch (NotRegisteredException e) {