mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 04:01:58 +01:00
Merge branch '3.6.0' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
0c698950e4
@ -228,6 +228,11 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/main/java/com/djrapitops/plan/utilities/comparators/SessionDataComparator.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/main/java/com/djrapitops/plan/utilities/metrics/BStats.java">
|
||||
<value>
|
||||
<set />
|
||||
@ -243,6 +248,11 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/main/resources/player.html">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/UserDataTest.java">
|
||||
<value>
|
||||
<set />
|
||||
@ -253,11 +263,36 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/KillHandlingTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ChatInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/DeathInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/InfoUuidCorrectionTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/KillInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java">
|
||||
<value>
|
||||
<set />
|
||||
@ -293,6 +328,11 @@
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java">
|
||||
<value>
|
||||
<set />
|
||||
</value>
|
||||
</entry>
|
||||
<entry key="$PROJECT_DIR$/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/HandlingInfoTimeComparatorTest.java">
|
||||
<value>
|
||||
<set />
|
||||
|
@ -105,6 +105,7 @@
|
||||
<targetPath>.</targetPath>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
<includes>
|
||||
<include>*.keystore</include>
|
||||
<include>*.js</include>
|
||||
<include>*.yml</include>
|
||||
<include>*.html</include>
|
||||
|
@ -1,11 +1,24 @@
|
||||
package main.java.com.djrapitops.plan.data.analysis;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.WorldPieCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Part responsible for all World Playtime related analysis.
|
||||
* <p>
|
||||
* World times Pie
|
||||
* <p>
|
||||
* Placeholder values can be retrieved using the get method.
|
||||
* <p>
|
||||
* Contains following place-holders: worldtotal, worldseries
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.6.0
|
||||
*/
|
||||
public class WorldPart extends RawData {
|
||||
|
||||
private final Map<String, Long> worldTimes;
|
||||
@ -16,7 +29,8 @@ public class WorldPart extends RawData {
|
||||
|
||||
@Override
|
||||
protected void analyse() {
|
||||
addValue("worldtotal", FormatUtils.formatTimeAmount(worldTimes.values().stream().mapToLong(Long::longValue).sum()));
|
||||
WorldTimes t = new WorldTimes(worldTimes);
|
||||
addValue("worldtotal", FormatUtils.formatTimeAmount(t.getTotal()));
|
||||
addValue("worldseries", WorldPieCreator.createSeriesData(worldTimes));
|
||||
}
|
||||
|
||||
@ -24,5 +38,4 @@ public class WorldPart extends RawData {
|
||||
Long value = worldTimes.computeIfAbsent(worldName, ifNotFound -> 0L);
|
||||
worldTimes.put(worldName, value + playTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class KillHandling {
|
||||
int victimID;
|
||||
try {
|
||||
UUID victimUUID = deadPlayer.getUniqueId();
|
||||
victimID = plugin.getDB().getUsersTable().getUserId(victimUUID + "");
|
||||
victimID = plugin.getDB().getUsersTable().getUserId(victimUUID);
|
||||
if (victimID == -1) {
|
||||
return;
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ public class PlanWorldChangeListener implements Listener {
|
||||
}
|
||||
UUID uuid = p.getUniqueId();
|
||||
long time = MiscUtils.getTime();
|
||||
handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.GM, time, p.getGameMode().name(), p.getWorld().getName()));
|
||||
handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.WORLD, time, p.getGameMode().name(), p.getWorld().getName()));
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +344,11 @@ public abstract class SQLDB extends Database {
|
||||
Map<String, Long> gmTimes = gmTimesTable.getGMTimes(userId);
|
||||
data.getGmTimes().setTimes(gmTimes);
|
||||
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
||||
data.getWorldTimes().setTimes(worldTimes);
|
||||
WorldTimes worldT = data.getWorldTimes();
|
||||
worldT.setTimes(worldTimes);
|
||||
if (worldT.getLastStateChange() == 0) {
|
||||
worldT.setLastStateChange(data.getPlayTime());
|
||||
}
|
||||
|
||||
List<SessionData> sessions = sessionsTable.getSessionData(userId);
|
||||
data.addSessions(sessions);
|
||||
@ -394,11 +398,19 @@ public abstract class SQLDB extends Database {
|
||||
UUID uuid = uData.getUuid();
|
||||
Integer id = userIds.get(uuid);
|
||||
uData.addIpAddresses(ipList.get(id));
|
||||
uData.addNicknames(nicknames.get(id));
|
||||
List<String> userNicks = nicknames.get(id);
|
||||
uData.addNicknames(userNicks);
|
||||
if (!userNicks.isEmpty()) {
|
||||
uData.setLastNick(userNicks.get(userNicks.size() - 1));
|
||||
}
|
||||
uData.addSessions(sessionData.get(id));
|
||||
uData.setPlayerKills(playerKills.get(id));
|
||||
uData.getGmTimes().setTimes(gmTimes.get(id));
|
||||
uData.getWorldTimes().setTimes(worldTimes.get(id));
|
||||
WorldTimes worldT = uData.getWorldTimes();
|
||||
worldT.setTimes(worldTimes.get(id));
|
||||
if (worldT.getLastStateChange() == 0) {
|
||||
worldT.setLastStateChange(uData.getPlayTime());
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark.stop("Database: Get UserData for " + uuidsCol.size());
|
||||
|
@ -20,6 +20,7 @@ import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.*;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
@ -169,7 +170,7 @@ public class WebServer {
|
||||
|
||||
private boolean startHttpsServer() throws IOException {
|
||||
String keyStorePath = Settings.WEBSERVER_CERTIFICATE_PATH.toString();
|
||||
if (!keyStorePath.contains(":")) {
|
||||
if (!Paths.get(keyStorePath).isAbsolute()) {
|
||||
keyStorePath = plugin.getDataFolder() + keyStorePath;
|
||||
}
|
||||
char[] storepass = Settings.WEBSERVER_CERTIFICATE_STOREPASS.toString().toCharArray();
|
||||
|
@ -6,11 +6,13 @@ import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.analysis.GamemodePart;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.database.tables.GMTimesTable;
|
||||
import main.java.com.djrapitops.plan.ui.html.Html;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.PlayerActivityGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.PunchCardGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.SessionLengthDistributionGraphCreator;
|
||||
import main.java.com.djrapitops.plan.ui.html.graphs.WorldPieCreator;
|
||||
import main.java.com.djrapitops.plan.ui.html.tables.KillsTableCreator;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
@ -106,12 +108,15 @@ public class PlaceholderUtils {
|
||||
Plan plugin = Plan.getInstance();
|
||||
replaceMap.put("%version%", plugin.getDescription().getVersion());
|
||||
replaceMap.put("%playersgraphcolor%", Settings.HCOLOR_ACT_ONL.toString());
|
||||
Set<SessionData> sessions = new HashSet<>(data.getSessions());
|
||||
replaceMap.put("%punchcardseries%", PunchCardGraphCreator.createDataSeries(sessions));
|
||||
List<Long> lengths = AnalysisUtils.transformSessionDataToLengths(sessions);
|
||||
replaceMap.put("%sessionlengthseries%", SessionLengthDistributionGraphCreator.createDataSeries(lengths));
|
||||
|
||||
Set<SessionData> sessions = new HashSet<>(data.getSessions());
|
||||
List<Long> lengths = AnalysisUtils.transformSessionDataToLengths(sessions);
|
||||
replaceMap.put("%punchcardseries%", PunchCardGraphCreator.createDataSeries(sessions));
|
||||
replaceMap.put("%sessionlengthseries%", SessionLengthDistributionGraphCreator.createDataSeries(lengths));
|
||||
replaceMap.put("%playersonlineseries%", PlayerActivityGraphCreator.buildSeriesDataStringSessions(sessions));
|
||||
WorldTimes worldTimes = data.getWorldTimes();
|
||||
replaceMap.put("%worldseries%", WorldPieCreator.createSeriesData(worldTimes.getTimes()));
|
||||
replaceMap.put("%worldtotal%", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
|
||||
|
||||
String[] colors = new String[]{Settings.HCOLOR_MAIN.toString(), Settings.HCOLOR_MAIN_DARK.toString(), Settings.HCOLOR_SEC.toString(), Settings.HCOLOR_TER.toString(), Settings.HCOLOR_TER_DARK.toString()};
|
||||
String[] defaultCols = new String[]{"348e0f", "267F00", "5cb239", "89c471", "5da341"};
|
||||
|
@ -13,6 +13,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -34,7 +35,7 @@ public class ExportUtility {
|
||||
*/
|
||||
public static File getFolder() {
|
||||
String path = Settings.ANALYSIS_EXPORT_PATH.toString();
|
||||
if (path.contains(":")) {
|
||||
if (Paths.get(path).isAbsolute()) {
|
||||
File folder = new File(path);
|
||||
if (folder.exists()
|
||||
&& folder.isDirectory()) {
|
||||
|
BIN
Plan/src/main/resources/Cert.keystore
Normal file
BIN
Plan/src/main/resources/Cert.keystore
Normal file
Binary file not shown.
@ -378,6 +378,9 @@
|
||||
<i class="fa fa-tag" aria-hidden="true"></i> UUID: %uuid%<br/>
|
||||
<i class="fa fa-globe" aria-hidden="true"></i> Has Connected from ips: %ips%</p>
|
||||
</div>
|
||||
<div class="about box column">
|
||||
<div id="worldPie" style="width: 100%; height: 400px;"></div>
|
||||
</div>
|
||||
<div class="about box column">
|
||||
<div id="gmPie" style="width: 100%; height: 400px;"></div>
|
||||
</div>
|
||||
@ -409,7 +412,7 @@
|
||||
<div class="headerbox">
|
||||
<div class="header-icon">
|
||||
<div class="header-label"><i class="fa fa-crosshairs" aria-hidden="true"></i><span
|
||||
class="header-text"> Last 10 Kills</span></div>
|
||||
class="header-text"> Last 25 Kills</span></div>
|
||||
</div>
|
||||
<div class="infobox" style="float: right;">
|
||||
<div class="info-icon">
|
||||
@ -487,6 +490,33 @@
|
||||
<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>
|
||||
<script src="https://code.highcharts.com/stock/highstock.js"></script>
|
||||
<script>
|
||||
function formatTime(seconds) {
|
||||
var out = "";
|
||||
seconds = Math.floor(seconds / 1000);
|
||||
|
||||
var dd = Math.floor(seconds / 86400);
|
||||
seconds -= (dd * 86400);
|
||||
|
||||
var dh = Math.floor(seconds / 3600);
|
||||
seconds -= (dh * 3600);
|
||||
|
||||
var dm = Math.floor(seconds / 60);
|
||||
seconds -= (dm * 60);
|
||||
|
||||
seconds = Math.floor(seconds);
|
||||
|
||||
if (dd != 0) {
|
||||
out += dd.toString() + "d ";
|
||||
}
|
||||
if (dh != 0) {
|
||||
out += dh.toString() + "h ";
|
||||
}
|
||||
if (dm != 0) {
|
||||
out += dm.toString() + "m ";
|
||||
}
|
||||
out += seconds.toString() + "s ";
|
||||
return out;
|
||||
}
|
||||
var playersOnlineSeries = {
|
||||
name: 'Online',
|
||||
data: %playersonlineseries%,
|
||||
@ -516,6 +546,11 @@
|
||||
y: gmData[3]
|
||||
}]
|
||||
};
|
||||
var worldSeries = {
|
||||
name: 'World Playtime',
|
||||
colorByPoint: true,
|
||||
data: %worldseries%
|
||||
};
|
||||
var sessionLengthSeries = {
|
||||
name: 'Sessions',
|
||||
color: '#89c471',
|
||||
@ -590,6 +625,35 @@
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
function worldPie() {
|
||||
var myChart = Highcharts.chart('worldPie', {
|
||||
chart: {
|
||||
plotBackgroundColor: null,
|
||||
plotBorderWidth: null,
|
||||
plotShadow: false,
|
||||
type: 'pie'
|
||||
},
|
||||
title: {text: 'World Playtime'},
|
||||
subtitle: {text: '%worldtotal%'},
|
||||
tooltip: {
|
||||
pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
|
||||
},
|
||||
plotOptions: {
|
||||
pie: {
|
||||
allowPointSelect: true,
|
||||
cursor: 'pointer',
|
||||
dataLabels: {
|
||||
enabled: false
|
||||
},
|
||||
showInLegend: true
|
||||
}
|
||||
},
|
||||
series: [worldSeries]
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
<script>
|
||||
function punchCard() {
|
||||
Highcharts.chart('punchcard' , {
|
||||
@ -682,6 +746,7 @@
|
||||
playersChart();
|
||||
sessionDistributionChart();
|
||||
gmPie();
|
||||
worldPie();
|
||||
punchCard();
|
||||
|
||||
countUpTimer();
|
||||
@ -715,32 +780,9 @@
|
||||
function countUpTimer() {
|
||||
var now = new Date();
|
||||
var begin = new Date(%refreshlong%);
|
||||
var out = "";
|
||||
|
||||
var seconds = now.getTime() - begin.getTime();
|
||||
seconds = Math.floor(seconds / 1000);
|
||||
|
||||
var dd = Math.floor(seconds / 86400);
|
||||
seconds -= (dd * 86400);
|
||||
|
||||
var dh = Math.floor(seconds / 3600);
|
||||
seconds -= (dh * 3600);
|
||||
|
||||
var dm = Math.floor(seconds / 60);
|
||||
seconds -= (dm * 60);
|
||||
|
||||
seconds = Math.floor(seconds);
|
||||
|
||||
if (dd != 0) {
|
||||
out += dd.toString() + "d ";
|
||||
}
|
||||
if (dh != 0) {
|
||||
out += dh.toString() + "h ";
|
||||
}
|
||||
if (dm != 0) {
|
||||
out += dm.toString() + "m ";
|
||||
}
|
||||
out += seconds.toString() + "s ";
|
||||
var out = formatTime(seconds);
|
||||
|
||||
document.getElementById('divTime').innerHTML = out;
|
||||
setTimeout('countUpTimer()', 1000);
|
||||
|
@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.KillHandling;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -26,6 +27,7 @@ import test.java.utils.TestInit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -63,6 +65,19 @@ public class KillHandlingTest {
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsersTable getUsersTable() {
|
||||
return new UsersTable(null, false) {
|
||||
@Override
|
||||
public int getUserId(UUID uuid) {
|
||||
if (uuid.equals(MockUtils.getPlayerUUID())) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
}
|
||||
@ -82,8 +97,6 @@ public class KillHandlingTest {
|
||||
public void testProcessKillInfoPlayer() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
IPlayer dead = MockUtils.mockIPlayer2();
|
||||
db.init();
|
||||
db.saveUserData(new UserData(dead));
|
||||
KillHandling.processKillInfo(data, 10L, (Player) dead.getWrappedPlayerClass(), "TestWeapon");
|
||||
KillData expected = new KillData(dead.getUuid(), 1, "TestWeapon", 10L);
|
||||
assertTrue("Didn't add the kill", data.getPlayerKills().size() == 1);
|
||||
@ -100,9 +113,8 @@ public class KillHandlingTest {
|
||||
*/
|
||||
@Test
|
||||
public void testProcessKillInfoException() throws SQLException, IOException {
|
||||
db.init();
|
||||
UserData data = MockUtils.mockUser();
|
||||
Player dead = (Player) MockUtils.mockIPlayer2().getWrappedPlayerClass();
|
||||
UserData data = MockUtils.mockUser2();
|
||||
Player dead = (Player) MockUtils.mockIPlayer().getWrappedPlayerClass();
|
||||
KillHandling.processKillInfo(data, 10L, dead, "TestWeapon");
|
||||
assertTrue("Added the kill", data.getPlayerKills().isEmpty());
|
||||
}
|
||||
|
@ -36,15 +36,4 @@ public class ChatInfoTest {
|
||||
assertTrue("Didn't succeed", i.process(data));
|
||||
assertTrue("Didn't add nickname", data.getNicknames().contains(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcessWrongUUID() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
String expected = "TestNicknameChatInfo";
|
||||
ChatInfo i = new ChatInfo(null, expected);
|
||||
assertTrue("Succeeded.", !i.process(data));
|
||||
}
|
||||
}
|
||||
|
@ -42,16 +42,4 @@ public class DeathInfoTest {
|
||||
assertTrue(i.process(data));
|
||||
assertEquals(1, data.getDeaths());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcessWrongUUID() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
DeathInfo i = new DeathInfo(null);
|
||||
assertTrue(!i.process(data));
|
||||
assertEquals(0, data.getDeaths());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,17 +5,16 @@
|
||||
*/
|
||||
package test.java.main.java.com.djrapitops.plan.data.handling.info;
|
||||
|
||||
import com.djrapitops.plugin.utilities.player.Fetch;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.KillData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.handling.info.KillInfo;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -25,6 +24,7 @@ import test.java.utils.MockUtils;
|
||||
import test.java.utils.TestInit;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@ -62,18 +62,23 @@ public class KillInfoTest {
|
||||
public void convertBukkitDataToDB() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UsersTable getUsersTable() {
|
||||
return new UsersTable(null, false) {
|
||||
@Override
|
||||
public int getUserId(UUID uuid) {
|
||||
if (uuid.equals(MockUtils.getPlayerUUID())) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
when(plan.getDB()).thenReturn(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws SQLException {
|
||||
db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@ -81,8 +86,6 @@ public class KillInfoTest {
|
||||
public void testProcess() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
Player dead = MockUtils.mockPlayer2();
|
||||
db.init();
|
||||
db.saveUserData(new UserData(Fetch.wrapBukkit(dead)));
|
||||
KillInfo i = new KillInfo(data.getUuid(), 10L, dead, "TestWeapon");
|
||||
assertTrue(i.process(data));
|
||||
KillData expected = new KillData(dead.getUniqueId(), 1, "TestWeapon", 10L);
|
||||
@ -105,17 +108,4 @@ public class KillInfoTest {
|
||||
assertTrue("Added a kill", data.getPlayerKills().isEmpty());
|
||||
assertEquals(1, data.getMobKills());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Test
|
||||
public void testProcessMobKillWrongUUID() throws SQLException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
KillInfo i = new KillInfo(null, 10L, null, "TestWeapon");
|
||||
assertTrue(!i.process(data));
|
||||
assertTrue("Added a kill", data.getPlayerKills().isEmpty());
|
||||
assertEquals(0, data.getMobKills());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,18 +65,4 @@ public class LoginInfoTest {
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Test
|
||||
public void testProcessWrongUUID() throws UnknownHostException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
data.setLastPlayed(0L);
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
String nick = "TestProcessLoginInfo";
|
||||
LoginInfo i = new LoginInfo(null, time, ip, true, nick, "CREATIVE", 1, "World");
|
||||
assertTrue(!i.process(data));
|
||||
}
|
||||
}
|
||||
|
@ -52,19 +52,4 @@ public class LogoutInfoTest {
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
assertEquals(1, data.getSessions().size());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testProcessWrongUUID() {
|
||||
UserData data = MockUtils.mockUser();
|
||||
data.setLastPlayed(10L);
|
||||
data.updateBanned(false);
|
||||
long time = 20L;
|
||||
Exception ex = null;
|
||||
LogoutInfo i = new LogoutInfo(null, time, true, "CREATIVE", new SessionData(0, 1), "World");
|
||||
assertTrue(!i.process(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,17 +66,4 @@ public class ReloadInfoTest {
|
||||
assertEquals("CREATIVE", data.getGmTimes().getState());
|
||||
assertEquals("World", data.getWorldTimes().getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnknownHostException
|
||||
*/
|
||||
@Test
|
||||
public void testProcessWrongUUID() throws UnknownHostException {
|
||||
UserData data = MockUtils.mockUser();
|
||||
InetAddress ip = InetAddress.getByName("137.19.188.146");
|
||||
long time = 10L;
|
||||
String nick = "TestProcessLoginInfo";
|
||||
ReloadInfo i = new ReloadInfo(null, time, ip, true, nick, "CREATIVE", "World");
|
||||
assertTrue(!i.process(data));
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ public class DatabaseTest {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\nOriginal: " + data);
|
||||
System.out.println("Database: "+d);
|
||||
System.out.println("Database: " + d);
|
||||
assertTrue("Not Equals", data.equals(d));
|
||||
}
|
||||
};
|
||||
@ -294,24 +294,14 @@ public class DatabaseTest {
|
||||
list.add(data2);
|
||||
db.saveMultipleUserData(list);
|
||||
data.addPlayerKill(new KillData(MockUtils.getPlayer2UUID(), 2, "DiamondSword", 75843759L));
|
||||
DBCallableProcessor process = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\n" + data.toString());
|
||||
System.out.println(d.toString());
|
||||
assertTrue("Not Equals", data.equals(d));
|
||||
}
|
||||
};
|
||||
db.giveUserDataToProcessors(data.getUuid(), process);
|
||||
DBCallableProcessor process2 = new DBCallableProcessor() {
|
||||
@Override
|
||||
public void process(UserData d) {
|
||||
System.out.println("\n" + data2.toString());
|
||||
System.out.println(d.toString());
|
||||
assertTrue("Not Equals", data2.equals(d));
|
||||
}
|
||||
};
|
||||
db.giveUserDataToProcessors(data2.getUuid(), process2);
|
||||
List<UserData> userDataForUUIDS = db.getUserDataForUUIDS(MockUtils.getUUIDs());
|
||||
|
||||
System.out.println("\nData1:" + data.toString());
|
||||
System.out.println("Data2:" + data2.toString() + "\n");
|
||||
for (UserData uData : userDataForUUIDS) {
|
||||
System.out.println("uData:" + uData.toString());
|
||||
assertTrue("Not Equals", (data.equals(uData) || data2.equals(uData)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,8 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
@ -121,6 +123,13 @@ public class MockUtils {
|
||||
return UUID.fromString("ec94a954-1fa1-445b-b09b-9b698519af80");
|
||||
}
|
||||
|
||||
public static Set<UUID> getUUIDs() {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
uuids.add(getPlayerUUID());
|
||||
uuids.add(getPlayer2UUID());
|
||||
return uuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user