Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
commands.add("stats");
}

if (plugin.getConfig().getBoolean("economy.enabled", false)
&& "gui".equalsIgnoreCase(plugin.getConfig().getString("economy.mode", "charge-to-keep"))) {
DKIConfig cfg = plugin.getDKIConfig();
if (cfg.economyEnabled && cfg.economyMode == EconomyMode.GUI) {
commands.add("confirm");
commands.add("autopay");
}
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/xyz/superez/dynamickeepinv/CommandDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public boolean dispatch(CommandSender sender, Command command, String label, Str
plugin.reloadConfig();
plugin.loadMessages();
plugin.reloadIntegrations();
plugin.reloadRuleManager();
plugin.reloadPendingDeathManager();
plugin.reloadStatsSystem();
if (plugin.getConfig().getBoolean("enabled", true)) {
Expand All @@ -73,13 +74,15 @@ public boolean dispatch(CommandSender sender, Command command, String label, Str
case "enable":
plugin.getConfig().set("enabled", true);
plugin.saveConfig();
plugin.refreshDKIConfig();
plugin.startChecking();
sender.sendMessage(plugin.parseMessage(plugin.getMessage("commands.enabled")));
break;

case "disable":
plugin.getConfig().set("enabled", false);
plugin.saveConfig();
plugin.refreshDKIConfig();
plugin.stopChecking(true);
sender.sendMessage(plugin.parseMessage(plugin.getMessage("commands.disabled")));
break;
Expand All @@ -88,6 +91,7 @@ public boolean dispatch(CommandSender sender, Command command, String label, Str
boolean newState = !plugin.getConfig().getBoolean("enabled", true);
plugin.getConfig().set("enabled", newState);
plugin.saveConfig();
plugin.refreshDKIConfig();
if (newState) {
plugin.startChecking();
sender.sendMessage(plugin.parseMessage(plugin.getMessage("commands.enabled")));
Expand Down Expand Up @@ -156,8 +160,8 @@ private boolean handleConfirmCommand(CommandSender sender) {
return true;
}

if (!plugin.getConfig().getBoolean("economy.enabled", false)
|| !"gui".equalsIgnoreCase(plugin.getConfig().getString("economy.mode", "charge-to-keep"))) {
DKIConfig cfg = plugin.getDKIConfig();
if (!cfg.economyEnabled || cfg.economyMode != EconomyMode.GUI) {
sender.sendMessage(plugin.parseMessage("&cDeath confirmation GUI is not enabled! Set economy mode to 'gui' in config."));
return true;
}
Expand All @@ -183,8 +187,8 @@ private boolean handleAutoPayCommand(CommandSender sender) {
return true;
}

if (!plugin.getConfig().getBoolean("economy.enabled", false)
|| !"gui".equalsIgnoreCase(plugin.getConfig().getString("economy.mode", "charge-to-keep"))) {
DKIConfig cfg = plugin.getDKIConfig();
if (!cfg.economyEnabled || cfg.economyMode != EconomyMode.GUI) {
sender.sendMessage(plugin.parseMessage("&cAuto-pay requires GUI economy mode! Set economy mode to 'gui' in config."));
return true;
}
Expand Down Expand Up @@ -289,15 +293,16 @@ private void handleTestCommand(CommandSender sender, String[] args) {
}

private void showStatus(CommandSender sender) {
DKIConfig cfg = plugin.getDKIConfig();
sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.header")));
sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.enabled")
.replace("{value}", String.valueOf(plugin.getConfig().getBoolean("enabled", true)))));
.replace("{value}", String.valueOf(cfg.enabled))));
sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.keep-inv-day")
.replace("{value}", String.valueOf(plugin.getConfig().getBoolean("rules.day.keep-items", true)))));
.replace("{value}", String.valueOf(cfg.dayKeepItems))));
sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.keep-inv-night")
.replace("{value}", String.valueOf(plugin.getConfig().getBoolean("rules.night.keep-items", false)))));
.replace("{value}", String.valueOf(cfg.nightKeepItems))));
sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.check-interval")
.replace("{value}", String.valueOf(plugin.getConfig().getInt("check-interval", 100)))));
.replace("{value}", String.valueOf(cfg.checkInterval))));

