mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-15 10:55:20 +01:00
Improve disabling of the plugin
This commit is contained in:
parent
5c75bea337
commit
b6a8d372f5
@ -114,11 +114,13 @@ public void open(@NotNull Player player, boolean editable)
|
||||
|
||||
// It's not perfect, but it is the only way of doing this.
|
||||
// This sets the title of the inventory based on the person who is opening it.
|
||||
// The owner will see an other title then everyone else.
|
||||
// The owner will see an other title, then everyone else.
|
||||
// This way we can add owner name to the tile for everyone else.
|
||||
try
|
||||
{
|
||||
//noinspection ConstantConditions
|
||||
FIELD_TITLE.setAccessible(true);
|
||||
//noinspection ConstantConditions
|
||||
FIELD_TITLE.set(METHOD_GET_INVENTORY.invoke(bp), player.equals(owner) ? Minepacks.getInstance().backpackTitle : titleOther);
|
||||
}
|
||||
catch(Exception e)
|
||||
@ -134,6 +136,13 @@ public void close(Player p)
|
||||
opened.remove(p);
|
||||
}
|
||||
|
||||
public void closeAll()
|
||||
{
|
||||
opened.forEach((key, value) -> key.closeInventory());
|
||||
opened.clear();
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
|
@ -69,6 +69,8 @@ public void init()
|
||||
public void close()
|
||||
{
|
||||
HandlerList.unregisterAll(this);
|
||||
backpacks.forEach((key, value) -> value.closeAll());
|
||||
backpacks.clear();
|
||||
unCacheStrategie.close();
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||
import at.pcgamingfreaks.UUIDConverter;
|
||||
import at.pcgamingfreaks.Utils;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@ -122,6 +123,7 @@ protected void loadSettings()
|
||||
public void close()
|
||||
{
|
||||
super.close();
|
||||
Utils.blockThread(1); // Give the database some time to perform async operations
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -72,6 +73,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin
|
||||
private int maxSize;
|
||||
private Collection<String> worldBlacklist;
|
||||
private WorldBlacklistMode worldBlacklistMode;
|
||||
private ItemsCollector collector;
|
||||
|
||||
public static Minepacks getInstance()
|
||||
{
|
||||
@ -160,7 +162,8 @@ private void load()
|
||||
//endregion
|
||||
if(config.getFullInvCollect())
|
||||
{
|
||||
(new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
|
||||
collector = new ItemsCollector(this);
|
||||
collector.runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
|
||||
}
|
||||
worldBlacklist = config.getWorldBlacklist();
|
||||
if(worldBlacklist.size() == 0)
|
||||
@ -175,7 +178,11 @@ private void load()
|
||||
|
||||
private void unload()
|
||||
{
|
||||
getServer().getScheduler().cancelTasks(this); // Stop the listener, we don't need them any longer
|
||||
//TODO disable command
|
||||
collector.cancel();
|
||||
if(database != null) database.close();
|
||||
HandlerList.unregisterAll(this); // Stop the listeners
|
||||
getServer().getScheduler().cancelTasks(this); // Kill all running task
|
||||
database.close(); // Close the DB connection, we won't need them any longer
|
||||
instance = null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user