Search in sources :

Example 16 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class Denizen method onEnable.

/*
     * Sets up Denizen on start of the CraftBukkit server.
     */
@Override
public void onEnable() {
    if (!NMSHandler.initialize(this)) {
        getLogger().warning("-------------------------------------");
        getLogger().warning("Denizen is not compatible with this Spigot version! Deactivating Denizen!");
        getLogger().warning("-------------------------------------");
        getServer().getPluginManager().disablePlugin(this);
        startedSuccessful = false;
        return;
    }
    try {
        org.spigotmc.AsyncCatcher.enabled = false;
    } catch (Throwable e) {
        dB.echoError("Running not-Spigot?!");
    }
    try {
        versionTag = this.getDescription().getVersion();
        // Load Denizen's core
        DenizenCore.init(this);
        // Activate dependencies
        depends.initialize();
        if (Depends.citizens == null || !Depends.citizens.isEnabled()) {
            getLogger().warning("Citizens does not seem to be activated! Denizen will have greatly reduced functionality!");
        //getServer().getPluginManager().disablePlugin(this);
        //return;
        }
        startedSuccessful = true;
        requirementChecker = new RequirementChecker();
        // Startup procedure
        dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
        dB.log(ChatColor.YELLOW + " _/_ _  ._  _ _  ");
        dB.log(ChatColor.YELLOW + "(/(-/ )/ /_(-/ ) " + ChatColor.GRAY + " scriptable minecraft");
        dB.log("");
        dB.log(ChatColor.GRAY + "by: " + ChatColor.WHITE + "aufdemrand");
        dB.log(ChatColor.GRAY + "version: " + ChatColor.WHITE + versionTag);
        dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        MetricsLite metrics = new MetricsLite(this);
        metrics.start();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        // Create the dNPC Registry
        dNPCRegistry = new dNPCRegistry(this);
        // Create our CommandManager to handle '/denizen' commands
        commandManager = new CommandManager();
        commandManager.setInjector(new Injector(this));
        commandManager.register(DenizenCommandHandler.class);
        // If Citizens is enabled, let it handle '/npc' commands
        if (Depends.citizens != null) {
            Depends.citizens.registerCommandClass(NPCCommandHandler.class);
        }
        DenizenEntityType.registerEntityType("ITEM_PROJECTILE", ItemProjectile.class);
        DenizenEntityType.registerEntityType("FAKE_ARROW", FakeArrow.class);
        DenizenEntityType.registerEntityType("FAKE_PLAYER", FakePlayer.class);
        // Track all player names for quick dPlayer matching
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            dPlayer.notePlayer(player);
        }
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        DenizenCore.setCommandRegistry(getCommandRegistry());
        getCommandRegistry().registerCoreMembers();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        // Register script-container types
        ScriptRegistry._registerCoreTypes();
        // Populate config.yml if it doesn't yet exist.
        saveDefaultConfig();
        reloadConfig();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        ScriptRegistry._registerType("interact", InteractScriptContainer.class);
        ScriptRegistry._registerType("book", BookScriptContainer.class);
        ScriptRegistry._registerType("item", ItemScriptContainer.class);
        ScriptRegistry._registerType("entity", EntityScriptContainer.class);
        ScriptRegistry._registerType("assignment", AssignmentScriptContainer.class);
        ScriptRegistry._registerType("format", FormatScriptContainer.class);
        ScriptRegistry._registerType("inventory", InventoryScriptContainer.class);
        ScriptRegistry._registerType("command", CommandScriptContainer.class);
        ScriptRegistry._registerType("map", MapScriptContainer.class);
        ScriptRegistry._registerType("version", VersionScriptContainer.class);
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        // Ensure the Scripts and Midi folder exist
        new File(getDataFolder() + "/scripts").mkdirs();
        new File(getDataFolder() + "/midi").mkdirs();
        new File(getDataFolder() + "/schematics").mkdirs();
        // Ensure the example Denizen.mid sound file is available
        if (!new File(getDataFolder() + "/midi/Denizen.mid").exists()) {
            String sourceFile = URLDecoder.decode(Denizen.class.getProtectionDomain().getCodeSource().getLocation().getFile());
            dB.log("Denizen.mid not found, extracting from " + sourceFile);
            Utilities.extractFile(new File(sourceFile), "Denizen.mid", getDataFolder() + "/midi/");
        }
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        // Warn if configuration is outdated / too new
        if (!getConfig().isSet("Config.Version") || getConfig().getInt("Config.Version", 0) < configVersion) {
            dB.echoError("Your Denizen config file is from an older version. " + "Some settings will not be available unless you generate a new one. " + "This is easily done by stopping the server, deleting the current config.yml file in the Denizen folder " + "and restarting the server.");
        }
        // Create the command script handler for listener
        ws_helper = new BukkitWorldScriptHelper();
        ItemScriptHelper is_helper = new ItemScriptHelper();
        InventoryScriptHelper in_helper = new InventoryScriptHelper();
        EntityScriptHelper es_helper = new EntityScriptHelper();
        CommandScriptHelper cs_helper = new CommandScriptHelper();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        if (Depends.citizens != null) {
            // Register traits
            // TODO: should this be a separate function?
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TriggerTrait.class).withName("triggers"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PushableTrait.class).withName("pushable"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(AssignmentTrait.class).withName("assignment"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(NicknameTrait.class).withName("nickname"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HealthTrait.class).withName("health"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ConstantsTrait.class).withName("constants"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HungerTrait.class).withName("hunger"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SittingTrait.class).withName("sitting"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(FishingTrait.class).withName("fishing"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SleepingTrait.class).withName("sleeping"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SneakingTrait.class).withName("sneaking"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(InvisibleTrait.class).withName("invisible"));
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(MobproxTrait.class).withName("mobprox"));
            // Register Speech AI
            CitizensAPI.getSpeechFactory().register(DenizenChat.class, "denizen_chat");
        }
        // ChatbotTrait
        if (Depends.hasProgramAB) {
            CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ChatbotTrait.class).withName("chatbot"));
        }
        // Compile and load Denizen externals
        runtimeCompiler = new RuntimeCompiler(this);
        runtimeCompiler.loader();
    } catch (Exception e) {
        dB.echoError(e);
    }
    // Register Core Members in the Denizen Registries
    try {
        if (Depends.citizens != null) {
            getTriggerRegistry().registerCoreMembers();
        }
        getRequirementRegistry().registerCoreMembers();
        getListenerRegistry().registerCoreMembers();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        tagManager().registerCoreTags();
        new CuboidTags(this);
        new EntityTags(this);
        new LocationTags(this);
        new PlayerTags(this);
        new ServerTags(this);
        new TextTags(this);
        new ParseTags(this);
        if (Depends.citizens != null) {
            new NPCTags(this);
            new AnchorTags(this);
            new ConstantTags(this);
        }
        new FlagTags(this);
        new NotableLocationTags(this);
        eventManager = new OldEventManager();
        // Register all the 'Core' SmartEvents.
        OldEventManager.registerSmartEvent(new CommandSmartEvent());
        OldEventManager.registerSmartEvent(new CuboidEnterExitSmartEvent());
        OldEventManager.registerSmartEvent(new FlagSmartEvent());
        OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent());
        eventManager().registerCoreMembers();
        ScriptEvent.registerScriptEvent(new BiomeEnterExitScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockBuiltScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockBurnsScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockDispensesScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockFadesScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockFallsScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockFormsScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockGrowsScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockIgnitesScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockPhysicsScriptEvent());
        ScriptEvent.registerScriptEvent(new BlockSpreadsScriptEvent());
        ScriptEvent.registerScriptEvent(new BrewsScriptEvent());
        ScriptEvent.registerScriptEvent(new ChatScriptEvent());
        ScriptEvent.registerScriptEvent(new ChunkLoadScriptEvent());
        ScriptEvent.registerScriptEvent(new ChunkUnloadScriptEvent());
        ScriptEvent.registerScriptEvent(new CreeperPoweredScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityBreaksHangingScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityChangesBlockScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityCombustsScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityCreatePortalScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityDamagedScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityDeathScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityDespawnScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityEntersPortalScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityEntersVehicleScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityExitsPortalScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityExitsVehicleScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityExplodesScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityExplosionPrimesScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityFoodLevelChangeScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityFormsBlockScriptEvent());
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
            ScriptEvent.registerScriptEvent(new EntityGlideScriptEvent());
        }
        ScriptEvent.registerScriptEvent(new EntityHealsScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityInteractScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityKilledScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityShootsBowEvent());
        ScriptEvent.registerScriptEvent(new EntitySpawnScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityTamesScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityTargetsScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityTeleportScriptEvent());
        ScriptEvent.registerScriptEvent(new EntityUnleashedScriptEvent());
        ScriptEvent.registerScriptEvent(new FireworkBurstsScriptEvent());
        ScriptEvent.registerScriptEvent(new FurnaceBurnsItemScriptEvent());
        ScriptEvent.registerScriptEvent(new FurnaceSmeltsItemScriptEvent());
        ScriptEvent.registerScriptEvent(new HangingBreaksScriptEvent());
        ScriptEvent.registerScriptEvent(new HorseJumpsScriptEvent());
        ScriptEvent.registerScriptEvent(new InventoryPicksUpItemScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemDespawnsScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemEnchantedScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemMergesScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemMoveScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemRecipeFormedScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemScrollScriptEvent());
        ScriptEvent.registerScriptEvent(new ItemSpawnsScriptEvent());
        ScriptEvent.registerScriptEvent(new LeafDecaysScriptEvent());
        ScriptEvent.registerScriptEvent(new LightningStrikesScriptEvent());
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
            ScriptEvent.registerScriptEvent(new LingeringPotionSplashScriptEvent());
        }
        ScriptEvent.registerScriptEvent(new LiquidSpreadScriptEvent());
        ScriptEvent.registerScriptEvent(new ListPingScriptEvent());
        ScriptEvent.registerScriptEvent(new PigZappedScriptEvent());
        ScriptEvent.registerScriptEvent(new PistonExtendsScriptEvent());
        ScriptEvent.registerScriptEvent(new PistonRetractsScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerAnimatesScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerBreaksBlockScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerBreaksItemScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerChangesGamemodeScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerChangesSignScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerChangesWorldScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerChangesXPScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerClosesInvScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerConsumesScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerCraftsItemScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerDamagesBlockScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerDragsInInvScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerDropsItemScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerEditsBookScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerEmptiesBucketScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerEntersBedScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerEquipsArmorScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerFillsBucketScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerFishesScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerFlyingScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerItemTakesDamageScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerJoinsScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerJumpScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerKickedScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerLeashesEntityScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerLeavesBedScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerLevelsUpScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerLoginScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerOpensInvScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerPicksUpScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerPlacesBlockScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerPlacesHangingScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerQuitsScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerReceivesMessageScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerRespawnsScriptEvent());
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
            ScriptEvent.registerScriptEvent(new PlayerRightClicksAtEntityScriptEvent());
            ScriptEvent.registerScriptEvent(new PlayerSwapsItemsScriptEvent());
        }
        ScriptEvent.registerScriptEvent(new PlayerRightClicksEntityScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerShearsScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerSneakScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerSprintScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerStatisticIncrementsScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerSteersEntityScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerStepsOnScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerTakesFromFurnaceScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerThrowsEggScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerUsesPortalScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerWalkScriptEvent());
        ScriptEvent.registerScriptEvent(new PlayerWalksOverScriptEvent());
        ScriptEvent.registerScriptEvent(new PortalCreateScriptEvent());
        ScriptEvent.registerScriptEvent(new PotionSplashScriptEvent());
        ScriptEvent.registerScriptEvent(new ProjectileHitsScriptEvent());
        ScriptEvent.registerScriptEvent(new ProjectileLaunchedScriptEvent());
        ScriptEvent.registerScriptEvent(new RedstoneScriptEvent());
        ScriptEvent.registerScriptEvent(new ResourcePackStatusScriptEvent());
        ScriptEvent.registerScriptEvent(new SheepDyedScriptEvent());
        ScriptEvent.registerScriptEvent(new SheepRegrowsScriptEvent());
        ScriptEvent.registerScriptEvent(new SlimeSplitsScriptEvent());
        ScriptEvent.registerScriptEvent(new SpawnChangeScriptEvent());
        ScriptEvent.registerScriptEvent(new StructureGrowsScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleCollidesBlockScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleCollidesEntityScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleCreatedScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleDamagedScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleDestroyedScriptEvent());
        ScriptEvent.registerScriptEvent(new VehicleMoveScriptEvent());
        ScriptEvent.registerScriptEvent(new WeatherChangesScriptEvent());
        ScriptEvent.registerScriptEvent(new WorldInitsScriptEvent());
        ScriptEvent.registerScriptEvent(new WorldLoadsScriptEvent());
        ScriptEvent.registerScriptEvent(new WorldSavesScriptEvent());
        ScriptEvent.registerScriptEvent(new WorldUnloadsScriptEvent());
        // b@
        ObjectFetcher.registerWithObjectFetcher(dBiome.class);
        // TODO: Automate this once all classes have tag registries
        dBiome.registerTags();
        // ch@
        ObjectFetcher.registerWithObjectFetcher(dChunk.class);
        // TODO: Automate this once all classes have tag registries
        dChunk.registerTags();
        // co@
        ObjectFetcher.registerWithObjectFetcher(dColor.class);
        // TODO: Automate this once all classes have tag registries
        dColor.registerTags();
        // cu@
        ObjectFetcher.registerWithObjectFetcher(dCuboid.class);
        // TODO: Automate this once all classes have tag registries
        dCuboid.registerTags();
        // ellipsoid@
        ObjectFetcher.registerWithObjectFetcher(dEllipsoid.class);
        // TODO: Automate this once all classes have tag registries
        dEllipsoid.registerTags();
        // e@
        ObjectFetcher.registerWithObjectFetcher(dEntity.class);
        // in@
        ObjectFetcher.registerWithObjectFetcher(dInventory.class);
        // i@
        ObjectFetcher.registerWithObjectFetcher(dItem.class);
        // TODO: Automate this once all classes have tag registries
        dItem.registerTags();
        // l@
        ObjectFetcher.registerWithObjectFetcher(dLocation.class);
        // m@
        ObjectFetcher.registerWithObjectFetcher(dMaterial.class);
        // TODO: Automate this once all classes have tag registries
        dMaterial.registerTags();
        if (Depends.citizens != null) {
            // n@
            ObjectFetcher.registerWithObjectFetcher(dNPC.class);
        }
        // p@
        ObjectFetcher.registerWithObjectFetcher(dPlayer.class);
        // pl@
        ObjectFetcher.registerWithObjectFetcher(dPlugin.class);
        // TODO: Automate this once all classes have tag registries
        dPlugin.registerTags();
        // w@
        ObjectFetcher.registerWithObjectFetcher(dWorld.class);
        // TODO: Automate this once all classes have tag registries
        dWorld.registerTags();
        // Register Core dObjects with the ObjectFetcher
        ObjectFetcher._registerCoreObjects();
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        // Initialize non-standard dMaterials
        dMaterial._initialize();
        // Initialize Property Parser
        propertyParser = new PropertyParser();
        // register properties that add Bukkit code to core objects
        propertyParser.registerProperty(BukkitScriptProperties.class, dScript.class);
        propertyParser.registerProperty(BukkitQueueProperties.class, ScriptQueue.class);
        propertyParser.registerProperty(BukkitElementProperties.class, Element.class);
        propertyParser.registerProperty(BukkitListProperties.class, dList.class);
        // register core dEntity properties
        propertyParser.registerProperty(EntityAge.class, dEntity.class);
        propertyParser.registerProperty(EntityAI.class, dEntity.class);
        propertyParser.registerProperty(EntityAnger.class, dEntity.class);
        propertyParser.registerProperty(EntityAngry.class, dEntity.class);
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
            propertyParser.registerProperty(EntityArmorBonus.class, dEntity.class);
            propertyParser.registerProperty(EntityInvulnerable.class, dEntity.class);
            propertyParser.registerProperty(EntityBoatType.class, dEntity.class);
        }
        propertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
        propertyParser.registerProperty(EntityArms.class, dEntity.class);
        propertyParser.registerProperty(EntityBasePlate.class, dEntity.class);
        propertyParser.registerProperty(EntityBoundingBox.class, dEntity.class);
        propertyParser.registerProperty(EntityChestCarrier.class, dEntity.class);
        propertyParser.registerProperty(EntityColor.class, dEntity.class);
        propertyParser.registerProperty(EntityCritical.class, dEntity.class);
        propertyParser.registerProperty(EntityCustomName.class, dEntity.class);
        propertyParser.registerProperty(EntityPotionEffects.class, dEntity.class);
        propertyParser.registerProperty(EntityElder.class, dEntity.class);
        propertyParser.registerProperty(EntityEquipment.class, dEntity.class);
        propertyParser.registerProperty(EntityFirework.class, dEntity.class);
        propertyParser.registerProperty(EntityFramed.class, dEntity.class);
        propertyParser.registerProperty(EntityGravity.class, dEntity.class);
        propertyParser.registerProperty(EntityHealth.class, dEntity.class);
        propertyParser.registerProperty(EntityInfected.class, dEntity.class);
        propertyParser.registerProperty(EntityInventory.class, dEntity.class);
        propertyParser.registerProperty(EntityItem.class, dEntity.class);
        propertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
        propertyParser.registerProperty(EntityKnockback.class, dEntity.class);
        propertyParser.registerProperty(EntityMarker.class, dEntity.class);
        propertyParser.registerProperty(EntityPainting.class, dEntity.class);
        propertyParser.registerProperty(EntityPotion.class, dEntity.class);
        propertyParser.registerProperty(EntityPowered.class, dEntity.class);
        propertyParser.registerProperty(EntityProfession.class, dEntity.class);
        propertyParser.registerProperty(EntityRotation.class, dEntity.class);
        propertyParser.registerProperty(EntitySmall.class, dEntity.class);
        propertyParser.registerProperty(EntitySilent.class, dEntity.class);
        propertyParser.registerProperty(EntitySitting.class, dEntity.class);
        propertyParser.registerProperty(EntitySize.class, dEntity.class);
        propertyParser.registerProperty(EntitySkeleton.class, dEntity.class);
        propertyParser.registerProperty(EntitySpeed.class, dEntity.class);
        propertyParser.registerProperty(EntityTame.class, dEntity.class);
        propertyParser.registerProperty(EntityVisible.class, dEntity.class);
        // register core dInventory properties
        // Holder must be loaded first to initiate correctly
        propertyParser.registerProperty(InventoryHolder.class, dInventory.class);
        // Same with size...(Too small for contents)
        propertyParser.registerProperty(InventorySize.class, dInventory.class);
        propertyParser.registerProperty(InventoryContents.class, dInventory.class);
        propertyParser.registerProperty(InventoryTitle.class, dInventory.class);
        // register core dItem properties
        propertyParser.registerProperty(ItemApple.class, dItem.class);
        propertyParser.registerProperty(ItemBaseColor.class, dItem.class);
        propertyParser.registerProperty(ItemBook.class, dItem.class);
        propertyParser.registerProperty(ItemDisplayname.class, dItem.class);
        propertyParser.registerProperty(ItemDurability.class, dItem.class);
        propertyParser.registerProperty(ItemDye.class, dItem.class);
        propertyParser.registerProperty(ItemEnchantments.class, dItem.class);
        propertyParser.registerProperty(ItemFirework.class, dItem.class);
        propertyParser.registerProperty(ItemFlags.class, dItem.class);
        propertyParser.registerProperty(ItemLore.class, dItem.class);
        propertyParser.registerProperty(ItemMap.class, dItem.class);
        propertyParser.registerProperty(ItemNBT.class, dItem.class);
        propertyParser.registerProperty(ItemAttributeNBT.class, dItem.class);
        propertyParser.registerProperty(ItemPatterns.class, dItem.class);
        propertyParser.registerProperty(ItemPlantgrowth.class, dItem.class);
        if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
            propertyParser.registerProperty(ItemPotion.class, dItem.class);
        }
        propertyParser.registerProperty(ItemQuantity.class, dItem.class);
        propertyParser.registerProperty(ItemSkullskin.class, dItem.class);
        propertyParser.registerProperty(ItemSpawnEgg.class, dItem.class);
        propertyParser.registerProperty(ItemUnbreakable.class, dItem.class);
    } catch (Exception e) {
        dB.echoError(e);
    }
    try {
        for (World world : getServer().getWorlds()) {
            EntityScriptHelper.linkWorld(world);
        }
    } catch (Exception e) {
        dB.echoError(e);
    }
    if (Settings.packetInterception()) {
        NMSHandler.getInstance().enablePacketInterception(new DenizenPacketHandler());
    }
    // Run everything else on the first server tick
    getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {

        @Override
        public void run() {
            try {
                DenizenCore.loadScripts();
                // Load the saves.yml into memory
                reloadSaves();
                // Fire the 'on Pre Server Start' world event
                ws_helper.serverPreStartEvent();
                // Reload notables from notables.yml into memory
                notableManager.reloadNotables();
                dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
                // Fire the 'on Server Start' world event
                ws_helper.serverStartEvent();
                if (Settings.allowStupidx()) {
                    dB.echoError("Don't screw with bad config values.");
                    Bukkit.shutdown();
                }
            } catch (Exception e) {
                dB.echoError(e);
            }
        }
    }, 1);
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
            // Sadly, minecraft has no delta timing, so a tick is always 50ms.
            DenizenCore.tick(50);
        }
    }, 1, 1);
    new BukkitRunnable() {

        @Override
        public void run() {
            if (Settings.canRecordStats()) {
                new StatsRecord().start();
            }
        }
    }.runTaskTimer(this, 100, 20 * 60 * 60);
}
Also used : RequirementChecker(net.aufdemrand.denizen.scripts.requirements.RequirementChecker) MetricsLite(net.aufdemrand.denizen.utilities.MetricsLite) CommandManager(net.aufdemrand.denizen.utilities.command.CommandManager) OfflinePlayer(org.bukkit.OfflinePlayer) NPCNavigationSmartEvent(net.aufdemrand.denizen.events.core.NPCNavigationSmartEvent) DenizenPacketHandler(net.aufdemrand.denizen.utilities.packets.DenizenPacketHandler) CuboidEnterExitSmartEvent(net.aufdemrand.denizen.events.core.CuboidEnterExitSmartEvent) PropertyParser(net.aufdemrand.denizencore.objects.properties.PropertyParser) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CommandSmartEvent(net.aufdemrand.denizen.events.core.CommandSmartEvent) World(org.bukkit.World) Injector(net.aufdemrand.denizen.utilities.command.Injector) net.aufdemrand.denizen.npc.dNPCRegistry(net.aufdemrand.denizen.npc.dNPCRegistry) File(java.io.File) StatsRecord(net.aufdemrand.denizen.utilities.debugging.StatsRecord) RuntimeCompiler(net.aufdemrand.denizen.utilities.RuntimeCompiler) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) IOException(java.io.IOException) FlagSmartEvent(net.aufdemrand.denizen.events.core.FlagSmartEvent)

