use of com.iridium.iridiumskyblock.api.UserChatToggleEvent in project IridiumSkyblock by Iridium-Development.
the class ChatCommand method execute.
/**
* Executes the command for the specified {@link CommandSender} with the provided arguments.
* Not called when the command execution was invalid (no permission, no player or command disabled).
* Chats with the sender's island members {@link Island}.
*
* @param sender The CommandSender which executes this command
* @param args The arguments used with this command. They contain the sub-command
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = (Player) sender;
Optional<Island> island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (args.length > 1) {
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
for (User user : island.get().getMembers()) {
Player recipient = Bukkit.getPlayer(user.getUuid());
if (recipient != null) {
recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%message%", message)));
}
}
} else {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat());
Bukkit.getPluginManager().callEvent(userChatToggleEvent);
if (userChatToggleEvent.isCancelled())
return false;
user.setIslandChat(!user.isIslandChat());
player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
return true;
}
Aggregations