Search in sources :

Example 1 with LogLevel

use of mc.dragons.core.logging.LogLevel in project DragonsOnline by UniverseCraft.

the class ServerOptionsCommands method serverOptionsCommand.

private void serverOptionsCommand(CommandSender sender, String[] args) {
    ServerOptions options = dragons.getServerOptions();
    if (args.length == 0) {
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions deathcountdown [Seconds]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions autosave [On|Off]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions autosaveperiod [Seconds]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions customspawning [On|Off]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions customspawnrate [Seconds]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions customspawnmargin [Margin]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions dropchancemultiplier [Multiplier]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions gameverification [On|Off]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions gameverificationsweeprate [Seconds]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions defaultwalkspeed [Value]");
        sender.sendMessage(ChatColor.YELLOW + "/serveroptions loglevel [LogLevel]");
    } else if (args[0].equalsIgnoreCase("deathcountdown")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Death countdown is currently " + options.getDeathCountdown() + "s");
        } else {
            options.setDeathCountdown(Integer.valueOf(args[1]));
            sender.sendMessage(ChatColor.GREEN + "Set death countdown to " + args[1] + "s");
        }
    } else if (args[0].equalsIgnoreCase("autosave")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "GameObject auto-saving is currently " + (options.isAutoSaveEnabled() ? "ON" : "OFF"));
        } else {
            options.setAutoSaveEnabled(args[1].equalsIgnoreCase("ON"));
            sender.sendMessage(ChatColor.GREEN + "GameObject auto-saving is now " + (options.isAutoSaveEnabled() ? "ON" : "OFF"));
        }
    } else if (args[0].equalsIgnoreCase("autosaveperiod")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "GameObject auto-save period is currently " + options.getAutoSavePeriodTicks() / 20 + "s");
        } else {
            options.setAutoSavePeriodTicks((int) (double) Double.valueOf(args[1]) * 20);
            sender.sendMessage(ChatColor.GREEN + "GameObject auto-save period is now " + args[1] + "s");
        }
    } else if (args[0].equalsIgnoreCase("customspawning")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawning is currently " + (options.isCustomSpawningEnabled() ? "ON" : "OFF"));
        } else {
            options.setCustomSpawningEnabled(args[1].equalsIgnoreCase("ON"));
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawning is now " + (options.isCustomSpawningEnabled() ? "ON" : "OFF"));
        }
    } else if (args[0].equalsIgnoreCase("customspawnrate")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawn rate is currently " + options.getCustomSpawnRate() / 20 + "s");
        } else {
            options.setCustomSpawnRate((int) (double) Double.valueOf(args[1]) * 20);
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawn rate is now " + args[1] + "s");
        }
    } else if (args[0].equalsIgnoreCase("customspawnmargin")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawn margin is currently " + options.getCustomSpawnMargin() + "m");
        } else {
            options.setCustomSpawnMargin(Integer.valueOf(args[1]));
            sender.sendMessage(ChatColor.GREEN + "GameObject custom spawn margin is now " + args[1] + "m");
        }
    } else if (args[0].equalsIgnoreCase("dropchancemultiplier")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Drop chance multiplier is currently " + options.getDropChanceMultiplier());
        } else {
            options.setDropChanceMultiplier(Double.valueOf(args[1]));
            sender.sendMessage(ChatColor.GREEN + "Drop chance multiplier is now " + args[1] + "x");
        }
    } else if (args[0].equalsIgnoreCase("gameverification")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Game environment verification is currently " + (options.isVerifyIntegrityEnabled() ? "ON" : "OFF"));
        } else {
            options.setVerifyIntegrityEnabled(args[1].equalsIgnoreCase("ON"));
            sender.sendMessage(ChatColor.GREEN + "Game environment verification is now " + (options.isVerifyIntegrityEnabled() ? "ON" : "OFF"));
        }
    } else if (args[0].equalsIgnoreCase("gameverificationsweeprate")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Game environment verification sweep rate is currently " + options.getVerifyIntegritySweepRate() / 20 + "s");
        } else {
            options.setVerifyIntegritySweepRate((int) (double) Double.valueOf(args[1]) * 20);
            sender.sendMessage(ChatColor.GREEN + "Game environment verification sweep rate is now " + args[1] + "s");
        }
    } else if (args[0].equalsIgnoreCase("defaultwalkspeed")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Default walk speed is currently " + options.getDefaultWalkSpeed());
        } else {
            options.setDefaultWalkSpeed(Double.valueOf(args[1]));
            sender.sendMessage(ChatColor.GREEN + "Default walk speed is now " + args[1]);
        }
    } else if (args[0].equalsIgnoreCase("loglevel")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.GREEN + "Log level is currently " + options.getLogLevel());
        } else {
            Level level = this.lookup(sender, () -> Level.parse(args[0].toUpperCase()), ChatColor.RED + "Invalid log level! /loglevel <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + ">");
            if (level == null)
                return;
            options.setLogLevel(level);
            sender.sendMessage(ChatColor.GREEN + "Log level is now " + level);
        }
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid option! /serveroptions");
    }
}
Also used : Level(java.util.logging.Level) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) LogLevel(mc.dragons.core.logging.LogLevel) ServerOptions(mc.dragons.core.ServerOptions)

Example 2 with LogLevel

use of mc.dragons.core.logging.LogLevel in project DragonsOnline by UniverseCraft.

the class LogLevelCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.DEVELOPER))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "Insufficient arguments! /loglevel <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + "> [Plugin]");
        sender.sendMessage(ChatColor.RED + "Global log level is currently " + Dragons.getInstance().getServerOptions().getLogLevel());
        return true;
    }
    Level level = this.lookup(sender, () -> Level.parse(args[0].toUpperCase()), ChatColor.RED + "Invalid log level! /loglevel <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + ">");
    if (level == null)
        return true;
    if (args.length == 1) {
        Dragons.getInstance().getServerOptions().setLogLevel(level);
        sender.sendMessage(ChatColor.GREEN + "Set log level to " + level.toString());
    } else {
        Plugin plugin = Bukkit.getPluginManager().getPlugin(args[1]);
        if (plugin == null) {
            sender.sendMessage(ChatColor.RED + "Invalid plugin name! /debug level <" + StringUtil.parseList(LogLevel.getApprovedLevels(), "|") + ">" + " [Plugin]");
            return true;
        }
        plugin.getLogger().setLevel(level);
        sender.sendMessage(ChatColor.GREEN + "Set log level of plugin " + plugin.getName() + " to " + level.toString());
    }
    return true;
}
Also used : PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) LogLevel(mc.dragons.core.logging.LogLevel) Level(java.util.logging.Level) Plugin(org.bukkit.plugin.Plugin)

Example 3 with LogLevel

use of mc.dragons.core.logging.LogLevel 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)

Aggregations

Level (java.util.logging.Level)3 LogLevel (mc.dragons.core.logging.LogLevel)3 PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)2 Plugin (org.bukkit.plugin.Plugin)2 ThreadMXBean (com.sun.management.ThreadMXBean)1 Entry (java.util.Map.Entry)1 Logger (java.util.logging.Logger)1 ServerOptions (mc.dragons.core.ServerOptions)1 GameObject (mc.dragons.core.gameobject.GameObject)1 User (mc.dragons.core.gameobject.user.User)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1 Item (org.bukkit.entity.Item)1 Player (org.bukkit.entity.Player)1 BukkitTask (org.bukkit.scheduler.BukkitTask)1 BukkitWorker (org.bukkit.scheduler.BukkitWorker)1