Fix real name update.

This commit is contained in:
DNx5 2016-02-16 07:14:40 +07:00
parent 814bc8df4e
commit 7c1dd888cc
7 changed files with 54 additions and 6 deletions

10
pom.xml
View File

@ -145,7 +145,7 @@
<version>2.4.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>´
<minimizeJar>false</minimizeJar>
</configuration>
<executions>
<execution>
@ -346,6 +346,12 @@
<id>xephi-repo</id>
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
</repository>
<!-- PermissionsEx Repo (Re-added, since Xephi's repo was down) -->
<repository>
<id>pex-repo</id>
<url>https://pex-repo.aoeu.xyz/</url>
</repository>
</repositories>
<dependencies>
@ -486,7 +492,7 @@
<dependency>
<groupId>ru.tehkode</groupId>
<artifactId>PermissionsEx</artifactId>
<version>1.23.4</version>
<version>1.23.1</version>
<scope>provided</scope>
<exclusions>
<exclusion>

View File

@ -230,6 +230,15 @@ public class CacheDataSource implements DataSource {
cachedAuths.invalidate(oldOne);
}
@Override
public boolean updateRealName(String user, String realName) {
boolean result = source.updateRealName(user, realName);
if (result) {
cachedAuths.refresh(user);
}
return result;
}
@Override
public List<PlayerAuth> getAllAuths() {
return source.getAllAuths();

View File

@ -204,6 +204,7 @@ public interface DataSource {
*/
void updateName(String oldOne, String newOne);
boolean updateRealName(String user, String realName);
/**
* Method getAllAuths.
*

View File

@ -716,6 +716,11 @@ public class FlatFile implements DataSource {
this.removeAuth(oldOne);
}
@Override
public boolean updateRealName(String user, String realName) {
return false;
}
@Override
public List<PlayerAuth> getAllAuths() {
BufferedReader br = null;

View File

@ -885,6 +885,21 @@ public class MySQL implements DataSource {
}
}
@Override
public boolean updateRealName(String user, String realName) {
try (Connection con = getConnection()) {
String sql = "UPDATE " + tableName + " SET " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, realName);
pst.setString(2, user);
pst.executeUpdate();
return true;
} catch (SQLException ex) {
logSqlException(ex);
}
return false;
}
@Override
public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>();

View File

@ -593,6 +593,20 @@ public class SQLite implements DataSource {
}
}
@Override
public boolean updateRealName(String user, String realName) {
String sql = "UPDATE " + tableName + " SET " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;";
try(PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, realName);
pst.setString(2, user);
pst.executeUpdate();
return true;
} catch (SQLException ex) {
logSqlException(ex);
}
return false;
}
@Override
public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>();

View File

@ -12,7 +12,6 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.GeoLiteAPI;
@ -109,7 +108,7 @@ public class AuthMePlayerListener implements Listener {
if (Settings.useEssentialsMotd && cmd.equals("/motd")) {
return;
}
if(!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) {
if (!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) {
return;
}
if (Settings.allowCommands.contains(cmd)) {
@ -250,8 +249,7 @@ public class AuthMePlayerListener implements Listener {
return;
}
if (realName.isEmpty() || realName.equals("Player")) {
auth.setRealName(event.getName());
plugin.getDataSource().saveAuth(auth);
plugin.getDataSource().updateRealName(event.getName().toLowerCase(), event.getName());
}
}