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> <version>2.4.3</version>
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>´ <minimizeJar>false</minimizeJar>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -346,6 +346,12 @@
<id>xephi-repo</id> <id>xephi-repo</id>
<url>http://ci.xephi.fr/plugin/repository/everything/</url> <url>http://ci.xephi.fr/plugin/repository/everything/</url>
</repository> </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> </repositories>
<dependencies> <dependencies>
@ -486,7 +492,7 @@
<dependency> <dependency>
<groupId>ru.tehkode</groupId> <groupId>ru.tehkode</groupId>
<artifactId>PermissionsEx</artifactId> <artifactId>PermissionsEx</artifactId>
<version>1.23.4</version> <version>1.23.1</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View File

@ -230,6 +230,15 @@ public class CacheDataSource implements DataSource {
cachedAuths.invalidate(oldOne); 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 @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
return source.getAllAuths(); return source.getAllAuths();

View File

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

View File

@ -716,6 +716,11 @@ public class FlatFile implements DataSource {
this.removeAuth(oldOne); this.removeAuth(oldOne);
} }
@Override
public boolean updateRealName(String user, String realName) {
return false;
}
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
BufferedReader br = null; 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 @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); 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 @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); 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.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.GeoLiteAPI;
@ -109,7 +108,7 @@ public class AuthMePlayerListener implements Listener {
if (Settings.useEssentialsMotd && cmd.equals("/motd")) { if (Settings.useEssentialsMotd && cmd.equals("/motd")) {
return; return;
} }
if(!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) { if (!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) {
return; return;
} }
if (Settings.allowCommands.contains(cmd)) { if (Settings.allowCommands.contains(cmd)) {
@ -250,8 +249,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (realName.isEmpty() || realName.equals("Player")) { if (realName.isEmpty() || realName.equals("Player")) {
auth.setRealName(event.getName()); plugin.getDataSource().updateRealName(event.getName().toLowerCase(), event.getName());
plugin.getDataSource().saveAuth(auth);
} }
} }