// Select a single drop from the `df-dragon-drops` loot set.
// TODO: actually, multiple drops should be supported, once
// BeastMaster supports deferred item drops.
protected void onDragonDeath(EnderDragon dragon) {
        log("The dragon died.");
        if (_stageNumber != 11) {
            log("But we're not in stage 11, so it doesn't count.");
            return;
        }
        if (DragonFight.CONFIG.FIGHT_OWNER == null) {
            log("But nobody owns the fight, so it doesn't count.");
            return;
        }
        // Bukkit.getOfflinePlayer() NEVER returns null, even for non-existent.
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(DragonFight.CONFIG.FIGHT_OWNER);
        getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.LIGHT_PURPLE + offlinePlayer.getName() +
                                                      ChatColor.DARK_PURPLE + " was awarded the prize for defeating the dragon."));
        Player player = offlinePlayer.getPlayer();
        if (player == null) {
            // Fight owner is offline. Record an unclaimed prize.
            log("An unclaimed prize was added to offline fight owner " + offlinePlayer.getName() + ".");
            getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.DARK_PURPLE + "They can claim it when they log in."));
            DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
        } else {
            // Select a single drop from the `df-dragon-drops` loot set.
            // TODO: actually, multiple drops should be supported, once
            // BeastMaster supports deferred item drops.
            log("Generating dragon prizes for " + player.getName());
            List<ItemStack> prizes = generatePrizes();
            if (!givePrizes(player, prizes)) {
                // The item(s) did not fit, so player must claim with command.
                DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
                String slots = ChatColor.LIGHT_PURPLE + Integer.toString(prizes.size()) +
                               ChatColor.DARK_PURPLE + " inventory slot" + (prizes.size() > 1 ? "s" : "");
                player.sendMessage(ChatColor.DARK_PURPLE + "You need at least " + slots + " empty.");
                player.sendMessage(ChatColor.DARK_PURPLE + "Run " +
                                   ChatColor.LIGHT_PURPLE + "/dragon prize" +
                                   ChatColor.DARK_PURPLE + " to claim your prize.");
            }
        }
        // Clear the fight owner once prizes have been given or unclaimed prizes
        // recorded, to prevent extra prizes if spurious dragons spawn.
        DragonFight.CONFIG.FIGHT_OWNER = null;
        DragonFight.CONFIG.save();
    }
DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
} else {
// Select a single drop from the `df-dragon-drops` loot set.
// TODO: actually, multiple drops should be supported, once
// BeastMaster supports deferred item drops.
log("Generating dragon prizes for " + player.getName());
List<ItemStack> prizes = generatePrizes();
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(DragonFight.CONFIG.FIGHT_OWNER);
getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.LIGHT_PURPLE + offlinePlayer.getName() +
ChatColor.DARK_PURPLE + " was awarded the prize for defeating the dragon."));
Player player = offlinePlayer.getPlayer();
if (player == null) {
// Fight owner is offline. Record an unclaimed prize.
log("An unclaimed prize was added to offline fight owner " + offlinePlayer.getName() + ".");
getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.DARK_PURPLE + "They can claim it when they log in."));
DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
} else {
// Select a single drop from the `df-dragon-drops` loot set.
// TODO: actually, multiple drops should be supported, once
// BeastMaster supports deferred item drops.
log("Generating dragon prizes for " + player.getName());
List<ItemStack> prizes = generatePrizes();
if (!givePrizes(player, prizes)) {
// The item(s) did not fit, so player must claim with command.
DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
String slots = ChatColor.LIGHT_PURPLE + Integer.toString(prizes.size()) +
ChatColor.DARK_PURPLE + " inventory slot" + (prizes.size() > 1 ? "s" : "");
player.sendMessage(ChatColor.DARK_PURPLE + "You need at least " + slots + " empty.");
player.sendMessage(ChatColor.DARK_PURPLE + "Run " +
ChatColor.LIGHT_PURPLE + "/dragon prize" +
log("The dragon died.");
if (_stageNumber != 11) {
log("But we're not in stage 11, so it doesn't count.");
return;
}
if (DragonFight.CONFIG.FIGHT_OWNER == null) {
log("But nobody owns the fight, so it doesn't count.");
return;
}
// Bukkit.getOfflinePlayer() NEVER returns null, even for non-existent.
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(DragonFight.CONFIG.FIGHT_OWNER);
getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.LIGHT_PURPLE + offlinePlayer.getName() +
ChatColor.DARK_PURPLE + " was awarded the prize for defeating the dragon."));
Player player = offlinePlayer.getPlayer();
if (player == null) {
// Fight owner is offline. Record an unclaimed prize.
log("An unclaimed prize was added to offline fight owner " + offlinePlayer.getName() + ".");
getNearbyPlayers().forEach(p -> p.sendMessage(ChatColor.DARK_PURPLE + "They can claim it when they log in."));
DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
} else {
// Select a single drop from the `df-dragon-drops` loot set.
// TODO: actually, multiple drops should be supported, once
// BeastMaster supports deferred item drops.
log("Generating dragon prizes for " + player.getName());
List<ItemStack> prizes = generatePrizes();
if (!givePrizes(player, prizes)) {
// The item(s) did not fit, so player must claim with command.
DragonFight.CONFIG.incUnclaimedPrizes(offlinePlayer.getUniqueId(), 1);
String slots = ChatColor.LIGHT_PURPLE + Integer.toString(prizes.size()) +
ChatColor.DARK_PURPLE + " inventory slot" + (prizes.size() > 1 ? "s" : "");
player.sendMessage(ChatColor.DARK_PURPLE + "You need at least " + slots + " empty.");
player.sendMessage(ChatColor.DARK_PURPLE + "Run " +
ChatColor.LIGHT_PURPLE + "/dragon prize" +
ChatColor.DARK_PURPLE + " to claim your prize.");
}
}
// Clear the fight owner once prizes have been given or unclaimed prizes
// recorded, to prevent extra prizes if spurious dragons spawn.
DragonFight.CONFIG.FIGHT_OWNER = null;
DragonFight.CONFIG.save();
}