use of com.iridium.iridiumskyblock.api.UserKickEvent in project IridiumSkyblock by Iridium-Development.
the class KickCommand 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).
* Kicks a user from an 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) {
if (args.length != 2) {
sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
Player player = (Player) sender;
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = user.getIsland();
if (!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]);
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
if (!island.get().equals(targetUser.getIsland().orElse(null))) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
if (targetUser.getIslandRank().getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.KICK)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotKickUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}
UserKickEvent userKickEvent = new UserKickEvent(island.get(), targetUser, user);
Bukkit.getPluginManager().callEvent(userKickEvent);
if (userKickEvent.isCancelled())
return false;
if (targetPlayer instanceof Player) {
((Player) targetPlayer).sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenKicked.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
PlayerUtils.teleportSpawn((Player) targetPlayer);
}
targetUser.setIsland(null);
// Send a message to all other members
for (User member : island.get().getMembers()) {
Player islandMember = Bukkit.getPlayer(member.getUuid());
if (islandMember != null) {
if (!islandMember.equals(player)) {
islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().kickedPlayer.replace("%kicker%", player.getName()).replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youKickedPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
}
}
}
IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_KICKED, user, targetUser, 0, "");
IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
return true;
}
Aggregations