Sketcher2 source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

package com.jotuntech.sketcher.client.command;
import java.nio.ByteBuffer;
import com.jotuntech.sketcher.client.Client;
import com.jotuntech.sketcher.client.Command;
import com.jotuntech.sketcher.client.Connection;
import com.jotuntech.sketcher.client.UserInterface;
import com.jotuntech.sketcher.common.User;
public class SayCommand implements Command {
boolean isAction;
String text;
public SayCommand() {
}
public SayCommand(String text, boolean isAction) {
this.isAction = isAction;
this.text = text;
}
public int perform(Client client, User user) {
if(user == null) {
return Connection.SEND_NONE;
}
if(user.isViewer()) {
return Connection.SEND_NONE;
}
if(isAction) {
client.getUserInterface().println("\u2022 " + user.getName() + text);
} else {
client.getUserInterface().println("<" + user.getName() + "> " + text);
}
if(client.isSoundEnabled()) {
UserInterface.AUDIO_CHAT.play();
}
return Connection.SEND_NONE;
}
public void decode(ByteBuffer in) {
isAction = in.get() != 0 ? true : false;
StringBuffer textBuffer = new StringBuffer();
while(in.remaining() >= 2) {
textBuffer.append(in.getChar());
}
text = textBuffer.toString();
}
public void encode(ByteBuffer out) {
out.put((byte) (isAction ? 0xFF : 0x00));
for(int i = 0; i < text.length(); i++) {
out.putChar(text.charAt(i));
}
}
}