当前位置: 首页>>代码示例>>Java>>正文


Java Listener类代码示例

本文整理汇总了Java中org.bukkit.event.Listener的典型用法代码示例。如果您正苦于以下问题:Java Listener类的具体用法?Java Listener怎么用?Java Listener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Listener类属于org.bukkit.event包,在下文中一共展示了Listener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerEvent

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
       Validate.notNull(listener, "Listener cannot be null");
       Validate.notNull(priority, "Priority cannot be null");
       Validate.notNull(executor, "Executor cannot be null");
       Validate.notNull(plugin, "Plugin cannot be null");

       if (!plugin.isEnabled()) {
           throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
       }

       if (useTimings) {
           getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
       } else {
           getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
       }
}
 
开发者ID:DevotedMC,项目名称:ExilePearl,代码行数:18,代码来源:TestPluginManager.java

示例2: execute

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
// 计算调用次数和花费总时间以及花费最多的时间
public void execute(Listener listener, Event e) throws EventException {
	if (e.isAsynchronous()) {
		this.eventExecutor.execute(listener, e);
	} else {
		long startTime = System.nanoTime();
		try {
			try{
				this.eventExecutor.execute(listener, e);
			}catch(Throwable ex){
				MonitorUtils.AExceptionCatcher(plugin, ex);
			}
		} finally {
			long endTime = System.nanoTime();
			long executeTime = endTime - startTime;
			if(ConfigFunction.MonitorPluginLagWarningenable){
				if(executeTime/1000000 > ConfigFunction.MonitorPluginLagWarningPeriod){
					AzureAPI.log("警告!服务器主线程陷入停顿超过配置设定值!因为插件" + this.getPlugin().getName() + " 执行了一次耗时 " + executeTime/1000000 + " 毫秒的位于 " + listener.getClass().getName() + " 的监听器 " + e.getEventName() + " 的操作!");
				}
			}
			this.record(e.getEventName(), executeTime);
		}
	}
}
 
开发者ID:GelandiAssociation,项目名称:EscapeLag,代码行数:26,代码来源:EventExecutorInjector.java

