Search in sources :

Example 66 with ISoliniaPlayer

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

the class SoliniaPlayerFactory method CreatePlayer.

public static ISoliniaPlayer CreatePlayer(Player player, boolean main) throws CoreStateInitException {
    // A player is different to a players entity
    ISoliniaPlayer soliniaPlayer = new SoliniaPlayer();
    soliniaPlayer.setUUID(player.getUniqueId());
    soliniaPlayer.setMain(main);
    String forename = getRandomNames(5, 1)[0];
    String lastname = "";
    try {
        while (StateManager.getInstance().getPlayerManager().IsNewNameValid(forename, lastname) == false) {
            forename = getRandomNames(5, 1)[0];
        }
        soliniaPlayer.setForename(forename);
        soliniaPlayer.setLastname(lastname);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    StateManager.getInstance().getPlayerManager().addPlayer(soliniaPlayer);
    soliniaPlayer = SoliniaPlayerAdapter.Adapt(player);
    soliniaPlayer.setExperience(0d);
    soliniaPlayer.setAAExperience(0d);
    soliniaPlayer.setMana(0);
    return soliniaPlayer;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaPlayer(com.solinia.solinia.Models.SoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 67 with ISoliniaPlayer

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

the class SoliniaNPCEventHandler method awardPlayer.

@Override
public void awardPlayer(Player triggerentity) {
    try {
        ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt(triggerentity);
        if (getAwardsQuest() > 0) {
            boolean foundQuest = false;
            for (PlayerQuest playerQuest : player.getPlayerQuests()) {
                if (playerQuest.getQuestId() == getAwardsQuest()) {
                    foundQuest = true;
                }
            }
            if (foundQuest == false)
                player.addPlayerQuest(getAwardsQuest());
        }
        if (getAwardsQuestFlag() != null && !getAwardsQuestFlag().equals("")) {
            boolean foundQuestFlag = false;
            for (String playerQuestFlag : player.getPlayerQuestFlags()) {
                if (playerQuestFlag.equals(getAwardsQuestFlag())) {
                    foundQuestFlag = true;
                }
            }
            if (foundQuestFlag == false) {
                player.addPlayerQuestFlag(getAwardsQuestFlag());
                // All item awards must be accompanied with a quest flag else they will repeat the item return over and over
                if (getAwardsItem() > 0) {
                    System.out.println("Awarding item with awardquestflag: " + getAwardsQuestFlag());
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(getAwardsItem());
                    final int awarditemid = getAwardsItem();
                    final UUID uuid = player.getBukkitPlayer().getUniqueId();
                    if (item != null) {
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("Solinia3Core"), new Runnable() {

                            public void run() {
                                try {
                                    ItemStack itemStack = item.asItemStack();
                                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(awarditemid);
                                    Bukkit.getPlayer(uuid).getWorld().dropItem(Bukkit.getPlayer(uuid).getLocation(), itemStack);
                                    System.out.println("Awarded item: " + item.getDisplayname());
                                } catch (CoreStateInitException e) {
                                // skip
                                }
                            }
                        });
                    }
                }
                if (this.isAwardsTitle() == true) {
                    if (this.getTitle() != null) {
                        if (!this.getTitle().equals("")) {
                            player.grantTitle(this.getTitle());
                        }
                    }
                }
                if (isAwardsRandomisedGear() == true) {
                    String suffix = "of Randomisation";
                    if (getRandomisedGearSuffix() != null) {
                        if (!getRandomisedGearSuffix().equals("")) {
                            suffix = getRandomisedGearSuffix();
                        }
                    }
                    System.out.println("Awarding randomisedgear with awardquestflag: " + getAwardsQuestFlag());
                    int playertier = 1;
                    if (player.getLevel() >= 1 && player.getLevel() < 11)
                        playertier = 1;
                    if (player.getLevel() >= 11 && player.getLevel() < 21)
                        playertier = 2;
                    if (player.getLevel() >= 21 && player.getLevel() < 31)
                        playertier = 3;
                    if (player.getLevel() >= 31 && player.getLevel() < 41)
                        playertier = 4;
                    if (player.getLevel() >= 41 && player.getLevel() < 51)
                        playertier = 5;
                    if (player.getLevel() >= 51 && player.getLevel() < 61)
                        playertier = 6;
                    try {
                        // always give the next tier up and then we will reset the player requirements ot current level
                        // this ability is for special seasonal rewards only
                        playertier += 1;
                        List<Integer> items = SoliniaItemFactory.CreateClassItemSet(player.getClassObj(), playertier, suffix, false, true);
                        for (int itemid : items) {
                            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemid);
                            final String playerName = player.getBukkitPlayer().getName();
                            final int minLevel = player.getLevel();
                            final int finalitemid = itemid;
                            if (item != null) {
                                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("Solinia3Core"), new Runnable() {

                                    public void run() {
                                        try {
                                            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(finalitemid);
                                            item.setMinLevel(minLevel);
                                            SoliniaAccountClaim claim = new SoliniaAccountClaim();
                                            claim.setId(StateManager.getInstance().getConfigurationManager().getNextAccountClaimId());
                                            claim.setMcname(playerName);
                                            claim.setItemid(finalitemid);
                                            claim.setClaimed(false);
                                            Player claimPlayer = Bukkit.getPlayer(playerName);
                                            if (claimPlayer != null) {
                                                claimPlayer.sendMessage(ChatColor.GOLD + "You have been awarded with a claim item! See /claim");
                                            }
                                            StateManager.getInstance().getConfigurationManager().addAccountClaim(claim);
                                            System.out.println("Awarded Claim: " + item.getDisplayname() + " to " + playerName);
                                        } catch (CoreStateInitException e) {
                                        // skip
                                        }
                                    }
                                });
                            }
                        }
                    } catch (SoliniaItemException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            }
        }
    } catch (CoreStateInitException e) {
        System.out.println(e.getMessage());
        return;
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack)

Example 68 with ISoliniaPlayer

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

the class SoliniaLivingEntity method doCheckForEnemies.

@Override
public void doCheckForEnemies() {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    if (getBukkitLivingEntity().isDead())
        return;
    if (!(getBukkitLivingEntity() instanceof Creature))
        return;
    if (((Creature) getBukkitLivingEntity()).getTarget() != null)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc.getFactionid() == 0)
            return;
        ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
        if (faction.getName().equals("NEUTRAL") || faction.getName().equals("KOS"))
            return;
        for (Entity entity : getBukkitLivingEntity().getNearbyEntities(10, 10, 10)) {
            if (!(entity instanceof Player))
                continue;
            if (entity.isDead())
                continue;
            Player player = (Player) entity;
            ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
            PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
            if (factionEntry != null) {
                switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
                    case FACTION_THREATENLY:
                    case FACTION_SCOWLS:
                        if (Utils.isEntityInLineOfSight(player, getBukkitLivingEntity())) {
                            ((Creature) getBukkitLivingEntity()).setTarget(player);
                            return;
                        } else {
                            continue;
                        }
                    default:
                        break;
                }
            }
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : 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) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 69 with ISoliniaPlayer

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

the class CommandGroupChat method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // TODO Auto-generated method stub
    if (!(sender instanceof Player)) {
        return false;
    }
    Player player = (Player) sender;
    if (args.length == 0) {
        player.sendMessage("You did not supply a message to send");
        return true;
    }
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        if (solplayer.getGroup() == null) {
            player.sendMessage("Group does not exist");
            return true;
        }
        if (solplayer.getGroup().getMembers().size() < 2) {
            player.sendMessage("There is only 1 person in the group");
            return true;
        }
        String message = arrayToString(args, " ");
        solplayer.getGroup().sendGroupMessage(player, ChatColor.AQUA + message + ChatColor.RESET);
        return true;
    } 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) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 70 with ISoliniaPlayer

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

