Search in sources :

Example 1 with SoliniaAsyncPlayerChatEvent

use of com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent in project solinia3-core by mixxit.

the class Solinia3CorePlayerListener method onChat.

@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
    if (event.isCancelled())
        return;
    SoliniaAsyncPlayerChatEvent soliniaevent;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(event.getPlayer());
        if (solplayer.getLanguage() == null || solplayer.getLanguage().equals("UNKNOWN")) {
            if (solplayer.getRace() == null) {
                event.getPlayer().sendMessage("You cannot speak until you set a race /setrace");
                Utils.CancelEvent(event);
                ;
                return;
            } else {
                solplayer.setLanguage(solplayer.getRace().getName().toUpperCase());
            }
        }
        soliniaevent = new SoliniaAsyncPlayerChatEvent(event, solplayer, event.getMessage());
        Bukkit.getPluginManager().callEvent(soliniaevent);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SoliniaAsyncPlayerChatEvent(com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SoliniaAsyncPlayerChatEvent

use of com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent in project solinia3-core by mixxit.

the class Solinia3CorePlayerChatListener method OnChat.

@EventHandler
public void OnChat(SoliniaAsyncPlayerChatEvent event) {
    if (event.isCancelled())
        return;
    if (!(event.getRawEvent() instanceof AsyncPlayerChatEvent))
        return;
    // We control all chat!
    AsyncPlayerChatEvent rawEvent = (AsyncPlayerChatEvent) event.getRawEvent();
    Utils.CancelEvent(rawEvent);
    String currentChannel = event.getPlayer().getCurrentChannel();
    // always redirect npc interactions to local
    if (event.getPlayer().getInteraction() != null) {
        currentChannel = "LOCAL";
    }
    // TODO - Support checking channel modes of player
    if (currentChannel.equals("LOCAL")) {
        StateManager.getInstance().getChannelManager().sendToLocalChannelDecorated(event.getPlayer(), event.getMessage());
    } else {
        StateManager.getInstance().getChannelManager().sendToGlobalChannelDecorated(event.getPlayer(), event.getMessage());
    }
    // NPC responses (if applicable)
    if (event.getPlayer().getInteraction() != null) {
        Entity entity = Bukkit.getEntity(event.getPlayer().getInteraction());
        if (entity != null && entity instanceof LivingEntity) {
            LivingEntity livingEntity = (LivingEntity) entity;
            ISoliniaLivingEntity solentity;
            try {
                solentity = StateManager.getInstance().getEntityManager().getLivingEntity(livingEntity);
                solentity.processInteractionEvent(event.getPlayer().getBukkitPlayer(), InteractionType.CHAT, event.getMessage());
            } catch (CoreStateInitException e) {
            // skip
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaAsyncPlayerChatEvent(com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

SoliniaAsyncPlayerChatEvent (com.solinia.solinia.Events.SoliniaAsyncPlayerChatEvent)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 EventHandler (org.bukkit.event.EventHandler)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 Entity (org.bukkit.entity.Entity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 AsyncPlayerChatEvent (org.bukkit.event.player.AsyncPlayerChatEvent)1