mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 16:14:26 +08:00
parent
1ce28cc486
commit
05d86e6cb8
@ -17,8 +17,8 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
*/
|
||||
public class Log {
|
||||
|
||||
final protected static String DEBUG = "DebugLog.txt";
|
||||
final protected static String ERRORS = "Errors.txt";
|
||||
final private static String DEBUG = "DebugLog.txt";
|
||||
final private static String ERRORS = "Errors.txt";
|
||||
|
||||
/**
|
||||
* Logs the message to the console as INFO.
|
||||
@ -137,4 +137,12 @@ public class Log {
|
||||
Log.error("Failed to create" + filename + "file");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDEBUG() {
|
||||
return DEBUG;
|
||||
}
|
||||
|
||||
public static String getErrorsFilename() {
|
||||
return ERRORS;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
/**
|
||||
* This class contains static methods used by the commands to check whether or
|
||||
* not the command should proceed.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class CommandUtils {
|
||||
|
||||
public static boolean pluginHasViewCapability() {
|
||||
final boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
final boolean webserverIsOn = Settings.WEBSERVER_ENABLED.isTrue();
|
||||
final boolean usingTextUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
return webserverIsOn || usingAlternativeIP || usingTextUI;
|
||||
}
|
||||
|
||||
public static UUID getUUID(String playerName) {
|
||||
try {
|
||||
return UUIDUtility.getUUIDOf(playerName);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean uuidIsValid(UUID uuid) {
|
||||
return uuid != null;
|
||||
}
|
||||
|
||||
public static boolean playerHasPlayed(UUID uuid) {
|
||||
if (!uuidIsValid(uuid)) {
|
||||
return false;
|
||||
}
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
||||
return p.hasPlayedBefore();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Risto
|
||||
*/
|
||||
public class Condition {
|
||||
final private String failMsg;
|
||||
final private boolean pass;
|
||||
|
||||
public Condition(boolean pass, String failMsg) {
|
||||
this.failMsg = failMsg;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
public String getFailMsg() {
|
||||
return failMsg;
|
||||
}
|
||||
|
||||
public boolean pass() {
|
||||
return pass;
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
@ -41,26 +43,19 @@ public class AnalyzeCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
if (!Settings.SHOW_ALTERNATIVE_IP.isTrue()) {
|
||||
if (!Settings.USE_ALTERNATIVE_UI.isTrue()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS + "");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
if (!analysisCache.isCached()) {
|
||||
if (!analysisCache.isCached() || MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
int bootAnID = plugin.getBootAnalysisTaskID();
|
||||
if (bootAnID != -1) {
|
||||
plugin.getServer().getScheduler().cancelTask(bootAnID);
|
||||
}
|
||||
analysisCache.updateCache();
|
||||
} else if (MiscUtils.getTime() - analysisCache.getData().getRefreshDate() > 60000) {
|
||||
analysisCache.updateCache();
|
||||
}
|
||||
|
||||
BukkitTask analysisMessageSenderTask = new BukkitRunnable() {
|
||||
final BukkitTask analysisMessageSenderTask = new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
@ -69,8 +64,10 @@ public class AnalyzeCommand extends SubCommand {
|
||||
if (analysisCache.isCached()) {
|
||||
sendAnalysisMessage(sender);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, Analysis.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Analysis"));
|
||||
this.cancel();
|
||||
}
|
||||
@ -82,9 +79,11 @@ public class AnalyzeCommand extends SubCommand {
|
||||
/**
|
||||
* Used to send the message after /plan analysis.
|
||||
*
|
||||
* Final because
|
||||
*
|
||||
* @param sender Command sender.
|
||||
*/
|
||||
public void sendAnalysisMessage(CommandSender sender) {
|
||||
final public void sendAnalysisMessage(CommandSender sender) {
|
||||
boolean textUI = Settings.USE_ALTERNATIVE_UI.isTrue();
|
||||
sender.sendMessage(Phrase.CMD_ANALYZE_HEADER + "");
|
||||
if (textUI) {
|
||||
|
@ -1,20 +1,22 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -45,87 +47,74 @@ public class InspectCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
final boolean useAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
if (!Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
if (!useAlternativeIP) {
|
||||
if (!Settings.USE_ALTERNATIVE_UI.isTrue()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_INSPECT + "");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_INSPECT + "");
|
||||
return true;
|
||||
}
|
||||
String playerName = MiscUtils.getPlayerName(args, sender);
|
||||
BukkitTask inspectTask = new BukkitRunnable() {
|
||||
final BukkitTask inspectTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
UUID uuid = CommandUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(CommandUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(CommandUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString()),
|
||||
new Condition(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString())
|
||||
};
|
||||
|
||||
for (Condition condition : preConditions) {
|
||||
if (!condition.pass()) {
|
||||
sender.sendMessage(condition.getFailMsg());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
||||
if (!p.hasPlayedBefore()) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_SEEN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
int configValue = Settings.CLEAR_INSPECT_CACHE.getNumber();
|
||||
if (configValue <= 0) {
|
||||
configValue = 4;
|
||||
}
|
||||
final int available = configValue;
|
||||
BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
final BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
if (Settings.USE_ALTERNATIVE_UI.isTrue()) {
|
||||
sender.sendMessage(TextUI.getInspectMessages(uuid));
|
||||
} else {
|
||||
// Link
|
||||
String url = HtmlUtils.getInspectUrl(playerName);
|
||||
String message = Phrase.CMD_LINK + "";
|
||||
boolean console = !(sender instanceof Player);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available + ""));
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
sendInspectMsg(sender, playerName, uuid);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, Inspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
||||
this.cancel();
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}.runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendInspectMsg(CommandSender sender, String playerName, UUID uuid) throws CommandException {
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
if (Settings.USE_ALTERNATIVE_UI.isTrue()) {
|
||||
sender.sendMessage(TextUI.getInspectMessages(uuid));
|
||||
} else {
|
||||
// Link
|
||||
String url = HtmlUtils.getInspectUrl(playerName);
|
||||
String message = Phrase.CMD_LINK + "";
|
||||
boolean console = !(sender instanceof Player);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
Bukkit.getConsoleSender(),
|
||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"" + Phrase.CMD_CLICK_ME + "\",\"underlined\":true,"
|
||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
@ -62,6 +63,7 @@ public class QuickAnalyzeCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, QuickAnalyze.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Analysis"));
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
package main.java.com.djrapitops.plan.command.commands;
|
||||
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.ui.TextUI;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -45,39 +44,26 @@ public class QuickInspectCommand extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
|
||||
BukkitTask inspectTask = new BukkitRunnable() {
|
||||
final BukkitTask inspectTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
throw new Exception("Username doesn't exist.");
|
||||
UUID uuid = CommandUtils.getUUID(playerName);
|
||||
Condition[] preConditions = new Condition[]{
|
||||
new Condition(CommandUtils.uuidIsValid(uuid), Phrase.USERNAME_NOT_VALID.toString()),
|
||||
new Condition(CommandUtils.playerHasPlayed(uuid), Phrase.USERNAME_NOT_SEEN.toString()),
|
||||
new Condition(plugin.getDB().wasSeenBefore(uuid), Phrase.USERNAME_NOT_KNOWN.toString())
|
||||
};
|
||||
|
||||
for (Condition condition : preConditions) {
|
||||
if (!condition.pass()) {
|
||||
sender.sendMessage(condition.getFailMsg());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
||||
if (!p.hasPlayedBefore()) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_SEEN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
int configValue = Settings.CLEAR_INSPECT_CACHE.getNumber();
|
||||
if (configValue <= 0) {
|
||||
configValue = 4;
|
||||
}
|
||||
final int available = configValue;
|
||||
BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
final BukkitTask inspectMessageSenderTask = new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
@ -90,6 +76,7 @@ public class QuickInspectCommand extends SubCommand {
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 10) {
|
||||
Log.debug("Command Timeout Message, QuickInspect.");
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Qinspect"));
|
||||
this.cancel();
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ public class ReloadCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
plugin.reloadConfig();
|
||||
plugin.onDisable();
|
||||
plugin.reloadConfig();
|
||||
plugin.onEnable();
|
||||
sender.sendMessage(Phrase.RELOAD_COMPLETE + "");
|
||||
return true;
|
||||
|
@ -7,8 +7,9 @@ import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Permissions;
|
||||
import main.java.com.djrapitops.plan.Phrase;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.command.CommandType;
|
||||
import main.java.com.djrapitops.plan.command.CommandUtils;
|
||||
import main.java.com.djrapitops.plan.command.Condition;
|
||||
import main.java.com.djrapitops.plan.command.SubCommand;
|
||||
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import main.java.com.djrapitops.plan.utilities.HtmlUtils;
|
||||
@ -45,18 +46,19 @@ public class SearchCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (!Settings.WEBSERVER_ENABLED.isTrue()) {
|
||||
if (!CommandUtils.pluginHasViewCapability()) {
|
||||
sender.sendMessage(Phrase.ERROR_WEBSERVER_OFF_ANALYSIS.toString());
|
||||
return true;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
Condition c = new Condition(args.length != 1, Phrase.COMMAND_REQUIRES_ARGUMENTS_ONE.toString());
|
||||
if (c.pass()) {
|
||||
sender.sendMessage(c.getFailMsg());
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
|
||||
BukkitTask searchTask = new BukkitRunnable() {
|
||||
final BukkitTask searchTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
@ -67,13 +69,6 @@ public class SearchCommand extends SubCommand {
|
||||
inspectCache.cache(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
int configValue = Settings.CLEAR_INSPECT_CACHE.getNumber();
|
||||
if (configValue <= 0) {
|
||||
configValue = 4;
|
||||
}
|
||||
final int available = configValue;
|
||||
|
||||
sender.sendMessage(Phrase.CMD_SEARCH_HEADER + args[0]);
|
||||
// Results
|
||||
if (uuids.isEmpty()) {
|
||||
@ -94,7 +89,7 @@ public class SearchCommand extends SubCommand {
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
Player player = (Player) sender;
|
||||
BukkitTask link = new BukkitRunnable() {
|
||||
final BukkitTask link = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getServer().dispatchCommand(
|
||||
@ -107,7 +102,6 @@ public class SearchCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available + ""));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.data.cache.queue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
@ -11,8 +11,8 @@ import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
* Abstract class used for importing data from other plugins.
|
||||
|
@ -232,6 +232,9 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
@Override
|
||||
public boolean wasSeenBefore(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return usersTable.getUserId(uuid.toString()) != -1;
|
||||
} catch (SQLException e) {
|
||||
@ -248,6 +251,9 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAccount(String uuid) throws SQLException {
|
||||
if (uuid == null || uuid.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Benchmark.start("Database remove Account " + uuid);
|
||||
try {
|
||||
@ -284,7 +290,6 @@ public abstract class SQLDB extends Database {
|
||||
try {
|
||||
checkConnection();
|
||||
} catch (Exception e) {
|
||||
Log.toLog("Preparing for Exception report - Processors: " + processors.toString());
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return;
|
||||
}
|
||||
@ -376,9 +381,7 @@ public abstract class SQLDB extends Database {
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Throwable> exceptions = new HashSet<>();
|
||||
List<UserData> saveLast = usersTable.saveUserDataInformationBatch(data);
|
||||
data.removeAll(saveLast);
|
||||
usersTable.saveUserDataInformationBatch(data);
|
||||
// Transform to map
|
||||
Map<UUID, UserData> userDatas = data.stream().collect(Collectors.toMap(UserData::getUuid, Function.identity()));
|
||||
// Get UserIDs
|
||||
@ -397,7 +400,6 @@ public abstract class SQLDB extends Database {
|
||||
Integer id = userIds.get(uuid);
|
||||
UserData uData = userDatas.get(uuid);
|
||||
if (id == -1) {
|
||||
saveLast.add(uData);
|
||||
Log.debug("User not seen before, saving last: " + uuid);
|
||||
continue;
|
||||
}
|
||||
@ -427,18 +429,6 @@ public abstract class SQLDB extends Database {
|
||||
.forEach(uData -> {
|
||||
uData.stopAccessing();
|
||||
});
|
||||
// Save leftovers
|
||||
saveLast.stream().forEach((userData) -> {
|
||||
try {
|
||||
saveUserData(userData);
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
});
|
||||
if (!exceptions.isEmpty()) {
|
||||
Log.error("SEVERE: MULTIPLE ERRORS OCCURRED: " + exceptions.size());
|
||||
Log.toLog(this.getClass().getName(), exceptions);
|
||||
}
|
||||
Benchmark.stop("DB Save multiple Userdata");
|
||||
}
|
||||
|
||||
|
@ -82,19 +82,59 @@ public class CommandUseTable extends Table {
|
||||
return;
|
||||
}
|
||||
Benchmark.start("Save Commanduse");
|
||||
Map<String, Integer> newData = new HashMap<>(data);
|
||||
Map<String, Integer> saved = getCommandUse();
|
||||
newData.keySet().removeAll(saved.keySet());
|
||||
insertCommands(newData);
|
||||
Map<String, Integer> updateData = new HashMap<>(data);
|
||||
updateData.keySet().removeAll(newData.keySet());
|
||||
for (String cmd : saved.keySet()) {
|
||||
Integer toSave = updateData.get(cmd);
|
||||
if (toSave != null) {
|
||||
if (toSave <= saved.get(cmd)) {
|
||||
updateData.remove(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateCommands(updateData);
|
||||
Benchmark.stop("Save Commanduse");
|
||||
}
|
||||
|
||||
private void updateCommands(Map<String, Integer> data) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
if (!removeAllData()) {
|
||||
Log.debug("CommandUse Table clear failed.");
|
||||
}
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnCommand + ", "
|
||||
+ columnTimesUsed
|
||||
+ ") VALUES (?, ?)");
|
||||
String updateStatement = "UPDATE " + tableName + " SET " + columnTimesUsed + "=? WHERE (" + columnCommand + "=?)";
|
||||
statement = prepareStatement(updateStatement);
|
||||
boolean commitRequired = false;
|
||||
for (String key : data.keySet()) {
|
||||
Integer amount = data.get(key);
|
||||
if (key.length() > 20) {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(1, amount);
|
||||
statement.setString(2, key);
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
}
|
||||
if (commitRequired) {
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertCommands(Map<String, Integer> data) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
String insertStatement = "INSERT INTO " + tableName + " ("
|
||||
+ columnCommand + ", "
|
||||
+ columnTimesUsed
|
||||
+ ") VALUES (?, ?)";
|
||||
statement = prepareStatement(insertStatement);
|
||||
boolean commitRequired = false;
|
||||
for (String key : data.keySet()) {
|
||||
Integer amount = data.get(key);
|
||||
// Log.debug("Saving Command: "+key+" "+amount);
|
||||
if (key.length() > 20) {
|
||||
continue;
|
||||
}
|
||||
@ -104,12 +144,10 @@ public class CommandUseTable extends Table {
|
||||
commitRequired = true;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("CommandUse: Executing batch, size: " + data.size());
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Save Commanduse");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +202,7 @@ public class IPsTable extends Table {
|
||||
+ columnIP
|
||||
+ ") VALUES (?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Integer id : ips.keySet()) {
|
||||
Set<InetAddress> ipAddresses = ips.get(id);
|
||||
Set<InetAddress> s = saved.get(id);
|
||||
@ -219,14 +220,16 @@ public class IPsTable extends Table {
|
||||
statement.setString(2, ip.getHostAddress());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing ips batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
Benchmark.stop("Save Ips Multiple " + ips.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Get Ips Multiple " + ips.size());
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
@ -141,7 +142,14 @@ public class KillsTable extends Table {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(1, userId);
|
||||
statement.setInt(2, kill.getVictimUserID());
|
||||
int victimUserID = kill.getVictimUserID();
|
||||
if (victimUserID == -1) {
|
||||
victimUserID = db.getUsersTable().getUserId(kill.getVictim());
|
||||
if (victimUserID == -1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
statement.setInt(2, victimUserID);
|
||||
statement.setString(3, kill.getWeapon());
|
||||
statement.setLong(4, kill.getDate());
|
||||
statement.addBatch();
|
||||
@ -167,7 +175,7 @@ public class KillsTable extends Table {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
Benchmark.start("Get Kills multiple "+ids.size());
|
||||
Benchmark.start("Get Kills multiple " + ids.size());
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -190,7 +198,7 @@ public class KillsTable extends Table {
|
||||
} finally {
|
||||
close(set);
|
||||
close(statement);
|
||||
Benchmark.stop("Get Kills multiple "+ids.size());
|
||||
Benchmark.stop("Get Kills multiple " + ids.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +212,7 @@ public class KillsTable extends Table {
|
||||
if (kills == null || kills.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Benchmark.start("Save Kills multiple "+kills.size());
|
||||
Benchmark.start("Save Kills multiple " + kills.size());
|
||||
Map<Integer, List<KillData>> saved = getPlayerKills(kills.keySet(), uuids);
|
||||
|
||||
PreparedStatement statement = null;
|
||||
@ -216,6 +224,7 @@ public class KillsTable extends Table {
|
||||
+ columnDate
|
||||
+ ") VALUES (?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Integer id : kills.keySet()) {
|
||||
List<KillData> playerKills = kills.get(id);
|
||||
List<KillData> s = saved.get(id);
|
||||
@ -227,19 +236,32 @@ public class KillsTable extends Table {
|
||||
continue;
|
||||
}
|
||||
statement.setInt(1, id);
|
||||
statement.setInt(2, kill.getVictimUserID());
|
||||
int victimUserID = kill.getVictimUserID();
|
||||
if (victimUserID == -1) {
|
||||
List<Integer> matchingIds = uuids.entrySet()
|
||||
.stream().filter(e -> e.getValue().equals(kill.getVictim()))
|
||||
.map(e -> e.getKey())
|
||||
.collect(Collectors.toList());
|
||||
if (matchingIds.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
victimUserID = matchingIds.get(0);
|
||||
}
|
||||
statement.setInt(2, victimUserID);
|
||||
statement.setString(3, kill.getWeapon());
|
||||
statement.setLong(4, kill.getDate());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing kills batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
}
|
||||
Benchmark.stop("Save Kills multiple " + kills.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Save Kills multiple "+kills.size());
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ public class LocationsTable extends Table {
|
||||
+ columnWorld
|
||||
+ ") VALUES (?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Location location : newLocations) {
|
||||
if (location == null) {
|
||||
continue;
|
||||
@ -170,8 +171,10 @@ public class LocationsTable extends Table {
|
||||
statement.setString(4, world.getName());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing locations batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
@ -199,6 +202,7 @@ public class LocationsTable extends Table {
|
||||
+ columnWorld
|
||||
+ ") VALUES (?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Integer id : locations.keySet()) {
|
||||
List<Location> newLocations = locations.get(id);
|
||||
if (newLocations == null || newLocations.isEmpty()) {
|
||||
@ -215,9 +219,11 @@ public class LocationsTable extends Table {
|
||||
statement.setString(4, world.getName());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing locations batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
|
@ -156,14 +156,17 @@ public class NicknamesTable extends Table {
|
||||
+ columnNick
|
||||
+ ") VALUES (?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (String name : names) {
|
||||
statement.setInt(1, userId);
|
||||
statement.setInt(2, (name.equals(lastNick)) ? 1 : 0);
|
||||
statement.setString(3, name);
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing nicknames batch: "+i);
|
||||
statement.executeBatch();
|
||||
|
||||
}
|
||||
|
@ -209,6 +209,7 @@ public class SessionsTable extends Table {
|
||||
+ ") VALUES (?, ?, ?)");
|
||||
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (Integer id : sessions.keySet()) {
|
||||
List<SessionData> sessionList = sessions.get(id);
|
||||
List<SessionData> s = saved.get(id);
|
||||
@ -229,14 +230,16 @@ public class SessionsTable extends Table {
|
||||
statement.setLong(3, end);
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (commitRequired) {
|
||||
statement.executeBatch();
|
||||
Log.debug("Executing session batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
Benchmark.stop("Save Sessions multiple " + sessions.size());
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Save Sessions multiple " + sessions.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,11 +633,80 @@ public class UsersTable extends Table {
|
||||
/**
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public List<UserData> saveUserDataInformationBatch(Collection<UserData> data) throws SQLException {
|
||||
public void saveUserDataInformationBatch(Collection<UserData> data) throws SQLException {
|
||||
Benchmark.start("Save UserInfo multiple " + data.size());
|
||||
try {
|
||||
List<UserData> newUserdata = updateExistingUserData(data);
|
||||
Benchmark.start("Insert new UserInfo multiple " + newUserdata.size());
|
||||
insertNewUserData(newUserdata);
|
||||
Benchmark.stop("Insert new UserInfo multiple " + newUserdata.size());
|
||||
} finally {
|
||||
Benchmark.stop("Save UserInfo multiple " + data.size());
|
||||
}
|
||||
}
|
||||
|
||||
private void insertNewUserData(Collection<UserData> data) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
||||
+ columnUUID + ", "
|
||||
+ columnDemAge + ", "
|
||||
+ columnDemGender + ", "
|
||||
+ columnDemGeoLocation + ", "
|
||||
+ columnLastGM + ", "
|
||||
+ columnLastGMSwapTime + ", "
|
||||
+ columnPlayTime + ", "
|
||||
+ columnLoginTimes + ", "
|
||||
+ columnLastPlayed + ", "
|
||||
+ columnDeaths + ", "
|
||||
+ columnMobKills + ", "
|
||||
+ columnContainsBukkitData + ", "
|
||||
+ columnOP + ", "
|
||||
+ columnBanned + ", "
|
||||
+ columnName + ", "
|
||||
+ columnRegistered
|
||||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
int i = 0;
|
||||
for (UserData uData : data) {
|
||||
UUID uuid = uData.getUuid();
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setInt(2, uData.getDemData().getAge());
|
||||
statement.setString(3, uData.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(4, uData.getDemData().getGeoLocation());
|
||||
GameMode gm = uData.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(5, uData.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(5, GameMode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(6, uData.getLastGmSwapTime());
|
||||
statement.setLong(7, uData.getPlayTime());
|
||||
statement.setInt(8, uData.getLoginTimes());
|
||||
statement.setLong(9, uData.getLastPlayed());
|
||||
statement.setInt(10, uData.getDeaths());
|
||||
statement.setInt(11, uData.getMobKills());
|
||||
statement.setBoolean(12, uData.getName() != null);
|
||||
statement.setBoolean(13, uData.isOp());
|
||||
statement.setBoolean(14, uData.isBanned());
|
||||
statement.setString(15, uData.getName());
|
||||
statement.setLong(16, uData.getRegistered());
|
||||
statement.addBatch();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing session batch: "+i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
private List<UserData> updateExistingUserData(Collection<UserData> data) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
List<UserData> saveLast = new ArrayList<>();
|
||||
@ -661,65 +730,61 @@ public class UsersTable extends Table {
|
||||
statement = prepareStatement(uSQL);
|
||||
boolean commitRequired = false;
|
||||
Set<UUID> savedUUIDs = getSavedUUIDs();
|
||||
int i = 0;
|
||||
for (UserData uData : data) {
|
||||
try {
|
||||
if (uData == null) {
|
||||
continue;
|
||||
}
|
||||
UUID uuid = uData.getUuid();
|
||||
if (uuid == null) {
|
||||
try {
|
||||
uData.setUuid(UUIDUtility.getUUIDOf(uData.getName(), db));
|
||||
} catch (Exception ex) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
uuid = uData.getUuid();
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
if (!savedUUIDs.contains(uuid)) {
|
||||
saveLast.add(uData);
|
||||
continue;
|
||||
}
|
||||
uData.access();
|
||||
statement.setInt(1, uData.getDemData().getAge());
|
||||
statement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, uData.getDemData().getGeoLocation());
|
||||
GameMode gm = uData.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, uData.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(4, GameMode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(5, uData.getLastGmSwapTime());
|
||||
statement.setLong(6, uData.getPlayTime());
|
||||
statement.setInt(7, uData.getLoginTimes());
|
||||
statement.setLong(8, uData.getLastPlayed());
|
||||
statement.setInt(9, uData.getDeaths());
|
||||
statement.setInt(10, uData.getMobKills());
|
||||
statement.setBoolean(11, uData.getName() != null);
|
||||
statement.setBoolean(12, uData.isOp());
|
||||
statement.setBoolean(13, uData.isBanned());
|
||||
statement.setString(14, uData.getName());
|
||||
statement.setLong(15, uData.getRegistered());
|
||||
statement.setString(16, uuid.toString());
|
||||
statement.addBatch();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
saveLast.add(uData);
|
||||
uData.stopAccessing();
|
||||
if (uData == null) {
|
||||
continue;
|
||||
}
|
||||
UUID uuid = uData.getUuid();
|
||||
if (uuid == null) {
|
||||
try {
|
||||
uData.setUuid(UUIDUtility.getUUIDOf(uData.getName(), db));
|
||||
} catch (Exception ex) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
uuid = uData.getUuid();
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
if (!savedUUIDs.contains(uuid)) {
|
||||
saveLast.add(uData);
|
||||
continue;
|
||||
}
|
||||
uData.access();
|
||||
statement.setInt(1, uData.getDemData().getAge());
|
||||
statement.setString(2, uData.getDemData().getGender().toString().toLowerCase());
|
||||
statement.setString(3, uData.getDemData().getGeoLocation());
|
||||
GameMode gm = uData.getLastGamemode();
|
||||
if (gm != null) {
|
||||
statement.setString(4, uData.getLastGamemode().name());
|
||||
} else {
|
||||
statement.setString(4, GameMode.SURVIVAL.name());
|
||||
}
|
||||
statement.setLong(5, uData.getLastGmSwapTime());
|
||||
statement.setLong(6, uData.getPlayTime());
|
||||
statement.setInt(7, uData.getLoginTimes());
|
||||
statement.setLong(8, uData.getLastPlayed());
|
||||
statement.setInt(9, uData.getDeaths());
|
||||
statement.setInt(10, uData.getMobKills());
|
||||
statement.setBoolean(11, uData.getName() != null);
|
||||
statement.setBoolean(12, uData.isOp());
|
||||
statement.setBoolean(13, uData.isBanned());
|
||||
statement.setString(14, uData.getName());
|
||||
statement.setLong(15, uData.getRegistered());
|
||||
statement.setString(16, uuid.toString());
|
||||
statement.addBatch();
|
||||
uData.stopAccessing();
|
||||
commitRequired = true;
|
||||
i++;
|
||||
}
|
||||
if (commitRequired) {
|
||||
Log.debug("Executing userinfo batch update: " + i);
|
||||
statement.executeBatch();
|
||||
}
|
||||
return saveLast;
|
||||
} finally {
|
||||
close(statement);
|
||||
Benchmark.stop("Save UserInfo multiple " + data.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,9 @@ public class WebSocketServer {
|
||||
Log.info(Phrase.WEBSERVER_CLOSE + "");
|
||||
shutdown = true;
|
||||
try {
|
||||
server.close();
|
||||
if (server != null) {
|
||||
server.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
@ -233,12 +233,16 @@ public class DatabaseTest {
|
||||
c.put("/help", 21);
|
||||
c.put("/roiergbnougbierubieugbeigubeigubgierbgeugeg", 3);
|
||||
db.saveCommandUse(c);
|
||||
c.remove("/roiergbnougbierubieugbeigubeigubgierbgeugeg");
|
||||
Map<String, Integer> commandUse = db.getCommandUse();
|
||||
assertTrue("Doesn't contain /plan", commandUse.containsKey("/plan"));
|
||||
assertTrue("Doesn't contain /tp", commandUse.containsKey("/tp"));
|
||||
assertTrue("Doesn't contain /pla", commandUse.containsKey("/pla"));
|
||||
assertTrue("Doesn't contain /help", commandUse.containsKey("/help"));
|
||||
assertTrue("Contains too long cmd", !commandUse.containsKey("/roiergbnougbierubieugbeigubeigubgierbgeugeg"));
|
||||
assertEquals(c, commandUse);
|
||||
c.put("/test", 3);
|
||||
c.put("/tp", 6);
|
||||
c.put("/pla", 4);
|
||||
db.saveCommandUse(c);
|
||||
c.put("/pla", 7);
|
||||
commandUse = db.getCommandUse();
|
||||
assertEquals(c, commandUse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user