Lang channel (International server)

Discussion in 'Archived: Plugin Requests' started by Erall, Nov 11, 2013.

  1. Offline

    Erall

    Hey,

    I've been looking for a plugin which adds some channels to the game, but each one I found sucks so I'm making a request here.
    The goal is that you can speak in normal chat so everyone can see it.
    But if you just join a channel set by the admin you can still see the global chat, but you can talk in the channel too. You see both channels messages (From the people speaking your language) and from the people who are talking to you in global chat.

    Here's an example :
    I come from Blabla country so I join the blabla channel. I can speak to my Blabla friends using blabla language simply doing something like "²Blabla bal sbla !" or "*Blabla bal sbla !" or any suffix you want. (You could also use a "/" but it's less cool). And oh I'm running in the forest and I see someone but I want to talk to him ! So I simply say "Hello !" using the global channel language because if you noticed, there's no suffix, so I'm talking in global channel.

    It has to be compatible with Essentials Chat (for my self, you can make it for each other if you want) and voila.


    Note: If this already exists please show me I couldn't find anything cool and easy to use.
     
  2. Offline

    CopyableCougar4

    Code:
    public class ChatChannel extends JavaPlugin{
        HashMap<Player, String> channelList = new HashMap<Player, String>();
        @Override
        public YamlConfiguration getConfig(){
            File f = new File(this.getDataFolder() + "/config.yml");
            return YamlConfiguration.loadConfiguration(f);
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            String[] channels = getConfig().getStringList("channels").toArray();
            for(int a = 0; a <= channels.length - 1; a++){
                  if(cmd.getName().equalsIgnoreCase(channels[a]){
                      channelList.put((Player)sender, channels[a]);
                      sender.sendMessage(ChatColor.AQUA + "[Chat] " + ChatColor.RED + "Joined channel: " + channels[a]);
                    return true;
                  }
            }
            return false;
        }
        @EventHandler
        public void onLogin(PlayerJoinEvent evt){
            channelList.put(evt.getPlayer(), "main");
        }
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event){
              if(channelList.get(event.getPlayer()) == null || channelList.get(event.getPlayer()) == "main"){
                  return;
              } else {
                    String message = event.getFormat();
                    event.setCancelled(true);
                    Player[] online = Bukkit.getOnlinePlayers();
                    for(int a = 0; a <= online.length - 1; a++){
                        if(channelList.get(online[a] == channelList.get(event.getPlayer()){
                            online[a].sendMessage("*" + message);
                        }
                    }
              }
        }
    }
    
    Plugin.yml would be:
    Code:
    name: ChatChannel
    main: <main package>.ChatChannel
    version: 1.0
    commands:
        <command>:
            permission: channel.<command>
    permissions:
        channel.<command>:
            default: true
    
    replace <main package> with the jar package of course :)
    Config.yml would be:
    Code:
    #Example channel for French people
    # channels:
    # - french
    channels:
    - main
    
    All you need is someone to write this up, import all the needed stuff, and export it to a .jar :) Hope this helps and let me know if there are any problems :)

    If you want to add an about page for each channel let me know and I can add some stuff to the above code :)
     
  3. Offline

    Erall

    The fact is I can make it but I have no time to...
    Thanks anyway, I will make this later :)
     
  4. Offline

    CopyableCougar4

    I can type this up Friday if nobody has by then :)
     
  5. Offline

    Erall

    Would be really cool, thank you :)
     
  6. Offline

    CD3

    I beleive this request has been filled. :D
     
  7. Offline

    Erall

    Oh really ? Where can I find that plugin then ?
     
  8. Offline

    TheKomputerKing

    It was posted by CopyableCougar4 underneath the OP.
     
    Jake6177 likes this.
  9. Offline

    CopyableCougar4

    Just in case nobody posted this and you still need it :) - LINK

    One problem: config still is only editable in jar file

    Note: /c-new should create channels, if it doesn't, let me know and I can add them straight to the file

    Commands:
    • /c <channel name> joins a channel
    • /c-new <channel name> creates a channel should work
     
  10. Offline

    Erall

    Oh great, thank you very much !
    But if I join a channel everyone can see what I say, am I missing a command or something ?
     
  11. Try ChAdmin?
     
  12. Offline

    Erall

    Yeah thank you, it is a great plugin, but not easy to use for players to switch channels :s
    The best would be like this :
    "Hey I'm talking to everyone or people who are close to me !"
    "!Hey guys I'm talking in the lang channel :)"
     
  13. Offline

    CopyableCougar4

    Okay I updated the file to do what Erall wanted :) LINK

    How to use:
    Messages would start with:
    ! for spanish
    ? for french
    @ for dutch
    otherwise they would just be in the main channel.

    However, if you guys want to do /c <channel name> you still should, in order to receive messages (I may change that soon):)
     
  14. Offline

    Brixishuge

  15. Offline

    CopyableCougar4

    Yup :)
    Show Spoiler

    Code:
    package me.CopyableCougar4.main;
     
    import java.util.*;
    import java.io.*;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.*;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.*;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ChatChannel extends JavaPlugin{
        HashMap<Player, String> channelList = new HashMap<Player, String>();
     
        @Override
        public YamlConfiguration getConfig(){
            File f = new File(this.getDataFolder() + "/config.yml");
            return YamlConfiguration.loadConfiguration(f);
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("c")){
                String channel = args[0].toString();
                channelList.put((Player)sender, channel);
                sender.sendMessage(ChatColor.AQUA + "[Chat] " + ChatColor.RED + "Joined channel: " + channel);
                return true;
            }
            if(cmd.getName().equalsIgnoreCase("c-list")){
                String[] channels = (String[])getConfig().getStringList("channels").toArray();
                String channelList = "";
                for(int a = 0; a <= channels.length; a++){
                    channelList = channelList + "\n- " + channels[a];
                }
                sender.sendMessage(ChatColor.RED + "Channels: " + channelList);
            }
            if(cmd.getName().equalsIgnoreCase("c-new")){
                this.getConfig().getStringList("channels").add(args[0].toString());
                sender.sendMessage(ChatColor.AQUA + "[Chat] " + ChatColor.RED + "Created channel: " + args[0].toString());
                this.saveConfig();
            }
            return false;
        }
     
        @EventHandler
        public void onLogin(PlayerJoinEvent evt){
            channelList.put(evt.getPlayer(), "main");
        }
     
        public void useChannel(Player p, String format, String channel){
            if(channel == "main"){
                Bukkit.broadcastMessage(format);
            } else {
                  Player[] online = Bukkit.getOnlinePlayers();
                  for(int a = 0; a <= online.length - 1; a++){
                      if(channelList.get(online[a]) == channel){
                          online[a].sendMessage("*" + format);
                      }
                  }
            }
        }
     
        @EventHandler
        public void onChat(AsyncPlayerChatEvent event){
            event.setCancelled(true);
            String channel = event.getMessage().substring(0, 1);
            String userChannel = "";
            switch(channel){
            case "!": userChannel = "spanish";
            case "?": userChannel = "french";
            case "@": userChannel = "dutch";
            case "$": userChannel = "spanish";
            default: userChannel = "main";     
            }
            useChannel(event.getPlayer(), event.getFormat(), userChannel);
        }
    }
    


    Ignore the getConfig() method, as I used to use that but it doesn't work for me anymore :(
     
  16. Offline

    Erall

    Thank you very much, it saves me good time :)
     
  17. Offline

    Brixishuge

    CopyableCougar4 What is this part used for?

    Code:java
    1. public void useChannel(Player p, String format, String channel){
    2. if(channel == "main"){
    3. Bukkit.broadcastMessage(format);
    4. } else {
    5. Player[] online = Bukkit.getOnlinePlayers();
    6. for(int a = 0; a <= online.length - 1; a++){
    7. if(channelList.get(online[a]) == channel){
    8. online[a].sendMessage("*" + format);
    9. }


    and I can't see where you've defined what "format" is...

    Thanks for answering ;)
     
  18. Offline

    CopyableCougar4

    This part of the code sends all users with the same channel toggled whatever the user was going to send. The 'String format' is just event.getFormat() sent from onChat.
     
    Brixishuge likes this.

Share This Page