Search in sources :

Example 6 with CommandSender

use of net.md_5.bungee.api.CommandSender 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 7 with CommandSender

use of net.md_5.bungee.api.CommandSender 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 8 with CommandSender

use of net.md_5.bungee.api.CommandSender 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 9 with CommandSender

use of net.md_5.bungee.api.CommandSender 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 10 with CommandSender

use of net.md_5.bungee.api.CommandSender in project commands by aikar.

the class ACFBungeeUtil method findPlayerSmart.

public static ProxiedPlayer findPlayerSmart(CommandIssuer issuer, String search) {
    CommandSender requester = issuer.getIssuer();
    String name = ACFUtil.replace(search, ":confirm", "");
    if (name.length() < 3) {
        issuer.sendError(MinecraftMessageKeys.USERNAME_TOO_SHORT);
        return null;
    }
    if (!isValidName(name)) {
        issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
        return null;
    }
    List<ProxiedPlayer> matches = new ArrayList<>(ProxyServer.getInstance().matchPlayer(name));
    if (matches.size() > 1) {
        String allMatches = matches.stream().map(ProxiedPlayer::getName).collect(Collectors.joining(", "));
        issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches);
        return null;
    }
    if (matches.isEmpty()) {
        issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name);
        return null;
    }
    return matches.get(0);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ArrayList(java.util.ArrayList) CommandSender(net.md_5.bungee.api.CommandSender)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)22 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)15 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)11 CommandSender (net.md_5.bungee.api.CommandSender)9 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)8 Player (org.bukkit.entity.Player)8 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)6 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)5 ArrayList (java.util.ArrayList)4 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)3 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)3 ChatSender (at.pcgamingfreaks.Bungee.Message.Sender.ChatSender)2 SendMethod (at.pcgamingfreaks.Bungee.Message.Sender.SendMethod)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 SoliniaActiveSpell (com.solinia.solinia.Models.SoliniaActiveSpell)2 SoliniaEntitySpells (com.solinia.solinia.Models.SoliniaEntitySpells)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2