Adds charset to TableSqlParser, NickChangeActionProcessor

This commit is contained in:
Rsl1122 2017-08-24 18:21:15 +03:00
parent a67e8a989e
commit 63cc2b2b0e
4 changed files with 111 additions and 14 deletions

View File

@ -8,7 +8,6 @@ import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.additional.AnalysisType;
import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import java.sql.SQLException;
@ -70,7 +69,7 @@ public class API {
}
/**
* Used to get the link to InspectPage of a player.
* Used to get a relative link to InspectPage of a player.
* <p>
* This method is useful if you have a table and want to link to the inspect
* page.
@ -79,34 +78,46 @@ public class API {
* {@code <a href="Link">PlayerName</a>}
*
* @param name Name of the player
* @return ip:port/security/player/PlayerName
* @return ./player/PlayerName
*/
public String getPlayerInspectPageLink(String name) {
return HtmlUtils.getInspectUrlWithProtocol(name);
return plugin.getInfoManager().getLinkTo("/player/" + name).relative().toString();
}
/**
* Check if the UserInfo is cached to the InspectCache.
* Check if Players's Inspect page is cached to pagecache.
*
* @param uuid UUID of the player.
* @return true/false
* @deprecated use {@code isPlayerHtmlCached}
*/
@Deprecated
public boolean isPlayersDataInspectCached(UUID uuid) {
return isPlayerHtmlCached(uuid);
}
public boolean isPlayerHtmlCached(UUID uuid) {
return plugin.getInfoManager().isCached(uuid);
}
/**
* Cache the UserInfo to InspectCache.
* <p>
* Uses cache if data is cached or database if not. Call from an Asynchronous
* thread.
* Cache Players's Inspect page to the PageCache of the WebServer.
*
* @param uuid UUID of the player.
* @deprecated use {@code cachePlayerHtml}
*/
@Deprecated
public void cacheUserDataToInspectCache(UUID uuid) {
// TODO Run Inspect parse
cachePlayerHtml(uuid);
}
/**
* Cache Players's Inspect page to the PageCache of the WebServer.
*
* @param uuid UUID of the player.
*/
public void cachePlayerHtml(UUID uuid) {
plugin.getInfoManager().cachePlayer(uuid);
}
/**

View File

@ -93,6 +93,14 @@ public class TableSqlParser extends SqlParser {
return this;
}
public TableSqlParser charSetUTF8(boolean mySQL) {
if (mySQL) {
addSpace();
append("CHARACTER SET utf8 COLLATE utf8mb4_general_ci");
}
return this;
}
/**
* Used for ALTER TABLE sql statements.
*

View File

@ -0,0 +1,56 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.processing;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.database.tables.Actions;
import main.java.com.djrapitops.plan.systems.processing.player.PlayerProcessor;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.html.Html;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import java.sql.SQLException;
import java.util.UUID;
/**
* Processor for inserting a Name Change action to the Actions table.
*
* @author Rsl1122
* @since 4.0.0
*/
public class NickChangeActionProcessor extends PlayerProcessor {
private final String displayName;
private final String inDB;
public NickChangeActionProcessor(UUID uuid, String displayName, String inDB) {
super(uuid);
this.displayName = displayName;
this.inDB = inDB;
}
@Override
public void process() {
UUID uuid = getUUID();
if (displayName.equals(inDB)) {
return;
}
String old = HtmlUtils.swapColorsToSpan(inDB);
String n = HtmlUtils.swapColorsToSpan(displayName);
String info = HtmlUtils.removeXSS(old + " " + Html.FONT_AWESOME_ICON.parse("long-arrow-right") + " " + n);
Action action = new Action(MiscUtils.getTime(), Actions.CHANGED_NAME, info);
try {
Plan.getInstance().getDB().getActionsTable().insertAction(uuid, action);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
}
}

View File

@ -7,15 +7,19 @@ package main.java.com.djrapitops.plan.systems.processing.player;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.NicknamesTable;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.processing.NickChangeActionProcessor;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
/**
* Processor for updating name in the database if the player has changed it.
*
* @author Rsl1122
* @since 4.0.0
*/
public class NameProcessor extends PlayerProcessor {
@ -36,20 +40,38 @@ public class NameProcessor extends PlayerProcessor {
String cachedName = dataCache.getName(uuid);
String cachedDisplayName = dataCache.getDisplayName(uuid);
if (playerName.equals(cachedName) && displayName.equals(cachedDisplayName)) {
boolean sameAsCached = displayName.equals(cachedDisplayName);
if (playerName.equals(cachedName) && sameAsCached) {
return;
}
Database db = plugin.getDB();
NicknamesTable nicknamesTable = db.getNicknamesTable();
cueNameChangeActionProcessor(uuid, plugin, sameAsCached, nicknamesTable);
try {
db.getUsersTable().updateName(uuid, playerName);
db.getNicknamesTable().saveUserName(uuid, displayName);
nicknamesTable.saveUserName(uuid, displayName);
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
dataCache.updateNames(uuid, playerName, displayName);
}
private void cueNameChangeActionProcessor(UUID uuid, Plan plugin, boolean sameAsCached, NicknamesTable nicknamesTable) {
try {
if (!sameAsCached) {
List<String> nicknames = nicknamesTable.getNicknames(uuid, Plan.getServerUUID());
if (!nicknames.isEmpty()) {
plugin.addToProcessQueue(new NickChangeActionProcessor(uuid, displayName, nicknames.get(nicknames.size() - 1)));
} else {
plugin.addToProcessQueue(new NickChangeActionProcessor(uuid, displayName, playerName));
}
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
}
}