Search in sources :

Example 11 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent 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 TextComponent

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

the class SoliniaLivingEntity method doAttack.

private DamageHitInfo doAttack(Plugin plugin, ISoliniaLivingEntity defender, DamageHitInfo hit) {
    if (defender == null)
        return hit;
    // for riposte
    int originalDamage = hit.damage_done;
    hit = defender.avoidDamage(this, hit);
    if (hit.avoided == true) {
        if (hit.riposted == true && originalDamage > 0) {
            if (defender.isPlayer()) {
                ((Player) defender.getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You riposte the attack!");
                defender.tryIncreaseSkill("RIPOSTE", 1);
            }
            if (isPlayer()) {
                ((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* " + defender.getBukkitLivingEntity().getCustomName() + " ripostes your attack!");
                damage(plugin, originalDamage, getBukkitLivingEntity());
            }
        }
        if (hit.dodged == true) {
            if (defender.isPlayer()) {
                ((Player) defender.getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You dodge the attack!");
                defender.tryIncreaseSkill("DODGE", 1);
            }
            if (isPlayer()) {
                ((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* " + defender.getBukkitLivingEntity().getCustomName() + " dodges your attack!");
            }
        }
    }
    if (hit.damage_done >= 0) {
        if (defender.checkHitChance(this, hit)) {
            hit = defender.meleeMitigation(this, hit);
            if (hit.damage_done > 0) {
                hit = applyDamageTable(hit);
                hit = commonOutgoingHitSuccess(defender, hit);
            }
        } else {
            if (getBukkitLivingEntity() instanceof Player) {
                ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You tried to hit " + defender.getBukkitLivingEntity().getCustomName() + ", but missed!"));
            }
            if (defender.getBukkitLivingEntity() instanceof Player) {
                ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(getBukkitLivingEntity().getCustomName() + " tried to hit you, but missed!"));
                try {
                    ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
                    solplayer.tryIncreaseSkill("DEFENSE", 1);
                } catch (CoreStateInitException e) {
                // skip
                }
            }
            hit.damage_done = 0;
        }
    }
    return hit;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Example 13 with TextComponent

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

the class Utils method sendRaceInfo.

public static void sendRaceInfo(CommandSender sender) throws CoreStateInitException {
    List<ISoliniaClass> classes = StateManager.getInstance().getConfigurationManager().getClasses();
    for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
        if (race.isAdmin())
            continue;
        String classBuilder = "";
        for (ISoliniaClass solclass : classes) {
            if (solclass.getValidRaces().contains(race.getId()))
                classBuilder += solclass.getName() + " ";
        }
        TextComponent tc = new TextComponent();
        tc.setText(ChatColor.RED + "~ RACE: " + ChatColor.GOLD + race.getName().toUpperCase() + ChatColor.GRAY + " [" + race.getId() + "] - " + ChatColor.RESET);
        TextComponent tc2 = new TextComponent();
        tc2.setText("Hover for more details");
        String details = ChatColor.GOLD + race.getName() + ChatColor.RESET + "\nRecommended Alignment: " + ChatColor.GOLD + race.getAlignment() + ChatColor.RESET + "\n" + race.getDescription() + "\nSTR: " + ChatColor.GOLD + race.getStrength() + ChatColor.RESET + " STA: " + ChatColor.GOLD + race.getStamina() + ChatColor.RESET + " AGI: " + ChatColor.GOLD + race.getAgility() + ChatColor.RESET + " DEX: " + ChatColor.GOLD + race.getDexterity() + ChatColor.RESET + " INT: " + ChatColor.GOLD + race.getIntelligence() + ChatColor.RESET + " WIS: " + ChatColor.GOLD + race.getWisdom() + ChatColor.RESET + " CHA: " + ChatColor.GOLD + race.getCharisma() + ChatColor.GOLD + " \nClasses: " + ChatColor.RESET + classBuilder;
        tc2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
        tc.addExtra(tc2);
        sender.spigot().sendMessage(tc);
    }
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 14 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project Ublisk by Derkades.

the class Guild method invitePlayer.

public synchronized void invitePlayer(final UPlayer source, final UPlayer target) {
    if (!this.exists())
        throw new UnsupportedOperationException("Cannot invite player to non-existent guild.");
    final GuildInvite invite = new GuildInvite(this, source);
    // Add invite to list of invites, and remove it after 60 seconds (if it hasn't been accepted)
    GUILD_INVITES.put(target.getName(), invite);
    new BukkitRunnable() {

        public void run() {
            if (GUILD_INVITES.containsKey(target.getName())) {
                GUILD_INVITES.remove(target.getName());
            }
        }
    }.runTaskLater(Main.getInstance(), 60 * 20);
    TextComponent inviteMessage = new TextComponent(source.getName() + " has invited you to join " + this.getName() + ". ");
    inviteMessage.setColor(ChatColor.DARK_AQUA);
    inviteMessage.setBold(true);
    BaseComponent[] hoverText = new ComponentBuilder("Click me!").color(ChatColor.YELLOW).create();
    TextComponent clickToAccept = new TextComponent("Click here to accept.");
    clickToAccept.setColor(ChatColor.AQUA);
    clickToAccept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText));
    clickToAccept.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/guild accept"));
    BaseComponent[] components = new BaseComponent[] { inviteMessage, clickToAccept };
    target.sendMessage(components);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 15 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project SkinsRestorerX by DoNotSpamPls.

the class SkinsRestorer method onEnable.

@Override
public void onEnable() {
    @SuppressWarnings("unused") MetricsLite metrics = new MetricsLite(this);
    instance = this;
    Config.load(getResourceAsStream("config.yml"));
    Locale.load();
    if (Config.USE_MYSQL) {
        SkinStorage.init(mysql = new MySQL(Config.MYSQL_HOST, Config.MYSQL_PORT, Config.MYSQL_DATABASE, Config.MYSQL_USERNAME, Config.MYSQL_PASSWORD));
    } else {
        SkinStorage.init(getDataFolder());
    }
    getProxy().getPluginManager().registerListener(this, new LoginListener());
    getProxy().getPluginManager().registerCommand(this, new AdminCommands());
    getProxy().getPluginManager().registerCommand(this, new PlayerCommands());
    getProxy().registerChannel("SkinsRestorer");
    SkinApplier.init();
    multibungee = Config.MULTIBUNGEE_ENABLED || ProxyServer.getInstance().getPluginManager().getPlugin("RedisBungee") != null;
    ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
        CommandSender console = getProxy().getConsole();
        if (Config.UPDATER_ENABLED)
            if (checkVersion(console).equals(getVersion())) {
                outdated = false;
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    | SkinsRestorer |"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b    Current version: §a" + getVersion()));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    This is the latest version!"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
            } else {
                outdated = true;
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    | SkinsRestorer |"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b    Current version: §c" + getVersion()));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e    A new version is available! Download it at:"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e    https://www.spigotmc.org/resources/skinsrestorer.2124"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
            }
        if (Config.DEFAULT_SKINS_ENABLED)
            for (String skin : Config.DEFAULT_SKINS) try {
                SkinStorage.setSkinData(skin, MojangAPI.getSkinProperty(MojangAPI.getUUID(skin)));
            } catch (SkinRequestException e) {
                if (SkinStorage.getSkinData(skin) == null)
                    console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §cDefault Skin '" + skin + "' request error:" + e.getReason()));
            }
    });
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) MetricsLite(org.bstats.bungeecord.MetricsLite) LoginListener(skinsrestorer.bungee.listeners.LoginListener) MySQL(skinsrestorer.shared.utils.MySQL) AdminCommands(skinsrestorer.bungee.commands.AdminCommands) PlayerCommands(skinsrestorer.bungee.commands.PlayerCommands) CommandSender(net.md_5.bungee.api.CommandSender) SkinRequestException(skinsrestorer.shared.utils.MojangAPI.SkinRequestException)

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