Remove Towny resident rename functionality

Towny doesn't need the name updater plugin anymore
This commit is contained in:
Norbi Peti 2021-01-18 17:14:15 +01:00
parent 2a008906f4
commit f92cc773c1
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 1 additions and 40 deletions

View file

@ -1,6 +1,5 @@
package buttondevteam.core; package buttondevteam.core;
import buttondevteam.core.component.towny.TownyComponent;
import buttondevteam.lib.*; import buttondevteam.lib.*;
import buttondevteam.lib.architecture.ButtonPlugin; import buttondevteam.lib.architecture.ButtonPlugin;
import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.ChatMessage;
@ -36,7 +35,6 @@ public class PlayerListener implements Listener {
player.PlayerName.set(p.getName()); player.PlayerName.set(p.getName());
MainPlugin.Instance.getLogger().info("Player name saved: " + player.PlayerName.get()); MainPlugin.Instance.getLogger().info("Player name saved: " + player.PlayerName.get());
} else if (!p.getName().equals(pname)) { } else if (!p.getName().equals(pname)) {
TownyComponent.renameInTowny(pname, p.getName());
MainPlugin.Instance.getLogger().info(pname + " renamed to " + p.getName()); MainPlugin.Instance.getLogger().info(pname + " renamed to " + p.getName());
player.PlayerName.set(p.getName()); player.PlayerName.set(p.getName());
} }

View file

@ -1,16 +1,10 @@
package buttondevteam.core.component.towny; package buttondevteam.core.component.towny;
import buttondevteam.core.ComponentManager;
import buttondevteam.core.MainPlugin; import buttondevteam.core.MainPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
/** /**
* Automatically renames Towny players if they changed their Minecraft name * Provides a command to remove invalid Towny residents.
*/ */
public class TownyComponent extends Component<MainPlugin> { public class TownyComponent extends Component<MainPlugin> {
@Override @Override
@ -21,35 +15,4 @@ public class TownyComponent extends Component<MainPlugin> {
@Override @Override
protected void disable() { protected void disable() {
} }
/**
* Only renames the resident if this component is enabled. Used to handle name changes.
*
* @param oldName The player's old name as known by us
* @param newName The player's new name
*/
public static void renameInTowny(String oldName, String newName) {
var component = ComponentManager.getIfEnabled(TownyComponent.class);
if (component == null)
return;
component.log("Renaming " + oldName + " in Towny to " + newName);
TownyUniverse tu = TownyUniverse.getInstance();
try {
Resident resident = tu.getDataSource().getResident(oldName);
if (resident == null) {
component.logWarn("Resident not found - couldn't rename in Towny.");
TBMCCoreAPI.sendDebugMessage("Resident not found - couldn't rename in Towny.");
} else if (tu.getDataSource().hasResident(newName)) {
component.logWarn("Target resident name is already in use.");
TBMCCoreAPI.sendDebugMessage("Target resident name is already in use. (" + oldName + " -> " + newName + ")");
} else {
tu.getDataSource().renamePlayer(resident, newName); //Fixed in Towny 0.91.1.2
component.log("Renaming done.");
}
} catch (AlreadyRegisteredException e) {
TBMCCoreAPI.SendException("Failed to rename resident, there's already one with this name.", e, component);
} catch (NotRegisteredException e) {
TBMCCoreAPI.SendException("Failed to rename resident, the resident isn't registered.", e, component);
}
}
} }