More Bugfixes [2.0.0-DEV]

Fixed Bugs:
- database now contains LoginTimes
- Commandlistener now gives proper command.
- Logintimes no longer null on inspect
- ServerData load SQL format fixed
- NickList and IpList changed to Set

Known bugs:
- (Id while saving might be faulty)
- (Database saves multiples of known things.)
- LastGameMode is set to null when player joins
- (Playtime is negative)
- ServerData not updating properly
- (DataBase saves non-existent ids)
- (LoginTimes is not updated)
- Locations not saved when player moves
- Location ID not primary key
This commit is contained in:
Rsl1122 2016-12-31 22:41:10 +02:00
parent fa776d30fd
commit 6ae61230df
11 changed files with 80 additions and 52 deletions

View File

@ -33,6 +33,8 @@ public class Plan extends JavaPlugin {
@Override
public void onEnable() {
logToFile("-- Server Start/Reload --");
getDataFolder().mkdirs();
databases = new HashSet<>();
@ -75,8 +77,6 @@ public class Plan extends JavaPlugin {
getCommand("plan").setExecutor(new PlanCommand(this));
handler.handleReload();
logToFile("-- Server Start/Reload --");
log("Player Analytics Enabled.");
}
@ -117,7 +117,7 @@ public class Plan extends JavaPlugin {
if (!folder.exists()) {
folder.mkdir();
}
File log = new File(getDataFolder(), "Errors.txt");
File log = new File(getDataFolder(), "Debug.txt");
try {
if (!log.exists()) {
log.createNewFile();
@ -128,7 +128,7 @@ public class Plan extends JavaPlugin {
pw.flush();
}
} catch (IOException e) {
logError("Failed to create Errors.txt file");
logError("Failed to create Debug.txt file");
}
}
}

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
@ -21,11 +22,12 @@ public class InfoCommand extends SubCommand {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
plugin.reloadConfig();
ChatColor operatorColor = ChatColor.DARK_GREEN;
ChatColor textColor = ChatColor.GRAY;
sender.sendMessage(textColor +"--["+operatorColor+"PLAN - Info"+textColor+"]--");
sender.sendMessage(operatorColor+"Version: "+textColor+plugin.getDescription().getVersion());
sender.sendMessage(textColor+MiscUtils.checkVersion());
ChatColor oColor = Phrase.COLOR_MAIN.color();
ChatColor tColor = Phrase.COLOR_SEC.color();
sender.sendMessage(tColor +"--["+oColor+"PLAN - Info"+tColor+"]--");
sender.sendMessage(oColor+"Version: "+tColor+plugin.getDescription().getVersion());
sender.sendMessage(tColor+MiscUtils.checkVersion());
sender.sendMessage(oColor+"Cache\n"+tColor+"Cached users: "+plugin.getHandler().getDataCache().keySet().size());
return true;
}

View File

@ -17,7 +17,7 @@ public class ReloadCommand extends SubCommand {
private Plan plugin;
public ReloadCommand(Plan plugin) {
super("reload", "plan.reload", "Reload plugin config & Hooks", CommandType.CONSOLE);
super("reload", "plan.reload", "Reload plugin config & save cached data", CommandType.CONSOLE);
this.plugin = plugin;
}
@ -25,6 +25,7 @@ public class ReloadCommand extends SubCommand {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
plugin.reloadConfig();
plugin.getHandler().saveCachedData();
plugin.hookPlanLite();
ChatColor operatorColor = Phrase.COLOR_MAIN.color();
ChatColor textColor = Phrase.COLOR_SEC.color();

View File

@ -4,6 +4,7 @@ import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -20,8 +21,8 @@ public class UserData {
private Location location;
private List<Location> locations;
private Location bedLocation;
private List<InetAddress> ips;
private List<String> nicknames;
private HashSet<InetAddress> ips;
private HashSet<String> nicknames;
private long registered;
private long lastPlayed;
private long playTime;
@ -38,14 +39,14 @@ public class UserData {
uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
if (bedLocation == null) {
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0 ,0);
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
registered = player.getFirstPlayed();
location = player.getLocation();
isOp = player.isOp();
locations = new ArrayList<>();
nicknames = new ArrayList<>();
ips = new ArrayList<>();
nicknames = new HashSet<>();
ips = new HashSet<>();
gmTimes = new HashMap<>();
long zero = Long.parseLong("0");
gmTimes.put(GameMode.SURVIVAL, zero);
@ -61,13 +62,13 @@ public class UserData {
uuid = player.getUniqueId();
bedLocation = player.getBedSpawnLocation();
if (bedLocation == null) {
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0 ,0);
bedLocation = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
registered = player.getFirstPlayed();
isOp = player.isOp();
locations = new ArrayList<>();
nicknames = new ArrayList<>();
ips = new ArrayList<>();
nicknames = new HashSet<>();
ips = new HashSet<>();
gmTimes = new HashMap<>();
long zero = Long.parseLong("0");
gmTimes.put(GameMode.SURVIVAL, zero);
@ -90,13 +91,15 @@ public class UserData {
public void addLocation(Location loc) {
locations.add(loc);
location = locations.get(locations.size() - 1);
location = loc;
}
public void addLocations(Collection<Location> addLocs) {
locations.addAll(addLocs);
if (!locations.isEmpty()) {
location = locations.get(locations.size() - 1);
}
}
public void addNickname(String nick) {
if (!nicknames.contains(nick)) {
@ -149,11 +152,11 @@ public class UserData {
return bedLocation;
}
public List<InetAddress> getIps() {
public HashSet<InetAddress> getIps() {
return ips;
}
public List<String> getNicknames() {
public HashSet<String> getNicknames() {
return nicknames;
}
@ -218,11 +221,11 @@ public class UserData {
this.bedLocation = bedLocation;
}
public void setIps(List<InetAddress> ips) {
public void setIps(HashSet<InetAddress> ips) {
this.ips = ips;
}
public void setNicknames(List<String> nicknames) {
public void setNicknames(HashSet<String> nicknames) {
this.nicknames = nicknames;
}

View File

@ -14,15 +14,14 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import static org.bukkit.Bukkit.getOfflinePlayer;
import org.bukkit.GameMode;
import org.bukkit.Location;
import static org.bukkit.Bukkit.getOfflinePlayer;
@ -51,6 +50,7 @@ public abstract class SQLDB extends Database {
private String userColumnDemGender;
private String userColumnLastGM;
private String userColumnLastGMSwapTime;
private String userColumnLoginTimes;
private final String locationColumnUserID;
private String locationColumnID;
private String locationColumnCoordinatesX;
@ -98,6 +98,7 @@ public abstract class SQLDB extends Database {
userColumnLastGM = "last_gamemode";
userColumnLastGMSwapTime = "last_gamemode_swap";
userColumnPlayTime = "play_time";
userColumnLoginTimes = "login_times";
locationColumnCoordinatesX = "x";
locationColumnCoordinatesZ = "z";
@ -162,7 +163,8 @@ public abstract class SQLDB extends Database {
+ userColumnDemGeoLocation + " varchar(50) NOT NULL, "
+ userColumnLastGM + " varchar(15) NOT NULL, "
+ userColumnLastGMSwapTime + " bigint NOT NULL, "
+ userColumnPlayTime + " bigint NOT NULL"
+ userColumnPlayTime + " bigint NOT NULL, "
+ userColumnLoginTimes + " int NOT NULL"
+ ")"
);
@ -315,7 +317,7 @@ public abstract class SQLDB extends Database {
String id = null;
while (set.next()) {
id = set.getString(userColumnID);
id = ""+set.getInt(userColumnID);
if (id == null) {
return null;
}
@ -325,6 +327,7 @@ public abstract class SQLDB extends Database {
data.setLastGamemode(MiscUtils.parseGM(set.getString(userColumnLastGM)));
data.setLastGmSwapTime(set.getLong(userColumnLastGMSwapTime));
data.setPlayTime(set.getLong(userColumnPlayTime));
data.setLoginTimes(set.getInt(userColumnLoginTimes));
}
set.close();
statement.close();
@ -408,15 +411,15 @@ public abstract class SQLDB extends Database {
HashMap<String, Integer> commandUse = getCommandUse();
int newPlayers = 0;
Date now = new Date();
Date startOfToday = new Date(now.getTime() - now.getTime() % 86400000);
Date startOfToday = new Date(now.getTime() - (now.getTime() % 86400000));
try {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + serverdataName
+ "ORDER BY " + serverdataColumnDate + " ASC");
+ " ORDER BY " + serverdataColumnDate + " ASC LIMIT 1");
ResultSet set = statement.executeQuery();
while (set.next()) {
Date lastSave = new Date(set.getLong(serverdataColumnDate));
Date startOfSaveDay = new Date(lastSave.getTime() - lastSave.getTime() % 86400000);
Date startOfSaveDay = new Date(lastSave.getTime() - (lastSave.getTime() % 86400000));
if (startOfSaveDay == startOfToday) {
newPlayers = set.getInt(serverdataColumnNewPlayers);
}
@ -539,7 +542,8 @@ public abstract class SQLDB extends Database {
+ userColumnDemGeoLocation + "=?, "
+ userColumnLastGM + "=?, "
+ userColumnLastGMSwapTime + "=?, "
+ userColumnPlayTime + "=? "
+ userColumnPlayTime + "=?, "
+ userColumnLoginTimes + "=? "
+ "WHERE UPPER(" + userColumnUUID + ") LIKE UPPER(?)";
PreparedStatement statement = connection.prepareStatement(sql);
@ -554,6 +558,8 @@ public abstract class SQLDB extends Database {
}
statement.setLong(5, data.getLastGmSwapTime());
statement.setLong(6, data.getPlayTime());
statement.setInt(7, data.getLoginTimes());
statement.setString(8, uuid.toString());
if (statement.executeUpdate() == 0) {
statement = connection.prepareStatement("INSERT INTO " + userName + " ("
@ -563,8 +569,9 @@ public abstract class SQLDB extends Database {
+ userColumnDemGeoLocation + ", "
+ userColumnLastGM + ", "
+ userColumnLastGMSwapTime + ", "
+ userColumnPlayTime
+ ") VALUES (?, ?, ?, ?, ?, ?, ?)");
+ userColumnPlayTime + ", "
+ userColumnLoginTimes
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
statement.setString(1, uuid.toString());
statement.setInt(2, data.getDemData().getAge());
@ -577,9 +584,11 @@ public abstract class SQLDB extends Database {
}
statement.setLong(6, data.getLastGmSwapTime());
statement.setLong(7, data.getPlayTime());
statement.setInt(8, data.getLoginTimes());
statement.execute();
statement.close();
userId = getUserId(uuid.toString());
}
saveLocationList(userId, data.getLocations());
saveNickList(userId, data.getNicknames());
@ -629,7 +638,7 @@ public abstract class SQLDB extends Database {
}
}
public void saveNickList(int userId, List<String> names) {
public void saveNickList(int userId, HashSet<String> names) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + nicknamesName + " WHERE UPPER(" + nicknamesColumnUserID + ") LIKE UPPER(?)");
@ -653,7 +662,7 @@ public abstract class SQLDB extends Database {
}
}
public void saveIPList(int userId, List<InetAddress> ips) {
public void saveIPList(int userId, HashSet<InetAddress> ips) {
try {
PreparedStatement statement = connection.prepareStatement(
"DELETE FROM " + ipsName + " WHERE UPPER(" + ipsColumnUserID + ") LIKE UPPER(?)");

View File

@ -24,23 +24,25 @@ public class ActivityHandler {
public void saveToCache(Player player, UserData data) {
long timeNow = new Date().getTime();
data.setPlayTime(data.getPlayTime() + (data.getLastPlayed() - timeNow));
data.setPlayTime(data.getPlayTime() + (timeNow - data.getLastPlayed()));
data.setLastPlayed(timeNow);
}
public void handleLogIn(PlayerLoginEvent event, UserData data) {
data.setLastPlayed(new Date().getTime());
data.updateBanned(event.getPlayer());
Player player = event.getPlayer();
data.updateBanned(player);
handler.getLocationHandler().addLocation(player.getUniqueId(), player.getLocation());
}
public void handleLogOut(PlayerQuitEvent event, UserData data) {
Player player = event.getPlayer();
data.setPlayTime(data.getPlayTime() + (data.getLastPlayed() - new Date().getTime()));
data.setPlayTime(data.getPlayTime() + (new Date().getTime() - data.getLastPlayed()));
data.setLastPlayed(player.getLastPlayed());
}
void handleReload(Player player, UserData data) {
data.setPlayTime(data.getPlayTime() + (data.getLastPlayed() - new Date().getTime()));
data.setPlayTime(data.getPlayTime() + (new Date().getTime() - data.getLastPlayed()));
data.setLastPlayed(player.getLastPlayed());
}
}

View File

@ -151,6 +151,10 @@ public class DataHandler {
dataCache.put(player.getUniqueId(), data);
}
public HashMap<UUID, UserData> getDataCache() {
return dataCache;
}
public ActivityHandler getActivityHandler() {
return activityHandler;
}

View File

@ -24,33 +24,40 @@ public class GamemodeTimesHandler {
public void handleChangeEvent(PlayerGameModeChangeEvent event, UserData data) {
HashMap<GameMode, Long> times = data.getGmTimes();
long lastSwap = data.getLastGmSwapTime();
handler.getActivityHandler().saveToCache(event.getPlayer(), data);
long lastSwap = data.getLastGmSwapTime();
long now = data.getPlayTime();
GameMode oldGM = data.getLastGamemode();
data.setGMTime(oldGM, times.get(oldGM) + (lastSwap - now));
data.setGMTime(oldGM, times.get(oldGM) + (now - lastSwap));
GameMode newGM = event.getNewGameMode();
data.setLastGamemode(newGM);
data.setLastGmSwapTime(now);
}
void saveToCache(Player p, UserData data) {
HashMap<GameMode, Long> times = data.getGmTimes();
long lastSwap = data.getLastGmSwapTime();
handler.getActivityHandler().saveToCache(p, data);
long lastSwap = data.getLastGmSwapTime();
long now = data.getPlayTime();
GameMode currentGM = p.getGameMode();
data.setGMTime(currentGM, times.get(currentGM) + (lastSwap - now));
data.setGMTime(currentGM, times.get(currentGM) + (now - lastSwap));
data.setLastGmSwapTime(now);
}
void handleReload(Player p, UserData data) {
HashMap<GameMode, Long> times = data.getGmTimes();
long lastSwap = data.getLastGmSwapTime();
handler.getActivityHandler().saveToCache(p, data);
long lastSwap = data.getLastGmSwapTime();
long now = data.getPlayTime();
GameMode currentGM = p.getGameMode();
data.setGMTime(currentGM, times.get(currentGM) + (lastSwap - now));
data.setGMTime(currentGM, times.get(currentGM) + (now - lastSwap));
data.setLastGmSwapTime(now);
}

View File

@ -25,6 +25,6 @@ public class PlanCommandPreprocessListener implements Listener {
if (event.isCancelled()) {
return;
}
serverH.handleCommand(event.getMessage().split("\\s*")[0]);
serverH.handleCommand(event.getMessage().split(" ")[0]);
}
}

View File

@ -30,7 +30,7 @@ public class PlanPlayerMoveListener implements Listener {
Player p = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ() && from.getWorld() == to.getWorld()) {
if (from.getX() == to.getX() && from.getZ() == to.getZ()) {
return;
}
locationH.addLocation(p.getUniqueId(), to);