Skip to content

Commit

Permalink
added checks for name difference from a PlayerReference and the datab…
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdiplomat committed Mar 16, 2015
1 parent c7a5cc8 commit bd5720e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/net/canarymod/backbone/BackboneUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void updatePlayer(PlayerReference player) {
try {
HashMap<String, Object> filter = new HashMap<String, Object>();
filter.put("uuid", player.getUUIDString());
filter.put("name", player.getName());
// filter.put("name", player.getName()); // Can't update a name if its filtered in...
Database.get().update(data, filter);
}
catch (DatabaseWriteException e) {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/net/canarymod/user/UserAndGroupsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import net.canarymod.Canary;
import net.canarymod.ToolBox;
import net.canarymod.api.OfflinePlayer;
import net.canarymod.api.PlayerReference;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.backbone.BackboneGroups;
import net.canarymod.backbone.BackboneUsers;
import net.canarymod.backbone.PlayerDataAccess;
import net.canarymod.database.Database;
import net.canarymod.database.exceptions.DatabaseWriteException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -173,6 +178,29 @@ public boolean playerExists(String uuid) {
return playerData.containsKey(uuid);
}

/**
* Checks if a {@link net.canarymod.api.PlayerReference} has changed names compared to the database
*
* @param reference
* the {@link net.canarymod.api.PlayerReference} to check
*
* @return {@code true} if the name is different in the database; {@code false} if not
*/
public boolean nameChanged(PlayerReference reference) {
PlayerDataAccess data = new PlayerDataAccess();
try {
HashMap<String, Object> filter = new HashMap<String, Object>();
filter.put("uuid", reference.getUUIDString());
Database.get().update(data, filter);
}
catch (DatabaseWriteException e) {
log.error(e.getMessage(), e);
return false; // It either broke, or they don't exist
}
return !reference.getName().equals(data.name);
}


/**
* Return array of all existent groups
*
Expand Down

0 comments on commit bd5720e

Please sign in to comment.