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


Java EventHandler類代碼示例

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


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

示例1: onRegen

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onRegen(EntityRegainHealthEvent event) {
    if (event.getEntityType() != EntityType.PLAYER || event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) return;
    event.setCancelled(true);

    Player player = (Player) event.getEntity();
    long currentTime = System.currentTimeMillis() / 1000;

    if (currentTime - getLastHealTime(player) < 3)
        return;

    double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();

    if (player.getHealth() < maxHealth) {
        player.setHealth(clamp(player.getHealth() + 1, 0.0, maxHealth));
        healTimes.put(player.getUniqueId(), currentTime);
    }

    float exhToApply = (float) 3;

    Bukkit.getScheduler().runTaskLater(TGM.get(), () -> {
        //This is because bukkit doesn't stop the exhaustion change when cancelling the event
        player.setExhaustion(player.getExhaustion() + exhToApply);
        //debug("Exhaustion before: " + previousExh + " Now: " + p.getExhaustion() + "Saturation: " + p.getSaturation(), p);
    }, 1L);
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:27,代碼來源:RegenModule.java

示例2: onSpawn

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onSpawn(CreatureSpawnEvent event) {
	if (ConfigOptimize.NoCrowdedEntityenable) {
		Chunk chunk = event.getEntity().getLocation().getChunk();
		Entity[] entities = chunk.getEntities();

		for (Entity e : entities) {
			EntityType type = e.getType();
			int count = 0;
			if (ConfigOptimize.NoCrowdedEntityTypeList.contains("*")
					|| ConfigOptimize.NoCrowdedEntityTypeList.contains(type.name())) {
				count++;
				if (count > ConfigOptimize.NoCrowdedEntityPerChunkLimit && e.getType() != EntityType.PLAYER) {
					e.remove();
				}
			}
		}
	}
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:20,代碼來源:NoCrowdEntity.java

示例3: onChat

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onChat(AsyncPlayerChatEvent event){
    if(plugin.getConfig().getString("chatformat").equals("true")){
        Player player = event.getPlayer();
        String message = event.getMessage();
        event.setCancelled(true);
        String playerNameWithPrefixSuffix = player.getName() + ": ";
        try {
            playerNameWithPrefixSuffix = ChatColor.translateAlternateColorCodes('&', (!RankManager.getRankPrefix(player).equals(" ")?RankManager.getRankPrefix(player) : "") + RankManager.getRankNameColor(player) +" "+ player.getName() +(!RankManager.getRankSuffix(player).equals(" ")? " "+ RankManager.getRankSuffix(player) : "") + ChatColor.GRAY + ": ");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        for(Player p : event.getRecipients()){
            p.sendMessage(playerNameWithPrefixSuffix + ChatColor.WHITE + message);
        }
    }
}
 
開發者ID:Warvale,項目名稱:Ace,代碼行數:18,代碼來源:RankListener.java

示例4: onMove

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onMove(PlayerMoveEvent evt) {
    Player p = evt.getPlayer();
    Block b = p.getLocation().getBlock();
    if (isImmune(p) // Verify we should get an alert from this player.
            || Utils.isSameBlock(evt.getFrom(), evt.getTo()) // Check they've moved at least to the next block.
            || !checkNearby(b)) // Check if a block is nearby them.
        return;

    double yDif = evt.getTo().getY() - evt.getFrom().getY();
    double ascentMax = 0.8D;
    if (p.hasPotionEffect(PotionEffectType.JUMP))
        ascentMax += (double) p.getPotionEffect(PotionEffectType.JUMP).getAmplifier() / 10;

    detections.detect(new Detection(p),
            yDif == 0 && !checkNearby(evt.getFrom(), Material.WATER_LILY, Material.CARPET), // Hover.
            yDif > ascentMax, // If they sharply ascend.
            yDif == -.125D); // Glide (Unsure if this works.)
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:20,代碼來源:Flight.java

示例5: onBowShot

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onBowShot(EntityShootBowEvent e) {
    if (e.getEntity() instanceof Player &&
            e.getProjectile() instanceof Arrow) {
        Bukkit.getScheduler().runTaskLater(this, () -> {
            if (!e.getProjectile().isDead()) {
                EntityTrail t = new EntityTrail(this, e.getProjectile(),
                        new CircumferenceSupplier(particle, 1.2f, 0.9f, 0.0f, 1)
                        .rotateY(tick -> tick * (2.0f * (float) Math.PI / 20))
                        , 1);
                trails.put(e.getProjectile(), t);
                t.begin();
            }
        }, 5L);
    }
}
 
開發者ID:devcexx,項目名稱:libtrails,代碼行數:17,代碼來源:ColorfulExample.java

示例6: handleWoolCrafting

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void handleWoolCrafting(PrepareItemCraftEvent event) {
    ItemStack result = event.getRecipe().getResult();
    InventoryHolder holder = event.getInventory().getHolder();

    if (holder instanceof Player) {
        MatchPlayer playerHolder = this.match.getPlayer((Player) holder);

        if (playerHolder != null && result != null && result.getType() == Material.WOOL) {
            for(MonumentWool wool : this.wools) {
                if(wool.getDefinition().isObjectiveWool(result)) {
                    if(!wool.getDefinition().isCraftable()) {
                        playerHolder.sendMessage(ChatColor.RED + PGMTranslations.t("match.wool.craftDisabled", playerHolder, BukkitUtils.woolMessage(wool.getDyeColor())));
                        event.getInventory().setResult(null);
                    }
                }
            }
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:21,代碼來源:WoolMatchModule.java

示例7: onEntityDamageByEntity

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
        Player attacker = BukkitUtils.getFinalAttacker(event, true);
        if (attacker == null)
            return;

        long remaining;
        Player player = (Player) entity;
        if ((remaining = getRemaining(player)) > 0L) {
            event.setCancelled(true);
            attacker.sendMessage(ChatColor.RED + player.getName() + " has their " + getDisplayName() + ChatColor.RED + " timer for another " + ChatColor.BOLD
                    + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.');

            return;
        }

        if ((remaining = getRemaining(attacker)) > 0L) {
            event.setCancelled(true);
            attacker.sendMessage(ChatColor.RED + "You cannot attack players whilst your " + getDisplayName() + ChatColor.RED + " timer is active [" + ChatColor.BOLD
                    + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + " remaining]. Use '" + ChatColor.GOLD + PVP_COMMAND + ChatColor.RED + "' to allow pvp.");
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:InvincibilityTimer.java

示例8: onCommand

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onCommand(PlayerCommandPreprocessEvent event){
	if(event.getMessage().isEmpty()){
		event.setMessage("/help");
		return;
	}
	Command cmd = commandMap.get(event.getMessage().replaceFirst("/", "").split(" ")[0].toLowerCase());
	if(cmd == null){
		event.setMessage("/help");
		return;
	}
	if(!cmd.testPermissionSilent(event.getPlayer()))
		if(!(cmd instanceof LinkCommand)){
			event.setMessage("/help");
		}
}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:17,代碼來源:CPManager.java

示例9: playerLeave

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void playerLeave(PlayerQuitEvent event){
	event.setQuitMessage("");
	VPPlayer player = getPlayer(event.getPlayer());
	player.setMenu(null);
	VPPLeaveEvent e = new  VPPLeaveEvent(player);
	if(getMsgPerm().has(player))
		e.setMessage(leave);
	e.save(player.save());
	player.setOffline();
	Bukkit.getServer().getPluginManager().callEvent(e);
	//TODO send removed event
	if(e.getMessage() != null)
		e.getMessage().addSReplacement(PlaceH.SENDER.get(), player).send();
	if(e.save())
		save(player, false);
}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:18,代碼來源:PlayerManager.java

示例10: onPlayerMove

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
	final Player player = event.getPlayer();

	final Material from = event.getFrom().getBlock().getRelative(BlockFace.DOWN).getType();

	final Behaviour behaviour = Profile.getProfile(player.getUniqueId()).getBehaviour();

	final long current = System.currentTimeMillis();

	if (player.isSprinting()) {
		behaviour.getMotion().setLastSprint(current);
	}
	if (player.isFlying()) {
		behaviour.getMotion().setLastFly(current);
	}

	if (from.isSolid() || behaviour.getMotion().getLastY() == -1.0 || !behaviour.getMotion().isDescending()) {
		behaviour.getMotion().setLastY(player.getLocation().getY());
	}

	if (!behaviour.isOnGround()) {
		behaviour.getMotion().setLastYDiff(event.getTo().getY() - event.getFrom().getY());
	}
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:26,代碼來源:BehaviourListeners.java

示例11: onConsumeCake

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsumeCake(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
	{
		Block cake = event.getClickedBlock();
		if(cake.getType().equals(Material.CAKE_BLOCK))
		{
			if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE))
			{
				addStats(player, carbon, 171);
				addStats(player, protein, 114);
				addStats(player, salts, 3);
			}
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:20,代碼來源:FoodDiversityConsume.java

示例12: onClick

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler
public void onClick(PlayerInteractEvent e) {
	if (e.getAction() == Action.PHYSICAL)
		return;
	if (e.getPlayer().getItemInHand() == null)
		return;
	if (!e.getPlayer().getItemInHand().getType().equals(Material.COMPASS))
		return;
	if (!e.getPlayer().getItemInHand().hasItemMeta())
		return;
	if (!e.getPlayer().getItemInHand().getItemMeta().getDisplayName()
			.equalsIgnoreCase(ChatColor.RED + "Selecteer jouw kingdom"))
		return;
	setKindomMenu(PlayerModule.getInstance().getPlayer(e.getPlayer()));
	e.setCancelled(true);
}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:18,代碼來源:KingdomMenu.java

示例13: onPlayerMove

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
    if (this.cooldown.contains(event.getPlayer().getUniqueId()))
        return;

    this.cooldown.add(event.getPlayer().getUniqueId());

    this.hub.getServer().getScheduler().runTask(this.hub, () ->
    {
        this.cooldown.remove(event.getPlayer().getUniqueId());
        Parkour parkour = this.hub.getParkourManager().getPlayerParkour(event.getPlayer().getUniqueId());

        if (parkour != null && event.getTo().getBlockY() <= parkour.getMinimalHeight())
            parkour.failPlayer(event.getPlayer());
    });
}
 
開發者ID:SamaGames,項目名稱:Hub,代碼行數:18,代碼來源:ParkourListener.java

示例14: onWalkieTalkieInteract

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void onWalkieTalkieInteract(PlayerInteractEvent e) {
	if (e.getPlayer().getInventory().getItemInMainHand().getType() != Material.REDSTONE_COMPARATOR)
		return;
	if (e.getHand() == EquipmentSlot.OFF_HAND)
		return;

	WalkieTalkie wt = new WalkieTalkie(main,
			main.getPlayerManager().getPlayer(e.getPlayer()).getCurrentWalkieTalkieFrequency());

	// Left click to tune frequency.
	if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
		if (e.getPlayer().isSneaking()) {
			wt.decreaseFrequency(e.getPlayer());
		} else {
			wt.increaseFrequency(e.getPlayer());
		}
	}

}
 
開發者ID:kadeska,項目名稱:MT_Communication,代碼行數:21,代碼來源:WalkieTalkieListener.java

示例15: PlayerCommandPreprocessEvent

import org.bukkit.event.EventHandler; //導入依賴的package包/類
@EventHandler
public void PlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event){
	if(!Config.getConfig("jail.eventManager.command.enabled").equals("true"))return;
	if(event.getPlayer() == null && !(event.getPlayer() instanceof Player)) return;
	Player player = event.getPlayer();
	if(isJailPlayer(player)){
		String cmd = event.getMessage().split(" ")[0].replace("/", "");
		ArrayList<String> list = Config.getList("jail.eventManager.command.whiteList");
		if(list !=null){
			for(int i=0;i < list.size();){
				if(cmd.equalsIgnoreCase(list.get(i)))return;
				i++;
			}
		}
   		playerTeleportJail(player);
		event.setCancelled(true);
	}
}
 
開發者ID:Saukiya,項目名稱:PVPAsWantedManager,代碼行數:19,代碼來源:JailManager.java


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