Search in sources :

Example 51 with ISoliniaPlayer

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

the class PlayerInventoryValidatorTimer method validatePlayerItems.

private void validatePlayerItems(Player player) {
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        List<Integer> slots = new ArrayList<Integer>();
        slots.add(36);
        slots.add(37);
        slots.add(38);
        slots.add(39);
        slots.add(40);
        for (int slotId = 0; slotId < 36; slotId++) {
            if (player.getInventory().getItem(slotId) == null)
                continue;
            try {
                ISoliniaItem i = SoliniaItemAdapter.Adapt(player.getInventory().getItem(slotId));
                if (i.isTemporary()) {
                    boolean foundFadedItem = false;
                    for (String loreLine : player.getInventory().getItem(slotId).getItemMeta().getLore()) {
                        if (!loreLine.startsWith("Temporary: "))
                            continue;
                        if (!loreLine.equals("Temporary: " + StateManager.getInstance().getInstanceGuid())) {
                            // Delete temporary item
                            player.sendMessage("Your temporary item has faded from existence");
                            player.getInventory().setItem(slotId, null);
                            player.updateInventory();
                            break;
                        }
                    }
                    if (foundFadedItem)
                        continue;
                }
                // Only monitor the defined slots
                if (!slots.contains(slotId))
                    continue;
                if (i.getMinLevel() > solplayer.getLevel()) {
                    player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
                    player.getInventory().setItem(slotId, null);
                    player.updateInventory();
                    player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
                    continue;
                }
                if (i.getAllowedClassNames().size() < 1)
                    continue;
                if (solplayer.getClassObj() == null) {
                    player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
                    player.getInventory().setItem(slotId, null);
                    player.updateInventory();
                    player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
                    continue;
                }
                if (!i.getAllowedClassNames().contains(solplayer.getClassObj().getName().toUpperCase())) {
                    player.getWorld().dropItemNaturally(player.getLocation(), player.getInventory().getItem(slotId));
                    player.getInventory().setItem(slotId, null);
                    player.updateInventory();
                    player.sendMessage(ChatColor.GRAY + "You cannot wear " + i.getDisplayname() + " so it has been dropped");
                    continue;
                }
            } catch (SoliniaItemException e) {
                continue;
            }
        }
    } catch (CoreStateInitException e) {
        // try next loop
        return;
    }
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 52 with ISoliniaPlayer

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

