-3

I am currently having some trouble with this code:

public class ChatPlugin extends JavaPlugin implements Listener{

private static ChatPlugin instance;

private final static String CHANNEL = "chat";
private JedisPool jedisPool;
private ChatChannel chatChannel;


@Override
public void onEnable()
{
    instance = this;
    saveDefaultConfig();

    this.jedisPool = new JedisPool(new JedisPoolConfig(), getConfig().getString("redis-host"), 6379, 0,getConfig().getString("redis-password"));
    this.chatChannel = new ChatChannel();

    this.jedisPool.getResource().subscribe(this.chatChannel, new String[]{"chat"});

    Bukkit.getPluginManager().registerEvents(this, this);
    getCommand("chat").setExecutor(this);
}

@Override
public void onDisable()
{
    instance = null;
    this.chatChannel.unsubscribe();
    this.jedisPool.destroy();
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (command.getName().equalsIgnoreCase("chat"))
    {
        getJedis().publish(CHANNEL, args[0]);
        sender.sendMessage(ChatColor.GREEN + "Sent!");
    }
    return true;
}


public Jedis getJedis(){
    return jedisPool.getResource();
}

public static ChatPlugin getInstance() {
    return instance;
}

public class ChatChannel extends JedisPubSub {

    @Override
    public void onMessage(String channel, String message) {
        new BukkitRunnable(){
            @Override
            public void run() {
                Bukkit.broadcastMessage(message);
            }
        }.runTask(ChatPlugin.getInstance());
    }
}

}

This is my first time working with redis' PUB/SUB feature, and I don't really know what is happening. There are no stacktraces, it's just, when the plugin enables, it freezes. Yes, I know this is because I am doing it on the main thread, but even if I run it async (Which I have) it still does not work.

Hope someone can help! Thanks

stargate
  • 21
  • 1
  • 4
  • 1
    You should be more specific with your title rather than say you need some help with a list of tags which are already associated with the post. Further, you should put your code here; not a link to it. – ChiefTwoPencils Jul 19 '16 at 23:46
  • You know every single time I use this forums it's always someone saying something. Can you just I don't know help me? If you're at least gonna correct me give me some advice on my code. Also, that class is pretty big, and forgive me for not knowing what to do. As for the title, what do you want me to put? I make my titles so OTHERS can find this request if they need help. Would you rather it be 'Redis Jedis PUB/SUB Doesn't work no errors bukkit' ? Who is gonna search anything close to that? Instead, if they search 'PUB/SUB Jedis Bukkit' this will come up. @ChiefTwoPencils – stargate Jul 20 '16 at 00:05
  • To add on, @ChiefTwoPencils. I don't quite know why you have come to this question, if you're just going to criticize the simplest thing? Please explain to me how that input would help me to reach my goal at all? And BTW, I edited the code to better meet your needs, because you know, you're the one who needs help! I'm probably breaking rules from commenting twice, but this text box has a character limit! Wow, omg, I just double posted, report me! – stargate Jul 20 '16 at 00:14
  • @stargate my friend, don't feel bad on those comments. Remember most of the people here are professionals (except me) and they are not paid to answer questions in SO but still they are doing this for kindness and sacrificing a portion of there time. BTW I am not familiar with PUB/SUB but I believe it can be done through sockets. Well I can help you personally by emailing me since I am just doing nothing. – Enzokie Jul 20 '16 at 00:17
  • If people say something every time then it's a matter of you not using it correctly or doing the most *you* can to get help. At the time of my comment you didn't even have code; care to explain how anyone could help you like that? When you enter the title it says be specific (anything's better than: "I need some tag tag tag help - that's not even a question); you should also avoid putting tags in your titles unless necessary as they're redundant. That is how I helped you get help; if you prefer to just get down-voted instead of helped keep that and your over-sensitivity up. – ChiefTwoPencils Jul 20 '16 at 00:29
  • As to your second comment, my objective isn't to help you reach your goal when you put little effort into your post. At that point my objective is to moderate the site. – ChiefTwoPencils Jul 20 '16 at 00:34
  • ChiefTwoPencils I have a lot to say, but I just can't deal with your kind of attitude right now, so I'm just say OK and be done with the topic! It was such a pleasure to meet you, really hope it doesn't happen again! @Enzokie Thank you your reply, at least someone is nice around here (cough.) If you don't mind me emailing you, I would really like that. Could you please send it to me? Thanks! :) – stargate Jul 20 '16 at 01:33
  • @stargate Just click my name so that you can go through my profile to see my email. I am avoiding posting contacts in questions :) brb – Enzokie Jul 20 '16 at 01:45
  • @stargate Stack Overflow [is not a forum](http://meta.stackoverflow.com/questions/294774/is-stack-overflow-not-a-forum). Please don't treat it as such. Here, we have high standards of quality, and they're honestly not hard to follow. If you really care about posting good questions that will help other people (not just you) in the future, and don't want be downvoted to hell, take a look at the [help centre](https://stackoverflow.com/help). – bcsb1001 Jul 21 '16 at 22:49
  • @bcsb1001 Can we just drop it? I understand the rules & regulations now. I don't understand why you are commenting here bringing up the past. – stargate Jul 25 '16 at 02:56

1 Answers1

0

You didn't sent us your saveDefaultConfig method so first of all check out if the plugin config is created correctly. After checking that you don't made any mistakes regarding Bukkit or any logical mistake, try to google for any example or try to find examples on programcreek.com (I've found some for jedis there).

If you still get no clue: try doing what you should have done before you've asked here. Read the wiki of Jedis! https://github.com/xetorthio/jedis/wiki