// Rule chain summary
sender.sendMessage(plugin.parseMessage("&7--- &eActive Rule Chain &7---"));
Expand All @@ -314,8 +319,8 @@ private void showStatus(CommandSender sender) {
}

sender.sendMessage(plugin.parseMessage(plugin.getMessage("status.world-header")));
long dayStart = plugin.getConfig().getLong("time.day-start", 0);
long nightStart = plugin.getConfig().getLong("time.night-start", 13000);
long dayStart = cfg.dayStart;
long nightStart = cfg.nightStart;
for (World world : Bukkit.getWorlds()) {
long time = world.getTime();
boolean isDay = plugin.isTimeInRange(time, dayStart, nightStart);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/xyz/superez/dynamickeepinv/DKIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class DKIConfig {
public final boolean worldGuardOwnRegionKeepXp;
public final boolean worldGuardOtherRegionKeepItems;
public final boolean worldGuardOtherRegionKeepXp;
public final boolean worldGuardWildernessEnabled;
public final boolean worldGuardWildernessKeepItems;
public final boolean worldGuardWildernessKeepXp;

// --- Integrations: Towny ---
public final boolean townyEnabled;
Expand Down Expand Up @@ -221,6 +224,9 @@ public DKIConfig(FileConfiguration cfg) {
worldGuardOwnRegionKeepXp = cfg.getBoolean("integrations.worldguard.in-own-region.keep-xp", true);
worldGuardOtherRegionKeepItems = cfg.getBoolean("integrations.worldguard.in-other-region.keep-items",false);
worldGuardOtherRegionKeepXp = cfg.getBoolean("integrations.worldguard.in-other-region.keep-xp", false);
worldGuardWildernessEnabled = cfg.getBoolean("integrations.worldguard.wilderness.enabled", false);
worldGuardWildernessKeepItems = cfg.getBoolean("integrations.worldguard.wilderness.keep-items", false);
worldGuardWildernessKeepXp = cfg.getBoolean("integrations.worldguard.wilderness.keep-xp", false);

// Towny
townyEnabled = cfg.getBoolean("integrations.towny.enabled", false);
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/xyz/superez/dynamickeepinv/DeathListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
plugin.debug("GUI mode: Saving inventory for confirmation GUI");

// Prepare inventory for saving, filtering out Soulbound items to keep them
ItemStack[] contents = player.getInventory().getContents();
ItemStack[] contents = player.getInventory().getStorageContents();
ItemStack[] armor = player.getInventory().getArmorContents();
ItemStack offHand = player.getInventory().getItemInOffHand();

Expand Down Expand Up @@ -177,7 +177,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
);

// Only save if there are items worth saving
if (pendingDeath.hasItems() || player.getLevel() > 0) {
if (pendingDeath.hasItems() || player.getTotalExperience() > 0) {
pendingManager.addPendingDeath(pendingDeath);

// IMPORTANT: Cancel drops and disable keepInventory
Expand Down Expand Up @@ -518,9 +518,10 @@ private void applyKeepInventorySettings(PlayerDeathEvent event, boolean keepItem

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(PlayerRespawnEvent event) {
DKIConfig cfg = plugin.getDKIConfig();
// Check if GUI mode is enabled
if (!plugin.getConfig().getBoolean("economy.enabled", false)) return;
if (!"gui".equalsIgnoreCase(plugin.getConfig().getString("economy.mode", "charge-to-keep"))) return;
if (!cfg.economyEnabled) return;
if (cfg.economyMode != EconomyMode.GUI) return;

Player player = event.getPlayer();
PendingDeathManager pendingManager = plugin.getPendingDeathManager();
Expand Down Expand Up @@ -551,15 +552,16 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
PendingDeathManager pendingManager = plugin.getPendingDeathManager();
DKIConfig cfg = plugin.getDKIConfig();

// Preload auto-pay settings if manager exists
if (pendingManager != null) {
pendingManager.preloadAutoPay(player.getUniqueId());
}

// Check if GUI mode is enabled
if (!plugin.getConfig().getBoolean("economy.enabled", false)) return;
if (!"gui".equalsIgnoreCase(plugin.getConfig().getString("economy.mode", "charge-to-keep"))) return;
if (!cfg.economyEnabled) return;
if (cfg.economyMode != EconomyMode.GUI) return;

if (pendingManager == null) return;

Expand Down
25 changes: 14 additions & 11 deletions src/main/java/xyz/superez/dynamickeepinv/DynamicKeepInvPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public void onEnable() {
getCommand("dynamickeepinv").setTabCompleter(new CommandCompleter(this));

// Initialize GUI economy mode components
if (getConfig().getBoolean("economy.enabled", false)
&& "gui".equalsIgnoreCase(getConfig().getString("economy.mode", "charge-to-keep"))) {
if (dkiConfig.economyEnabled && dkiConfig.economyMode == EconomyMode.GUI) {
pendingDeathManager = new PendingDeathManager(this);
deathConfirmGUI = new DeathConfirmGUI(this);
getLogger().info("Death confirmation GUI mode enabled!");
Expand All @@ -104,9 +103,9 @@ public void onEnable() {

getLogger().info("DynamicKeepInv is starting... (Platform: " + (isFolia ? "Folia" : "Paper/Spigot") + ")");

if (getConfig().getBoolean("enabled", true)) {
if (dkiConfig.enabled) {
startChecking();
List<String> enabledWorlds = getConfig().getStringList("worlds.enabled");
List<String> enabledWorlds = dkiConfig.enabledWorlds;
if (!enabledWorlds.isEmpty()) {
getLogger().info("Enabled worlds: " + String.join(", ", enabledWorlds));
} else {
Expand Down Expand Up @@ -146,7 +145,7 @@ public void handleWorldUnload(World world) {
}

public EconomyManager getEconomyManager() {
if (!getConfig().getBoolean("economy.enabled", false)) {
if (!dkiConfig.economyEnabled) {
return economyManager;
}

Expand Down Expand Up @@ -261,7 +260,7 @@ public Component parseMessage(String message) {
void startChecking() {
stopChecking(false);

int interval = getConfig().getInt("check-interval", 100);
int interval = dkiConfig.checkInterval;

if (isFolia) {
GlobalRegionScheduler scheduler = Bukkit.getGlobalRegionScheduler();
Expand Down Expand Up @@ -501,7 +500,7 @@ private void cleanupStatsSystem() {
void reloadStatsSystem() {
cleanupStatsSystem();

if (getConfig().getBoolean("stats.enabled", true)) {
if (dkiConfig.statsEnabled) {
statsManager = new StatsManager(this);
statsGUI = new StatsGUI(this);
statsListener = new StatsListener(this);
Expand All @@ -523,8 +522,7 @@ void reloadPendingDeathManager() {
}

// Initialize if GUI mode enabled
if (getConfig().getBoolean("economy.enabled", false)
&& "gui".equalsIgnoreCase(getConfig().getString("economy.mode", "charge-to-keep"))) {
if (dkiConfig.economyEnabled && dkiConfig.economyMode == EconomyMode.GUI) {
pendingDeathManager = new PendingDeathManager(this);
deathConfirmGUI = new DeathConfirmGUI(this);
getLogger().info("Death confirmation GUI mode enabled!");
Expand All @@ -547,7 +545,8 @@ public boolean isTimeInRange(long time, long rangeStart, long rangeEnd) {
}

public boolean isDayTime(long time) {
return isTimeInRange(time, getConfig().getLong("time.day-start", 0), getConfig().getLong("time.night-start", 13000));
DKIConfig cfg = dkiConfig;
return isTimeInRange(time, cfg.dayStart, cfg.nightStart);
}

private boolean getWorldKeepInventory(World world, boolean isDay, boolean globalKeepInvDay, boolean globalKeepInvNight) {
Expand All @@ -566,7 +565,7 @@ private boolean getWorldKeepInventory(World world, boolean isDay, boolean global
}

public void debug(String message) {
if (getConfig().getBoolean("debug", false)) {
if (dkiConfig.debug) {
getLogger().log(Level.INFO, "[DEBUG] " + message);
}
}
Expand All @@ -585,6 +584,10 @@ private void setupRuleManager() {
ruleManager.registerRule(new WorldTimeRule());
}

void reloadRuleManager() {
setupRuleManager();
}

public RuleManager getRuleManager() {
return ruleManager;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/xyz/superez/dynamickeepinv/IntegrationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,33 @@ public IntegrationManager(DynamicKeepInvPlugin plugin) {
}

public void reload() {
if (plugin.getConfig().getBoolean("integrations.lands.enabled", false)) {
DKIConfig cfg = plugin.getDKIConfig();

if (cfg.landsEnabled) {
landsHook = new LandsHook(plugin);
} else {
landsHook = null;
}

if (plugin.getConfig().getBoolean("integrations.griefprevention.enabled", false)) {
if (cfg.gpEnabled) {
griefPreventionHook = new GriefPreventionHook(plugin);
} else {
griefPreventionHook = null;
}

if (plugin.getConfig().getBoolean("integrations.worldguard.enabled", false)) {
if (cfg.worldGuardEnabled) {
worldGuardHook = new WorldGuardHook(plugin);
} else {
worldGuardHook = null;
}

if (plugin.getConfig().getBoolean("integrations.towny.enabled", false)) {
if (cfg.townyEnabled) {
townyHook = new TownyHook(plugin);
} else {
townyHook = null;
}

if (plugin.getConfig().getBoolean("integrations.gravesx.enabled", false)) {
if (cfg.gravesXEnabled) {
if (Bukkit.getPluginManager().getPlugin("GravesX") != null) {
gravesXHook = new GravesXHook(plugin);
if (!gravesXHook.setup()) {
Expand All @@ -64,7 +66,7 @@ public void reload() {
gravesXHook = null;
}

if (plugin.getConfig().getBoolean("integrations.axgraves.enabled", false)) {
if (cfg.axGravesEnabled) {
if (Bukkit.getPluginManager().getPlugin("AxGraves") != null) {
axGravesHook = new AxGravesHook(plugin);
if (!axGravesHook.setup()) {
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/xyz/superez/dynamickeepinv/PendingDeath.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,37 @@ public long getAgeMs() {
* Check if inventory has any items worth saving
*/
public boolean hasItems() {
// savedInventory comes from PlayerInventory.getContents() which includes armor and offhand
for (ItemStack item : savedInventory) {
if (item != null && !item.getType().isAir()) {
return true;
}
}
return false;
for (ItemStack item : savedArmor) {
if (item != null && !item.getType().isAir()) {
return true;
}
}
return offhandItem != null && !offhandItem.getType().isAir();
}

/**
* Count total items in inventory
*/
public int countItems() {
// savedInventory comes from PlayerInventory.getContents() which includes armor and offhand
int count = 0;
for (ItemStack item : savedInventory) {
if (item != null && !item.getType().isAir()) {
count++;
}
}
for (ItemStack item : savedArmor) {
if (item != null && !item.getType().isAir()) {
count++;
}
}
if (offhandItem != null && !offhandItem.getType().isAir()) {
count++;
}
return count;
}
}
Loading