the class CommandSetRace method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    sender.sendMessage("See /raceinfo for more information");
    String racelist = "";
    List<ISoliniaRace> races = new ArrayList<ISoliniaRace>();
    try {
        for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
            if (!race.isAdmin()) {
                racelist = racelist + " " + ChatColor.LIGHT_PURPLE + race.getName().toUpperCase() + ChatColor.RESET;
                races.add(race);
            }
        }
    } catch (CoreStateInitException e1) {
        sender.sendMessage("Race command failed. " + e1.getMessage());
        return false;
    }
    if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
        try {
            Utils.sendRaceInfo(sender);
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    }
    Player player = (Player) sender;
    ISoliniaPlayer soliniaplayer;
    try {
        soliniaplayer = SoliniaPlayerAdapter.Adapt(player);
    } catch (CoreStateInitException e2) {
        player.sendMessage("Race command failed. " + e2.getMessage());
        return false;
    }
    if (soliniaplayer.hasChosenRace() == true) {
        player.sendMessage("You cannot choose a race as you have already selected one");
        return true;
    }
    if (args.length == 0) {
        try {
            Utils.sendRaceInfo(sender);
        } catch (CoreStateInitException e1) {
        }
        player.sendMessage("Insufficient arguments. Please provide correct race name");
        if (soliniaplayer != null) {
            ISoliniaRace solrace;
            try {
                solrace = StateManager.getInstance().getConfigurationManager().getRace(soliniaplayer.getRaceId());
            } catch (CoreStateInitException e) {
                player.sendMessage("Race command failed. " + e.getMessage());
                return false;
            }
            if (solrace == null)
                player.sendMessage("Your current race is: UNKNOWN");
            else
                player.sendMessage("Your current race is: " + solrace.getName());
        }
        return false;
    }
    String race = args[0].toUpperCase();
    boolean found = false;
    for (ISoliniaRace allowedrace : races) {
        if (allowedrace.getName().equals(race)) {
            found = true;
        }
    }
    if (found == false) {
        try {
            Utils.sendRaceInfo(sender);
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        player.sendMessage("Insufficient arguments. Please provide correct race name");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getRace(race) != null) {
            soliniaplayer.setRaceId(StateManager.getInstance().getConfigurationManager().getRace(race).getId());
            soliniaplayer.setChosenRace(true);
            player.sendMessage("* Race set to " + race);
            return true;
        } else {
            Utils.sendRaceInfo(sender);
            player.sendMessage("Insufficient arguments. Please provide correct race name");
            return false;
        }
    } catch (CoreStateInitException e) {
        player.sendMessage("Race command failed. " + e.getMessage());
        return false;
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 53 with ISoliniaPlayer

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

the class CommandStats method onCommand.

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        try {
            Player player = (Player) sender;
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
            ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(player);
            player.sendMessage("Your Level: " + solplayer.getLevel());
            player.sendMessage("STR: " + solentity.getStrength() + " STA: " + solentity.getStamina() + " AGI: " + solentity.getAgility() + " DEX: " + solentity.getDexterity() + " INT: " + solentity.getIntelligence() + " WIS: " + solentity.getWisdom() + " CHA: " + solentity.getCharisma());
            player.sendMessage("You have a maximum HP of: " + player.getHealth() + "/" + player.getMaxHealth());
            player.sendMessage("You have a maximum MP of: " + solplayer.getMana() + "/" + solentity.getMaxMP());
            player.sendMessage("You currently have a Armour Class Mitigation of: " + solentity.getMitigationAC());
            player.sendMessage("You currently have a Attack Value of: " + solentity.getAttk());
            player.sendMessage("You currently have a Total Rune of: " + solentity.getRune());
            player.sendMessage("FR: " + solplayer.getResist(SpellResistType.RESIST_FIRE) + " CR: " + solplayer.getResist(SpellResistType.RESIST_COLD) + " MR: " + solplayer.getResist(SpellResistType.RESIST_MAGIC) + " PR: " + solplayer.getResist(SpellResistType.RESIST_POISON) + " DR: " + solplayer.getResist(SpellResistType.RESIST_DISEASE));
            Double newlevel = (double) solplayer.getLevel();
            Double xpneededforcurrentlevel = Utils.getExperienceRequirementForLevel((int) (newlevel + 0));
            Double xpneededfornextlevel = Utils.getExperienceRequirementForLevel((int) (newlevel + 1));
            Double totalxpneeded = xpneededfornextlevel - xpneededforcurrentlevel;
            Double currentxpprogress = solplayer.getExperience() - xpneededforcurrentlevel;
            Double percenttolevel = Math.floor((currentxpprogress / totalxpneeded) * 100);
            Double percenttoaa = Math.floor((solplayer.getAAExperience() / Utils.getMaxAAXP()) * 100);
            int ipercenttolevel = percenttolevel.intValue();
            int ipercenttoaa = percenttoaa.intValue();
            player.sendMessage("Level progress: " + ipercenttolevel + "% into level - Have: " + solplayer.getExperience().longValue() + " Need: " + xpneededfornextlevel.longValue());
            player.sendMessage("AA points: " + solplayer.getAAPoints());
            player.sendMessage("Next AA progress: " + ipercenttoaa + "% into AA - Have: " + solplayer.getAAExperience().longValue() + " Need: " + Utils.getMaxAAXP().longValue());
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 54 with ISoliniaPlayer

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

the class CommandTarot method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        try {
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
            if (solplayer == null) {
                player.sendMessage("Failed to emote, player does not exist");
                return false;
            }
            List<String> tarot = new ArrayList<String>();
            tarot.add("The Fool");
            tarot.add("The Magician");
            tarot.add("The High Priestess");
            tarot.add("The Empress");
            tarot.add("The Emperor");
            tarot.add("The Hierophant");
            tarot.add("The Lovers");
            tarot.add("The Chariot");
            tarot.add("Strength");
            tarot.add("The Hermit");
            tarot.add("Wheel of Fortune");
            tarot.add("Justice");
            tarot.add("The Hanged Man");
            tarot.add("Death");
            tarot.add("Temperance");
            tarot.add("The Devil");
            tarot.add("The Tower");
            tarot.add("The Star");
            tarot.add("The Moon");
            tarot.add("The Sun");
            tarot.add("Judgement");
            tarot.add("The World");
            Collections.shuffle(tarot);
            Collections.shuffle(tarot);
            Collections.shuffle(tarot);
            String past = tarot.get(0);
            String present = tarot.get(1);
            String future = tarot.get(2);
            String message = ChatColor.AQUA + " * " + solplayer.getFullName() + " shuffles a deck of tarot cards and slowly draws. Drawing the Card of the Past: " + past + ", Card of the Present: " + present + " and finally, Card of the " + future + "." + ChatColor.RESET;
            solplayer.emote(message);
        } catch (CoreStateInitException e) {
            player.sendMessage(e.getMessage());
        }
    }
    return true;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 55 with ISoliniaPlayer

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

the class SoliniaActiveSpell method applyCurrentMpSpellEffect.

private void applyCurrentMpSpellEffect(SpellEffect spellEffect, ISoliniaSpell soliniaSpell, int casterLevel) {
    if (!isOwnerPlayer())
        return;
    Entity sourceEntity = Bukkit.getEntity(getSourceUuid());
    if (sourceEntity == null)
        return;
    if (!(sourceEntity instanceof LivingEntity))
        return;
    LivingEntity sourceLivingEntity = (LivingEntity) sourceEntity;
    int instrument_mod = 0;
    try {
        ISoliniaLivingEntity sourceSoliniaLivingEntity = SoliniaLivingEntityAdapter.Adapt(sourceLivingEntity);
        if (sourceSoliniaLivingEntity != null) {
            instrument_mod = sourceSoliniaLivingEntity.getInstrumentMod(this.getSpell());
        }
    } catch (CoreStateInitException e) {
    // just skip it
    }
    int mpToRemove = soliniaSpell.calcSpellEffectValue(spellEffect, sourceLivingEntity, getLivingEntity(), casterLevel, getTicksLeft(), instrument_mod);
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(this.getOwnerUuid()));
        ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(Bukkit.getPlayer(this.getOwnerUuid()));
        int amount = (int) Math.round(solplayer.getMana()) + mpToRemove;
        if (amount > solentity.getMaxMP()) {
            amount = (int) Math.round(solentity.getMaxMP());
        }
        if (amount < 0)
            amount = 0;
        solplayer.setMana(amount);
    } catch (CoreStateInitException e) {
        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) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Aggregations

ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)89 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)85 Player (org.bukkit.entity.Player)57 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)16 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)13 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)12 EventHandler (org.bukkit.event.EventHandler)11 LivingEntity (org.bukkit.entity.LivingEntity)10 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)9 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)8 TextComponent (net.md_5.bungee.api.chat.TextComponent)8 ItemStack (org.bukkit.inventory.ItemStack)8 CommandSender (org.bukkit.command.CommandSender)5 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)5 Entity (org.bukkit.entity.Entity)5 Timestamp (java.sql.Timestamp)4 LocalDateTime (java.time.LocalDateTime)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)4