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:
Rsl1122 2017-02-22 11:36:09 +02:00
parent 44d1f6f021
commit 964954c674
13 changed files with 226 additions and 151 deletions

View File

@ -33,7 +33,7 @@ public class InspectCommand extends SubCommand {
* @param plugin Current instance of Plan
*/
public InspectCommand(Plan plugin) {
super("inspect", "plan.inspect", Phrase.CMD_USG_INSPECT+"", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_PLAYER+"");
super("inspect", "plan.inspect", Phrase.CMD_USG_INSPECT + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_PLAYER + "");
this.plugin = plugin;
inspectCache = plugin.getInspectCache();
@ -67,66 +67,73 @@ public class InspectCommand extends SubCommand {
}
}
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
UUID uuid;
try {
uuid = UUIDFetcher.getUUIDOf(playerName);
if (uuid == null) {
throw new Exception("Username doesn't exist.");
}
} catch (Exception e) {
sender.sendMessage(Phrase.USERNAME_NOT_VALID.toString());
return true;
}
OfflinePlayer p = Bukkit.getOfflinePlayer(uuid);
if (!p.hasPlayedBefore()) {
sender.sendMessage(Phrase.USERNAME_NOT_SEEN.toString());
return true;
}
if (!plugin.getDB().wasSeenBefore(uuid)) {
sender.sendMessage(Phrase.USERNAME_NOT_KNOWN.toString());
return true;
}
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() {
private int timesrun = 0;
BukkitTask inspectTask = (new BukkitRunnable() {
@Override
public void run() {
timesrun++;
if (inspectCache.isCached(uuid)) {
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
// 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 + "\"}}]");
UUID uuid;
try {
uuid = UUIDFetcher.getUUIDOf(playerName);
if (uuid == null) {
throw new Exception("Username doesn't exist.");
}
} 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() {
private int timesrun = 0;
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available+""));
sender.sendMessage(Phrase.CMD_FOOTER+"");
this.cancel();
}
if (timesrun > 10) {
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
this.cancel();
}
@Override
public void run() {
timesrun++;
if (inspectCache.isCached(uuid)) {
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
// 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 + "");
this.cancel();
}
if (timesrun > 10) {
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
this.cancel();
}
}
}).runTaskTimer(plugin, 1 * 20, 5 * 20);
}
}).runTaskTimer(plugin, 1 * 20, 5 * 20);
}).runTaskAsynchronously(plugin);
return true;
}
}

View File

@ -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;
/**
*
@ -33,7 +35,7 @@ public class SearchCommand extends SubCommand {
* @param plugin Current instance of Plan
*/
public SearchCommand(Plan plugin) {
super("search", "plan.search", Phrase.CMD_USG_SEARCH+"", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_SEARCH+"");
super("search", "plan.search", Phrase.CMD_USG_SEARCH + "", CommandType.CONSOLE_WITH_ARGUMENTS, Phrase.ARG_SEARCH + "");
this.plugin = plugin;
inspectCache = plugin.getInspectCache();
}
@ -63,50 +65,55 @@ public class SearchCommand extends SubCommand {
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
Set<UUID> uuids = new HashSet<>();
for (OfflinePlayer match : matches) {
UUID uuid = match.getUniqueId();
if (plugin.getDB().wasSeenBefore(uuid)) {
uuids.add(uuid);
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()) {
sender.sendMessage(Phrase.CMD_NO_RESULTS.parse(Arrays.toString(args)));
} else {
for (OfflinePlayer match : matches) {
if (!uuids.contains(match.getUniqueId())) {
continue;
BukkitTask searchTask = (new BukkitRunnable() {
@Override
public void run() {
Set<UUID> uuids = new HashSet<>();
for (OfflinePlayer match : matches) {
UUID uuid = match.getUniqueId();
if (plugin.getDB().wasSeenBefore(uuid)) {
uuids.add(uuid);
inspectCache.cache(uuid);
}
}
String name = match.getName();
sender.sendMessage(Phrase.CMD_MATCH + name);
// Link
String url = HtmlUtils.getInspectUrl(name);
String message = Phrase.CMD_LINK+"";
boolean console = !(sender instanceof Player);
if (console) {
sender.sendMessage(message + url);
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()) {
sender.sendMessage(Phrase.CMD_NO_RESULTS.parse(Arrays.toString(args)));
} else {
sender.sendMessage(message);
Player player = (Player) sender;
Bukkit.getServer().dispatchCommand(
Bukkit.getConsoleSender(),
"tellraw " + player.getName() + " [\"\",{\"text\":\"Click Me\",\"underlined\":true,"
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
for (OfflinePlayer match : matches) {
if (!uuids.contains(match.getUniqueId())) {
continue;
}
String name = match.getName();
sender.sendMessage(Phrase.CMD_MATCH + name);
// Link
String url = HtmlUtils.getInspectUrl(name);
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\":\"Click Me\",\"underlined\":true,"
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
}
}
}
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available + ""));
sender.sendMessage(Phrase.CMD_FOOTER + "");
}
}
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available+""));
sender.sendMessage(Phrase.CMD_FOOTER+"");
}).runTaskAsynchronously(plugin);
return true;
}
}

View File

@ -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()) {

View File

@ -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.

View File

@ -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
*/

View File

@ -25,6 +25,10 @@ public abstract class Hook {
}
}
public Hook() {
enabled = false;
}
/**
* @return Whether or not the plugin was successfully hooked.
*/

View File

@ -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() {
@ -73,7 +97,7 @@ public class HookHandler {
TownyHook tH = townyHook;
addReplace.put("%towntable%", tH.isEnabled() ? SortableTownTableCreator.createSortableTownsTable(tH.getTopTowns(), tH) : "");
addReplace.put("%factionstable%", fH.isEnabled() ? SortableFactionsTableCreator.createSortableFactionsTable(fH.getTopFactions(), fH) : "");
addReplace.put("%essentialswarps%", eH.isEnabled() ? "<br/>Warps: "+eH.getWarps().toString() : "");
addReplace.put("%essentialswarps%", eH.isEnabled() ? "<br/>Warps: " + eH.getWarps().toString() : "");
return addReplace;
}

View File

@ -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.

View File

@ -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

View File

@ -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;
}

View File

@ -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,22 +63,28 @@ public class PlanPlayerListener implements Listener {
public void onPlayerLogin(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
boolean isNewPlayer = activityH.isFirstTimeJoin(uuid);
if (isNewPlayer) {
handler.newPlayer(player);
}
DBCallableProcessor loginProcessor = new DBCallableProcessor() {
BukkitTask asyncLoginSaveTask = (new BukkitRunnable() {
@Override
public void process(UserData data) {
activityH.handleLogin(player.isBanned(), data);
InetAddress ip = player.getAddress().getAddress();
basicInfoH.handleLogin(player.getDisplayName(), ip, data);
gmTimesH.handleLogin(player.getGameMode(), data);
demographicH.handleLogin(ip, data);
handler.saveCachedData(uuid);
public void run() {
boolean isNewPlayer = activityH.isFirstTimeJoin(uuid);
if (isNewPlayer) {
handler.newPlayer(player);
}
DBCallableProcessor loginProcessor = new DBCallableProcessor() {
@Override
public void process(UserData data) {
activityH.handleLogin(player.isBanned(), data);
InetAddress ip = player.getAddress().getAddress();
basicInfoH.handleLogin(player.getDisplayName(), ip, data);
gmTimesH.handleLogin(player.getGameMode(), data);
demographicH.handleLogin(ip, data);
handler.saveCachedData(uuid);
}
};
handler.getUserDataForProcessing(loginProcessor, uuid);
this.cancel();
}
};
handler.getUserDataForProcessing(loginProcessor, uuid);
}).runTaskAsynchronously(plugin);
}
/**

View File

@ -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());

View File

@ -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