Example 17 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_9_R2 method walkTo.

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
    if (entity == null || location == null) {
        return;
    }
    net.minecraft.server.v1_9_R2.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
    if (!(nmsEntityEntity instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
    final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
    final PathEntity path;
    final boolean aiDisabled = isAIDisabled(entity);
    if (aiDisabled) {
        toggleAI(entity, true);
        nmsEntity.onGround = true;
    }
    path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
    if (path != null) {
        entityNavigation.a(path, 1D);
        entityNavigation.a(2D);
        final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
        nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (entityNavigation.n() || path.b()) {
                    if (callback != null) {
                        callback.run();
                    }
                    nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
                    if (aiDisabled) {
                        toggleAI(entity, false);
                    }
                    cancel();
                }
            }
        }.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
    } else //if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
    // TODO: generate waypoints to the target location?
    {
        entity.teleport(location);
    }
}
Also used : net.minecraft.server.v1_9_R2(net.minecraft.server.v1_9_R2) CompoundTag_v1_9_R2(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2) CraftEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 18 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class ProfileEditor_v1_9_R2 method updatePlayer.

@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
    final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    final UUID uuid = player.getUniqueId();
    PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId());
    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (!p.getUniqueId().equals(uuid)) {
            PacketHelper_v1_9_R2.sendPacket(p, destroyPacket);
        }
    }
    new BukkitRunnable() {

        @Override
        public void run() {
            PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
            PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                PacketHelper_v1_9_R2.sendPacket(player, playerInfo);
                if (!player.getUniqueId().equals(uuid)) {
                    PacketHelper_v1_9_R2.sendPacket(player, spawnPacket);
                } else {
                    if (isSkinChanging) {
                        boolean isFlying = player.isFlying();
                        PacketHelper_v1_9_R2.sendPacket(player, new PacketPlayOutRespawn(player.getWorld().getEnvironment().getId(), entityPlayer.getWorld().getDifficulty(), entityPlayer.getWorld().worldData.getType(), entityPlayer.playerInteractManager.getGameMode()));
                        player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
                        player.setFlying(isFlying);
                    }
                    player.updateInventory();
                }
            }
        }
    }.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
