Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hyperion.rs2.content.clan;
- import java.util.Optional;
- import java.util.stream.IntStream;
- import org.hyperion.rs2.Misc.SystemClock;
- import org.hyperion.rs2.model.Player;
- import org.hyperion.rs2.model.World;
- import org.hyperion.rs2.packet.ActionPacketHandler;
- import org.hyperion.rs2.packet.ActionPacketHandler.Type;
- /**
- * Clan Manager for the player
- *
- * @author Dan0194
- * TODO add ability to be a friend in clan
- */
- public final class ClanManager {
- /**
- * The current clan the player is in
- */
- private Clan currentClan;
- /**
- * The player
- */
- private Player player;
- /**
- * @param player to the player
- */
- public ClanManager(Player player) {
- this.player = player;
- }
- /**
- * The setup screen for the clan
- */
- public void initSetup() {
- /** Sends the clan setup interface*/
- player.getActionSender().sendInterface(ClanConstants.CLAN_SETUP);
- /** Updates the setup interface*/
- updateSetup();
- }
- /**
- * Updates the setup screen
- */
- public void updateSetup() {
- /** If the player is viewing the clan set up screen */
- if(player.getInterfaceState().getCurrentInterface() == ClanConstants.CLAN_SETUP) {
- /** Makes an optional of the players clan */
- Optional<Clan> clan = World.getWorld().getClanByOwner(player.getName());
- /** If player has a clan then update the interface */
- if(clan.isPresent()) {
- player.getActionSender().sendString(18306, clan.get().getTitle());
- player.getActionSender().sendString(18309, clan.get().getEnterRank().getText());
- player.getActionSender().sendString(18312, clan.get().getTalkRank().getText());
- player.getActionSender().sendString(18315, clan.get().getKickRank().getText());
- player.getActionSender().sendString(18318, clan.get().getBanRank().getText());
- clan.get().getBannedPlayers().update(player);
- clan.get().getClanPlayers().update(player);
- }
- }
- }
- /**
- * Setting a new title of the clan
- */
- public void setTitle() {
- /** Creates new enter name chatbox */
- ActionPacketHandler.submit(player, Type.ENTER_NAME, new ActionPacketHandler() {
- @Override
- public void execute(Object object) {
- /** The title of the clan */
- String title = (String) object;
- /** An optional if a clan already exists for the player */
- Optional<Clan> clan = World.getWorld().getClanByOwner(player.getName());
- /** If a clan does not exist */
- if(!clan.isPresent()) {
- /** Creates a new clan */
- Clan newClan = new Clan(player.getName(), title);
- newClan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.OWNER));
- World.getWorld().getClans().add(newClan);
- player.getActionSender().sendMessage("You have just created a new clan.");
- } else {
- /** Sets new title for clan */
- clan.get().setTitle(title);
- }
- /** Sends title to clan edit screen */
- player.getActionSender().sendString(18306, title);
- }
- });
- }
- /**
- * Makes player join a clan in the game
- */
- public void join() {
- /** Creates enter name text box */
- ActionPacketHandler.submit(player, Type.ENTER_NAME, new ActionPacketHandler() {
- @Override
- public void execute(Object object) {
- /** Gets the input */
- String name = (String) object;
- player.getActionSender().sendMessage("Joining clan...");
- /** Makes an optional on the input name's clan */
- Optional<Clan> clan = World.getWorld().getClanByOwner(name);
- /** If that player does not have a clan */
- if(!clan.isPresent()) {
- player.getActionSender().sendMessage("This clan does not exist.");
- return;
- }
- /** Joins the clan */
- join(clan.get());
- }
- });
- }
- /**
- *
- * Joins a specific clan in the game
- *
- * @param clan The clan the player will be attempting to join
- */
- public void join(Clan clan) {
- /** If the clan is full of players */
- if(clan.getPlayers().size() >= ClanConstants.MAX_PLAYERS) {
- player.getActionSender().sendMessage("The clan you are trying to enter is full.");
- return;
- }
- /** If the player is banned from the clan */
- if(clan.getBannedPlayers().contains(player.getName())) {
- player.getActionSender().sendMessage("You have been banned from this clan chat.");
- return;
- }
- /** Makes an optional if the player is kicked */
- Optional<SystemClock> kickedPlayer = Optional.ofNullable(clan.getKickedPlayers().get(player.getName()));
- /** If the player is kicked and the timer has not finished */
- if(kickedPlayer.isPresent() && !kickedPlayer.get().isFinished()) {
- player.getActionSender().sendMessage("You were kicked out of the chat. Please wait a while before joining again.");
- clan.getKickedPlayers().remove(player.getName());
- return;
- }
- /** Gets an Optional of the clan player from the players name */
- Optional<ClanPlayer> clanPlayer = clan.getClanPlayerByName(player.getName());
- /** If the player has never joined the clan before */
- if(!clanPlayer.isPresent()) {
- /** If player is an admin */
- if(player.getRights().toInteger() >= 2) {
- /** Sets rights to admin rank */
- clan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.ADMIN));
- } else {
- /** Sets rights to normal rank */
- clan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.NORMAL));
- }
- }
- /** Gets the new clan player */
- ClanPlayer player = clan.getClanPlayerByName(this.player.getName()).get();
- /** If the players rank is too low to enter the chat */
- if(player.getRank().getPosition() < clan.getEnterRank().getPosition()) {
- this.player.getActionSender().sendMessage("Your rank is too low to enter this clan.");
- return;
- }
- /** Updates the interfaces strings*/
- this.player.getActionSender().sendString(18135, "Leave Chat");
- this.player.getActionSender().sendString(18139, "Talking in: " + clan.getTitle());
- this.player.getActionSender().sendString(18140, "Owner: " + clan.getOwner());
- this.player.getActionSender().sendMessage("You have joined " + clan.getOwner() + "'s chat / You are talking in " + clan.getTitle());
- /** Adds the player to the clan list */
- clan.getPlayers().add(this.player);
- /** Sets the player's current clan to this one */
- currentClan = clan;
- /** Updates the clan roster */
- clan.getPlayers().update();
- }
- /**
- * Clears the line ids of the clan chat
- */
- public void clear() {
- IntStream.range(18144, 18244).forEach(i -> player.getActionSender().sendString(i, ""));
- IntStream.range(18323, 18422).forEach(i -> player.getActionSender().sendString(i, ""));
- IntStream.range(18424, 18503).forEach(i -> player.getActionSender().sendString(i, ""));
- player.getActionSender().sendString(18139, "Talking in");
- player.getActionSender().sendString(18140, "Owner:");
- player.getActionSender().sendString(18135, "Join Chat");
- player.getActionSender().sendString(18306, "Not set");
- player.getActionSender().sendString(18309, "Anyone");
- player.getActionSender().sendString(18312, "Anyone");
- player.getActionSender().sendString(18315, "Only me");
- player.getActionSender().sendString(18318, "Only me");
- }
- /**
- * Gets the clan the player is in
- *
- * @return clan
- */
- public Clan getCurrentClan() {
- return currentClan;
- }
- /**
- * Sets the current clan the player is in
- *
- * @param currentClan to the currentClan
- */
- public void setCurrentClan(Clan currentClan) {
- this.currentClan = currentClan;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment