Search in sources :

Example 11 with GameObject

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

the class TestQuestCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.TESTER) || !requirePlayer(sender))
        return true;
    User user = user(sender);
    if (args.length == 0) {
        sender.sendMessage(ChatColor.YELLOW + "/testquest -listquests");
        sender.sendMessage(ChatColor.YELLOW + "/testquest <QuestName> [-reset|-stage <#>]");
        return true;
    } else if (args[0].equalsIgnoreCase("-listquests")) {
        sender.sendMessage(ChatColor.GREEN + "Listing all quests:");
        for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.QUEST)) {
            Quest quest = (Quest) gameObject;
            sender.sendMessage(ChatColor.GRAY + "- " + quest.getName() + " (" + quest.getQuestName() + ") [Lv " + quest.getLevelMin() + "] [" + quest.getSteps().size() + " steps]" + (quest.isValid() ? "" : ChatColor.RED + " (Incomplete Setup!)"));
        }
        return true;
    }
    Quest quest = lookupQuest(sender, args[0]);
    if (quest == null)
        return true;
    if (quest.isLocked() && !hasPermission(sender, PermissionLevel.GM)) {
        sender.sendMessage(ChatColor.RED + "That quest is currently locked! Try again later.");
    }
    if (args.length >= 2) {
        if (args[1].equalsIgnoreCase("-reset")) {
            user.removeQuest(quest);
            sender.sendMessage(ChatColor.GREEN + "Erased your progress for quest " + quest.getQuestName() + ".");
        } else if (args[1].equalsIgnoreCase("-stage")) {
            if (args.length == 2) {
                sender.sendMessage(ChatColor.RED + "Specify a step name to jump to! /testquest <QuestName> -stage <#>");
                return true;
            }
            Integer stepNo = parseInt(sender, args[2]);
            if (stepNo == null)
                return true;
            user.updateQuestProgress(quest, quest.getSteps().get(stepNo));
            sender.sendMessage(ChatColor.GREEN + "Jumped to step " + stepNo + " of quest " + quest.getQuestName());
        }
        return true;
    }
    if (!quest.isValid()) {
        sender.sendMessage(ChatColor.RED + "Warning: This quest is invalid or incomplete and may not work as expected.");
    }
    user.updateQuestProgress(quest, quest.getSteps().get(0));
    sender.sendMessage(ChatColor.GREEN + "Began testing quest " + quest.getName() + " (" + quest.getQuestName() + ")");
    return true;
}
Also used : User(mc.dragons.core.gameobject.user.User) GameObject(mc.dragons.core.gameobject.GameObject) Quest(mc.dragons.core.gameobject.quest.Quest)

Example 12 with GameObject

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

the class EntityDamageListener method onEntityDamage.

