Fix resident rename
Even more than last time
This commit is contained in:
parent
6b68bdab0f
commit
7b505bb8e9
1 changed files with 15 additions and 15 deletions
|
@ -4,7 +4,6 @@ import buttondevteam.core.ComponentManager;
|
||||||
import buttondevteam.core.MainPlugin;
|
import buttondevteam.core.MainPlugin;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
import buttondevteam.lib.architecture.Component;
|
import buttondevteam.lib.architecture.Component;
|
||||||
import com.palmergames.bukkit.towny.Towny;
|
|
||||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||||
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
@ -34,18 +33,19 @@ public class TownyComponent extends Component<MainPlugin> {
|
||||||
if (!ComponentManager.isEnabled(TownyComponent.class))
|
if (!ComponentManager.isEnabled(TownyComponent.class))
|
||||||
return;
|
return;
|
||||||
Bukkit.getLogger().info("Renaming" + oldName + " in Towny to " + newName);
|
Bukkit.getLogger().info("Renaming" + oldName + " in Towny to " + newName);
|
||||||
TownyUniverse tu = Towny.getPlugin(Towny.class).getTownyUniverse();
|
TownyUniverse tu = TownyUniverse.getInstance();
|
||||||
Resident resident = tu.getResidentMap().get(oldName.toLowerCase()); //The map keys are lowercase
|
try {
|
||||||
|
Resident resident = tu.getDataSource().getResident(oldName);
|
||||||
if (resident == null) {
|
if (resident == null) {
|
||||||
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
|
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
|
||||||
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
|
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
|
||||||
} else if (tu.getDataSource().hasResident(newName)) {
|
} else if (tu.getDataSource().hasResident(newName)) {
|
||||||
Bukkit.getLogger().warning("Target resident name is already in use.");
|
Bukkit.getLogger().warning("Target resident name is already in use.");
|
||||||
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
|
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
|
||||||
} else
|
} else {
|
||||||
try {
|
|
||||||
tu.getDataSource().renamePlayer(resident, newName); //Fixed in Towny 0.91.1.2
|
tu.getDataSource().renamePlayer(resident, newName); //Fixed in Towny 0.91.1.2
|
||||||
Bukkit.getLogger().info("Renaming done.");
|
Bukkit.getLogger().info("Renaming done.");
|
||||||
|
}
|
||||||
} catch (AlreadyRegisteredException e) {
|
} catch (AlreadyRegisteredException e) {
|
||||||
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
|
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
|
|
Loading…
Reference in a new issue