-3
我目前遇到一些麻煩,此代碼:需要一些PUB/SUB Jedis幫助Bukkit
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());
}
}
}
這是我第一次用Redis的PUB/SUB功能的工作,和我不真的不知道發生了什麼。沒有堆棧跟蹤,只是當插件啓用時,它會凍結。是的,我知道這是因爲我在主線程上執行它,但即使我運行它異步(我有)它仍然不起作用。
希望有人能幫助! 謝謝
你應該對你的標題更加具體,而不是說你需要一些已經與帖子關聯的標籤列表。此外,你應該把你的代碼放在這裏;不是它的鏈接。 – ChiefTwoPencils
你知道我每次使用這個論壇時,總是有人在說些什麼。你能幫我嗎?如果你至少要糾正我給我一些關於我的代碼的建議。而且,這個班級非常大,請原諒我不知道該怎麼做。至於標題,你想要我放什麼?我製作我的標題,以便其他人可以在需要幫助時找到此請求。你會喜歡它'Redis Jedis PUB/SUB不工作沒有錯誤bukkit'嗎?誰會去搜索接近那個的東西?相反,如果他們搜索「PUB/SUB Jedis Bukkit」,它會出現。 @ChiefTwoPencils – stargate
要添加,@ChiefTwoPencils。如果你只是批評最簡單的東西,我不知道你爲什麼會問這個問題?請向我解釋這些意見將如何幫助我實現我的目標?順便說一下,我編輯了代碼以更好地滿足您的需求,因爲您知道,您是需要幫助的人!我可能違反評論規則兩次,但這個文本框有一個字符限制!哇,我只是雙貼,舉報我! – stargate