Search in sources :

Example 1 with ChatChannel

use of mc.dragons.core.gameobject.user.chat.ChatChannel in project DragonsOnline by UniverseCraft.

the class ChannelCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender))
        return true;
    User user = user(sender);
    boolean staff = hasPermission(sender, PermissionLevel.BUILDER);
    if (handleAlias(sender, label))
        return true;
    if (args.length == 0) {
        openGUI(user);
        return true;
    }
    if (args.length == 1) {
        ChatChannel channel = parse(sender, staff, args[0]);
        if (channel == null)
            return true;
        if (user.getActiveChatChannels().contains(channel)) {
            user.removeActiveChatChannel(channel);
            sender.sendMessage(ChatColor.GREEN + "You are no longer " + (user.getSpeakingChannel() == channel ? "speaking or " : "") + "listening on " + channel);
        } else {
            user.setSpeakingChannel(channel);
            user.addActiveChatChannel(channel);
            sender.sendMessage(ChatColor.GREEN + "You are now speaking and listening on " + channel);
            if (user.getActiveChatChannels().size() > 1) {
                List<ChatChannel> others = new ArrayList<>(user.getActiveChatChannels());
                others.remove(channel);
                sender.sendMessage(ChatColor.GRAY + "You are also listening on " + StringUtil.parseList(others.stream().map(c -> c.toString()).collect(Collectors.toList())));
            }
        }
        return true;
    }
    ChatChannel channel = parse(sender, staff, args[1]);
    if (channel == null)
        return true;
    if (args[0].equalsIgnoreCase("speak") || args[0].equalsIgnoreCase("s")) {
        if (user.getSpeakingChannel() == channel) {
            sender.sendMessage(ChatColor.RED + "You are already speaking on " + channel);
        }
        user.setSpeakingChannel(channel);
        sender.sendMessage(ChatColor.GREEN + "Now speaking and listening on " + channel);
        if (!user.getActiveChatChannels().contains(channel)) {
            user.addActiveChatChannel(channel);
        // sender.sendMessage(ChatColor.GREEN + "You are now listening to this channel as well.");
        }
    } else if (args[0].equalsIgnoreCase("listen") || args[0].equalsIgnoreCase("l")) {
        if (user.getActiveChatChannels().contains(channel)) {
            user.removeActiveChatChannel(channel);
            sender.sendMessage(ChatColor.GREEN + "You are no longer listening on " + channel);
            return true;
        }
        user.addActiveChatChannel(channel);
        sender.sendMessage(ChatColor.GREEN + "You are now listening on " + channel);
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid arguments! /channel");
    }
    return true;
}
Also used : ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) User(mc.dragons.core.gameobject.user.User) ArrayList(java.util.ArrayList)

Example 2 with ChatChannel

use of mc.dragons.core.gameobject.user.chat.ChatChannel in project DragonsOnline by UniverseCraft.

the class ChannelCommand method openGUI.

private void openGUI(User user) {
    boolean staff = hasPermission(user, PermissionLevel.BUILDER);
    GUI gui = new GUI(5, ChatColor.WHITE + "Chat Channels");
    gui.add(new GUIElement(4, Material.BOOK, ChatColor.AQUA + "Chat Channels", List.of(ChatColor.WHITE + "Channels are different streams of chat", ChatColor.WHITE + "that you can speak or listen on.", "", ChatColor.WHITE + "You can listen to multiple channels,", ChatColor.WHITE + "but can only speak on one.", "", ChatColor.WHITE + "Do " + ChatColor.GRAY + "/channel <channel> " + ChatColor.WHITE + "to manually", ChatColor.WHITE + "change channels."), 1, u -> {
    }));
    // Assume we have 7 or fewer channels, otherwise overflow occurs
    int i = 10;
    for (ChatChannel channel : ChatChannel.values()) {
        if (channel == ChatChannel.STAFF && !staff)
            continue;
        boolean speaking = user.getSpeakingChannel() == channel;
        boolean listening = user.getActiveChatChannels().contains(channel);
        gui.add(new GUIElement(i, Material.OAK_SIGN, ChatColor.YELLOW + "" + ChatColor.BOLD + channel, List.of(ChatColor.GRAY + channel.getDescription(), ChatColor.GRAY + "- " + (speaking ? ChatColor.GREEN + "You are speaking on this channel" : ChatColor.RED + "You are not speaking on this channel"), ChatColor.GRAY + "- " + (listening ? ChatColor.GREEN + "You are listening to this channel" : ChatColor.RED + "You are not speaking to this channel")), 1, u -> {
        }));
        gui.add(new GUIElement(i + 9, speaking ? Material.EMERALD_BLOCK : Material.STONE, speaking ? ChatColor.GRAY + "You are currently speaking on this channel" : ChatColor.GREEN + "Click to speak on " + channel, ChatColor.GRAY + "You can only speak on one channel at a time", u -> {
            u.setSpeakingChannel(channel);
            if (!u.getActiveChatChannels().contains(channel)) {
                u.addActiveChatChannel(channel);
            }
            openGUI(u);
        }));
        gui.add(new GUIElement(i + 9 * 2, listening ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK, listening ? speaking ? ChatColor.RED + "You must listen to the channel you're speaking on" : ChatColor.RED + "Click to stop listening to " + channel : ChatColor.GREEN + "Click to listen to " + channel, ChatColor.GRAY + "You can listen to multiple channels at once", u -> {
            if (speaking && listening)
                return;
            if (listening) {
                u.removeActiveChatChannel(channel);
            } else {
                u.addActiveChatChannel(channel);
            }
            openGUI(u);
        }));
        i++;
    }
    gui.open(user);
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) Arrays(java.util.Arrays) CommandSender(org.bukkit.command.CommandSender) ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) GUIElement(mc.dragons.core.gui.GUIElement) User(mc.dragons.core.gameobject.user.User) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) GUI(mc.dragons.core.gui.GUI) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Material(org.bukkit.Material) ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) GUIElement(mc.dragons.core.gui.GUIElement) GUI(mc.dragons.core.gui.GUI)

