Search in sources :

Example 11 with Item

use of net.minecraft.server.v1_15_R1.Item in project solinia3-core by mixxit.

the class SoliniaSpell method isValidEffectForEntity.

public static Tuple<Boolean, String> isValidEffectForEntity(LivingEntity target, LivingEntity source, ISoliniaSpell soliniaSpell) throws CoreStateInitException {
    try {
        if (source == null) {
            System.out.println("Source was null for isValidEffectForEntity: " + soliniaSpell.getName() + " on target: " + target.getCustomName());
            return new Tuple<Boolean, String>(false, "Source was null for spell");
        }
        if (target == null) {
            System.out.println("Target was null for isValidEffectForEntity: " + soliniaSpell.getName() + " from source: " + source.getCustomName());
            return new Tuple<Boolean, String>(false, "Target was null for spell");
        }
        if (source.isDead() || target.isDead())
            return new Tuple<Boolean, String>(false, "Source or target is dead");
        ISoliniaLivingEntity solTarget = SoliniaLivingEntityAdapter.Adapt(target);
        if (solTarget != null) {
            switch(SpellUtils.getSpellTargetType(soliniaSpell.getTargettype())) {
                case SummonedAE:
                    if (!solTarget.isUndead()) {
                        return new Tuple<Boolean, String>(false, "Only affects undead");
                    }
                    break;
                case UndeadAE:
                    if (!solTarget.isUndead()) {
                        return new Tuple<Boolean, String>(false, "Only affects undead");
                    }
                    break;
                case Undead:
                    if (!solTarget.isUndead()) {
                        source.sendMessage("This spell is only effective on Undead");
                        return new Tuple<Boolean, String>(false, "Only affects undead");
                    }
                    break;
                case Summoned:
                    if (!solTarget.isCurrentlyNPCPet() && !solTarget.isCharmed()) {
                        source.sendMessage("This spell is only effective on Summoned");
                        return new Tuple<Boolean, String>(false, "Only affects summoned");
                    }
                    break;
                case Animal:
                    if (!solTarget.isAnimal()) {
                        source.sendMessage("This spell is only effective on Animals");
                        return new Tuple<Boolean, String>(false, "Only affects animals");
                    }
                    break;
                case Plant:
                    if (!solTarget.isPlant()) {
                        source.sendMessage("This spell is only effective on Plants");
                        return new Tuple<Boolean, String>(false, "Only affects plants");
                    }
                    break;
                default:
                    break;
            }
        }
        ISoliniaLivingEntity solSource = SoliniaLivingEntityAdapter.Adapt(source);
        if (solTarget.isNPC()) {
            if (source instanceof Player || solSource.isCurrentlyNPCPet()) {
                ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(solTarget.getNpcid());
                if (npc != null) {
                    if (npc.isBoss() || npc.isRaidboss())
                        if (!soliniaSpell.isBossApplyable()) {
                            source.sendMessage(ChatColor.RED + "This NPC is immune to runspeed, gravity and mezmersization changes");
                            return new Tuple<Boolean, String>(false, "Immune to runspeed/gravity/mez");
                        }
                    if (npc.isRaidheroic())
                        if (!soliniaSpell.isRaidApplyable()) {
                            source.sendMessage(ChatColor.RED + "This NPC is immune to runspeed, gravity and mezmersization changes");
                            return new Tuple<Boolean, String>(false, "Immune to runspeed/gravity/mez");
                        }
                }
            }
        }
        if (!solSource.isNPC() && solTarget.isImmuneToSpell(soliniaSpell)) {
            source.sendMessage(ChatColor.RED + "Your target cannot be affected (with this spell) [Spell has maxlevel or effect already]");
            return new Tuple<Boolean, String>(false, "Target is (currently) immune to spell - Spell maxlevel limit,haseffect etc..");
        }
        // Always allow self only spells if the target and source is the self
        if (source.getUniqueId().equals(target.getUniqueId()) && SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
            // just be sure to check the item its giving if its an item spell
            for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
                if (effect.getSpellEffectType().equals(SpellEffectType.SummonHorse)) {
                    if (source instanceof Player) {
                        if (source.getUniqueId().equals(target.getUniqueId())) {
                            if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(source.getUniqueId()) != null) {
                                source.sendMessage("You can only summon a mount once per server session. Please wait for the next 4 hourly restart");
                                return new Tuple<Boolean, String>(false, "Cannot summon mount this soon");
                            }
                        } else {
                            return new Tuple<Boolean, String>(false, "Source was not target");
                        }
                    } else {
                        return new Tuple<Boolean, String>(false, "Source wasnt player");
                    }
                }
                if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
                    int itemId = effect.getBase();
                    try {
                        ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                        if (item == null) {
                            return new Tuple<Boolean, String>(false, "Item was null");
                        }
                        if (!item.isTemporary() && !soliniaSpell.isIgnoreSummonItemTemporaryCheck()) {
                            return new Tuple<Boolean, String>(false, "Item wasnt temporary");
                        }
                        if (!(target instanceof LivingEntity)) {
                            return new Tuple<Boolean, String>(false, "Targert wasnt living");
                        }
                    } catch (CoreStateInitException e) {
                        return new Tuple<Boolean, String>(false, "Plugin wasnt initialised");
                    }
                }
            }
            // "), returning as valid, always");
            return new Tuple<Boolean, String>(true, "Self only spell");
        }
        if (!source.getUniqueId().equals(target.getUniqueId()))
            if (!solSource.isPlayer()) {
                if (!solSource.checkLosFN(solTarget, true))
                    return new Tuple<Boolean, String>(false, "Target not in line of sight of source");
            } else {
                // we dont care about directional for players
                if (!solSource.checkLosFN(solTarget, false))
                    return new Tuple<Boolean, String>(false, "Target not in line of sight of source");
            }
        // Try not to kill potentially friendly player tameables with hostile spells
        if (solTarget.isCurrentlyNPCPet() && target instanceof Creature && !soliniaSpell.isBeneficial()) {
            if (soliniaSpell.isCharmSpell() && source.getUniqueId().equals(solTarget.getOwnerEntity().getUniqueId())) {
                // Our owner wants to renew his charm
                return new Tuple<Boolean, String>(true, "Charm spell and source is target");
            } else {
                Creature cr = (Creature) target;
                if (cr.getTarget() == null)
                    return new Tuple<Boolean, String>(false, "Target is null");
                if (!cr.getTarget().getUniqueId().equals(source.getUniqueId()))
                    return new Tuple<Boolean, String>(false, "Target is not the source");
            }
        }
        for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
            // and the spell is a detrimental
            if (source instanceof Player && target instanceof Player && soliniaSpell.isDetrimental()) {
                ISoliniaPlayer solsourceplayer = SoliniaPlayerAdapter.Adapt((Player) source);
                if (solsourceplayer.getGroup() != null) {
                    if (solsourceplayer.getGroup().getUnmodifiableGroupMembersForBuffs(true, false).contains(target.getUniqueId())) {
                        return new Tuple<Boolean, String>(false, "Detrimental against group member");
                    }
                }
            }
            // Return false if the target is in the same faction as the npc and not self
            if (!(source instanceof Player) && !(target instanceof Player) && soliniaSpell.isDetrimental() && !source.getUniqueId().equals(target.getUniqueId())) {
                if (source instanceof LivingEntity && target instanceof LivingEntity) {
                    ISoliniaLivingEntity solsourceEntity = SoliniaLivingEntityAdapter.Adapt(source);
                    ISoliniaLivingEntity soltargetEntity = SoliniaLivingEntityAdapter.Adapt(target);
                    if (solsourceEntity.isNPC() && soltargetEntity.isNPC()) {
                        ISoliniaNPC sourceNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                        ISoliniaNPC targetNpc = StateManager.getInstance().getConfigurationManager().getNPC(soltargetEntity.getNpcid());
                        if (sourceNpc.getFactionid() > 0 && targetNpc.getFactionid() > 0) {
                            if (sourceNpc.getFactionid() == targetNpc.getFactionid())
                                return new Tuple<Boolean, String>(false, "Faction is same");
                        }
                    }
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.Revive)) {
                if (!(target instanceof Player)) {
                    return new Tuple<Boolean, String>(false, "Target is not player");
                }
                if (!(source instanceof Player))
                    return new Tuple<Boolean, String>(false, "Source is not player");
                Player sourcePlayer = (Player) source;
                if (!sourcePlayer.getInventory().getItemInOffHand().getType().equals(Material.NAME_TAG)) {
                    sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (MC): " + sourcePlayer.getInventory().getItemInOffHand().getType().name());
                    return new Tuple<Boolean, String>(false, "Not holding item in offhand");
                }
                ItemStack item = sourcePlayer.getInventory().getItemInOffHand();
                if (item.getEnchantmentLevel(Enchantment.DURABILITY) != 1) {
                    sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (EC)");
                    return new Tuple<Boolean, String>(false, "Not holding item in offhand");
                }
                if (!item.getItemMeta().getDisplayName().equals("Signaculum")) {
                    sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (NC)");
                    return new Tuple<Boolean, String>(false, "Not holding item in offhand");
                }
                if (item.getItemMeta().getLore().size() < 5) {
                    sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (LC)");
                    return new Tuple<Boolean, String>(false, "Not holding item in offhand");
                }
                String sigdataholder = item.getItemMeta().getLore().get(3);
                String[] sigdata = sigdataholder.split("\\|");
                if (sigdata.length != 2) {
                    sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (SD)");
                    return new Tuple<Boolean, String>(false, "Not holding item in offhand");
                }
                String str_experience = sigdata[0];
                String str_stimetsamp = sigdata[1];
                int experience = Integer.parseInt(str_experience);
                Timestamp timestamp = Timestamp.valueOf(str_stimetsamp);
                LocalDateTime datetime = LocalDateTime.now();
                Timestamp currenttimestamp = Timestamp.valueOf(datetime);
                long maxminutes = 60 * 7;
                if ((currenttimestamp.getTime() - timestamp.getTime()) >= maxminutes * 60 * 1000) {
                    sourcePlayer.sendMessage("This Signaculum has lost its binding to the soul");
                    return new Tuple<Boolean, String>(false, "Expired signaculum");
                }
                String characterId = item.getItemMeta().getLore().get(4);
                try {
                    ISoliniaPlayer soliniaPlayer = StateManager.getInstance().getConfigurationManager().getCharacterById(Integer.parseInt(characterId));
                    if (soliniaPlayer == null) {
                        sourcePlayer.sendMessage("You cannot resurrect that player as this character no longer exists");
                        return new Tuple<Boolean, String>(false, "Character no longer exists");
                    }
                    Player targetplayer = Bukkit.getPlayer(soliniaPlayer.getOwnerUUID());
                    if (targetplayer == null || !targetplayer.isOnline()) {
                        sourcePlayer.sendMessage("You cannot resurrect that player as they are offline");
                        return new Tuple<Boolean, String>(false, "Offline player");
                    }
                } catch (NumberFormatException e) {
                    sourcePlayer.sendMessage("This signaculum has been corrupted by the void");
                    return new Tuple<Boolean, String>(false, "Character identifier is corrupted");
                }
            }
            // Validate spelleffecttype rules
            if (effect.getSpellEffectType().equals(SpellEffectType.CurrentHP) || effect.getSpellEffectType().equals(SpellEffectType.CurrentHPOnce)) {
                // Ignore this rule if the spell is self
                if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1)) {
                    // If the effect is negative standard nuke and on self, cancel out
                    if (effect.getBase() < 0 && target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target was self");
                }
                // cancel
                if (source instanceof Player) {
                    if (!(target instanceof Player)) {
                        ISoliniaLivingEntity soltargetentity = SoliniaLivingEntityAdapter.Adapt(target);
                        if (!soltargetentity.isCurrentlyNPCPet()) {
                            if (effect.getBase() > 0)
                                return new Tuple<Boolean, String>(false, "Target wasnt a pet npc");
                        }
                    }
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.Illusion) || effect.getSpellEffectType().equals(SpellEffectType.IllusionaryTarget) || effect.getSpellEffectType().equals(SpellEffectType.IllusionCopy) || effect.getSpellEffectType().equals(SpellEffectType.IllusionOther) || effect.getSpellEffectType().equals(SpellEffectType.IllusionPersistence)) {
                // if target has spell effect of above already then we cant apply another
                for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(target).getActiveSpells()) {
                    if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Illusion))
                        return new Tuple<Boolean, String>(false, "Contained illusion");
                    if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionaryTarget))
                        return new Tuple<Boolean, String>(false, "Contained illusion target");
                    if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionCopy))
                        return new Tuple<Boolean, String>(false, "Contained illusion copy");
                    if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionOther))
                        return new Tuple<Boolean, String>(false, "Contained illusion other");
                    if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionPersistence))
                        return new Tuple<Boolean, String>(false, "Contained illusion persistence");
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                int itemId = effect.getBase();
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                    System.out.println("Validating SummonItem for source: " + source.getCustomName());
                    if (item == null) {
                        System.out.println("Validating SummonItem said item was null");
                        return new Tuple<Boolean, String>(false, "Item didnt exist");
                    }
                    if (!item.isTemporary()) {
                        System.out.println("Validating SummonItem said item was not temporary");
                        return new Tuple<Boolean, String>(false, "Item was not temporary");
                    }
                    if (!(target instanceof LivingEntity)) {
                        System.out.println("Validating SummonItem said target was not a living entity");
                        return new Tuple<Boolean, String>(false, "Target not living");
                    }
                } catch (CoreStateInitException e) {
                    return new Tuple<Boolean, String>(false, "Plugin not initialised");
                }
            }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.ResistAll) || effect.getSpellEffectType().equals(SpellEffectType.ResistCold) || effect.getSpellEffectType().equals(SpellEffectType.ResistFire) || effect.getSpellEffectType().equals(SpellEffectType.ResistMagic) || effect.getSpellEffectType().equals(SpellEffectType.ResistPoison) || effect.getSpellEffectType().equals(SpellEffectType.ResistDisease) || effect.getSpellEffectType().equals(SpellEffectType.ResistCorruption)) {
                    // If the effect is negative standard resist debuffer and on self, cancel out
                    if (effect.getBase() < 0 && target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.Mez)) {
                    // If the effect is a mez, cancel out
                    if (target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (effect.getSpellEffectType().equals(SpellEffectType.Charm)) {
                if (target instanceof Player)
                    return new Tuple<Boolean, String>(false, "Target of spell is player");
            }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.Charm)) {
                    // If the effect is a charm, cancel out
                    if (target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.Stun)) {
                    // If the effect is a stun, cancel out
                    if (target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.Root)) {
                    // If the effect is a root, cancel out
                    if (target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (!SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AECaster) && !SpellUtils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.AEClientV1))
                if (effect.getSpellEffectType().equals(SpellEffectType.Blind)) {
                    // If the effect is a blindness, cancel out
                    if (target.equals(source))
                        return new Tuple<Boolean, String>(false, "Target of spell is source");
                }
            if (effect.getSpellEffectType().equals(SpellEffectType.DamageShield) && !(target instanceof Player) && !SoliniaLivingEntityAdapter.Adapt(target).isCurrentlyNPCPet()) {
                // If the effect is a mez, cancel out
                if (target.equals(source))
                    return new Tuple<Boolean, String>(false, "Target of spell is source");
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.NecPet) || effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
                // If the effect is teleport and the target is not a player then fail
                if (!(target instanceof Player))
                    return new Tuple<Boolean, String>(false, "Target of spell not a player");
                if (!(source instanceof Player))
                    return new Tuple<Boolean, String>(false, "Source of spell not a player");
                // fail
                if (effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
                    // if target is not the player casting
                    if (!target.getUniqueId().equals(source.getUniqueId())) {
                        ISoliniaPlayer solplayertarget = SoliniaPlayerAdapter.Adapt((Player) target);
                        if (solplayertarget == null)
                            return new Tuple<Boolean, String>(false, "Target not found");
                        if (solplayertarget.getGroup() == null)
                            return new Tuple<Boolean, String>(false, "Group not found");
                        if (!(solplayertarget.getGroup().getUnmodifiableGroupMembersForBuffs(false, false).contains(source.getUniqueId())))
                            return new Tuple<Boolean, String>(false, "Group member not found");
                    }
                }
                if (effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.NecPet)) {
                    try {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(soliniaSpell.getTeleportZone());
                        if (npc == null) {
                            return new Tuple<Boolean, String>(false, "NPC not found for pet");
                        }
                        if (npc.isCorePet() == false) {
                            System.out.print("NPC " + soliniaSpell.getTeleportZone() + " is not defined as a pet");
                            return new Tuple<Boolean, String>(false, "Pet is not defined on spell");
                        }
                    } catch (CoreStateInitException e) {
                        return new Tuple<Boolean, String>(false, "Plugin not initialised");
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return new Tuple<Boolean, String>(false, "Exception: " + e.getStackTrace() + " " + e.getMessage());
    }
    return new Tuple<Boolean, String>(true, "");
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Creature(org.bukkit.entity.Creature) Timestamp(java.sql.Timestamp) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) Tuple(net.minecraft.server.v1_15_R1.Tuple)

