1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 23:13:48 +01:00

Fix AbstractMethodError when some software does not supports new databases

- Improved the database shutdown process
- Slightly optimized the database calls when a player quits

Closes #1061
This commit is contained in:
montlikadani 2021-01-19 08:35:38 +01:00
parent fb91fb7104
commit 2ad3e54e4d
5 changed files with 53 additions and 51 deletions

View File

@ -493,24 +493,6 @@ public class Jobs extends JavaPlugin {
}); });
} }
/**
* Executes clean shutdown
*/
public static void shutdown() {
if (saveTask != null)
saveTask.shutdown();
if (paymentThread != null)
paymentThread.shutdown();
getPlayerManager().removePlayerAdditions();
getPlayerManager().saveAll();
if (dao != null) {
dao.closeConnections();
}
}
/** /**
* Executes close connections * Executes close connections
*/ */
@ -733,8 +715,11 @@ public class Jobs extends JavaPlugin {
// unregister all registered listeners by this plugin and register again // unregister all registered listeners by this plugin and register again
if (!startup) { if (!startup) {
org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager(); org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager();
HandlerList.unregisterAll(instance); HandlerList.unregisterAll(instance);
com.gamingmesh.jobs.CMIGUI.GUIManager.registerListener(); com.gamingmesh.jobs.CMIGUI.GUIManager.registerListener();
pm.registerEvents(new JobsListener(instance), instance); pm.registerEvents(new JobsListener(instance), instance);
pm.registerEvents(new JobsPaymentListener(instance), instance); pm.registerEvents(new JobsPaymentListener(instance), instance);
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
@ -754,12 +739,10 @@ public class Jobs extends JavaPlugin {
if (saveTask != null) { if (saveTask != null) {
saveTask.shutdown(); saveTask.shutdown();
saveTask = null;
} }
if (paymentThread != null) { if (paymentThread != null) {
paymentThread.shutdown(); paymentThread.shutdown();
paymentThread = null;
} }
smanager = new SelectionManager(); smanager = new SelectionManager();
@ -817,25 +800,40 @@ public class Jobs extends JavaPlugin {
HandlerList.unregisterAll(instance); HandlerList.unregisterAll(instance);
dao.saveExplore(); if (dao != null) {
getBpManager().saveCache(); dao.saveExplore();
}
if (bpManager != null) {
bpManager.saveCache();
}
blockOwnerShips.forEach(BlockOwnerShip::save); blockOwnerShips.forEach(BlockOwnerShip::save);
ToggleBarHandling.save(); ToggleBarHandling.save();
shutdown(); if (saveTask != null)
saveTask.shutdown();
if (paymentThread != null)
paymentThread.shutdown();
if (pManager != null) {
pManager.removePlayerAdditions();
pManager.saveAll();
}
if (dao != null) {
dao.closeConnections();
}
instance = null; instance = null;
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully."); consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
setEnabled(false);
} }
private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) { private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) {
if (!job.getQuests().isEmpty()) { if (!job.getQuests().isEmpty()) {
List<QuestProgression> q = jPlayer.getQuestProgressions(job, info.getType()); for (QuestProgression one : jPlayer.getQuestProgressions(job, info.getType())) {
for (QuestProgression one : q) { one.processQuest(jPlayer, info);
if (one != null) {
one.processQuest(jPlayer, info);
}
} }
} }
} }
@ -1274,7 +1272,6 @@ public class Jobs extends JavaPlugin {
} }
public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) { public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) {
// JobsPayment event
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.get(CurrencyType.EXP)); JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.get(CurrencyType.EXP));
Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent);
// If event is canceled, don't do anything // If event is canceled, don't do anything

View File

@ -152,7 +152,6 @@ public class PermissionManager {
amount = temp; amount = temp;
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
ignored.printStackTrace(); ignored.printStackTrace();
// Should be ignored
} }
} }

View File