/**
 * Handles player-vs-player, player-vs-entity, and entity-vs-player interactions.
 * Calculates damage amounts and applies any special damage effects.
 *
 * @param event
 */
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    LOGGER.trace("Damage event on " + StringUtil.entityToString(event.getEntity()) + " by " + StringUtil.entityToString(event.getDamager()));
    Entity damager = event.getDamager();
    User userDamager = null;
    NPC npcDamager = null;
    Item attackerHeldItem = null;
    if (damager instanceof Player) {
        if (!dragons.getEntityHider().canSee((Player) damager, event.getEntity())) {
            event.setCancelled(true);
            return;
        }
        userDamager = UserLoader.fromPlayer((Player) damager);
        attackerHeldItem = ItemLoader.fromBukkit(userDamager.getPlayer().getInventory().getItemInMainHand());
        if (attackerHeldItem != null && !attackerHeldItem.getItemClass().checkCanUse(userDamager, true)) {
            // Don't cancel the event, just don't modify the damage from the default
            return;
        }
    } else if (damager instanceof Arrow) {
        Arrow arrow = (Arrow) damager;
        if (arrow.getShooter() instanceof Entity) {
            npcDamager = NPCLoader.fromBukkit((Entity) arrow.getShooter());
        }
    } else {
        npcDamager = NPCLoader.fromBukkit(damager);
    }
    if (damager.hasMetadata("partOf")) {
        npcDamager = (NPC) damager.getMetadata("partOf").get(0).value();
    }
    if (npcDamager != null && npcDamager.getNPCType() != NPC.NPCType.HOSTILE) {
        event.setCancelled(true);
        return;
    }
    boolean external = false;
    Entity target = event.getEntity();
    User userTarget = null;
    NPC npcTarget = null;
    if (target.getPersistentDataContainer().has(Dragons.FIXED_ENTITY_KEY, PersistentDataType.SHORT)) {
        if (userDamager != null) {
            userDamager.debug("- Fixed entity, cancelling");
            damager.sendMessage(ChatColor.RED + "You cannot damage or destroy a fixed entity! Please un-fix this entity (/fixed) if you wish to remove it.");
        }
        event.setCancelled(true);
        return;
    }
    if (target.isInvulnerable()) {
        event.setCancelled(true);
        return;
    }
    if (target instanceof Player) {
        userTarget = UserLoader.fromPlayer((Player) target);
        if (userTarget == null) {
            npcTarget = NPCLoader.fromBukkit(target);
            if (npcTarget == null) {
                event.setCancelled(true);
                return;
            }
        } else if (userTarget.isGodMode()) {
            immortalTarget(target, userDamager);
            userTarget.debug("- God mode, cancelling");
            event.setCancelled(true);
            return;
        }
    /*
		 * Complex entities are rendered as composites of simpler entities.
		 * When a player attacks a complex entity, one of those component
		 * entities actually receives the damage. We route it to the appropriate
		 * actual entity by checking for the appropriate metadata.
		 */
    } else if (target.hasMetadata("partOf")) {
        LOGGER.trace("-Target is part of a complex entity!");
        npcTarget = (NPC) target.getMetadata("partOf").get(0).value();
        external = true;
    } else {
        npcTarget = NPCLoader.fromBukkit(target);
        if (npcTarget != null) {
            if (npcTarget.isImmortal() || target.isInvulnerable()) {
                event.setCancelled(true);
                if (userDamager != null) {
                    Item item = ItemLoader.fromBukkit(userDamager.getPlayer().getInventory().getItemInMainHand());
                    /*
						 * This specific item class allows removal of immortal entities,
						 * intended for use by the content team.
						 */
                    if (item != null && item.getClassName().equals(ItemConstants.IMMORTAL_OVERRIDE_ITEM_CLASS)) {
                        npcTarget.getEntity().remove();
                        dragons.getGameObjectRegistry().removeFromDatabase(npcTarget);
                        userDamager.getPlayer().sendMessage(ChatColor.GREEN + "Removed NPC successfully.");
                        return;
                    }
                    immortalTarget(target, userDamager);
                }
                npcTarget.updateHealthBar();
                return;
            }
        } else {
            /*
				 * Sometimes vanilla entities will sneak their way into a production world.
				 */
            LOGGER.trace("- Target is an entity but not an NPC! HasHandle=" + target.hasMetadata("handle"));
            LOGGER.warning("- Unauthorized vanilla interaction from " + StringUtil.entityToString(damager) + " to " + StringUtil.entityToString(target));
            if (userDamager != null && PermissionUtil.verifyActivePermissionLevel(userDamager, PermissionLevel.TESTER, false)) {
                HologramUtil.temporaryHologram(target, ChatColor.RED + "Error: Unbound Entity Target", 20 * 5, true);
            }
        }
    }
    if (userDamager != null && npcTarget != null) {
        Item item = ItemLoader.fromBukkit(((Player) damager).getInventory().getItemInMainHand());
        if (item != null) {
            // TODO verify this
            item.getItemClass().handleLeftClick(userDamager);
        }
    }
    /*
		 * When a player is talking to a quest NPC, they cannot interact with other entities.
		 */
    if (userDamager != null && npcTarget != null && userDamager.hasActiveDialogue()) {
        userDamager.sendActionBar(ChatColor.GRAY + "PVE is disabled during quest dialogue!");
        event.setCancelled(true);
        return;
    }
    if (npcDamager != null && userTarget != null && userTarget.hasActiveDialogue()) {
        event.setCancelled(true);
        return;
    }
    double distance = damager.getLocation().distance(target.getLocation());
    double damage = event.getDamage();
    if (userDamager == null && npcDamager == null || userTarget == null && npcTarget == null || npcDamager != null && npcTarget != null) {
        return;
    }
    if (userDamager != null && userDamager.isGodMode()) {
        if (npcTarget != null) {
            npcTarget.remove();
        } else if (!(target instanceof Player)) {
            target.remove();
        } else {
            ((Player) target).setHealth(0.0D);
        }
        return;
    }
    Set<Region> regions = regionLoader.getRegionsByLocation(target.getLocation());
    if (userTarget != null) {
        userTarget.debug("user target");
        for (Region region : regions) {
            if (!Boolean.valueOf(region.getFlags().getString("pve"))) {
                userTarget.debug("- Cancelled damage due to region " + region.getName() + ": PVE flag = false");
                event.setCancelled(true);
                return;
            }
        }
    }
    if (npcDamager != null) {
        /*
			 * Adjust damage amount based on the level difference. A high level entity will damage a
			 * low level player more than it would damage a high level player.
			 */
        double weightedLevelDiscrepancy = Math.max(0.0D, npcDamager.getLevel() - TARGET_LEVEL_DISCOUNTING * userTarget.getLevel());
        damage += LEVEL_DISCREPANCY_FACTOR * weightedLevelDiscrepancy;
    } else {
        /*
			 * Apply item based damage modifiers and cooldowns
			 */
        double itemDamage = 0.5D;
        if (attackerHeldItem != null) {
            if (attackerHeldItem.hasCooldownRemaining()) {
                userDamager.sendActionBar(ChatColor.RED + "- WAIT - " + MathUtil.round(attackerHeldItem.getCooldownRemaining()) + "s -");
                event.setCancelled(true);
                return;
            }
            if (!external) {
                attackerHeldItem.registerUse();
            }
            final User fUserDamager = userDamager;
            final Item fAttackerHeldItem = attackerHeldItem;
            new BukkitRunnable() {

                @Override
                public void run() {
                    Item currentHeldItem = ItemLoader.fromBukkit(fUserDamager.getPlayer().getInventory().getItemInMainHand());
                    if (currentHeldItem == null || !currentHeldItem.equals(fAttackerHeldItem)) {
                        return;
                    }
                    double percentRemaining = fAttackerHeldItem.getCooldownRemaining() / fAttackerHeldItem.getCooldown();
                    String cooldownName = String.valueOf(fAttackerHeldItem.getDecoratedName()) + ChatColor.DARK_GRAY + " [" + ChatColor.RESET + "WAIT " + ProgressBarUtil.getCountdownBar(percentRemaining) + ChatColor.DARK_GRAY + "]";
                    fUserDamager.getPlayer().getInventory().setItemInMainHand(fAttackerHeldItem.localRename(cooldownName));
                    if (!fAttackerHeldItem.hasCooldownRemaining()) {
                        sync(() -> {
                            Item currentHeldItem2 = ItemLoader.fromBukkit(fUserDamager.getPlayer().getInventory().getItemInMainHand());
                            if (currentHeldItem2 == null || !currentHeldItem2.equals(fAttackerHeldItem)) {
                                return;
                            }
                            fUserDamager.getPlayer().getInventory().setItemInMainHand(fAttackerHeldItem.localRename(fAttackerHeldItem.getDecoratedName()));
                        }, 10);
                        cancel();
                    }
                }
            }.runTaskTimer(dragons, 0L, 5L);
            itemDamage = attackerHeldItem.getDamage();
            damage += itemDamage;
        }
        if (userTarget == null) {
            for (Region region : regions) {
                if (!Boolean.valueOf(region.getFlags().getString("pve"))) {
                    event.setCancelled(true);
                    userDamager.sendActionBar(ChatColor.GRAY + "PVE is disabled in this region.");
                    return;
                }
            }
        } else {
            for (Region region : regions) {
                if (!Boolean.valueOf(region.getFlags().getString("pvp"))) {
                    event.setCancelled(true);
                    userDamager.sendActionBar(ChatColor.GRAY + "PVP is disabled in this region.");
                    return;
                }
            }
        }
        /* Melee skill increases inversely proportionally with distance from target */
        userDamager.incrementSkillProgress(SkillType.MELEE, Math.min(0.5D, 1.0D / distance));
        double randomMelee = Math.random() * userDamager.getSkillLevel(SkillType.MELEE) / distance;
        damage += randomMelee;
    }
    if (userTarget != null) {
        double randomDefense = Math.random() * Math.random() * userTarget.getSkillLevel(SkillType.DEFENSE);
        damage -= randomDefense;
        Item targetHeldItem = ItemLoader.fromBukkit(userTarget.getPlayer().getInventory().getItemInMainHand());
        double itemDefense = 0.0D;
        if (targetHeldItem != null && targetHeldItem.getItemClass().checkCanUse(userTarget, false)) {
            itemDefense = targetHeldItem.getArmor();
        }
        for (ItemStack itemStack : userTarget.getPlayer().getInventory().getArmorContents()) {
            Item armorItem = ItemLoader.fromBukkit(itemStack);
            if (armorItem != null && armorItem.getItemClass().checkCanUse(userTarget, false)) {
                itemDefense += armorItem.getArmor();
            }
        }
        double actualItemDefense = Math.min(damage, Math.random() * itemDefense);
        damage -= actualItemDefense;
        userTarget.incrementSkillProgress(SkillType.DEFENSE, Math.random() * actualItemDefense);
    }
    damage = Math.max(0.0D, damage);
    if (userDamager != null) {
        userDamager.debug("DMG OUTGOING: " + damage + " to " + StringUtil.entityToString(target));
    }
    if (userTarget != null) {
        userTarget.debug("DMG INCOMING: " + damage + " from " + StringUtil.entityToString(damager));
    }
    if (npcTarget != null) {
        npcTarget.setDamageExternalized(external);
    }
    if (external) {
        npcTarget.damage(damage, damager);
        event.setDamage(0.0D);
        LOGGER.trace("-Damage event external from " + StringUtil.entityToString(target) + " to " + StringUtil.entityToString(npcTarget.getEntity()));
    } else {
        event.setDamage(damage);
        if (userDamager != null) {
            String tag = ChatColor.RED + "-" + Math.round(damage) + "❤";
            if (target.getNearbyEntities(10.0D, 10.0D, 10.0D).stream().filter(e -> (e.getType() == EntityType.PLAYER)).count() > 1L) {
                tag = String.valueOf(tag) + ChatColor.GRAY + " from " + userDamager.getName();
            }
            HologramUtil.temporaryHologram(target, tag, 20, false);
        }
    }
    if (npcTarget != null) {
        npcTarget.getNPCClass().handleTakeDamage(npcTarget, npcDamager != null ? (GameObject) npcDamager : (GameObject) userDamager, damage);
        npcTarget.updateHealthBar(damage);
        if (userDamager != null) {
            npcTarget.getNPCClass().executeConditionals(NPCTrigger.HIT, userDamager, npcTarget);
        }
    }
    if (npcDamager != null) {
        if (npcDamager.getEntityType() == EntityType.PLAYER) {
            npcDamager.getPlayerNPC().playAnimation(NPCAnimation.SWING_MAIN_HAND);
        }
        npcDamager.getNPCClass().handleDealDamage(npcDamager, npcTarget != null ? (GameObject) npcTarget : (GameObject) userTarget, damage);
    }
}
Also used : NPC(mc.dragons.core.gameobject.npc.NPC) Arrow(org.bukkit.entity.Arrow) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Item(mc.dragons.core.gameobject.item.Item) GameObject(mc.dragons.core.gameobject.GameObject) Region(mc.dragons.core.gameobject.region.Region) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 13 with GameObject

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

