[2.5.2] Fix for #11 & Player fetch optimization for analysis

- Removed bedlocation because it was causing issues
- Total players now displays only players found in the database.
This commit is contained in:
Rsl1122 2017-02-13 11:02:27 +02:00
parent 869df1f374
commit b6d245725f
5 changed files with 11 additions and 40 deletions

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData; import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -22,7 +21,6 @@ public class UserData {
private UUID uuid; private UUID uuid;
private Location location; private Location location;
private List<Location> locations; private List<Location> locations;
private Location bedLocation;
private HashSet<InetAddress> ips; private HashSet<InetAddress> ips;
private HashSet<String> nicknames; private HashSet<String> nicknames;
private long registered; private long registered;
@ -49,10 +47,6 @@ public class UserData {
public UserData(Player player, DemographicsData demData, Database db) { public UserData(Player player, DemographicsData demData, Database db) {
uuid = player.getUniqueId(); uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
if (bedLocation == null) {
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
registered = player.getFirstPlayed(); registered = player.getFirstPlayed();
location = player.getLocation(); location = player.getLocation();
isOp = player.isOp(); isOp = player.isOp();
@ -77,10 +71,6 @@ public class UserData {
public UserData(OfflinePlayer player, DemographicsData demData, Database db) { public UserData(OfflinePlayer player, DemographicsData demData, Database db) {
uuid = player.getUniqueId(); uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
if (bedLocation == null) {
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
registered = player.getFirstPlayed(); registered = player.getFirstPlayed();
isOp = player.isOp(); isOp = player.isOp();
locations = new ArrayList<>(); locations = new ArrayList<>();
@ -189,10 +179,6 @@ public class UserData {
return locations; return locations;
} }
public Location getBedLocation() {
return bedLocation;
}
public HashSet<InetAddress> getIps() { public HashSet<InetAddress> getIps() {
return ips; return ips;
} }
@ -262,10 +248,6 @@ public class UserData {
this.locations = locations; this.locations = locations;
} }
public void setBedLocation(Location bedLocation) {
this.bedLocation = bedLocation;
}
public void setIps(HashSet<InetAddress> ips) { public void setIps(HashSet<InetAddress> ips) {
this.ips = ips; this.ips = ips;
} }

View File

@ -5,7 +5,6 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.UserData; import com.djrapitops.plan.data.UserData;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -68,6 +67,5 @@ public class LocationHandler {
if (bedSpawnLocation == null) { if (bedSpawnLocation == null) {
return; return;
} }
handler.getCurrentData(p.getUniqueId()).setBedLocation(bedSpawnLocation);
} }
} }

View File

@ -20,8 +20,8 @@ import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData; import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import main.java.com.djrapitops.plan.ui.Html; import main.java.com.djrapitops.plan.ui.Html;
import main.java.com.djrapitops.plan.utilities.HtmlUtils; import main.java.com.djrapitops.plan.utilities.HtmlUtils;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
/** /**
@ -61,15 +61,8 @@ public class Analysis {
rawData.clear(); rawData.clear();
added.clear(); added.clear();
log(Phrase.ANALYSIS_START + ""); log(Phrase.ANALYSIS_START + "");
OfflinePlayer[] offlinePlayers;
try {
offlinePlayers = plugin.getServer().getOfflinePlayers();
} catch (IndexOutOfBoundsException e) {
plugin.log(Phrase.ANALYSIS_FAIL_NO_PLAYERS + "");
return;
}
List<UUID> uuids = fetchPlayersInDB(offlinePlayers); List<UUID> uuids = fetchPlayersInDB();
if (uuids.isEmpty()) { if (uuids.isEmpty()) {
plugin.log(Phrase.ANALYSIS_FAIL_NO_DATA + ""); plugin.log(Phrase.ANALYSIS_FAIL_NO_DATA + "");
return; return;
@ -187,7 +180,7 @@ public class Analysis {
totalMobKills += uData.getMobKills(); totalMobKills += uData.getMobKills();
totalDeaths += uData.getDeaths(); totalDeaths += uData.getDeaths();
} catch (NullPointerException e) { } catch (NullPointerException e) {
plugin.logError(Phrase.DATA_CORRUPTION_WARN.parse(uData.getUuid()+"")); plugin.logError(Phrase.DATA_CORRUPTION_WARN.parse(uData.getUuid() + ""));
} }
} }
@ -250,7 +243,7 @@ public class Analysis {
data.setInactive(inactive); data.setInactive(inactive);
data.setBanned(totalBanned); data.setBanned(totalBanned);
data.setJoinleaver(joinleaver); data.setJoinleaver(joinleaver);
data.setTotal(offlinePlayers.length); data.setTotal(uuids.size());
} }
private void analyzeAverageAge(List<Integer> ages, AnalysisData data) { private void analyzeAverageAge(List<Integer> ages, AnalysisData data) {
@ -362,16 +355,15 @@ public class Analysis {
}).runTaskAsynchronously(plugin); }).runTaskAsynchronously(plugin);
} }
private List<UUID> fetchPlayersInDB(OfflinePlayer[] offlinePlayers) { private List<UUID> fetchPlayersInDB() {
final List<UUID> uuids = new ArrayList<>(); final List<UUID> uuids = new ArrayList<>();
log(Phrase.ANALYSIS_FETCH_PLAYERS + ""); log(Phrase.ANALYSIS_FETCH_PLAYERS + "");
Set<UUID> savedUUIDs = plugin.getDB().getSavedUUIDs(); Set<UUID> savedUUIDs = plugin.getDB().getSavedUUIDs();
for (OfflinePlayer p : offlinePlayers) { savedUUIDs.parallelStream()
UUID uuid = p.getUniqueId(); .filter((uuid) -> (getOfflinePlayer(uuid).hasPlayedBefore()))
if (savedUUIDs.contains(uuid)) { .forEach((uuid) -> {
uuids.add(uuid); uuids.add(uuid);
} });
}
return uuids; return uuids;
} }

View File

@ -94,7 +94,6 @@ public class PlaceholderUtils {
replaceMap.put("%uuid%", (showIPandUUID ? "" + data.getUuid() : Html.HIDDEN.parse())); replaceMap.put("%uuid%", (showIPandUUID ? "" + data.getUuid() : Html.HIDDEN.parse()));
replaceMap.put("%lastseen%", FormatUtils.formatTimeStamp("" + data.getLastPlayed())); replaceMap.put("%lastseen%", FormatUtils.formatTimeStamp("" + data.getLastPlayed()));
replaceMap.put("%logintimes%", "" + data.getLoginTimes()); replaceMap.put("%logintimes%", "" + data.getLoginTimes());
replaceMap.put("%bed%", FormatUtils.formatLocation(data.getBedLocation()));
replaceMap.put("%geoloc%", data.getDemData().getGeoLocation()); replaceMap.put("%geoloc%", data.getDemData().getGeoLocation());
boolean isActive = AnalysisUtils.isActive(data.getLastPlayed(), data.getPlayTime(), data.getLoginTimes()); boolean isActive = AnalysisUtils.isActive(data.getLastPlayed(), data.getPlayTime(), data.getLoginTimes());
replaceMap.put("%active%", isActive ? Html.ACTIVE.parse() : Html.INACTIVE.parse()); replaceMap.put("%active%", isActive ? Html.ACTIVE.parse() : Html.INACTIVE.parse());

View File

@ -1,7 +1,7 @@
name: Plan name: Plan
author: Rsl1122 author: Rsl1122
main: com.djrapitops.plan.Plan main: com.djrapitops.plan.Plan
version: 2.5.1 version: 2.5.2
commands: commands:
plan: plan: