Search in sources :

Example 16 with GameObject

use of mc.dragons.core.gameobject.GameObject in project DragonsOnline by UniverseCraft.

the class DebugCommands method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.DEVELOPMENT))
        return true;
    User user = user(sender);
    if (label.equalsIgnoreCase("streamconsole")) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.RED + "Specify a log level! /streamconsole <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + ">");
            return true;
        }
        Level level = LogLevel.parseLevel(sender, args[0]);
        if (level == null)
            return true;
        user.setStreamConsoleLevel(level);
        if (level == LogLevel.OFF) {
            sender.sendMessage(ChatColor.GREEN + "Disabled console streaming");
        } else {
            sender.sendMessage(ChatColor.GREEN + "Streaming console messages at or above level " + level);
        }
    } else if (args.length == 0) {
        sender.sendMessage(ChatColor.YELLOW + "/debug level <LogLevel>");
        sender.sendMessage(ChatColor.YELLOW + "/debug dump gameobjects");
        sender.sendMessage(ChatColor.YELLOW + "/debug dump entities");
        sender.sendMessage(ChatColor.YELLOW + "/debug dump threads");
        sender.sendMessage(ChatColor.YELLOW + "/debug dump workers [Plugin]");
        sender.sendMessage(ChatColor.YELLOW + "/debug dump pendingtasks [Plugin]");
        // sender.sendMessage(ChatColor.YELLOW + "/debug errors [-stop]");
        sender.sendMessage(ChatColor.YELLOW + "/debug <attach|detach> <Player>");
    } else if (args[0].equalsIgnoreCase("level")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Specify a log level! /debug level <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + ">");
            return true;
        }
        Level level = LogLevel.parseLevel(sender, args[1]);
        if (level == null)
            return true;
        Dragons.getInstance().getServerOptions().setLogLevel(level);
        sender.sendMessage(ChatColor.GREEN + "Set log level to " + level);
    } else if (args[0].equalsIgnoreCase("dump")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Specify a dump option! /debug dump <gameobjects|entities>");
            return true;
        }
        if (args[1].equalsIgnoreCase("gameobjects")) {
            Logger logger = Dragons.getInstance().getLogger();
            logger.info("=== BEGIN COMPLETE GAME OBJECT DUMP ===");
            logger.info("GameObjectMemoryAddress\tGameObjectType\tGameObjectUUID");
            logger.info("-----------------------\t--------------\t--------------");
            for (GameObject gameObject : Dragons.getInstance().getGameObjectRegistry().getRegisteredObjects()) {
                logger.info(gameObject + "\t" + gameObject.getType() + "\t" + gameObject.getUUID());
            }
            logger.info("=== END COMPLETE GAME OBJECT DUMP ===");
            sender.sendMessage(ChatColor.GREEN + "Dumped all game objects to console.");
        } else if (args[1].equalsIgnoreCase("entities")) {
            Logger logger = dragons.getLogger();
            logger.info("=== BEGIN COMPLETE ENTITY DUMP ===");
            logger.info("EntityType\tEntityID\tValid\tGameObjectType\tGameObjectUUID");
            logger.info("----------\t--------\t-----\t--------------\t--------------");
            for (World world : Bukkit.getWorlds()) {
                logger.info("World: " + world.getName());
                for (Entity entity : world.getEntities()) {
                    GameObject gameObject = null;
                    if (entity instanceof Player) {
                        gameObject = UserLoader.fromPlayer((Player) entity);
                    } else if (entity instanceof Item) {
                        gameObject = ItemLoader.fromBukkit(((Item) entity).getItemStack());
                    } else {
                        gameObject = NPCLoader.fromBukkit(entity);
                    }
                    logger.info(entity.getType() + "\t" + entity.getEntityId() + "\t" + entity.isValid() + "\t" + (gameObject == null ? "null\tnull" : gameObject.getType() + "\t" + gameObject.getUUID()));
                }
            }
            logger.info("=== END COMPLETE ENTITY DUMP ===");
            sender.sendMessage(ChatColor.GREEN + "Dumped all entities to console.");
        } else if (args[1].equalsIgnoreCase("threads")) {
            ThreadMXBean threadBean = ManagementFactory.getPlatformMXBean(ThreadMXBean.class);
            Logger logger = dragons.getLogger();
            logger.info("=== BEGIN COMPLETE THREAD DUMP ===");
            for (Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
                logger.info("THREAD " + entry.getKey().getId() + ": " + entry.getKey().getName() + " (Priority: " + entry.getKey().getPriority() + ", " + "State: " + entry.getKey().getState() + ", CPU Time: " + threadBean.getThreadCpuTime(entry.getKey().getId()) + ")");
                for (StackTraceElement elem : entry.getValue()) {
                    logger.info("    " + elem.toString());
                }
            }
            logger.info("=== END COMPLETE THREAD DUMP ===");
            sender.sendMessage(ChatColor.GREEN + "Dumped all threads to console.");
        } else if (args[1].equalsIgnoreCase("workers")) {
            Logger logger = dragons.getLogger();
            String filter = "";
            Plugin pluginFor = null;
            if (args.length > 2) {
                filter = " for plugin " + args[2];
                pluginFor = Bukkit.getPluginManager().getPlugin(args[2]);
                if (pluginFor == null) {
                    sender.sendMessage(ChatColor.RED + "Invalid plugin! /debug dump workers [Plugin]");
                    return true;
                }
            }
            logger.info("=== BEGIN COMPLETE WORKER DUMP" + filter.toUpperCase() + " ===");
            for (BukkitWorker worker : Bukkit.getScheduler().getActiveWorkers()) {
                if (pluginFor != null && worker.getOwner() != pluginFor) {
                    continue;
                }
                logger.info("WORKER " + worker.getTaskId() + ": Class " + worker.getClass().getName() + ", Owner " + worker.getOwner().getName() + ", Thread " + worker.getThread().getId() + " (" + worker.getThread().getName() + ") ");
            }
            logger.info("=== END COMPLETE WORKER DUMP" + filter.toUpperCase() + " ===");
            sender.sendMessage(ChatColor.GREEN + "Dumped all workers " + filter + " to console.");
        } else if (args[1].equalsIgnoreCase("pendingtasks")) {
            Logger logger = Dragons.getInstance().getLogger();
            String filter = "";
            Plugin pluginFor = null;
            if (args.length > 2) {
                filter = " for plugin " + args[2];
                pluginFor = Bukkit.getPluginManager().getPlugin(args[2]);
                if (pluginFor == null) {
                    sender.sendMessage(ChatColor.RED + "Invalid plugin! /debug dump pendingtasks [Plugin]");
                    return true;
                }
            }
            logger.info("=== BEGIN COMPLETE PENDING TASK DUMP" + filter.toUpperCase() + " ===");
            for (BukkitTask task : Bukkit.getScheduler().getPendingTasks()) {
                if (pluginFor != null) {
                    if (task.getOwner() != pluginFor) {
                        continue;
                    }
                }
                logger.info("TASK " + task.getTaskId() + ": Class " + task.getClass().getName() + ", Owner " + task.getOwner().getName() + ", Sync=" + task.isSync() + ", Cancelled=" + task.isCancelled());
            }
            logger.info("=== END COMPLETE PENDING TASK DUMP" + filter.toUpperCase() + " ===");
            sender.sendMessage(ChatColor.GREEN + "Dumped all pending tasks" + filter + " to console.");
        } else {
            sender.sendMessage(ChatColor.RED + "Invalid dump option! /debug dump <gameobjects|entities|threads|workers [Plugin]|pendingtasks [Plugin]>");
        }
    } else if (args[0].equalsIgnoreCase("attach")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Specify a player to debug! (Must be online) /debug attach <Player>");
            return true;
        }
        Player target = Bukkit.getPlayerExact(args[1]);
        if (target == null) {
            sender.sendMessage(ChatColor.RED + "Invalid player! (Must be online) /debug attach <Player>");
            return true;
        }
        User targetUser = UserLoader.fromPlayer(target);
        targetUser.addDebugTarget(sender);
        sender.sendMessage(ChatColor.GREEN + "Began debugging " + target.getName());
    } else if (args[0].equalsIgnoreCase("detach")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Specify a player to stop debugging! /debug detach <Player>");
            return true;
        }
        Player target = Bukkit.getPlayerExact(args[1]);
        if (target == null) {
            sender.sendMessage(ChatColor.RED + "Invalid player! (Must be online) /debug detach <Player>");
            return true;
        }
        User targetUser = UserLoader.fromPlayer(target);
        targetUser.removeDebugTarget(sender);
        sender.sendMessage(ChatColor.GREEN + "Stopped debugging " + target.getName());
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid usage! /debug");
    }
    return true;
}
Also used : Entity(org.bukkit.entity.Entity) ThreadMXBean(com.sun.management.ThreadMXBean) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) BukkitTask(org.bukkit.scheduler.BukkitTask) BukkitWorker(org.bukkit.scheduler.BukkitWorker) Logger(java.util.logging.Logger) World(org.bukkit.World) Item(org.bukkit.entity.Item) Entry(java.util.Map.Entry) GameObject(mc.dragons.core.gameobject.GameObject) Level(java.util.logging.Level) LogLevel(mc.dragons.core.logging.LogLevel) Plugin(org.bukkit.plugin.Plugin)