Example 3 with ChatChannel

use of mc.dragons.core.gameobject.user.chat.ChatChannel in project DragonsOnline by UniverseCraft.

the class SocialUserHook method onVerifiedJoin.

@Override
public void onVerifiedJoin(User user) {
    /* Send guild welcome(s) */
    Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
        List<Guild> guilds = guildLoader.getAllGuildsWithRaw(user.getUUID());
        boolean shown = false;
        for (Guild guild : guilds) {
            if (!guild.getMOTD().equals("")) {
                if (!shown) {
                    user.getPlayer().sendMessage(" ");
                    user.getPlayer().sendMessage(ChatColor.GREEN + "---[ " + ChatColor.GOLD + "Guild Messages" + ChatColor.GREEN + " ]---");
                }
                shown = true;
                user.getPlayer().sendMessage(guild.getThemeColor().primary() + "" + ChatColor.BOLD + guild.getName());
                user.getPlayer().sendMessage(guild.getThemeColor().secondary() + guild.getMOTD());
                user.getPlayer().sendMessage(" ");
            }
        }
    }, 20L);
    /* Warn if others are online but cannot hear the user */
    boolean anyCanHear = false;
    for (User test : UserLoader.allUsers()) {
        if (test.equals(user))
            continue;
        for (ChatChannel ch : test.getActiveChatChannels()) {
            if (ch.canHear(test, user)) {
                anyCanHear = true;
                break;
            }
        }
    }
    if (!anyCanHear && Bukkit.getOnlinePlayers().size() > 1) {
        Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
            user.getPlayer().sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Warning: " + ChatColor.RED + "Nobody else can hear you in the channel you're speaking in.");
            user.getPlayer().sendMessage(ChatColor.GRAY + "Do " + ChatColor.RESET + "/channel " + ChatColor.GRAY + "to manage channels.");
        }, 20L * 2);
    }
}
Also used : ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) User(mc.dragons.core.gameobject.user.User) Guild(mc.dragons.social.guild.GuildLoader.Guild)

Example 4 with ChatChannel

use of mc.dragons.core.gameobject.user.chat.ChatChannel in project DragonsOnline by UniverseCraft.

the class User method handleJoin.

/*
	 * Event handlers
	 */
