Skip to content

Commit

Permalink
Retravail automessage et ajout d'un type de message
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann151924 committed Feb 25, 2020
1 parent 7d32fc1 commit 31860e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ public ChatService(String uri, AurionChat plugin){
}

@Override
public void sendMessage(String channelName, String message){
String channel = channelName.toLowerCase();
//#TODO a check
if(config.getAutomessageEnable()){
utils.broadcastToPlayer(channel, message);
}
public void sendMessage(String channel, String message){
utils.sendMessageToPlayer(channel, message);
if(plugin.getConfigPlugin().getConsoleSpy()){
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&',message));
plugin.sendConsoleMessage(message);
}

}

@Override
public void sendAutoMessage(String channel, String message) {
if(config.getAutomessageEnable()){
utils.broadcastToPlayer(channel, message);
}
}

@Override
public void desactivatePlugin(){
Bukkit.getPluginManager().disablePlugin(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ public void join(String queueName) throws IOException{
}
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, EXCHANGE_NAME, "aurion.chat.*");
//canaux peuvent etre : aurion.chat.<server> et/ou aurion.automessage.<server>
channel.queueBind(queueName, EXCHANGE_NAME, "aurion.#");

DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String json = new String(delivery.getBody(), StandardCharsets.UTF_8);
String message = new JsonParser().parse(json).getAsJsonObject().get("message").getAsString();
String channel = delivery.getEnvelope().getRoutingKey().split("\\.")[2];
sendMessage(channel, message);
String type = delivery.getEnvelope().getRoutingKey().split("\\.")[1];
String channel = delivery.getEnvelope().getRoutingKey().split("\\.")[2].toLowerCase();
if(type.equalsIgnoreCase("automessage")){
sendAutoMessage(channel, message);
} else if(type.equalsIgnoreCase("chat")) {
sendMessage(channel, message);
} else {
System.out.println("Received message with the type " + type + " and the message was " + message + ". It won't be processed");
}
};
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {});
}
Expand All @@ -72,6 +80,7 @@ public void close() throws TimeoutException, IOException{
}

abstract public void sendMessage(String channelName, String message);
abstract public void sendAutoMessage(String channelName, String message);
abstract public void desactivatePlugin();

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginGroup=com.mineaurion
pluginId=aurionchat
pluginVersion=0.7
pluginVersion=0.7.1
jarName=AurionChat
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ public ChatService(String uri, AurionChat plugin){
}

@Override
public void sendMessage(String channelName, String message){
String channel = channelName.toLowerCase();
//#TODO a check
if(config.options.automessage){
utils.broadcastToPlayer(channel, message);
}
public void sendMessage(String channel, String message){
utils.sendMessageToPlayer(channel, message);
if(config.options.spy){
plugin.sendConsoleMessage(message);
}
}

@Override
public void sendAutoMessage(String channel, String message) {
if(config.options.automessage){
utils.broadcastToPlayer(channel, message);
}
}

@Override
public void desactivatePlugin(){
Sponge.getEventManager().unregisterListeners(plugin);
Expand Down

0 comments on commit 31860e3

Please sign in to comment.