當前位置: 首頁>>代碼示例>>Java>>正文


Java Listener類代碼示例

本文整理匯總了Java中org.spongepowered.api.event.Listener的典型用法代碼示例。如果您正苦於以下問題:Java Listener類的具體用法?Java Listener怎麽用?Java Listener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Listener類屬於org.spongepowered.api.event包,在下文中一共展示了Listener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onReload

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onReload(GameReloadEvent event)
{
    try
    {
        MessageReceiver src = event.getCause().first(CommandSource.class).orElse(Sponge.getServer().getConsole());
        src.sendMessage(this.translation.take("virtualchest.reload.start"));
        this.loadConfig();
        this.saveConfig();
        src.sendMessage(this.translation.take("virtualchest.reload.finish"));
    }
    catch (IOException e)
    {
        throw Throwables.propagate(e);
    }
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:17,代碼來源:VirtualChestPlugin.java

示例2: onStartedServer

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onStartedServer(GameStartedServerEvent event)
{
    try
    {
        this.logger.info("Start loading config ...");
        this.loadConfig();
        if (this.doCheckUpdate)
        {
            new Thread(this::checkUpdate).start();
        }
        this.saveConfig();
        this.logger.info("Loading config complete.");
    }
    catch (IOException e)
    {
        throw Throwables.propagate(e);
    }
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:20,代碼來源:VirtualChestPlugin.java

示例3: onPlayerDeath

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event)
{
    if(event.getTargetEntity() instanceof Player)
    {
        Player player = (Player)event.getTargetEntity();

        PowerService.decreasePower(player.getUniqueId());

        player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Your power has been decreased by ", TextColors.GOLD, String.valueOf(MainLogic.getPowerDecrement()) + "\n",
                TextColors.GRAY, "Current power: ", String.valueOf(PowerService.getPlayerPower(player.getUniqueId())) + "/" + String.valueOf(PowerService.getPlayerMaxPower(player.getUniqueId()))));

        PlayerService.setPlayerChunkPosition(player.getUniqueId(), null);

        return;
    }
    else return;
}
 
開發者ID:Aquerr,項目名稱:EagleFactions,代碼行數:19,代碼來源:PlayerDeathListener.java

示例4: onPlayerJoin

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event, @Root Player player) {
	Date now = new Date(java.util.Date.from(Instant.now()).getTime());
	UserData userData = dataStore.getOrCreateUserData(player);

	int index[] = new int[1];
	dataStore.getPlayerRegions(player.getUniqueId()).forEach(region -> {
		if (region.getType() == LoadedRegion.ChunkType.PERSONAL)
			region.forceChunks();
		index[0]++;
	});

	logger.info(String.format("Loaded %s chunks for %s", index[0], player.getName()));

	// Update the userData in case it's an existing userData
	dataStore.getOrCreateUserData(player).setLastSeen(now).update();

	database.saveUserData(userData);
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:20,代碼來源:PlayerConnectionListener.java

示例5: onPlayerLeave

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onPlayerLeave(ClientConnectionEvent.Disconnect event, @Root Player player) {
	Date now = new Date(java.util.Date.from(Instant.now()).getTime());
	UserData userData = dataStore.getOrCreateUserData(player);

	int index[] = new int[1];
	index[0] = 0;
	dataStore.getPlayerRegions(player.getUniqueId()).forEach(region -> {
		if (region.getType() == LoadedRegion.ChunkType.PERSONAL) {
			region.unForceChunks();
			index[0]++;
		}
	});

	logger.info(String.format("Unloaded %s chunks for %s", index[0], player.getName()));

	// Update the userData in case it's an existing userData
	dataStore.getOrCreateUserData(player).setLastSeen(now).update();
	database.saveUserData(userData);
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:21,代碼來源:PlayerConnectionListener.java

示例6: onPostInitEvent

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onPostInitEvent(GamePostInitializationEvent event)
{
    printUnformattedMessage("========================= P I X E L U P G R A D E =========================");
    printUnformattedMessage("--> §aChecking whether an economy plugin is present...");

    Optional<EconomyService> potentialEconomyService = Sponge.getServiceManager().provide(EconomyService.class);
    if (!potentialEconomyService.isPresent())
        printUnformattedMessage("--> §eNo economy plugin was found. Proceeding with integration disabled.");
    else
    {
        printUnformattedMessage("--> §aAn economy plugin was detected. Enabling integration!");
        economyEnabled = true;
        economyService = potentialEconomyService.get();
    }

    printUnformattedMessage("--> §aAll systems nominal.");
    printUnformattedMessage("===========================================================================");
}
 
開發者ID:xPXpanD,項目名稱:PixelUpgrade,代碼行數:20,代碼來源:PixelUpgrade.java

示例7: gameStarted

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void gameStarted(GameStartedServerEvent event){

    if(forceStop) {
        return;
    }

    HuskyCommandManager huskyCommandManager = new HuskyCommandManager();

    scheduler = Sponge.getScheduler();
    //genericCause = Cause.of(EventContext.);
    Sponge.getCommandManager().register(this, huskyCommandManager.getCrateSpec(), "hc","huskycrates");
    Sponge.getCommandManager().register(this, huskyCommandManager.getHuskySpec(), "husky");
    metrics.addCustomChart(new Metrics.SimplePie("huskyui_version", () -> HuskyUI.PLUGIN_VERSION));
    logger.info("Crates has been started.");
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:17,代碼來源:HuskyCrates.java

示例8: onLiquidFlow

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
	if (e.getLocations().isEmpty()) return;
			
	Location<World> loc = e.getLocations().get(0);
	BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
	
	Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
	if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
		String name = "Water";
		BlockType type = snapshot.getState().getType();
		if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
			name = "Lava";
		db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
	}
}
 
開發者ID:Karanum,項目名稱:AdamantineShield,代碼行數:17,代碼來源:LiquidFlowListener.java

示例9: onServerStart

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onServerStart(GameStartedServerEvent event) {
	instance = this;
	
	ConfigBuilder.configPath = Paths.get(configDir.toString(), "config.json");
	
	RText.impl(new RTextSponge());
	RColour.impl(new RColourSponge());
	Travellers.impl(new SpongeTravellers());
	
	CommandSpec camCommandSpec = CommandSpec.builder()
			.arguments(GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("cmd"))))
			.executor(new SpongeCommandManager())
			.build();

	Sponge.getCommandManager().register(this, camCommandSpec, "cam", "camerastudio");
}
 
