use of io.xol.chunkstories.api.events.player.PlayerChatEvent in project chunkstories by Hugobros3.
the class ClientConnection method handleSystemRequest.
@Override
public boolean handleSystemRequest(String message) {
if (message.startsWith("info")) {
this.clientsManager.sendServerInfo(this);
return true;
} else if (message.startsWith("login/")) {
return loginHelper.handleLogin(message.substring(6, message.length()));
} else if (message.equals("mods")) {
sendTextMessage("info/mods:" + clientsManager.getServer().getModsProvider().getModsString());
this.flush();
return true;
} else if (message.equals("icon-file")) {
PacketSendFile iconPacket = new PacketSendFile();
iconPacket.file = new File("server-icon.png");
iconPacket.fileTag = "server-icon";
this.pushPacket(iconPacket);
this.flush();
return true;
}
// Any other commands need an authentificated player !
if (player == null)
return false;
// Login-mandatory requests ( you need to be authentificated to use them )
if (message.equals("co/off")) {
this.disconnect("Client-terminated connection");
} else if (message.startsWith("send-mod/")) {
String modDescriptor = message.substring(9);
String md5 = modDescriptor.substring(4);
logger.info(this + " asked to be sent mod " + md5);
// Give him what he asked for.
File found = clientsManager.getServer().getModsProvider().obtainModRedistribuable(md5);
if (found == null) {
logger.info("No such mod found.");
} else {
logger.info("Pushing mod md5 " + md5 + "to user.");
PacketSendFile modUploadPacket = new PacketSendFile();
modUploadPacket.file = found;
modUploadPacket.fileTag = modDescriptor;
this.pushPacket(modUploadPacket);
}
} else if (message.startsWith("world/")) {
// TODO this bit will obviously need to be rewritten when I get arround to doing multiworld support
WorldServer world = clientsManager.getServer().getWorld();
message = message.substring(6, message.length());
if (message.equals("enter")) {
player.setWorld(world);
// Sends the construction info for the world, and then the player entity
PacketSendWorldInfo packet = new PacketSendWorldInfo((WorldInfoImplementation) world.getWorldInfo());
pushPacket(packet);
// TODO only spawn the player when he asks to
world.spawnPlayer(player);
return true;
} else if (message.equals("translator")) {
PacketContentTranslator packet = new PacketContentTranslator((AbstractContentTranslator) world.getContentTranslator());
player.pushPacket(packet);
return true;
} else if (message.equals("respawn")) {
// Only allow to respawn if the current entity is null or dead
if (player.getControlledEntity() == null || (player.getControlledEntity() instanceof EntityLiving && ((EntityLiving) player.getControlledEntity()).isDead())) {
world.spawnPlayer(player);
player.sendMessage("Respawning ...");
} else
player.sendMessage("You're not dead, or you are controlling a non-living entity.");
return true;
}
return false;
} else if (message.startsWith("chat/")) {
String chatMessage = message.substring(5, message.length());
// Messages starting with / are commands
if (chatMessage.startsWith("/")) {
chatMessage = chatMessage.substring(1, chatMessage.length());
String cmdName = chatMessage.toLowerCase();
String[] args = {};
if (chatMessage.contains(" ")) {
cmdName = chatMessage.substring(0, chatMessage.indexOf(" "));
args = chatMessage.substring(chatMessage.indexOf(" ") + 1, chatMessage.length()).split(" ");
}
clientsManager.getServer().getConsole().dispatchCommand(player, cmdName, args);
return true;
// The rest is just normal chat
} else if (chatMessage.length() > 0) {
PlayerChatEvent event = new PlayerChatEvent(player, chatMessage);
clientsManager.getServer().getPluginManager().fireEvent(event);
if (!event.isCancelled())
server.broadcastMessage(event.getFormattedMessage());
return true;
} else {
// Ignore empty messages
return true;
}
}
return false;
}
Aggregations