Search in sources :

Example 6 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class Solinia3CoreItemPickupListener method PickupItem.

@EventHandler
public void PickupItem(PlayerPickupItemEvent e) {
    ItemStack pickedUpItemStack = e.getItem().getItemStack();
    // Replace oxygen items with durability items
    if (pickedUpItemStack.getEnchantmentLevel(Enchantment.OXYGEN) > 999) {
        e.getPlayer().sendMessage("Detected an item in the old format, converting to the new format. Please drop all your old items and pick them up if you are having problems with them");
        try {
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItemByOxygen(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
        } catch (CoreStateInitException eOxy) {
        }
    }
    String temporaryGuid = null;
    Integer augmentationItemId = null;
    try {
        if (Utils.IsSoliniaItem(pickedUpItemStack) && pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK)) {
            e.getPlayer().sendMessage(ChatColor.GRAY + "You have picked up an ability! To use it, hold it in your hand and right click!");
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (pickedUpItemStack != null) {
                if (latestitem != null) {
                    ItemStack latestitemstack = latestitem.asItemStack();
                    pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                } else {
                    // this is an item that is broken
                    e.getPlayer().sendMessage("This item is no longer implemented");
                    Utils.CancelEvent(e);
                    e.getItem().remove();
                }
            }
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
        }
        if (Utils.IsSoliniaItem(pickedUpItemStack) && !(pickedUpItemStack.getType().equals(Material.ENCHANTED_BOOK))) {
            Map<Enchantment, Integer> oldenchantments = pickedUpItemStack.getEnchantments();
            ISoliniaItem latestitem = StateManager.getInstance().getConfigurationManager().getItem(pickedUpItemStack);
            if (latestitem.getDiscoverer() == null || latestitem.getDiscoverer().equals("")) {
                latestitem.setDiscoverer(e.getPlayer().getCustomName());
                e.getPlayer().getServer().broadcastMessage(ChatColor.YELLOW + "* " + latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
                StateManager.getInstance().getChannelManager().sendToDiscordMC(null, StateManager.getInstance().getChannelManager().getDefaultDiscordChannel(), latestitem.getDisplayname() + " was discovered by " + e.getPlayer().getCustomName() + "!");
            }
            if (pickedUpItemStack != null) {
                ItemStack latestitemstack = latestitem.asItemStack();
                // We need to store this information before we change the itemmeta, so we can update it afterwards
                if (latestitem.isTemporary()) {
                    temporaryGuid = ItemStackUtils.getTemporaryItemGuid(pickedUpItemStack);
                }
                augmentationItemId = ItemStackUtils.getAugmentationItemId(pickedUpItemStack);
                // Now go and replace the itemmeta
                pickedUpItemStack.setItemMeta(latestitemstack.getItemMeta());
                // Now re-apply enchantments that it had before
                for (Map.Entry<Enchantment, Integer> entry : oldenchantments.entrySet()) {
                    Enchantment key = entry.getKey();
                    Integer value = entry.getValue();
                    if (value < 1000) {
                        pickedUpItemStack.addUnsafeEnchantment(key, value);
                    }
                }
                // Since the item is temporary, attempt to apply the temporary timestamp it had prior to this
                if (latestitem.isTemporary()) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyTemporaryStamp(pickedUpItemStack, temporaryGuid));
                }
                if (augmentationItemId != null && augmentationItemId != 0) {
                    pickedUpItemStack.setItemMeta(ItemStackUtils.applyAugmentationToItemStack(pickedUpItemStack, augmentationItemId));
                }
            }
        }
        // group messages
        if (Utils.IsSoliniaItem(pickedUpItemStack)) {
            ISoliniaItem item;
            try {
                item = SoliniaItemAdapter.Adapt(pickedUpItemStack);
                if (item.getAllowedClassNames().size() > 0) {
                    ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(e.getPlayer());
                    if (solPlayer.getGroup() != null && solPlayer.getGroup().getMembers() != null)
                        for (UUID playerUuid : solPlayer.getGroup().getMembers()) {
                            if (playerUuid.equals(e.getPlayer().getUniqueId()))
                                continue;
                            Player groupMember = Bukkit.getPlayer(playerUuid);
                            ISoliniaPlayer groupSolPlayer = SoliniaPlayerAdapter.Adapt(groupMember);
                            if (groupSolPlayer != null) {
                                if (groupSolPlayer.getClassObj() != null)
                                    if (item.getAllowedClassNames().contains(groupSolPlayer.getClassObj().getName().toUpperCase())) {
                                        TextComponent tc = new TextComponent();
                                        tc.setText("* " + groupSolPlayer.getFullName() + " picked up an item of interest to your class: [" + ChatColor.AQUA + item.getDisplayname() + ChatColor.RESET + "]");
                                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                                        groupSolPlayer.getBukkitPlayer().spigot().sendMessage(tc);
                                    }
                            }
                        }
                }
            } catch (SoliniaItemException e1) {
            }
        }
    } catch (CoreStateInitException coreException) {
    // do nothing
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) 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) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) UUID(java.util.UUID) Map(java.util.Map) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 7 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class CommandPet method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // TODO Auto-generated method stub
    if (sender instanceof Player) {
        try {
            Player player = (Player) sender;
            LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
            if (pet == null) {
                player.sendMessage("You don't have a pet");
                return true;
            }
            if (args.length > 0) {
                String petcommand = args[0];
                if (petcommand.equals("back")) {
                    Wolf c = (Wolf) pet;
                    player.setLastDamageCause(null);
                    player.sendMessage("* As you wish my master");
                    c.setTarget(null);
                }
            }
            player.sendMessage("Pet Name: " + pet.getName());
            player.sendMessage("Pet HP: " + pet.getHealth() + "/" + pet.getMaxHealth());
            ISoliniaLivingEntity petLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
            EntityInsentient entityhandle = (EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) pet).getHandle();
            double dmg = entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
            player.sendMessage("Pet DMG: " + dmg);
            player.sendMessage("STR: " + petLivingEntity.getStrength() + " STA: " + petLivingEntity.getStamina() + " AGI: " + petLivingEntity.getAgility() + " DEX: " + petLivingEntity.getDexterity() + " INT: " + petLivingEntity.getIntelligence() + " WIS: " + petLivingEntity.getWisdom() + " CHA: " + petLivingEntity.getCharisma());
            player.sendMessage("Pet Armour Class Mitigation : " + petLivingEntity.getMitigationAC());
            player.sendMessage("Pet Attack Value: " + petLivingEntity.getAttk());
            player.sendMessage("Pet Total Rune of: " + petLivingEntity.getRune());
            player.sendMessage("Active Effects:");
            SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(pet);
            for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
                ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                String removetext = "";
                ChatColor spellcolor = ChatColor.GREEN;
                if (spell.isBeneficial()) {
                    removetext = "Removable spell";
                } 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);
                tc.addExtra(tc2);
                sender.spigot().sendMessage(tc);
            }
            return true;
        } catch (CoreStateInitException e) {
        }
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 8 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class CommandSetTitle 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 (args.length == 0) {
                player.sendMessage("Available titles:");
                for (String title : solplayer.getAvailableTitles()) {
                    TextComponent tc = new TextComponent();
                    tc.setText("- " + title);
                    TextComponent tc2 = new TextComponent();
                    tc2.setText(ChatColor.GRAY + "Click here to set this title" + ChatColor.RESET);
                    tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/settitle " + title));
                    tc.addExtra(tc2);
                    sender.spigot().sendMessage(tc);
                }
                player.sendMessage("/settitle none to remove your current title");
                return true;
            }
            String targetTitle = args[0];
            if (args.length > 0) {
                targetTitle = "";
                int current = 0;
                for (String entry : args) {
                    current++;
                    targetTitle = targetTitle + entry + " ";
                }
                targetTitle = targetTitle.trim();
            }
            if (!targetTitle.equals("none")) {
                boolean found = false;
                for (String title : solplayer.getAvailableTitles()) {
                    if (targetTitle.toUpperCase().equals(title.toUpperCase())) {
                        targetTitle = title;
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    player.sendMessage("You do not have this title");
                    return true;
                }
                solplayer.setTitle(targetTitle);
            } else {
                solplayer.setTitle("");
            }
            System.out.println("* [" + player.getName() + "] Title set to: " + "'" + solplayer.getTitle() + "'");
            player.sendMessage("* Title set to: '" + solplayer.getTitle() + "'");
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            player.sendMessage(e.getMessage());
        }
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 9 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class CommandCharacter method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        if (args.length == 0) {
            player.sendMessage("Your Characters: ");
            String main = "ALT";
            if (solplayer.isMain()) {
                main = "MAIN";
            }
            player.sendMessage("- " + ChatColor.LIGHT_PURPLE + solplayer.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - " + ChatColor.GREEN + "ACTIVE" + ChatColor.RESET);
            for (ISoliniaPlayer character : StateManager.getInstance().getPlayerManager().getCharactersByPlayerUUID(player.getUniqueId())) {
                if (character.getCharacterId().equals(solplayer.getCharacterId()))
                    continue;
                if (character.isMain()) {
                    main = "MAIN";
                } else {
                    main = "ALT";
                }
                TextComponent tc = new TextComponent();
                tc.setText("- " + ChatColor.LIGHT_PURPLE + character.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - ");
                String details = ChatColor.GOLD + character.getFullNameWithTitle() + " Level: " + character.getLevel() + ChatColor.RESET;
                TextComponent tc2 = new TextComponent();
                String changetext = "/character load " + character.getCharacterId().toString();
                if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                    tc2.setText(ChatColor.RED + "Already changed this session" + ChatColor.RESET);
                } else {
                    tc2.setText(ChatColor.AQUA + "[Click to Switch]" + ChatColor.RESET);
                    tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, changetext));
                }
                tc.addExtra(tc2);
                tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                sender.spigot().sendMessage(tc);
            }
            player.sendMessage("Note, new characters may not be visible for up to 15 minutes");
            player.sendMessage("Use '/character new' to create a new character");
        } else {
            switch(args[0].toUpperCase()) {
                case "NEW":
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    ISoliniaPlayer newPlayer = StateManager.getInstance().getPlayerManager().createNewPlayerAlt(plugin, player);
                    if (newPlayer != null) {
                        player.sendMessage("Your character has been stored and a new character created");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem creating your new character");
                    }
                    break;
                case "LOAD":
                    if (args.length < 2) {
                        player.sendMessage("You must provide the character UUID");
                        return true;
                    }
                    if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
                        player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
                        return true;
                    }
                    UUID characterUUID = UUID.fromString(args[1]);
                    ISoliniaPlayer loadedPlayer = StateManager.getInstance().getPlayerManager().loadPlayerAlt(plugin, player, characterUUID);
                    if (loadedPlayer != null) {
                        player.sendMessage("Your character has been stored and your new character loaded");
                        player.sendMessage("Please check you have not dropped any items due to your character change");
                    } else {
                        player.sendMessage("Problem loading requested character");
                    }
                    break;
                default:
                    player.sendMessage("Unknown character subcommand");
                    break;
            }
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 10 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class SoliniaLivingEntity method triggerDefensiveProcs.

