use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HandlerPlayInChatMessage method handle.
@Override
public void handle(NetworkContext context, MessagePlayInChatMessage message) {
final NetworkSession session = context.getSession();
final LanternPlayer player = session.getPlayer();
player.resetIdleTimeoutCounter();
final String message0 = message.getMessage();
// Check for a valid click action callback
final Matcher matcher = LanternClickActionCallbacks.COMMAND_PATTERN.matcher(message0);
if (matcher.matches()) {
final UUID uniqueId = UUID.fromString(matcher.group(1));
final Optional<Consumer<CommandSource>> callback = LanternClickActionCallbacks.get().getCallbackForUUID(uniqueId);
if (callback.isPresent()) {
callback.get().accept(player);
} else {
player.sendMessage(error(t("The callback you provided was not valid. Keep in mind that callbacks will expire " + "after 10 minutes, so you might want to consider clicking faster next time!")));
}
return;
}
String message1 = StringUtils.normalizeSpace(message0);
if (!isAllowedString(message0)) {
session.disconnect(t("multiplayer.disconnect.illegal_characters"));
return;
}
if (message1.startsWith("/")) {
Lantern.getSyncExecutorService().submit(() -> Sponge.getCommandManager().process(player, message1.substring(1)));
} else {
final Text nameText = player.get(Keys.DISPLAY_NAME).get();
final Text rawMessageText = Text.of(message0);
final GlobalConfig.Chat.Urls urls = Lantern.getGame().getGlobalConfig().getChat().getUrls();
final Text messageText;
if (urls.isEnabled() && player.hasPermission(Permissions.Chat.FORMAT_URLS)) {
messageText = newTextWithLinks(message0, urls.getTemplate(), false);
} else {
messageText = rawMessageText;
}
final MessageChannel channel = player.getMessageChannel();
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.addContext(EventContextKeys.PLAYER, player);
final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(causeStack.getCurrentCause(), channel, Optional.of(channel), new MessageEvent.MessageFormatter(nameText, messageText), rawMessageText, false);
if (!Sponge.getEventManager().post(event) && !event.isMessageCancelled()) {
event.getChannel().ifPresent(c -> c.send(player, event.getMessage(), ChatTypes.CHAT));
}
}
}
final Attribute<ChatData> attr = context.getChannel().attr(CHAT_DATA);
ChatData chatData = attr.get();
if (chatData == null) {
chatData = new ChatData();
final ChatData chatData1 = attr.setIfAbsent(chatData);
if (chatData1 != null) {
chatData = chatData1;
}
}
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (chatData) {
final long currentTime = LanternGame.currentTimeTicks();
if (chatData.lastChatTime != -1L) {
chatData.chatThrottle = (int) Math.max(0, chatData.chatThrottle - (currentTime - chatData.lastChatTime));
}
chatData.lastChatTime = currentTime;
chatData.chatThrottle += 20;
if (chatData.chatThrottle > Lantern.getGame().getGlobalConfig().getChatSpamThreshold()) {
session.disconnect(t("disconnect.spam"));
}
}
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HandlerPlayInClientSettings method handle.
@Override
public void handle(NetworkContext context, MessagePlayInClientSettings message) {
final LanternPlayer player = context.getSession().getPlayer();
final Cause cause = Cause.of(EventContext.empty(), player);
final PlayerChangeClientSettingsEvent event = SpongeEventFactory.createPlayerChangeClientSettingsEvent(cause, message.getChatVisibility(), LanternSkinPart.fromBitPattern(message.getSkinPartsBitPattern()), message.getLocale(), player, message.getEnableColors(), message.getViewDistance());
Sponge.getEventManager().post(event);
player.setLocale(event.getLocale());
player.setViewDistance(event.getViewDistance());
player.setChatVisibility(event.getChatVisibility());
player.setChatColorsEnabled(message.getEnableColors());
player.offer(LanternKeys.DISPLAYED_SKIN_PARTS, event.getDisplayedSkinParts());
player.offer(Keys.DOMINANT_HAND, message.getDominantHand());
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HandlerPlayInCraftingBookState method handle.
@Override
public void handle(NetworkContext context, MessagePlayInCraftingBookState message) {
final LanternPlayer player = context.getSession().getPlayer();
player.offer(LanternKeys.RECIPE_BOOK_FILTER_ACTIVE, message.hasFilter());
player.offer(LanternKeys.RECIPE_BOOK_GUI_OPEN, message.isCurrentlyOpen());
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HandlerPlayInPlayerMovement method handle.
@Override
public void handle(NetworkContext context, MessagePlayInPlayerMovement message) {
final LanternPlayer player = context.getSession().getPlayer();
player.setRawPosition(new Vector3d(message.getX(), message.getY(), message.getZ()));
player.handleOnGroundState(message.isOnGround());
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HandlerPlayInPlayerMovementAndLook method handle.
@Override
public void handle(NetworkContext context, MessagePlayInPlayerMovementAndLook message) {
final LanternPlayer player = context.getSession().getPlayer();
player.setRawPosition(new Vector3d(message.getX(), message.getY(), message.getZ()));
player.setRawRotation(HandlerPlayInPlayerLook.toRotation(message.getPitch(), message.getYaw()));
player.handleOnGroundState(message.isOnGround());
}
Aggregations