Example 12 with Item

use of net.minecraft.server.v1_15_R1.Item in project solinia3-core by mixxit.

the class ItemStackAdapter method generateSpellLoreText.

private static List<String> generateSpellLoreText(ISoliniaItem soliniaItem) {
    List<String> loreTxt = new ArrayList<String>();
    ISoliniaSpell spell;
    try {
        spell = StateManager.getInstance().getConfigurationManager().getSpell(soliniaItem.getAbilityid());
        if (spell.getEffectid1() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid1()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid1()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue1() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid1()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue1() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid1()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid2() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid2()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid2()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue2() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid2()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue2() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid2()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid3() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid3()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid3()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue3() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid3()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue3() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid3()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid4() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid4()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid4()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue4() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid4()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue4() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid4()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid5() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid5()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid5()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue5() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid5()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue5() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid5()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid6() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid6()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid6()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue6() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid6()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue6() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid6()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid7() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid7()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid7()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue7() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid7()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue7() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid7()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid8() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid8()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid8()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue8() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid8()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue8() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid8()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid9() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid9()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid9()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue9() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid9()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue9() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid9()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid10() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid10()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid10()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue10() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid10()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue10() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid10()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid11() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid11()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid11()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue11() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid11()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue11() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid11()).name() + ChatColor.RESET);
        }
        if (spell.getEffectid12() != 254 && !SpellUtils.getSpellEffectType(spell.getEffectid12()).name().contains("LIMIT_") && !(SpellUtils.getSpellEffectType(spell.getEffectid12()).equals(SpellEffectType.CHA) && spell.getEffectBaseValue12() == 0) && !SpellUtils.getSpellEffectType(spell.getEffectid12()).name().contains("StackingCommand_")) {
            String pos = "+";
            if (spell.getEffectBaseValue12() < 0)
                pos = "-";
            loreTxt.add(ChatColor.WHITE + "Effect: " + ChatColor.YELLOW + pos + SpellUtils.getSpellEffectType(spell.getEffectid12()).name() + ChatColor.RESET);
        }
        if (!spell.isBardSong()) {
            if (spell.getComponents1() > 0) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(spell.getComponents1());
                if (item != null && item.isReagent()) {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + item.getDisplayname() + " x " + spell.getComponentCounts1() + ChatColor.RESET);
                } else {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + "ERROR-ALERT-ADMIN-SPELL" + spell.getId() + "-ID" + spell.getComponents1());
                }
            }
            if (spell.getComponents2() > 0) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(spell.getComponents2());
                if (item != null && item.isReagent()) {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + item.getDisplayname() + " x " + spell.getComponentCounts2() + ChatColor.RESET);
                } else {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + "ERROR-ALERT-ADMIN-SPELL" + spell.getId() + "-ID" + spell.getComponents2());
                }
            }
            if (spell.getComponents3() > 0) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(spell.getComponents3());
                if (item != null && item.isReagent()) {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + item.getDisplayname() + " x " + spell.getComponentCounts3() + ChatColor.RESET);
                } else {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + "ERROR-ALERT-ADMIN-SPELL" + spell.getId() + "-ID" + spell.getComponents3());
                }
            }
            if (spell.getComponents4() > 0) {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(spell.getComponents4());
                if (item != null && item.isReagent()) {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + item.getDisplayname() + " x " + spell.getComponentCounts4() + ChatColor.RESET);
                } else {
                    loreTxt.add(ChatColor.WHITE + "Requires Component: " + ChatColor.YELLOW + "ERROR-ALERT-ADMIN-SPELL" + spell.getId() + "-ID" + spell.getComponents4());
                }
            }
        }
        loreTxt.add(ChatColor.WHITE + "Mana/Power: " + ChatColor.YELLOW + spell.getMana() + ChatColor.RESET);
        loreTxt.add(ChatColor.WHITE + "Spell Skill: " + ChatColor.YELLOW + SkillUtils.getSkillType(spell.getSkill()).name().toUpperCase() + ChatColor.RESET);
        loreTxt.add(ChatColor.WHITE + "Range: " + ChatColor.YELLOW + spell.getRange() + ChatColor.RESET);
        loreTxt.add(ChatColor.WHITE + "Casting Time: " + ChatColor.YELLOW + (spell.getCastTime() / 1000) + " seconds" + ChatColor.RESET);
        if (spell.isAASpell()) {
            loreTxt.add(ChatColor.WHITE + "This spell is an AA spell" + ChatColor.RESET);
        }
        if (spell.isBuffSpell() && spell.getBuffduration() > 0) {
            loreTxt.add(ChatColor.WHITE + "Buff Duration: " + ChatColor.YELLOW + (spell.getBuffduration() * 6) + " seconds" + ChatColor.RESET);
        }
        loreTxt.add(ChatColor.WHITE + "Target Type: " + ChatColor.YELLOW + SpellUtils.getSpellTargetType(spell.getTargettype()).name() + ChatColor.RESET);
        List<String> classInfo = generateClassesText(spell);
        if (classInfo.size() > 0)
            loreTxt.addAll(classInfo);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return loreTxt;
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) NBTTagString(net.minecraft.server.v1_15_R1.NBTTagString)

