Skip to content

Commit

Permalink
Add debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
StarchierOrb committed Jul 23, 2021
1 parent 749cee8 commit 65724cc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import me.starchier.inventorykeeper.hooks.PlaceholderAPIHook;
import me.starchier.inventorykeeper.i18n.MessagesUtil;
import me.starchier.inventorykeeper.util.DataManager;
import me.starchier.inventorykeeper.util.Debugger;
import me.starchier.inventorykeeper.util.ItemHandler;
import me.starchier.inventorykeeper.util.PluginHandler;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -49,6 +50,7 @@ public void onEnable() {
ph.initConfigCache();
ItemHandler ih = new ItemHandler(this, ph);
ph.loadItems(ih);
Debugger.enabledDebug = ph.getBooleanConfigValue("debug", true);
/*
TODO: Need to be re-code.
if(!ih.isItem()) {
Expand All @@ -69,7 +71,7 @@ public void onEnable() {
CommandExec commandExec = new CommandExec(ph, this);
Bukkit.getPluginManager().registerEvents(new DeathHandler(this, dataManager, commandExec, ph), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
Bukkit.getPluginManager().registerEvents(new RespawnHandler(this, dataManager, commandExec, ph), this);
Bukkit.getPluginManager().registerEvents(new RespawnHandler(commandExec), this);
Bukkit.getPluginManager().registerEvents(new PlayerDataInit(dataManager), this);
//Bukkit.getPluginManager().registerEvents(new InventoryClickHandler(this),this);
Bukkit.getPluginManager().registerEvents(new BlockPlaceListener(ih, ph), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import me.starchier.inventorykeeper.items.ItemBase;
import me.starchier.inventorykeeper.storage.PlayerStorage;
import me.starchier.inventorykeeper.util.DataManager;
import me.starchier.inventorykeeper.util.Debugger;
import me.starchier.inventorykeeper.util.ExpHandler;
import me.starchier.inventorykeeper.util.PluginHandler;
import org.bukkit.ChatColor;
import org.bukkit.GameRule;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -158,6 +160,8 @@ public void onPlayerDeath(PlayerDeathEvent evt) {
}
}

Debugger.logDebugMessage(evt.getEntity().getName() + " died, consumeType: " + consumeType);

if (consumeType == CONSUME_NONE) {
PlayerStorage.removeKiller(evt.getEntity());
PlayerStorage.clearPlayer(evt.getEntity());
Expand Down Expand Up @@ -197,6 +201,7 @@ public void onPlayerDeath(PlayerDeathEvent evt) {
PlayerStorage.clearPlayer(evt.getEntity());
if (isConsumedFinally) {
PlayerStorage.setConsumed(evt.getEntity(), consumeItemNames[consumeType]);
Debugger.logDebugMessage(evt.getEntity().getName() + " died, consumed item: " + consumeItemNames[consumeType]);
commandExec.doKeepModInventory(evt.getEntity());
commandExec.runCommands(evt.getEntity(), true, consumeItemNames[consumeType] + ".run-commands-on-death", false);
commandExec.runRandomCommands(evt.getEntity(), true, consumeItemNames[consumeType] + ".run-random-commands-on-death", false);
Expand All @@ -215,6 +220,7 @@ public void onPlayerDeath(PlayerDeathEvent evt) {
targetItem.setAmount(amount);
}
evt.getEntity().getInventory().setItem(physicalSlot, targetItem);
Debugger.logDebugMessage(evt.getEntity().getName() + " died, target slot:" + physicalSlot);
} else if (consumeType == CONSUME_VIRTUAL) {
dataManager.setConsumed(evt.getEntity(), consumeItemNames[consumeType]);
}
Expand Down Expand Up @@ -267,6 +273,16 @@ public void onPlayerDeath(PlayerDeathEvent evt) {
int lost = expHandler.loseExp(evt, consumeItemNames[consumeType]);
evt.getEntity().sendMessage(String.format(pluginHandler.getMessage("lost-exp"), lost, (evt.getEntity().getLevel() - lost)));
}
Debugger.logDebugMessage(evt.getEntity().getName() + " death status:");
Debugger.logDebugMessage("keep level: " + evt.getKeepLevel());
Debugger.logDebugMessage("keep inventory: " + evt.getKeepInventory());
}
}

@EventHandler(priority = EventPriority.MONITOR)
public void playerDeathDebugger(PlayerDeathEvent evt) {
Debugger.logDebugMessage(evt.getEntity().getName() + " : final death status:");
Debugger.logDebugMessage("keep level: " + evt.getKeepLevel());
Debugger.logDebugMessage("keep inventory: " + evt.getKeepInventory());
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
package me.starchier.inventorykeeper.events;

import me.starchier.inventorykeeper.InventoryKeeper;
import me.starchier.inventorykeeper.command.CommandExec;
import me.starchier.inventorykeeper.storage.PlayerStorage;
import me.starchier.inventorykeeper.util.DataManager;
import me.starchier.inventorykeeper.util.PluginHandler;
import me.starchier.inventorykeeper.util.Debugger;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class RespawnHandler implements Listener {
private final InventoryKeeper plugin;
private final DataManager dataManager;
private final CommandExec commandExec;
private final PluginHandler pluginHandler;

public RespawnHandler(InventoryKeeper plugin, DataManager dataManager, CommandExec commandExec, PluginHandler pluginHandler) {
this.plugin = plugin;
this.dataManager = dataManager;
public RespawnHandler(CommandExec commandExec) {
this.commandExec = commandExec;
this.pluginHandler = pluginHandler;
}

@EventHandler
Expand All @@ -30,16 +20,20 @@ public void onPlayerRespawn(PlayerRespawnEvent evt) {
try {
consumedItem = PlayerStorage.getConsumed(evt.getPlayer());
} catch (NullPointerException e) {
Debugger.logDebugMessage(evt.getPlayer().getName() + " Respawn: no death cause");
return;
}
if (consumedItem == null) {
commandExec.runCommands(evt.getPlayer(), false, "settings.run-commands-on-respawn-if-drops", true);
commandExec.runRandomCommands(evt.getPlayer(), false, "settings.run-random-commands-on-respawn-if-drops", true);
Debugger.logDebugMessage(evt.getPlayer().getName() + " Respawn: drop inventory");
PlayerStorage.resetConsumed(evt.getPlayer());
return;
}
commandExec.doRestoreModInventory(evt.getPlayer());
commandExec.runCommands(evt.getPlayer(), false, consumedItem + ".run-commands-on-respawn", false);
commandExec.runRandomCommands(evt.getPlayer(), false, consumedItem + ".run-random-commands-on-respawn", false);
Debugger.logDebugMessage(evt.getPlayer().getName() + " Respawn: consumed " + consumedItem);
PlayerStorage.resetConsumed(evt.getPlayer());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.starchier.inventorykeeper.util;

import me.starchier.inventorykeeper.InventoryKeeper;
import me.starchier.inventorykeeper.items.ItemBase;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/me/starchier/inventorykeeper/util/Debugger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.starchier.inventorykeeper.util;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

public class Debugger {
public static boolean enabledDebug = false;

public static void logDebugMessage(String message) {
if (!enabledDebug) {
return;
}
Bukkit.getLogger().info(ChatColor.AQUA + " [DEBUG] " + message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.regex.Pattern;

public class PluginHandler {
InventoryKeeper plugin;
private final InventoryKeeper plugin;
public static final String SERVER_VERSION = getVersion();
public static final int FIXED_SERVER_VERSION = Integer.parseInt(getVersion().replace(".", "").replace("_", "").replace("v", "").replace("R", ""));
public static final boolean IS_LEGACY = isLegacy();
Expand Down

0 comments on commit 65724cc

Please sign in to comment.