private void triggerDefensiveProcs(ISoliniaLivingEntity defender, int damage, boolean arrowHit) {
    if (damage < 0)
        return;
    if (arrowHit)
        return;
    try {
        SoliniaEntitySpells effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(defender.getBukkitLivingEntity());
        if (effects == null)
            return;
        for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
            if (spell == null)
                continue;
            if (!spell.isDamageShield())
                continue;
            for (ActiveSpellEffect spelleffect : activeSpell.getActiveSpellEffects()) {
                if (spelleffect.getSpellEffectType().equals(SpellEffectType.DamageShield)) {
                    // hurt enemy with damage shield
                    if (spelleffect.getCalculatedValue() < 0) {
                        EntityDamageSource source = new EntityDamageSource("thorns", ((CraftEntity) defender.getBukkitLivingEntity()).getHandle());
                        source.setMagic();
                        source.ignoresArmor();
                        ((CraftEntity) this.getBukkitLivingEntity()).getHandle().damageEntity(source, spelleffect.getCalculatedValue() * -1);
                        // attacker.damage(spelleffect.getBase() * -1);
                        DecimalFormat df = new DecimalFormat();
                        df.setMaximumFractionDigits(2);
                        if (defender instanceof Player) {
                            ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("Your damage shield hit " + this.getBukkitLivingEntity().getName() + " for " + df.format(spelleffect.getCalculatedValue() * -1) + "[" + df.format(this.getBukkitLivingEntity().getHealth() - (spelleffect.getCalculatedValue() * -1)) + "/" + df.format(this.getBukkitLivingEntity().getMaxHealth()) + "]"));
                        }
                    }
                }
            }
        }
    } catch (CoreStateInitException e) {
        return;
    }
}
Also used : 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) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) DecimalFormat(java.text.DecimalFormat) EntityDamageSource(net.minecraft.server.v1_12_R1.EntityDamageSource)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)12 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)12 Player (org.bukkit.entity.Player)12 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)11 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)11 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)9 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)9 IOException (java.io.IOException)6 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)5 ArrayList (java.util.ArrayList)5 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)4 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)4 DecimalFormat (java.text.DecimalFormat)4 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)3 SoliniaActiveSpell (com.solinia.solinia.Models.SoliniaActiveSpell)3 File (java.io.File)3 EventHandler (net.md_5.bungee.event.EventHandler)3