mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +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:
parent
fb91fb7104
commit
2ad3e54e4d
@ -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
|
||||
*/
|
||||
@ -733,8 +715,11 @@ public class Jobs extends JavaPlugin {
|
||||
// unregister all registered listeners by this plugin and register again
|
||||
if (!startup) {
|
||||
org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager();
|
||||
|
||||
HandlerList.unregisterAll(instance);
|
||||
|
||||
com.gamingmesh.jobs.CMIGUI.GUIManager.registerListener();
|
||||
|
||||
pm.registerEvents(new JobsListener(instance), instance);
|
||||
pm.registerEvents(new JobsPaymentListener(instance), instance);
|
||||
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
|
||||
@ -754,12 +739,10 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
if (saveTask != null) {
|
||||
saveTask.shutdown();
|
||||
saveTask = null;
|
||||
}
|
||||
|
||||
if (paymentThread != null) {
|
||||
paymentThread.shutdown();
|
||||
paymentThread = null;
|
||||
}
|
||||
|
||||
smanager = new SelectionManager();
|
||||
@ -817,25 +800,40 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
HandlerList.unregisterAll(instance);
|
||||
|
||||
dao.saveExplore();
|
||||
getBpManager().saveCache();
|
||||
if (dao != null) {
|
||||
dao.saveExplore();
|
||||
}
|
||||
|
||||
if (bpManager != null) {
|
||||
bpManager.saveCache();
|
||||
}
|
||||
|
||||
blockOwnerShips.forEach(BlockOwnerShip::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;
|
||||
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
private static void checkDailyQuests(JobsPlayer jPlayer, Job job, ActionInfo info) {
|
||||
if (!job.getQuests().isEmpty()) {
|
||||
List<QuestProgression> q = jPlayer.getQuestProgressions(job, info.getType());
|
||||
for (QuestProgression one : q) {
|
||||
if (one != null) {
|
||||
one.processQuest(jPlayer, info);
|
||||
}
|
||||
for (QuestProgression one : jPlayer.getQuestProgressions(job, info.getType())) {
|
||||
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) {
|
||||
// JobsPayment event
|
||||
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.get(CurrencyType.EXP));
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent);
|
||||
// If event is canceled, don't do anything
|
||||
|
@ -152,7 +152,6 @@ public class PermissionManager {
|
||||
amount = temp;
|
||||
} catch (NumberFormatException ignored) {
|
||||
ignored.printStackTrace();
|
||||
// Should be ignored
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -325,6 +326,8 @@ public class Placeholder {
|
||||
return message;
|
||||
}
|
||||
|
||||
private final AtomicInteger jobLevel = new AtomicInteger();
|
||||
|
||||
private String translateOwnPlaceHolder(Player player, String message) {
|
||||
if (message == null)
|
||||
return null;
|
||||
@ -509,16 +512,14 @@ public class Placeholder {
|
||||
if (vals.size() < 2 || job == null)
|
||||
return "";
|
||||
|
||||
int amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(vals.get(1));
|
||||
jobLevel.set(Integer.parseInt(vals.get(1)));
|
||||
} catch (NumberFormatException e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
final int top = amount;
|
||||
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())) {
|
||||
JobProgression prog = l.getPlayerInfo().getJobsPlayer().getJobProgression(job);
|
||||
return prog == null ? "" : Integer.toString(prog.getLevel());
|
||||
|
@ -27,7 +27,12 @@ public class JobsConnection {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -26,7 +26,6 @@ import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -109,7 +108,7 @@ public class JobsListener implements Listener {
|
||||
if (msg == null)
|
||||
return;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(plugin, () -> player.performCommand(msg + event.getMessage()));
|
||||
plugin.getServer().getScheduler().runTask(plugin, () -> player.performCommand(msg + event.getMessage()));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -158,7 +157,7 @@ public class JobsListener implements Listener {
|
||||
|
||||
if (Jobs.getSelectionManager().hasPlacedBoth(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())
|
||||
Jobs.getPlayerManager().playerJoin(event.getPlayer());
|
||||
else {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, () ->
|
||||
Jobs.getPlayerManager().playerJoin(event.getPlayer()), 10L);
|
||||
}
|
||||
}
|
||||
@ -190,14 +189,15 @@ public class JobsListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
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)
|
||||
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)
|
||||
@ -326,7 +326,7 @@ public class JobsListener implements Listener {
|
||||
|
||||
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)
|
||||
@ -436,7 +436,7 @@ public class JobsListener implements Listener {
|
||||
if (!Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld()))
|
||||
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)
|
||||
@ -525,7 +525,7 @@ public class JobsListener implements Listener {
|
||||
return;
|
||||
|
||||
JobsChunkChangeEvent jobsChunkChangeEvent = new JobsChunkChangeEvent(event.getPlayer(), from, to);
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsChunkChangeEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(jobsChunkChangeEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -579,7 +579,7 @@ public class JobsListener implements Listener {
|
||||
(equipping ? inv.getBoots() == null : inv.getBoots() != null)) {
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.SHIFT_CLICK, newArmorType, equipping ? null : event
|
||||
.getCurrentItem(), equipping ? event.getCurrentItem() : null);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -606,7 +606,7 @@ public class JobsListener implements Listener {
|
||||
if (event.getAction() == InventoryAction.HOTBAR_SWAP || numberkey)
|
||||
method = EquipMethod.HOTBAR_SWAP;
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent((Player) event.getWhoClicked(), method, newArmorType, oldArmorPiece, newArmorPiece);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled())
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -638,7 +638,7 @@ public class JobsListener implements Listener {
|
||||
inv.getBoots() == null) {
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(player, EquipMethod.HOTBAR, ArmorTypes.matchType(event.getItem()), null, event
|
||||
.getItem());
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
player.updateInventory();
|
||||
@ -696,7 +696,7 @@ public class JobsListener implements Listener {
|
||||
ploc.getZ() <= loc.getZ()) {
|
||||
|
||||
JobsArmorChangeEvent armorEquipEvent = new JobsArmorChangeEvent(p, EquipMethod.DISPENSER, type, null, item);
|
||||
Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
plugin.getServer().getPluginManager().callEvent(armorEquipEvent);
|
||||
if (armorEquipEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user