當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。