Example 17 with GameObject

use of mc.dragons.core.gameobject.GameObject in project DragonsOnline by UniverseCraft.

the class GoToFloorCommand method listFloors.

private void listFloors(CommandSender sender) {
    sender.sendMessage(ChatColor.GREEN + "Listing all floors:");
    for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.FLOOR)) {
        Floor floor = (Floor) gameObject;
        sender.sendMessage(ChatColor.GRAY + "- " + floor.getFloorName() + " [" + floor.getWorldName() + "] [Lv " + floor.getLevelMin() + "]");
    }
}
Also used : Floor(mc.dragons.core.gameobject.floor.Floor) GameObject(mc.dragons.core.gameobject.GameObject)

Aggregations

GameObject (mc.dragons.core.gameobject.GameObject)17 User (mc.dragons.core.gameobject.user.User)5 Entity (org.bukkit.entity.Entity)5 NPC (mc.dragons.core.gameobject.npc.NPC)4 Floor (mc.dragons.core.gameobject.floor.Floor)3 Player (org.bukkit.entity.Player)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 UUID (java.util.UUID)2 Level (java.util.logging.Level)2 GameObjectType (mc.dragons.core.gameobject.GameObjectType)2 Item (mc.dragons.core.gameobject.item.Item)2 Quest (mc.dragons.core.gameobject.quest.Quest)2 Region (mc.dragons.core.gameobject.region.Region)2 StorageAccess (mc.dragons.core.storage.StorageAccess)2 LocalStorageAccess (mc.dragons.core.storage.local.LocalStorageAccess)2 World (org.bukkit.World)2 Item (org.bukkit.entity.Item)2 ItemStack (org.bukkit.inventory.ItemStack)2 ThreadMXBean (com.sun.management.ThreadMXBean)1 Base64 (java.util.Base64)1