Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hyperion.rs2.content.clan;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Optional;
- import java.util.function.Consumer;
- import java.util.function.Predicate;
- import org.hyperion.rs2.Misc.SystemClock;
- import org.hyperion.rs2.model.Player;
- import org.hyperion.rs2.model.World;
- /**
- * A clan
- *
- * @author Dan0194
- */
- public final class Clan {
- /**
- * The players clan list
- */
- @SuppressWarnings("serial")
- public ClanList<Player> players = new ClanList<Player>(18144, 18244) {
- /**
- *
- * Makes it update for everyone in the clan
- *
- * (non-Javadoc)
- * @see org.hyperion.rs2.content.clan.ClanList#update(org.hyperion.rs2.model.Player)
- */
- @Override
- public void update(Player owner) {
- stream().forEach((Player p) -> super.update(p));
- }
- /**
- * (non-Javadoc)
- * @see org.hyperion.rs2.content.clan.ClanList#onUpdate(org.hyperion.rs2.model.Player, java.util.Optional, int)
- */
- @Override
- public void onUpdate(Player owner, Optional<Player> value, int slot) {
- owner.getActionSender().sendString(slot, value.isPresent() ? "<clan=" + getClanPlayerByName(value.get().getName()).get().getRank().getPosition() + "> " + value.get().getName() : "");
- }
- };
- /**
- * The banned players clan list
- */
- @SuppressWarnings("serial")
- private ClanList<String> bannedPlayers = new ClanList<String>(18424, 18503) {
- /**
- * (non-Javadoc)
- * @see org.hyperion.rs2.content.clan.ClanList#onUpdate(org.hyperion.rs2.model.Player, java.util.Optional, int)
- */
- @Override
- public void onUpdate(Player owner, Optional<String> value, int slot) {
- owner.getActionSender().sendString(slot, value.isPresent() ? "<clan=" + getClanPlayerByName(value.get()).get().getRank().getPosition() + "> " + value.get() : "");
- }
- };
- @SuppressWarnings("serial")
- private ClanList<ClanPlayer> clanPlayers = new ClanList<ClanPlayer>(18323, 18422) {
- /**
- * (non-Javadoc)
- * @see org.hyperion.rs2.content.clan.ClanList#onUpdate(org.hyperion.rs2.model.Player, java.util.Optional, int)
- */
- @Override
- public void onUpdate(Player owner, Optional<ClanPlayer> value, int slot) {
- owner.getActionSender().sendString(slot, value.isPresent() ? "<clan=" + getClanPlayerByName(value.get().getName()).get().getRank().getPosition() + "> " + value.get().getName() : "");
- }
- };
- /**
- * The map of all the kicked players in the clan chat
- */
- private Map<String, SystemClock> kickedPlayers = new HashMap<>(ClanConstants.MAX_PLAYERS_IN_CLAN);
- /**
- * The rank able enter the chat
- */
- private ClanRank enterRank = ClanRank.NORMAL;
- /**
- * The rank able to talk in the chat
- */
- private ClanRank talkRank = ClanRank.NORMAL;
- /**
- * The rank able to kick people in the chat
- */
- private ClanRank kickRank = ClanRank.OWNER;
- /**
- * The rank able to ban people in the chat
- */
- private ClanRank banRank = ClanRank.OWNER;
- /**
- * The owner of the clan
- */
- private String owner;
- /**
- * The title of the clan
- */
- private String title;
- /**
- * If the clan is on loot share
- */
- private boolean lootshare;
- /**
- * @param owner The owner of the clan
- * @param title The title of the clan
- */
- public Clan(String owner, String title) {
- this.title = title;
- this.owner = owner;
- }
- /**
- * Gets an optional of a clan player depending on the name
- *
- * @return an optional with the value of clan player or an optional that is empty
- */
- public Optional<ClanPlayer> getClanPlayerByName(String name) {
- Predicate<ClanPlayer> player = (ClanPlayer c) -> c.getName().equals(name);
- return clanPlayers.stream().filter(player).findFirst();
- }
- /**
- * Gets an optional of a player in a clan chat depending on name
- *
- * @return an optional with the value of the player or an optional that is empty
- */
- public Optional<Player> getPlayerByName(String name) {
- Predicate<Player> player = (Player p) -> p.getName().equals(name);
- return players.stream().filter(player).findFirst();
- }
- /**
- * Kicks a player out of the clan chat
- *
- * @param player The player kicking the player out of the chat
- * @param kickedPlayer The player being kicked out of the chat
- */
- public void kick(Player player, Player kickedPlayer) {
- /** Gets the clan player depending on the name */
- ClanPlayer clanPlayer = getClanPlayerByName(player.getName()).get();
- /** If the player is too low to kick people out of the clan chat */
- if(clanPlayer.getRank().getPosition() < kickRank.getPosition()) {
- player.getActionSender().sendMessage("Your too low of a rank to kick someone out.");
- return;
- }
- /** If the player they are trying to kick out is themselves*/
- if(kickedPlayer.equals(player)) {
- player.getActionSender().sendMessage("You can't kick yourself out of the chat.");
- return;
- }
- /** If the player is trying to kick out the creator of the clan chat */
- if(kickedPlayer.getName().equals(owner)) {
- player.getActionSender().sendMessage("You can't kick the creator of the clan.");
- return;
- }
- /** Kicks them out of the clan chat */
- eject(kickedPlayer, "You have been kicked out of the chat.");
- kickedPlayer.getClanManager().clear();
- SystemClock clock = new SystemClock(ClanConstants.KICK_TIMER * 1000);
- kickedPlayers.put(kickedPlayer.getName(), clock);
- clock.reset();
- }
- /**
- * Bans a player from the clan
- *
- * @param the player The player banning the other player
- * @param bannedPlayer The player being banned
- */
- public void ban(Player player, Player bannedPlayer) {
- /** Gets the clan player */
- ClanPlayer clanPlayer = this.getClanPlayerByName(player.getName()).get();
- /** If the player is too low to ban someone from the chat */
- if(clanPlayer.getRank().getPosition() < banRank.getPosition()) {
- player.getActionSender().sendMessage("Your rank is too low to ban someone.");
- return;
- }
- /** If the player is trying to ban themselves */
- if(player.equals(bannedPlayer)) {
- player.getActionSender().sendMessage("You can't ban yourself.");
- return;
- }
- /** If the player is trying to ban the creator of the chat */
- if(bannedPlayer.getName().equals(owner)) {
- player.getActionSender().sendMessage("You can't ban the creator of the clan.");
- return;
- }
- /** Bans the player from the clan chat*/
- bannedPlayers.add(bannedPlayer.getName());
- eject(bannedPlayer, "You have been banned from the chat.");
- bannedPlayer.getClanManager().clear();
- }
- /**
- * Unbans a player from the clan
- *
- * @param owner The creator unbanning the player from the chat
- * @param bannedPlayer The name of the player being unbanned
- */
- public void unban(Player owner, String bannedPlayer) {
- bannedPlayers.remove(bannedPlayer);
- bannedPlayers.update(owner);
- }
- /**
- * Sends message to entire clan chat
- *
- * @param player The player sending the message
- * @param message being sent to entire clan chat
- */
- public void message(Player player, String message) {
- /** Gets the clan player from the player's name */
- ClanPlayer rank = getClanPlayerByName(player.getName()).get();
- /** If the player is too low rank to talk in the chat */
- if(rank.getRank().getPosition() < talkRank.getPosition()) {
- player.getActionSender().sendMessage("Your rank is too low to talk in the chat.");
- return;
- }
- /** Sends the message to everyone in the chat */
- players.stream().filter(Objects::nonNull).forEach((Player p) -> p.getActionSender().sendClanMessage(player.getName(), message, title, player.getRights().toInteger()));
- }
- /**
- * Ranks up a player in the clan
- *
- * @param owner The owner who is ranking the player
- * @param clanPlayer the player in the clan who is being ranked
- * @param rank The new rank
- */
- public void rank(Player owner, ClanPlayer clanPlayer, ClanRank rank) {
- /** If the owner is trying to rank himself */
- if(this.owner.equals(clanPlayer.getName())) {
- owner.getActionSender().sendMessage("You cannot set a rank for yourself!");
- return;
- }
- /** If the owner is trying to demote an admin */
- if(clanPlayer.getRank().equals(ClanRank.ADMIN)) {
- owner.getActionSender().sendMessage("You cannot demote an admin.");
- return;
- }
- /** If the rank is the same as the Clan player's rank */
- if(rank.equals(clanPlayer.getRank())) {
- owner.getActionSender().sendMessage("That player is already that rank.");
- return;
- }
- /** Makes sure your not setting the rank to a friend */
- rank = rank.equals(ClanRank.FRIEND) ? ClanRank.NORMAL : rank;
- /** Sets the rank and updates all the players in the clan */
- clanPlayer.setRank(rank);
- clanPlayers.update(owner);
- /** Gets an optional of the clan player */
- Optional<Player> rankedPlayer = getPlayerByName(clanPlayer.getName());
- /** If the clan player is in the chat update the entire chat */
- if(rankedPlayer.isPresent()) {
- players.update();
- }
- }
- /**
- * Deletes the entire clan
- *
- * @param owner The owner deleting the clan
- */
- public void delete(Player owner) {
- /** Creates a new list of the entire clan to be looped through */
- new ArrayList<Player>(players).stream().forEach(new Consumer<Player>() {
- @Override
- public void accept(Player t) {
- /** The message the player will be sent */
- String message = t.equals(owner) ? "Deleting clan..." : "The clan you were in has been deleted.";
- /** Ejects the player out of the clan */
- eject(t, message);
- t.getClanManager().clear();
- }
- });
- /** Removes the clan from the global list of all clans */
- World.getWorld().getClans().remove(this);
- owner.getActionSender().sendMessage("You delete the clan.");
- owner.getClanManager().clear();
- }
- /**
- * Ejects a player out of the clan
- *
- * @param player The player being ejected out of clan
- * @param message The message that will be sent to the player
- */
- public void eject(Player player, String message) {
- player.getActionSender().sendMessage(message);
- players.remove(player);
- player.getClanManager().setCurrentClan(null);
- players.update();
- }
- /**
- * Sets the new enter rank
- *
- * @param enterRank to the enterRank
- */
- public void setEnterRank(ClanRank enterRank) {
- this.enterRank = enterRank;
- }
- /**
- * Sets the new talk rank
- *
- * @param talkRank to the talkRank
- */
- public void setTalkRank(ClanRank talkRank) {
- this.talkRank = talkRank;
- }
- /**
- * Sets the new kick rank
- *
- * @param kickRank to the kickRank
- */
- public void setKickRank(ClanRank kickRank) {
- this.kickRank = kickRank;
- }
- /**
- * Sets the new ban rank
- *
- * @param banRank to banRank
- */
- public void setBanRank(ClanRank banRank) {
- this.banRank = banRank;
- }
- /**
- * Gets the owner of the clan
- *
- * @return owner
- */
- public String getOwner() {
- return owner;
- }
- /**
- * Gets the title of the clan
- *
- * @return title
- */
- public String getTitle() {
- return title;
- }
- /**
- * Gets if the clan is on lootshare
- *
- * @return lootshare
- */
- public boolean onLootshare() {
- return lootshare;
- }
- /**
- * Sets the new title of the clan
- *
- * @param title to the title
- */
- public void setTitle(String title) {
- this.title = title;
- }
- /**
- * Sets if the clan is on lootshare
- *
- * @param lootshare to lootshare
- */
- public void setLootshare(boolean lootshare) {
- this.lootshare = lootshare;
- }
- /**
- * Gets the clan list of all players
- *
- * @return clanPlayers
- */
- public ClanList<ClanPlayer> getClanPlayers() {
- return clanPlayers;
- }
- /**
- * Gets the players in the chat
- *
- * @return players
- */
- public ClanList<Player> getPlayers() {
- return players;
- }
- /**
- * Gets the banned players list
- *
- * @return bannedPlayers
- */
- public ClanList<String> getBannedPlayers() {
- return bannedPlayers;
- }
- /**
- * Gets the enter rank
- *
- * @return enterRank
- */
- public ClanRank getEnterRank() {
- return enterRank;
- }
- /**
- * Gets the talk rank
- *
- * @return talkRank
- */
- public ClanRank getTalkRank() {
- return talkRank;
- }
- /**
- * Gets the kick rank
- *
- * @return kickRank
- */
- public ClanRank getKickRank() {
- return kickRank;
- }
- /**
- * Gets the ban rank
- *
- * @return banRank
- */
- public ClanRank getBanRank() {
- return banRank;
- }
- /**
- * Gets the kicked players
- *
- * @return kickedPlayers
- */
- public Map<String, SystemClock> getKickedPlayers() {
- return kickedPlayers;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment