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
@ -33,7 +33,7 @@ public class InspectCommand extends SubCommand {
|
|||||||
* @param plugin Current instance of Plan
|
* @param plugin Current instance of Plan
|
||||||
*/
|
*/
|
||||||
public InspectCommand(Plan plugin) {
|
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;
|
this.plugin = plugin;
|
||||||
inspectCache = plugin.getInspectCache();
|
inspectCache = plugin.getInspectCache();
|
||||||
@ -67,66 +67,73 @@ public class InspectCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
|
String playerName = MiscUtils.getPlayerDisplayname(args, sender);
|
||||||
|
BukkitTask inspectTask = (new BukkitRunnable() {
|
||||||
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;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
timesrun++;
|
UUID uuid;
|
||||||
if (inspectCache.isCached(uuid)) {
|
try {
|
||||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
uuid = UUIDFetcher.getUUIDOf(playerName);
|
||||||
// Link
|
if (uuid == null) {
|
||||||
String url = HtmlUtils.getInspectUrl(playerName);
|
throw new Exception("Username doesn't exist.");
|
||||||
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 + "\"}}]");
|
|
||||||
}
|
}
|
||||||
|
} 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+""));
|
@Override
|
||||||
sender.sendMessage(Phrase.CMD_FOOTER+"");
|
public void run() {
|
||||||
this.cancel();
|
timesrun++;
|
||||||
}
|
if (inspectCache.isCached(uuid)) {
|
||||||
if (timesrun > 10) {
|
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
// Link
|
||||||
this.cancel();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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
|
* @param plugin Current instance of Plan
|
||||||
*/
|
*/
|
||||||
public SearchCommand(Plan plugin) {
|
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;
|
this.plugin = plugin;
|
||||||
inspectCache = plugin.getInspectCache();
|
inspectCache = plugin.getInspectCache();
|
||||||
}
|
}
|
||||||
@ -63,50 +65,55 @@ public class SearchCommand extends SubCommand {
|
|||||||
|
|
||||||
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
|
||||||
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
|
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
|
||||||
Set<UUID> uuids = new HashSet<>();
|
BukkitTask searchTask = (new BukkitRunnable() {
|
||||||
for (OfflinePlayer match : matches) {
|
@Override
|
||||||
UUID uuid = match.getUniqueId();
|
public void run() {
|
||||||
if (plugin.getDB().wasSeenBefore(uuid)) {
|
Set<UUID> uuids = new HashSet<>();
|
||||||
uuids.add(uuid);
|
for (OfflinePlayer match : matches) {
|
||||||
inspectCache.cache(uuid);
|
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;
|
|
||||||
}
|
}
|
||||||
String name = match.getName();
|
|
||||||
sender.sendMessage(Phrase.CMD_MATCH + name);
|
int configValue = Settings.CLEAR_INSPECT_CACHE.getNumber();
|
||||||
// Link
|
if (configValue <= 0) {
|
||||||
String url = HtmlUtils.getInspectUrl(name);
|
configValue = 4;
|
||||||
String message = Phrase.CMD_LINK+"";
|
}
|
||||||
boolean console = !(sender instanceof Player);
|
final int available = configValue;
|
||||||
if (console) {
|
|
||||||
sender.sendMessage(message + url);
|
sender.sendMessage(Phrase.CMD_SEARCH_HEADER + args[0]);
|
||||||
|
// Results
|
||||||
|
if (uuids.isEmpty()) {
|
||||||
|
sender.sendMessage(Phrase.CMD_NO_RESULTS.parse(Arrays.toString(args)));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(message);
|
for (OfflinePlayer match : matches) {
|
||||||
Player player = (Player) sender;
|
if (!uuids.contains(match.getUniqueId())) {
|
||||||
Bukkit.getServer().dispatchCommand(
|
continue;
|
||||||
Bukkit.getConsoleSender(),
|
}
|
||||||
"tellraw " + player.getName() + " [\"\",{\"text\":\"Click Me\",\"underlined\":true,"
|
String name = match.getName();
|
||||||
+ "\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + url + "\"}}]");
|
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 + "");
|
||||||
}
|
}
|
||||||
}
|
}).runTaskAsynchronously(plugin);
|
||||||
sender.sendMessage(Phrase.CMD_RESULTS_AVAILABLE.parse(available+""));
|
|
||||||
sender.sendMessage(Phrase.CMD_FOOTER+"");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ public class AdvancedAchievementsHook extends Hook {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AdvancedAchievementsHook() {
|
||||||
|
super();
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
private int calcTotalAchievements() throws Exception, NoClassDefFoundError {
|
private int calcTotalAchievements() throws Exception, NoClassDefFoundError {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (NormalAchievements category : NormalAchievements.values()) {
|
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.
|
* Grabs information not provided by Player class or Plan from Essentials.
|
||||||
* isEnabled() should be called before this method.
|
* isEnabled() should be called before this method.
|
||||||
|
@ -32,6 +32,11 @@ public class FactionsHook extends Hook {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FactionsHook() {
|
||||||
|
super();
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of Faction names sorted by power
|
* @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.
|
* @return Whether or not the plugin was successfully hooked.
|
||||||
*/
|
*/
|
||||||
|
@ -32,12 +32,36 @@ public class HookHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void hook() {
|
private void hook() {
|
||||||
try {advancedAchievementsHook = new AdvancedAchievementsHook(plan);} catch (NoClassDefFoundError e) {}
|
try {
|
||||||
try {essentialsHook = new EssentialsHook(plan);} catch (NoClassDefFoundError e) {}
|
advancedAchievementsHook = new AdvancedAchievementsHook(plan);
|
||||||
try {superbVoteHook = new SuperbVoteHook(plan);} catch (NoClassDefFoundError e) {}
|
} catch (NoClassDefFoundError e) {
|
||||||
try {factionsHook = new FactionsHook(plan);} catch (NoClassDefFoundError e) {}
|
advancedAchievementsHook = new AdvancedAchievementsHook();
|
||||||
try {townyHook = new TownyHook(plan);} catch (NoClassDefFoundError e) {}
|
}
|
||||||
try {onTimeHook = new OnTimeHook(plan);} catch (NoClassDefFoundError e) {}
|
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() {
|
public AdvancedAchievementsHook getAdvancedAchievementsHook() {
|
||||||
@ -73,7 +97,7 @@ public class HookHandler {
|
|||||||
TownyHook tH = townyHook;
|
TownyHook tH = townyHook;
|
||||||
addReplace.put("%towntable%", tH.isEnabled() ? SortableTownTableCreator.createSortableTownsTable(tH.getTopTowns(), tH) : "");
|
addReplace.put("%towntable%", tH.isEnabled() ? SortableTownTableCreator.createSortableTownsTable(tH.getTopTowns(), tH) : "");
|
||||||
addReplace.put("%factionstable%", fH.isEnabled() ? SortableFactionsTableCreator.createSortableFactionsTable(fH.getTopFactions(), fH) : "");
|
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;
|
return addReplace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ public class OnTimeHook extends Hook {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OnTimeHook() {
|
||||||
|
super();
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs information not provided by Player class or Plan from OnTime.
|
* Grabs information not provided by Player class or Plan from OnTime.
|
||||||
* isEnabled() should be called before this method.
|
* isEnabled() should be called before this method.
|
||||||
|
@ -24,6 +24,11 @@ public class SuperbVoteHook extends Hook {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SuperbVoteHook() {
|
||||||
|
super();
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grabs votes from SuperbVote.
|
* Grabs votes from SuperbVote.
|
||||||
* isEnabled() should be called before this
|
* isEnabled() should be called before this
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main.java.com.djrapitops.plan.data.additional;
|
package main.java.com.djrapitops.plan.data.additional;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.Towny;
|
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.Resident;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
@ -23,7 +22,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
|||||||
public class TownyHook extends Hook {
|
public class TownyHook extends Hook {
|
||||||
|
|
||||||
private final Plan plugin;
|
private final Plan plugin;
|
||||||
private final Towny towny;
|
private Towny towny;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hooks to Factions plugin
|
* Hooks to Factions plugin
|
||||||
@ -36,6 +35,11 @@ public class TownyHook extends Hook {
|
|||||||
this.towny = getPlugin(Towny.class);
|
this.towny = getPlugin(Towny.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TownyHook() {
|
||||||
|
super();
|
||||||
|
plugin = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of Faction names sorted by power
|
* @return List of Faction names sorted by power
|
||||||
*/
|
*/
|
||||||
@ -62,7 +66,7 @@ public class TownyHook extends Hook {
|
|||||||
info.put("RESIDENTS", town.getNumResidents());
|
info.put("RESIDENTS", town.getNumResidents());
|
||||||
info.put("MAYOR", town.getMayor().getName());
|
info.put("MAYOR", town.getMayor().getName());
|
||||||
info.put("LAND", town.getPurchasedBlocks());
|
info.put("LAND", town.getPurchasedBlocks());
|
||||||
} catch (NotRegisteredException ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
@ -85,7 +89,7 @@ public class TownyHook extends Hook {
|
|||||||
info.put("TOWN", "Not in town");
|
info.put("TOWN", "Not in town");
|
||||||
}
|
}
|
||||||
info.put("FRIENDS", res.getFriends().toString());
|
info.put("FRIENDS", res.getFriends().toString());
|
||||||
} catch (NotRegisteredException ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
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) {
|
public void onPlayerLogin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
boolean isNewPlayer = activityH.isFirstTimeJoin(uuid);
|
BukkitTask asyncLoginSaveTask = (new BukkitRunnable() {
|
||||||
if (isNewPlayer) {
|
|
||||||
handler.newPlayer(player);
|
|
||||||
}
|
|
||||||
DBCallableProcessor loginProcessor = new DBCallableProcessor() {
|
|
||||||
@Override
|
@Override
|
||||||
public void process(UserData data) {
|
public void run() {
|
||||||
activityH.handleLogin(player.isBanned(), data);
|
boolean isNewPlayer = activityH.isFirstTimeJoin(uuid);
|
||||||
InetAddress ip = player.getAddress().getAddress();
|
if (isNewPlayer) {
|
||||||
basicInfoH.handleLogin(player.getDisplayName(), ip, data);
|
handler.newPlayer(player);
|
||||||
gmTimesH.handleLogin(player.getGameMode(), data);
|
}
|
||||||
demographicH.handleLogin(ip, data);
|
DBCallableProcessor loginProcessor = new DBCallableProcessor() {
|
||||||
handler.saveCachedData(uuid);
|
@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();
|
||||||
}
|
}
|
||||||
};
|
}).runTaskAsynchronously(plugin);
|
||||||
handler.getUserDataForProcessing(loginProcessor, uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +8,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -188,9 +189,12 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
boolean usingMySQL = supportsModification;
|
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 = true;
|
||||||
boolean newDatabase = set.next();
|
try {
|
||||||
set.close();
|
getVersion();
|
||||||
|
newDatabase = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
|
query("CREATE TABLE IF NOT EXISTS " + userName + " ("
|
||||||
+ userColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
|
+ userColumnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
|
||||||
+ userColumnUUID + " varchar(36) NOT NULL UNIQUE, "
|
+ userColumnUUID + " varchar(36) NOT NULL UNIQUE, "
|
||||||
@ -272,38 +276,29 @@ public abstract class SQLDB extends Database {
|
|||||||
+ ")"
|
+ ")"
|
||||||
);
|
);
|
||||||
if (newDatabase) {
|
if (newDatabase) {
|
||||||
setVersion(2);
|
plugin.log("New Database created.");
|
||||||
|
setVersion(3);
|
||||||
}
|
}
|
||||||
int version = getVersion();
|
int version = getVersion();
|
||||||
if (version < 1) {
|
if (version < 3) {
|
||||||
|
String sqlite = usingMySQL ? "" : "COLUMN ";
|
||||||
String[] queries = new String[]{
|
String[] queries = new String[]{
|
||||||
"ALTER TABLE " + userName + " ADD " + userColumnDeaths + " integer NOT NULL DEFAULT 0",
|
"ALTER TABLE " + userName + " ADD " + sqlite + userColumnDeaths + " integer NOT NULL DEFAULT 0",
|
||||||
"ALTER TABLE " + userName + " ADD " + userColumnMobKills + " integer NOT NULL DEFAULT 0",
|
"ALTER TABLE " + userName + " ADD " + sqlite + userColumnMobKills + " integer NOT NULL DEFAULT 0",
|
||||||
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT (false)",
|
"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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setVersion(1);
|
|
||||||
} else if (version < 2) {
|
|
||||||
String[] queries = new String[]{
|
|
||||||
"ALTER TABLE " + nicknamesName + " ADD " + nicknamesColumnCurrent + " boolean NOT NULL DEFAULT 0",
|
|
||||||
"DROP TABLE IF EXISTS " + serverdataName
|
"DROP TABLE IF EXISTS " + serverdataName
|
||||||
};
|
};
|
||||||
for (String query : queries) {
|
for (String query : queries) {
|
||||||
try {
|
try {
|
||||||
query(query);
|
query(query);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usingMySQL) {
|
if (usingMySQL) {
|
||||||
query("ALTER TABLE " + userName + " DROP INDEX " + userColumnPlayerKills);
|
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
|
// Check if user is in the database
|
||||||
if (!wasSeenBefore(uuid)) {
|
if (!wasSeenBefore(uuid)) {
|
||||||
plugin.logError(uuid + " was not found from the database!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<World> worldList = Bukkit.getServer().getWorlds();
|
List<World> worldList = Bukkit.getServer().getWorlds();
|
||||||
@ -705,7 +699,7 @@ public abstract class SQLDB extends Database {
|
|||||||
for (UserData uData : data) {
|
for (UserData uData : data) {
|
||||||
try {
|
try {
|
||||||
if (uData == null) {
|
if (uData == null) {
|
||||||
throw new IllegalStateException("UserData is null somehow!");
|
continue;
|
||||||
}
|
}
|
||||||
uData.access();
|
uData.access();
|
||||||
int userId = getUserId(uData.getUuid().toString());
|
int userId = getUserId(uData.getUuid().toString());
|
||||||
@ -751,7 +745,7 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
for (UserData uData : data) {
|
for (UserData uData : data) {
|
||||||
if (uData == null) {
|
if (uData == null) {
|
||||||
throw new IllegalStateException("UserData is null somehow!");
|
continue;
|
||||||
}
|
}
|
||||||
uData.access();
|
uData.access();
|
||||||
try {
|
try {
|
||||||
@ -867,7 +861,9 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveAdditionalLocationsList(int userId, List<Location> locations) throws SQLException {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
PreparedStatement saveStatement = connection.prepareStatement("INSERT INTO " + locationName + " ("
|
PreparedStatement saveStatement = connection.prepareStatement("INSERT INTO " + locationName + " ("
|
||||||
@ -877,8 +873,8 @@ public abstract class SQLDB extends Database {
|
|||||||
+ locationColumnWorld
|
+ locationColumnWorld
|
||||||
+ ") VALUES (?, ?, ?, ?)");
|
+ ") VALUES (?, ?, ?, ?)");
|
||||||
boolean commitRequired = false;
|
boolean commitRequired = false;
|
||||||
if (!locations.isEmpty()) {
|
if (!newLocations.isEmpty()) {
|
||||||
for (Location location : locations) {
|
for (Location location : newLocations) {
|
||||||
saveStatement.setInt(1, userId);
|
saveStatement.setInt(1, userId);
|
||||||
saveStatement.setInt(2, (int) location.getBlockX());
|
saveStatement.setInt(2, (int) location.getBlockX());
|
||||||
saveStatement.setInt(3, (int) location.getBlockZ());
|
saveStatement.setInt(3, (int) location.getBlockZ());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: Plan
|
name: Plan
|
||||||
author: Rsl1122
|
author: Rsl1122
|
||||||
main: main.java.com.djrapitops.plan.Plan
|
main: main.java.com.djrapitops.plan.Plan
|
||||||
version: 2.6.0
|
version: 2.6.1
|
||||||
|
|
||||||
softdepend:
|
softdepend:
|
||||||
- OnTime
|
- OnTime
|
||||||
|
Loading…
Reference in New Issue
Block a user