Search in sources :

Example 11 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class CommandEffects method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        try {
            SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(player);
            if (spells == null)
                return true;
            if (args.length == 0) {
                player.sendMessage(ChatColor.GOLD + "Active Spell Effects on you:" + ChatColor.WHITE);
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                if (solplayer.getExperienceBonusExpires() != null) {
                    System.out.println("Experience Bonus was not null: " + solplayer.getExperienceBonusExpires().toString());
                    LocalDateTime datetime = LocalDateTime.now();
                    Timestamp nowtimestamp = Timestamp.valueOf(datetime);
                    Timestamp expiretimestamp = solplayer.getExperienceBonusExpires();
                    if (expiretimestamp != null) {
                        System.out.println("Experience Bonus expire timestamp " + solplayer.getExperienceBonusExpires() + " vs Now: " + nowtimestamp.toString());
                        if (!nowtimestamp.after(expiretimestamp)) {
                            System.out.println("Experience bonus was after, displaying in effects");
                            int secondsleft = (int) Math.floor(Utils.compareTwoTimeStamps(expiretimestamp, nowtimestamp));
                            TextComponent tc = new TextComponent();
                            tc.setText("- " + ChatColor.GREEN + "100% Experience Potion" + ChatColor.RESET + " " + secondsleft + " seconds");
                            sender.spigot().sendMessage(tc);
                        }
                    }
                } else {
                    System.out.println("Experience Bonus was null");
                }
                for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
                    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                    String removetext = "";
                    ChatColor spellcolor = ChatColor.GREEN;
                    if (spell.isBeneficial()) {
                        removetext = "/effects remove " + spell.getId();
                    } else {
                        removetext = "Unremovable spell";
                        spellcolor = ChatColor.RED;
                    }
                    TextComponent tc = new TextComponent();
                    tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
                    TextComponent tc2 = new TextComponent();
                    tc2.setText(removetext);
                    if (spell.isBeneficial()) {
                        tc2.setText(ChatColor.GRAY + "Click here to remove" + ChatColor.RESET);
                        tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, removetext));
                    }
                    tc.addExtra(tc2);
                    sender.spigot().sendMessage(tc);
                }
            } else {
                if (args.length < 2)
                    return true;
                int spellid = Integer.parseInt(args[1]);
                ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
                if (spell == null) {
                    player.sendMessage("That spell does not exist");
                    return true;
                }
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, player.getUniqueId(), spell.getId());
                if (!spell.isBeneficial()) {
                    player.sendMessage("Can only remove beneficial spells");
                    return true;
                }
                player.sendMessage("Spell Effect removed");
            }
        } catch (CoreStateInitException e) {
            player.sendMessage(e.getMessage());
        }
    }
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) Timestamp(java.sql.Timestamp) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 12 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class CommandListSpells method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        sender.sendMessage("You must provide some text to filter the spells by");
        return true;
    }
    // Filter for name
    int found = 0;
    try {
        for (ISoliniaSpell spell : StateManager.getInstance().getConfigurationManager().getSpells()) {
            found++;
            if (spell.getName().toUpperCase().contains(args[0].toUpperCase())) {
                String spellmessage = spell.getId() + " - " + spell.getName();
                sender.sendMessage(spellmessage);
            }
        }
        if (found == 0) {
            sender.sendMessage("Spell could not be located by search string");
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
        e.printStackTrace();
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 13 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class SoliniaActiveSpell method apply.

public void apply(Plugin plugin) {
    try {
        ISoliniaSpell soliniaSpell = StateManager.getInstance().getConfigurationManager().getSpell(getSpellId());
        if (soliniaSpell == null) {
            System.out.print("Spell not found");
            return;
        }
        Entity sourceEntity = Bukkit.getEntity(this.getSourceUuid());
        if (sourceEntity == null || (!(sourceEntity instanceof LivingEntity)))
            return;
        ISoliniaLivingEntity solsource = SoliniaLivingEntityAdapter.Adapt((LivingEntity) sourceEntity);
        if (solsource == null)
            return;
        if (isFirstRun) {
            if (soliniaSpell.getCastOnYou() != null && !soliniaSpell.getCastOnYou().equals("") && isOwnerPlayer) {
                Player player = Bukkit.getPlayer(getOwnerUuid());
                player.sendMessage("* " + ChatColor.GRAY + soliniaSpell.getCastOnYou());
            }
            if (soliniaSpell.getCastOnOther() != null && !soliniaSpell.getCastOnOther().equals(""))
                SoliniaLivingEntityAdapter.Adapt((LivingEntity) Bukkit.getEntity(getOwnerUuid())).emote(ChatColor.GRAY + "* " + this.getLivingEntity().getName() + soliniaSpell.getCastOnOther());
        }
        for (ActiveSpellEffect spellEffect : getActiveSpellEffects()) {
            applySpellEffect(plugin, spellEffect, soliniaSpell, isFirstRun, solsource.getLevel());
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 14 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class NPCSpellList method sendSettingsToSender.

public void sendSettingsToSender(CommandSender sender) {
    sender.sendMessage(ChatColor.RED + "NPC Spell List Settings for " + ChatColor.GOLD + getName() + ChatColor.RESET);
    sender.sendMessage("----------------------------");
    sender.sendMessage("- id: " + ChatColor.GOLD + getId() + ChatColor.RESET);
    sender.sendMessage("- name: " + ChatColor.GOLD + getName() + ChatColor.RESET);
    sender.sendMessage("----------------------------");
    sender.sendMessage(ChatColor.RED + "ENTRIES" + ChatColor.RESET);
    for (NPCSpellListEntry entry : this.getSpellListEntry()) {
        ISoliniaSpell spell = null;
        try {
            spell = StateManager.getInstance().getConfigurationManager().getSpell(entry.getSpellid());
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (spell != null) {
            sender.sendMessage("- entry.getId() " + ChatColor.GOLD + spell.getName() + " (" + entry.getSpellid() + ")" + ChatColor.RESET);
        }
    }
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 15 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class SoliniaPlayer method interact.

@Override
public void interact(Plugin plugin, PlayerInteractEvent event) {
    // TODO Auto-generated method stub
    ItemStack itemstack = event.getItem();
    try {
        // this is the item not in offhand
        if (event.getHand() == EquipmentSlot.HAND && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
            if (itemstack == null) {
                return;
            }
            if ((!Utils.IsSoliniaItem(itemstack)))
                return;
            // We have our custom item id, lets check it exists
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemstack);
            if (item == null) {
                return;
            }
            // Start applying an augmentation
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isAugmentation()) {
                if (StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getPlayer().getUniqueId()) == null || StateManager.getInstance().getPlayerManager().getApplyingAugmentation(event.getPlayer().getUniqueId()) == 0) {
                    StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getPlayer().getUniqueId(), item.getId());
                    event.getPlayer().sendMessage("* Applying " + item.getDisplayname() + " to an item, please right click the item you wish to apply this augmentation to. . To cancel applying, right click while holding this item again");
                } else {
                    StateManager.getInstance().getPlayerManager().setApplyingAugmentation(event.getPlayer().getUniqueId(), 0);
                    event.getPlayer().sendMessage("* Cancelled applying augmentation");
                }
                return;
            }
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isPetControlRod()) {
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), 50);
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, false);
                    return;
                }
            }
            if (item.getAbilityid() < 1) {
                return;
            }
            if (ItemStackUtils.isPotion(itemstack)) {
                // Handled by on consume event
                return;
            }
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getAbilityid());
            // Only applies to consumable items
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && item.isConsumable()) {
                if (itemstack.getAmount() > 1) {
                    event.getPlayer().sendMessage("Tried to use an entire stack at once! Cancelling, did you forget to split them?");
                    return;
                }
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), spell.getRange());
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, true);
                    event.getPlayer().setItemInHand(null);
                    event.getPlayer().updateInventory();
                    return;
                } else {
                    item.useItemOnEntity(plugin, event.getPlayer(), event.getPlayer(), true);
                    event.getPlayer().setItemInHand(null);
                    event.getPlayer().updateInventory();
                    return;
                }
            }
            // Only applies to non-consumable items
            if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && !item.isConsumable() && !itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                LivingEntity targetmob = Utils.getTargettedLivingEntity(event.getPlayer(), spell.getRange());
                if (targetmob != null) {
                    item.useItemOnEntity(plugin, event.getPlayer(), targetmob, true);
                    return;
                } else {
                    item.useItemOnEntity(plugin, event.getPlayer(), event.getPlayer(), true);
                    return;
                }
            }
            // Only applies to spell effects
            if (!itemstack.getType().equals(Material.ENCHANTED_BOOK)) {
                return;
            }
            // Reroute action depending on target
            if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                doCastSpellItem(plugin, spell, event.getPlayer(), item);
            }
        }
    } catch (CoreStateInitException e) {
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)20 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)16 Player (org.bukkit.entity.Player)8 ArrayList (java.util.ArrayList)7 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)4 SoliniaSpellClass (com.solinia.solinia.Models.SoliniaSpellClass)4 TextComponent (net.md_5.bungee.api.chat.TextComponent)4 LivingEntity (org.bukkit.entity.LivingEntity)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 Timestamp (java.sql.Timestamp)3 LocalDateTime (java.time.LocalDateTime)3 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)3 CommandSender (org.bukkit.command.CommandSender)3 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)3 ItemStack (org.bukkit.inventory.ItemStack)3 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)2 SoliniaActiveSpell (com.solinia.solinia.Models.SoliniaActiveSpell)2 SoliniaEntitySpells (com.solinia.solinia.Models.SoliniaEntitySpells)2 DecimalFormat (java.text.DecimalFormat)2