Java Code Examples for org.bukkit.plugin.PluginManager#registerEvents()

The following examples show how to use org.bukkit.plugin.PluginManager#registerEvents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthMe.java    From AuthMeReloaded with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Registers all event listeners.
 *
 * @param injector the injector
 */
void registerEventListeners(Injector injector) {
    // Get the plugin manager instance
    PluginManager pluginManager = getServer().getPluginManager();

    // Register event listeners
    pluginManager.registerEvents(injector.getSingleton(PlayerListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(BlockListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(EntityListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(ServerListener.class), this);

    // Try to register 1.9 player listeners
    if (isClassLoaded("org.bukkit.event.player.PlayerSwapHandItemsEvent")) {
        pluginManager.registerEvents(injector.getSingleton(PlayerListener19.class), this);
    }

    // Try to register 1.9 spigot player listeners
    if (isClassLoaded("org.spigotmc.event.player.PlayerSpawnLocationEvent")) {
        pluginManager.registerEvents(injector.getSingleton(PlayerListener19Spigot.class), this);
    }

    // Register listener for 1.11 events if available
    if (isClassLoaded("org.bukkit.event.entity.EntityAirChangeEvent")) {
        pluginManager.registerEvents(injector.getSingleton(PlayerListener111.class), this);
    }
}
 
Example 2
Source File: PerWorldInventory.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
protected void registerEventListeners(Injector injector) {
    getLogger().info("Registering listeners...");

    PluginManager pluginManager = getServer().getPluginManager();

    pluginManager.registerEvents(injector.getSingleton(PluginListener.class), this);

    pluginManager.registerEvents(injector.getSingleton(PlayerTeleportListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(PlayerChangedWorldListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(PlayerDeathListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(PlayerGameModeChangeListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(PlayerQuitListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(EntityPortalEventListener.class), this);
    pluginManager.registerEvents(injector.getSingleton(InventoryLoadingListener.class), this);

    // The PlayerSpawnLocationEvent is only fired in Spigot
    // As of version 1.9.2
    if (Bukkit.getVersion().contains("Spigot") && Utils.checkServerVersion(Bukkit.getVersion(), 1, 9, 2)) {
        pluginManager.registerEvents(injector.getSingleton(PlayerSpawnLocationListener.class), this);
    }
    getLogger().info("Listeners registered!");
}
 
Example 3
Source File: KillMobs.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onStart() {
	/* Register a listener to watch for killed mobs. */
	final PluginManager pluginManager = CivCraft.getPlugin().getServer().getPluginManager();
	pluginManager.registerEvents(this, CivCraft.getPlugin());
	requireMobs = Integer.valueOf(this.getString("amount"));
	target = EntityType.valueOf(getString("what"));		
}
 
Example 4
Source File: VoxelGamesLib.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
private void registerListeners() {
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(injector.getInstance(GameListener.class), this);
    pm.registerEvents(injector.getInstance(SignListener.class), this);
    pm.registerEvents(injector.getInstance(UserListener.class), this);
    pm.registerEvents(injector.getInstance(ChatListener.class), this);
    pm.registerEvents(injector.getInstance(SignPlaceholders.class), this);
    pm.registerEvents(injector.getInstance(SignButtons.class), this);
    pm.registerEvents(injector.getInstance(CommandHandler.class), this);
    pm.registerEvents(injector.getInstance(StatListener.class), this);
}
 
Example 5
Source File: BukkitPartiesPlugin.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void registerListeners() {
	getLoggerManager().logDebug(Constants.DEBUG_PLUGIN_REGISTERING, true);
	PluginManager pm = ((Plugin) getBootstrap()).getServer().getPluginManager();
	pm.registerEvents(new BukkitChatListener(this), ((Plugin) getBootstrap()));
	pm.registerEvents(new BukkitExpListener(this), ((Plugin) getBootstrap()));
	pm.registerEvents(new BukkitFightListener(this), ((Plugin) getBootstrap()));
	pm.registerEvents(new BukkitFollowListener(this), ((Plugin) getBootstrap()));
	pm.registerEvents(new BukkitJoinLeaveListener(this), ((Plugin) getBootstrap()));
}
 
Example 6
Source File: uSkyBlock.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvents() {
    final PluginManager manager = getServer().getPluginManager();
    manager.registerEvents(new InternalEvents(this), this);
    manager.registerEvents(new PlayerEvents(this), this);
    manager.registerEvents(new MenuEvents(this), this);
    manager.registerEvents(new ExploitEvents(this), this);
    if (getConfig().getBoolean("options.protection.enabled", true)) {
        manager.registerEvents(new GriefEvents(this), this);
        if (getConfig().getBoolean("options.protection.item-drops", true)) {
            manager.registerEvents(new ItemDropEvents(this), this);
        }
    }
    if (getConfig().getBoolean("options.island.spawn-limits.enabled", true)) {
        manager.registerEvents(new SpawnEvents(this), this);
    }
    if (getConfig().getBoolean("options.protection.visitors.block-banned-entry", true)) {
        manager.registerEvents(new WorldGuardEvents(this), this);
    }
    if (Settings.nether_enabled) {
        manager.registerEvents(new NetherTerraFormEvents(this), this);
    }
    if (getConfig().getBoolean("tool-menu.enabled", true)) {
        manager.registerEvents(new ToolMenuEvents(this), this);
    }
    if (getConfig().getBoolean("signs.enabled", true)) {
        manager.registerEvents(new SignEvents(this, new SignLogic(this)), this);
    }
    PlaceholderHandler.register(this);
    manager.registerEvents(new ChatEvents(chatLogic, this), this);
}
 
Example 7
Source File: BlockBreak.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onStart() {
	/* Register a listener to watch for killed mobs. */
	final PluginManager pluginManager = CivCraft.getPlugin().getServer().getPluginManager();
	pluginManager.registerEvents(this, CivCraft.getPlugin());
	
}
 
Example 8
Source File: ObsidianDestroyer.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable() {
    instance = this;
    LOG = getLogger();

    // Initialize managers
    new ConfigManager(false);
    new HookManager();
    new MaterialManager();
    new ChunkManager();

    // Set command executor
    getCommand("od").setExecutor(new ODCommand());

    // Register Event listeners
    PluginManager pm = getServer().getPluginManager();

    pm.registerEvents(new EntityExplodeListener(), this);
    if (HookManager.getInstance().isHookedCannons()) {
        pm.registerEvents(new EntityImpactListener(), this);
    }
    pm.registerEvents(new PlayerListener(), this);
    pm.registerEvents(new BlockListener(), this);
    pm.registerEvents(new ObsidianDestroyerListener(), this);
    try {
        Class.forName("org.bukkit.event.block.BlockExplodeEvent");
        pm.registerEvents(new SpigotListener(), this);
    } catch (ClassNotFoundException e) {
        // YAY
    }
}
 
Example 9
Source File: CivCraft.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
private void registerEvents() {
	final PluginManager pluginManager = getServer().getPluginManager();
	pluginManager.registerEvents(new BlockListener(), this);
	pluginManager.registerEvents(new ChatListener(), this);
	pluginManager.registerEvents(new BonusGoodieManager(), this);
	pluginManager.registerEvents(new MarkerPlacementManager(), this);
	pluginManager.registerEvents(new CustomItemManager(), this);
	pluginManager.registerEvents(new PlayerListener(), this);		
	pluginManager.registerEvents(new DebugListener(), this);
	pluginManager.registerEvents(new LoreCraftableMaterialListener(), this);
	pluginManager.registerEvents(new LoreGuiItemListener(), this);
	pluginManager.registerEvents(new DisableXPListener(), this);
	pluginManager.registerEvents(new PvPLogger(), this);
	pluginManager.registerEvents(new TradeInventoryListener(), this);
	pluginManager.registerEvents(new MobListener(), this);
	pluginManager.registerEvents(new ArenaListener(), this);
	pluginManager.registerEvents(new CannonListener(), this);
	pluginManager.registerEvents(new WarListener(), this);
	pluginManager.registerEvents(new FishingListener(), this);	
	pluginManager.registerEvents(new PvPListener(), this);
	pluginManager.registerEvents(new LoreEnhancementArenaItem(), this);
	
	if (hasPlugin("TagAPI")) {
		pluginManager.registerEvents(new TagAPIListener(), this);
	}
	
	if (hasPlugin("HeroChat")) {
		pluginManager.registerEvents(new HeroChatListener(), this);
	}
}
 
Example 10
Source File: MobTagger.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable() {
    JavaPlugin plugin = getPlugin().getPlugin();
    PluginManager manager = Bukkit.getPluginManager();
    
    ListenerMobCombat listener = new ListenerMobCombat(this);
    manager.registerEvents(listener, plugin);
}
 
Example 11
Source File: CheatPrevention.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable() {
    PluginManager manager = Bukkit.getPluginManager();
    JavaPlugin plugin = getPlugin().getPlugin();

    // All Versions
    manager.registerEvents(new ListenerBlocks(this), plugin);
    manager.registerEvents(new ListenerChat(this), plugin);
    manager.registerEvents(new ListenerCommandBlocker(this), plugin);
    manager.registerEvents(new ListenerEntities(this), plugin);
    manager.registerEvents(new ListenerFlight(this), plugin);
    manager.registerEvents(new ListenerGameMode(this), plugin);
    manager.registerEvents(new ListenerInventories(this), plugin);
    manager.registerEvents(new ListenerPotions(this), plugin);
    manager.registerEvents(new ListenerTeleport(this), plugin);

    int minorVersion = VersionUtil.getMinorVersion();

    // 1.9+ Elytra
    if(minorVersion >= 9) manager.registerEvents(new ListenerElytra(this), plugin);

    // 1.11+ Totem of Undying
    if(minorVersion >= 11) manager.registerEvents(new ListenerTotemOfUndying(this), plugin);

    // 1.12+ PlayerPickupItemEvent --> EntityPickupItemEvent
    Listener itemPickupListener = minorVersion >= 12 ? new ListenerNewItemPickup(this) : new ListenerLegacyItemPickup(this);
    manager.registerEvents(itemPickupListener, plugin);

    // 1.13+ Riptide Enchantment
    if(minorVersion >= 13) manager.registerEvents(new ListenerRiptide(this), plugin);
    
    // Essentials Hook
    if(manager.isPluginEnabled("Essentials")) {
        ListenerEssentials listenerEssentials = new ListenerEssentials(this);
        manager.registerEvents(listenerEssentials, plugin);
    }
}
 
Example 12
Source File: ZombieEscape.java    From ZombieEscape with GNU General Public License v2.0 5 votes vote down vote up
private void registerListeners() {
    PluginManager pm = Bukkit.getPluginManager();
    pm.registerEvents(new EntityDamageByEntity(this), this);
    pm.registerEvents(new PlayerDeath(this), this);
    pm.registerEvents(new PlayerInteract(this), this);
    pm.registerEvents(new PlayerJoin(this), this);
    pm.registerEvents(new PlayerPickupItem(), this);
    pm.registerEvents(new PlayerQuit(this), this);

    pm.registerEvents(new ServerListener(this), this);
}
 
Example 13
Source File: Notifier.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable() {
    ICombatLogX combat = getPlugin();
    JavaPlugin plugin = combat.getPlugin();
    
    PluginManager manager = Bukkit.getPluginManager();
    manager.registerEvents(new ListenerNotifier(this), plugin);

    CommandNotifier commandNotifier = new CommandNotifier(this);
    combat.registerCommand("notifier", commandNotifier, "Toggle the boss bar, scoreboard, and action bar.", "/notifier bossbar/actionbar/scoreboard", "clx-toggle");

    hookIfEnabled("MVdWPlaceholderAPI");
    hookIfEnabled("PlaceholderAPI");
    hookIfEnabled("TitleManager");
}
 
Example 14
Source File: Rewards.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEnable() {
    PluginManager manager = Bukkit.getPluginManager();
    JavaPlugin plugin = getPlugin().getPlugin();
    manager.registerEvents(new ListenerRewards(this), plugin);
}
 
Example 15
Source File: Minepacks.java    From Minepacks with GNU General Public License v3.0 4 votes vote down vote up
private void load()
{
	updater.setChannel(config.getUpdateChannel());
	lang.load(config);
	database = Database.getDatabase(this);
	if(database == null)
	{
		new NoDatabaseWorker(this);
		return;
	}
	maxSize = config.getBackpackMaxSize();
	at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setShrinkApproach(config.getShrinkApproach());
	at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setTitle(config.getBPTitle(), config.getBPTitleOther());
	messageNotFromConsole  = lang.getMessage("NotFromConsole");
	messageNoPermission    = lang.getMessage("Ingame.NoPermission");
	messageInvalidBackpack = lang.getMessage("Ingame.InvalidBackpack");
	messageWorldDisabled   = lang.getMessage("Ingame.WorldDisabled");
	messageNotANumber      = lang.getMessage("Ingame.NaN");

	commandManager = new CommandManager(this);
	if(config.isInventoryManagementClearCommandEnabled()) inventoryClearCommand = new InventoryClearCommand(this);

	//region register events
	PluginManager pluginManager = getServer().getPluginManager();
	pluginManager.registerEvents(new BackpackEventListener(this), this);
	if(config.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
	if(config.isItemFilterEnabled())
	{
		itemFilter = new ItemFilter(this);
		pluginManager.registerEvents(itemFilter, this);
	}
	if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
	if(config.isItemShortcutEnabled())
	{
		shortcut = new ItemShortcut(this);
		pluginManager.registerEvents(shortcut, this);
	}
	else shortcut = null;
	if(config.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this);
	//endregion
	if(config.getFullInvCollect()) collector = new ItemsCollector(this);
	worldBlacklist = config.getWorldBlacklist();
	worldBlacklistMode = (worldBlacklist.size() == 0) ? WorldBlacklistMode.None : config.getWorldBlockMode();

	gameModes = config.getAllowedGameModes();
	if(config.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this);

	openSound = config.getOpenSound();
}
 
Example 16
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static void registerListeners(NoEntryExpansion expansion) {
    Listener listener = new Listener_V6_1(expansion);
    JavaPlugin plugin = expansion.getPlugin().getPlugin();
    PluginManager manager = Bukkit.getPluginManager();
    manager.registerEvents(listener, plugin);
}
 
Example 17
Source File: HookWorldGuard_V7_0.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static void registerListeners(NoEntryExpansion expansion) {
    Listener listener = new Listener_V7_0(expansion);
    JavaPlugin plugin = expansion.getPlugin().getPlugin();
    PluginManager manager = Bukkit.getPluginManager();
    manager.registerEvents(listener, plugin);
}
 
Example 18
Source File: HookWorldGuard_V6_2.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static void registerListeners(NoEntryExpansion expansion) {
    Listener listener = new Listener_V6_2(expansion);
    JavaPlugin plugin = expansion.getPlugin().getPlugin();
    PluginManager manager = Bukkit.getPluginManager();
    manager.registerEvents(listener, plugin);
}
 
Example 19
Source File: FunnyGuilds.java    From FunnyGuilds with Apache License 2.0 4 votes vote down vote up
@Override
public void onEnable() {
    funnyguilds = this;
    if (this.forceDisabling) {
        return;
    }

    this.dataModel = DataModel.create(this, this.pluginConfiguration.dataModel);
    this.dataModel.load();

    this.dataPersistenceHandler = new DataPersistenceHandler(this);
    this.dataPersistenceHandler.startHandler();

    this.invitationPersistenceHandler = new InvitationPersistenceHandler(this);
    this.invitationPersistenceHandler.loadInvitations();
    this.invitationPersistenceHandler.startHandler();

    MetricsCollector collector = new MetricsCollector(this);
    collector.start();

    this.guildValidationTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new GuildValidationHandler(), 100L, 20L);
    this.tablistBroadcastTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new TablistBroadcastHandler(), 20L, this.pluginConfiguration.playerListUpdateInterval_);
    this.rankRecalculationTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RankRecalculationTask(), 20L, this.pluginConfiguration.rankingUpdateInterval_);

    PluginManager pluginManager = Bukkit.getPluginManager();
    pluginManager.registerEvents(new GuiActionHandler(), this);
    pluginManager.registerEvents(new EntityDamage(), this);
    pluginManager.registerEvents(new EntityInteract(), this);
    pluginManager.registerEvents(new PlayerChat(), this);
    pluginManager.registerEvents(new PlayerDeath(), this);
    pluginManager.registerEvents(new PlayerJoin(this), this);
    pluginManager.registerEvents(new PlayerLogin(), this);
    pluginManager.registerEvents(new PlayerQuit(), this);
    pluginManager.registerEvents(new GuildHeartProtectionHandler(), this);

    this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled,
            new BlockBreak(),
            new BlockIgnite(),
            new BlockPlace(),
            new BucketAction(),
            new EntityExplode(),
            new HangingBreak(),
            new HangingPlace(),
            new PlayerCommand(),
            new PlayerInteract()
    );

    this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.eventMove, new PlayerMove());
    this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.eventPhysics, new BlockPhysics());
    this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.respawnInBase, new PlayerRespawn());
    this.dynamicListenerManager.reloadAll();
    this.patch();

    try {
        this.githubAPI = new GitHubBuilder().build();
    }
    catch (IOException ex) {
        this.getPluginLogger().debug("Could not initialize GitHub API!");
        this.getPluginLogger().debug(Throwables.getStackTraceAsString(ex));
    }

    FunnyGuildsVersion.isNewAvailable(this.getServer().getConsoleSender(), true);
    PluginHook.init();

    FunnyGuilds.getInstance().getPluginLogger().info("~ Created by FunnyGuilds Team ~");
}
 
Example 20
Source File: EchoPetPlugin.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
@SneakyThrows(IOException.class)
public void onEnable() {
    EchoPet.setPlugin(this);
    isUsingNetty = CommonReflection.isUsingNetty();

    this.configManager = new YAMLConfigManager(this);
    COMMAND_MANAGER = new CommandManager(this);
    // Make sure that the plugin is running under the correct version to prevent errors

    if (NmsVersion.current() == null || !INMS.isSupported()) {
        EchoPet.LOG.log(ChatColor.RED + "SonarPet " + ChatColor.GOLD
                + this.getDescription().getVersion() + ChatColor.RED
                + " is not compatible with this version of CraftBukkit");
        EchoPet.LOG.log(ChatColor.RED + "Initialisation failed. Please update the plugin.");

        DynamicPluginCommand cmd = new DynamicPluginCommand(this.cmdString, new String[0], "", "",
                new VersionIncompatibleCommand(this, this.cmdString, ChatColor.YELLOW +
                        "SonarPet " + ChatColor.GOLD + this.getDescription().getVersion() + ChatColor.YELLOW + " is not compatible with this version of CraftBukkit. Please update the plugin.",
                        "echopet.pet", ChatColor.YELLOW + "You are not allowed to do that."),
                null, this);
        COMMAND_MANAGER.register(cmd);
        return;
    }
    EntityRegistry entityRegistry;
    if (CitizensEntityRegistryHack.isNeeded()) {
        getLogger().warning("Attempting to inject citizens compatibility hack....");
        entityRegistry = CitizensEntityRegistryHack.createInstance();
        getLogger().warning("Successfully injected citizens compatibility hack!");
    } else {
        //noinspection deprecation // We check for citizens first ;)
        entityRegistry = INMS.getInstance().createDefaultEntityRegistry();
    }
    this.entityRegistry = Objects.requireNonNull(entityRegistry);

    this.loadConfiguration();

    PluginManager manager = getServer().getPluginManager();

    MANAGER = new PetManager();
    SQL_MANAGER = new SqlPetManager();

    if (OPTIONS.useSql()) {
        this.prepareSqlDatabase();
    }

    // Register custom commands
    // Command string based off the string defined in config.yml
    // By default, set to 'pet'
    // PetAdmin command draws from the original, with 'admin' on the end
    this.cmdString = OPTIONS.getCommandString();
    this.adminCmdString = OPTIONS.getCommandString() + "admin";
    DynamicPluginCommand petCmd = new DynamicPluginCommand(this.cmdString, new String[0], "Create and manage your own custom pets.", "Use /" + this.cmdString + " help to see the command list.", new PetCommand(this.cmdString), null, this);
    petCmd.setTabCompleter(new CommandComplete());
    COMMAND_MANAGER.register(petCmd);
    COMMAND_MANAGER.register(new DynamicPluginCommand(this.adminCmdString, new String[0], "Create and manage the pets of other players.", "Use /" + this.adminCmdString + " help to see the command list.", new PetAdminCommand(this.adminCmdString), null, this));

    // Initialize hook classes
    for (ClassPath.ClassInfo hookType : ClassPath.from(getClass().getClassLoader()).getTopLevelClasses("net.techcable.sonarpet.nms.entity.type")) {
        if (!hookType.load().isAnnotationPresent(EntityHook.class)) continue;
        for (EntityHookType type : hookType.load().getAnnotation(EntityHook.class).value()) {
            if (!type.isActive()) continue;
            hookRegistry.registerHookClass(type, hookType.load().asSubclass(IEntityPet.class));
        }
    }

    // Register listeners
    manager.registerEvents(new MenuListener(), this);
    manager.registerEvents(new PetEntityListener(this), this);
    manager.registerEvents(new PetOwnerListener(), this);
    if (VersionNotificationListener.isNeeded()) {
        manager.registerEvents(new VersionNotificationListener(), this);
        PluginVersioning.INSTANCE.sendOutdatedVersionNotification(Bukkit.getConsoleSender());
    }
    //manager.registerEvents(new ChunkListener(), this);

    this.vanishProvider = new VanishProvider(this);
    this.worldGuardProvider = new WorldGuardProvider(this);
}