package me.minidigger.voxelgameslib.chat;

import javax.inject.Inject;
import javax.inject.Singleton;

import me.minidigger.voxelgameslib.user.User;
import me.minidigger.voxelgameslib.user.UserHandler;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;

@Singleton
public class ChatListener implements Listener {
    @Inject
    private ChatHandler chatHandler;
    @Inject
    private UserHandler userHandler;

    @EventHandler
    public void onChat(AsyncPlayerChatEvent event) {
        User user = userHandler.getUser(event.getPlayer().getUniqueId()).isPresent() ? userHandler.getUser(event.getPlayer().getUniqueId()).get() : null;

        if (user != null) {
            user.getActiveChannel().sendMessage(user, event.getMessage());
        }

        event.setCancelled(true);
    }
}

@@ -36,16 +36,43 @@
 .chat;%0A%0A
+import java.util.Optional;%0A
 import j
@@ -586,20 +586,30 @@
         
+Optional%3C
 User
+%3E
  user = 
@@ -664,135 +664,48 @@
 d())
-.isPresent() ? userHandler.getUser(event.getPlayer().getUniqueId()).get() : null;%0A%0A        if (user != null) %7B%0A           
+;%0A%0A        user.ifPresent(user1 -%3E
  user
+1
 .get
@@ -736,16 +736,17 @@
 age(user
+1
 , event.
@@ -762,19 +762,10 @@
 e())
+)
 ;
-%0A        %7D
 %0A%0A  

refactor another optional