@ -8,6 +8,7 @@ import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -325,6 +326,8 @@ public class Placeholder {
return message; return message;
} }
private final AtomicInteger jobLevel = new AtomicInteger();
private String translateOwnPlaceHolder(Player player, String message) { private String translateOwnPlaceHolder(Player player, String message) {
if (message == null) if (message == null)
return null; return null;
@ -509,16 +512,14 @@ public class Placeholder {
if (vals.size() < 2 || job == null) if (vals.size() < 2 || job == null)
return ""; return "";
int amount = 0;
try { try {
amount = Integer.parseInt(vals.get(1)); jobLevel.set(Integer.parseInt(vals.get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return ""; return "";
} }
final int top = amount;
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
for (TopList l : Jobs.getJobsDAO().getGlobalTopList(top)) { for (TopList l : Jobs.getJobsDAO().getGlobalTopList(jobLevel.get())) {
if (l.getPlayerInfo().getName().equals(user.getName())) { if (l.getPlayerInfo().getName().equals(user.getName())) {
JobProgression prog = l.getPlayerInfo().getJobsPlayer().getJobProgression(job); JobProgression prog = l.getPlayerInfo().getJobsPlayer().getJobProgression(job);
return prog == null ? "" : Integer.toString(prog.getLevel()); return prog == null ? "" : Integer.toString(prog.getLevel());

View File

@ -27,7 +27,12 @@ public class JobsConnection {
} }
public synchronized boolean isValid(int timeout) throws SQLException { public synchronized boolean isValid(int timeout) throws SQLException {
return conn.isValid(timeout); try {
return conn.isValid(timeout);
} catch (AbstractMethodError e) {
}
return true;
} }
public synchronized void closeConnection() throws SQLException { public synchronized void closeConnection() throws SQLException {

View File

@ -26,7 +26,6 @@ import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -109,7 +108,7 @@ public class JobsListener implements Listener {
if (msg == null) if (msg == null)
return; return;
Bukkit.getServer().getScheduler().runTask(plugin, () -> player.performCommand(msg + event.getMessage())); plugin.getServer().getScheduler().runTask(plugin, () -> player.performCommand(msg + event.getMessage()));
event.setCancelled(true); event.setCancelled(true);
} }
@ -158,7 +157,7 @@ public class JobsListener implements Listener {
if (Jobs.getSelectionManager().hasPlacedBoth(player)) { if (Jobs.getSelectionManager().hasPlacedBoth(player)) {
JobsAreaSelectionEvent jobsAreaSelectionEvent = new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player)); JobsAreaSelectionEvent jobsAreaSelectionEvent = new JobsAreaSelectionEvent(player, Jobs.getSelectionManager().getSelectionCuboid(player));
Bukkit.getServer().getPluginManager().callEvent(jobsAreaSelectionEvent); plugin.getServer().getPluginManager().callEvent(jobsAreaSelectionEvent);
} }
} }
@ -167,7 +166,7 @@ public class JobsListener implements Listener {
if (!Jobs.getGCManager().MultiServerCompatability()) if (!Jobs.getGCManager().MultiServerCompatability())
Jobs.getPlayerManager().playerJoin(event.getPlayer()); Jobs.getPlayerManager().playerJoin(event.getPlayer());
else { else {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> plugin.getServer().getScheduler().runTaskLater(plugin, () ->
Jobs.getPlayerManager().playerJoin(event.getPlayer()), 10L); Jobs.getPlayerManager().playerJoin(event.getPlayer()), 10L);
} }
} }
@ -190,14 +189,15 @@ public class JobsListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Jobs.getPlayerManager().playerQuit(event.getPlayer()); java.util.concurrent.CompletableFuture.supplyAsync(() -> {
Jobs.getPlayerManager().playerQuit(event.getPlayer());
return true;
});
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerWorldChange(PlayerChangedWorldEvent event) { public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
if (plugin.isEnabled()) { Jobs.getPermissionHandler().recalculatePermissions(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()));
Jobs.getPermissionHandler().recalculatePermissions(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()));
}
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -326,7 +326,7 @@ public class JobsListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> signUtil.SignUpdate(job, type), 1L); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> signUtil.SignUpdate(job, type), 1L);
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@ -436,7 +436,7 @@ public class JobsListener implements Listener {
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
return; return;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.getBpManager().remove(event.getBlock()), 1L); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> Jobs.getBpManager().remove(event.getBlock()), 1L);
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
@ -525,7 +525,7 @@ public class JobsListener implements Listener {
return; return;
JobsChunkChangeEvent jobsChunkChangeEvent = new JobsChunkChangeEvent(event.getPlayer(), from, to); JobsChunkChangeEvent jobsChunkChangeEvent = new JobsChunkChangeEvent(event.getPlayer(), from, to);
Bukkit.getServer().getPluginManager().callEvent(jobsChunkChangeEvent); plugin.getServer().getPluginManager().callEvent(jobsChunkChangeEvent);
} }
@EventHandler @EventHandler
@ -579,7 +579,7 @@ public class JobsListener implements Listener {
(equipping ? inv.getBoots() == null : inv.getBoots() != null)) { (equipping ? inv.getBoots() == null : inv.getBoots() != null)) {
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event
.getCurrentItem(), equipping ? event.getCurrentItem() : null); .getCurrentItem(), equipping ? event.getCurrentItem() : null);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) { if (armorEquipEvent.isCancelled()) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -606,7 +606,7 @@ public class JobsListener implements Listener {
if (event.getAction() == InventoryAction.HOTBAR_SWAP || numberkey) if (event.getAction() == InventoryAction.HOTBAR_SWAP || numberkey)
method = EquipMethod.HOTBAR_SWAP; method = EquipMethod.HOTBAR_SWAP;
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece); JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) if (armorEquipEvent.isCancelled())
event.setCancelled(true); event.setCancelled(true);
} }
@ -638,7 +638,7 @@ public class JobsListener implements Listener {
inv.getBoots() == null) { inv.getBoots() == null) {
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event
.getItem()); .getItem());
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) { if (armorEquipEvent.isCancelled()) {
event.setCancelled(true); event.setCancelled(true);
player.updateInventory(); player.updateInventory();
@ -696,7 +696,7 @@ public class JobsListener implements Listener {
ploc.getZ() <= loc.getZ()) { ploc.getZ() <= loc.getZ()) {
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item); JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item);
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
if (armorEquipEvent.isCancelled()) { if (armorEquipEvent.isCancelled()) {
event.setCancelled(true); event.setCancelled(true);
return; return;