the class RegionCommand method listRegions.

private void listRegions(CommandSender sender, String[] args) {
    String startingWith = "";
    if (args.length > 1) {
        startingWith = args[1];
    }
    sender.sendMessage(ChatColor.GREEN + "Listing all regions" + (startingWith.length() > 0 ? (" starting with \"" + startingWith + "\"") : "") + ":");
    for (GameObject gameObject : dragons.getGameObjectRegistry().getRegisteredObjects(GameObjectType.REGION)) {
        Region region = (Region) gameObject;
        if (!region.getName().startsWith(startingWith))
            continue;
        String floorData = "";
        if (region.getFloor() != null) {
            floorData = " (Floor: " + region.getFloor().getDisplayName() + ")";
        }
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + region.getName() + floorData, "/region goto " + region.getName(), "Click to teleport to this region"));
    }
}
Also used : GameObject(mc.dragons.core.gameobject.GameObject) Region(mc.dragons.core.gameobject.region.Region)

Example 14 with GameObject

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

the class QuestCommand method listQuests.

private void listQuests(CommandSender sender, String[] args) {
    unusedParameter(args);
    sender.sendMessage(ChatColor.GREEN + "Listing all quests:");
    int nInvalid = 0;
    for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.QUEST)) {
        Quest quest = (Quest) gameObject;
        if (!quest.isValid())
            nInvalid++;
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + quest.getName() + " (" + quest.getQuestName() + ") [Lv " + quest.getLevelMin() + "] [" + quest.getSteps().size() + " steps]" + (quest.isValid() ? "" : ChatColor.RED + " (Incomplete Setup!)"), "/quest " + quest.getName(), "Click to view quest details"));
    }
    if (nInvalid > 0) {
        sender.sendMessage(ChatColor.RED + "" + nInvalid + " invalid or incomplete quests found!");
    }
}
Also used : GameObject(mc.dragons.core.gameobject.GameObject) Quest(mc.dragons.core.gameobject.quest.Quest)