Example 13 with Item

use of net.minecraft.server.v1_15_R1.Item in project powerbot by powerbot.

the class DrawItems method repaint.

public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    render.setFont(new Font("Arial", 0, 10));
    render.setColor(Color.green);
    if (ctx.bank.opened()) {
        final Component container = ctx.widgets.component(Constants.BANK_WIDGET, Constants.BANK_ITEMS);
        final Rectangle r = container.viewportRect();
        if (r != null) {
            for (final Item item : ctx.bank.select()) {
                final Component c = item.component();
                if (c == null) {
                    continue;
                }
                final Rectangle r2 = c.boundingRect();
                if (r2 == null) {
                    continue;
                }
                if (c.relativePoint().y == 0 || !r.contains(r2)) {
                    continue;
                }
                final Point p = c.screenPoint();
                render.drawString(c.itemId() + "", p.x, p.y + c.height());
            }
        }
    }
    if (ctx.backpack.component().visible()) {
        for (final Item item : ctx.backpack.select()) {
            final Component c = item.component();
            if (c == null) {
                continue;
            }
            final Point p = c.screenPoint();
            render.drawString(c.itemId() + "", p.x, p.y + c.height());
        }
    }
    if (ctx.equipment.component().visible()) {
        for (final Item item : ctx.equipment.select()) {
            if (item == null) {
                continue;
            }
            final Component c = item.component();
            if (c == null) {
                continue;
            }
            final Point p = c.screenPoint();
            render.drawString(c.itemId() + "", p.x, p.y + c.height());
        }
    }
}
Also used : Item(org.powerbot.script.rt6.Item) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Component(org.powerbot.script.rt6.Component) Font(java.awt.Font)

