org.bukkit.event.player.PlayerExpChangeEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerExpChangeEvent. 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: PlayerExpChangeListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onPlayerExpChange(PlayerExpChangeEvent event) {
    try {
        final Player player = event.getPlayer();
        final Location location = player.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        final User user = User.getUser(player);
        final Island island = user.getIsland();
        if (island == null) return;

        for (Mission mission : IridiumSkyblock.getMissions().missions) {
            final Map<String, Integer> levels = island.getMissionLevels();
            levels.putIfAbsent(mission.name, 1);

            final MissionData level = mission.levels.get(levels.get(mission.name));
            if (level.type == MissionType.EXPERIENCE)
                island.addMission(mission.name, event.getAmount());
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example #2
Source File: XPGainedListener.java    From Statz with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onXPGain(final PlayerExpChangeEvent event) {

    final PlayerStat stat = PlayerStat.XP_GAINED;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
            new XPGainedSpecification(player.getUniqueId(), event.getAmount(), player.getWorld().getName())
                    .constructQuery());

}
 
Example #3
Source File: ExpEarnTaskType.java    From Quests with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onExpEarn(PlayerExpChangeEvent e) {
    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(e.getPlayer().getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
    
    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
            
            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                
                if (taskProgress.isCompleted()) {
                    continue;
                }
                int amount = e.getAmount();
                int expNeeded = (int) task.getConfigValue("amount");
                
                int progressExp;
                if (taskProgress.getProgress() == null) {
                    progressExp = 0;
                } else {
                    progressExp = (int) taskProgress.getProgress();
                }
                
                taskProgress.setProgress(progressExp + amount);
                
                if (((int) taskProgress.getProgress()) >= expNeeded) {
                    taskProgress.setCompleted(true);
                }                    
            }
        }
    }        
}
 
Example #4
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onXpChange(PlayerExpChangeEvent event) {
	sendDurabilityBossBar(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand(),
			EquipmentSlot.HAND);
	sendDurabilityBossBar(event.getPlayer(), event.getPlayer().getInventory().getItemInOffHand(),
			EquipmentSlot.OFF_HAND);
}
 
Example #5
Source File: LootProtectListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
private static void giveExp(Player p, int amount) {
    if (amount <= 0) return;
    List<ItemStack> candidate = new ArrayList<>(13);

    for (ItemStack item : new ItemStack[]{
            p.getInventory().getHelmet(),
            p.getInventory().getChestplate(),
            p.getInventory().getLeggings(),
            p.getInventory().getBoots(),
            p.getInventory().getItemInMainHand(),
            p.getInventory().getItemInOffHand()}) {
        if (item != null && item.hasItemMeta() && item.getItemMeta().hasEnchant(Enchantment.MENDING)) {
            if (item.getType().getMaxDurability() > 0 && ((Damageable) item.getItemMeta()).getDamage() > 0) {
                candidate.add(item);
            }
        }
    }

    ItemStack repair = null;
    if (candidate.size() > 0) {
        candidate.sort(LootProtectListener::compareByDamagePercentage);
        repair = candidate.get(0);
    }

    if (repair != null) {
        Damageable itemMeta = (Damageable) repair.getItemMeta();
        int durability = itemMeta.getDamage();
        int repairPoint = durability;
        if (amount * 2 < repairPoint) repairPoint = amount * 2;
        int expConsumption = ((repairPoint % 2) == 1) ? (repairPoint + 1) / 2 : repairPoint / 2;
        itemMeta.setDamage(durability - repairPoint);
        repair.setItemMeta((ItemMeta) itemMeta);
        amount -= expConsumption;
    }

    if (amount > 0) p.giveExp(amount);
    PlayerExpChangeEvent event = new PlayerExpChangeEvent(p, amount);
    Bukkit.getServer().getPluginManager().callEvent(event);
}
 
Example #6
Source File: DisableXPListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerExpChange(PlayerExpChangeEvent event) {
	Resident resident = CivGlobal.getResident(event.getPlayer());
	CivMessage.send(resident, CivColor.LightGreen+"Picked up "+CivColor.Yellow+event.getAmount()+CivColor.LightGreen+" coins.");
	resident.getTreasury().deposit(event.getAmount());
	
	
	event.setAmount(0);
}
 
Example #7
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onExpGain(PlayerExpChangeEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("exp")) {
        Location l = event.getPlayer().getLocation().clone();
        l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("exp"));
        HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("exp"), true, Settings.INDICATOR_FORMAT.getValue("exp", "default") + "+" + event.getAmount() + " exp");
    }
}
 
Example #8
Source File: BonusXpSplitOnPickupListener.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void splitWithPartner(PlayerExpChangeEvent event, Player partner, double xp, Object o, MarriagePlayer player, Marriage marriage)
{
	int xpPlayer = (int) Math.round((xp)), xpPartner = (int) xp;
	BonusXPSplitEvent xpSplitEvent = new BonusXPSplitEvent(player, marriage, xpPlayer);
	Bukkit.getServer().getPluginManager().callEvent(xpSplitEvent);
	if(!xpSplitEvent.isCancelled())
	{
		event.setAmount(xpSplitEvent.getAmount());
		if(xpPartner > 0) partner.giveExp(xpPartner); // If the partner is near he/she must also be online
	}
}
 
Example #9
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onCivilianGainExp(PlayerExpChangeEvent event) {
    Civilian civilian = CivilianManager.getInstance().getCivilian(event.getPlayer().getUniqueId());
    civilian.setExpOrbs(event.getAmount());
}
 
Example #10
Source File: BonusXpSplitOnPickupListener.java    From MarriageMaster with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(PlayerExpChangeEvent event)
{
	calculator.process(event, event.getPlayer(), event.getAmount(), null);
}
 
Example #11
Source File: BonusXpSplitOnPickupListener.java    From MarriageMaster with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setEventExp(PlayerExpChangeEvent event, double xp, Object o, MarriagePlayer player, Marriage marriage) {}