use of com.wasteofplastic.acidisland.events.IslandLeaveEvent in project acidisland by tastybento.
the class IslandCmd method removePlayerFromTeam.
/**
* Removes a player from a team run by teamleader
*
* @param playerUUID - the player's UUID
* @param teamLeader
* @param makeLeader - true if this is the result of switching leader
* @return true if successful, false if not
*/
public boolean removePlayerFromTeam(final UUID playerUUID, final UUID teamLeader, boolean makeLeader) {
// Remove player from the team
plugin.getPlayers().removeMember(teamLeader, playerUUID);
// If player is not the leader of their own team
if (teamLeader == null || !playerUUID.equals(teamLeader)) {
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
return false;
}
// plugin.getPlayers().setHomeLocation(player, null);
plugin.getPlayers().clearHomeLocations(playerUUID);
plugin.getPlayers().setIslandLocation(playerUUID, null);
plugin.getPlayers().setTeamIslandLocation(playerUUID, null);
if (!makeLeader) {
OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(playerUUID);
if (offlinePlayer.isOnline()) {
// Check perms
if (!((Player) offlinePlayer).hasPermission(Settings.PERMPREFIX + "command.leaveexempt")) {
runCommands(Settings.leaveCommands, offlinePlayer);
}
} else {
// If offline, all commands are run, sorry
runCommands(Settings.leaveCommands, offlinePlayer);
}
// Deduct a reset
if (Settings.leaversLoseReset && Settings.resetLimit >= 0) {
int resetsLeft = plugin.getPlayers().getResetsLeft(playerUUID);
if (resetsLeft > 0) {
resetsLeft--;
plugin.getPlayers().setResetsLeft(playerUUID, resetsLeft);
}
}
}
// Fire event
if (teamLeader != null) {
final Island island = plugin.getGrid().getIsland(teamLeader);
final IslandLeaveEvent event = new IslandLeaveEvent(playerUUID, island);
plugin.getServer().getPluginManager().callEvent(event);
}
} else {
// removed
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
// Event was cancelled for some reason
return false;
}
}
return true;
}
Aggregations