Example 14 with Item

use of net.minecraft.server.v1_15_R1.Item in project powerbot by powerbot.

the class TicketDestroy method poll.

@Override
public void poll() {
    if (ctx.properties.getProperty("key.token.disable", "").equals("true")) {
        // TODO: review this random event
        return;
    }
    final Item item = ctx.backpack.select().id(Constants.TICKETDESTROY_ITEMS).poll();
    if (!item.valid() || !ctx.hud.opened(Hud.Window.BACKPACK) || !ctx.players.local().idle()) {
        priority.set(0);
        return;
    }
    priority.set(3);
    if (!ctx.backpack.scroll(item)) {
        return;
    }
    if (((ctx.varpbits.varpbit(1448) & 0xFF00) >>> 8) < (item.id() == Constants.TICKETDESTROY_ITEMS[0] ? 10 : 9)) {
        item.interact("Claim");
        return;
    }
    if (!item.interact("Destroy")) {
        return;
    }
    final Widget widget = ctx.widgets.widget(1183);
    if (!Condition.wait(new Condition.Check() {

        @Override
        public boolean poll() {
            return widget.valid();
        }
    })) {
        return;
    }
    Component component = null;
    for (final Component c : widget.components()) {
        if (c.visible() && c.tooltip().trim().equalsIgnoreCase("destroy")) {
            component = c;
            break;
        }
    }
    if (component != null && component.interact("Destroy")) {
        Condition.wait(new Condition.Check() {

            @Override
            public boolean poll() {
                return item.component().itemId() == -1;
            }
        }, 175);
    }
}
Also used : Condition(org.powerbot.script.Condition) Item(org.powerbot.script.rt6.Item) Widget(org.powerbot.script.rt6.Widget) Component(org.powerbot.script.rt6.Component)