Also used : Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_9_R2.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityDestroy(net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy) EntityPlayer(net.minecraft.server.v1_9_R2.EntityPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) PacketPlayOutPlayerInfo(net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo) PacketPlayOutRespawn(net.minecraft.server.v1_9_R2.PacketPlayOutRespawn) UUID(java.util.UUID)

Example 19 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class PlayerDragsInInvScriptEvent method onPlayerDragsInInv.

@EventHandler
public void onPlayerDragsInInv(InventoryDragEvent event) {
    if (dEntity.isCitizensNPC(event.getWhoClicked())) {
        return;
    }
    entity = dEntity.getPlayerFrom(event.getWhoClicked());
    inventory = event.getInventory();
    dInv = dInventory.mirrorBukkitInventory(inventory);
    item = new dItem(event.getOldCursor());
    slots = new dList();
    for (Integer slot : event.getInventorySlots()) {
        slots.add(slot.toString());
    }
    raw_slots = new dList();
    for (Integer raw_slot : event.getRawSlots()) {
        raw_slots.add(raw_slot.toString());
    }
    cancelled = event.isCancelled();
    manual_cancelled = false;
    this.event = event;
    fire();
    if (cancelled && manual_cancelled) {
        final InventoryHolder holder = inventory.getHolder();
        new BukkitRunnable() {

            @Override
            public void run() {
                entity.getPlayerEntity().updateInventory();
                if (holder != null && holder instanceof Player) {
                    ((Player) holder).updateInventory();
                }
            }
        }.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
    }
    event.setCancelled(cancelled);
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 20 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.

the class PlayerBreaksItemScriptEvent method onPlayerItemBreak.

@EventHandler
public void onPlayerItemBreak(PlayerItemBreakEvent event) {
    if (dEntity.isNPC(event.getPlayer())) {
        return;
    }
    item = new dItem(event.getBrokenItem());
    this.event = event;
    fire();
    if (cancelled) {
        final Player player = event.getPlayer();
        final ItemStack itemstack = event.getBrokenItem();
        itemstack.setAmount(itemstack.getAmount() + 1);
        new BukkitRunnable() {

            public void run() {
                itemstack.setDurability(itemstack.getType().getMaxDurability());
                player.updateInventory();
            }
        }.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
    }
}
Also used : Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10