the class CoreState method sendGroupMessage.

public void sendGroupMessage(Player player, String message) {
    if (message == null || message.equals("")) {
        player.sendMessage("You cannot send an empty message");
        return;
    }
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        ISoliniaGroup group = getGroupByMember(player.getUniqueId());
        if (group == null) {
            player.sendMessage("You are not in a group");
            return;
        }
        String type = "";
        if (group.getOwner().equals(player.getUniqueId())) {
            type = "[" + ChatColor.LIGHT_PURPLE + "L" + ChatColor.RESET + "]";
        } else {
            type = "[" + ChatColor.LIGHT_PURPLE + "M" + ChatColor.RESET + "]";
        }
        if (group.getMembers().size() > 0) {
            for (UUID memberid : group.getMembers()) {
                Player groupplayer = Bukkit.getPlayer(memberid);
                if (groupplayer != null) {
                    System.out.println("group: " + group.getId() + ":" + player.getDisplayName() + ": " + ChatColor.AQUA + message);
                    groupplayer.sendMessage(type + " " + ChatColor.WHITE + solplayer.getFullName() + ChatColor.RESET + " [" + ChatColor.RED + (int) player.getHealth() + ChatColor.RESET + "/" + ChatColor.BLUE + solplayer.getMana() + ChatColor.RESET + "]: " + ChatColor.AQUA + message);
                }
            }
        } else {
            player.sendMessage("There were no members of that group");
            return;
        }
    } catch (CoreStateInitException e) {
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID)

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