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();
}
}
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
}
}
}
}
Aggregations