public void handleJoin(boolean firstJoin) {
    joined = true;
    setData("username", getPlayer().getName());
    setData("lastJoined", System.currentTimeMillis());
    setData("currentServer", instance.getServerName());
    if (PermissionUtil.verifyActivePermissionLevel(this, PermissionLevel.TESTER, false)) {
        sync(() -> player.setGameMode(getSavedGameMode()));
    } else {
        sync(() -> player.setGameMode(GameMode.ADVENTURE));
    }
    if (isVanished()) {
        player.sendMessage(ChatColor.DARK_GREEN + "You are currently vanished.");
    } else if (getRank().ordinal() >= Rank.PATRON.ordinal()) {
        Bukkit.broadcastMessage(getRank().getNameColor() + "" + ChatColor.BOLD + getRank().getRankName() + " " + player.getName() + " joined!");
    } else {
        Bukkit.broadcastMessage(ChatColor.GRAY + player.getName() + " joined!");
    }
    player.sendMessage(ChatColor.GOLD + "Hello " + getName() + " and welcome to DragonsOnline.");
    String spacer = ChatColor.GRAY + "    -    ";
    player.sendMessage(ChatColor.LIGHT_PURPLE + "Level: " + getLevel() + spacer + ChatColor.GREEN + "XP: " + getXP() + " (" + MathUtil.round(getLevelProgress() * 100.0F) + "%)" + spacer + ChatColor.YELLOW + "Gold: " + getGold());
    TextComponent component = new TextComponent(ChatColor.AQUA + "Speaking in ");
    TextComponent speaking = getSpeakingChannel().format();
    speaking.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
    component.addExtra(speaking);
    component.addExtra(ChatColor.AQUA + " and listening to ");
    List<ChatChannel> channels = getActiveChatChannels();
    for (int i = 0; i < channels.size(); i++) {
        TextComponent listening = channels.get(i).format();
        listening.setColor(net.md_5.bungee.api.ChatColor.DARK_AQUA);
        component.addExtra(listening);
        if (i < channels.size() - 1) {
            component.addExtra(", ");
        }
    }
    player.spigot().sendMessage(component);
    if (firstJoin) {
        player.sendMessage(ChatColor.AQUA + "Use " + ChatColor.DARK_AQUA + "/channel" + ChatColor.AQUA + " to change channels.");
    }
    if (getUnreadChangeLogs().size() > 0) {
        player.sendMessage(ChatColor.DARK_GREEN + "You have unread changelogs! Do " + ChatColor.GREEN + "/whatsnew" + ChatColor.DARK_GREEN + " to read them!");
    }
    userHookRegistry.getHooks().forEach(h -> h.onVerifiedJoin(this));
    player.sendMessage("");
    updateState();
    updateVanishState();
    updateVanishStatesOnSelf();
    updateVanillaLeveling();
    updateTablistHeaders();
    updatePrimaryNameTag();
    String ip = player.getAddress().getAddress().getHostAddress();
    setData("ip", ip);
    List<String> ipHistory = getData().getList("ipHistory", String.class);
    if (!ipHistory.contains(ip)) {
        ipHistory.add(ip);
    }
    setData("ipHistory", ipHistory);
    connectionMessageHandler.logConnect(this);
    player.updateInventory();
    LOGGER.exiting("User", "handleJoin");
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel)

Example 5 with ChatChannel

use of mc.dragons.core.gameobject.user.chat.ChatChannel in project DragonsOnline by UniverseCraft.

the class User method setState.

public UUID setState(UUID token) {
    UUID backup = getState();
    Document state = stateLoader.getState(token);
    if (state == null || state.isEmpty())
        return backup;
    player.teleport(StorageUtil.docToLoc(state.get("loc", Document.class)));
    setXP(state.getInteger("xp"));
    player.setHealth(state.getDouble("health"));
    player.setGameMode(GameMode.valueOf(state.getString("gamemode")));
    loadQuests(null, state.get("quests", Document.class));
    if (state.getInteger("deathCountdown", 0) != 0) {
        setDeathCountdown(state.getInteger("deathCountdown"));
    }
    setSpeakingChannel(ChatChannel.valueOf(state.getString("speaking")));
    List<ChatChannel> ch = new ArrayList<>(getActiveChatChannels());
    for (ChatChannel c : ch) {
        removeActiveChatChannel(c);
    }
    for (String c : state.getList("listening", String.class)) {
        addActiveChatChannel(ChatChannel.valueOf(c));
    }
    clearInventory();
    loadInventory(null, state.get("inventory", Document.class));
    setGold(state.getDouble("gold"), false);
    getData().append("skills", state.get("skills", Document.class));
    getData().append("skillProgress", state.get("skillProgress", Document.class));
    getData().append("lastResId", state.getInteger("lastRes"));
    if (state.getBoolean("resExitTo") != null) {
        getData().append("resExitTo", StorageUtil.docToLoc(state.get("resExitTo", Document.class)));
    }
    Bukkit.getScheduler().runTaskLater(instance, () -> {
        sendActionBar(ChatColor.GRAY + "Your state was updated (" + token + ")");
    }, 5L);
    return backup;
}
Also used : ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Document(org.bson.Document)

Aggregations

ChatChannel (mc.dragons.core.gameobject.user.chat.ChatChannel)5 ArrayList (java.util.ArrayList)3 User (mc.dragons.core.gameobject.user.User)3 Arrays (java.util.Arrays)1 List (java.util.List)1 UUID (java.util.UUID)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Collectors (java.util.stream.Collectors)1 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)1 PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)1 GUI (mc.dragons.core.gui.GUI)1 GUIElement (mc.dragons.core.gui.GUIElement)1 StringUtil (mc.dragons.core.util.StringUtil)1 Guild (mc.dragons.social.guild.GuildLoader.Guild)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 Document (org.bson.Document)1 ChatColor (org.bukkit.ChatColor)1 Material (org.bukkit.Material)1 Command (org.bukkit.command.Command)1 CommandSender (org.bukkit.command.CommandSender)1