開發者ID:redstone,項目名稱:RCameraStudio,代碼行數:18,代碼來源:RCameraStudioSponge.java

示例10: onServerStart

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onServerStart(GameStartingServerEvent event) {
    Sponge.getCommandManager().register(this, CommandSpec.builder()
            .description(Text.of("Gets info on the user."))
            .arguments(flags()
                    .permissionFlag("whois.all", ALL, "-all")
                    .permissionFlag("whois.address", IP, "-ip")
                    .flag(FIRST, "-firstjoined")
                    .flag(LAST, "-lastjoined")
                    .flag(WORLD, "-world")
                    .flag(COORDINATES, "-coords")
                    .flag(GAMEMODE, "-gamemode")
                    .flag(BAN, "-ban")
                    .buildWith(optional(user(KEY_USER))))
            .permission("whois.command")
            .executor(this::whois)
            .build(), "whois");

}
 
開發者ID:killjoy1221,項目名稱:WhoIs,代碼行數:20,代碼來源:Whois.java

示例11: onBlockPrimaryInteract

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onBlockPrimaryInteract(InteractBlockEvent.Primary.MainHand e, @First Player p) {
	if (!plugin.getInspectManager().isInspector(p))
		return;
	
	e.setCancelled(true);
	BlockSnapshot block = e.getTargetBlock();
	if (block == null || !block.getLocation().isPresent())
		return;
	
	Location<World> loc = block.getLocation().get();
	
	p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
	Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
		plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
}
 
開發者ID:Karanum,項目名稱:AdamantineShield,代碼行數:17,代碼來源:PlayerInspectListener.java

示例12: onMessageChannelChat

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener(order = Order.LATE)
public void onMessageChannelChat(MessageChannelEvent.Chat event) {
    if (event.isCancelled()) {
        return;
    }

    Optional<Player> playerOpt = event.getCause().first(Player.class);
    if (!playerOpt.isPresent()) {
        return;
    }
    Player player = playerOpt.get();

    ClanPlayerImpl clanPlayer = ClansImpl.getInstance().getClanPlayer(player.getUniqueId());
    if (clanPlayer != null && clanPlayer.getClan() != null) {
        PlayerChatState chatState = clanPlayer.getChatState();
        PlayerChatState tempChatState = clanPlayer.getTempChatState();

        if (tempChatState == null) {
            handleChat(player, clanPlayer, chatState, event);
        } else {
            handleChat(player, clanPlayer, tempChatState, event);
            clanPlayer.setTempChatState(null);
        }
    }
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:26,代碼來源:PlayerChatListener.java

示例13: onDamageEntity

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener(order = Order.LATE)
public void onDamageEntity(DamageEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Optional<Player> damagerOpt = event.getCause().first(Player.class);
    if (!damagerOpt.isPresent()) {
        return;
    }

    Player victim = (Player) event.getTargetEntity();
    Player damager = damagerOpt.get();

    ClanPlayerImpl victimClanPlayer = ClansImpl.getInstance().getClanPlayer(victim.getUniqueId());

    if (victimClanPlayer == null) {
        victimClanPlayer = ClansImpl.getInstance().createClanPlayer(victim.getUniqueId(), victim.getName());
    }

    victimClanPlayer.setLastPlayerDamage(damager.getUniqueId());
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:25,代碼來源:UpdateLastPlayerDamageListener.java

示例14: onPlayerJoin

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event, @Root Player player) {
    if (!player.hasPermission("iplog.bypasslogging")) {
        final Storage storage = IPLog.getPlugin().getStorage();

        final InetAddress ip = player.getConnection().getAddress().getAddress();
        final UUID uuid = player.getUniqueId();
        final LocalDateTime time = LocalDateTime.now();

        if (storage.isPresent(ip, uuid)) {
            storage.updateConnection(ip, uuid, time);
        } else {
            storage.addConnection(ip, uuid, time);
        }
    }
}
 
開發者ID:ichorpowered,項目名稱:iplog,代碼行數:17,代碼來源:JoinListener.java

示例15: onChangeBlockEvent

import org.spongepowered.api.event.Listener; //導入依賴的package包/類
@Listener
public void onChangeBlockEvent(ChangeBlockEvent.Break e, @First Player player) {
    if (plugin.getMainConfig().isUseSigns()) {
        if (player.hasPermission("minecraftmarket.signs")) {
            if (e.getTransactions().size() > 0) {
                BlockSnapshot blockSnapshot = e.getTransactions().get(0).getOriginal();
                Optional<Location<World>> optionalLocation = blockSnapshot.getLocation();
                if (optionalLocation.isPresent()) {
                    if (plugin.getSignsConfig().getDonorSignFor(optionalLocation.get()) != null) {
                        if (plugin.getSignsConfig().removeDonorSign(optionalLocation.get())) {
                            player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_removed")));
                            plugin.getSignsTask().updateSigns();
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:MinecraftMarket,項目名稱:MinecraftMarket-Plugin,代碼行數:20,代碼來源:SignsListener.java


注:本文中的org.spongepowered.api.event.Listener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。