mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-01 00:10:12 +01:00
Bugfixes [2.6.1]
- Fix for #17: Schema now updated properly - Fix for #18 Hooks to other plugins no longer cause NPE if plugin is not found. (Added another constructor that sets isEnabled to false) - Fix for #19 Removed debug message and replaced with continue; - Fix for #20 Made new player creation async Made inspect & search commands async
This commit is contained in:
parent
44d1f6f021
commit
964954c674
@ -67,7 +67,9 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
|
||||
|
||||
BukkitTask inspectTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||
@ -76,16 +78,19 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
|
||||
return true;
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
|
||||
if (!p.hasPlayedBefore()) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_SEEN.toString());
|
||||
return true;
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
if (!plugin.getDB().wasSeenBefore(uuid)) {
|
||||
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
|
||||
return true;
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
inspectCache.cache(uuid);
|
||||
@ -127,6 +132,8 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -63,6 +65,9 @@ public class SearchCommand extends SubCommand {
|
||||
|
||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
|
||||
BukkitTask searchTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
for (OfflinePlayer match : matches) {
|
||||
UUID uuid = match.getUniqueId();
|
||||
@ -107,6 +112,8 @@ public class SearchCommand extends SubCommand {
|
||||
}
|
||||
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available + ""));
|
||||
sender.sendMessage(Phrase.CMD_FOOTER + "");
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ public class AdvancedAchievementsHook extends Hook {
|
||||
}
|
||||
}
|
||||
|
||||
public AdvancedAchievementsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
private int calcTotalAchievements() throws Exception, NoClassDefFoundError {
|
||||
int total = 0;
|
||||
for (NormalAchievements category : NormalAchievements.values()) {
|
||||
|
@ -33,6 +33,11 @@ public class EssentialsHook extends Hook {
|
||||
}
|
||||
}
|
||||
|
||||
public EssentialsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs information not provided by Player class or Plan from Essentials.
|
||||
* isEnabled() should be called before this method.
|
||||
|
@ -32,6 +32,11 @@ public class FactionsHook extends Hook {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public FactionsHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
|
@ -25,6 +25,10 @@ public abstract class Hook {
|
||||
}
|
||||
}
|
||||
|
||||
public Hook() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not the plugin was successfully hooked.
|
||||
*/
|
||||
|
@ -32,12 +32,36 @@ public class HookHandler {
|
||||
}
|
||||
|
||||
private void hook() {
|
||||
try {advancedAchievementsHook = new AdvancedAchievementsHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {essentialsHook = new EssentialsHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {superbVoteHook = new SuperbVoteHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {factionsHook = new FactionsHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {townyHook = new TownyHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {onTimeHook = new OnTimeHook(plan);} catch (NoClassDefFoundError e) {}
|
||||
try {
|
||||
advancedAchievementsHook = new AdvancedAchievementsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
advancedAchievementsHook = new AdvancedAchievementsHook();
|
||||
}
|
||||
try {
|
||||
essentialsHook = new EssentialsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
essentialsHook = new EssentialsHook();
|
||||
}
|
||||
try {
|
||||
superbVoteHook = new SuperbVoteHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
superbVoteHook = new SuperbVoteHook();
|
||||
}
|
||||
try {
|
||||
factionsHook = new FactionsHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
factionsHook = new FactionsHook();
|
||||
}
|
||||
try {
|
||||
townyHook = new TownyHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
townyHook = new TownyHook();
|
||||
}
|
||||
try {
|
||||
onTimeHook = new OnTimeHook(plan);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
onTimeHook = new OnTimeHook();
|
||||
}
|
||||
}
|
||||
|
||||
public AdvancedAchievementsHook getAdvancedAchievementsHook() {
|
||||
|
@ -25,6 +25,11 @@ public class OnTimeHook extends Hook {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public OnTimeHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs information not provided by Player class or Plan from OnTime.
|
||||
* isEnabled() should be called before this method.
|
||||
|
@ -24,6 +24,11 @@ public class SuperbVoteHook extends Hook {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public SuperbVoteHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs votes from SuperbVote.
|
||||
* isEnabled() should be called before this
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||
@ -23,7 +22,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
public class TownyHook extends Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
private final Towny towny;
|
||||
private Towny towny;
|
||||
|
||||
/**
|
||||
* Hooks to Factions plugin
|
||||
@ -36,6 +35,11 @@ public class TownyHook extends Hook {
|
||||
this.towny = getPlugin(Towny.class);
|
||||
}
|
||||
|
||||
public TownyHook() {
|
||||
super();
|
||||
plugin = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of Faction names sorted by power
|
||||
*/
|
||||
@ -62,7 +66,7 @@ public class TownyHook extends Hook {
|
||||
info.put("RESIDENTS", town.getNumResidents());
|
||||
info.put("MAYOR", town.getMayor().getName());
|
||||
info.put("LAND", town.getPurchasedBlocks());
|
||||
} catch (NotRegisteredException ex) {
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
@ -85,7 +89,7 @@ public class TownyHook extends Hook {
|
||||
info.put("TOWN", "Not in town");
|
||||
}
|
||||
info.put("FRIENDS", res.getFriends().toString());
|
||||
} catch (NotRegisteredException ex) {
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -61,6 +63,9 @@ public class PlanPlayerListener implements Listener {
|
||||
public void onPlayerLogin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
BukkitTask asyncLoginSaveTask = (new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean isNewPlayer = activityH.isFirstTimeJoin(uuid);
|
||||
if (isNewPlayer) {
|
||||
handler.newPlayer(player);
|
||||
@ -77,6 +82,9 @@ public class PlanPlayerListener implements Listener {
|
||||
}
|
||||
};
|
||||
handler.getUserDataForProcessing(loginProcessor, uuid);
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -188,9 +189,12 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
boolean usingMySQL = supportsModification;
|
||||
|
||||
ResultSet set = connection.prepareStatement(supportsModification ? ("SHOW TABLES LIKE '" + userName + "'") : "SELECT name FROM sqlite_master WHERE type='table' AND name='" + userName + "'").executeQuery();
|
||||
boolean newDatabase = set.next();
|
||||
set.close();
|
||||
boolean newDatabase = true;
|
||||
try {
|
||||
getVersion();
|
||||
newDatabase = false;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
|
||||
+ userColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
|
||||
+ userColumnUUID + " varchar(36) NOT NULL UNIQUE, "
|
||||
@ -272,38 +276,29 @@ public abstract class SQLDB extends Database {
|
||||
+ ")"
|
||||
);
|
||||
if (newDatabase) {
|
||||
setVersion(2);
|
||||
plugin.log("New Database created.");
|
||||
setVersion(3);
|
||||
}
|
||||
int version = getVersion();
|
||||
if (version < 1) {
|
||||
if (version < 3) {
|
||||
String sqlite = usingMySQL ? "" : "COLUMN ";
|
||||
String[] queries = new String[]{
|
||||
"ALTER TABLE " + userName + " ADD " + userColumnDeaths + " integer NOT NULL DEFAULT 0",
|
||||
"ALTER TABLE " + userName + " ADD " + userColumnMobKills + " integer NOT NULL DEFAULT 0",
|
||||
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT (false)",
|
||||
"DROP TABLE IF EXISTS " + serverdataName
|
||||
};
|
||||
for (String query : queries) {
|
||||
try {
|
||||
query(query);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
setVersion(1);
|
||||
} else if (version < 2) {
|
||||
String[] queries = new String[]{
|
||||
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT 0",
|
||||
"ALTER TABLE " + userName + " ADD " + sqlite + userColumnDeaths + " integer NOT NULL DEFAULT 0",
|
||||
"ALTER TABLE " + userName + " ADD " + sqlite + userColumnMobKills + " integer NOT NULL DEFAULT 0",
|
||||
"ALTER TABLE " + nicknamesName + " ADD " + sqlite + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT 0",
|
||||
"DROP TABLE IF EXISTS " + serverdataName
|
||||
};
|
||||
for (String query : queries) {
|
||||
try {
|
||||
query(query);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (usingMySQL) {
|
||||
query("ALTER TABLE " + userName + " DROP INDEX " + userColumnPlayerKills);
|
||||
}
|
||||
setVersion(2);
|
||||
setVersion(3);
|
||||
}
|
||||
|
||||
}
|
||||
@ -514,7 +509,6 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
// Check if user is in the database
|
||||
if (!wasSeenBefore(uuid)) {
|
||||
plugin.logError(uuid + " was not found from the database!");
|
||||
return;
|
||||
}
|
||||
List<World> worldList = Bukkit.getServer().getWorlds();
|
||||
@ -705,7 +699,7 @@ public abstract class SQLDB extends Database {
|
||||
for (UserData uData : data) {
|
||||
try {
|
||||
if (uData == null) {
|
||||
throw new IllegalStateException("UserData is null somehow!");
|
||||
continue;
|
||||
}
|
||||
uData.access();
|
||||
int userId = getUserId(uData.getUuid().toString());
|
||||
@ -751,7 +745,7 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
for (UserData uData : data) {
|
||||
if (uData == null) {
|
||||
throw new IllegalStateException("UserData is null somehow!");
|
||||
continue;
|
||||
}
|
||||
uData.access();
|
||||
try {
|
||||
@ -867,7 +861,9 @@ public abstract class SQLDB extends Database {
|
||||
}
|
||||
|
||||
public void saveAdditionalLocationsList(int userId, List<Location> locations) throws SQLException {
|
||||
if (locations.isEmpty()) {
|
||||
List<Location> newLocations = new ArrayList<>();
|
||||
newLocations.addAll(locations);
|
||||
if (newLocations.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PreparedStatement saveStatement = connection.prepareStatement("INSERT INTO " + locationName + " ("
|
||||
@ -877,8 +873,8 @@ public abstract class SQLDB extends Database {
|
||||
+ locationColumnWorld
|
||||
+ ") VALUES (?, ?, ?, ?)");
|
||||
boolean commitRequired = false;
|
||||
if (!locations.isEmpty()) {
|
||||
for (Location location : locations) {
|
||||
if (!newLocations.isEmpty()) {
|
||||
for (Location location : newLocations) {
|
||||
saveStatement.setInt(1, userId);
|
||||
saveStatement.setInt(2, (int) location.getBlockX());
|
||||
saveStatement.setInt(3, (int) location.getBlockZ());
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Plan
|
||||
author: Rsl1122
|
||||
main: main.java.com.djrapitops.plan.Plan
|
||||
version: 2.6.0
|
||||
version: 2.6.1
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
|
Loading…
Reference in New Issue
Block a user