Guest User

Untitled

a guest
Mar 9th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.38 KB | None | 0 0
  1.  
  2. package org.hyperion.rs2.content.clan;
  3.  
  4. import java.util.Optional;
  5. import java.util.stream.IntStream;
  6.  
  7. import org.hyperion.rs2.Misc.SystemClock;
  8. import org.hyperion.rs2.model.Player;
  9. import org.hyperion.rs2.model.World;
  10. import org.hyperion.rs2.packet.ActionPacketHandler;
  11. import org.hyperion.rs2.packet.ActionPacketHandler.Type;
  12.  
  13. /**
  14.  * Clan Manager for the player
  15.  *
  16.  * @author Dan0194
  17.  * TODO add ability to be a friend in clan
  18.  */
  19. public final class ClanManager {
  20.        
  21.         /**
  22.          * The current clan the player is in
  23.          */
  24.         private Clan currentClan;
  25.  
  26.         /**
  27.          * The player
  28.          */
  29.         private Player player;
  30.        
  31.         /**
  32.          * @param player to the player
  33.          */
  34.         public ClanManager(Player player) {
  35.                 this.player = player;
  36.         }
  37.        
  38.         /**
  39.          * The setup screen for the clan
  40.          */
  41.         public void initSetup() {
  42.                
  43.                 /** Sends the clan setup interface*/
  44.                 player.getActionSender().sendInterface(ClanConstants.CLAN_SETUP);
  45.                
  46.                 /** Updates the setup interface*/
  47.                 updateSetup();
  48.         }
  49.        
  50.         /**
  51.          * Updates the setup screen
  52.          */
  53.         public void updateSetup() {
  54.                
  55.                 /** If the player is viewing the clan set up screen */
  56.                 if(player.getInterfaceState().getCurrentInterface() == ClanConstants.CLAN_SETUP) {
  57.                        
  58.                         /** Makes an optional of the players clan */
  59.                         Optional<Clan> clan = World.getWorld().getClanByOwner(player.getName());
  60.                        
  61.                         /** If player has a clan then update the interface */
  62.                         if(clan.isPresent()) {
  63.                                 player.getActionSender().sendString(18306, clan.get().getTitle());
  64.                                 player.getActionSender().sendString(18309, clan.get().getEnterRank().getText());
  65.                                 player.getActionSender().sendString(18312, clan.get().getTalkRank().getText());
  66.                                 player.getActionSender().sendString(18315, clan.get().getKickRank().getText());
  67.                                 player.getActionSender().sendString(18318, clan.get().getBanRank().getText());
  68.                                 clan.get().getBannedPlayers().update(player);
  69.                                 clan.get().getClanPlayers().update(player);
  70.                         }
  71.                        
  72.                 }
  73.                
  74.         }
  75.        
  76.         /**
  77.          * Setting a new title of the clan
  78.          */
  79.         public void setTitle() {
  80.                
  81.                 /** Creates new enter name chatbox */
  82.                 ActionPacketHandler.submit(player, Type.ENTER_NAME, new ActionPacketHandler() {
  83.  
  84.                         @Override
  85.                         public void execute(Object object) {
  86.                                
  87.                                 /** The title of the clan */
  88.                                 String title = (String) object;
  89.                                
  90.                                 /** An optional if a clan already exists for the player */
  91.                                 Optional<Clan> clan = World.getWorld().getClanByOwner(player.getName());
  92.                                
  93.                                 /** If a clan does not exist */
  94.                                 if(!clan.isPresent()) {
  95.                                        
  96.                                         /** Creates a new clan */
  97.                                         Clan newClan = new Clan(player.getName(), title);
  98.                                         newClan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.OWNER));
  99.                                         World.getWorld().getClans().add(newClan);
  100.                                
  101.                                         player.getActionSender().sendMessage("You have just created a new clan.");
  102.                                
  103.                                 } else {
  104.                                        
  105.                                         /** Sets new title for clan */
  106.                                         clan.get().setTitle(title);
  107.                                 }
  108.                                
  109.                                 /** Sends title to clan edit screen */
  110.                                 player.getActionSender().sendString(18306, title);
  111.                                
  112.                                
  113.                         }
  114.                        
  115.                 });
  116.         }
  117.        
  118.        
  119.         /**
  120.          * Makes player join a clan in the game
  121.          */
  122.         public void join() {
  123.                
  124.                 /** Creates enter name text box */
  125.                 ActionPacketHandler.submit(player, Type.ENTER_NAME, new ActionPacketHandler() {
  126.  
  127.                         @Override
  128.                         public void execute(Object object) {
  129.                                
  130.                                 /** Gets the input */
  131.                                 String name = (String) object;
  132.                                
  133.                                 player.getActionSender().sendMessage("Joining clan...");
  134.                                
  135.                                 /** Makes an optional on the input name's clan */
  136.                                 Optional<Clan> clan = World.getWorld().getClanByOwner(name);
  137.                                
  138.                                 /** If that player does not have a clan */
  139.                                 if(!clan.isPresent()) {
  140.                                         player.getActionSender().sendMessage("This clan does not exist.");
  141.                                         return;
  142.                                 }
  143.                                
  144.                                 /** Joins the clan */
  145.                                 join(clan.get());
  146.                         }
  147.                        
  148.                 });
  149.         }
  150.        
  151.         /**
  152.          *
  153.          * Joins a specific clan in the game
  154.          *
  155.          * @param clan The clan the player will be attempting to join
  156.          */
  157.         public void join(Clan clan) {
  158.                
  159.                 /** If the clan is full of players */
  160.                 if(clan.getPlayers().size() >= ClanConstants.MAX_PLAYERS) {
  161.                         player.getActionSender().sendMessage("The clan you are trying to enter is full.");
  162.                         return;
  163.                 }
  164.                
  165.                 /** If the player is banned from the clan */
  166.                 if(clan.getBannedPlayers().contains(player.getName())) {
  167.                         player.getActionSender().sendMessage("You have been banned from this clan chat.");
  168.                         return;
  169.                 }
  170.                
  171.                 /** Makes an optional if the player is kicked */
  172.                 Optional<SystemClock> kickedPlayer = Optional.ofNullable(clan.getKickedPlayers().get(player.getName()));
  173.                
  174.                 /** If the player is kicked and the timer has not finished */
  175.                 if(kickedPlayer.isPresent() && !kickedPlayer.get().isFinished()) {
  176.                         player.getActionSender().sendMessage("You were kicked out of the chat. Please wait a while before joining again.");
  177.                         clan.getKickedPlayers().remove(player.getName());
  178.                         return;
  179.                 }
  180.                
  181.                 /** Gets an Optional of the clan player from the players name */
  182.                 Optional<ClanPlayer> clanPlayer = clan.getClanPlayerByName(player.getName());
  183.                
  184.                 /** If the player has never joined the clan before */
  185.                 if(!clanPlayer.isPresent()) {
  186.                        
  187.                         /** If player is an admin */
  188.                         if(player.getRights().toInteger() >= 2) {
  189.                                
  190.                                 /** Sets rights to admin rank */
  191.                                 clan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.ADMIN));
  192.                                
  193.                         } else {
  194.                        
  195.                                 /** Sets rights to normal rank */
  196.                                 clan.getClanPlayers().add(new ClanPlayer(player.getName(), ClanRank.NORMAL));
  197.                         }
  198.                        
  199.                 }
  200.                
  201.                 /** Gets the new clan player */
  202.                 ClanPlayer player = clan.getClanPlayerByName(this.player.getName()).get();
  203.  
  204.                 /** If the players rank is too low to enter the chat */
  205.                 if(player.getRank().getPosition() < clan.getEnterRank().getPosition()) {
  206.                         this.player.getActionSender().sendMessage("Your rank is too low to enter this clan.");
  207.                         return;
  208.                 }
  209.                
  210.                 /** Updates the interfaces strings*/
  211.                 this.player.getActionSender().sendString(18135, "Leave Chat");
  212.                 this.player.getActionSender().sendString(18139, "Talking in: " + clan.getTitle());
  213.                 this.player.getActionSender().sendString(18140, "Owner: " + clan.getOwner());
  214.                 this.player.getActionSender().sendMessage("You have joined " + clan.getOwner() + "'s chat / You are talking in " + clan.getTitle());
  215.                
  216.                 /** Adds the player to the clan list */
  217.                 clan.getPlayers().add(this.player);
  218.                
  219.                 /** Sets the player's current clan to this one */
  220.                 currentClan = clan;
  221.        
  222.                 /** Updates the clan roster */
  223.                 clan.getPlayers().update();
  224.         }
  225.        
  226.         /**
  227.          * Clears the line ids of the clan chat
  228.          */
  229.         public void clear() {
  230.                
  231.                 IntStream.range(18144, 18244).forEach(i -> player.getActionSender().sendString(i, ""));
  232.                 IntStream.range(18323, 18422).forEach(i -> player.getActionSender().sendString(i, ""));
  233.                 IntStream.range(18424, 18503).forEach(i -> player.getActionSender().sendString(i, ""));
  234.  
  235.                 player.getActionSender().sendString(18139, "Talking in");
  236.                 player.getActionSender().sendString(18140, "Owner:");
  237.                 player.getActionSender().sendString(18135, "Join Chat");
  238.                
  239.                 player.getActionSender().sendString(18306, "Not set");
  240.                 player.getActionSender().sendString(18309, "Anyone");
  241.                 player.getActionSender().sendString(18312, "Anyone");
  242.                 player.getActionSender().sendString(18315, "Only me");
  243.                 player.getActionSender().sendString(18318, "Only me");
  244.  
  245.         }
  246.        
  247.         /**
  248.          * Gets the clan the player is in
  249.          *
  250.          * @return clan
  251.          */
  252.         public Clan getCurrentClan() {
  253.                 return currentClan;
  254.         }
  255.        
  256.         /**
  257.          * Sets the current clan the player is in
  258.          *
  259.          * @param currentClan to the currentClan
  260.          */
  261.         public void setCurrentClan(Clan currentClan) {
  262.                 this.currentClan = currentClan;
  263.         }
  264.        
  265. }
Advertisement
Add Comment
Please, Sign In to add comment