Example usage for net.minecraftforge.common UsernameCache containsUUID

List of usage examples for net.minecraftforge.common UsernameCache containsUUID

Introduction

In this page you can find the example usage for net.minecraftforge.common UsernameCache containsUUID.

Prototype

public static boolean containsUUID(UUID uuid) 

Source Link

Document

Check if the cache contains the given player's username

Usage

From source file:vazkii.botania.common.item.relic.ItemRelic.java

License:Open Source License

public void updateRelic(ItemStack stack, EntityPlayer player) {
    if (stack == null || !(stack.getItem() instanceof IRelic))
        return;/*from w  ww .  ja v a 2s.c o m*/

    boolean rightPlayer = true;
    if (hasUUID(stack)) {
        // Sync to username todo is this worth 'optimizing'?
        if (UsernameCache.containsUUID(getSoulbindUUID(stack))) {
            bindToUsername(UsernameCache.getLastKnownUsername(getSoulbindUUID(stack)), stack);
        } else {
            bindToUsername("", stack);
        }

        // UUID trumps username
        rightPlayer = getSoulbindUUID(stack).equals(player.getUniqueID());
    } else {
        if ("".equals(getSoulbindUsername(stack))) {
            // New user
            bindToUUID(player.getUniqueID(), stack);
            player.addStat(((IRelic) stack.getItem()).getBindAchievement(), 1);
        } else {
            if (player.getName().equals(getSoulbindUsername(stack))) {
                // Old relic, correct owner, convert to UUID
                bindToUUID(player.getUniqueID(), stack);
            } else {
                // Old relic, wrong owner, damage
                rightPlayer = false;
            }
        }
    }

    if (!rightPlayer && player.ticksExisted % 10 == 0 && (!(stack.getItem() instanceof ItemRelic)
            || ((ItemRelic) stack.getItem()).shouldDamageWrongPlayer()))
        player.attackEntityFrom(damageSource(), 2);
}