示例3: onEnable

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
protected void onEnable() {
    EventExecutor.getInstance().register(this);

    // load config
    this.config = Moo.getInstance().loadConfig(Lightning.getInstance().getDataFolder());
    this.languageManager = new LanguageManager(Lightning.getInstance().getDataFolder(),
            s -> ChatColor.translateAlternateColorCodes('&', s));
    this.languageManager.load("language");

    // if disabled stop enabling
    if(!((boolean) config.get("activated"))) {
        Lightning.getInstance().getLogs().info("*** Lightning disabled. ***");
        return;
    }

    // register handler
    Moo.getInstance().registerHandler(o -> {
        if(o instanceof Listener) Bukkit.getServer().getPluginManager().registerEvents((Listener) o, Lightning.getInstance());
    }, new ChatListener(), new ServerListener());

    // connect to cloud
    if(config.isLoaded()) {
        Moo.getInstance().connect(config.get("group-id"), ClientType.SERVER, config.get("cloud-ip"), config.get("cloud-port"));
    }
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:27,代码来源:LightningPluginModule.java

示例4: generateClass

import org.bukkit.event.Listener; //导入依赖的package包/类
public static Class<?> generateClass() throws NotFoundException, CannotCompileException {
    ClassPool classpath = ClassPool.getDefault();
    classpath.insertClassPath(new ClassClassPath(EventCallbackGenerator.class));
    CtClass eventClass = classpath.makeClass("online.pizzacrust.lukkitplus" +
            ".EventCallback");
    eventClass.addInterface(classpath.get(Listener.class.getName()));
    for (Class<? extends Event> event : LukkitPlus.BUKKIT_EVENTS) {
        if (containsStaticHandlerList(event)) {
            CtMethod eventMethod = CtNewMethod.make(CtClass.voidType, "on" + event.getSimpleName
                    (), new CtClass[]{classpath.get(event.getName())}, new CtClass[0], "online" +
                    ".pizzacrust.lukkitplus.EventCallbackGenerator.call($1);", eventClass);
            eventClass.addMethod(eventMethod);
            AnnotationsAttribute attribute = new AnnotationsAttribute(eventClass.getClassFile()
                    .getConstPool(), AnnotationsAttribute.visibleTag);
            Annotation eventHandlerAnnt = new Annotation(EventHandler.class.getName(), eventClass
                    .getClassFile().getConstPool());
            attribute.addAnnotation(eventHandlerAnnt);
            eventMethod.getMethodInfo().addAttribute(attribute);
        }
    }
    return eventClass.toClass(LukkitPlus.class.getClassLoader());
}
 
开发者ID:LukkitPlus,项目名称:Lukkit,代码行数:23,代码来源:EventCallbackGenerator.java

示例5: register

import org.bukkit.event.Listener; //导入依赖的package包/类
/**
 * Registers the given spell
 */
public void register(Spell spell) {
	spells.put(spell.getName(), spell);
	MystiCraft.getCraftingManager().addRecipe(spell.getRecipe());
	if (spell instanceof Listener) {
		MystiCraft.getInstance().getServer().getPluginManager().registerEvents((Listener) spell, MystiCraft.getInstance());
	}
	if (spell instanceof Configurable) {
		if (!spellConfig.getConfig().has(spell.getName())) {
			JsonObject obj = new JsonObject();
			((Configurable) spell).setDefaults(obj);
			spellConfig.getConfig().add(spell.getName(), obj);
			spellConfig.saveConfig();
			((Configurable) spell).load(obj);
		} else {
			((Configurable) spell).load(spellConfig.getConfig().get(spell.getName()).getAsJsonObject());
		}
	}
}
 
开发者ID:mcardy,项目名称:MystiCraft,代码行数:22,代码来源:SpellManager.java

示例6: callEvent

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
public void callEvent(Event event) throws IllegalStateException
{
	events.add(event);
	for (Listener listener : eventListeners.values())
	{
		for (Method method : listener.getClass().getMethods())
		{
			if (method.isAnnotationPresent(EventHandler.class) && method.getParameterCount() == 1
					&& method.getParameters()[0].getType().isInstance(event))
			{
				try
				{
					method.invoke(listener, event);
				}
				catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
				{
					throw new RuntimeException(e);
				}
			}
		}
	}
}
 
开发者ID:seeseemelk,项目名称:MockBukkit,代码行数:24,代码来源:PluginManagerMock.java

示例7: execute

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
// 计算调用次数和花费总时间以及花费最多的时间
public void execute(Listener listener, Event e) throws EventException {
	if (e.isAsynchronous()) {
		this.eventExecutor.execute(listener, e);
	} else {
		long startTime = System.nanoTime();
		try {
			this.eventExecutor.execute(listener, e);
		} finally {
			long endTime = System.nanoTime();
			long executeTime = endTime - startTime;
			this.record(e.getEventName(), executeTime);
		}
	}
}
 
开发者ID:jiongjionger,项目名称:NeverLag,代码行数:17,代码来源:EventExecutorInjector.java

示例8: unregister

import org.bukkit.event.Listener; //导入依赖的package包/类
public void unregister(@Nonnull Listener listener, @Nonnull Game game) {
    //noinspection unchecked
    Arrays.stream(listener.getClass().getMethods())
            .filter((method -> method.isAnnotationPresent(GameEvent.class)))
            .filter(method -> method.getParameterCount() != 1 || method.getParameterCount() != 2)
            .filter(method -> Event.class.isAssignableFrom(method.getParameterTypes()[0]))
            .map(method -> (Class<Event>) method.getParameterTypes()[0]).forEach(
            eventClass -> activeEvents.get(eventClass).removeIf(registeredListener -> registeredListener.getListener().equals(listener)));

    if (activeListeners.containsKey(game.getUuid())) {
        activeListeners.get(game.getUuid()).removeIf(registeredListener -> registeredListener.getListener().equals(listener));
        if (activeListeners.get(game.getUuid()).size() == 0) {
            activeListeners.remove(game.getUuid());
        }
    }

    HandlerList.unregisterAll(listener);
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:19,代码来源:EventHandler.java

示例9: listener

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
protected Listener listener(Consumer<Block> callback) {
    return new Listener() {
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
            Player clicker = event.getPlayer();
            EquipmentSlot hand = event.getHand();
            Block block = event.getClickedBlock();

            if (block != null && clicker.equals(player)
                    && (!MCUtils.isOffHandSupport() || hand == EquipmentSlot.HAND)) {
                clicker.sendMessage(MCUtils.colorize(messageFunc.apply(block)));
                callback.accept(block);
                event.setCancelled(true);
            }
        }
    };
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:19,代码来源:ClickWizard.java

示例10: init

import org.bukkit.event.Listener; //导入依赖的package包/类
public static void init(MCLibrary plugin) {
    Bukkit.getPluginManager().registerEvents(new Listener() {
        @EventHandler
        @SuppressWarnings("deprecation")
        public void onInteract(PlayerInteractEvent event) {
            if (MCUtils.isOffHandSupport() && event.getHand() != EquipmentSlot.HAND)
                return;

            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
            if (block == null || !INFO_LISTENERS.contains(player))
                return;

            Location loc = block.getLocation();
            CommandSenderWrapper wrapper = new CommandSenderWrapper(player);
            wrapper.sendMessage("---------------------------------------------");
            wrapper.sendMessage("&eworld: &f" + loc.getWorld().getName());
            wrapper.sendMessage(String.format("&ex: &f%s (%s)", loc.getBlockX(), loc.getX()));
            wrapper.sendMessage(String.format("&ey: &f%s (%s)", loc.getBlockY(), loc.getY()));
            wrapper.sendMessage(String.format("&ez: &f%s (%s)", loc.getBlockZ(), loc.getZ()));
            wrapper.sendMessage(String.format("&eblock: &f%s:%s (%s)", block.getTypeId(), block.getData(), block.getType().name()));
        }
    }, plugin);
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:25,代码来源:LibraryCommand.java

示例11: interactListener

import org.bukkit.event.Listener; //导入依赖的package包/类
public Listener interactListener() {
	return new Listener() {
		@EventHandler
		public void onInteract(PlayerInteractEvent e) {
			if (!(e.getPlayer().getEquipment().getItemInMainHand() == null)) { return; }
			if (!(e.getItem() == null)) { return; }
			if (!(e.getItem().getType() == null)) { return; }
			if (!(e.getItem().getType() == Material.AIR)) { return; }
			
			if (!e.getPlayer().getEquipment().getItemInMainHand().getItemMeta().getLore().contains(ChatColor.RED + getName())) { return; }
			if (!applicableTo().contains(e.getItem().getType())) { return; }
			
			if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
				getRun().run(e.getPlayer(), e.getClickedBlock());
			} else if (e.getAction() == Action.RIGHT_CLICK_AIR) {
				getRun().run(e.getPlayer(), null);
			}
		}
	};
}
 
开发者ID:crazyhorse961,项目名称:NationZ,代码行数:21,代码来源:Ability.java

示例12: register

import org.bukkit.event.Listener; //导入依赖的package包/类
@Override
	public void register(final Trigger trigger) {
//		if (types == null) {
//			final BlockLocation l = new BlockLocation(world, x, y, z);
//			List<Trigger> ts = blockTriggers.get(l);
//			if (ts == null)
//				blockTriggers.put(l, ts = new ArrayList<Trigger>());
//			ts.add(trigger);
//		} else {
		for (final ItemType t : types) {
			for (final ItemData d : t) {
				if (d.getId() > Skript.MAXBLOCKID)
					continue;
				List<Trigger> ts = itemTypeTriggers.get(d.getId());
				if (ts == null)
					itemTypeTriggers.put(d.getId(), ts = new ArrayList<Trigger>());
				ts.add(trigger);
			}
		}
//		}
		if (!registeredExecutor) {
			Bukkit.getPluginManager().registerEvent(PlayerMoveEvent.class, new Listener() {}, SkriptConfig.defaultEventPriority.value(), executor, Skript.getInstance(), true);
			registeredExecutor = true;
		}
	}
 
开发者ID:nfell2009,项目名称:Skript,代码行数:26,代码来源:EvtMoveOn.java

示例13: init

import org.bukkit.event.Listener; //导入依赖的package包/类
public static void init(JavaPlugin plugin) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        try {
            BufferedReader reader = URLs.IP_CHECKER.openBufferedReader();
            address = reader.readLine();
        } catch (IOException e) {
            // Ignore
        }
    });
    Bukkit.getPluginManager().registerEvents(new Listener() {
        @EventHandler
        public void onLogin(PlayerLoginEvent event) throws UnknownHostException {
            String host = event.getHostname();
            String addrStr = host.substring(0, host.indexOf(':'));
            InetAddress addr = InetAddress.getByName(addrStr);
            if (!addr.isLoopbackAddress() && !addr.isSiteLocalAddress()) {
                address = addrStr;
                event.getHandlers().unregister(this);
            }
        }
    }, plugin);
}
 