Example 15 with GameObject

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

the class VerifyGameIntegrityCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.DEVELOPER))
        return true;
    int errors = 0;
    int fixed = 0;
    boolean resolve = false;
    boolean silent = false;
    for (int i = 0; i < args.length; i++) {
        if (args[i].equalsIgnoreCase("-resolve")) {
            resolve = true;
        }
        if (args[i].equalsIgnoreCase("-silent")) {
            silent = true;
        }
    }
    sendMessageIfNotSilent(sender, silent, ChatColor.GREEN + "Verifying integrity of active game environment...");
    sendMessageIfNotSilent(sender, silent, ChatColor.GRAY + "- Validating user data:");
    for (GameObject gameObject : registry.getRegisteredObjects(GameObjectType.USER)) {
        User testUser = (User) gameObject;
        if (testUser.getPlayer() == null) {
            sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - User " + testUser.getName() + " does not correspond to a valid player");
            errors++;
            if (resolve) {
                userLoader.unregister(testUser);
                sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                fixed++;
            }
        }
        if (testUser.getSystemProfile() == null) {
            if (testUser.getActivePermissionLevel() != PermissionLevel.USER) {
                sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - User " + testUser.getName() + " has an elevated active permission level without being logged in to a system profile");
                errors++;
                if (resolve) {
                    testUser.setActivePermissionLevel(PermissionLevel.USER);
                    sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                    fixed++;
                }
            }
        } else {
            if (testUser.getActivePermissionLevel().ordinal() > testUser.getSystemProfile().getMaxPermissionLevel().ordinal()) {
                sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - User " + testUser.getName() + " has an active permission level exceeding the maximum of their system profile");
                errors++;
                if (resolve) {
                    testUser.setActivePermissionLevel(PermissionLevel.USER);
                    sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                    fixed++;
                }
            }
        }
    }
    for (Player testPlayer : Bukkit.getOnlinePlayers()) {
        if (UserLoader.fromPlayer(testPlayer) == null) {
            sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Player " + testPlayer.getName() + " does not correspond to a valid GameObject");
            errors++;
            if (resolve) {
                testPlayer.kickPlayer("An error was found with your account, please relog");
                sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                fixed++;
            }
        }
        for (ItemStack itemStack : testPlayer.getInventory().getContents()) {
            if (ItemLoader.fromBukkit(itemStack) == null) {
                if (itemStack == null)
                    continue;
                if (itemStack.getType() == null)
                    continue;
                // Is this possible?
                if (itemStack.getAmount() == 0)
                    continue;
                if (testPlayer.getGameMode() == GameMode.CREATIVE)
                    continue;
                User testUser = UserLoader.fromPlayer(testPlayer);
                if (testUser.getActivePermissionLevel().ordinal() >= PermissionLevel.BUILDER.ordinal())
                    continue;
                sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Player " + testPlayer.getName() + " has an unauthorized vanilla item [" + itemStack.getType().toString() + "]");
                errors++;
                if (resolve) {
                    testPlayer.getInventory().remove(itemStack);
                    testPlayer.sendMessage(ChatColor.RED + "A vanilla item was removed from your inventory.");
                    sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                    fixed++;
                }
            }
        }
    }
    sendMessageIfNotSilent(sender, silent, ChatColor.GRAY + "- Validating entities:");
    for (World world : Bukkit.getWorlds()) {
        for (Entity entity : world.getEntities()) {
            if (entity.getPersistentDataContainer().has(Dragons.FIXED_ENTITY_KEY, PersistentDataType.INTEGER))
                continue;
            if (entity instanceof Player)
                continue;
            if (entity instanceof ItemFrame)
                continue;
            if (!entity.isValid()) {
                sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Entity " + StringUtil.entityToString(entity) + " in world " + world.getName() + " is invalid");
                if (resolve) {
                    entity.remove();
                    sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                    fixed++;
                }
            }
            NPC npc = NPCLoader.fromBukkit(entity);
            if (entity instanceof Item) {
                if (ItemLoader.fromBukkit(((Item) entity).getItemStack()) == null) {
                    sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Entity #" + entity.getEntityId() + " [type " + entity.getType().toString() + "] in world " + world.getName() + " does not correspond to a valid GameObject");
                    if (resolve) {
                        entity.remove();
                        sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                        fixed++;
                    }
                    errors++;
                }
            } else if (npc == null) {
                // Riding things is OK, usually
                if (entity.isInsideVehicle())
                    continue;
                if (entity.hasMetadata("partOf"))
                    continue;
                if (entity.hasMetadata("allow"))
                    continue;
                sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Entity #" + entity.getEntityId() + " [type " + entity.getType().toString() + "] in world " + world.getName() + " does not correspond to a valid GameObject");
                errors++;
                if (resolve) {
                    entity.remove();
                    sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                    fixed++;
                }
            } else {
                if (npc.getEntity().getEntityId() != entity.getEntityId()) {
                    sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - Entity " + StringUtil.entityToString(entity) + " in world " + world.getName() + " is improperly linked to an NPC");
                    if (resolve) {
                        entity.remove();
                        sendMessageIfNotSilent(sender, silent, ChatColor.DARK_GREEN + "        [Fixed]");
                        fixed++;
                    }
                }
            }
        }
    }
    sendMessageIfNotSilent(sender, silent, ChatColor.GRAY + "- Validating floors:");
    for (World world : Bukkit.getWorlds()) {
        if (world.getName().equals("world") || world.getName().contains("_nether") || world.getName().contains("_the_end"))
            continue;
        if (FloorLoader.fromWorld(world) == null) {
            sendMessageIfNotSilent(sender, silent, ChatColor.RED + "    - World " + world.getName() + " does not correspond to a valid floor");
            errors++;
        }
    }
    if (errors == 0) {
        sendMessageIfNotSilent(sender, silent, ChatColor.GREEN + "All checks passed! Active game environment is valid.");
    } else {
        sendMessageIfNotSilent(sender, silent, ChatColor.RED + "There were " + errors + " errors found in the active game environment.");
        if (resolve) {
            sendMessageIfNotSilent(sender, silent, ChatColor.RED + "" + fixed + " errors were fixed.");
        } else {
            sendMessageIfNotSilent(sender, silent, ChatColor.RED + "Run " + ChatColor.GRAY + "/verifygameintegrity -resolve " + ChatColor.RED + "to attempt to fix these issues. " + "You may need to run this multiple times in some cases.");
        }
    }
    // If it's a console command, we'll log even if it's silent
    if (silent && !(sender instanceof Player)) {
        Dragons.getInstance().getLogger().info("Verified game environment. Found " + errors + " errors, fixed " + fixed);
    }
    return true;
}
Also used : NPC(mc.dragons.core.gameobject.npc.NPC) Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) GameObject(mc.dragons.core.gameobject.GameObject) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.bukkit.inventory.ItemStack) World(org.bukkit.World)

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