Example 15 with Item

use of net.minecraft.server.v1_15_R1.Item in project CokesAddon by Cokes86.

the class v1_15_R1 method injectPlayer.

public void injectPlayer(Player player) {
    CraftPlayer player1 = (CraftPlayer) player;
    if (!player.isValid())
        return;
    if (channelHandlers.containsKey(player.getUniqueId())) {
        final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
        if (!pair.getLeft().isValid()) {
            try {
                pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
            } catch (NoSuchElementException ignored) {
            }
        } else
            return;
    }
    final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
            if (packet instanceof PacketPlayOutEntityEquipment) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
                }
            } else if (packet instanceof PacketPlayOutEntityMetadata) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
                    if (items.size() != 0) {
                        Item<?> item = items.get(0);
                        if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
                            Item<Byte> byteItem = (Item<Byte>) item;
                            byteItem.a((byte) (byteItem.b() | 1 << 5));
                            ((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
                        }
                    }
                }
            }
            super.write(ctx, packet, promise);
        }
    };
    channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
    player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
Also used : Item(net.minecraft.server.v1_15_R1.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)12 ItemStack (org.bukkit.inventory.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)8 Field (java.lang.reflect.Field)7 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 ArrayList (java.util.ArrayList)5 Item (net.minecraft.server.v1_12_R1.Item)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 Font (java.awt.Font)2 Point (java.awt.Point)2 Timestamp (java.sql.Timestamp)2 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.server.v1_12_R1.Block)2