Search in sources :

Example 11 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Minigames by AddstarMC.

the class FlatFileExporter method exportPlayers.

private void exportPlayers() {
    notifyNext("Exporting players...");
    Set<UUID> uniquePlayers = Sets.newHashSet(completions.values());
    for (UUID playerId : uniquePlayers) {
        // Attempt to get information about this player
        OfflinePlayer player = Bukkit.getPlayer(playerId);
        if (player != null && player.getName() != null) {
            callback.acceptPlayer(playerId, player.getName(), player.getName());
        } else {
            callback.acceptPlayer(playerId, "Unknown", "Unknown");
        }
        ++notifyCount;
        notifyProgress();
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID)

Example 12 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Bukkit by Bukkit.

the class DeopCommand method tabComplete.

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");
    if (args.length == 1) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getOperators()) {
            String playerName = player.getName();
            if (StringUtil.startsWithIgnoreCase(playerName, args[0])) {
                completions.add(playerName);
            }
        }
        return completions;
    }
    return ImmutableList.of();
}
Also used : ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer)

Example 13 with OfflinePlayer

use of org.bukkit.OfflinePlayer 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 14 with OfflinePlayer

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

the class Denizen method onDisable.

/*
     * Unloads Denizen on shutdown of the craftbukkit server.
     */
@Override
public void onDisable() {
    if (!startedSuccessful) {
        return;
    }
    // <--[event]
    // @Events
    // shutdown
    //
    // @Warning not all plugins will be loaded and delayed scripts will be dropped.
    //
    // @Triggers when the server is shutting down.
    //
    // @Context
    // None.
    //
    // -->
    HashMap<String, dObject> context = new HashMap<String, dObject>();
    OldEventManager.doEvents(Arrays.asList("shutdown"), new BukkitScriptEntryData(null, null), context);
    // Disable the log interceptor... otherwise bad things on /reload
    logInterceptor.standardOutput();
    // Save notables
    notableManager.saveNotables();
    // Save scoreboards
    ScoreboardHelper._saveScoreboards();
    // Save entities
    EntityScriptHelper.saveEntities();
    // Save offline player inventories
    InventoryScriptHelper._savePlayerInventories();
    // Deconstruct listeners (server shutdown seems not to be triggering a PlayerQuitEvent)
    for (Player player : this.getServer().getOnlinePlayers()) {
        getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player));
    }
    for (OfflinePlayer player : this.getServer().getOfflinePlayers()) {
        try {
            getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player));
        } catch (Exception e) {
            if (player == null) {
                dB.echoError("Tell the Denizen team ASAP about this error! ERR: OPN: " + e.toString());
            } else {
                dB.echoError("'" + player.getName() + "' is having trouble deconstructing! " + "You might have a corrupt player file!");
            }
        }
    }
    // Unload loaded dExternals
    for (dExternal external : RuntimeCompiler.loadedExternals) {
        external.unload();
    }
    RuntimeCompiler.loadedExternals.clear();
    //Disable core members
    getCommandRegistry().disableCoreMembers();
    getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
    Bukkit.getServer().getScheduler().cancelTasks(this);
    HandlerList.unregisterAll(this);
    for (World world : getServer().getWorlds()) {
        EntityScriptHelper.unlinkWorld(world);
    }
    saveSaves();
}
Also used : net.aufdemrand.denizencore.interfaces.dExternal(net.aufdemrand.denizencore.interfaces.dExternal) OfflinePlayer(org.bukkit.OfflinePlayer) Player(org.bukkit.entity.Player) FakePlayer(net.aufdemrand.denizen.nms.interfaces.FakePlayer) HashMap(java.util.HashMap) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) OfflinePlayer(org.bukkit.OfflinePlayer) World(org.bukkit.World) IOException(java.io.IOException)

Example 15 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project Bukkit by Bukkit.

the class WhitelistCommand method tabComplete.

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");
    if (args.length == 1) {
        return StringUtil.copyPartialMatches(args[0], WHITELIST_SUBCOMMANDS, new ArrayList<String>(WHITELIST_SUBCOMMANDS.size()));
    } else if (args.length == 2) {
        if (args[0].equalsIgnoreCase("add")) {
            List<String> completions = new ArrayList<String>();
            for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
                String name = player.getName();
                if (StringUtil.startsWithIgnoreCase(name, args[1]) && !player.isWhitelisted()) {
                    completions.add(name);
                }
            }
            return completions;
        } else if (args[0].equalsIgnoreCase("remove")) {
            List<String> completions = new ArrayList<String>();
            for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
                String name = player.getName();
                if (StringUtil.startsWithIgnoreCase(name, args[1])) {
                    completions.add(name);
                }
            }
            return completions;
        }
    }
    return ImmutableList.of();
}
Also used : ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList)

Aggregations

OfflinePlayer (org.bukkit.OfflinePlayer)55 Player (org.bukkit.entity.Player)21 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)10 Job (com.gamingmesh.jobs.container.Job)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 ArrayList (java.util.ArrayList)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 World (org.bukkit.World)4 CommandSender (org.bukkit.command.CommandSender)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 UUID (java.util.UUID)3 Location (org.bukkit.Location)3 JobProgression (com.gamingmesh.jobs.container.JobProgression)2 Island (com.wasteofplastic.acidisland.Island)2 List (java.util.List)2 Set (java.util.Set)2 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)2