开发者ID:EntryPointKR,项目名称:K-Security,代码行数:23,代码来源:Static.java

示例14: registerEvent

import org.bukkit.event.Listener; //导入依赖的package包/类
/**
 * Registers the given event to the specified listener using a directly
 * passed EventExecutor
 *
 * @param event Event class to register
 * @param listener PlayerListener to register
 * @param priority Priority of this event
 * @param executor EventExecutor to register
 * @param plugin Plugin to register
 * @param ignoreCancelled Do not call executor if event was already
 *     cancelled
 */
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) {
    Validate.notNull(listener, "Listener cannot be null");
    Validate.notNull(priority, "Priority cannot be null");
    Validate.notNull(executor, "Executor cannot be null");
    Validate.notNull(plugin, "Plugin cannot be null");

    if (!plugin.isEnabled()) {
        throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
    }

    if (useTimings) {
        getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
    } else {
        getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
    }
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:29,代码来源:SimplePluginManager.java

示例15: load

import org.bukkit.event.Listener; //导入依赖的package包/类
public static void load(CSCoreLib plugin) {
	if (ReflectionUtils.getVersion().startsWith("v1_9_")) {
		plugin.getServer().getPluginManager().registerEvents(new CustomBookOverlay1_9(), plugin);
	}
	else if (ReflectionUtils.getVersion().startsWith("v1_10_")) {
		plugin.getServer().getPluginManager().registerEvents(new CustomBookOverlay1_9(), plugin);
	}
	else if (ReflectionUtils.getVersion().startsWith("v1_11_")) {
		plugin.getServer().getPluginManager().registerEvents(new CustomBookOverlay1_9(), plugin);
	}
	else if (ReflectionUtils.getVersion().startsWith("v1_12_")) {
		plugin.getServer().getPluginManager().registerEvents(new CustomBookOverlay1_9(), plugin);
	}

	plugin.getServer().getPluginManager().registerEvents(new Listener() {

		@EventHandler
		public void onDrop(PlayerDropItemEvent e) {
			if (opening.contains(e.getPlayer().getUniqueId())) e.setCancelled(true);
		}

	}, plugin);
}
 
开发者ID:TheBusyBiscuit,项目名称:CS-CoreLib,代码行数:24,代码来源:CustomBookOverlay.java


注:本文中的org.bukkit.event.Listener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。