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,22 +33,23 @@ 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 {
|
||||||
if (resident == null) {
|
Resident resident = tu.getDataSource().getResident(oldName);
|
||||||
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
|
if (resident == null) {
|
||||||
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
|
Bukkit.getLogger().warning("Resident not found - couldn't rename in Towny.");
|
||||||
} else if (tu.getDataSource().hasResident(newName)) {
|
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
|
||||||
Bukkit.getLogger().warning("Target resident name is already in use.");
|
} else if (tu.getDataSource().hasResident(newName)) {
|
||||||
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
|
Bukkit.getLogger().warning("Target resident name is already in use.");
|
||||||
} else
|
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
|
||||||
try {
|
} else {
|
||||||
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) {
|
|
||||||
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
TBMCCoreAPI.SendException("Failed to rename resident, the resident isn't registered.", e);
|
|
||||||
}
|
}
|
||||||
|
} catch (AlreadyRegisteredException e) {
|
||||||
|
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e);
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
TBMCCoreAPI.SendException("Failed to rename resident, the resident isn't registered.", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue